Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulBredl committed Jun 28, 2024
1 parent 874c648 commit 69a8253
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.ResponseError;
import org.springframework.graphql.test.tester.HttpGraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;

import java.time.OffsetDateTime;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId;
import static de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser.UserRoleInCourse.STUDENT;
Expand Down Expand Up @@ -196,7 +198,7 @@ void testUpdateChapterAdminOnly(final HttpGraphQlTester tester) {
}

@Test
void testDeleteChapterAdminOnly(HttpGraphQlTester tester) {
void testDeleteChapterAdminOnly(WebGraphQlTester tester) {
final ChapterEntity chapterEntity = chapterRepository.save(TestUtils.dummyChapterBuilder().courseId(courseId).build());

final String query = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import de.unistuttgart.iste.meitrex.generated.dto.UserRoleInCourse;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.test.tester.HttpGraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;

import java.util.UUID;

Expand All @@ -28,7 +28,7 @@ class MutationCourseMembershipTest {
private CourseRepository courseRepository;

@Test
void createMembershipTest(HttpGraphQlTester tester) {
void createMembershipTest(WebGraphQlTester tester) {
// create course
final CourseEntity course = courseRepository.save(TestUtils.dummyCourseBuilder().build());

Expand Down Expand Up @@ -71,7 +71,7 @@ void createMembershipTest(HttpGraphQlTester tester) {
}

@Test
void updateMembershipMembershipNotExistingTest(HttpGraphQlTester tester) {
void updateMembershipMembershipNotExistingTest(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down Expand Up @@ -118,7 +118,7 @@ void updateMembershipMembershipNotExistingTest(HttpGraphQlTester tester) {
}

@Test
void updateMembershipTest(HttpGraphQlTester tester) {
void updateMembershipTest(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down Expand Up @@ -171,7 +171,7 @@ void updateMembershipTest(HttpGraphQlTester tester) {
}

@Test
void deleteNotExistingMembershipTest(HttpGraphQlTester tester) {
void deleteNotExistingMembershipTest(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down Expand Up @@ -220,7 +220,7 @@ void deleteNotExistingMembershipTest(HttpGraphQlTester tester) {
}

@Test
void deleteMembershipTest(HttpGraphQlTester tester) {
void deleteMembershipTest(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.ChapterEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.*;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.ChapterRepository;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseMembershipRepository;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseRepository;
import de.unistuttgart.iste.meitrex.course_service.test_utils.TestUtils;
import de.unistuttgart.iste.meitrex.generated.dto.Chapter;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.graphql.test.tester.HttpGraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;
import org.springframework.test.context.ContextConfiguration;

import java.time.OffsetDateTime;
Expand Down Expand Up @@ -40,7 +42,7 @@ class MutationCreateChapterTest {
* Then the chapter is created and returned
*/
@Test
void testCreateChapter(HttpGraphQlTester tester) {
void testCreateChapter(WebGraphQlTester tester) {
final CourseEntity course = courseRepository.save(CourseEntity.builder()
.title("New Course")
.description("This is a new course")
Expand Down Expand Up @@ -106,7 +108,7 @@ void testCreateChapter(HttpGraphQlTester tester) {
* Then an error is returned
*/
@Test
void testCreateChapterCourseNotExisting(HttpGraphQlTester tester) {
void testCreateChapterCourseNotExisting(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down Expand Up @@ -247,7 +249,7 @@ void testTooLongDescription(final GraphQlTester tester) {
* Then a validation error is returned
*/
@Test
void testStartDateAfterEndDate(HttpGraphQlTester tester) {
void testStartDateAfterEndDate(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down Expand Up @@ -290,7 +292,7 @@ void testStartDateAfterEndDate(HttpGraphQlTester tester) {
* Then a validation error is returned
*/
@Test
void testSuggestedStartDateAfterEndDate(HttpGraphQlTester tester) {
void testSuggestedStartDateAfterEndDate(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down Expand Up @@ -334,7 +336,7 @@ void testSuggestedStartDateAfterEndDate(HttpGraphQlTester tester) {
* Then a validation error is returned
*/
@Test
void testSuggestedStartDateAfterSuggestedEndDate(HttpGraphQlTester tester) {
void testSuggestedStartDateAfterSuggestedEndDate(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down Expand Up @@ -379,7 +381,7 @@ void testSuggestedStartDateAfterSuggestedEndDate(HttpGraphQlTester tester) {
* Then a validation error is returned
*/
@Test
void testSuggestedStartDateBeforeStartDate(HttpGraphQlTester tester) {
void testSuggestedStartDateBeforeStartDate(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down Expand Up @@ -423,7 +425,7 @@ void testSuggestedStartDateBeforeStartDate(HttpGraphQlTester tester) {
* Then a validation error is returned
*/
@Test
void testSuggestedEndDateBeforeStartDate(HttpGraphQlTester tester) {
void testSuggestedEndDateBeforeStartDate(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down Expand Up @@ -467,7 +469,7 @@ void testSuggestedEndDateBeforeStartDate(HttpGraphQlTester tester) {
* Then a validation error is returned
*/
@Test
void testSuggestedEndDateAfterEndDate(HttpGraphQlTester tester) {
void testSuggestedEndDateAfterEndDate(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.graphql.test.tester.HttpGraphQlTester;
import org.springframework.test.context.ContextConfiguration;

import java.time.OffsetDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
import de.unistuttgart.iste.meitrex.course_service.test_utils.TestUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.test.tester.HttpGraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;
import org.springframework.test.context.ContextConfiguration;

import java.time.OffsetDateTime;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -39,7 +41,7 @@ class MutationDeleteChapterTest {
* Then the chapter is deleted and the uuid is returned
*/
@Test
void testDeletion(HttpGraphQlTester tester) {
void testDeletion(WebGraphQlTester tester) {
// create a course in the database
final var course = courseRepository.save(TestUtils.dummyCourseBuilder().build());
// create two chapters in the database
Expand Down Expand Up @@ -81,7 +83,7 @@ void testDeletion(HttpGraphQlTester tester) {
* Then an error is returned
*/
@Test
void testDeletionInvalidId(HttpGraphQlTester tester) {
void testDeletionInvalidId(WebGraphQlTester tester) {
final UUID chapterId = UUID.randomUUID();

final String query = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser;
import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser.UserRoleInCourse;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.*;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.ChapterRepository;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseMembershipRepository;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseRepository;
import de.unistuttgart.iste.meitrex.course_service.test_utils.TestUtils;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.test.tester.HttpGraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;
import org.springframework.test.context.ContextConfiguration;

import java.util.List;
Expand Down Expand Up @@ -41,7 +43,7 @@ class MutationDeleteCourseTest {
* Then the course is deleted and the uuid is returned
*/
@Test
void testDeletion(HttpGraphQlTester tester) {
void testDeletion(WebGraphQlTester tester) {
// create two courses in the database
final List<CourseEntity> initialCourses = Stream.of(
TestUtils.dummyCourseBuilder().title("Course 1").build(),
Expand Down Expand Up @@ -84,7 +86,7 @@ void testDeletion(HttpGraphQlTester tester) {
* Then an error is returned
*/
@Test
void testDeletionInvalidId(HttpGraphQlTester tester) {
void testDeletionInvalidId(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

import de.unistuttgart.iste.meitrex.common.testutil.GraphQlApiTest;
import de.unistuttgart.iste.meitrex.common.testutil.InjectCurrentUserHeader;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.*;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseMembershipEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseMembershipPk;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseMembershipRepository;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseRepository;
import de.unistuttgart.iste.meitrex.generated.dto.UserRoleInCourse;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.test.tester.HttpGraphQlTester;

import java.time.OffsetDateTime;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import de.unistuttgart.iste.meitrex.common.testutil.GraphQlApiTest;
import de.unistuttgart.iste.meitrex.common.testutil.InjectCurrentUserHeader;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.*;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseMembershipEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseMembershipPk;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseMembershipRepository;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseRepository;
import de.unistuttgart.iste.meitrex.generated.dto.CourseMembership;
import de.unistuttgart.iste.meitrex.generated.dto.UserRoleInCourse;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.test.tester.HttpGraphQlTester;

import java.time.OffsetDateTime;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.ChapterEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.*;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.ChapterRepository;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseMembershipRepository;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseRepository;
import de.unistuttgart.iste.meitrex.course_service.test_utils.TestUtils;
import de.unistuttgart.iste.meitrex.generated.dto.Chapter;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.graphql.test.tester.HttpGraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;
import org.springframework.test.context.ContextConfiguration;

import java.time.OffsetDateTime;
import java.util.*;
import java.util.Collections;
import java.util.Objects;
import java.util.UUID;

import static de.unistuttgart.iste.meitrex.common.testutil.HeaderUtils.addCurrentUserHeader;
import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId;
Expand All @@ -39,7 +43,7 @@ class MutationUpdateChapterTest {
* Then the chapter is updated and returned
*/
@Test
void testUpdateChapter(HttpGraphQlTester tester) {
void testUpdateChapter(WebGraphQlTester tester) {
final CourseEntity course = courseRepository.save(CourseEntity.builder()
.title("New Course")
.description("This is a new course")
Expand Down Expand Up @@ -114,7 +118,7 @@ void testUpdateChapter(HttpGraphQlTester tester) {
* Then an error is returned
*/
@Test
void testUpdateChapterNotExisting(HttpGraphQlTester tester) {
void testUpdateChapterNotExisting(WebGraphQlTester tester) {
// create admin user object
final LoggedInUser adminUser = new LoggedInUser(UUID.randomUUID(),
"admin",
Expand Down Expand Up @@ -257,7 +261,7 @@ void testTooLongDescription(final GraphQlTester tester) {
* Then a validation error is returned
*/
@Test
void testStartDateAfterEndDate(HttpGraphQlTester tester) {
void testStartDateAfterEndDate(WebGraphQlTester tester) {
// create and save chapter
final ChapterEntity chapter = chapterRepository.save(TestUtils.dummyChapterBuilder().build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.ChapterEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseEntity;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.*;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.ChapterRepository;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseMembershipRepository;
import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseRepository;
import de.unistuttgart.iste.meitrex.course_service.test_utils.TestUtils;
import de.unistuttgart.iste.meitrex.generated.dto.Chapter;
import de.unistuttgart.iste.meitrex.generated.dto.YearDivision;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.graphql.test.tester.GraphQlTester;
import org.springframework.graphql.test.tester.HttpGraphQlTester;
import org.springframework.graphql.test.tester.WebGraphQlTester;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -47,7 +49,7 @@ class MutationUpdateCourseTest {
*/
@Test
@Transactional
void testUpdateCourseSuccessful(HttpGraphQlTester tester) {
void testUpdateCourseSuccessful(WebGraphQlTester tester) {
// create a course with a chapter in the database
final CourseEntity initialCourse = courseRepository.save(CourseEntity.builder().title("Course 1")
.description("This is course 1")
Expand Down Expand Up @@ -138,7 +140,7 @@ void testUpdateCourseSuccessful(HttpGraphQlTester tester) {
* Then an error is returned
*/
@Test
void testUpdateCourseNotExisting(HttpGraphQlTester tester) {
void testUpdateCourseNotExisting(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down Expand Up @@ -272,7 +274,7 @@ void testTooLongDescription(final GraphQlTester tester) {
* Then a validation error is returned
*/
@Test
void testStartDateAfterEndDate(HttpGraphQlTester tester) {
void testStartDateAfterEndDate(WebGraphQlTester tester) {
final UUID courseId = UUID.randomUUID();

// create admin user object
Expand Down
Loading

0 comments on commit 69a8253

Please sign in to comment.