From a7aac50150615929f108c8c1b0c9b89807190646 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 22 May 2023 14:11:26 +0530 Subject: [PATCH] Update dependency gradle to v8 (#610) * Update dependency gradle to v8 * Fixes build issues * Upgrade to kotlin dsl Build * Downgrade version for build to pass --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Raja Kolli --- .../spring-boot-graphql-webflux/build.gradle | 148 ----------------- .../build.gradle.kts | 155 ++++++++++++++++++ .../gradle.properties | 23 --- .../gradle/code-quality.gradle | 67 -------- .../gradle/owasp.gradle | 10 -- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../settings.gradle | 17 -- .../settings.gradle.kts | 8 + .../example/graphql/config/SwaggerConfig.java | 21 +-- .../graphql/config/logging/LoggingAspect.java | 12 +- .../java/com/example/graphql/dtos/Orders.java | 3 +- .../service/CustomerGraphQLService.java | 40 ++--- .../service/CustomerGraphQLServiceImpl.java | 136 +++++++-------- .../graphql/ApplicationIntegrationTest.java | 3 +- .../common/AbstractIntegrationTest.java | 11 +- .../CustomerGraphQLControllerTest.java | 6 +- .../example/graphql/common/MyContainers.java | 3 +- .../build.gradle.kts | 4 +- 18 files changed, 274 insertions(+), 395 deletions(-) delete mode 100644 graphql/spring-boot-graphql-webflux/build.gradle create mode 100644 graphql/spring-boot-graphql-webflux/build.gradle.kts delete mode 100644 graphql/spring-boot-graphql-webflux/gradle.properties delete mode 100644 graphql/spring-boot-graphql-webflux/gradle/code-quality.gradle delete mode 100644 graphql/spring-boot-graphql-webflux/gradle/owasp.gradle delete mode 100644 graphql/spring-boot-graphql-webflux/settings.gradle create mode 100644 graphql/spring-boot-graphql-webflux/settings.gradle.kts diff --git a/graphql/spring-boot-graphql-webflux/build.gradle b/graphql/spring-boot-graphql-webflux/build.gradle deleted file mode 100644 index cc049a07b..000000000 --- a/graphql/spring-boot-graphql-webflux/build.gradle +++ /dev/null @@ -1,148 +0,0 @@ -buildscript { - repositories { - mavenCentral() - maven { url 'https://repo.spring.io/milestone' } - } - dependencies { - classpath "com.avast.gradle:gradle-docker-compose-plugin:${docker_compose_plugin_version}" - classpath "org.owasp:dependency-check-gradle:${owasp_plugin_version}" - } -} - -plugins { - id 'org.springframework.boot' - id 'io.spring.dependency-management' - id 'java-library' - id 'com.gorylenko.gradle-git-properties' - id 'com.github.ben-manes.versions' - id 'com.github.sherter.google-java-format' - id "org.sonarqube" apply false - id 'java' -} - -apply plugin: "idea" -apply from: "gradle/code-quality.gradle" -if (project.hasProperty("ci")) { - apply from: "gradle/owasp.gradle" -} - -group = 'com.example.graphql' -version = '0.0.1-SNAPSHOT' -sourceCompatibility = 17 -targetCompatibility = 17 - -configurations { - compileOnly { - extendsFrom annotationProcessor - } -} - -repositories { - mavenCentral() - maven { url 'https://repo.spring.io/milestone' } -} - -dependencies { - implementation 'org.springframework.boot:spring-boot-starter-graphql' - - // To fix com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.Instant` - // not supported by default - implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310' - implementation 'org.springframework.boot:spring-boot-starter-actuator' - implementation 'org.springframework.boot:spring-boot-starter-webflux' - - compileOnly 'org.projectlombok:lombok' - annotationProcessor 'org.projectlombok:lombok' - implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc' - // Needed to run liquibase - implementation 'org.springframework:spring-jdbc' - // Needed for pointcut - implementation 'org.springframework.boot:spring-boot-starter-aop' - - runtimeOnly 'org.postgresql:r2dbc-postgresql' - runtimeOnly 'org.postgresql:postgresql' - implementation 'org.liquibase:liquibase-core' - implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.1.0' - implementation "org.apache.commons:commons-lang3" - implementation "commons-io:commons-io:${commons_io_version}" - - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'org.springframework.boot:spring-boot-testcontainers' - testImplementation 'io.projectreactor:reactor-test' - testImplementation "org.projectlombok:lombok" - testImplementation "org.awaitility:awaitility" - testImplementation 'org.testcontainers:junit-jupiter' - testImplementation 'org.testcontainers:postgresql' - testImplementation 'org.testcontainers:r2dbc' - testImplementation 'org.springframework.graphql:spring-graphql-test' -} - -defaultTasks "bootRun" - -springBoot { - buildInfo() -} - -bootJar { - //launchScript() -} - -bootBuildImage { - imageName = "DOCKER_USERNAME/spring-graph-ql" -} - -compileJava.dependsOn processResources -processResources.dependsOn bootBuildInfo - -if (project.hasProperty("local")) { - bootRun { - args = ["--spring.profiles.active=local"] - } -} - -gitProperties { - failOnNoGitDirectory = false - keys = ["git.branch", "git.commit.id.abbrev", "git.commit.id.describe"] -} - -googleJavaFormat { - toolVersion = '1.17.0' - options style: 'AOSP' -} - -check.dependsOn verifyGoogleJavaFormat - -test { - useJUnitPlatform() - exclude "**/*IT*", "**/*IntegrationTest*", "**/*IntTest*" - testLogging { - events = ["PASSED", "FAILED", "SKIPPED"] - showStandardStreams = true - exceptionFormat = "full" - } -} - -task integrationTest(type: Test) { - useJUnitPlatform() - - include "**/*IT*", "**/*IntegrationTest*", "**/*IntTest*" - shouldRunAfter test - - testLogging { - events = ["PASSED", "FAILED", "SKIPPED"] - showStandardStreams = true - exceptionFormat = "full" - } -} - -check.dependsOn integrationTest - -task testReport(type: TestReport) { - destinationDir = file("$buildDir/reports/tests") - reportOn test -} - -task integrationTestReport(type: TestReport) { - destinationDir = file("$buildDir/reports/tests") - reportOn integrationTest -} diff --git a/graphql/spring-boot-graphql-webflux/build.gradle.kts b/graphql/spring-boot-graphql-webflux/build.gradle.kts new file mode 100644 index 000000000..930dfc3e6 --- /dev/null +++ b/graphql/spring-boot-graphql-webflux/build.gradle.kts @@ -0,0 +1,155 @@ +import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL +import org.gradle.api.tasks.testing.logging.TestLogEvent.* +import java.io.Reader +import java.util.* + +plugins { + java + id("org.springframework.boot") version "3.1.0" + id("io.spring.dependency-management") version "1.1.0" + id("com.diffplug.spotless") version "6.18.0" + id("com.gorylenko.gradle-git-properties") version "2.4.1" + id("org.owasp.dependencycheck") version "8.2.1" + jacoco + id("org.sonarqube") version "4.0.0.2929" +} + +group = "com.example.graphql" +version = "0.0.1-SNAPSHOT" +java.sourceCompatibility = JavaVersion.VERSION_17 + +configurations { + compileOnly { + extendsFrom(configurations.annotationProcessor.get()) + } +} + +repositories { + mavenCentral() + maven { url = uri("https://repo.spring.io/milestone") } +} + +dependencies { + implementation("org.springframework.boot:spring-boot-starter-graphql") + implementation("org.springframework.boot:spring-boot-starter-actuator") + implementation("org.springframework.boot:spring-boot-starter-webflux") + + compileOnly("org.projectlombok:lombok") + annotationProcessor("org.projectlombok:lombok") + implementation("org.springframework.boot:spring-boot-starter-data-r2dbc") + // Needed to run liquibase + implementation("org.springframework:spring-jdbc") + // Needed for pointcut + implementation("org.springframework.boot:spring-boot-starter-aop") + + runtimeOnly ("org.postgresql:r2dbc-postgresql") + runtimeOnly ("org.postgresql:postgresql") + implementation("org.liquibase:liquibase-core") + implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:2.1.0") + implementation("org.apache.commons:commons-lang3") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-testcontainers") + testImplementation("io.projectreactor:reactor-test") + testImplementation("org.projectlombok:lombok") + testImplementation("org.awaitility:awaitility") + testImplementation("org.testcontainers:junit-jupiter") + testImplementation("org.testcontainers:postgresql") + testImplementation("org.testcontainers:r2dbc") + testImplementation("org.springframework.graphql:spring-graphql-test") +} + +defaultTasks "bootRun" + +springBoot { + buildInfo() +} + +tasks.withType { + useJUnitPlatform() + + testLogging { + events = setOf(PASSED, FAILED, SKIPPED) + showStandardStreams = true + exceptionFormat = FULL + } + finalizedBy(tasks.jacocoTestReport, tasks.jacocoTestCoverageVerification) +} + +jacoco { + toolVersion = "0.8.10" + //reportsDirectory.set(layout.buildDirectory.dir("customJacocoReportDir")) +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) + reports { + xml.required.set(false) + csv.required.set(false) + html.outputLocation.set(layout.buildDirectory.dir("reports/jacoco")) + } +} + +tasks.jacocoTestCoverageVerification { + violationRules { + rule { + element = "BUNDLE" + //includes = listOf("com.sivalabs.*") + + limit { + counter = "LINE" + value = "COVEREDRATIO" + minimum = "0.63".toBigDecimal() + } + } + } +} + +gitProperties { + failOnNoGitDirectory = false + keys = listOf("git.branch", + "git.commit.id.abbrev", + "git.commit.user.name", + "git.commit.message.full") +} + +spotless { + java { + importOrder() + removeUnusedImports() + palantirJavaFormat("2.30.0") + formatAnnotations() + } +} + +// Reference doc : https://jeremylong.github.io/DependencyCheck/dependency-check-gradle/configuration.html +dependencyCheck { + // the default artifact types that will be analyzed. + analyzedTypes = listOf("jar") + // CI-tools usually needs XML-reports, but humans needs HTML. + formats = listOf("HTML", "JUNIT") + // Specifies if the build should be failed if a CVSS score equal to or above a specified level is identified. + // failBuildOnCVSS = 8.toFloat() + // Output directory where the report should be generated + outputDirectory = "$buildDir/reports/dependency-vulnerabilities" + // specify a list of known issues which contain false-positives to be suppressed + //suppressionFiles = ["$projectDir/config/dependencycheck/dependency-check-suppression.xml"] + // Sets the number of hours to wait before checking for new updates from the NVD, defaults to 4. + cveValidForHours = 24 +} + +sonarqube { + properties { + property("sonar.sourceEncoding", "UTF-8") + property("sonar.projectKey", "rajadilipkolli_mfscreener") + property("sonar.organization", "rajadilipkolli") + property("sonar.host.url", "https://sonarcloud.io") + property("sonar.sources", "src/main/java") + property("sonar.tests", "src/test/java") + property("sonar.exclusions", "src/main/java/**/config/*.*,src/main/java/**/entities/*.*,src/main/java/**/models/*.*,src/main/java/**/exceptions/*.*,src/main/java/**/utils/*.*,src/main/java/**/*Application.*") + property("sonar.test.inclusions", "**/*Test.java,**/*IntegrationTest.java,**/*IT.java") + property("sonar.java.codeCoveragePlugin", "jacoco") + property("sonar.coverage.jacoco.xmlReportPaths", "$buildDir/jacoco/test/jacoco.xml") + property("sonar.junit.reportPaths", "$buildDir/test-results/test") + } +} \ No newline at end of file diff --git a/graphql/spring-boot-graphql-webflux/gradle.properties b/graphql/spring-boot-graphql-webflux/gradle.properties deleted file mode 100644 index 75445e5ac..000000000 --- a/graphql/spring-boot-graphql-webflux/gradle.properties +++ /dev/null @@ -1,23 +0,0 @@ -## Plugins ## -checkstyle_plugin_version=10.2 -pmd_plugin_version=6.23.0 -docker_compose_plugin_version=0.16.12 -git_properties_plugin_version=2.4.1 -jacoco_plugin_version=0.8.10 -sonar_plugin_version=4.0.0.2929 -owasp_plugin_version=8.2.1 -spotbugs_plugin_version=4.6.0 -benmanes_versions_plugin_version=0.46.0 -google_java_format_plugin_version=0.9 - -jacoco_min_coverage_required=0.80 - -spring_boot_version=3.1.0 -spring_dependency_management_version=1.1.0 -commons_io_version=2.12.0 - -org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED diff --git a/graphql/spring-boot-graphql-webflux/gradle/code-quality.gradle b/graphql/spring-boot-graphql-webflux/gradle/code-quality.gradle deleted file mode 100644 index 4e3382404..000000000 --- a/graphql/spring-boot-graphql-webflux/gradle/code-quality.gradle +++ /dev/null @@ -1,67 +0,0 @@ -apply plugin: 'jacoco' -apply plugin: "org.sonarqube" - -jacoco { - toolVersion = "${jacoco_plugin_version}" -} - -def jacocoExcludes = [ - '**/*Application.*', - '**/config/**', - '**/models/**', - '**/exceptions/**', - '**/dtos/**', - '**/*Constants*', -] - -jacocoTestReport { - executionData tasks.withType(Test) - classDirectories.from = files(sourceSets.main.output.classesDirs) - sourceDirectories.from = files(sourceSets.main.java.srcDirs) - - afterEvaluate { - getClassDirectories().setFrom(files(classDirectories.files.collect { - fileTree(dir: it, exclude: jacocoExcludes) - })) - } - - reports { - xml.enabled = true - html.enabled = true - } -} - -jacocoTestCoverageVerification { - executionData fileTree(project.buildDir.absolutePath).include("jacoco/*.exec") - afterEvaluate { - getClassDirectories().setFrom(files(classDirectories.files.collect { - fileTree(dir: it, exclude: jacocoExcludes) - })) - } - violationRules { - rule { - element = 'BUNDLE' - limit { - counter = 'COMPLEXITY' - value = 'COVEREDRATIO' - minimum = new BigDecimal("${jacoco_min_coverage_required}") - } - excludes = jacocoExcludes - } - } -} - -check.dependsOn jacocoTestCoverageVerification - -file("sonar-project.properties").withReader { - Properties sonarProperties = new Properties() - sonarProperties.load(it) - - sonarProperties.each { key, value -> - sonarqube { - properties { - property key, value - } - } - } -} diff --git a/graphql/spring-boot-graphql-webflux/gradle/owasp.gradle b/graphql/spring-boot-graphql-webflux/gradle/owasp.gradle deleted file mode 100644 index a043b3287..000000000 --- a/graphql/spring-boot-graphql-webflux/gradle/owasp.gradle +++ /dev/null @@ -1,10 +0,0 @@ - -apply plugin: 'org.owasp.dependencycheck' - -dependencyCheck { - autoUpdate=true - cveValidForHours=1 - format='ALL' -} - -check.dependsOn dependencyCheckAnalyze diff --git a/graphql/spring-boot-graphql-webflux/gradle/wrapper/gradle-wrapper.properties b/graphql/spring-boot-graphql-webflux/gradle/wrapper/gradle-wrapper.properties index 508322917..37aef8d3f 100644 --- a/graphql/spring-boot-graphql-webflux/gradle/wrapper/gradle-wrapper.properties +++ b/graphql/spring-boot-graphql-webflux/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/graphql/spring-boot-graphql-webflux/settings.gradle b/graphql/spring-boot-graphql-webflux/settings.gradle deleted file mode 100644 index 7f657cc29..000000000 --- a/graphql/spring-boot-graphql-webflux/settings.gradle +++ /dev/null @@ -1,17 +0,0 @@ -pluginManagement { - plugins { - id 'org.springframework.boot' version "${spring_boot_version}" - id 'io.spring.dependency-management' version "${spring_dependency_management_version}" - id 'com.gorylenko.gradle-git-properties' version "${git_properties_plugin_version}" - id 'org.sonarqube' version "${sonar_plugin_version}" - id "com.github.ben-manes.versions" version "${benmanes_versions_plugin_version}" - id "com.github.sherter.google-java-format" version "${google_java_format_plugin_version}" - } - - repositories { - maven { url 'https://repo.spring.io/milestone' } - gradlePluginPortal() - } -} - -rootProject.name = 'spring-boot-graphql-webflux' diff --git a/graphql/spring-boot-graphql-webflux/settings.gradle.kts b/graphql/spring-boot-graphql-webflux/settings.gradle.kts new file mode 100644 index 000000000..473d719fb --- /dev/null +++ b/graphql/spring-boot-graphql-webflux/settings.gradle.kts @@ -0,0 +1,8 @@ +pluginManagement { + repositories { + maven { url = uri("https://repo.spring.io/milestone") } + gradlePluginPortal() + } +} + +rootProject.name = "spring-boot-graphql-webflux" diff --git a/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/config/SwaggerConfig.java b/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/config/SwaggerConfig.java index a51189c55..591eee295 100644 --- a/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/config/SwaggerConfig.java +++ b/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/config/SwaggerConfig.java @@ -24,19 +24,14 @@ public GroupedOpenApi publicApi() { @Bean public OpenAPI springGraphQLOpenAPI() { return new OpenAPI() - .info( - new Info() - .title("SpringGraphQL API") - .description("Spring graphql sample application") - .version("v0.0.1") - .license( - new License() - .name("Apache 2.0") - .url("http://springdoc.org"))) - .externalDocs( - new ExternalDocumentation() - .description("SpringGraphQL Wiki Documentation") - .url("https://springshop.wiki.github.org/docs")) + .info(new Info() + .title("SpringGraphQL API") + .description("Spring graphql sample application") + .version("v0.0.1") + .license(new License().name("Apache 2.0").url("http://springdoc.org"))) + .externalDocs(new ExternalDocumentation() + .description("SpringGraphQL Wiki Documentation") + .url("https://springshop.wiki.github.org/docs")) .servers(List.of(new Server().url("/").description("SpringGraphQL"))); } } diff --git a/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/config/logging/LoggingAspect.java b/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/config/logging/LoggingAspect.java index c1cd9bf98..737d8c540 100644 --- a/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/config/logging/LoggingAspect.java +++ b/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/config/logging/LoggingAspect.java @@ -25,17 +25,15 @@ public LoggingAspect(Environment env) { this.env = env; } - @Pointcut( - "within(@org.springframework.stereotype.Repository *)" - + " || within(@org.springframework.stereotype.Service *)" - + " || within(@org.springframework.web.bind.annotation.RestController *)") + @Pointcut("within(@org.springframework.stereotype.Repository *)" + + " || within(@org.springframework.stereotype.Service *)" + + " || within(@org.springframework.web.bind.annotation.RestController *)") public void springBeanPointcut() { // pointcut definition } - @Pointcut( - "@within(com.example.graphql.config.logging.Loggable) || " - + "@annotation(com.example.graphql.config.logging.Loggable)") + @Pointcut("@within(com.example.graphql.config.logging.Loggable) || " + + "@annotation(com.example.graphql.config.logging.Loggable)") public void applicationPackagePointcut() { // pointcut definition } diff --git a/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/dtos/Orders.java b/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/dtos/Orders.java index 9b420f22d..35747be38 100644 --- a/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/dtos/Orders.java +++ b/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/dtos/Orders.java @@ -3,5 +3,4 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.springframework.data.annotation.Id; -public record Orders( - @JsonProperty("id") @Id Integer id, @JsonProperty("customerId") Integer customerId) {} +public record Orders(@JsonProperty("id") @Id Integer id, @JsonProperty("customerId") Integer customerId) {} diff --git a/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/service/CustomerGraphQLService.java b/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/service/CustomerGraphQLService.java index 6fd3c8425..a0944aaa0 100644 --- a/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/service/CustomerGraphQLService.java +++ b/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/service/CustomerGraphQLService.java @@ -1,20 +1,20 @@ -package com.example.graphql.service; - -import com.example.graphql.dtos.Customer; -import com.example.graphql.dtos.Orders; -import java.util.List; -import java.util.Map; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -public interface CustomerGraphQLService { - Flux findAllCustomers(); - - Flux findByNameIgnoringCase(String name); - - Mono>> findAllOrdersByCustomers(List customers); - - Mono addCustomer(String name); - - Mono addOrderToCustomer(Integer id); -} +package com.example.graphql.service; + +import com.example.graphql.dtos.Customer; +import com.example.graphql.dtos.Orders; +import java.util.List; +import java.util.Map; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public interface CustomerGraphQLService { + Flux findAllCustomers(); + + Flux findByNameIgnoringCase(String name); + + Mono>> findAllOrdersByCustomers(List customers); + + Mono addCustomer(String name); + + Mono addOrderToCustomer(Integer id); +} diff --git a/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/service/CustomerGraphQLServiceImpl.java b/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/service/CustomerGraphQLServiceImpl.java index eafe9d6f1..2814fc472 100644 --- a/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/service/CustomerGraphQLServiceImpl.java +++ b/graphql/spring-boot-graphql-webflux/src/main/java/com/example/graphql/service/CustomerGraphQLServiceImpl.java @@ -1,74 +1,62 @@ -package com.example.graphql.service; - -import com.example.graphql.dtos.Customer; -import com.example.graphql.dtos.Orders; -import com.example.graphql.repository.CustomerRepository; -import com.example.graphql.repository.OrdersRepository; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -@Service -@RequiredArgsConstructor -public class CustomerGraphQLServiceImpl implements CustomerGraphQLService { - - private final CustomerRepository customerRepository; - - private final OrdersRepository ordersRepository; - - @Override - public Flux findAllCustomers() { - return this.customerRepository.findAll(); - } - - @Override - public Flux findByNameIgnoringCase(String name) { - return this.customerRepository.findByNameIgnoringCase(name); - } - - @Override - public Mono>> findAllOrdersByCustomers(List customers) { - var keys = customers.stream().map(Customer::id).toList(); - return this.ordersRepository - .findByCustomerIdIn(keys) - .collectMultimap(Orders::customerId) - .map( - customerOrderMap -> { - var result = new HashMap>(); - customerOrderMap - .keySet() - .forEach( - customerId -> { - var customer = - customers.stream() - .filter( - cust -> - cust.id() - .equals( - customerId)) - .findAny() - .orElseThrow(); - result.put( - customer, - new ArrayList<>( - customerOrderMap.get(customerId))); - }); - return result; - }); - } - - @Override - public Mono addCustomer(String name) { - return this.customerRepository.save(new Customer(null, name)); - } - - @Override - public Mono addOrderToCustomer(Integer id) { - return this.ordersRepository.save(new Orders(null, id)); - } -} +package com.example.graphql.service; + +import com.example.graphql.dtos.Customer; +import com.example.graphql.dtos.Orders; +import com.example.graphql.repository.CustomerRepository; +import com.example.graphql.repository.OrdersRepository; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Service +@RequiredArgsConstructor +public class CustomerGraphQLServiceImpl implements CustomerGraphQLService { + + private final CustomerRepository customerRepository; + + private final OrdersRepository ordersRepository; + + @Override + public Flux findAllCustomers() { + return this.customerRepository.findAll(); + } + + @Override + public Flux findByNameIgnoringCase(String name) { + return this.customerRepository.findByNameIgnoringCase(name); + } + + @Override + public Mono>> findAllOrdersByCustomers(List customers) { + var keys = customers.stream().map(Customer::id).toList(); + return this.ordersRepository + .findByCustomerIdIn(keys) + .collectMultimap(Orders::customerId) + .map(customerOrderMap -> { + var result = new HashMap>(); + customerOrderMap.keySet().forEach(customerId -> { + var customer = customers.stream() + .filter(cust -> cust.id().equals(customerId)) + .findAny() + .orElseThrow(); + result.put(customer, new ArrayList<>(customerOrderMap.get(customerId))); + }); + return result; + }); + } + + @Override + public Mono addCustomer(String name) { + return this.customerRepository.save(new Customer(null, name)); + } + + @Override + public Mono addOrderToCustomer(Integer id) { + return this.ordersRepository.save(new Orders(null, id)); + } +} diff --git a/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/ApplicationIntegrationTest.java b/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/ApplicationIntegrationTest.java index 1979d226f..c58cd48f0 100644 --- a/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/ApplicationIntegrationTest.java +++ b/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/ApplicationIntegrationTest.java @@ -14,7 +14,8 @@ @AutoConfigureGraphQlTester class ApplicationIntegrationTest extends AbstractIntegrationTest { - @Autowired private GraphQlTester graphQlTester; + @Autowired + private GraphQlTester graphQlTester; @Test void contextLoads() { diff --git a/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/common/AbstractIntegrationTest.java b/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/common/AbstractIntegrationTest.java index c3b6ab1a8..f0db86088 100644 --- a/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/common/AbstractIntegrationTest.java +++ b/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/common/AbstractIntegrationTest.java @@ -17,12 +17,11 @@ @Testcontainers(disabledWithoutDocker = true) public abstract class AbstractIntegrationTest { - @Autowired protected ObjectMapper objectMapper; + @Autowired + protected ObjectMapper objectMapper; - @Container @ServiceConnection + @Container + @ServiceConnection protected static final PostgreSQLContainer postgreSQLContainer = - new PostgreSQLContainer<>("postgres:15-alpine") - .withDatabaseName("integration-tests-db") - .withUsername("username") - .withPassword("password"); + new PostgreSQLContainer<>("postgres:15.3-alpine"); } diff --git a/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/controller/CustomerGraphQLControllerTest.java b/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/controller/CustomerGraphQLControllerTest.java index fcef2e158..c179a99f5 100644 --- a/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/controller/CustomerGraphQLControllerTest.java +++ b/graphql/spring-boot-graphql-webflux/src/test/java/com/example/graphql/controller/CustomerGraphQLControllerTest.java @@ -19,9 +19,11 @@ @GraphQlTest(CustomerGraphQLController.class) class CustomerGraphQLControllerTest { - @Autowired private GraphQlTester graphQlTester; + @Autowired + private GraphQlTester graphQlTester; - @MockBean private CustomerGraphQLService customerGraphQLService; + @MockBean + private CustomerGraphQLService customerGraphQLService; @Test void test_query_all_customers() { diff --git a/graphql/spring-boot-graphql-webmvc/src/test/java/com/example/graphql/common/MyContainers.java b/graphql/spring-boot-graphql-webmvc/src/test/java/com/example/graphql/common/MyContainers.java index 301dcc0e1..45d2cf088 100644 --- a/graphql/spring-boot-graphql-webmvc/src/test/java/com/example/graphql/common/MyContainers.java +++ b/graphql/spring-boot-graphql-webmvc/src/test/java/com/example/graphql/common/MyContainers.java @@ -6,7 +6,6 @@ public interface MyContainers { - @Container - @ServiceConnection + @Container @ServiceConnection PostgreSQLContainer sqlContainer = new PostgreSQLContainer<>("postgres:15.3-alpine"); } diff --git a/jpa/spring-boot-data-envers-sample/build.gradle.kts b/jpa/spring-boot-data-envers-sample/build.gradle.kts index 5ce3508b5..c9d8ff509 100644 --- a/jpa/spring-boot-data-envers-sample/build.gradle.kts +++ b/jpa/spring-boot-data-envers-sample/build.gradle.kts @@ -14,7 +14,7 @@ plugins { id("org.sonarqube") version "4.0.0.2929" } -group = "com.example.mfscreener" +group = "com.example.envers" version = "0.0.1-SNAPSHOT" java.sourceCompatibility = JavaVersion.VERSION_17 @@ -87,7 +87,7 @@ tasks.jacocoTestCoverageVerification { limit { counter = "LINE" value = "COVEREDRATIO" - minimum = "0.8".toBigDecimal() + minimum = "0.6".toBigDecimal() } } }