diff --git a/src/main/resources/generator/ci/renovate/renovate.json.mustache b/src/main/resources/generator/ci/renovate/renovate.json.mustache index 6e22b893b0a..01b485af0a4 100644 --- a/src/main/resources/generator/ci/renovate/renovate.json.mustache +++ b/src/main/resources/generator/ci/renovate/renovate.json.mustache @@ -13,8 +13,6 @@ ], "prHourlyLimit": 20, "docker-compose": { - "fileMatch": [ - "^src/main/docker/[^/]*\\.ya?ml$" - ] + "fileMatch": ["^src/main/docker/[^/]*\\.ya?ml$"] } } diff --git a/src/main/resources/generator/client/vue/test/spec/http/AxiosHttp.spec.ts.mustache b/src/main/resources/generator/client/vue/test/spec/http/AxiosHttp.spec.ts.mustache index f58c8f7bded..7df43e716fc 100644 --- a/src/main/resources/generator/client/vue/test/spec/http/AxiosHttp.spec.ts.mustache +++ b/src/main/resources/generator/client/vue/test/spec/http/AxiosHttp.spec.ts.mustache @@ -70,10 +70,7 @@ describe('axiosHttp', () => { axiosInstance.put.resolves(responseResult()); const axiosHttp = new AxiosHttp(axiosInstance); - const result = await axiosHttp.put( - '/uri', - fakePayload(), - ); + const result = await axiosHttp.put('/uri', fakePayload()); const [uri, payload] = axiosInstance.put.getCall(0).args; expect(payload).toEqual(fakePayload()); @@ -99,10 +96,7 @@ describe('axiosHttp', () => { axiosInstance.post.resolves(responseResult()); const axiosHttp = new AxiosHttp(axiosInstance); - const result = await axiosHttp.post( - '/uri', - fakePayload(), - ); + const result = await axiosHttp.post('/uri', fakePayload()); const [uri, payload] = axiosInstance.post.getCall(0).args; expect(payload).toEqual(fakePayload()); diff --git a/src/main/resources/generator/client/vue/vite.config.ts.mustache b/src/main/resources/generator/client/vue/vite.config.ts.mustache index 4c4efd4a80c..7168cfb58e3 100644 --- a/src/main/resources/generator/client/vue/vite.config.ts.mustache +++ b/src/main/resources/generator/client/vue/vite.config.ts.mustache @@ -9,9 +9,7 @@ export default defineConfig({ '@': path.resolve(__dirname, './src/main/webapp/app'), }, }, - plugins: [ - vue(), - ], + plugins: [vue()], build: { outDir: '../../../{{projectBuildDirectory}}/classes/static', }, diff --git a/src/main/resources/generator/client/vue/vitest.config.ts.mustache b/src/main/resources/generator/client/vue/vitest.config.ts.mustache index 16220cbe5c2..53a3ab8fe5a 100644 --- a/src/main/resources/generator/client/vue/vitest.config.ts.mustache +++ b/src/main/resources/generator/client/vue/vitest.config.ts.mustache @@ -32,7 +32,14 @@ export default defineConfig({ autoUpdate: true, 100: true, }, - exclude: ['src/main/webapp/**/*.component.ts', 'src/main/webapp/app/main.ts', '.eslintrc.cjs', '.lintstagedrc.cjs', 'src/test/**/*', '{{projectBuildDirectory}}/**'], + exclude: [ + 'src/main/webapp/**/*.component.ts', + 'src/main/webapp/app/main.ts', + '.eslintrc.cjs', + '.lintstagedrc.cjs', + 'src/test/**/*', + '{{projectBuildDirectory}}/**', + ], provider: 'istanbul', reportsDirectory: '{{projectBuildDirectory}}/test-results/', reporter: ['html', 'json-summary', 'text', 'text-summary', 'lcov', 'clover'], diff --git a/src/main/resources/generator/client/vue/webapp/app/http/AxiosHttp.ts.mustache b/src/main/resources/generator/client/vue/webapp/app/http/AxiosHttp.ts.mustache index 421ef702764..3801c5937be 100644 --- a/src/main/resources/generator/client/vue/webapp/app/http/AxiosHttp.ts.mustache +++ b/src/main/resources/generator/client/vue/webapp/app/http/AxiosHttp.ts.mustache @@ -9,18 +9,11 @@ export class AxiosHttp { return this.axiosInstance.get(uri, config); } - async put( - uri: string, - data?: Payload, - ): Promise> { + async put(uri: string, data?: Payload): Promise> { return this.axiosInstance.put(uri, data); } - async post( - uri: string, - data?: Payload, - config?: AxiosRequestConfig, - ): Promise> { + async post(uri: string, data?: Payload, config?: AxiosRequestConfig): Promise> { return this.axiosInstance.post(uri, data, config); } diff --git a/src/main/resources/generator/client/vue/webapp/index.html.mustache b/src/main/resources/generator/client/vue/webapp/index.html.mustache index 28849b246ac..e494020bd20 100644 --- a/src/main/resources/generator/client/vue/webapp/index.html.mustache +++ b/src/main/resources/generator/client/vue/webapp/index.html.mustache @@ -1,4 +1,4 @@ - + diff --git a/src/main/resources/generator/prettier/.prettierrc.mustache b/src/main/resources/generator/prettier/.prettierrc.mustache index 685455babbb..71ed128e088 100644 --- a/src/main/resources/generator/prettier/.prettierrc.mustache +++ b/src/main/resources/generator/prettier/.prettierrc.mustache @@ -4,7 +4,7 @@ printWidth: 140 singleQuote: true tabWidth: {{indentSize}} useTabs: false -endOfLine: "{{endOfLine}}" +endOfLine: '{{endOfLine}}' plugins: - '@prettier/plugin-xml' diff --git a/src/main/resources/generator/server/javatool/archunit/test/AnnotationArchTest.java.mustache b/src/main/resources/generator/server/javatool/archunit/test/AnnotationArchTest.java.mustache index f8f1e77b031..b0c1d26ae41 100644 --- a/src/main/resources/generator/server/javatool/archunit/test/AnnotationArchTest.java.mustache +++ b/src/main/resources/generator/server/javatool/archunit/test/AnnotationArchTest.java.mustache @@ -25,6 +25,7 @@ class AnnotationArchTest { .and(not(equivalentTo(ComponentTest.class)))) ) ); + //@formatter:on @Test diff --git a/src/main/resources/generator/server/javatool/archunit/test/HexagonalArchTest.java.mustache b/src/main/resources/generator/server/javatool/archunit/test/HexagonalArchTest.java.mustache index cb28d029ebd..a61b9762340 100644 --- a/src/main/resources/generator/server/javatool/archunit/test/HexagonalArchTest.java.mustache +++ b/src/main/resources/generator/server/javatool/archunit/test/HexagonalArchTest.java.mustache @@ -40,11 +40,7 @@ class HexagonalArchTest { // the empty package is related to: https://github.com/TNG/ArchUnit/issues/191#issuecomment-507964792 private static final Collection vanillaPackages = List.of("java..", ""); - private static final Collection commonToolsAndUtilsPackages = List.of( - "org.apache.commons..", - "org.jmolecules..", - "org.slf4j.." - ); + private static final Collection commonToolsAndUtilsPackages = List.of("org.apache.commons..", "org.jmolecules..", "org.slf4j.."); private static Collection buildPackagesPatterns(Collection packages) { return packages.stream().map(path -> path + "..").toList(); @@ -93,27 +89,23 @@ class HexagonalArchTest { @Test void shouldNotDependOnOtherBoundedContextDomains() { - Stream - .concat(businessContexts.stream(), sharedKernels.stream()) - .forEach(context -> { - noClasses() - .that() - .resideInAnyPackage(context + "..") - .should() - .dependOnClassesThat() - .resideInAnyPackage(otherBusinessContextsDomains(context)) - .because("Contexts can only depend on classes in the same context or shared kernels") - .check(classes); - }); + Stream.concat(businessContexts.stream(), sharedKernels.stream()).forEach(context -> { + noClasses() + .that() + .resideInAnyPackage(context + "..") + .should() + .dependOnClassesThat() + .resideInAnyPackage(otherBusinessContextsDomains(context)) + .because("Contexts can only depend on classes in the same context or shared kernels") + .check(classes); + }); } @Test void shouldBeAnHexagonalArchitecture() { - Stream - .concat(businessContexts.stream(), sharedKernels.stream()) - .forEach(context -> - Architectures - .layeredArchitecture() + Stream.concat(businessContexts.stream(), sharedKernels.stream()).forEach( + context -> + Architectures.layeredArchitecture() .consideringOnlyDependenciesInAnyPackage(context + "..") .withOptionalLayers(true) .layer("domain models") @@ -134,7 +126,7 @@ class HexagonalArchTest { .mayNotBeAccessedByAnyLayer() .because("Each bounded context should implement an hexagonal architecture") .check(classes) - ); + ); } @Test @@ -176,8 +168,7 @@ class HexagonalArchTest { } private String[] authorizedDomainPackages() { - return Stream - .of(List.of("..domain.."), vanillaPackages, commonToolsAndUtilsPackages, sharedKernelsPackages) + return Stream.of(List.of("..domain.."), vanillaPackages, commonToolsAndUtilsPackages, sharedKernelsPackages) .flatMap(Collection::stream) .toArray(String[]::new); } @@ -237,18 +228,16 @@ class HexagonalArchTest { @Test void shouldNotDependOnSameContextPrimary() { - Stream - .concat(businessContexts.stream(), sharedKernels.stream()) - .forEach(context -> { - noClasses() - .that() - .resideInAPackage(context + ".infrastructure.secondary..") - .should() - .dependOnClassesThat() - .resideInAPackage(context + ".infrastructure.primary") - .because("Secondary should not loop to its own context's primary") - .check(classes); - }); + Stream.concat(businessContexts.stream(), sharedKernels.stream()).forEach(context -> { + noClasses() + .that() + .resideInAPackage(context + ".infrastructure.secondary..") + .should() + .dependOnClassesThat() + .resideInAPackage(context + ".infrastructure.primary") + .because("Secondary should not loop to its own context's primary") + .check(classes); + }); } } diff --git a/src/main/resources/generator/server/javatool/base/main/package-types.md.mustache b/src/main/resources/generator/server/javatool/base/main/package-types.md.mustache index bb9ef353ed9..769b29f785a 100644 --- a/src/main/resources/generator/server/javatool/base/main/package-types.md.mustache +++ b/src/main/resources/generator/server/javatool/base/main/package-types.md.mustache @@ -2,14 +2,15 @@ This application comes with two package level annotations: -* `SharedKernel` used to mark packages containing classes shared between multiple contexts; -* `BusinessContext` used to mark packages containing classes to answer a specific business need. Classes in this package can't be used in another package. +- `SharedKernel` used to mark packages containing classes shared between multiple contexts; +- `BusinessContext` used to mark packages containing classes to answer a specific business need. Classes in this package can't be used in another package. To mark a package, you have to add a `package-info.java` file at the package root with: ```java @{{basePackage}}.SharedKernel package {{packageName}}; + ``` or: @@ -17,4 +18,5 @@ or: ```java @{{basePackage}}.BusinessContext package {{packageName}}; + ``` diff --git a/src/main/resources/generator/server/javatool/base/test/collection/ProjectCollectionsTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/collection/ProjectCollectionsTest.java.mustache index 0da0b91a020..efabc9e9806 100644 --- a/src/main/resources/generator/server/javatool/base/test/collection/ProjectCollectionsTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/collection/ProjectCollectionsTest.java.mustache @@ -2,7 +2,6 @@ package {{packageName}}.shared.collection.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -13,6 +12,7 @@ import java.util.Set; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class {{ baseName }}CollectionsTest { diff --git a/src/main/resources/generator/server/javatool/base/test/error/AssertTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/error/AssertTest.java.mustache index 886bd07eed4..807c69c3e18 100644 --- a/src/main/resources/generator/server/javatool/base/test/error/AssertTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/error/AssertTest.java.mustache @@ -2,7 +2,6 @@ package {{packageName}}.shared.error.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import java.math.BigDecimal; import java.time.Instant; import java.util.Arrays; @@ -14,6 +13,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import {{packageName}}.UnitTest; @UnitTest class AssertTest { @@ -1015,7 +1015,9 @@ class AssertTest { @ParameterizedTest @ValueSource(ints = { 3, 4 }) void shouldValidateCollectionWithSizeUnderMaxSize(int maxSize) { - assertThatCode(() -> Assert.field(FIELD_NAME, List.of("value1", "value2", "value3")).maxSize(maxSize)).doesNotThrowAnyException(); + assertThatCode( + () -> Assert.field(FIELD_NAME, new String[] { "value1", "value2", "value3" }).maxSize(maxSize) + ).doesNotThrowAnyException(); } @Test diff --git a/src/main/resources/generator/server/javatool/base/test/error/MissingMandatoryValueExceptionTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/error/MissingMandatoryValueExceptionTest.java.mustache index 59315df8050..d29801c75fb 100644 --- a/src/main/resources/generator/server/javatool/base/test/error/MissingMandatoryValueExceptionTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/error/MissingMandatoryValueExceptionTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.shared.error.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class MissingMandatoryValueExceptionTest { diff --git a/src/main/resources/generator/server/javatool/base/test/error/NotAfterTimeExceptionTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/error/NotAfterTimeExceptionTest.java.mustache index c020d724e04..061b2aebd5a 100644 --- a/src/main/resources/generator/server/javatool/base/test/error/NotAfterTimeExceptionTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/error/NotAfterTimeExceptionTest.java.mustache @@ -2,9 +2,9 @@ package {{packageName}}.shared.error.domain; import static org.assertj.core.api.Assertions.assertThat; -import {{packageName}}.UnitTest; import java.time.Instant; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class NotAfterTimeExceptionTest { @@ -26,8 +26,9 @@ class NotAfterTimeExceptionTest { NotAfterTimeException exception = NotAfterTimeException.strictlyNotAfter().value(VALUE).field(FIELD).other(OTHER); assertDefaultInformation(exception); - assertThat(exception.getMessage()) - .isEqualTo("Time 1970-01-01T00:22:17Z in \"myField\" must be strictly after 2024-02-21T21:00:00Z but wasn't"); + assertThat(exception.getMessage()).isEqualTo( + "Time 1970-01-01T00:22:17Z in \"myField\" must be strictly after 2024-02-21T21:00:00Z but wasn't" + ); } private void assertDefaultInformation(NotAfterTimeException exception) { diff --git a/src/main/resources/generator/server/javatool/base/test/error/NotBeforeTimeExceptionTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/error/NotBeforeTimeExceptionTest.java.mustache index 0416e4ab3e3..48eba56d39f 100644 --- a/src/main/resources/generator/server/javatool/base/test/error/NotBeforeTimeExceptionTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/error/NotBeforeTimeExceptionTest.java.mustache @@ -2,9 +2,9 @@ package {{packageName}}.shared.error.domain; import static org.assertj.core.api.Assertions.assertThat; -import {{packageName}}.UnitTest; import java.time.Instant; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class NotBeforeTimeExceptionTest { @@ -22,15 +22,15 @@ class NotBeforeTimeExceptionTest { @Test void shouldGetNotStrictlyAfterExceptionInformation() { - NotBeforeTimeException exception = NotBeforeTimeException - .strictlyNotBefore() + NotBeforeTimeException exception = NotBeforeTimeException.strictlyNotBefore() .value(VALUE) .field(FIELD) .other(Instant.ofEpochSecond(1337)); assertDefaultInformation(exception); - assertThat(exception.getMessage()) - .isEqualTo("Time 2024-02-21T21:00:00Z in \"myField\" must be strictly before 1970-01-01T00:22:17Z but wasn't"); + assertThat(exception.getMessage()).isEqualTo( + "Time 2024-02-21T21:00:00Z in \"myField\" must be strictly before 1970-01-01T00:22:17Z but wasn't" + ); } private void assertDefaultInformation(NotBeforeTimeException exception) { diff --git a/src/main/resources/generator/server/javatool/base/test/error/NullElementInCollectionExceptionTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/error/NullElementInCollectionExceptionTest.java.mustache index 39555f06aa2..c4e5014136f 100644 --- a/src/main/resources/generator/server/javatool/base/test/error/NullElementInCollectionExceptionTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/error/NullElementInCollectionExceptionTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.shared.error.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class NullElementInCollectionExceptionTest { diff --git a/src/main/resources/generator/server/javatool/base/test/error/NumberValueTooHighExceptionTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/error/NumberValueTooHighExceptionTest.java.mustache index 1e334b834da..dad16ccf3ad 100644 --- a/src/main/resources/generator/server/javatool/base/test/error/NumberValueTooHighExceptionTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/error/NumberValueTooHighExceptionTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.shared.error.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class NumberValueTooHighExceptionTest { diff --git a/src/main/resources/generator/server/javatool/base/test/error/NumberValueTooLowExceptionTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/error/NumberValueTooLowExceptionTest.java.mustache index 0a47984930e..1f37d3f1a7d 100644 --- a/src/main/resources/generator/server/javatool/base/test/error/NumberValueTooLowExceptionTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/error/NumberValueTooLowExceptionTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.shared.error.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class NumberValueTooLowExceptionTest { diff --git a/src/main/resources/generator/server/javatool/base/test/error/StringTooLongExceptionTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/error/StringTooLongExceptionTest.java.mustache index 041268b7b1b..5bf61befd28 100644 --- a/src/main/resources/generator/server/javatool/base/test/error/StringTooLongExceptionTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/error/StringTooLongExceptionTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.shared.error.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class StringTooLongExceptionTest { diff --git a/src/main/resources/generator/server/javatool/base/test/error/StringTooShortExceptionTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/error/StringTooShortExceptionTest.java.mustache index 3f7e030702a..85f53bf41aa 100644 --- a/src/main/resources/generator/server/javatool/base/test/error/StringTooShortExceptionTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/error/StringTooShortExceptionTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.shared.error.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class StringTooShortExceptionTest { diff --git a/src/main/resources/generator/server/javatool/base/test/error/TooManyElementsExceptionTest.java.mustache b/src/main/resources/generator/server/javatool/base/test/error/TooManyElementsExceptionTest.java.mustache index 1a16c3f64bd..def3b42dcbc 100644 --- a/src/main/resources/generator/server/javatool/base/test/error/TooManyElementsExceptionTest.java.mustache +++ b/src/main/resources/generator/server/javatool/base/test/error/TooManyElementsExceptionTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.shared.error.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class TooManyElementsExceptionTest { diff --git a/src/main/resources/generator/server/javatool/checkstyle/main/checkstyle.xml.mustache b/src/main/resources/generator/server/javatool/checkstyle/main/checkstyle.xml.mustache index b56ece2f54a..59e2f013136 100644 --- a/src/main/resources/generator/server/javatool/checkstyle/main/checkstyle.xml.mustache +++ b/src/main/resources/generator/server/javatool/checkstyle/main/checkstyle.xml.mustache @@ -23,26 +23,26 @@ - + - + - - - - - + + + + + - + - + - - - + + + diff --git a/src/main/resources/generator/server/javatool/enums/main/Enums.java.mustache b/src/main/resources/generator/server/javatool/enums/main/Enums.java.mustache index 7995246320a..b499bebcad0 100644 --- a/src/main/resources/generator/server/javatool/enums/main/Enums.java.mustache +++ b/src/main/resources/generator/server/javatool/enums/main/Enums.java.mustache @@ -36,9 +36,9 @@ public final class Enums { private > Function, Map, Enum>> buildCache(Enum from) { return key -> { try { - return Arrays - .stream(key.from().getEnumConstants()) - .collect(Collectors.toMap(Function.identity(), source -> Enum.valueOf(key.to(), source.name()))); + return Arrays.stream(key.from().getEnumConstants()).collect( + Collectors.toMap(Function.identity(), source -> Enum.valueOf(key.to(), source.name())) + ); } catch (IllegalArgumentException e) { throw new UnmappableEnumException(from.getClass(), key.to()); } diff --git a/src/main/resources/generator/server/javatool/protobuf/test/ProtobufDatesReaderTest.java.mustache b/src/main/resources/generator/server/javatool/protobuf/test/ProtobufDatesReaderTest.java.mustache index 0e23547ed64..ce9b7df3c5b 100644 --- a/src/main/resources/generator/server/javatool/protobuf/test/ProtobufDatesReaderTest.java.mustache +++ b/src/main/resources/generator/server/javatool/protobuf/test/ProtobufDatesReaderTest.java.mustache @@ -3,9 +3,9 @@ package {{packageName}}.shared.protobuf.infrastructure.primary; import static org.assertj.core.api.Assertions.*; import com.google.protobuf.util.Timestamps; -import {{packageName}}.UnitTest; import java.util.Date; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class ProtobufDatesReaderTest { diff --git a/src/main/resources/generator/server/javatool/protobuf/test/ProtobufDatesWriterTest.java.mustache b/src/main/resources/generator/server/javatool/protobuf/test/ProtobufDatesWriterTest.java.mustache index 8aee064bb22..242882c5a9f 100644 --- a/src/main/resources/generator/server/javatool/protobuf/test/ProtobufDatesWriterTest.java.mustache +++ b/src/main/resources/generator/server/javatool/protobuf/test/ProtobufDatesWriterTest.java.mustache @@ -3,9 +3,9 @@ package {{packageName}}.shared.protobuf.infrastructure.secondary; import static org.assertj.core.api.Assertions.*; import com.google.protobuf.Timestamp; -import {{packageName}}.UnitTest; import java.time.Instant; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class ProtobufDatesWriterTest { @@ -17,7 +17,8 @@ class ProtobufDatesWriterTest { @Test void shouldBuildTimestampFromInstant() { - assertThat(ProtobufDatesWriter.buildTimestamp(Instant.ofEpochMilli(1337))) - .isEqualTo(Timestamp.newBuilder().setSeconds(1).setNanos(337000000).build()); + assertThat(ProtobufDatesWriter.buildTimestamp(Instant.ofEpochMilli(1337))).isEqualTo( + Timestamp.newBuilder().setSeconds(1).setNanos(337000000).build() + ); } } diff --git a/src/main/resources/generator/server/pagination/domain/main/AppPage.java.mustache b/src/main/resources/generator/server/pagination/domain/main/AppPage.java.mustache index 9fc8de179ed..f25d83cd85b 100644 --- a/src/main/resources/generator/server/pagination/domain/main/AppPage.java.mustache +++ b/src/main/resources/generator/server/pagination/domain/main/AppPage.java.mustache @@ -2,7 +2,6 @@ package {{packageName}}.shared.pagination.domain; import java.util.List; import java.util.function.Function; - import {{packageName}}.shared.collection.domain.{{baseName}}Collections; import {{packageName}}.shared.error.domain.Assert; diff --git a/src/main/resources/generator/server/pagination/domain/main/AppPageable.java.mustache b/src/main/resources/generator/server/pagination/domain/main/AppPageable.java.mustache index 958af2b7c69..1af34487b9e 100644 --- a/src/main/resources/generator/server/pagination/domain/main/AppPageable.java.mustache +++ b/src/main/resources/generator/server/pagination/domain/main/AppPageable.java.mustache @@ -2,9 +2,8 @@ package {{packageName}}.shared.pagination.domain; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; - -import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; import {{packageName}}.shared.error.domain.Assert; +import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; public class {{baseName}}Pageable { diff --git a/src/main/resources/generator/server/pagination/domain/test/AppPageTest.java.mustache b/src/main/resources/generator/server/pagination/domain/test/AppPageTest.java.mustache index 000e3b309d4..68843dfb263 100644 --- a/src/main/resources/generator/server/pagination/domain/test/AppPageTest.java.mustache +++ b/src/main/resources/generator/server/pagination/domain/test/AppPageTest.java.mustache @@ -4,9 +4,7 @@ import static org.assertj.core.api.Assertions.*; import static {{packageName}}.shared.pagination.domain.{{baseName}}PagesFixture.*; import java.util.List; - import org.junit.jupiter.api.Test; - import {{packageName}}.UnitTest; import {{packageName}}.shared.error.domain.MissingMandatoryValueException; diff --git a/src/main/resources/generator/server/pagination/domain/test/AppPageableTest.java.mustache b/src/main/resources/generator/server/pagination/domain/test/AppPageableTest.java.mustache index a754f0c5aa6..b6a476f0348 100644 --- a/src/main/resources/generator/server/pagination/domain/test/AppPageableTest.java.mustache +++ b/src/main/resources/generator/server/pagination/domain/test/AppPageableTest.java.mustache @@ -3,7 +3,6 @@ package {{packageName}}.shared.pagination.domain; import static org.assertj.core.api.Assertions.*; import org.junit.jupiter.api.Test; - import {{packageName}}.UnitTest; import {{packageName}}.shared.error.domain.NumberValueTooHighException; import {{packageName}}.shared.error.domain.NumberValueTooLowException; diff --git a/src/main/resources/generator/server/pagination/domain/test/AppPagesFixture.java.mustache b/src/main/resources/generator/server/pagination/domain/test/AppPagesFixture.java.mustache index 0bf95e1144f..97e0fe69b3f 100644 --- a/src/main/resources/generator/server/pagination/domain/test/AppPagesFixture.java.mustache +++ b/src/main/resources/generator/server/pagination/domain/test/AppPagesFixture.java.mustache @@ -1,7 +1,6 @@ package {{packageName}}.shared.pagination.domain; import java.util.List; - import {{packageName}}.shared.pagination.domain.{{baseName}}Page.{{baseName}}PageBuilder; public final class {{baseName}}PagesFixture { diff --git a/src/main/resources/generator/server/pagination/jpa/jpa-pages.md.mustache b/src/main/resources/generator/server/pagination/jpa/jpa-pages.md.mustache index e138292a650..3808cd0540f 100644 --- a/src/main/resources/generator/server/pagination/jpa/jpa-pages.md.mustache +++ b/src/main/resources/generator/server/pagination/jpa/jpa-pages.md.mustache @@ -1,30 +1,30 @@ # Jpa pages -Let's consider a very common use case to get paginated information from a JPA Spring Repository. In `JpaBeersRepository` we have this method: +Let's consider a very common use case to get paginated information from a JPA Spring Repository. In `JpaBeersRepository` we have this method: ```java Page findAll(Pageable pagination); + ``` -We can call that this way: +We can call that this way: ```java private final JpaBeersRepository beers; // ... -public {{baseName}}Page list({{baseName}}Pageable pagination) { - return {{baseName}}Pages.from( - beers.findAll({{baseName}}Pages.from(pagination, Sort.by(Sort.Direction.ASC, "name"))), - BeerEntity::toDomain - ); +public FullappPage list(FullappPageable pagination) { + return FullappPages.from(beers.findAll(FullappPages.from(pagination, Sort.by(Sort.Direction.ASC, "name"))), BeerEntity::toDomain); } + ``` -And we'll need a mapping method in `BeerEntity`: +And we'll need a mapping method in `BeerEntity`: ```java Beer toDomain() { // ... } -``` \ No newline at end of file + +``` diff --git a/src/main/resources/generator/server/pagination/jpa/main/AppPages.java.mustache b/src/main/resources/generator/server/pagination/jpa/main/AppPages.java.mustache index 559ce48a9f0..ddb19cc87c7 100644 --- a/src/main/resources/generator/server/pagination/jpa/main/AppPages.java.mustache +++ b/src/main/resources/generator/server/pagination/jpa/main/AppPages.java.mustache @@ -1,12 +1,10 @@ package {{packageName}}.shared.pagination.infrastructure.secondary; import java.util.function.Function; - import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; - import {{packageName}}.shared.error.domain.Assert; import {{packageName}}.shared.pagination.domain.{{baseName}}Page; import {{packageName}}.shared.pagination.domain.{{baseName}}Pageable; @@ -30,8 +28,7 @@ public final class {{baseName}}Pages { Assert.notNull("springPage", springPage); Assert.notNull("mapper", mapper); - return {{baseName}}Page - .builder(springPage.getContent().stream().map(mapper).toList()) + return {{baseName}}Page.builder(springPage.getContent().stream().map(mapper).toList()) .currentPage(springPage.getNumber()) .pageSize(springPage.getSize()) .totalElementsCount(springPage.getTotalElements()) diff --git a/src/main/resources/generator/server/pagination/jpa/test/AppPagesTest.java.mustache b/src/main/resources/generator/server/pagination/jpa/test/AppPagesTest.java.mustache index e5e1bb35bb9..e0d5e398a79 100644 --- a/src/main/resources/generator/server/pagination/jpa/test/AppPagesTest.java.mustache +++ b/src/main/resources/generator/server/pagination/jpa/test/AppPagesTest.java.mustache @@ -4,13 +4,11 @@ import static org.assertj.core.api.Assertions.*; import java.util.List; import java.util.function.Function; - import org.junit.jupiter.api.Test; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; - import {{packageName}}.UnitTest; import {{packageName}}.shared.error.domain.MissingMandatoryValueException; import {{packageName}}.shared.pagination.domain.{{baseName}}Page; diff --git a/src/main/resources/generator/server/pagination/rest/main/RestAppPage.java.mustache b/src/main/resources/generator/server/pagination/rest/main/RestAppPage.java.mustache index 84ae820c8b0..72a425983d4 100644 --- a/src/main/resources/generator/server/pagination/rest/main/RestAppPage.java.mustache +++ b/src/main/resources/generator/server/pagination/rest/main/RestAppPage.java.mustache @@ -1,14 +1,12 @@ package {{packageName}}.shared.pagination.infrastructure.primary; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; import java.util.List; import java.util.function.Function; - import {{packageName}}.shared.error.domain.Assert; import {{packageName}}.shared.pagination.domain.{{baseName}}Page; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; - @Schema(name = "Page", description = "Paginated content") public final class Rest{{baseName}}Page { diff --git a/src/main/resources/generator/server/pagination/rest/main/RestAppPageable.java.mustache b/src/main/resources/generator/server/pagination/rest/main/RestAppPageable.java.mustache index c1f6b5f7883..a0f4ea54499 100644 --- a/src/main/resources/generator/server/pagination/rest/main/RestAppPageable.java.mustache +++ b/src/main/resources/generator/server/pagination/rest/main/RestAppPageable.java.mustache @@ -1,9 +1,8 @@ package {{packageName}}.shared.pagination.infrastructure.primary; +import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; - -import io.swagger.v3.oas.annotations.media.Schema; import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; import {{packageName}}.shared.pagination.domain.{{baseName}}Pageable; diff --git a/src/main/resources/generator/server/pagination/rest/rest-pagination.md.mustache b/src/main/resources/generator/server/pagination/rest/rest-pagination.md.mustache index ec87fedbe20..13a4944bd76 100644 --- a/src/main/resources/generator/server/pagination/rest/rest-pagination.md.mustache +++ b/src/main/resources/generator/server/pagination/rest/rest-pagination.md.mustache @@ -6,6 +6,7 @@ Let's consider a very common use case to get paginated information. In `BeersApp public {{baseName}}Page list({{baseName}}Pageable pagination) { // ... } + ``` To call that and expose a result using a rest service, we can do something like that: @@ -18,6 +19,7 @@ private final BeersApplicationService beers; ResponseEntity> list(@Validated Rest{{baseName}}Pageable pagination) { return ResponseEntity.ok(Rest{{baseName}}Page.from(beers.list(pagination.toPageable()), RestBeer::from)); } + ``` And we'll need a mapping method in `RestBeer`: @@ -26,4 +28,5 @@ And we'll need a mapping method in `RestBeer`: static RestBeer from(Beer beer) { // ... } + ``` diff --git a/src/main/resources/generator/server/pagination/rest/test/RestAppPageTest.java.mustache b/src/main/resources/generator/server/pagination/rest/test/RestAppPageTest.java.mustache index 7b63c7cf0cc..9f8fef3de44 100644 --- a/src/main/resources/generator/server/pagination/rest/test/RestAppPageTest.java.mustache +++ b/src/main/resources/generator/server/pagination/rest/test/RestAppPageTest.java.mustache @@ -4,11 +4,9 @@ import static org.assertj.core.api.Assertions.*; import static {{packageName}}.shared.pagination.domain.{{baseName}}PagesFixture.*; import java.util.function.Function; - import org.junit.jupiter.api.Test; - -import {{packageName}}.UnitTest; import {{packageName}}.JsonHelper; +import {{packageName}}.UnitTest; import {{packageName}}.shared.error.domain.MissingMandatoryValueException; @UnitTest diff --git a/src/main/resources/generator/server/pagination/rest/test/RestAppPageableTest.java.mustache b/src/main/resources/generator/server/pagination/rest/test/RestAppPageableTest.java.mustache index 86d1a5ee61b..a5602684db9 100644 --- a/src/main/resources/generator/server/pagination/rest/test/RestAppPageableTest.java.mustache +++ b/src/main/resources/generator/server/pagination/rest/test/RestAppPageableTest.java.mustache @@ -1,10 +1,9 @@ package {{packageName}}.shared.pagination.infrastructure.primary; -import static {{packageName}}.BeanValidationAssertions.*; import static org.assertj.core.api.Assertions.*; +import static {{packageName}}.BeanValidationAssertions.*; import org.junit.jupiter.api.Test; - import {{packageName}}.UnitTest; import {{packageName}}.shared.pagination.domain.{{baseName}}Pageable; diff --git a/src/main/resources/generator/server/springboot/apidocumentation/springdocjwt/SpringdocJWTConfiguration.java.mustache b/src/main/resources/generator/server/springboot/apidocumentation/springdocjwt/SpringdocJWTConfiguration.java.mustache index 3a4990f9ce0..5db8646efae 100644 --- a/src/main/resources/generator/server/springboot/apidocumentation/springdocjwt/SpringdocJWTConfiguration.java.mustache +++ b/src/main/resources/generator/server/springboot/apidocumentation/springdocjwt/SpringdocJWTConfiguration.java.mustache @@ -7,7 +7,6 @@ import org.springdoc.core.customizers.GlobalOpenApiCustomizer; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; - import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; @Configuration diff --git a/src/main/resources/generator/server/springboot/cache/caffeine/caffeine.md.mustache b/src/main/resources/generator/server/springboot/cache/caffeine/caffeine.md.mustache index 7b65119bbce..c671193c71f 100644 --- a/src/main/resources/generator/server/springboot/cache/caffeine/caffeine.md.mustache +++ b/src/main/resources/generator/server/springboot/cache/caffeine/caffeine.md.mustache @@ -10,6 +10,7 @@ package {{packageName}}.user.domain; public interface UsersRepository { Users list(Group group); } + ``` Allowing us to list users in a given group. To implement this, we'll make a call to our IDP: @@ -31,6 +32,7 @@ class MyApplicationUsersRepository implements UsersRepository { return users.list(group); } } + ``` But, we'll soon find that calling this has a cost and that the users in groups are not updated that often so we want to configure a simple local cache: @@ -38,15 +40,13 @@ But, we'll soon find that calling this has a cost and that the users in groups a ```java package {{packageName}}.user.infrastructure.secondary; +import com.github.benmanes.caffeine.cache.Caffeine; import java.util.concurrent.TimeUnit; - import org.springframework.cache.CacheManager; import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.github.benmanes.caffeine.cache.Caffeine; - @Configuration class UsersCacheConfiguration { @@ -59,6 +59,7 @@ class UsersCacheConfiguration { return manager; } } + ``` And update our repository to cache users: @@ -74,11 +75,12 @@ class MyApplicationUsersRepository implements UsersRepository { //... @Override - @Cacheable(cacheNames = "users-cache") + @Cacheable(cacheNames = "users-cache") public Users list(Group group) { //... } } + ``` That's it, we now have a 5mn cache for our users. diff --git a/src/main/resources/generator/server/springboot/cache/ehcache/main/JavaCacheConfiguration.java.mustache b/src/main/resources/generator/server/springboot/cache/ehcache/main/JavaCacheConfiguration.java.mustache index 62337491703..b2baff1211c 100644 --- a/src/main/resources/generator/server/springboot/cache/ehcache/main/JavaCacheConfiguration.java.mustache +++ b/src/main/resources/generator/server/springboot/cache/ehcache/main/JavaCacheConfiguration.java.mustache @@ -18,13 +18,15 @@ class CacheConfiguration { private final javax.cache.configuration.Configuration configuration; public CacheConfiguration(EhcacheProperties properties) { - this.configuration = - Eh107Configuration.fromEhcacheCacheConfiguration( - CacheConfigurationBuilder - .newCacheConfigurationBuilder(Object.class, Object.class, ResourcePoolsBuilder.heap(properties.getMaxEntries())) - .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(properties.getTimeToLiveSeconds()))) - .build() - ); + this.configuration = Eh107Configuration.fromEhcacheCacheConfiguration( + CacheConfigurationBuilder.newCacheConfigurationBuilder( + Object.class, + Object.class, + ResourcePoolsBuilder.heap(properties.getMaxEntries()) + ) + .withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(properties.getTimeToLiveSeconds()))) + .build() + ); } @Bean diff --git a/src/main/resources/generator/server/springboot/core/main/ApplicationStartupTraces.java.mustache b/src/main/resources/generator/server/springboot/core/main/ApplicationStartupTraces.java.mustache index 837f9c86a7f..273a3821a0e 100644 --- a/src/main/resources/generator/server/springboot/core/main/ApplicationStartupTraces.java.mustache +++ b/src/main/resources/generator/server/springboot/core/main/ApplicationStartupTraces.java.mustache @@ -9,8 +9,8 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; -import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; import {{packageName}}.shared.error.domain.Assert; +import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; final class ApplicationStartupTraces { diff --git a/src/main/resources/generator/server/springboot/cucumber/CucumberConfiguration.java.mustache b/src/main/resources/generator/server/springboot/cucumber/CucumberConfiguration.java.mustache index 232a10934d9..904e74d8e0a 100644 --- a/src/main/resources/generator/server/springboot/cucumber/CucumberConfiguration.java.mustache +++ b/src/main/resources/generator/server/springboot/cucumber/CucumberConfiguration.java.mustache @@ -15,8 +15,8 @@ import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.web.client.RestTemplate; import org.springframework.test.context.ActiveProfiles; +import org.springframework.web.client.RestTemplate; import {{packageName}}.{{ baseName }}App; import {{packageName}}.cucumber.CucumberConfiguration.CucumberRestTemplateConfiguration; import {{packageName}}.cucumber.rest.CucumberRestTemplate; diff --git a/src/main/resources/generator/server/springboot/cucumber/cucumber.md.mustache b/src/main/resources/generator/server/springboot/cucumber/cucumber.md.mustache index b09ad0ca376..c206be2f39e 100644 --- a/src/main/resources/generator/server/springboot/cucumber/cucumber.md.mustache +++ b/src/main/resources/generator/server/springboot/cucumber/cucumber.md.mustache @@ -17,13 +17,14 @@ You'll then have to define the glue code: ```java import static {{packageName}}.cucumber.rest.CucumberRestAssertions.*; -import {{packageName}}.cucumber.CucumberRestTemplate; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.web.client.TestRestTemplate; +import {{packageName}}.cucumber.CucumberRestTemplate; public class SimpleSteps { + @Autowired private CucumberRestTemplate rest; @@ -43,6 +44,7 @@ public class SimpleSteps { .withValue(age); } } + ``` Use a `TestRestTemplate` to make your rest calls, so you'll have the `context` management: the stuff allowing easier assertions in the `Then` steps. @@ -79,6 +81,7 @@ public void shouldGetResponseContent(Map response) { public void shouldGetResponseContent(List> responses) { assertThatLastResponse().hasElement("$.users").containingExactly(responses); } + ``` ## Reading responses content @@ -114,7 +117,10 @@ You may need to mock beans for your component tests, but you won't be able to do ```java @ActiveProfiles("test") @CucumberContextConfiguration -@SpringBootTest(classes = { JhipsterSampleApplicationApp.class, CucumberMocksConfiguration.class }, webEnvironment = WebEnvironment.RANDOM_PORT) +@SpringBootTest( + classes = { JhipsterSampleApplicationApp.class, CucumberMocksConfiguration.class }, + webEnvironment = WebEnvironment.RANDOM_PORT +) public class CucumberConfiguration { // other code omitted @@ -129,6 +135,7 @@ public class CucumberConfiguration { } } } + ``` **Careful: the mock bean names (by default the method name) must be different from the real one or else they may just be ignored** diff --git a/src/main/resources/generator/server/springboot/cucumber/rest/Awaiter.java.mustache b/src/main/resources/generator/server/springboot/cucumber/rest/Awaiter.java.mustache index 56a177d97c8..2b7ccf045d0 100644 --- a/src/main/resources/generator/server/springboot/cucumber/rest/Awaiter.java.mustache +++ b/src/main/resources/generator/server/springboot/cucumber/rest/Awaiter.java.mustache @@ -10,16 +10,15 @@ final class Awaiter { private Awaiter() {} static void await(Duration maxTime, ThrowingRunnable assertion) { - awaiter(maxTime) - .untilAsserted(() -> { - try { - assertion.run(); - } catch (AssertionError e) { - CucumberRestTestContext.retry(); + awaiter(maxTime).untilAsserted(() -> { + try { + assertion.run(); + } catch (AssertionError e) { + CucumberRestTestContext.retry(); - assertion.run(); - } - }); + assertion.run(); + } + }); } private static ConditionFactory awaiter(Duration maxTime) { diff --git a/src/main/resources/generator/server/springboot/cucumber/rest/CucumberJson.java.mustache b/src/main/resources/generator/server/springboot/cucumber/rest/CucumberJson.java.mustache index 4bc49223af6..3c1d9036ee1 100644 --- a/src/main/resources/generator/server/springboot/cucumber/rest/CucumberJson.java.mustache +++ b/src/main/resources/generator/server/springboot/cucumber/rest/CucumberJson.java.mustache @@ -19,8 +19,7 @@ final class CucumberJson { private CucumberJson() {} public static ObjectMapper jsonMapper() { - return JsonMapper - .builder() + return JsonMapper.builder() .serializationInclusion(JsonInclude.Include.NON_NULL) .addModule(new JavaTimeModule()) .addModules(new Jdk8Module()) diff --git a/src/main/resources/generator/server/springboot/cucumber/rest/CucumberRestAssertions.java.mustache b/src/main/resources/generator/server/springboot/cucumber/rest/CucumberRestAssertions.java.mustache index 7077ccea2f2..0b754474a5b 100644 --- a/src/main/resources/generator/server/springboot/cucumber/rest/CucumberRestAssertions.java.mustache +++ b/src/main/resources/generator/server/springboot/cucumber/rest/CucumberRestAssertions.java.mustache @@ -38,12 +38,13 @@ public final class CucumberRestAssertions { assertThat(statuses).as("Can't check statuses without statuses").isNotEmpty(); assertThat(CucumberRestTestContext.getStatus()) - .as(() -> - "Expecting request to result in any of " + - Stream.of(statuses).map(HttpStatus::toString).collect(Collectors.joining(", ")) + - " but got " + - CucumberRestTestContext.getStatus() + - callContext() + .as( + () -> + "Expecting request to result in any of " + + Stream.of(statuses).map(HttpStatus::toString).collect(Collectors.joining(", ")) + + " but got " + + CucumberRestTestContext.getStatus() + + callContext() ) .isIn((Object[]) statuses); } diff --git a/src/main/resources/generator/server/springboot/cucumber/rest/CucumberRestTestContextUnitTest.java.mustache b/src/main/resources/generator/server/springboot/cucumber/rest/CucumberRestTestContextUnitTest.java.mustache index 544e549c517..d55381139e5 100644 --- a/src/main/resources/generator/server/springboot/cucumber/rest/CucumberRestTestContextUnitTest.java.mustache +++ b/src/main/resources/generator/server/springboot/cucumber/rest/CucumberRestTestContextUnitTest.java.mustache @@ -96,10 +96,9 @@ class CucumberRestTestContextUnitTest { fail(e.getMessage()); } - assertThatThrownBy(() -> - CucumberRestTestContext.addResponse(mockedRequest("/"), httpResponse, mock(ClientHttpRequestExecution.class), "body".getBytes()) - ) - .isExactlyInstanceOf(AssertionError.class); + assertThatThrownBy( + () -> CucumberRestTestContext.addResponse(mockedRequest("/"), httpResponse, mock(ClientHttpRequestExecution.class), "body".getBytes()) + ).isExactlyInstanceOf(AssertionError.class); } @Test diff --git a/src/main/resources/generator/server/springboot/cucumberauthentication/jwt/AuthenticationSteps.java.mustache b/src/main/resources/generator/server/springboot/cucumberauthentication/jwt/AuthenticationSteps.java.mustache index 74022927c97..810fd9e350b 100644 --- a/src/main/resources/generator/server/springboot/cucumberauthentication/jwt/AuthenticationSteps.java.mustache +++ b/src/main/resources/generator/server/springboot/cucumberauthentication/jwt/AuthenticationSteps.java.mustache @@ -2,7 +2,6 @@ package {{packageName}}.shared.authentication.infrastructure.primary; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.shared.authentication.domain.Role; import io.cucumber.java.en.Given; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.security.Keys; @@ -20,6 +19,7 @@ import javax.crypto.SecretKey; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpHeaders; import org.springframework.http.client.ClientHttpRequestInterceptor; +import {{packageName}}.shared.authentication.domain.Role; public class AuthenticationSteps { @@ -111,8 +111,7 @@ public class AuthenticationSteps { @SuppressWarnings("java:S1144") private String token() { - return Jwts - .builder() + return Jwts.builder() .subject(username) .signWith(key) .claim("auth", authorities) diff --git a/src/main/resources/generator/server/springboot/dbmigration/liquibase/main/LiquibaseConfiguration.java.mustache b/src/main/resources/generator/server/springboot/dbmigration/liquibase/main/LiquibaseConfiguration.java.mustache index bddaa1232da..5678f027d63 100644 --- a/src/main/resources/generator/server/springboot/dbmigration/liquibase/main/LiquibaseConfiguration.java.mustache +++ b/src/main/resources/generator/server/springboot/dbmigration/liquibase/main/LiquibaseConfiguration.java.mustache @@ -45,24 +45,22 @@ class LiquibaseConfiguration { SpringLiquibase liquibase; if (async) { log.debug("Configuring Liquibase with async"); - liquibase = - SpringLiquibaseUtil.createAsyncSpringLiquibase( - this.env, - executor, - liquibaseDataSource.getIfAvailable(), - liquibaseProperties, - dataSource.getIfUnique(), - dataSourceProperties - ); + liquibase = SpringLiquibaseUtil.createAsyncSpringLiquibase( + this.env, + executor, + liquibaseDataSource.getIfAvailable(), + liquibaseProperties, + dataSource.getIfUnique(), + dataSourceProperties + ); } else { log.debug("Configuring Liquibase with sync"); - liquibase = - SpringLiquibaseUtil.createSpringLiquibase( - liquibaseDataSource.getIfAvailable(), - liquibaseProperties, - dataSource.getIfUnique(), - dataSourceProperties - ); + liquibase = SpringLiquibaseUtil.createSpringLiquibase( + liquibaseDataSource.getIfAvailable(), + liquibaseProperties, + dataSource.getIfUnique(), + dataSourceProperties + ); } liquibase.setChangeLog(changeLogClassPath); liquibase.setContexts(liquibaseProperties.getContexts()); diff --git a/src/main/resources/generator/server/springboot/dbmigration/liquibase/test/SpringLiquibaseUtilTest.java.mustache b/src/main/resources/generator/server/springboot/dbmigration/liquibase/test/SpringLiquibaseUtilTest.java.mustache index 6b702b14b0b..754457ee289 100644 --- a/src/main/resources/generator/server/springboot/dbmigration/liquibase/test/SpringLiquibaseUtilTest.java.mustache +++ b/src/main/resources/generator/server/springboot/dbmigration/liquibase/test/SpringLiquibaseUtilTest.java.mustache @@ -13,7 +13,6 @@ import org.springframework.core.io.PathResource; import java.io.IOException; {{/propertiesSpringConfigurationFormat}} import java.util.Properties; - import com.zaxxer.hikari.HikariDataSource; import javax.sql.DataSource; import liquibase.integration.spring.SpringLiquibase; @@ -188,7 +187,8 @@ class SpringLiquibaseUtilTest { DataSourceProperties dataSourceProperties = new DataSourceProperties(); dataSourceProperties.setPassword("password"); - assertThatThrownBy(() -> + assertThatThrownBy( + () -> SpringLiquibaseUtil.createAsyncSpringLiquibase( null, null, @@ -197,8 +197,7 @@ class SpringLiquibaseUtilTest { normalDataSource, dataSourceProperties ) - ) - .isExactlyInstanceOf(NullPointerException.class); + ).isExactlyInstanceOf(NullPointerException.class); } @Test @@ -211,7 +210,8 @@ class SpringLiquibaseUtilTest { DataSourceProperties dataSourceProperties = new DataSourceProperties(); dataSourceProperties.setPassword("password"); - assertThatThrownBy(() -> + assertThatThrownBy( + () -> SpringLiquibaseUtil.createAsyncSpringLiquibase( null, null, @@ -220,16 +220,15 @@ class SpringLiquibaseUtilTest { normalDataSource, dataSourceProperties ) - ) - .isExactlyInstanceOf(NullPointerException.class); + ).isExactlyInstanceOf(NullPointerException.class); } private static Properties testProperties() { try { {{#yamlSpringConfigurationFormat}} YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean(); - yaml.setResources(new PathResource( - SpringLiquibaseUtilTest.class.getClassLoader().getResource("config/application-test.yml").toURI()) + yaml.setResources( + new PathResource(SpringLiquibaseUtilTest.class.getClassLoader().getResource("config/application-test.yml").toURI()) ); return yaml.getObject(); } catch (URISyntaxException exception) { diff --git a/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpConfigurationTest.java.mustache b/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpConfigurationTest.java.mustache index c06fe2cbb9d..7b521ef8d7d 100644 --- a/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpConfigurationTest.java.mustache +++ b/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpConfigurationTest.java.mustache @@ -2,7 +2,6 @@ package {{packageName}}.wire.logstash.infrastructure.secondary; import static org.assertj.core.api.Assertions.assertThat; -import {{packageName}}.UnitTest; import java.io.IOException; import java.util.Map; import org.junit.jupiter.api.Test; @@ -10,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.json.JsonTest; import org.springframework.boot.test.json.JacksonTester; import org.springframework.boot.test.json.ObjectContent; +import {{packageName}}.UnitTest; @UnitTest @JsonTest diff --git a/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpLifeCycleTest.java.mustache b/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpLifeCycleTest.java.mustache index 4622b097bcc..f5f55b55168 100644 --- a/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpLifeCycleTest.java.mustache +++ b/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpLifeCycleTest.java.mustache @@ -1,13 +1,12 @@ package {{packageName}}.wire.logstash.infrastructure.secondary; -import static {{packageName}}.wire.logstash.infrastructure.secondary.LogstashTcpLifeCycle.ASYNC_LOGSTASH_APPENDER_NAME; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static {{packageName}}.wire.logstash.infrastructure.secondary.LogstashTcpLifeCycle.ASYNC_LOGSTASH_APPENDER_NAME; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.pattern.ThrowableHandlingConverter; import com.fasterxml.jackson.databind.ObjectMapper; -import {{packageName}}.UnitTest; import java.io.IOException; import java.net.InetSocketAddress; import java.time.Duration; @@ -23,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.json.JsonTest; import org.springframework.boot.test.json.JacksonTester; import org.springframework.boot.test.json.ObjectContent; +import {{packageName}}.UnitTest; @UnitTest @JsonTest diff --git a/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpPropertiesTest.java.mustache b/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpPropertiesTest.java.mustache index 0e88c20fad2..f653b59b098 100644 --- a/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpPropertiesTest.java.mustache +++ b/src/main/resources/generator/server/springboot/logging/logstash/test/LogstashTcpPropertiesTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.wire.logstash.infrastructure.secondary; import static org.assertj.core.api.Assertions.assertThat; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class LogstashTcpPropertiesTest { diff --git a/src/main/resources/generator/server/springboot/logsspy/test/LogsSpyExtension.java.mustache b/src/main/resources/generator/server/springboot/logsspy/test/LogsSpyExtension.java.mustache index cb6a578ccde..6ab487c9ddc 100644 --- a/src/main/resources/generator/server/springboot/logsspy/test/LogsSpyExtension.java.mustache +++ b/src/main/resources/generator/server/springboot/logsspy/test/LogsSpyExtension.java.mustache @@ -55,14 +55,13 @@ public final class LogsSpyExtension private void injectFields(Class testClass, Object testInstance, Predicate predicate) { predicate = predicate.and(field -> LogsSpy.class.isAssignableFrom(field.getType())); - findAnnotatedFields(testClass, Logs.class, predicate) - .forEach(field -> { - try { - field.setAccessible(true); - field.set(testInstance, logsSpy); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - }); + findAnnotatedFields(testClass, Logs.class, predicate).forEach(field -> { + try { + field.setAccessible(true); + field.set(testInstance, logsSpy); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + }); } } diff --git a/src/main/resources/generator/server/springboot/mvc/frontend/RedirectionResource.java.mustache b/src/main/resources/generator/server/springboot/mvc/frontend/RedirectionResource.java.mustache index 2b47c0803f5..714a966843a 100644 --- a/src/main/resources/generator/server/springboot/mvc/frontend/RedirectionResource.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/frontend/RedirectionResource.java.mustache @@ -3,7 +3,6 @@ package {{packageName}}.wire.frontend.infrastructure.primary; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; - import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; @Controller diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/documentation/application-errors.md.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/documentation/application-errors.md.mustache index 0e270b24814..2eb8e98152d 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/documentation/application-errors.md.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/documentation/application-errors.md.mustache @@ -37,11 +37,11 @@ enum FilesErrorKey implements ErrorKey { And updates to all messages files in `src/main/resources/messages/errors` to add: -* `error.unknown-file-to-delete.title`: With error title following [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807) title -* `error.unknown-file-to-delete.detail`: With error detail following [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807) title. Here you can use mustaches ({{ and }}) with parameters in your exception (here {{ file }}) +- `error.unknown-file-to-delete.title`: With error title following [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807) title +- `error.unknown-file-to-delete.detail`: With error detail following [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807) title. Here you can use mustaches ({{ and }}) with parameters in your exception (here {{ file }}) This may sound like a lot of work but that way you'll: -* Have really clear stack traces whenever a problem occurs; -* Never have a missing translation (this is tested); -* Won't have to sync client <-> server deployment since client just have to display a message sent by the server. +- Have really clear stack traces whenever a problem occurs; +- Never have a missing translation (this is tested); +- Won't have to sync client <-> server deployment since client just have to display a message sent by the server. diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ApplicationException.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ApplicationException.java.mustache index 20fa04baa17..85c1c98556b 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ApplicationException.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ApplicationException.java.mustache @@ -46,8 +46,7 @@ public class {{ baseName }}Exception extends RuntimeException { } private ErrorStatus defaultStatus() { - return Stream - .of(Thread.currentThread().getStackTrace()) + return Stream.of(Thread.currentThread().getStackTrace()) .map(StackTraceElement::getClassName) .filter(inProject()) .filter(notCurrentException()) diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/AssertionErrorsHandler.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/AssertionErrorsHandler.java.mustache index c935c56d602..f6894ae0bce 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/AssertionErrorsHandler.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/AssertionErrorsHandler.java.mustache @@ -48,8 +48,7 @@ class AssertionErrorsHandler { } private HttpStatus buildStatus(AssertionException exception) { - return Stream - .of(exception.getStackTrace()) + return Stream.of(exception.getStackTrace()) .map(StackTraceElement::getClassName) .filter(inApplication()) .filter(notInErrorDomain()) diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ErrorStatus.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ErrorStatus.java.mustache index 2c6883a19d8..7f33203930c 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ErrorStatus.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/main/ErrorStatus.java.mustache @@ -12,5 +12,5 @@ public enum ErrorStatus { GONE, I_AM_A_TEAPOT, INTERNAL_SERVER_ERROR, - NOT_IMPLEMENTED + NOT_IMPLEMENTED, } diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsHandlerTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsHandlerTest.java.mustache index a82c3ff3055..85d8b905ed6 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsHandlerTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsHandlerTest.java.mustache @@ -24,9 +24,7 @@ class {{ baseName }}ErrorsHandlerTest { @Test void shouldLogServerErrorAsError() { - handler.handle{{ baseName }}Exception( - {{ baseName }}Exception.internalServerError(StandardErrorKey.INTERNAL_SERVER_ERROR).message("Oops").build() - ); + handler.handleFullappException(FullappException.internalServerError(StandardErrorKey.INTERNAL_SERVER_ERROR).message("Oops").build()); logs.shouldHave(Level.ERROR, "Oops"); } diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsMessagesTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsMessagesTest.java.mustache index 5de90fd0fed..1bc67152383 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsMessagesTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationErrorsMessagesTest.java.mustache @@ -32,16 +32,15 @@ class {{ baseName }}ErrorsMessagesTest { .setUrls(ClasspathHelper.forPackage(BASE_PACKAGE)) .setScanners(Scanners.SubTypes) .filterInputsBy(new FilterBuilder().includePackage(BASE_PACKAGE)) - ) - .getSubTypesOf(ErrorKey.class); + ).getSubTypesOf(ErrorKey.class); private static final Map ALL_ASSERTION_MESSAGES = loadMessages(); private static Map loadMessages() { try { - return Files - .list(Paths.get("src/main/resources/messages/errors")) - .collect(Collectors.toUnmodifiableMap(Path::toString, toProperties())); + return Files.list(Paths.get("src/main/resources/messages/errors")).collect( + Collectors.toUnmodifiableMap(Path::toString, toProperties()) + ); } catch (IOException e) { throw new AssertionError(); } @@ -62,20 +61,21 @@ class {{ baseName }}ErrorsMessagesTest { @Test void shouldHaveOnlyEnumImplementations() { - ERRORS.forEach(error -> - assertThat(error.isEnum() || error.isInterface()) - .as("Implementations of " + ErrorKey.class.getName() + " must be enums and " + error.getName() + " wasn't") - .isTrue() + ERRORS.forEach( + error -> + assertThat(error.isEnum() || error.isInterface()) + .as("Implementations of " + ErrorKey.class.getName() + " must be enums and " + error.getName() + " wasn't") + .isTrue() ); } @Test - void shouldHave{{ baseName }}ErrorTitleInAllSupportedLanguages() { + void shouldHaveFullappErrorTitleInAllSupportedLanguages() { errorKeys().map(error -> "error." + error.get() + ".title").forEach(assertHasMessage()); } @Test - void shouldHave{{ baseName }}ErrorDetailInAllSupportedLanguages() { + void shouldHaveFullappErrorDetailInAllSupportedLanguages() { errorKeys().map(error -> "error." + error.get() + ".detail").forEach(assertHasMessage()); } @@ -85,8 +85,9 @@ class {{ baseName }}ErrorsMessagesTest { private Consumer assertHasMessage() { return messageKey -> - ALL_ASSERTION_MESSAGES.forEach((file, localeMessages) -> - assertThat(localeMessages).as(() -> "Missing " + messageKey + " translation in " + file).containsKey(messageKey) + ALL_ASSERTION_MESSAGES.forEach( + (file, localeMessages) -> + assertThat(localeMessages).as(() -> "Missing " + messageKey + " translation in " + file).containsKey(messageKey) ); } } diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationExceptionTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationExceptionTest.java.mustache index 3d455505102..96ce3b3087c 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationExceptionTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ApplicationExceptionTest.java.mustache @@ -35,8 +35,7 @@ class {{ baseName }}ExceptionTest { @Test void shouldGetFull{{ baseName }}Exception() { RuntimeException cause = new RuntimeException(); - {{ baseName }}Exception exception = {{ baseName }}Exception - .builder(StandardErrorKey.BAD_REQUEST) + {{ baseName }}Exception exception = {{ baseName }}Exception.builder(StandardErrorKey.BAD_REQUEST) .message("This is an error") .cause(cause) .addParameter("parameter", "value") diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ArgumentsReplacerTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ArgumentsReplacerTest.java.mustache index 4395c4de4c5..3d4cbd89294 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ArgumentsReplacerTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ArgumentsReplacerTest.java.mustache @@ -22,8 +22,9 @@ class ArgumentsReplacerTest { @Test void shouldReplaceKnownArguments() { - assertThat(ArgumentsReplacer.replaceParameters("Hey {{ user }}, how's {{ friend }} doing? Say {{user}}", Map.of("user", "Joe"))) - .isEqualTo("Hey Joe, how's {{ friend }} doing? Say Joe"); + assertThat( + ArgumentsReplacer.replaceParameters("Hey {{ user }}, how's {{ friend }} doing? Say {{ user }}", Map.of("user", "Joe")) + ).isEqualTo("Hey Joe, how's {{ friend }} doing? Say Joe"); } @Test @@ -32,7 +33,8 @@ class ArgumentsReplacerTest { arguments.put("number", 42); arguments.put("null", null); - assertThat(ArgumentsReplacer.replaceParameters("Hey {{ number }}, how's {{ null }} doing?", arguments)) - .isEqualTo("Hey 42, how's {{ null }} doing?"); + assertThat(ArgumentsReplacer.replaceParameters("Hey {{ number }}, how's {{ null }} doing?", arguments)).isEqualTo( + "Hey 42, how's {{ null }} doing?" + ); } } diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorMessagesTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorMessagesTest.java.mustache index 427cc698ee2..41d86b182ad 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorMessagesTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorMessagesTest.java.mustache @@ -23,9 +23,9 @@ class AssertionErrorMessagesTest { private static Map loadMessages() { try { - return Files - .list(Paths.get("src/main/resources/messages/assertions-errors")) - .collect(Collectors.toUnmodifiableMap(Path::toString, toProperties())); + return Files.list(Paths.get("src/main/resources/messages/assertions-errors")).collect( + Collectors.toUnmodifiableMap(Path::toString, toProperties()) + ); } catch (IOException e) { throw new AssertionError(); } @@ -46,24 +46,23 @@ class AssertionErrorMessagesTest { @Test void shouldHaveAssertionErrorTitleInAllSupportedLanguages() { - Stream - .of(AssertionErrorType.values()) + Stream.of(AssertionErrorType.values()) .map(assertionError -> "assertion-error." + assertionError.name() + ".title") .forEach(assertHasMessage()); } @Test void shouldHaveAssertionErrorDetailInAllSupportedLanguages() { - Stream - .of(AssertionErrorType.values()) + Stream.of(AssertionErrorType.values()) .map(assertionError -> "assertion-error." + assertionError.name() + ".detail") .forEach(assertHasMessage()); } private Consumer assertHasMessage() { return messageKey -> - ALL_ASSERTION_MESSAGES.forEach((file, localeMessages) -> - assertThat(localeMessages).as(() -> "Missing " + messageKey + " translation in " + file).containsKey(messageKey) + ALL_ASSERTION_MESSAGES.forEach( + (file, localeMessages) -> + assertThat(localeMessages).as(() -> "Missing " + messageKey + " translation in " + file).containsKey(messageKey) ); } } diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorsHandlerTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorsHandlerTest.java.mustache index 334b3bc6ba8..81742398b9b 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorsHandlerTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/AssertionErrorsHandlerTest.java.mustache @@ -3,6 +3,9 @@ package {{ packageName }}.shared.error.infrastructure.primary; import static org.mockito.Mockito.*; import ch.qos.logback.classic.Level; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.context.MessageSource; import {{ packageName }}.Logs; import {{ packageName }}.LogsSpy; import {{ packageName }}.LogsSpyExtension; @@ -10,9 +13,6 @@ import {{ packageName }}.UnitTest; import {{ packageName }}.shared.error.domain.AssertionErrorType; import {{ packageName }}.shared.error.domain.AssertionException; import {{ packageName }}.shared.error_generator.domain.NullElementInCollectionExceptionFactory; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.context.MessageSource; @UnitTest @ExtendWith(LogsSpyExtension.class) diff --git a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ErrorKeyTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ErrorKeyTest.java.mustache index f9206fd8513..1ac1169a54d 100644 --- a/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ErrorKeyTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/internationalized-errors/test/ErrorKeyTest.java.mustache @@ -17,29 +17,30 @@ class ErrorKeyTest { private static final String BASE_PACKAGE = "{{ packageName }}"; - private static final Set> KEYS = new Reflections( + private static final Set> KEYS = new Reflections( new ConfigurationBuilder() .setUrls(ClasspathHelper.forPackage(BASE_PACKAGE)) .setScanners(Scanners.SubTypes) .filterInputsBy(new FilterBuilder().includePackage(BASE_PACKAGE)) - ) - .getSubTypesOf(ErrorKey.class); + ).getSubTypesOf(ErrorKey.class); @Test void shouldHaveOnlyEnumsImplementations() { - KEYS.forEach(error -> - assertThat(error.isEnum() || error.isInterface()) - .as(() -> "Implementations of " + ErrorKey.class.getName() + " must be enums and " + error.getName() + " wasn't") - .isTrue() + KEYS.forEach( + error -> + assertThat(error.isEnum() || error.isInterface()) + .as(() -> "Implementations of " + ErrorKey.class.getName() + " must be enums and " + error.getName() + " wasn't") + .isTrue() ); } @Test void shouldNotGenerateBlankStringKey() { - KEYS.forEach(key -> - Stream - .of(key.getEnumConstants()) - .forEach(enumKey -> assertThat(enumKey.get()).as(() -> key + "." + enumKey + " generates a blank key").isNotBlank()) + KEYS.forEach( + key -> + Stream.of(key.getEnumConstants()).forEach( + enumKey -> assertThat(enumKey.get()).as(() -> key + "." + enumKey + " generates a blank key").isNotBlank() + ) ); } } diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeerIdAccessChecker.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeerIdAccessChecker.java.mustache index 964d174f2e6..33a9473ed7a 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeerIdAccessChecker.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeerIdAccessChecker.java.mustache @@ -1,10 +1,10 @@ package {{packageName}}.sample.application; +import org.springframework.stereotype.Component; import {{packageName}}.sample.domain.BeerId; import {{packageName}}.shared.kipe.application.AccessChecker; import {{packageName}}.shared.kipe.application.AccessContext; import {{packageName}}.shared.kipe.application.{{ baseName }}Authorizations; -import org.springframework.stereotype.Component; @Component class BeerIdAccessChecker implements AccessChecker { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeerToCreateAccessChecker.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeerToCreateAccessChecker.java.mustache index f60618703d3..a8bc78d3b21 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeerToCreateAccessChecker.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeerToCreateAccessChecker.java.mustache @@ -1,10 +1,10 @@ package {{packageName}}.sample.application; +import org.springframework.stereotype.Component; import {{packageName}}.sample.domain.beer.BeerToCreate; import {{packageName}}.shared.kipe.application.AccessChecker; import {{packageName}}.shared.kipe.application.AccessContext; import {{packageName}}.shared.kipe.application.{{ baseName }}Authorizations; -import org.springframework.stereotype.Component; @Component class BeerToCreateAccessChecker implements AccessChecker { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeersAccessesConfiguration.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeersAccessesConfiguration.java.mustache index 06a094ba6ce..95a73d4a1c9 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeersAccessesConfiguration.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeersAccessesConfiguration.java.mustache @@ -1,17 +1,16 @@ package {{packageName}}.sample.application; -import {{packageName}}.shared.authentication.domain.Role; -import {{packageName}}.shared.kipe.domain.RolesAccesses; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import {{packageName}}.shared.authentication.domain.Role; +import {{packageName}}.shared.kipe.domain.RolesAccesses; @Configuration class BeersAccessesConfiguration { @Bean RolesAccesses beersAccesses() { - return RolesAccesses - .builder() + return RolesAccesses.builder() .role(Role.ADMIN) .allAuthorized("create", BeerResource.BEERS) .allAuthorized("remove", BeerResource.BEERS) diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeersApplicationService.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeersApplicationService.java.mustache index 1a206c820d0..00d72d486d7 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeersApplicationService.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/application/BeersApplicationService.java.mustache @@ -1,5 +1,7 @@ package {{packageName}}.sample.application; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; import {{packageName}}.sample.domain.BeerId; import {{packageName}}.sample.domain.beer.Beer; import {{packageName}}.sample.domain.beer.BeerToCreate; @@ -8,9 +10,6 @@ import {{packageName}}.sample.domain.beer.BeersCreator; import {{packageName}}.sample.domain.beer.BeersRemover; import {{packageName}}.sample.domain.beer.BeersRepository; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.stereotype.Service; - @Service public class BeersApplicationService { @@ -38,5 +37,4 @@ public class BeersApplicationService { public Beers catalog() { return beers.catalog(); } - } diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/Amount.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/Amount.java.mustache index b367510a382..73fdbdec83b 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/Amount.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/Amount.java.mustache @@ -1,9 +1,8 @@ package {{packageName}}.sample.domain; -import {{packageName}}.shared.error.domain.Assert; - import java.math.BigDecimal; import java.math.RoundingMode; +import {{packageName}}.shared.error.domain.Assert; public record Amount(BigDecimal amount) { public static final Amount ZERO = new Amount(BigDecimal.ZERO); diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/BeerId.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/BeerId.java.mustache index 73ef9ae858b..243372c49b1 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/BeerId.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/BeerId.java.mustache @@ -1,7 +1,7 @@ package {{packageName}}.sample.domain; -import {{packageName}}.shared.error.domain.Assert; import java.util.UUID; +import {{packageName}}.shared.error.domain.Assert; public record BeerId(UUID id) { public BeerId { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/Beer.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/Beer.java.mustache index 7ae245ce62a..c6fd2d29011 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/Beer.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/Beer.java.mustache @@ -1,7 +1,6 @@ package {{packageName}}.sample.domain.beer; import java.math.BigDecimal; - import {{packageName}}.sample.domain.Amount; import {{packageName}}.sample.domain.BeerId; import {{packageName}}.shared.error.domain.Assert; diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/Beers.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/Beers.java.mustache index 7e402034558..263d5753382 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/Beers.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/Beers.java.mustache @@ -1,9 +1,9 @@ package {{packageName}}.sample.domain.beer; -import {{packageName}}.shared.error.domain.Assert; import java.util.Collection; import java.util.Comparator; import java.util.stream.Stream; +import {{packageName}}.shared.error.domain.Assert; public record Beers(Collection beers) { private static final Comparator BEER_NAME_COMPARATOR = Comparator.comparing(beer -> beer.name().get()); diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/BeersRepository.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/BeersRepository.java.mustache index 481a4af1c6b..6ab6d2c408b 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/BeersRepository.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/beer/BeersRepository.java.mustache @@ -1,7 +1,7 @@ package {{packageName}}.sample.domain.beer; -import {{packageName}}.sample.domain.BeerId; import java.util.Optional; +import {{packageName}}.sample.domain.BeerId; public interface BeersRepository { void save(Beer beer); diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/order/BeerOrder.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/order/BeerOrder.java.mustache index fbe777c11a1..8aacae2d99d 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/order/BeerOrder.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/domain/order/BeerOrder.java.mustache @@ -1,7 +1,5 @@ package {{packageName}}.sample.domain.order; -import {{packageName}}.sample.domain.Amount; -import {{packageName}}.shared.error.domain.Assert; import java.util.Collection; import java.util.HashMap; import java.util.List; @@ -9,6 +7,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.function.BiFunction; import java.util.function.Function; +import {{packageName}}.sample.domain.Amount; +import {{packageName}}.shared.error.domain.Assert; public final class BeerOrder { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/BeersResource.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/BeersResource.java.mustache index 818f4f76808..3d84d8d8467 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/BeersResource.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/BeersResource.java.mustache @@ -1,8 +1,5 @@ package {{packageName}}.sample.infrastructure.primary.beer; -import {{packageName}}.sample.application.BeersApplicationService; -import {{packageName}}.sample.domain.BeerId; -import {{packageName}}.sample.domain.beer.Beer; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; @@ -17,6 +14,9 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import {{packageName}}.sample.application.BeersApplicationService; +import {{packageName}}.sample.domain.BeerId; +import {{packageName}}.sample.domain.beer.Beer; @RestController @Tag(name = "Beers") diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeer.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeer.java.mustache index f8534c82769..0f2679e7e7c 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeer.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeer.java.mustache @@ -1,12 +1,11 @@ package {{packageName}}.sample.infrastructure.primary.beer; -import {{packageName}}.sample.domain.beer.Beer; -import {{packageName}}.shared.error.domain.Assert; -import java.math.BigDecimal; -import java.util.UUID; - import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; +import java.math.BigDecimal; +import java.util.UUID; +import {{packageName}}.sample.domain.beer.Beer; +import {{packageName}}.shared.error.domain.Assert; @Schema(name = "beer", description = "A beer") final class RestBeer { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeerToCreate.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeerToCreate.java.mustache index 1719af6e86a..821ddfa2ae3 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeerToCreate.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeerToCreate.java.mustache @@ -1,14 +1,13 @@ package {{packageName}}.sample.infrastructure.primary.beer; import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; +import jakarta.validation.constraints.NotNull; +import java.math.BigDecimal; import {{packageName}}.sample.domain.Amount; import {{packageName}}.sample.domain.beer.BeerName; import {{packageName}}.sample.domain.beer.BeerToCreate; -import jakarta.validation.constraints.NotNull; -import java.math.BigDecimal; - -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; @Schema(name = "beerToCreate", description = "A beer to create") class RestBeerToCreate { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeers.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeers.java.mustache index 76fd560663b..9f72e6891a5 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeers.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/main/infrastructure/primary/beer/RestBeers.java.mustache @@ -1,9 +1,9 @@ package {{packageName}}.sample.infrastructure.primary.beer; -import {{packageName}}.sample.domain.beer.Beers; -import {{packageName}}.shared.error.domain.Assert; import io.swagger.v3.oas.annotations.media.Schema; import java.util.Collection; +import {{packageName}}.sample.domain.beer.Beers; +import {{packageName}}.shared.error.domain.Assert; @Schema(name = "beers", description = "Some beers") final class RestBeers { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/HttpSteps.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/HttpSteps.java.mustache index 69e8e708a54..92242d1ccfb 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/HttpSteps.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/HttpSteps.java.mustache @@ -2,9 +2,8 @@ package {{packageName}}; import static {{packageName}}.cucumber.rest.CucumberRestAssertions.*; -import org.springframework.http.HttpStatus; - import io.cucumber.java.en.Then; +import org.springframework.http.HttpStatus; public class HttpSteps { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/application/BeerIdAccessCheckerTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/application/BeerIdAccessCheckerTest.java.mustache index 67e09130d23..70a89f1b2a0 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/application/BeerIdAccessCheckerTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/application/BeerIdAccessCheckerTest.java.mustache @@ -1,14 +1,14 @@ package {{packageName}}.sample.application; +import static org.assertj.core.api.Assertions.*; import static {{packageName}}.sample.domain.BeersIdentityFixture.*; import static {{packageName}}.shared.kipe.application.TestAuthentications.*; -import static org.assertj.core.api.Assertions.*; +import java.util.List; +import org.junit.jupiter.api.Test; import {{packageName}}.UnitTest; import {{packageName}}.shared.kipe.application.AccessContext; import {{packageName}}.shared.kipe.application.{{ baseName }}Authorizations; -import java.util.List; -import org.junit.jupiter.api.Test; @UnitTest class BeerIdAccessCheckerTest { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/application/BeerToCreateAccessCheckerTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/application/BeerToCreateAccessCheckerTest.java.mustache index 33c9aed99de..e0ca2e99c75 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/application/BeerToCreateAccessCheckerTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/application/BeerToCreateAccessCheckerTest.java.mustache @@ -1,14 +1,14 @@ package {{packageName}}.sample.application; +import static org.assertj.core.api.Assertions.*; import static {{packageName}}.sample.domain.beer.BeersFixture.*; import static {{packageName}}.shared.kipe.application.TestAuthentications.*; -import static org.assertj.core.api.Assertions.*; +import java.util.List; +import org.junit.jupiter.api.Test; import {{packageName}}.UnitTest; import {{packageName}}.shared.kipe.application.AccessContext; import {{packageName}}.shared.kipe.application.{{ baseName }}Authorizations; -import java.util.List; -import org.junit.jupiter.api.Test; @UnitTest class BeerToCreateAccessCheckerTest { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/AmountTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/AmountTest.java.mustache index 6fbabf9d981..6eb640db3e8 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/AmountTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/AmountTest.java.mustache @@ -2,12 +2,12 @@ package {{packageName}}.sample.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import java.math.BigDecimal; import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import {{packageName}}.UnitTest; @UnitTest class AmountTest { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersFixture.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersFixture.java.mustache index 27988d29592..5475a8788e5 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersFixture.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersFixture.java.mustache @@ -7,8 +7,7 @@ public final class BeersFixture { private BeersFixture() {} public static Beer beer() { - return Beer - .builder() + return Beer.builder() .id(cloackOfFeathersId()) .name(cloakOfFeathersName().get()) .unitPrice(cloakOfFeatherUnitPrice().get()) diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersRemoverTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersRemoverTest.java.mustache index a85ea27ec90..b892b566e04 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersRemoverTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersRemoverTest.java.mustache @@ -2,13 +2,13 @@ package {{packageName}}.sample.domain.beer; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; -import {{packageName}}.sample.domain.BeersIdentityFixture; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import {{packageName}}.UnitTest; +import {{packageName}}.sample.domain.BeersIdentityFixture; @UnitTest @ExtendWith(MockitoExtension.class) diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersTest.java.mustache index 961a4eacf71..9d2293386d5 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/beer/BeersTest.java.mustache @@ -1,20 +1,19 @@ package {{packageName}}.sample.domain.beer; +import static org.assertj.core.api.Assertions.*; import static {{packageName}}.sample.domain.BeersIdentityFixture.*; import static {{packageName}}.sample.domain.beer.BeersFixture.*; -import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import java.util.List; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class BeersTest { @Test void shouldSortBeersByNames() { - Beer anteMeridiem = Beer - .builder() + Beer anteMeridiem = Beer.builder() .id(anteMeridiemId()) .name(new BeerName("Ante Meridiem")) .unitPrice(anteMeridiemUnitPrice()) diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/order/BeerOrderTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/order/BeerOrderTest.java.mustache index c77232a51af..712bc4f0de4 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/order/BeerOrderTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/domain/order/BeerOrderTest.java.mustache @@ -1,13 +1,13 @@ package {{packageName}}.sample.domain.order; -import static {{packageName}}.sample.domain.order.BeerOrderFixture.*; import static org.assertj.core.api.Assertions.*; +import static {{packageName}}.sample.domain.order.BeerOrderFixture.*; +import java.math.BigDecimal; +import org.junit.jupiter.api.Test; import {{packageName}}.UnitTest; import {{packageName}}.sample.domain.Amount; import {{packageName}}.shared.error.domain.MissingMandatoryValueException; -import java.math.BigDecimal; -import org.junit.jupiter.api.Test; @UnitTest class BeerOrderTest { @@ -21,8 +21,10 @@ class BeerOrderTest { void shouldGetConsolidatedOrderLines() { BeerOrder order = beerOrder(); - assertThat(order.lines()) - .containsExactlyInAnyOrder(new BeerOrderLine(orderedCloakOfFeather(), 2), new BeerOrderLine(orderedAnteMeridiem(), 3)); + assertThat(order.lines()).containsExactlyInAnyOrder( + new BeerOrderLine(orderedCloakOfFeather(), 2), + new BeerOrderLine(orderedAnteMeridiem(), 3) + ); } @Test diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/BeersSteps.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/BeersSteps.java.mustache index 89431103ac7..062b9eb64a5 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/BeersSteps.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/BeersSteps.java.mustache @@ -2,21 +2,22 @@ package {{packageName}}.sample.infrastructure.primary.beer; import static {{packageName}}.cucumber.rest.CucumberRestAssertions.*; -import {{packageName}}.cucumber.rest.CucumberRestTemplate; -import {{packageName}}.cucumber.rest.CucumberRestTestContext; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import java.util.List; import java.util.Map; +import {{packageName}}.cucumber.rest.CucumberRestTemplate; +import {{packageName}}.cucumber.rest.CucumberRestTestContext; public class BeersSteps { - private static final String ADD_BEER_TEMPLATE = """ - { - "name": "{NAME}", - "unitPrice": {UNIT_PRICE} - } - """; + private static final String ADD_BEER_TEMPLATE = + """ + { + "name": "{NAME}", + "unitPrice": {UNIT_PRICE} + } + """; private final CucumberRestTemplate rest; diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeerTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeerTest.java.mustache index 6e86cc82c2b..c3fefee1934 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeerTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeerTest.java.mustache @@ -1,11 +1,11 @@ package {{packageName}}.sample.infrastructure.primary.beer; -import static {{packageName}}.sample.domain.beer.BeersFixture.*; import static org.assertj.core.api.Assertions.*; +import static {{packageName}}.sample.domain.beer.BeersFixture.*; +import org.junit.jupiter.api.Test; import {{packageName}}.JsonHelper; import {{packageName}}.UnitTest; -import org.junit.jupiter.api.Test; @UnitTest class RestBeerTest { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeerToCreateTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeerToCreateTest.java.mustache index 073ff096330..4fec96f22ac 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeerToCreateTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeerToCreateTest.java.mustache @@ -1,12 +1,12 @@ package {{packageName}}.sample.infrastructure.primary.beer; -import static {{packageName}}.BeanValidationAssertions.*; import static org.assertj.core.api.Assertions.*; +import static {{packageName}}.BeanValidationAssertions.*; -import {{packageName}}.UnitTest; +import org.junit.jupiter.api.Test; import {{packageName}}.JsonHelper; +import {{packageName}}.UnitTest; import {{packageName}}.sample.domain.beer.BeersFixture; -import org.junit.jupiter.api.Test; @UnitTest class RestBeerToCreateTest { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeersTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeersTest.java.mustache index 83d8c046875..7df3d17c982 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeersTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/feature/test/sample/infrastructure/primary/beer/RestBeersTest.java.mustache @@ -2,12 +2,12 @@ package {{packageName}}.sample.infrastructure.primary.beer; import static org.assertj.core.api.Assertions.*; +import java.util.List; +import org.junit.jupiter.api.Test; import {{packageName}}.JsonHelper; import {{packageName}}.UnitTest; import {{packageName}}.sample.domain.beer.Beers; import {{packageName}}.sample.domain.beer.BeersFixture; -import java.util.List; -import org.junit.jupiter.api.Test; @UnitTest class RestBeersTest { diff --git a/src/main/resources/generator/server/springboot/mvc/sample/jpapersistence/main/infrastructure/secondary/BeerEntity.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/jpapersistence/main/infrastructure/secondary/BeerEntity.java.mustache index fc510b808f4..4b71d9f2930 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/jpapersistence/main/infrastructure/secondary/BeerEntity.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/jpapersistence/main/infrastructure/secondary/BeerEntity.java.mustache @@ -1,22 +1,20 @@ package {{packageName}}.sample.infrastructure.secondary; -import java.math.BigDecimal; -import java.util.UUID; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import jakarta.persistence.Id; import jakarta.persistence.Table; -import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; +import java.math.BigDecimal; +import java.util.UUID; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; import {{packageName}}.sample.domain.BeerId; import {{packageName}}.sample.domain.beer.Beer; import {{packageName}}.sample.domain.beer.BeerSellingState; import {{packageName}}.shared.error.domain.Assert; +import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; @Entity @Table(name = "beers") diff --git a/src/main/resources/generator/server/springboot/mvc/sample/jpapersistence/test/infrastructure/secondary/JpaBeersRepositoryIT.java.mustache b/src/main/resources/generator/server/springboot/mvc/sample/jpapersistence/test/infrastructure/secondary/JpaBeersRepositoryIT.java.mustache index 586ce522512..6ca7af2fac2 100644 --- a/src/main/resources/generator/server/springboot/mvc/sample/jpapersistence/test/infrastructure/secondary/JpaBeersRepositoryIT.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/sample/jpapersistence/test/infrastructure/secondary/JpaBeersRepositoryIT.java.mustache @@ -7,7 +7,6 @@ import static {{packageName}}.sample.domain.beer.BeersFixture.*; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; - import {{packageName}}.IntegrationTest; @Transactional diff --git a/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Role.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Role.java.mustache index d2b95d9a918..961cf36fcc6 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Role.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Role.java.mustache @@ -1,10 +1,10 @@ package {{packageName}}.shared.authentication.domain; -import {{packageName}}.shared.error.domain.Assert; import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; +import {{packageName}}.shared.error.domain.Assert; public enum Role { ADMIN, diff --git a/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Roles.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Roles.java.mustache index b6dafe36e44..f51caa22237 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Roles.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Roles.java.mustache @@ -1,12 +1,11 @@ package {{packageName}}.shared.authentication.domain; -import {{packageName}}.shared.collection.domain.{{ baseName }}Collections; -import {{packageName}}.shared.error.domain.Assert; import java.util.Set; import java.util.stream.Stream; +import {{packageName}}.shared.collection.domain.{{ baseName }}Collections; +import {{packageName}}.shared.error.domain.Assert; public record Roles(Set roles) { - public static final Roles EMPTY = new Roles(null); public Roles(Set roles) { diff --git a/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Username.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Username.java.mustache index a2a02cae439..84a2c9d544a 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Username.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/common/main/domain/Username.java.mustache @@ -1,8 +1,8 @@ package {{packageName}}.shared.authentication.domain; -import {{packageName}}.shared.error.domain.Assert; import java.util.Optional; import org.apache.commons.lang3.StringUtils; +import {{packageName}}.shared.error.domain.Assert; public record Username(String username) { public Username { diff --git a/src/main/resources/generator/server/springboot/mvc/security/common/main/infrastructure/primary/AuthenticationExceptionAdvice.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/common/main/infrastructure/primary/AuthenticationExceptionAdvice.java.mustache index 8db8e51096f..a00475d9321 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/common/main/infrastructure/primary/AuthenticationExceptionAdvice.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/common/main/infrastructure/primary/AuthenticationExceptionAdvice.java.mustache @@ -1,14 +1,13 @@ package {{packageName}}.shared.authentication.infrastructure.primary; -import {{packageName}}.shared.authentication.application.NotAuthenticatedUserException; -import {{packageName}}.shared.authentication.application.UnknownAuthenticationException; - import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.http.HttpStatus; import org.springframework.http.ProblemDetail; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; +import {{packageName}}.shared.authentication.application.NotAuthenticatedUserException; +import {{packageName}}.shared.authentication.application.UnknownAuthenticationException; @ControllerAdvice @Order(Ordered.LOWEST_PRECEDENCE - 20_000) diff --git a/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/RoleTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/RoleTest.java.mustache index 4545cbb4078..1857cb9372a 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/RoleTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/RoleTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.shared.authentication.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class RoleTest { diff --git a/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/RolesTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/RolesTest.java.mustache index a24378140a3..8daedc6fe88 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/RolesTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/RolesTest.java.mustache @@ -2,9 +2,9 @@ package {{packageName}}.shared.authentication.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import java.util.Set; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class RolesTest { diff --git a/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/UsernameTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/UsernameTest.java.mustache index f36b0e25a9b..858e45ec024 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/UsernameTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/common/test/domain/UsernameTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.shared.authentication.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class UsernameTest { diff --git a/src/main/resources/generator/server/springboot/mvc/security/common/test/infrastructure/primary/AccountExceptionResource.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/common/test/infrastructure/primary/AccountExceptionResource.java.mustache index dfd021f8149..fadeb2bccdf 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/common/test/infrastructure/primary/AccountExceptionResource.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/common/test/infrastructure/primary/AccountExceptionResource.java.mustache @@ -1,11 +1,10 @@ package {{packageName}}.shared.authentication.infrastructure.primary; -import {{packageName}}.shared.authentication.application.NotAuthenticatedUserException; -import {{packageName}}.shared.authentication.application.UnknownAuthenticationException; - import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import {{packageName}}.shared.authentication.application.NotAuthenticatedUserException; +import {{packageName}}.shared.authentication.application.UnknownAuthenticationException; @RestController @RequestMapping("/api/account-exceptions") diff --git a/src/main/resources/generator/server/springboot/mvc/security/common/test/infrastructure/primary/AuthenticationExceptionAdviceIT.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/common/test/infrastructure/primary/AuthenticationExceptionAdviceIT.java.mustache index 7aa2c43cbba..d0d4d088730 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/common/test/infrastructure/primary/AuthenticationExceptionAdviceIT.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/common/test/infrastructure/primary/AuthenticationExceptionAdviceIT.java.mustache @@ -3,12 +3,12 @@ package {{packageName}}.shared.authentication.infrastructure.primary; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import {{packageName}}.IntegrationTest; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; +import {{packageName}}.IntegrationTest; @IntegrationTest @AutoConfigureMockMvc diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/application/AuthenticatedUser.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/application/AuthenticatedUser.java.mustache index f014e873f80..22c39e12ffa 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/application/AuthenticatedUser.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/application/AuthenticatedUser.java.mustache @@ -1,9 +1,5 @@ package {{packageName}}.shared.authentication.application; -import {{packageName}}.shared.authentication.domain.Role; -import {{packageName}}.shared.authentication.domain.Roles; -import {{packageName}}.shared.authentication.domain.Username; -import {{packageName}}.shared.error.domain.Assert; import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -11,6 +7,10 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; +import {{packageName}}.shared.authentication.domain.Role; +import {{packageName}}.shared.authentication.domain.Roles; +import {{packageName}}.shared.authentication.domain.Username; +import {{packageName}}.shared.error.domain.Assert; /** * This is a utility class to get authenticated user information diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JWTFilter.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JWTFilter.java.mustache index 4f9e64bff59..ec91b81708c 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JWTFilter.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JWTFilter.java.mustache @@ -1,20 +1,18 @@ package {{packageName}}.shared.authentication.infrastructure.primary; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; import java.io.IOException; import java.util.Optional; import java.util.function.Consumer; - import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpHeaders; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.filter.GenericFilterBean; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.ServletRequest; -import jakarta.servlet.ServletResponse; -import jakarta.servlet.http.HttpServletRequest; import {{packageName}}.shared.error.domain.Assert; class JWTFilter extends GenericFilterBean { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JwtAuthenticationProperties.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JwtAuthenticationProperties.java.mustache index 248a0c11d6c..ccfc4d6d78b 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JwtAuthenticationProperties.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JwtAuthenticationProperties.java.mustache @@ -1,10 +1,9 @@ package {{packageName}}.shared.authentication.infrastructure.primary; +import jakarta.validation.constraints.NotBlank; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; -import jakarta.validation.constraints.NotBlank; - @Validated @ConfigurationProperties("application.security") class JwtAuthenticationProperties { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JwtReader.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JwtReader.java.mustache index 9a710ea59f1..e9ce7d7191c 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JwtReader.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/JwtReader.java.mustache @@ -1,6 +1,5 @@ package {{packageName}}.shared.authentication.infrastructure.primary; -import {{packageName}}.shared.error.domain.Assert; import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtException; import io.jsonwebtoken.JwtParser; @@ -14,6 +13,7 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio import org.springframework.security.core.Authentication; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.User; +import {{packageName}}.shared.error.domain.Assert; class JwtReader implements AuthenticationTokenReader { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/SecurityConfiguration.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/SecurityConfiguration.java.mustache index b8a965223d5..2f793113544 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/SecurityConfiguration.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/main/infrastructure/primary/SecurityConfiguration.java.mustache @@ -2,7 +2,6 @@ package {{packageName}}.shared.authentication.infrastructure.primary; import static org.springframework.security.web.util.matcher.AntPathRequestMatcher.*; -import {{packageName}}.shared.authentication.domain.Role; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.security.Keys; import java.nio.charset.StandardCharsets; @@ -12,12 +11,12 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer.FrameOptionsConfig; -import org.springframework.security.config.Customizer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; @@ -27,6 +26,7 @@ import org.springframework.security.web.header.writers.ReferrerPolicyHeaderWrite import org.springframework.security.web.servlet.util.matcher.MvcRequestMatcher; import org.springframework.web.filter.CorsFilter; import org.springframework.web.servlet.handler.HandlerMappingIntrospector; +import {{packageName}}.shared.authentication.domain.Role; @Configuration @EnableWebSecurity @@ -38,11 +38,7 @@ class SecurityConfiguration { private final CorsFilter corsFilter; private final HandlerMappingIntrospector introspector; - public SecurityConfiguration( - JwtAuthenticationProperties properties, - CorsFilter corsFilter, - HandlerMappingIntrospector introspector - ) { + public SecurityConfiguration(JwtAuthenticationProperties properties, CorsFilter corsFilter, HandlerMappingIntrospector introspector) { this.properties = properties; this.corsFilter = corsFilter; this.introspector = introspector; diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/application/AuthenticatedUserTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/application/AuthenticatedUserTest.java.mustache index 731d8c8bf40..7f692c6a2dc 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/application/AuthenticatedUserTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/application/AuthenticatedUserTest.java.mustache @@ -1,11 +1,8 @@ package {{packageName}}.shared.authentication.application; -import static {{packageName}}.shared.authentication.application.AuthenticatedUser.*; import static org.assertj.core.api.Assertions.*; +import static {{packageName}}.shared.authentication.application.AuthenticatedUser.*; -import {{packageName}}.UnitTest; -import {{packageName}}.shared.authentication.domain.Role; -import {{packageName}}.shared.authentication.domain.Username; import java.util.Collection; import java.util.List; import java.util.stream.Stream; @@ -25,6 +22,9 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.User; +import {{packageName}}.UnitTest; +import {{packageName}}.shared.authentication.domain.Role; +import {{packageName}}.shared.authentication.domain.Username; @UnitTest class AuthenticatedUserTest { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/infrastructure/primary/JWTFilterTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/infrastructure/primary/JWTFilterTest.java.mustache index 6e9a7ba4422..a416eaa664b 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/infrastructure/primary/JWTFilterTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/infrastructure/primary/JWTFilterTest.java.mustache @@ -3,7 +3,9 @@ package {{packageName}}.shared.authentication.infrastructure.primary; import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -import {{packageName}}.UnitTest; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Optional; import org.junit.jupiter.api.AfterEach; @@ -19,10 +21,7 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.security.authentication.TestingAuthenticationToken; import org.springframework.security.core.context.SecurityContextHolder; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletResponse; +import {{packageName}}.UnitTest; @UnitTest @ExtendWith(MockitoExtension.class) diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/infrastructure/primary/JwtReaderTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/infrastructure/primary/JwtReaderTest.java.mustache index cb1cebfd67e..db551514e63 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/infrastructure/primary/JwtReaderTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/authentication/test/infrastructure/primary/JwtReaderTest.java.mustache @@ -3,10 +3,6 @@ package {{packageName}}.shared.authentication.infrastructure.primary; import static org.assertj.core.api.Assertions.*; import ch.qos.logback.classic.Level; -import {{packageName}}.Logs; -import {{packageName}}.LogsSpy; -import {{packageName}}.LogsSpyExtension; -import {{packageName}}.UnitTest; import io.jsonwebtoken.JwtParser; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.security.Keys; @@ -20,6 +16,10 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.security.core.Authentication; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.User; +import {{packageName}}.Logs; +import {{packageName}}.LogsSpy; +import {{packageName}}.LogsSpyExtension; +import {{packageName}}.UnitTest; @UnitTest @ExtendWith({ LogsSpyExtension.class, MockitoExtension.class }) @@ -30,6 +30,7 @@ class JwtReaderTest { ); private final JwtReader reader = new JwtReader(parser()); + @Logs private LogsSpy logs; @@ -60,13 +61,14 @@ class JwtReaderTest { Authentication authentication = reader.read(userToken()).get(); assertThat(((User) authentication.getPrincipal()).getUsername()).isEqualTo("test"); - assertThat(authentication.getAuthorities().stream().map(SimpleGrantedAuthority.class::cast)) - .containsExactly(new SimpleGrantedAuthority("ROLE_USER"), new SimpleGrantedAuthority("ROLE_ADMIN")); + assertThat(authentication.getAuthorities().stream().map(SimpleGrantedAuthority.class::cast)).containsExactly( + new SimpleGrantedAuthority("ROLE_USER"), + new SimpleGrantedAuthority("ROLE_ADMIN") + ); } private String userToken() { - return Jwts - .builder() + return Jwts.builder() .subject("test") .claim("auth", "ROLE_USER,ROLE_ADMIN,,") .signWith(KEY, Jwts.SIG.HS512) @@ -83,11 +85,6 @@ class JwtReaderTest { } private String userTokenWithoutRoles() { - return Jwts - .builder() - .subject("test") - .signWith(KEY, Jwts.SIG.HS512) - .expiration(Date.from(Instant.now().plusSeconds(120))) - .compact(); + return Jwts.builder().subject("test").signWith(KEY, Jwts.SIG.HS512).expiration(Date.from(Instant.now().plusSeconds(120))).compact(); } } diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/application/AccountApplicationService.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/application/AccountApplicationService.java.mustache index d4df22ae02f..1d9cf350a32 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/application/AccountApplicationService.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/application/AccountApplicationService.java.mustache @@ -1,9 +1,9 @@ package {{packageName}}.account.application; +import org.springframework.stereotype.Service; import {{packageName}}.account.domain.AuthenticationQuery; import {{packageName}}.account.domain.Token; import {{packageName}}.account.domain.TokensRepository; -import org.springframework.stereotype.Service; @Service public class AccountApplicationService { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/AccountResource.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/AccountResource.java.mustache index 9ed8d906881..f4bd176e9d4 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/AccountResource.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/AccountResource.java.mustache @@ -1,12 +1,12 @@ package {{packageName}}.account.infrastructure.primary; -import {{packageName}}.shared.authentication.domain.Role; -import {{packageName}}.shared.authentication.application.AuthenticatedUser; import java.util.Set; import java.util.stream.Collectors; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import {{packageName}}.shared.authentication.application.AuthenticatedUser; +import {{packageName}}.shared.authentication.domain.Role; @RestController @RequestMapping("/api") diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/AuthenticationResource.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/AuthenticationResource.java.mustache index 7504d4b5ac3..001bcc71511 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/AuthenticationResource.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/AuthenticationResource.java.mustache @@ -1,7 +1,8 @@ package {{packageName}}.account.infrastructure.primary; -import {{packageName}}.account.domain.Token; import io.swagger.v3.oas.annotations.Operation; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.validation.Valid; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -10,9 +11,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.validation.Valid; +import {{packageName}}.account.domain.Token; @RestController @RequestMapping("/api/authenticate") diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/Authenticator.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/Authenticator.java.mustache index 490c4d15701..e8347ddad56 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/Authenticator.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/Authenticator.java.mustache @@ -1,12 +1,12 @@ package {{packageName}}.account.infrastructure.primary; -import {{packageName}}.account.application.AccountApplicationService; -import {{packageName}}.account.domain.Token; -import {{packageName}}.shared.authentication.application.AuthenticatedUser; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; +import {{packageName}}.account.application.AccountApplicationService; +import {{packageName}}.account.domain.Token; +import {{packageName}}.shared.authentication.application.AuthenticatedUser; @Service class Authenticator { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestAccount.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestAccount.java.mustache index 94a64186708..425a637e455 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestAccount.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestAccount.java.mustache @@ -1,10 +1,9 @@ package {{packageName}}.account.infrastructure.primary; -import {{packageName}}.shared.error.domain.Assert; -import java.util.Set; - import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; +import java.util.Set; +import {{packageName}}.shared.error.domain.Assert; @Schema(name = "account", description = "Information for the authenticated user account") class RestAccount { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestAuthenticationQuery.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestAuthenticationQuery.java.mustache index 3adb771b470..acc87a63b62 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestAuthenticationQuery.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestAuthenticationQuery.java.mustache @@ -1,20 +1,17 @@ package {{packageName}}.account.infrastructure.primary; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; - import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; - +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; import {{packageName}}.account.domain.AuthenticationQuery; import {{packageName}}.account.infrastructure.primary.RestAuthenticationQuery.RestAuthenticationQueryBuilder; import {{packageName}}.shared.authentication.domain.Roles; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; - @JsonDeserialize(builder = RestAuthenticationQueryBuilder.class) @Schema(name = "AuthenticationQuery", description = "Query to authenticate au user") final class RestAuthenticationQuery { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestToken.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestToken.java.mustache index 68a619e6c83..032f5b93220 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestToken.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/primary/RestToken.java.mustache @@ -1,10 +1,9 @@ package {{packageName}}.account.infrastructure.primary; import com.fasterxml.jackson.annotation.JsonProperty; -import {{packageName}}.account.domain.Token; - import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema.RequiredMode; +import {{packageName}}.account.domain.Token; @Schema(name = "token", description = "A JWT token") final class RestToken { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/secondary/JwtTokensProperties.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/secondary/JwtTokensProperties.java.mustache index bf95ab942b5..68586790f63 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/secondary/JwtTokensProperties.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/secondary/JwtTokensProperties.java.mustache @@ -1,13 +1,11 @@ package {{packageName}}.account.infrastructure.secondary; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import java.time.Duration; - import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; - @Validated @ConfigurationProperties("application.security") class JwtTokensProperties { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/secondary/JwtTokensRepository.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/secondary/JwtTokensRepository.java.mustache index ec0caff77f7..a94df309be6 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/secondary/JwtTokensRepository.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/main/infrastructure/secondary/JwtTokensRepository.java.mustache @@ -1,10 +1,5 @@ package {{packageName}}.account.infrastructure.secondary; -import {{packageName}}.account.domain.AuthenticationQuery; -import {{packageName}}.account.domain.Token; -import {{packageName}}.account.domain.TokensRepository; -import {{packageName}}.shared.authentication.domain.Role; -import {{packageName}}.shared.error.domain.Assert; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.security.Keys; import java.nio.charset.StandardCharsets; @@ -13,6 +8,11 @@ import java.util.Date; import java.util.stream.Collectors; import javax.crypto.SecretKey; import org.springframework.stereotype.Repository; +import {{packageName}}.account.domain.AuthenticationQuery; +import {{packageName}}.account.domain.Token; +import {{packageName}}.account.domain.TokensRepository; +import {{packageName}}.shared.authentication.domain.Role; +import {{packageName}}.shared.error.domain.Assert; @Repository class JwtTokensRepository implements TokensRepository { @@ -30,8 +30,7 @@ class JwtTokensRepository implements TokensRepository { public Token buildToken(AuthenticationQuery query) { Assert.notNull("query", query); - String token = Jwts - .builder() + String token = Jwts.builder() .subject(query.username().get()) .claim("auth", buildAuthorities(query)) .signWith(key, Jwts.SIG.HS512) diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/AccountResourceIT.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/AccountResourceIT.java.mustache index fcbf228e848..0859fb38806 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/AccountResourceIT.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/AccountResourceIT.java.mustache @@ -3,14 +3,14 @@ package {{packageName}}.account.infrastructure.primary; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import {{packageName}}.IntegrationTest; -import {{packageName}}.shared.authentication.domain.Role; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.security.test.context.support.WithAnonymousUser; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; +import {{packageName}}.IntegrationTest; +import {{packageName}}.shared.authentication.domain.Role; @IntegrationTest @AutoConfigureMockMvc diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/AuthenticationResourceIT.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/AuthenticationResourceIT.java.mustache index b84e6588fb0..075bb57d0d4 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/AuthenticationResourceIT.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/AuthenticationResourceIT.java.mustache @@ -4,13 +4,13 @@ import static org.hamcrest.Matchers.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import {{packageName}}.IntegrationTest; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.web.servlet.MockMvc; +import {{packageName}}.IntegrationTest; @IntegrationTest @AutoConfigureMockMvc @@ -109,8 +109,7 @@ class AuthenticationResourceIT { } public String build() { - return AUTHENTICATION_TEMPLATE - .replace("{USER}", username) + return AUTHENTICATION_TEMPLATE.replace("{USER}", username) .replace("{PASSWORD}", password) .replace("{REMEMBER_ME}", String.valueOf(rememberMe)); } diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestAccountTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestAccountTest.java.mustache index 9274ae00f97..5b4c4ceef81 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestAccountTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestAccountTest.java.mustache @@ -2,10 +2,10 @@ package {{packageName}}.account.infrastructure.primary; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.JsonHelper; -import {{packageName}}.UnitTest; import java.util.Set; import org.junit.jupiter.api.Test; +import {{packageName}}.JsonHelper; +import {{packageName}}.UnitTest; @UnitTest class RestAccountTest { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestAuthenticationQueryTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestAuthenticationQueryTest.java.mustache index f42b6b296d6..dae9148ab19 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestAuthenticationQueryTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestAuthenticationQueryTest.java.mustache @@ -2,10 +2,10 @@ package {{packageName}}.account.infrastructure.primary; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.JsonHelper; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import {{packageName}}.JsonHelper; +import {{packageName}}.UnitTest; @UnitTest class RestAuthenticationQueryTest { diff --git a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestTokenTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestTokenTest.java.mustache index 00ba99299b5..0c6f6fbeccd 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestTokenTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/jwt/basic-auth/test/infrastructure/primary/RestTokenTest.java.mustache @@ -1,11 +1,11 @@ package {{packageName}}.account.infrastructure.primary; -import static {{packageName}}.account.domain.TokensFixture.*; import static org.assertj.core.api.Assertions.*; +import static {{packageName}}.account.domain.TokensFixture.*; +import org.junit.jupiter.api.Test; import {{packageName}}.JsonHelper; import {{packageName}}.UnitTest; -import org.junit.jupiter.api.Test; @UnitTest class RestTokenTest { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/kipe-authorization.md.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/kipe-authorization.md.mustache index e722d737f6f..548edd2324d 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/kipe-authorization.md.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/kipe-authorization.md.mustache @@ -21,6 +21,7 @@ enum MyResource implements Resource { return key; } } + ``` You'll then have to define one (or more) `RolesAccesses` spring beans: @@ -47,19 +48,19 @@ class RolesConfiguration { For each role, you'll be able to define multiple accesses. There are three things defining an access: -* The scope: can be `all` or `specific`; -* The action, it's a verb (`read` in the example); -* The `Resource`. +- The scope: can be `all` or `specific`; +- The action, it's a verb (`read` in the example); +- The `Resource`. -Once you have defined one (or more) `RolesAccesses` you can inject `{{ baseName }}Authorizations` and check for authorizations. If you use `kipe-authorization` along with `kipe-expression` you'll be able to define `AccessChecker` looking like this: +Once you have defined one (or more) `RolesAccesses` you can inject `FullappAuthorizations` and check for authorizations. If you use `kipe-authorization` along with `kipe-expression` you'll be able to define `AccessChecker` looking like this: ```java @Component class MyObjectAccessChecker implements AccessChecker { - private final {{ baseName }}Authorizations authorizations; + private final FullappAuthorizations authorizations; - public MyObjectAccessChecker({{ baseName }}Authorizations authorizations) { + public MyObjectAccessChecker(FullappAuthorizations authorizations) { this.authorizations = authorizations; } @@ -76,6 +77,7 @@ class MyObjectAccessChecker implements AccessChecker { return false; } } + ``` This way, you'll have fine-grained, easy to test authorizations check allowing custom configuration for each action in your application. diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/Accesses.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/Accesses.java.mustache index 9abb73574c6..f8fc5a94857 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/Accesses.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/Accesses.java.mustache @@ -62,18 +62,19 @@ public final class Accesses { } Accesses merge(Accesses other) { - Map> mergedAccesses = Stream - .concat(actionsAccesses.entrySet().stream(), other.actionsAccesses.entrySet().stream()) - .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, mergeResourceAccesses())); + Map> mergedAccesses = Stream.concat( + actionsAccesses.entrySet().stream(), + other.actionsAccesses.entrySet().stream() + ).collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, mergeResourceAccesses())); return new Accesses(mergedAccesses); } private BinaryOperator> mergeResourceAccesses() { return (first, second) -> - Stream - .concat(first.entrySet().stream(), second.entrySet().stream()) - .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, mergeAccessesScopes())); + Stream.concat(first.entrySet().stream(), second.entrySet().stream()).collect( + Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, mergeAccessesScopes()) + ); } private BinaryOperator mergeAccessesScopes() { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/ApplicationAuthorizations.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/ApplicationAuthorizations.java.mustache index ec816246711..84d67b8e267 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/ApplicationAuthorizations.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/ApplicationAuthorizations.java.mustache @@ -4,6 +4,9 @@ import java.util.Collection; import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.stereotype.Component; import {{packageName}}.shared.authentication.application.AuthenticatedUser; import {{packageName}}.shared.authentication.domain.Role; import {{packageName}}.shared.authentication.domain.Roles; @@ -11,9 +14,6 @@ import {{packageName}}.shared.authentication.domain.Username; import {{packageName}}.shared.kipe.domain.Action; import {{packageName}}.shared.kipe.domain.Resource; import {{packageName}}.shared.kipe.domain.RolesAccesses; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.stereotype.Component; @Component public class {{ baseName }}Authorizations { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/RolesAccesses.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/RolesAccesses.java.mustache index 5327d55fa23..81de221ade1 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/RolesAccesses.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/main/RolesAccesses.java.mustache @@ -71,9 +71,9 @@ public final class RolesAccesses { public RolesAccesses merge(RolesAccesses other) { Assert.notNull("other", other); - Map mergedRoles = Stream - .concat(roles.entrySet().stream(), other.roles.entrySet().stream()) - .collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, Accesses::merge)); + Map mergedRoles = Stream.concat(roles.entrySet().stream(), other.roles.entrySet().stream()).collect( + Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue, Accesses::merge) + ); return new RolesAccesses(mergedRoles); } diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/ActionTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/ActionTest.java.mustache index 33c1f459c5b..27b79139a10 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/ActionTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/ActionTest.java.mustache @@ -2,8 +2,8 @@ package {{packageName}}.shared.kipe.domain; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; +import {{packageName}}.UnitTest; @UnitTest class ActionTest { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/ApplicationAuthorizationsTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/ApplicationAuthorizationsTest.java.mustache index 2091dc2534c..0d5020d4ce0 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/ApplicationAuthorizationsTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/ApplicationAuthorizationsTest.java.mustache @@ -7,11 +7,6 @@ import static {{packageName}}.shared.kipe.domain.RolesAccessesFixture.*; import java.util.List; import java.util.stream.Stream; -import {{packageName}}.UnitTest; -import {{packageName}}.shared.authentication.application.UnknownAuthenticationException; -import {{packageName}}.shared.authentication.domain.Username; -import {{packageName}}.shared.error.domain.MissingMandatoryValueException; -import {{packageName}}.shared.kipe.domain.RolesAccessesFixture.TestResource; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -20,6 +15,11 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.springframework.security.core.Authentication; import org.springframework.security.core.userdetails.UserDetails; +import {{packageName}}.UnitTest; +import {{packageName}}.shared.authentication.application.UnknownAuthenticationException; +import {{packageName}}.shared.authentication.domain.Username; +import {{packageName}}.shared.error.domain.MissingMandatoryValueException; +import {{packageName}}.shared.kipe.domain.RolesAccessesFixture.TestResource; @UnitTest class {{ baseName }}AuthorizationsTest { @@ -78,21 +78,20 @@ class {{ baseName }}AuthorizationsTest { @Test void shouldNotGetAuthenticatedUserUsernameForUnknownAuthentication() { - assertThatThrownBy(() -> authorizations.getUsername(TestAuthentications.user(null))).isExactlyInstanceOf(UnknownAuthenticationException.class); + assertThatThrownBy(() -> authorizations.getUsername(TestAuthentications.user(null))).isExactlyInstanceOf( + UnknownAuthenticationException.class + ); } private static Stream allValidAuthentications() { - return Stream.of( - Arguments.of(createDummyAuthenticationWithPrincipalDetails("admin")), - Arguments.of(TestAuthentications.admin()) - ); + return Stream.of(Arguments.of(createDummyAuthenticationWithPrincipalDetails("admin")), Arguments.of(TestAuthentications.admin())); } private static Authentication createDummyAuthenticationWithPrincipalDetails(String username) { UserDetails principalDetails = createUserDetailsWithUsername(username); Authentication authentication = mock(Authentication.class); when(authentication.getPrincipal()).thenReturn(principalDetails); - when(authentication.toString()).thenReturn("Authentication with userDetails, username="+username); + when(authentication.toString()).thenReturn("Authentication with userDetails, username=" + username); return authentication; } diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/RolesAccessesTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/RolesAccessesTest.java.mustache index ea0d3335361..9a9e8dd5b97 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/RolesAccessesTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/RolesAccessesTest.java.mustache @@ -4,11 +4,11 @@ import static org.assertj.core.api.Assertions.*; import static {{packageName}}.shared.kipe.domain.RolesAccessesFixture.*; import java.util.Set; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import {{packageName}}.UnitTest; import {{packageName}}.shared.authentication.domain.Role; import {{packageName}}.shared.authentication.domain.Roles; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; @UnitTest class RolesAccessesTest { @@ -63,8 +63,7 @@ class RolesAccessesTest { @Test void shouldMergeAccesses() { - RolesAccesses initial = RolesAccesses - .builder() + RolesAccesses initial = RolesAccesses.builder() .role(Role.USER) .allAuthorized("read", TestResource.USERS) .specificAuthorized("update", TestResource.USERS) diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/TestAuthentications.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/TestAuthentications.java.mustache index 32d05a115f4..3eb5f7b18d0 100755 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/TestAuthentications.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/authorization/test/TestAuthentications.java.mustache @@ -1,8 +1,8 @@ package {{packageName}}.shared.kipe.application; -import {{packageName}}.shared.authentication.domain.Role; import org.springframework.security.authentication.TestingAuthenticationToken; import org.springframework.security.core.Authentication; +import {{packageName}}.shared.authentication.domain.Role; public final class TestAuthentications { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/kipe-expression.md.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/kipe-expression.md.mustache index 55e6a38b76d..131b49a71b7 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/kipe-expression.md.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/kipe-expression.md.mustache @@ -11,6 +11,7 @@ It will allow you to use a new `can('action', #element)` expression in `@PreAuth public void update(KipeDummy dummy) { // ... } + ``` Those expressions will then be evaluated in dedicated `AccessChecker`. To do so, you'll have to define spring beans (`@Component` or `@Service`) implementing `AccessChecker`: @@ -24,6 +25,7 @@ class KipeDummyAccessChecker implements AccessChecker { //TODO: your business authorization logic } } + ``` Kipe's only job is to call the `AccessChecker` for your object class. diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/AccessEvaluator.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/AccessEvaluator.java.mustache index f80ea719e2f..a7ce92e884f 100755 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/AccessEvaluator.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/AccessEvaluator.java.mustache @@ -9,13 +9,12 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; - -import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; -import {{packageName}}.shared.error.domain.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Service; +import {{packageName}}.shared.error.domain.Assert; +import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; @Service class AccessEvaluator { @@ -29,7 +28,7 @@ class AccessEvaluator { public AccessEvaluator(List> checkers) { evaluators = new ConcurrentHashMap<>(checkers.stream().collect(Collectors.toMap(this::getCheckerResourceClass, Function.identity()))); - if(logger.isInfoEnabled()) { + if (logger.isInfoEnabled()) { logger.info("Authorized types: {}", evaluators.keySet().stream().map(Class::getName).collect(Collectors.joining(", "))); } @@ -40,12 +39,10 @@ class AccessEvaluator { private Class getCheckerResourceClass(AccessChecker checker) { Class checkerClass = checker.getClass(); - return (Class) ( - (ParameterizedType) streamParameterizedTypes(checkerClass) + return (Class) ((ParameterizedType) streamParameterizedTypes(checkerClass) .filter(type -> ((ParameterizedType) type).getRawType().equals(AccessChecker.class)) .findFirst() - .orElseThrow() - ).getActualTypeArguments()[0]; + .orElseThrow()).getActualTypeArguments()[0]; } private Stream streamParameterizedTypes(Class checkerClass) { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/ElementAccessContext.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/ElementAccessContext.java.mustache index c0de96dfedf..d0688fb2867 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/ElementAccessContext.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/ElementAccessContext.java.mustache @@ -1,7 +1,7 @@ package {{packageName}}.shared.kipe.application; -import {{packageName}}.shared.error.domain.Assert; import org.springframework.security.core.Authentication; +import {{packageName}}.shared.error.domain.Assert; public record ElementAccessContext(Authentication authentication, String action, T element) implements AccessContext { public ElementAccessContext { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/KipeMethodSecurityExpressionHandler.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/KipeMethodSecurityExpressionHandler.java.mustache index ff94b2b51c2..66864443d3f 100755 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/KipeMethodSecurityExpressionHandler.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/KipeMethodSecurityExpressionHandler.java.mustache @@ -39,10 +39,7 @@ class KipeMethodSecurityExpressionHandler extends DefaultMethodSecurityExpressio return AopUtils.getMostSpecificMethod(mi.getMethod(), AopProxyUtils.ultimateTargetClass(mi.getThis())); } - private MethodSecurityExpressionOperations buildExpressionRoot( - Supplier authentication, - MethodInvocation invocation - ) { + private MethodSecurityExpressionOperations buildExpressionRoot(Supplier authentication, MethodInvocation invocation) { KipeMethodSecurityExpressionRoot root = new KipeMethodSecurityExpressionRoot(authentication, evaluator); root.setThis(invocation.getThis()); diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/KipeMethodSecurityExpressionRoot.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/KipeMethodSecurityExpressionRoot.java.mustache index b4cfa57beff..7a0aa8137f3 100755 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/KipeMethodSecurityExpressionRoot.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/KipeMethodSecurityExpressionRoot.java.mustache @@ -1,10 +1,10 @@ package {{packageName}}.shared.kipe.application; import java.util.function.Supplier; -import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; import org.springframework.security.access.expression.SecurityExpressionRoot; import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations; import org.springframework.security.core.Authentication; +import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; @ExcludeFromGeneratedCodeCoverage(reason = "Spring glue bean") class KipeMethodSecurityExpressionRoot extends SecurityExpressionRoot implements MethodSecurityExpressionOperations { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/NullElementAccessContext.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/NullElementAccessContext.java.mustache index 14159773bcb..c89760e1d1d 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/NullElementAccessContext.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/NullElementAccessContext.java.mustache @@ -1,8 +1,8 @@ package {{packageName}}.shared.kipe.application; -import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; -import {{packageName}}.shared.error.domain.Assert; import org.springframework.security.core.Authentication; +import {{packageName}}.shared.error.domain.Assert; +import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; @ExcludeFromGeneratedCodeCoverage(reason = "Untested null object structure") record NullElementAccessContext(Authentication authentication, String action) implements AccessContext { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/ObjectAccessChecker.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/ObjectAccessChecker.java.mustache index 45502e2f9e0..c814b7cda07 100755 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/ObjectAccessChecker.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/main/ObjectAccessChecker.java.mustache @@ -1,9 +1,9 @@ package {{packageName}}.shared.kipe.application; -import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import {{packageName}}.shared.generation.domain.ExcludeFromGeneratedCodeCoverage; @Component class ObjectAccessChecker implements AccessChecker { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessCheckerIT.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessCheckerIT.java.mustache index 6238b48db3b..e71b061cafd 100755 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessCheckerIT.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessCheckerIT.java.mustache @@ -5,12 +5,11 @@ import static org.assertj.core.api.Assertions.*; import java.lang.annotation.Annotation; import java.util.Set; import java.util.stream.Stream; - -import {{packageName}}.IntegrationTest; import org.junit.jupiter.api.Test; import org.reflections.Reflections; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; +import {{packageName}}.IntegrationTest; @IntegrationTest class AccessCheckerIT { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessContextFactoryTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessContextFactoryTest.java.mustache index c95871efb3a..21b29e99e05 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessContextFactoryTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessContextFactoryTest.java.mustache @@ -3,9 +3,9 @@ package {{packageName}}.shared.kipe.application; import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -import {{packageName}}.UnitTest; import org.junit.jupiter.api.Test; import org.springframework.security.core.Authentication; +import {{packageName}}.UnitTest; @UnitTest class AccessContextFactoryTest { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessEvaluatorTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessEvaluatorTest.java.mustache index 0f15341130f..322cf090726 100755 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessEvaluatorTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/AccessEvaluatorTest.java.mustache @@ -4,6 +4,11 @@ import static org.assertj.core.api.Assertions.*; import ch.qos.logback.classic.Level; import java.util.List; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.security.core.Authentication; import {{packageName}}.Logs; import {{packageName}}.LogsSpy; import {{packageName}}.LogsSpyExtension; @@ -11,11 +16,6 @@ import {{packageName}}.UnitTest; import {{packageName}}.shared.error.domain.MissingMandatoryValueException; import {{packageName}}.shared.kipe.domain.KipeDummy; import {{packageName}}.shared.kipe.domain.KipeDummyChild; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.security.core.Authentication; @UnitTest @ExtendWith({ MockitoExtension.class, LogsSpyExtension.class }) diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeApplicationService.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeApplicationService.java.mustache index 3a49bb6b394..88b12c50380 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeApplicationService.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeApplicationService.java.mustache @@ -1,8 +1,8 @@ package {{packageName}}.shared.kipe.application; -import {{packageName}}.shared.kipe.domain.KipeDummy; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; +import {{packageName}}.shared.kipe.domain.KipeDummy; @Service public class KipeApplicationService { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeDummyAccessChecker.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeDummyAccessChecker.java.mustache index 5e3b59c8ea7..a84447e65ae 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeDummyAccessChecker.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeDummyAccessChecker.java.mustache @@ -1,7 +1,7 @@ package {{packageName}}.shared.kipe.application; -import {{packageName}}.shared.kipe.domain.KipeDummy; import org.springframework.stereotype.Component; +import {{packageName}}.shared.kipe.domain.KipeDummy; @Component class KipeDummyAccessChecker implements AccessChecker { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeIT.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeIT.java.mustache index 8660c6f67ec..97ed01fa112 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeIT.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/KipeIT.java.mustache @@ -2,12 +2,12 @@ package {{packageName}}.shared.kipe.application; import static org.assertj.core.api.Assertions.*; -import {{packageName}}.IntegrationTest; -import {{packageName}}.shared.kipe.domain.KipeDummy; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authorization.AuthorizationDeniedException; import org.springframework.security.test.context.support.WithMockUser; +import {{packageName}}.IntegrationTest; +import {{packageName}}.shared.kipe.domain.KipeDummy; @IntegrationTest class KipeIT { diff --git a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/ObjectAccessCheckerTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/ObjectAccessCheckerTest.java.mustache index cc9ef6e8651..27b40cb88b9 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/ObjectAccessCheckerTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/kipe/expression/test/ObjectAccessCheckerTest.java.mustache @@ -4,13 +4,13 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; import ch.qos.logback.classic.Level; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.security.core.Authentication; import {{packageName}}.Logs; import {{packageName}}.LogsSpy; import {{packageName}}.LogsSpyExtension; import {{packageName}}.UnitTest; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.security.core.Authentication; @UnitTest @ExtendWith(LogsSpyExtension.class) diff --git a/src/main/resources/generator/server/springboot/mvc/security/oauth2/core/main/application/AuthenticatedUser.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/oauth2/core/main/application/AuthenticatedUser.java.mustache index 95a69a994cd..2021b7491e0 100644 --- a/src/main/resources/generator/server/springboot/mvc/security/oauth2/core/main/application/AuthenticatedUser.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/security/oauth2/core/main/application/AuthenticatedUser.java.mustache @@ -1,9 +1,5 @@ package {{packageName}}.shared.authentication.application; -import {{packageName}}.shared.authentication.domain.Role; -import {{packageName}}.shared.authentication.domain.Roles; -import {{packageName}}.shared.authentication.domain.Username; -import {{packageName}}.shared.error.domain.Assert; import java.util.Map; import java.util.Optional; import java.util.function.Function; @@ -15,6 +11,10 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser; import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken; +import {{packageName}}.shared.authentication.domain.Role; +import {{packageName}}.shared.authentication.domain.Roles; +import {{packageName}}.shared.authentication.domain.Username; +import {{packageName}}.shared.error.domain.Assert; /** * This is a utility class to get authenticated user information diff --git a/src/main/resources/generator/server/springboot/mvc/web/test/BeanValidationTest.java.mustache b/src/main/resources/generator/server/springboot/mvc/web/test/BeanValidationTest.java.mustache index c6951a2ef8b..1f6d63daf27 100644 --- a/src/main/resources/generator/server/springboot/mvc/web/test/BeanValidationTest.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/web/test/BeanValidationTest.java.mustache @@ -37,8 +37,7 @@ class BeanValidationTest { .setUrls(ClasspathHelper.forPackage(ROOT_PACKAGE)) .setScanners(Scanners.TypesAnnotated, Scanners.SubTypes) .filterInputsBy(new FilterBuilder().includePackage(ROOT_PACKAGE)) - ) - .getTypesAnnotatedWith(RestController.class); + ).getTypesAnnotatedWith(RestController.class); @Test void shouldHaveValidatedAnnotationForAllParameters() { @@ -65,13 +64,15 @@ class BeanValidationTest { private Consumer checkValidatedAnnotation() { return method -> - Arrays - .stream(method.getParameters()) + Arrays.stream(method.getParameters()) .filter(checkedTypes()) - .forEach(parameter -> assertThat(parameter.getAnnotations()) - .as(errorMessage(method, parameter)) - .extracting(Annotation::annotationType) - .anyMatch(Validated.class::equals)); + .forEach( + parameter -> + assertThat(parameter.getAnnotations()) + .as(errorMessage(method, parameter)) + .extracting(Annotation::annotationType) + .anyMatch(Validated.class::equals) + ); } private String errorMessage(Method method, Parameter parameter) { diff --git a/src/main/resources/generator/server/springboot/mvc/web/test/JsonHelper.java.mustache b/src/main/resources/generator/server/springboot/mvc/web/test/JsonHelper.java.mustache index 9199a664435..b4ea283084e 100644 --- a/src/main/resources/generator/server/springboot/mvc/web/test/JsonHelper.java.mustache +++ b/src/main/resources/generator/server/springboot/mvc/web/test/JsonHelper.java.mustache @@ -17,8 +17,7 @@ public final class JsonHelper { private JsonHelper() {} public static ObjectMapper jsonMapper() { - return JsonMapper - .builder() + return JsonMapper.builder() .serializationInclusion(JsonInclude.Include.NON_NULL) .addModule(new JavaTimeModule()) .addModules(new Jdk8Module())