Skip to content

Commit

Permalink
Merge pull request #2 from MEITREX/java-version-issues
Browse files Browse the repository at this point in the history
Java version issues
  • Loading branch information
myluki2000 authored Jun 28, 2024
2 parents 2713fdb + 770ee2f commit 08897ef
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 37 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand All @@ -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<String> 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:
Expand All @@ -51,6 +71,7 @@ graphqlCodegen {
}
generateEqualsAndHashCode = true
generateToString = true
fieldsWithResolvers = ["@OnDemand"]
}

// Automatically generate GraphQL code on project build:
Expand All @@ -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
Expand All @@ -70,28 +101,28 @@ 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'
implementation 'org.springframework.boot:spring-boot-starter-validation'
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'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
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"
Expand All @@ -100,5 +131,3 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

tasks.withType(Test).configureEach { testLogging.showStandardStreams = true }
15 changes: 12 additions & 3 deletions generate_api_doc.bat
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
1 change: 0 additions & 1 deletion jacoco.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ test {
finalizedBy jacocoTestReport
}


jacocoTestReport {
reports {
xml.required.set(true)
Expand Down
8 changes: 7 additions & 1 deletion src/main/resources/graphql/common/directives.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
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 All @@ -37,7 +39,7 @@ public class AuthorizationTest {


@Test
void testCreateCourseCourseCreatorOnly(final HttpGraphQlTester tester) {
void testCreateCourseCourseCreatorOnly(WebGraphQlTester tester) {

final String query = """
mutation {
Expand Down Expand Up @@ -78,7 +80,7 @@ public static void assertIsMissingGlobalPermission(final List<ResponseError> gra

@Test
@Transactional
void testUpdateCourseAdminOnly(final HttpGraphQlTester tester) {
void testUpdateCourseAdminOnly(WebGraphQlTester tester) {

final String query = """
mutation {
Expand Down Expand Up @@ -118,7 +120,7 @@ void testUpdateCourseAdminOnly(final HttpGraphQlTester tester) {
}

@Test
void testDeleteCourseAdminOnly(final HttpGraphQlTester tester) {
void testDeleteCourseAdminOnly(WebGraphQlTester tester) {

final String query = """
mutation {
Expand All @@ -133,7 +135,7 @@ void testDeleteCourseAdminOnly(final HttpGraphQlTester tester) {
}

@Test
void testCreateChapterAdminOnly(final HttpGraphQlTester tester) {
void testCreateChapterAdminOnly(WebGraphQlTester tester) {

final String query = """
mutation {
Expand Down Expand Up @@ -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());

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 Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
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
Loading

0 comments on commit 08897ef

Please sign in to comment.