diff --git a/Dockerfile b/Dockerfile index 384cca8..f848966 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:experimental -FROM gradle:7.6.2-jdk17 AS build +FROM gradle:8-jdk21 AS build WORKDIR /workspace/app # Copy only gradle files to container so we can install them diff --git a/build.gradle b/build.gradle index 49809c4..da58da7 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { id 'org.springframework.boot' version '3.+' id 'io.spring.dependency-management' version '1.+' id "io.github.kobylynskyi.graphql.codegen" version "5.+" - id "org.sonarqube" version "4.+" + id "org.sonarqube" version "5.+" id "jacoco" id 'com.adarshr.test-logger' version '3.2.0' } @@ -26,7 +26,27 @@ sonarqube { property("sonar.organization", "meitrex") property("sonar.host.url", "https://sonarcloud.io") } +} + +// workaround to fetch schema files from external repositories +// as gradle only supports java dependencies +def fetchFilesFromRepo(String repository, List files) { + def baseurl = "https://raw.githubusercontent.com/MEITREX/" + def fileUrl = "${baseurl}${repository}/main/src/main/resources/graphql/" + def outputDir = "src/main/resources/graphql" + + files.each { file -> + tasks.register("fetchExternalSchema-${file.capitalize()}", Exec) { + commandLine 'curl', "${fileUrl}${file}", '-o', "${outputDir}/${repository}/${file}" + } + } +} + +fetchFilesFromRepo("common", ["directives.graphqls", "scalars.graphqls", "sortFilterPagination.graphqls"]) +// run this task to fetch the latest schema files from the external github repositories +tasks.register("fetchAllExternalSchemas", Task) { + dependsOn tasks.matching { it.name.startsWith("fetchExternalSchema-") } } // Automatically generate DTOs from GraphQL schema: @@ -51,6 +71,7 @@ graphqlCodegen { } generateEqualsAndHashCode = true generateToString = true + fieldsWithResolvers = ["@OnDemand"] } // Automatically generate GraphQL code on project build: @@ -59,6 +80,16 @@ compileJava.dependsOn 'graphqlCodegen' // Add generated sources to your project source sets: sourceSets.main.java.srcDir "$buildDir/generated" +// Automatically generate API documentation on project build: +// Remark: Only works on Windows +tasks.register('generateApiDocs', Exec) { + commandLine 'cmd', '/c', 'generate_api_doc.bat' +} + +tasks.named('assemble') { + finalizedBy('generateApiDocs') +} + configurations { compileOnly { extendsFrom annotationProcessor @@ -70,7 +101,7 @@ repositories { } dependencies { - implementation 'de.unistuttgart.iste.meitrex:meitrex-common:1.0.0' + implementation 'de.unistuttgart.iste.meitrex:meitrex-common:1.0.6' implementation 'com.google.code.findbugs:jsr305:3.0.2' // removes a gradle warning about an unknown annotation implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-graphql' @@ -78,8 +109,8 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.modelmapper:modelmapper:3.+' - implementation 'com.graphql-java:graphql-java-extended-scalars:20.0' - implementation 'com.graphql-java:graphql-java-extended-validation:20.0' + implementation 'com.graphql-java:graphql-java-extended-scalars:22.0' + implementation 'com.graphql-java:graphql-java-extended-validation:22.0' implementation 'io.dapr:dapr-sdk:1.9.0' // Dapr's core SDK with all features, except Actors. implementation 'io.dapr:dapr-sdk-springboot:1.9.0' // Dapr's SDK integration with SpringBoot compileOnly 'org.projectlombok:lombok' @@ -87,11 +118,11 @@ dependencies { runtimeOnly 'org.postgresql:postgresql' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' - testImplementation 'de.unistuttgart.iste.meitrex:meitrex-common-test:1.0.0' + testImplementation 'de.unistuttgart.iste.meitrex:meitrex-common-test:1.0.6' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework:spring-webflux' testImplementation 'org.springframework.graphql:spring-graphql-test' - testImplementation "org.mockito:mockito-core:3.+" + testImplementation "org.mockito:mockito-core:5.+" testImplementation 'org.hamcrest:hamcrest:2.+' testImplementation "org.testcontainers:postgresql:1.18.3" testImplementation "org.testcontainers:junit-jupiter:1.18.3" @@ -100,5 +131,3 @@ dependencies { tasks.named('test') { useJUnitPlatform() } - -tasks.withType(Test).configureEach { testLogging.showStandardStreams = true } diff --git a/generate_api_doc.bat b/generate_api_doc.bat index 60b112e..17ddc17 100644 --- a/generate_api_doc.bat +++ b/generate_api_doc.bat @@ -1,11 +1,12 @@ @echo off echo Generating API documentation... -echo This requires the service to be running +echo This requires npm to be installed! REM clear old docs del api.md +REM Delete the combined file +del combined.graphql -set port=2001 set title=Course Service API REM install graphql-markdown if not installed @@ -14,4 +15,12 @@ if not exist node_modules\graphql-markdown ( npm install graphql-markdown ) -npx graphql-markdown "http://localhost:%port%/graphql" --title "%title%" > api.md +REM Concatenate all graphql files into one +for /r src\main\resources\graphql %%i in (*.graphqls) do type "%%i" >> combined.graphql + +REM Run npx in a separate cmd instance +cmd /c npx graphql-markdown combined.graphql --title "%title%" > api.md +echo API documentation generated. + +REM Delete the combined file +del combined.graphql \ No newline at end of file diff --git a/jacoco.gradle b/jacoco.gradle index 79af5a1..e7e99ec 100644 --- a/jacoco.gradle +++ b/jacoco.gradle @@ -6,7 +6,6 @@ test { finalizedBy jacocoTestReport } - jacocoTestReport { reports { xml.required.set(true) diff --git a/src/main/resources/graphql/common/directives.graphqls b/src/main/resources/graphql/common/directives.graphqls index 4cf44c4..5b85062 100644 --- a/src/main/resources/graphql/common/directives.graphqls +++ b/src/main/resources/graphql/common/directives.graphqls @@ -14,4 +14,10 @@ directive @Positive(message : String = "graphql.validation.Positive.message") on directive @PositiveOrZero(message : String = "graphql.validation.PositiveOrZero.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION directive @Range(min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.Range.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION directive @Size(min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.Size.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION -directive @ContainerSize(min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.ContainerSize.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION \ No newline at end of file +directive @ContainerSize(min : Int = 0, max : Int = 2147483647, message : String = "graphql.validation.ContainerSize.message") on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION + +""" +The @OnDemand directive is used to mark fields that are only internally resolved when requested. +Implementation Note: This will cause the code generator to omit the field from the generated DTOs. +""" +directive @OnDemand on FIELD_DEFINITION \ No newline at end of file diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/AuthorizationTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/AuthorizationTest.java index 3380c35..57866eb 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/AuthorizationTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/AuthorizationTest.java @@ -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; @@ -37,7 +39,7 @@ public class AuthorizationTest { @Test - void testCreateCourseCourseCreatorOnly(final HttpGraphQlTester tester) { + void testCreateCourseCourseCreatorOnly(WebGraphQlTester tester) { final String query = """ mutation { @@ -78,7 +80,7 @@ public static void assertIsMissingGlobalPermission(final List gra @Test @Transactional - void testUpdateCourseAdminOnly(final HttpGraphQlTester tester) { + void testUpdateCourseAdminOnly(WebGraphQlTester tester) { final String query = """ mutation { @@ -118,7 +120,7 @@ void testUpdateCourseAdminOnly(final HttpGraphQlTester tester) { } @Test - void testDeleteCourseAdminOnly(final HttpGraphQlTester tester) { + void testDeleteCourseAdminOnly(WebGraphQlTester tester) { final String query = """ mutation { @@ -133,7 +135,7 @@ void testDeleteCourseAdminOnly(final HttpGraphQlTester tester) { } @Test - void testCreateChapterAdminOnly(final HttpGraphQlTester tester) { + void testCreateChapterAdminOnly(WebGraphQlTester tester) { final String query = """ mutation { @@ -163,7 +165,7 @@ void testCreateChapterAdminOnly(final HttpGraphQlTester tester) { } @Test - void testUpdateChapterAdminOnly(final HttpGraphQlTester tester) { + void testUpdateChapterAdminOnly(WebGraphQlTester tester) { final ChapterEntity chapterEntity = chapterRepository.save(TestUtils.dummyChapterBuilder().courseId(courseId).build()); @@ -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 = """ @@ -224,7 +226,7 @@ void testDeleteChapterAdminOnly(HttpGraphQlTester tester) { @Test - void testCreateMembershipAdminOnly(final HttpGraphQlTester tester) { + void testCreateMembershipAdminOnly(WebGraphQlTester tester) { final CourseMembership expectedDto = CourseMembership.builder() .setUserId(UUID.randomUUID()) @@ -255,7 +257,7 @@ void testCreateMembershipAdminOnly(final HttpGraphQlTester tester) { } @Test - void testUpdateMembershipAdminOnly(final HttpGraphQlTester tester) { + void testUpdateMembershipAdminOnly(WebGraphQlTester tester) { final CourseMembership expectedDto = CourseMembership.builder() .setUserId(currentUser.getId()) @@ -286,7 +288,7 @@ void testUpdateMembershipAdminOnly(final HttpGraphQlTester tester) { } @Test - void testDeleteMembershipAdminOnly(final HttpGraphQlTester tester) { + void testDeleteMembershipAdminOnly(WebGraphQlTester tester) { final CourseMembership expectedDto = CourseMembership.builder() .setUserId(currentUser.getId()) diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCourseMembershipTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCourseMembershipTest.java index af56ed4..0ba413d 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCourseMembershipTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCourseMembershipTest.java @@ -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; @@ -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()); @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCreateChapterTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCreateChapterTest.java index 5b2c7fc..70e4c05 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCreateChapterTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCreateChapterTest.java @@ -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; @@ -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") @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCreateCourseTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCreateCourseTest.java index 290f109..f5bd23d 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCreateCourseTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationCreateCourseTest.java @@ -1,6 +1,8 @@ package de.unistuttgart.iste.meitrex.course_service.api; -import de.unistuttgart.iste.meitrex.common.testutil.*; +import de.unistuttgart.iste.meitrex.common.testutil.GraphQlApiTest; +import de.unistuttgart.iste.meitrex.common.testutil.InjectCurrentUserHeader; +import de.unistuttgart.iste.meitrex.common.testutil.MockTestPublisherConfiguration; import de.unistuttgart.iste.meitrex.common.user_handling.LoggedInUser; import de.unistuttgart.iste.meitrex.course_service.persistence.repository.ChapterRepository; import de.unistuttgart.iste.meitrex.course_service.persistence.repository.CourseRepository; @@ -9,7 +11,7 @@ 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; @@ -43,7 +45,7 @@ class MutationCreateCourseTest { * Then the course is created and returned */ @Test - void testCreateCourse(final HttpGraphQlTester tester) { + void testCreateCourse(WebGraphQlTester tester) { final String query = """ mutation { createCourse( @@ -100,7 +102,7 @@ void testCreateCourse(final HttpGraphQlTester tester) { * Then the course is created and returned */ @Test - void testCreateCourseWithTerm(final HttpGraphQlTester tester) { + void testCreateCourseWithTerm(GraphQlTester tester) { final String query = """ mutation { createCourse( @@ -254,7 +256,7 @@ void testTooLongDescription(final GraphQlTester tester) { * Then a validation error is returned */ @Test - void testStartDateAfterEndDate(final HttpGraphQlTester tester) { + void testStartDateAfterEndDate(WebGraphQlTester tester) { final String query = """ mutation { createCourse( diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationDeleteChapterTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationDeleteChapterTest.java index 39fe578..90a5d11 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationDeleteChapterTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationDeleteChapterTest.java @@ -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; @@ -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 @@ -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 = """ diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationDeleteCourseTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationDeleteCourseTest.java index 285cdbf..5d97290 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationDeleteCourseTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationDeleteCourseTest.java @@ -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; @@ -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 initialCourses = Stream.of( TestUtils.dummyCourseBuilder().title("Course 1").build(), @@ -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 diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationJoinCourseTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationJoinCourseTest.java index ff73bff..a2734f1 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationJoinCourseTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationJoinCourseTest.java @@ -2,13 +2,15 @@ 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 org.springframework.graphql.test.tester.WebGraphQlTester; import java.time.OffsetDateTime; import java.util.UUID; @@ -28,7 +30,7 @@ class MutationJoinCourseTest { private final UUID currentUserId = UUID.randomUUID(); @Test - void testJoinCourse(final HttpGraphQlTester tester) { + void testJoinCourse(WebGraphQlTester tester) { final CourseEntity course = courseRepository.save(CourseEntity.builder().title("Course 1") .description("This is course 1") .startDate(OffsetDateTime.parse("2020-01-01T00:00:00.000Z")) diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationLeaveCourseTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationLeaveCourseTest.java index 3673d9b..29d7394 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationLeaveCourseTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationLeaveCourseTest.java @@ -2,7 +2,9 @@ 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; @@ -10,7 +12,7 @@ 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 org.springframework.graphql.test.tester.WebGraphQlTester; import java.time.OffsetDateTime; import java.util.UUID; @@ -27,7 +29,7 @@ class MutationLeaveCourseTest { private final UUID currentUserId = UUID.randomUUID(); @Test - void testLeaveCourse(final HttpGraphQlTester tester) { + void testLeaveCourse(WebGraphQlTester tester) { final CourseEntity course = courseRepository.save(CourseEntity.builder().title("Course 1") .description("This is course 1") .startDate(OffsetDateTime.parse("2020-01-01T00:00:00.000Z")) diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationUpdateChapterTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationUpdateChapterTest.java index b3ebaa4..fa73aea 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationUpdateChapterTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationUpdateChapterTest.java @@ -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; @@ -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") @@ -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", @@ -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()); diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationUpdateCourseTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationUpdateCourseTest.java index c8788b9..a7292cc 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationUpdateCourseTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/MutationUpdateCourseTest.java @@ -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; @@ -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") @@ -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 @@ -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 diff --git a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/QueryCourseMembershipsTest.java b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/QueryCourseMembershipsTest.java index 351b52b..a38c422 100644 --- a/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/QueryCourseMembershipsTest.java +++ b/src/test/java/de/unistuttgart/iste/meitrex/course_service/api/QueryCourseMembershipsTest.java @@ -7,14 +7,18 @@ import de.unistuttgart.iste.meitrex.course_service.persistence.entity.CourseMembershipEntity; 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.*; +import de.unistuttgart.iste.meitrex.generated.dto.Course; +import de.unistuttgart.iste.meitrex.generated.dto.CourseMembership; +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.GraphQlTester; -import org.springframework.graphql.test.tester.HttpGraphQlTester; +import org.springframework.graphql.test.tester.WebGraphQlTester; import java.time.OffsetDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import static de.unistuttgart.iste.meitrex.common.testutil.HeaderUtils.addCurrentUserHeader; import static de.unistuttgart.iste.meitrex.common.testutil.TestUsers.userWithMembershipInCourseWithId; @@ -74,7 +78,7 @@ void testMembership(final GraphQlTester tester) { } @Test - void testMembershipsFieldInCourse(HttpGraphQlTester tester) { + void testMembershipsFieldInCourse(WebGraphQlTester tester) { final CourseEntity course = courseRepository.save(createTestCourse()); final LoggedInUser currentUser = userWithMembershipInCourseWithId(course.getId(), ADMINISTRATOR); @@ -110,7 +114,7 @@ void testMembershipsFieldInCourse(HttpGraphQlTester tester) { } @Test - void testMembershipsFieldInCourseNoPermission(HttpGraphQlTester tester) { + void testMembershipsFieldInCourseNoPermission(WebGraphQlTester tester) { final CourseEntity course = courseRepository.save(createTestCourse()); final LoggedInUser currentUser = userWithMembershipInCourseWithId(course.getId(), STUDENT);