From 269e255d7035bfc7030ab2a135147357f7b15c17 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 6 Oct 2022 11:23:48 +0000 Subject: [PATCH 01/21] Bump quarkus.platform.version from 2.13.0.Final to 2.13.1.Final Bumps `quarkus.platform.version` from 2.13.0.Final to 2.13.1.Final. Updates `quarkus-universe-bom` from 2.13.0.Final to 2.13.1.Final - [Release notes](https://github.com/quarkusio/quarkus-platform/releases) - [Commits](https://github.com/quarkusio/quarkus-platform/compare/2.13.0.Final...2.13.1.Final) Updates `quarkus-maven-plugin` from 2.13.0.Final to 2.13.1.Final --- updated-dependencies: - dependency-name: io.quarkus:quarkus-universe-bom dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: io.quarkus:quarkus-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6f1823af..1b7bf086 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ SPDX-License-Identifier: Apache-2.0 0.9.3 - 2.13.0.Final + 2.13.1.Final 2.3.6 3.0 2.0.3 From cd73331a519e79314628467980ce2081e44bd7c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 13 Oct 2022 11:19:03 +0000 Subject: [PATCH 02/21] Bump quarkus.platform.version from 2.13.1.Final to 2.13.2.Final Bumps `quarkus.platform.version` from 2.13.1.Final to 2.13.2.Final. Updates `quarkus-universe-bom` from 2.13.1.Final to 2.13.2.Final - [Release notes](https://github.com/quarkusio/quarkus-platform/releases) - [Commits](https://github.com/quarkusio/quarkus-platform/compare/2.13.1.Final...2.13.2.Final) Updates `quarkus-maven-plugin` from 2.13.1.Final to 2.13.2.Final --- updated-dependencies: - dependency-name: io.quarkus:quarkus-universe-bom dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: io.quarkus:quarkus-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1b7bf086..5ccf38b9 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ SPDX-License-Identifier: Apache-2.0 0.9.3 - 2.13.1.Final + 2.13.2.Final 2.3.6 3.0 2.0.3 From 1e00756a41791514b434f416a4c812f14a61f2e8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:41:41 +0000 Subject: [PATCH 03/21] Bump whelk-io/maven-settings-xml-action from 20 to 21 Bumps [whelk-io/maven-settings-xml-action](https://github.com/whelk-io/maven-settings-xml-action) from 20 to 21. - [Release notes](https://github.com/whelk-io/maven-settings-xml-action/releases) - [Commits](https://github.com/whelk-io/maven-settings-xml-action/compare/v20...v21) --- updated-dependencies: - dependency-name: whelk-io/maven-settings-xml-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build-project.yml | 2 +- .github/workflows/release-project.yml | 2 +- .github/workflows/sonarcloud-analysis.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-project.yml b/.github/workflows/build-project.yml index 8bba8114..a7d51d65 100644 --- a/.github/workflows/build-project.yml +++ b/.github/workflows/build-project.yml @@ -45,7 +45,7 @@ jobs: java-version: '17' - name: Create custom Maven Settings.xml - uses: whelk-io/maven-settings-xml-action@v20 + uses: whelk-io/maven-settings-xml-action@v21 with: output_file: custom_maven_settings.xml servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]' diff --git a/.github/workflows/release-project.yml b/.github/workflows/release-project.yml index 0ff955af..e9fb31d6 100644 --- a/.github/workflows/release-project.yml +++ b/.github/workflows/release-project.yml @@ -51,7 +51,7 @@ jobs: password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Create custom Maven Settings.xml - uses: whelk-io/maven-settings-xml-action@v20 + uses: whelk-io/maven-settings-xml-action@v21 with: output_file: custom_maven_settings.xml servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]' diff --git a/.github/workflows/sonarcloud-analysis.yml b/.github/workflows/sonarcloud-analysis.yml index 77fa1f30..13c4eb5d 100644 --- a/.github/workflows/sonarcloud-analysis.yml +++ b/.github/workflows/sonarcloud-analysis.yml @@ -56,7 +56,7 @@ jobs: -Dsonar.projectKey=com-pas_compas-scl-data-service \ -Dsonar.organization=com-pas )" - name: Create custom Maven Settings.xml - uses: whelk-io/maven-settings-xml-action@v20 + uses: whelk-io/maven-settings-xml-action@v21 with: output_file: custom_maven_settings.xml servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]' From 3358278deec151d8896e0b6c0c0610fe50827b65 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Oct 2022 11:14:40 +0000 Subject: [PATCH 04/21] Bump alex-page/github-project-automation-plus from 0.8.1 to 0.8.2 Bumps [alex-page/github-project-automation-plus](https://github.com/alex-page/github-project-automation-plus) from 0.8.1 to 0.8.2. - [Release notes](https://github.com/alex-page/github-project-automation-plus/releases) - [Commits](https://github.com/alex-page/github-project-automation-plus/compare/v0.8.1...v0.8.2) --- updated-dependencies: - dependency-name: alex-page/github-project-automation-plus dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/automate-projects.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/automate-projects.yml b/.github/workflows/automate-projects.yml index 3c61af07..ec3166d7 100644 --- a/.github/workflows/automate-projects.yml +++ b/.github/workflows/automate-projects.yml @@ -14,14 +14,14 @@ jobs: steps: - name: add-new-issues-to-organization-based-project-column if: github.event_name == 'issues' && github.event.action == 'opened' - uses: alex-page/github-project-automation-plus@v0.8.1 + uses: alex-page/github-project-automation-plus@v0.8.2 with: project: CoMPAS Issues Overview Board column: To do repo-token: ${{ secrets.ORG_GITHUB_ACTION_SECRET }} - name: add-new-pull-request-to-organization-based-project-column if: (github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.action == 'opened' - uses: alex-page/github-project-automation-plus@v0.8.1 + uses: alex-page/github-project-automation-plus@v0.8.2 with: project: CoMPAS Pull Request Overview Board column: To do From 3f39aa83a7ee5b31af910de83752cf6579b4a486 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 19 Oct 2022 11:14:55 +0000 Subject: [PATCH 05/21] Bump jaxb-impl from 2.3.6 to 2.3.7 Bumps jaxb-impl from 2.3.6 to 2.3.7. --- updated-dependencies: - dependency-name: com.sun.xml.bind:jaxb-impl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5ccf38b9..3fc4573b 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ SPDX-License-Identifier: Apache-2.0 0.9.3 2.13.2.Final - 2.3.6 + 2.3.7 3.0 2.0.3 0.9.1 From 9d5f40ae82057bd459aafbf818ca8f9c90835e7c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 20 Oct 2022 11:24:03 +0000 Subject: [PATCH 06/21] Bump quarkus.platform.version from 2.13.2.Final to 2.13.3.Final Bumps `quarkus.platform.version` from 2.13.2.Final to 2.13.3.Final. Updates `quarkus-universe-bom` from 2.13.2.Final to 2.13.3.Final - [Release notes](https://github.com/quarkusio/quarkus-platform/releases) - [Commits](https://github.com/quarkusio/quarkus-platform/compare/2.13.2.Final...2.13.3.Final) Updates `quarkus-maven-plugin` from 2.13.2.Final to 2.13.3.Final --- updated-dependencies: - dependency-name: io.quarkus:quarkus-universe-bom dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: io.quarkus:quarkus-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3fc4573b..12153d4a 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ SPDX-License-Identifier: Apache-2.0 0.9.3 - 2.13.2.Final + 2.13.3.Final 2.3.7 3.0 2.0.3 From 7942fca4b398b783b43dfcc304ee23a3d5410610 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 11:07:01 +0000 Subject: [PATCH 07/21] Bump quarkus.platform.version from 2.13.3.Final to 2.13.4.Final Bumps `quarkus.platform.version` from 2.13.3.Final to 2.13.4.Final. Updates `quarkus-universe-bom` from 2.13.3.Final to 2.13.4.Final - [Release notes](https://github.com/quarkusio/quarkus-platform/releases) - [Commits](https://github.com/quarkusio/quarkus-platform/compare/2.13.3.Final...2.13.4.Final) Updates `quarkus-maven-plugin` from 2.13.3.Final to 2.13.4.Final --- updated-dependencies: - dependency-name: io.quarkus:quarkus-universe-bom dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: io.quarkus:quarkus-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 12153d4a..bdfb52a2 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ SPDX-License-Identifier: Apache-2.0 0.9.3 - 2.13.3.Final + 2.13.4.Final 2.3.7 3.0 2.0.3 From 58d41718e62e1c61e96f9590750bbb7fc391fe52 Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Tue, 8 Nov 2022 15:45:39 +0100 Subject: [PATCH 08/21] Added Websocket support for creating and updating the SCL File. Signed-off-by: Dennis Labordus --- app/pom.xml | 18 +- .../CompasSclDataServiceConfiguration.java | 4 +- .../CompasNoDataFoundExceptionHandler.java | 2 +- .../data/rest/v1/CompasCommonResource.java | 11 +- .../v1/CompasSclCreateServerEndpoint.java | 73 ++++++ .../data/rest/v1/CompasSclDataResource.java | 56 +++-- .../v1/CompasSclUpdateServerEndpoint.java | 78 +++++++ .../v1/event/CompasSclDataEventHandler.java | 46 ++++ .../rest/v1/event/CreateEventRequest.java | 50 ++++ .../rest/v1/event/UpdateEventRequest.java | 58 +++++ .../scl/data/rest/v1/model/CreateRequest.java | 2 + .../scl/data/rest/v1/model/UpdateRequest.java | 2 + .../v1/websocket/CreateRequestDecoder.java | 20 ++ .../v1/websocket/CreateRequestEncoder.java | 15 ++ .../v1/websocket/CreateResponseDecoder.java | 20 ++ .../v1/websocket/CreateResponseEncoder.java | 15 ++ .../v1/websocket/UpdateRequestDecoder.java | 20 ++ .../v1/websocket/UpdateRequestEncoder.java | 15 ++ .../v1/websocket/UpdateResponseDecoder.java | 20 ++ .../v1/websocket/UpdateResponseEncoder.java | 15 ++ app/src/main/resources/application.properties | 44 +++- ...CompasNoDataFoundExceptionHandlerTest.java | 2 +- .../AbstractServerEndpointAsReaderTest.java | 42 ++++ ...asSclCreateServerEndpointAsEditorTest.java | 89 ++++++++ ...asSclCreateServerEndpointAsReaderTest.java | 21 ++ .../v1/CompasSclDataResourceAsEditorTest.java | 7 +- .../v1/CompasSclDataResourceAsReaderTest.java | 7 +- ...asSclUpdateServerEndpointAsEditorTest.java | 93 ++++++++ ...asSclUpdateServerEndpointAsReaderTest.java | 23 ++ .../event/CompasSclDataEventHandlerTest.java | 214 ++++++++++++++++++ .../rest/v1/event/CreateEventRequestTest.java | 51 +++++ .../rest/v1/event/UpdateEventRequestTest.java | 55 +++++ .../websocket/CreateRequestDecoderTest.java | 61 +++++ .../websocket/CreateRequestEncoderTest.java | 51 +++++ .../websocket/CreateResponseDecoderTest.java | 55 +++++ .../websocket/CreateResponseEncoderTest.java | 45 ++++ .../websocket/UpdateRequestDecoderTest.java | 62 +++++ .../websocket/UpdateRequestEncoderTest.java | 52 +++++ .../websocket/UpdateResponseDecoderTest.java | 55 +++++ .../websocket/UpdateResponseEncoderTest.java | 45 ++++ pom.xml | 9 +- .../data/util/SclElementProcessorTest.java | 27 ++- 42 files changed, 1589 insertions(+), 61 deletions(-) create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpoint.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpoint.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandler.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequest.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequest.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoder.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsEditorTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsReaderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsEditorTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsReaderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandlerTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequestTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequestTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoderTest.java diff --git a/app/pom.xml b/app/pom.xml index 0926733c..5166dab1 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -50,7 +50,11 @@ SPDX-License-Identifier: Apache-2.0 org.lfenergy.compas.core - jaxrs-commons + rest-commons + + + org.lfenergy.compas.core + websocket-commons @@ -59,16 +63,17 @@ SPDX-License-Identifier: Apache-2.0 io.quarkus - quarkus-resteasy + quarkus-resteasy-reactive io.quarkus - quarkus-resteasy-jaxb + quarkus-resteasy-reactive-jaxb io.quarkus - quarkus-hibernate-validator + quarkus-websockets + io.quarkus quarkus-smallrye-jwt @@ -81,6 +86,11 @@ SPDX-License-Identifier: Apache-2.0 io.quarkus quarkus-smallrye-health + + + io.quarkus + quarkus-hibernate-validator + io.quarkus quarkus-agroal diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/CompasSclDataServiceConfiguration.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/CompasSclDataServiceConfiguration.java index 26f426b2..2054f037 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/CompasSclDataServiceConfiguration.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/CompasSclDataServiceConfiguration.java @@ -14,8 +14,8 @@ * Create Beans from other dependencies that are used in the application. */ @RegisterForReflection(targets = { - org.lfenergy.compas.core.jaxrs.model.ErrorResponse.class, - org.lfenergy.compas.core.jaxrs.model.ErrorMessage.class + org.lfenergy.compas.core.commons.model.ErrorResponse.class, + org.lfenergy.compas.core.commons.model.ErrorMessage.class }) public class CompasSclDataServiceConfiguration { @Produces diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/exception/CompasNoDataFoundExceptionHandler.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/exception/CompasNoDataFoundExceptionHandler.java index 3b7974e3..efee3683 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/exception/CompasNoDataFoundExceptionHandler.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/exception/CompasNoDataFoundExceptionHandler.java @@ -3,7 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 package org.lfenergy.compas.scl.data.rest.exception; -import org.lfenergy.compas.core.jaxrs.model.ErrorResponse; +import org.lfenergy.compas.core.commons.model.ErrorResponse; import org.lfenergy.compas.scl.data.exception.CompasNoDataFoundException; import javax.ws.rs.core.Response; diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasCommonResource.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasCommonResource.java index 79c5d6ef..4bec038e 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasCommonResource.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasCommonResource.java @@ -4,6 +4,7 @@ package org.lfenergy.compas.scl.data.rest.v1; import io.quarkus.security.Authenticated; +import io.smallrye.mutiny.Uni; import org.eclipse.microprofile.jwt.JsonWebToken; import org.lfenergy.compas.scl.data.rest.UserInfoProperties; import org.lfenergy.compas.scl.data.rest.v1.model.Type; @@ -40,10 +41,10 @@ public class CompasCommonResource { @GET @Path("/type/list") @Produces(MediaType.APPLICATION_XML) - public TypeListResponse list(@HeaderParam("Authorization") String authHeader) { + public Uni list(@HeaderParam("Authorization") String authHeader) { LOGGER.trace("Authorization Header '{}'", authHeader); - // Retrieve the roles the logged in user has. + // Retrieve the roles the logged-in user has. var roles = jsonWebToken.getGroups(); var response = new TypeListResponse(); @@ -54,19 +55,19 @@ public TypeListResponse list(@HeaderParam("Authorization") String authHeader) { .map(sclFileType -> new Type(sclFileType.name(), sclFileType.getDescription())) .sorted(Comparator.comparing(Type::getDescription)) .toList()); - return response; + return Uni.createFrom().item(response); } @GET @Path("/userinfo") @Produces(MediaType.APPLICATION_XML) - public UserInfoResponse getUserInfo(@HeaderParam("Authorization") String authHeader) { + public Uni getUserInfo(@HeaderParam("Authorization") String authHeader) { LOGGER.trace("Authorization Header '{}'", authHeader); var response = new UserInfoResponse(); response.setName(jsonWebToken.getClaim(userInfoProperties.name())); response.setSessionWarning(userInfoProperties.sessionWarning()); response.setSessionExpires(userInfoProperties.sessionExpires()); - return response; + return Uni.createFrom().item(response); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpoint.java new file mode 100644 index 00000000..e921dc16 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpoint.java @@ -0,0 +1,73 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1; + +import io.quarkus.security.Authenticated; +import io.vertx.mutiny.core.eventbus.EventBus; +import org.eclipse.microprofile.jwt.JsonWebToken; +import org.lfenergy.compas.core.websocket.ErrorResponseEncoder; +import org.lfenergy.compas.scl.data.rest.UserInfoProperties; +import org.lfenergy.compas.scl.data.rest.v1.event.CreateEventRequest; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest; +import org.lfenergy.compas.scl.data.rest.v1.websocket.CreateRequestDecoder; +import org.lfenergy.compas.scl.data.rest.v1.websocket.CreateResponseEncoder; +import org.lfenergy.compas.scl.extensions.model.SclFileType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.websocket.*; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; + +import static org.lfenergy.compas.scl.data.rest.Constants.TYPE_PATH_PARAM; + +@Authenticated +@ApplicationScoped +@ServerEndpoint(value = "/scl-ws/v1/{" + TYPE_PATH_PARAM + "}/create", + decoders = {CreateRequestDecoder.class}, + encoders = {CreateResponseEncoder.class, ErrorResponseEncoder.class}) +public class CompasSclCreateServerEndpoint { + private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclCreateServerEndpoint.class); + + private final EventBus eventBus; + + @Inject + JsonWebToken jsonWebToken; + + @Inject + UserInfoProperties userInfoProperties; + + @Inject + public CompasSclCreateServerEndpoint(EventBus eventBus) { + this.eventBus = eventBus; + } + + @OnOpen + public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.debug("Starting session {} for type {}.", session.getId(), type); + } + + @OnMessage + public void onCreateMessage(Session session, CreateRequest request, @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.info("Message from session {} for type {}.", session.getId(), type); + + String who = jsonWebToken.getClaim(userInfoProperties.who()); + LOGGER.trace("Username used for Who {}", who); + + eventBus.send("create-ws", new CreateEventRequest( + session, SclFileType.valueOf(type), request.getName(), who, request.getComment(), request.getSclData())); + } + + @OnError + public void onError(Session session, @PathParam(TYPE_PATH_PARAM) String type, Throwable throwable) { + LOGGER.warn("Error with session {} for type {}.", session.getId(), type, throwable); + } + + @OnClose + public void onClose(Session session, @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.debug("Closing session {} for type {}.", session.getId(), type); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResource.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResource.java index 1cf3c31e..8dbdcffe 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResource.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResource.java @@ -4,6 +4,8 @@ package org.lfenergy.compas.scl.data.rest.v1; import io.quarkus.security.Authenticated; +import io.smallrye.common.annotation.Blocking; +import io.smallrye.mutiny.Uni; import org.eclipse.microprofile.jwt.JsonWebToken; import org.lfenergy.compas.scl.data.model.Version; import org.lfenergy.compas.scl.data.rest.UserInfoProperties; @@ -42,89 +44,95 @@ public CompasSclDataResource(CompasSclDataService compasSclDataService) { } @POST + @Blocking @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) - public CreateResponse create(@PathParam(TYPE_PATH_PARAM) SclFileType type, - @Valid CreateRequest request) { + public Uni create(@PathParam(TYPE_PATH_PARAM) SclFileType type, + @Valid CreateRequest request) { String who = jsonWebToken.getClaim(userInfoProperties.who()); LOGGER.trace("Username used for Who {}", who); var response = new CreateResponse(); response.setSclData(compasSclDataService.create(type, request.getName(), who, request.getComment(), request.getSclData())); - return response; + return Uni.createFrom().item(response); } @GET @Path("/list") @Produces(MediaType.APPLICATION_XML) - public ListResponse list(@PathParam(TYPE_PATH_PARAM) SclFileType type) { + public Uni list(@PathParam(TYPE_PATH_PARAM) SclFileType type) { var response = new ListResponse(); response.setItems(compasSclDataService.list(type)); - return response; + return Uni.createFrom().item(response); } @GET @Path("/{" + ID_PATH_PARAM + "}/versions") @Produces(MediaType.APPLICATION_XML) - public VersionsResponse listVersionsByUUID(@PathParam(TYPE_PATH_PARAM) SclFileType type, - @PathParam(ID_PATH_PARAM) UUID id) { + public Uni listVersionsByUUID(@PathParam(TYPE_PATH_PARAM) SclFileType type, + @PathParam(ID_PATH_PARAM) UUID id) { var response = new VersionsResponse(); response.setItems(compasSclDataService.listVersionsByUUID(type, id)); - return response; + return Uni.createFrom().item(response); } @GET @Path("/{" + ID_PATH_PARAM + "}") @Produces(MediaType.APPLICATION_XML) - public GetResponse findByUUID(@PathParam(TYPE_PATH_PARAM) SclFileType type, - @PathParam(ID_PATH_PARAM) UUID id) { + public Uni findByUUID(@PathParam(TYPE_PATH_PARAM) SclFileType type, + @PathParam(ID_PATH_PARAM) UUID id) { var response = new GetResponse(); response.setSclData(compasSclDataService.findByUUID(type, id)); - return response; + return Uni.createFrom().item(response); } @GET @Path("/{" + ID_PATH_PARAM + "}/{" + VERSION_PATH_PARAM + "}") @Produces(MediaType.APPLICATION_XML) - public GetResponse findByUUIDAndVersion(@PathParam(TYPE_PATH_PARAM) SclFileType type, - @PathParam(ID_PATH_PARAM) UUID id, - @PathParam(VERSION_PATH_PARAM) Version version) { + public Uni findByUUIDAndVersion(@PathParam(TYPE_PATH_PARAM) SclFileType type, + @PathParam(ID_PATH_PARAM) UUID id, + @PathParam(VERSION_PATH_PARAM) Version version) { var response = new GetResponse(); response.setSclData(compasSclDataService.findByUUID(type, id, version)); - return response; + return Uni.createFrom().item(response); } @PUT + @Blocking @Path("/{" + ID_PATH_PARAM + "}") @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_XML) - public UpdateResponse update(@PathParam(TYPE_PATH_PARAM) SclFileType type, - @PathParam(ID_PATH_PARAM) UUID id, - @Valid UpdateRequest request) { + public Uni update(@PathParam(TYPE_PATH_PARAM) SclFileType type, + @PathParam(ID_PATH_PARAM) UUID id, + @Valid UpdateRequest request) { String who = jsonWebToken.getClaim(userInfoProperties.who()); LOGGER.trace("Username used for Who {}", who); var response = new UpdateResponse(); response.setSclData(compasSclDataService.update(type, id, request.getChangeSetType(), who, request.getComment(), request.getSclData())); - return response; + return Uni.createFrom().item(response); } @DELETE + @Blocking @Path("/{" + ID_PATH_PARAM + "}") @Produces(MediaType.APPLICATION_XML) - public void deleteAll(@PathParam(TYPE_PATH_PARAM) SclFileType type, - @PathParam(ID_PATH_PARAM) UUID id) { + public Uni deleteAll(@PathParam(TYPE_PATH_PARAM) SclFileType type, + @PathParam(ID_PATH_PARAM) UUID id) { compasSclDataService.delete(type, id); + return Uni.createFrom().nullItem(); } @DELETE + @Blocking @Path("/{" + ID_PATH_PARAM + "}/{" + VERSION_PATH_PARAM + "}") @Produces(MediaType.APPLICATION_XML) - public void deleteVersion(@PathParam(TYPE_PATH_PARAM) SclFileType type, - @PathParam(ID_PATH_PARAM) UUID id, - @PathParam(VERSION_PATH_PARAM) Version version) { + public Uni deleteVersion(@PathParam(TYPE_PATH_PARAM) SclFileType type, + @PathParam(ID_PATH_PARAM) UUID id, + @PathParam(VERSION_PATH_PARAM) Version version) { compasSclDataService.delete(type, id, version); + return Uni.createFrom().nullItem(); } } \ No newline at end of file diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpoint.java new file mode 100644 index 00000000..9143d60c --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpoint.java @@ -0,0 +1,78 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1; + +import io.quarkus.security.Authenticated; +import io.vertx.mutiny.core.eventbus.EventBus; +import org.eclipse.microprofile.jwt.JsonWebToken; +import org.lfenergy.compas.core.websocket.ErrorResponseEncoder; +import org.lfenergy.compas.scl.data.rest.UserInfoProperties; +import org.lfenergy.compas.scl.data.rest.v1.event.UpdateEventRequest; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest; +import org.lfenergy.compas.scl.data.rest.v1.websocket.UpdateRequestDecoder; +import org.lfenergy.compas.scl.data.rest.v1.websocket.UpdateResponseEncoder; +import org.lfenergy.compas.scl.extensions.model.SclFileType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.websocket.*; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; +import java.util.UUID; + +import static org.lfenergy.compas.scl.data.rest.Constants.ID_PATH_PARAM; +import static org.lfenergy.compas.scl.data.rest.Constants.TYPE_PATH_PARAM; + +@Authenticated +@ApplicationScoped +@ServerEndpoint(value = "/scl-ws/v1/{" + TYPE_PATH_PARAM + "}/update/{" + ID_PATH_PARAM + "}", + decoders = {UpdateRequestDecoder.class}, + encoders = {UpdateResponseEncoder.class, ErrorResponseEncoder.class}) +public class CompasSclUpdateServerEndpoint { + private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclUpdateServerEndpoint.class); + + private final EventBus eventBus; + + @Inject + JsonWebToken jsonWebToken; + + @Inject + UserInfoProperties userInfoProperties; + + @Inject + public CompasSclUpdateServerEndpoint(EventBus eventBus) { + this.eventBus = eventBus; + } + + @OnOpen + public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.debug("Starting session {} for type {}.", session.getId(), type); + } + + @OnMessage + public void onUpdateMessage(Session session, UpdateRequest request, + @PathParam(TYPE_PATH_PARAM) String type, + @PathParam(ID_PATH_PARAM) String id) { + LOGGER.info("Message from session {} for type {}.", session.getId(), type); + + String who = jsonWebToken.getClaim(userInfoProperties.who()); + LOGGER.trace("Username used for Who {}", who); + + eventBus.send("update-ws", new UpdateEventRequest( + session, SclFileType.valueOf(type), UUID.fromString(id), request.getChangeSetType(), + who, request.getComment(), request.getSclData())); + } + + @OnError + public void onError(Session session, @PathParam(TYPE_PATH_PARAM) String type, Throwable throwable) { + LOGGER.warn("Error with session {} for type {}.", session.getId(), type, throwable); + } + + @OnClose + public void onClose(Session session, @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.debug("Closing session {} for type {}.", session.getId(), type); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandler.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandler.java new file mode 100644 index 00000000..9dd1fa45 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandler.java @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.event; + +import io.quarkus.vertx.ConsumeEvent; +import org.lfenergy.compas.core.websocket.WebsocketHandler; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.service.CompasSclDataService; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +/** + * Event Handler used to execute the validation asynchronized. + */ +@ApplicationScoped +public class CompasSclDataEventHandler { + private final CompasSclDataService compasSclDataService; + + @Inject + public CompasSclDataEventHandler(CompasSclDataService compasSclDataService) { + this.compasSclDataService = compasSclDataService; + } + + @ConsumeEvent(value = "create-ws", blocking = true) + public void createWebsocketsEvent(CreateEventRequest request) { + new WebsocketHandler().execute(request.getSession(), () -> { + var response = new CreateResponse(); + response.setSclData(compasSclDataService.create(request.getType(), request.getName(), request.getWho(), + request.getComment(), request.getSclData())); + return response; + }); + } + + @ConsumeEvent(value = "update-ws", blocking = true) + public void updateWebsocketsEvent(UpdateEventRequest request) { + new WebsocketHandler().execute(request.getSession(), () -> { + var response = new UpdateResponse(); + response.setSclData(compasSclDataService.update(request.getType(), request.getId(), request.getChangeSetType(), + request.getWho(), request.getComment(), request.getSclData())); + return response; + }); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequest.java new file mode 100644 index 00000000..6965d752 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequest.java @@ -0,0 +1,50 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.event; + +import org.lfenergy.compas.scl.extensions.model.SclFileType; + +import javax.websocket.Session; + +public class CreateEventRequest { + private final Session session; + private final SclFileType type; + private final String name; + private final String who; + private final String comment; + private final String sclData; + + public CreateEventRequest(Session session, SclFileType type, String name, String who, String comment, String sclData) { + this.session = session; + this.type = type; + this.name = name; + this.who = who; + this.comment = comment; + this.sclData = sclData; + } + + public Session getSession() { + return session; + } + + public SclFileType getType() { + return type; + } + + public String getName() { + return name; + } + + public String getWho() { + return who; + } + + public String getComment() { + return comment; + } + + public String getSclData() { + return sclData; + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequest.java new file mode 100644 index 00000000..0bc694f3 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequest.java @@ -0,0 +1,58 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.event; + +import org.lfenergy.compas.scl.data.model.ChangeSetType; +import org.lfenergy.compas.scl.extensions.model.SclFileType; + +import javax.websocket.Session; +import java.util.UUID; + +public class UpdateEventRequest { + private final Session session; + private final SclFileType type; + private final UUID id; + private final ChangeSetType changeSetType; + private final String who; + private final String comment; + private final String sclData; + + public UpdateEventRequest(Session session, SclFileType type, UUID id, ChangeSetType changeSetType, String who, String comment, String sclData) { + this.session = session; + this.type = type; + this.id = id; + this.changeSetType = changeSetType; + this.who = who; + this.comment = comment; + this.sclData = sclData; + } + + public Session getSession() { + return session; + } + + public SclFileType getType() { + return type; + } + + public UUID getId() { + return id; + } + + public ChangeSetType getChangeSetType() { + return changeSetType; + } + + public String getWho() { + return who; + } + + public String getComment() { + return comment; + } + + public String getSclData() { + return sclData; + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java index 7b7889cb..117b35d5 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java @@ -7,6 +7,7 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.lfenergy.compas.core.commons.constraint.FilenameValid; +import javax.validation.constraints.NotBlank; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -30,6 +31,7 @@ public class CreateRequest { @Schema(description = "The XML Content of the SCL added as CDATA. The content should contain a XML according to the IEC 61850 standard.", example = "....]]") + @NotBlank @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI) private String sclData; diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java index c34016ee..f64bc37c 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java @@ -7,6 +7,7 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.lfenergy.compas.scl.data.model.ChangeSetType; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -32,6 +33,7 @@ public class UpdateRequest { @Schema(description = "The XML Content of the SCL added as CDATA. The content should contain a XML according to the IEC 61850 standard.", example = "....]]") + @NotBlank @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI) private String sclData; diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoder.java new file mode 100644 index 00000000..bdec45ec --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoder.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.lfenergy.compas.core.websocket.AbstractDecoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest; + +public class CreateRequestDecoder extends AbstractDecoder { + @Override + public boolean willDecode(String message) { + return (message != null); + } + + @Override + public CreateRequest decode(String message) { + return WebsocketSupport.decode(message, CreateRequest.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoder.java new file mode 100644 index 00000000..9d85a5a2 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoder.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.lfenergy.compas.core.websocket.AbstractEncoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest; + +public class CreateRequestEncoder extends AbstractEncoder { + @Override + public String encode(CreateRequest jaxbObject) { + return WebsocketSupport.encode(jaxbObject, CreateRequest.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoder.java new file mode 100644 index 00000000..e2c44374 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoder.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.lfenergy.compas.core.websocket.AbstractDecoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; + +public class CreateResponseDecoder extends AbstractDecoder { + @Override + public boolean willDecode(String message) { + return (message != null); + } + + @Override + public CreateResponse decode(String message) { + return WebsocketSupport.decode(message, CreateResponse.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoder.java new file mode 100644 index 00000000..7ca3a472 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoder.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.lfenergy.compas.core.websocket.AbstractEncoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; + +public class CreateResponseEncoder extends AbstractEncoder { + @Override + public String encode(CreateResponse jaxbObject) { + return WebsocketSupport.encode(jaxbObject, CreateResponse.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoder.java new file mode 100644 index 00000000..b193dcba --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoder.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.lfenergy.compas.core.websocket.AbstractDecoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest; + +public class UpdateRequestDecoder extends AbstractDecoder { + @Override + public boolean willDecode(String message) { + return (message != null); + } + + @Override + public UpdateRequest decode(String message) { + return WebsocketSupport.decode(message, UpdateRequest.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoder.java new file mode 100644 index 00000000..cb6782d9 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoder.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.lfenergy.compas.core.websocket.AbstractEncoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest; + +public class UpdateRequestEncoder extends AbstractEncoder { + @Override + public String encode(UpdateRequest jaxbObject) { + return WebsocketSupport.encode(jaxbObject, UpdateRequest.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoder.java new file mode 100644 index 00000000..a3c66156 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoder.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.lfenergy.compas.core.websocket.AbstractDecoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; + +public class UpdateResponseDecoder extends AbstractDecoder { + @Override + public boolean willDecode(String message) { + return (message != null); + } + + @Override + public UpdateResponse decode(String message) { + return WebsocketSupport.decode(message, UpdateResponse.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoder.java new file mode 100644 index 00000000..e223a01b --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoder.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.lfenergy.compas.core.websocket.AbstractEncoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; + +public class UpdateResponseEncoder extends AbstractEncoder { + @Override + public String encode(UpdateResponse jaxbObject) { + return WebsocketSupport.encode(jaxbObject, UpdateResponse.class); + } +} diff --git a/app/src/main/resources/application.properties b/app/src/main/resources/application.properties index bfdaef62..08342b81 100644 --- a/app/src/main/resources/application.properties +++ b/app/src/main/resources/application.properties @@ -15,8 +15,8 @@ quarkus.log.level = INFO quarkus.log.category."org.lfenergy.compas.scl.data".level = INFO # Add scanning these dependencies for scanning, also used by native compilation. -quarkus.index-dependency.jaxrs-commons.group-id = org.lfenergy.compas.core -quarkus.index-dependency.jaxrs-commons.artifact-id = jaxrs-commons +quarkus.index-dependency.rest-commons.group-id = org.lfenergy.compas.core +quarkus.index-dependency.rest-commons.artifact-id = rest-commons quarkus.index-dependency.scl-data-service.group-id = org.lfenergy.compas.scl.data quarkus.index-dependency.scl-data-service.artifact-id = service @@ -56,6 +56,11 @@ quarkus.http.auth.permission.SSD_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.SSD_DELETE_DELETE.policy=SSD_DELETE quarkus.http.auth.permission.SSD_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.SSD_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/SSD/create +quarkus.http.auth.permission.SSD_CREATE_POST_WS.policy=SSD_CREATE +quarkus.http.auth.permission.SSD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/SSD/update/* +quarkus.http.auth.permission.SSD_UPDATE_PUT_WS.policy=SSD_UPDATE + quarkus.http.auth.policy.IID_READ.roles-allowed=IID_READ quarkus.http.auth.permission.IID_READ_GET.paths=/compas-scl-data-service/scl/v1/IID/* quarkus.http.auth.permission.IID_READ_GET.policy=IID_READ @@ -73,6 +78,11 @@ quarkus.http.auth.permission.IID_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.IID_DELETE_DELETE.policy=IID_DELETE quarkus.http.auth.permission.IID_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.IID_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/IID/create +quarkus.http.auth.permission.IID_CREATE_POST_WS.policy=IID_CREATE +quarkus.http.auth.permission.IID_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/IID/update/* +quarkus.http.auth.permission.IID_UPDATE_PUT_WS.policy=IID_UPDATE + quarkus.http.auth.policy.ICD_READ.roles-allowed=ICD_READ quarkus.http.auth.permission.ICD_READ_GET.paths=/compas-scl-data-service/scl/v1/ICD/* quarkus.http.auth.permission.ICD_READ_GET.policy=ICD_READ @@ -90,6 +100,11 @@ quarkus.http.auth.permission.ICD_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.ICD_DELETE_DELETE.policy=ICD_DELETE quarkus.http.auth.permission.ICD_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.ICD_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/ICD/create +quarkus.http.auth.permission.ICD_CREATE_POST_WS.policy=ICD_CREATE +quarkus.http.auth.permission.ICD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/ICD/update/* +quarkus.http.auth.permission.ICD_UPDATE_PUT_WS.policy=ICD_UPDATE + quarkus.http.auth.policy.SCD_READ.roles-allowed=SCD_READ quarkus.http.auth.permission.SCD_READ_GET.paths=/compas-scl-data-service/scl/v1/SCD/* quarkus.http.auth.permission.SCD_READ_GET.policy=SCD_READ @@ -107,6 +122,11 @@ quarkus.http.auth.permission.SCD_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.SCD_DELETE_DELETE.policy=SCD_DELETE quarkus.http.auth.permission.SCD_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.SCD_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/SCD/create +quarkus.http.auth.permission.SCD_CREATE_POST_WS.policy=SCD_CREATE +quarkus.http.auth.permission.SCD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/SCD/update/* +quarkus.http.auth.permission.SCD_UPDATE_PUT_WS.policy=SCD_UPDATE + quarkus.http.auth.policy.CID_READ.roles-allowed=CID_READ quarkus.http.auth.permission.CID_READ_GET.paths=/compas-scl-data-service/scl/v1/CID/* quarkus.http.auth.permission.CID_READ_GET.policy=CID_READ @@ -124,6 +144,11 @@ quarkus.http.auth.permission.CID_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.CID_DELETE_DELETE.policy=CID_DELETE quarkus.http.auth.permission.CID_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.CID_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/CID/create +quarkus.http.auth.permission.CID_CREATE_POST_WS.policy=CID_CREATE +quarkus.http.auth.permission.CID_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/CID/update/* +quarkus.http.auth.permission.CID_UPDATE_PUT_WS.policy=CID_UPDATE + quarkus.http.auth.policy.SED_READ.roles-allowed=SED_READ quarkus.http.auth.permission.SED_READ_GET.paths=/compas-scl-data-service/scl/v1/SED/* quarkus.http.auth.permission.SED_READ_GET.policy=SED_READ @@ -141,6 +166,11 @@ quarkus.http.auth.permission.SED_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.SED_DELETE_DELETE.policy=SED_DELETE quarkus.http.auth.permission.SED_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.SED_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/SED/create +quarkus.http.auth.permission.SED_CREATE_POST_WS.policy=SED_CREATE +quarkus.http.auth.permission.SED_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/SED/update/* +quarkus.http.auth.permission.SED_UPDATE_PUT_WS.policy=SED_UPDATE + quarkus.http.auth.policy.ISD_READ.roles-allowed=ISD_READ quarkus.http.auth.permission.ISD_READ_GET.paths=/compas-scl-data-service/scl/v1/ISD/* quarkus.http.auth.permission.ISD_READ_GET.policy=ISD_READ @@ -158,6 +188,11 @@ quarkus.http.auth.permission.ISD_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.ISD_DELETE_DELETE.policy=ISD_DELETE quarkus.http.auth.permission.ISD_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.ISD_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/ISD/create +quarkus.http.auth.permission.ISD_CREATE_POST_WS.policy=ISD_CREATE +quarkus.http.auth.permission.ISD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/ISD/update/* +quarkus.http.auth.permission.ISD_UPDATE_PUT_WS.policy=ISD_UPDATE + quarkus.http.auth.policy.STD_READ.roles-allowed=STD_READ quarkus.http.auth.permission.STD_READ_GET.paths=/compas-scl-data-service/scl/v1/STD/* quarkus.http.auth.permission.STD_READ_GET.policy=STD_READ @@ -174,3 +209,8 @@ quarkus.http.auth.policy.STD_DELETE.roles-allowed=STD_DELETE quarkus.http.auth.permission.STD_DELETE_DELETE.paths=/compas-scl-data-service/scl/v1/STD/* quarkus.http.auth.permission.STD_DELETE_DELETE.policy=STD_DELETE quarkus.http.auth.permission.STD_DELETE_DELETE.methods=DELETE + +quarkus.http.auth.permission.STD_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/STD/create +quarkus.http.auth.permission.STD_CREATE_POST_WS.policy=STD_CREATE +quarkus.http.auth.permission.STD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/STD/update/* +quarkus.http.auth.permission.STD_UPDATE_PUT_WS.policy=STD_UPDATE diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/exception/CompasNoDataFoundExceptionHandlerTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/exception/CompasNoDataFoundExceptionHandlerTest.java index 80402ad1..40179946 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/exception/CompasNoDataFoundExceptionHandlerTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/exception/CompasNoDataFoundExceptionHandlerTest.java @@ -4,7 +4,7 @@ package org.lfenergy.compas.scl.data.rest.exception; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.core.jaxrs.model.ErrorResponse; +import org.lfenergy.compas.core.commons.model.ErrorResponse; import org.lfenergy.compas.scl.data.exception.CompasNoDataFoundException; import static javax.ws.rs.core.Response.Status.NOT_FOUND; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java new file mode 100644 index 00000000..e05b16ea --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1; + +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakeException; +import io.quarkus.test.security.TestSecurity; +import io.quarkus.test.security.jwt.Claim; +import io.quarkus.test.security.jwt.JwtSecurity; + +import javax.websocket.ClientEndpoint; +import javax.websocket.ContainerProvider; +import java.io.InterruptedIOException; +import java.net.URI; +import java.util.concurrent.ExecutionException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.lfenergy.compas.scl.data.rest.Constants.READ_ROLE; + +@TestSecurity(user = "test-editor", roles = {"SCD_" + READ_ROLE}) +@JwtSecurity(claims = { + // Default the claim "name" is configured for Who, so we will set this claim for the test. + @Claim(key = "name", value = CompasSclDataResourceAsEditorTest.USERNAME) +}) +public abstract class AbstractServerEndpointAsReaderTest { + protected void testWhenForbiddenToExecute(URI uri) { + var container = ContainerProvider.getWebSocketContainer(); + var exception = assertThrows(InterruptedIOException.class, () -> container.connectToServer(Client.class, uri)); + + assertEquals(exception.getSuppressed().length, 1); + assertEquals(exception.getSuppressed()[0].getClass(), ExecutionException.class); + assertEquals((exception.getSuppressed()[0]).getCause().getClass(), WebSocketClientHandshakeException.class); + var wschExp = (WebSocketClientHandshakeException) (exception.getSuppressed()[0]).getCause(); + assertEquals(wschExp.response().status(), HttpResponseStatus.FORBIDDEN); + } + + @ClientEndpoint() + private static class Client { + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsEditorTest.java new file mode 100644 index 00000000..a698b114 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsEditorTest.java @@ -0,0 +1,89 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1; + +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import io.quarkus.test.security.TestSecurity; +import io.quarkus.test.security.jwt.Claim; +import io.quarkus.test.security.jwt.JwtSecurity; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.rest.v1.websocket.CreateRequestEncoder; +import org.lfenergy.compas.scl.data.rest.v1.websocket.CreateResponseDecoder; +import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.extensions.model.SclFileType; + +import javax.websocket.ClientEndpoint; +import javax.websocket.ContainerProvider; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import java.io.IOException; +import java.net.URI; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.lfenergy.compas.scl.data.rest.Constants.CREATE_ROLE; +import static org.mockito.Mockito.*; + +@QuarkusTest +@TestSecurity(user = "test-editor", roles = {"SCD_" + CREATE_ROLE}) +@JwtSecurity(claims = { + // Default the claim "name" is configured for Who, so we will set this claim for the test. + @Claim(key = "name", value = CompasSclDataResourceAsEditorTest.USERNAME) +}) +class CompasSclCreateServerEndpointAsEditorTest { + private static final LinkedBlockingDeque sclDataQueue = new LinkedBlockingDeque<>(); + + @InjectMock + private CompasSclDataService service; + + @TestHTTPResource("/scl-ws/v1/SCD/create") + private URI uri; + + @Test + void createSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { + var encoder = new CreateRequestEncoder(); + var sclFileTye = SclFileType.SCD; + var name = "Some name"; + var comment = "Some comment"; + var sclData = readSCL(); + + var request = new CreateRequest(); + request.setName(name); + request.setComment(comment); + request.setSclData(sclData); + + when(service.create(sclFileTye, name, CompasSclDataResourceAsEditorTest.USERNAME, comment, sclData)) + .thenReturn(sclData); + + try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(Client.class, uri)) { + session.getAsyncRemote().sendText(encoder.encode(request)); + + var updatedSclData = sclDataQueue.poll(10, TimeUnit.SECONDS); + assertEquals(sclData, updatedSclData); + assertEquals(0, sclDataQueue.size()); + verify(service, times(1)).create(sclFileTye, name, CompasSclDataResourceAsEditorTest.USERNAME, comment, sclData); + } + } + + @ClientEndpoint(decoders = CreateResponseDecoder.class) + private static class Client { + @OnMessage + public void onMessage(CreateResponse response) { + sclDataQueue.add(response.getSclData()); + } + } + + private String readSCL() throws IOException { + try (var inputStream = getClass().getResourceAsStream("/scl/icd_import_ied_test.scd")) { + assert inputStream != null; + + return new String(inputStream.readAllBytes()); + } + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsReaderTest.java new file mode 100644 index 00000000..17b3a32a --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsReaderTest.java @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1; + +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +import java.net.URI; + +@QuarkusTest +class CompasSclCreateServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTest { + @TestHTTPResource("/scl-ws/v1/SCD/create") + private URI uri; + + @Test + void createSCL_WhenCalled_ThenExpectedResponseIsRetrieved() { + testWhenForbiddenToExecute(uri); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java index a50fb5df..d27ebf15 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java @@ -268,9 +268,10 @@ void deleteVersion_WhenCalled_ThenServiceCalled() { } private String readSCL() throws IOException { - var inputStream = getClass().getResourceAsStream("/scl/icd_import_ied_test.scd"); - assert inputStream != null; + try (var inputStream = getClass().getResourceAsStream("/scl/icd_import_ied_test.scd")) { + assert inputStream != null; - return new String(inputStream.readAllBytes()); + return new String(inputStream.readAllBytes()); + } } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java index 73cf38fd..f638417c 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java @@ -223,9 +223,10 @@ void deleteVersion_WhenCalled_ThenServiceCalled() { } private String readSCL() throws IOException { - var inputStream = getClass().getResourceAsStream("/scl/icd_import_ied_test.scd"); - assert inputStream != null; + try (var inputStream = getClass().getResourceAsStream("/scl/icd_import_ied_test.scd")) { + assert inputStream != null; - return new String(inputStream.readAllBytes()); + return new String(inputStream.readAllBytes()); + } } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsEditorTest.java new file mode 100644 index 00000000..3b90cc84 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsEditorTest.java @@ -0,0 +1,93 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1; + +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import io.quarkus.test.security.TestSecurity; +import io.quarkus.test.security.jwt.Claim; +import io.quarkus.test.security.jwt.JwtSecurity; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.model.ChangeSetType; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.rest.v1.websocket.UpdateRequestEncoder; +import org.lfenergy.compas.scl.data.rest.v1.websocket.UpdateResponseDecoder; +import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.extensions.model.SclFileType; + +import javax.websocket.ClientEndpoint; +import javax.websocket.ContainerProvider; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import java.io.IOException; +import java.net.URI; +import java.util.UUID; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.lfenergy.compas.scl.data.rest.Constants.UPDATE_ROLE; +import static org.mockito.Mockito.*; + +@QuarkusTest +@TestSecurity(user = "test-editor", roles = {"SCD_" + UPDATE_ROLE}) +@JwtSecurity(claims = { + // Default the claim "name" is configured for Who, so we will set this claim for the test. + @Claim(key = "name", value = CompasSclDataResourceAsEditorTest.USERNAME) +}) +class CompasSclUpdateServerEndpointAsEditorTest { + private static final LinkedBlockingDeque sclDataQueue = new LinkedBlockingDeque<>(); + + private static final String ID_VALUE = "9bb30944-8c85-4509-97ec-365381c355ef"; + + @InjectMock + private CompasSclDataService service; + + @TestHTTPResource("/scl-ws/v1/SCD/update/" + ID_VALUE) + private URI uri; + + @Test + void updateSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { + var encoder = new UpdateRequestEncoder(); + var sclFileTye = SclFileType.SCD; + var cst = ChangeSetType.PATCH; + var comment = "Some comment"; + var sclData = readSCL(); + + var request = new UpdateRequest(); + request.setChangeSetType(cst); + request.setComment(comment); + request.setSclData(sclData); + + when(service.update(sclFileTye, UUID.fromString(ID_VALUE), cst, CompasSclDataResourceAsEditorTest.USERNAME, comment, sclData)) + .thenReturn(sclData); + + try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(Client.class, uri)) { + session.getAsyncRemote().sendText(encoder.encode(request)); + + var updatedSclData = sclDataQueue.poll(10, TimeUnit.SECONDS); + assertEquals(sclData, updatedSclData); + assertEquals(0, sclDataQueue.size()); + verify(service, times(1)).update(sclFileTye, UUID.fromString(ID_VALUE), cst, CompasSclDataResourceAsEditorTest.USERNAME, comment, sclData); + } + } + + @ClientEndpoint(decoders = UpdateResponseDecoder.class) + private static class Client { + @OnMessage + public void onMessage(UpdateResponse response) { + sclDataQueue.add(response.getSclData()); + } + } + + private String readSCL() throws IOException { + try (var inputStream = getClass().getResourceAsStream("/scl/icd_import_ied_test.scd")) { + assert inputStream != null; + + return new String(inputStream.readAllBytes()); + } + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsReaderTest.java new file mode 100644 index 00000000..1565c843 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsReaderTest.java @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1; + +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; + +import java.net.URI; + +@QuarkusTest +class CompasSclUpdateServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTest { + private static final String ID_VALUE = "9bb30944-8c85-4509-97ec-365381c355ef"; + + @TestHTTPResource("/scl-ws/v1/SCD/update/" + ID_VALUE) + private URI uri; + + @Test + void createSCL_WhenCalled_ThenExpectedResponseIsRetrieved() { + testWhenForbiddenToExecute(uri); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandlerTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandlerTest.java new file mode 100644 index 00000000..626ecd3b --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandlerTest.java @@ -0,0 +1,214 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.event; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.lfenergy.compas.core.commons.exception.CompasException; +import org.lfenergy.compas.core.commons.model.ErrorResponse; +import org.lfenergy.compas.scl.data.model.ChangeSetType; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.extensions.model.SclFileType; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; + +import javax.websocket.RemoteEndpoint; +import javax.websocket.Session; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_GENERAL_ERROR_CODE; +import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.DUPLICATE_SCL_NAME_ERROR_CODE; +import static org.mockito.Mockito.*; + +@ExtendWith(MockitoExtension.class) +class CompasSclDataEventHandlerTest { + @Mock + private CompasSclDataService service; + + @InjectMocks + private CompasSclDataEventHandler eventHandler; + + @Test + void createWebsocketsEvent_WhenCalled_ThenCreateResponseReturned() { + var type = SclFileType.CID; + var name = "Some name"; + var who = "Who executed it"; + var comment = "Some comment"; + var sclData = "Some SCL Data"; + + var session = Mockito.mock(Session.class); + var async = Mockito.mock(RemoteEndpoint.Async.class); + when(session.getAsyncRemote()).thenReturn(async); + var request = new CreateEventRequest(session, type, name, who, comment, sclData); + + when(service.create(type, name, who, comment, sclData)).thenReturn(sclData); + + eventHandler.createWebsocketsEvent(request); + + verify(session, times(1)).getAsyncRemote(); + ArgumentCaptor captor = ArgumentCaptor.forClass(CreateResponse.class); + verify(async, times(1)).sendObject(captor.capture()); + var response = captor.getValue(); + assertEquals(sclData, response.getSclData()); + + verify(service, times(1)).create(type, name, who, comment, sclData); + } + + @Test + void createWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenErrorResponseReturned() { + var type = SclFileType.CID; + var name = "Some name"; + var who = "Who executed it"; + var comment = "Some comment"; + var sclData = "Some SCL Data"; + var errorMessage = "Some Error"; + + var session = Mockito.mock(Session.class); + var async = Mockito.mock(RemoteEndpoint.Async.class); + when(session.getAsyncRemote()).thenReturn(async); + var request = new CreateEventRequest(session, type, name, who, comment, sclData); + + when(service.create(type, name, who, comment, sclData)) + .thenThrow(new CompasException(DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage)); + + eventHandler.createWebsocketsEvent(request); + + verify(session, times(1)).getAsyncRemote(); + ArgumentCaptor captor = ArgumentCaptor.forClass(ErrorResponse.class); + verify(async, times(1)).sendObject(captor.capture()); + var response = captor.getValue(); + assertEquals(1, response.getErrorMessages().size()); + var message = response.getErrorMessages().get(0); + assertEquals(DUPLICATE_SCL_NAME_ERROR_CODE, message.getCode()); + assertEquals(errorMessage, message.getMessage()); + + verify(service, times(1)).create(type, name, who, comment, sclData); + } + + @Test + void createWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErrorResponseReturned() { + var type = SclFileType.CID; + var name = "Some name"; + var who = "Who executed it"; + var comment = "Some comment"; + var sclData = "Some SCL Data"; + var errorMessage = "Some Error"; + + var session = Mockito.mock(Session.class); + var async = Mockito.mock(RemoteEndpoint.Async.class); + when(session.getAsyncRemote()).thenReturn(async); + var request = new CreateEventRequest(session, type, name, who, comment, sclData); + + when(service.create(type, name, who, comment, sclData)).thenThrow(new RuntimeException(errorMessage)); + + eventHandler.createWebsocketsEvent(request); + + verify(session, times(1)).getAsyncRemote(); + ArgumentCaptor captor = ArgumentCaptor.forClass(ErrorResponse.class); + verify(async, times(1)).sendObject(captor.capture()); + var response = captor.getValue(); + assertEquals(1, response.getErrorMessages().size()); + var message = response.getErrorMessages().get(0); + assertEquals(WEBSOCKET_GENERAL_ERROR_CODE, message.getCode()); + assertEquals(errorMessage, message.getMessage()); + + verify(service, times(1)).create(type, name, who, comment, sclData); + } + + @Test + void updateWebsocketsEvent_WhenCalled_ThenUpdateResponseReturned() { + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var cst = ChangeSetType.MINOR; + var who = "Who executed it"; + var comment = "Some comment"; + var sclData = "Some SCL Data"; + + var session = Mockito.mock(Session.class); + var async = Mockito.mock(RemoteEndpoint.Async.class); + when(session.getAsyncRemote()).thenReturn(async); + var request = new UpdateEventRequest(session, type, id, cst, who, comment, sclData); + + when(service.update(type, id, cst, who, comment, sclData)).thenReturn(sclData); + + eventHandler.updateWebsocketsEvent(request); + + verify(session, times(1)).getAsyncRemote(); + ArgumentCaptor captor = ArgumentCaptor.forClass(UpdateResponse.class); + verify(async, times(1)).sendObject(captor.capture()); + var response = captor.getValue(); + assertEquals(sclData, response.getSclData()); + + verify(service, times(1)).update(type, id, cst, who, comment, sclData); + } + + @Test + void updateWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenErrorResponseReturned() { + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var cst = ChangeSetType.MINOR; + var who = "Who executed it"; + var comment = "Some comment"; + var sclData = "Some SCL Data"; + var errorMessage = "Some Error"; + + var session = Mockito.mock(Session.class); + var async = Mockito.mock(RemoteEndpoint.Async.class); + when(session.getAsyncRemote()).thenReturn(async); + var request = new UpdateEventRequest(session, type, id, cst, who, comment, sclData); + + when(service.update(type, id, cst, who, comment, sclData)) + .thenThrow(new CompasException(DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage)); + + eventHandler.updateWebsocketsEvent(request); + + verify(session, times(1)).getAsyncRemote(); + ArgumentCaptor captor = ArgumentCaptor.forClass(ErrorResponse.class); + verify(async, times(1)).sendObject(captor.capture()); + var response = captor.getValue(); + assertEquals(1, response.getErrorMessages().size()); + var message = response.getErrorMessages().get(0); + assertEquals(DUPLICATE_SCL_NAME_ERROR_CODE, message.getCode()); + assertEquals(errorMessage, message.getMessage()); + + verify(service, times(1)).update(type, id, cst, who, comment, sclData); + } + + @Test + void updateWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErrorResponseReturned() { + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var cst = ChangeSetType.MINOR; + var who = "Who executed it"; + var comment = "Some comment"; + var sclData = "Some SCL Data"; + var errorMessage = "Some Error"; + + var session = Mockito.mock(Session.class); + var async = Mockito.mock(RemoteEndpoint.Async.class); + when(session.getAsyncRemote()).thenReturn(async); + var request = new UpdateEventRequest(session, type, id, cst, who, comment, sclData); + + when(service.update(type, id, cst, who, comment, sclData)).thenThrow(new RuntimeException(errorMessage)); + + eventHandler.updateWebsocketsEvent(request); + + verify(session, times(1)).getAsyncRemote(); + ArgumentCaptor captor = ArgumentCaptor.forClass(ErrorResponse.class); + verify(async, times(1)).sendObject(captor.capture()); + var response = captor.getValue(); + assertEquals(1, response.getErrorMessages().size()); + var message = response.getErrorMessages().get(0); + assertEquals(WEBSOCKET_GENERAL_ERROR_CODE, message.getCode()); + assertEquals(errorMessage, message.getMessage()); + + verify(service, times(1)).update(type, id, cst, who, comment, sclData); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequestTest.java new file mode 100644 index 00000000..8489d792 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequestTest.java @@ -0,0 +1,51 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.event; + +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.extensions.model.SclFileType; +import org.mockito.Mockito; + +import javax.websocket.Session; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class CreateEventRequestTest { + @Test + void constructor_WhenCalledWith3Arguments_ThenValuesSet() { + var session = Mockito.mock(Session.class); + var type = SclFileType.CID; + var name = "Some name"; + var who = "Who executed it"; + var comment = "Some comment"; + var sclData = "Some SCL Data"; + + var result = new CreateEventRequest(session, type, name, who, comment, sclData); + + assertEquals(session, result.getSession()); + assertEquals(type, result.getType()); + assertEquals(name, result.getName()); + assertEquals(who, result.getWho()); + assertEquals(comment, result.getComment()); + assertEquals(sclData, result.getSclData()); + } + + @Test + void validateSettersAndGetters() { + var personPojo = PojoClassFactory.getPojoClass(CreateEventRequest.class); + var validator = ValidatorBuilder.create() + // Let's make sure that we have a getter for every field defined. + .with(new GetterMustExistRule()) + // Let's also validate that they are behaving as expected + .with(new GetterTester()) + .build(); + + // Start the Test + validator.validate(personPojo); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequestTest.java new file mode 100644 index 00000000..fb57933e --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequestTest.java @@ -0,0 +1,55 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.event; + +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.model.ChangeSetType; +import org.lfenergy.compas.scl.extensions.model.SclFileType; +import org.mockito.Mockito; + +import javax.websocket.Session; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class UpdateEventRequestTest { + @Test + void constructor_WhenCalledWith3Arguments_ThenValuesSet() { + var session = Mockito.mock(Session.class); + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var changeSetType = ChangeSetType.MAJOR; + var who = "Who executed it"; + var comment = "Some comment"; + var sclData = "Some SCL Data"; + + var result = new UpdateEventRequest(session, type, id, changeSetType, who, comment, sclData); + + assertEquals(session, result.getSession()); + assertEquals(type, result.getType()); + assertEquals(id, result.getId()); + assertEquals(changeSetType, result.getChangeSetType()); + assertEquals(who, result.getWho()); + assertEquals(comment, result.getComment()); + assertEquals(sclData, result.getSclData()); + } + + @Test + void validateSettersAndGetters() { + var personPojo = PojoClassFactory.getPojoClass(UpdateEventRequest.class); + var validator = ValidatorBuilder.create() + // Let's make sure that we have a getter for every field defined. + .with(new GetterMustExistRule()) + // Let's also validate that they are behaving as expected + .with(new GetterTester()) + .build(); + + // Start the Test + validator.validate(personPojo); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoderTest.java new file mode 100644 index 00000000..764edad9 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoderTest.java @@ -0,0 +1,61 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.core.commons.exception.CompasException; + +import javax.xml.bind.UnmarshalException; + +import static org.junit.jupiter.api.Assertions.*; +import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class CreateRequestDecoderTest { + private CreateRequestDecoder decoder; + + @BeforeEach + void init() { + decoder = new CreateRequestDecoder(); + decoder.init(null); + } + + @Test + void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { + var sclData = "Some SCL Data"; + var name = "Some name"; + var comment = "Some comment"; + var message = "" + + "" + + "" + name + "" + + "" + comment + "" + + "" + + ""; + + var result = decoder.decode(message); + + assertNotNull(result); + assertEquals(name, result.getName()); + assertEquals(comment, result.getComment()); + assertEquals(sclData, result.getSclData()); + } + + @Test + void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { + var message = "" + + "" + + ""; + + var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); + assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); + assertEquals(UnmarshalException.class, exception.getCause().getClass()); + } + + @AfterEach + void destroy() { + decoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoderTest.java new file mode 100644 index 00000000..53c977a5 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoderTest.java @@ -0,0 +1,51 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class CreateRequestEncoderTest { + private CreateRequestEncoder encoder; + + @BeforeEach + void init() { + encoder = new CreateRequestEncoder(); + encoder.init(null); + } + + @Test + void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { + var sclData = "Some SCL Data"; + var name = "Some name"; + var comment = "Some comment"; + + var request = new CreateRequest(); + request.setName(name); + request.setComment(comment); + request.setSclData(sclData); + + var result = encoder.encode(request); + + var expectedResult = "" + + "" + + "" + name + "" + + "" + comment + "" + + "" + sclData + "" + + ""; + assertNotNull(result); + assertEquals(expectedResult, result); + } + + @AfterEach + void destroy() { + encoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoderTest.java new file mode 100644 index 00000000..f6d3221e --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoderTest.java @@ -0,0 +1,55 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.core.commons.exception.CompasException; + +import javax.xml.bind.UnmarshalException; + +import static org.junit.jupiter.api.Assertions.*; +import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class CreateResponseDecoderTest { + private CreateResponseDecoder decoder; + + @BeforeEach + void init() { + decoder = new CreateResponseDecoder(); + decoder.init(null); + } + + @Test + void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { + var sclData = "Some SCL Data"; + var message = "" + + "" + + "" + + ""; + + var result = decoder.decode(message); + + assertNotNull(result); + assertEquals(sclData, result.getSclData()); + } + + @Test + void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { + var message = "" + + "" + + ""; + + var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); + assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); + assertEquals(UnmarshalException.class, exception.getCause().getClass()); + } + + @AfterEach + void destroy() { + decoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoderTest.java new file mode 100644 index 00000000..0f84d24f --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoderTest.java @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class CreateResponseEncoderTest { + private CreateResponseEncoder encoder; + + @BeforeEach + void init() { + encoder = new CreateResponseEncoder(); + encoder.init(null); + } + + @Test + void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { + var sclData = "Some SCL Data"; + + var request = new CreateResponse(); + request.setSclData(sclData); + + var result = encoder.encode(request); + + var expectedResult = "" + + "" + + "" + sclData + "" + + ""; + assertNotNull(result); + assertEquals(expectedResult, result); + } + + @AfterEach + void destroy() { + encoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoderTest.java new file mode 100644 index 00000000..d321bdf9 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoderTest.java @@ -0,0 +1,62 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.core.commons.exception.CompasException; +import org.lfenergy.compas.scl.data.model.ChangeSetType; + +import javax.xml.bind.UnmarshalException; + +import static org.junit.jupiter.api.Assertions.*; +import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class UpdateRequestDecoderTest { + private UpdateRequestDecoder decoder; + + @BeforeEach + void init() { + decoder = new UpdateRequestDecoder(); + decoder.init(null); + } + + @Test + void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { + var sclData = "Some SCL Data"; + var cst = ChangeSetType.MAJOR; + var comment = "Some comment"; + var message = "" + + "" + + "" + cst + "" + + "" + comment + "" + + "" + + ""; + + var result = decoder.decode(message); + + assertNotNull(result); + assertEquals(cst, result.getChangeSetType()); + assertEquals(comment, result.getComment()); + assertEquals(sclData, result.getSclData()); + } + + @Test + void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { + var message = "" + + "" + + ""; + + var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); + assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); + assertEquals(UnmarshalException.class, exception.getCause().getClass()); + } + + @AfterEach + void destroy() { + decoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoderTest.java new file mode 100644 index 00000000..79d2cfed --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoderTest.java @@ -0,0 +1,52 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.model.ChangeSetType; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class UpdateRequestEncoderTest { + private UpdateRequestEncoder encoder; + + @BeforeEach + void init() { + encoder = new UpdateRequestEncoder(); + encoder.init(null); + } + + @Test + void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { + var sclData = "Some SCL Data"; + var cst = ChangeSetType.MAJOR; + var comment = "Some comment"; + + var request = new UpdateRequest(); + request.setChangeSetType(cst); + request.setComment(comment); + request.setSclData(sclData); + + var result = encoder.encode(request); + + var expectedResult = "" + + "" + + "" + cst + "" + + "" + comment + "" + + "" + sclData + "" + + ""; + assertNotNull(result); + assertEquals(expectedResult, result); + } + + @AfterEach + void destroy() { + encoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoderTest.java new file mode 100644 index 00000000..b6c3ee3f --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoderTest.java @@ -0,0 +1,55 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.core.commons.exception.CompasException; + +import javax.xml.bind.UnmarshalException; + +import static org.junit.jupiter.api.Assertions.*; +import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class UpdateResponseDecoderTest { + private UpdateResponseDecoder decoder; + + @BeforeEach + void init() { + decoder = new UpdateResponseDecoder(); + decoder.init(null); + } + + @Test + void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { + var sclData = "Some SCL Data"; + var message = "" + + "" + + "" + + ""; + + var result = decoder.decode(message); + + assertNotNull(result); + assertEquals(sclData, result.getSclData()); + } + + @Test + void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { + var message = "" + + "" + + ""; + + var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); + assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); + assertEquals(UnmarshalException.class, exception.getCause().getClass()); + } + + @AfterEach + void destroy() { + decoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoderTest.java new file mode 100644 index 00000000..3ae446bc --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoderTest.java @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.rest.v1.websocket; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class UpdateResponseEncoderTest { + private UpdateResponseEncoder encoder; + + @BeforeEach + void init() { + encoder = new UpdateResponseEncoder(); + encoder.init(null); + } + + @Test + void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { + var sclData = "Some SCL Data"; + + var request = new UpdateResponse(); + request.setSclData(sclData); + + var result = encoder.encode(request); + + var expectedResult = "" + + "" + + "" + sclData + "" + + ""; + assertNotNull(result); + assertEquals(expectedResult, result); + } + + @AfterEach + void destroy() { + encoder.destroy(); + } +} diff --git a/pom.xml b/pom.xml index 12153d4a..f5abe1ae 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ SPDX-License-Identifier: Apache-2.0 3.0.0-M7 3.2.0 - 0.9.3 + 0.10.0 2.13.3.Final 2.3.7 @@ -99,7 +99,12 @@ SPDX-License-Identifier: Apache-2.0 org.lfenergy.compas.core - jaxrs-commons + rest-commons + ${compas.core.version} + + + org.lfenergy.compas.core + websocket-commons ${compas.core.version} diff --git a/repository/src/test/java/org/lfenergy/compas/scl/data/util/SclElementProcessorTest.java b/repository/src/test/java/org/lfenergy/compas/scl/data/util/SclElementProcessorTest.java index d5930ffc..0191a302 100644 --- a/repository/src/test/java/org/lfenergy/compas/scl/data/util/SclElementProcessorTest.java +++ b/repository/src/test/java/org/lfenergy/compas/scl/data/util/SclElementProcessorTest.java @@ -202,40 +202,39 @@ void cleanupHistoryItem_WhenCalledWithVersion_ThenSameAndNewerVersionsAreRemoved @Test void shouldRemoveHItem_WhenCalledWithInvalidVersion_ThenFalseReturned() { - var scl = readSCL("scl_cleanup_history.scd"); - var hItem = getHItem(scl, "Siemens"); - - assertFalse(processor.shouldRemoveHItem(hItem, new Version("1.0.2"))); + executeShouldRemoveHItemWhenCalledThenFalseReturned("Siemens"); } @Test void shouldRemoveHItem_WhenCalledWithEmptyVersion_ThenFalseReturned() { - var scl = readSCL("scl_cleanup_history.scd"); - var hItem = getHItem(scl, "Empty"); - - assertFalse(processor.shouldRemoveHItem(hItem, new Version("1.0.2"))); + executeShouldRemoveHItemWhenCalledThenFalseReturned("Empty"); } @Test void shouldRemoveHItem_WhenCalledWithOlderVersion_ThenFalseReturned() { + executeShouldRemoveHItemWhenCalledThenFalseReturned("Created"); + } + + private void executeShouldRemoveHItemWhenCalledThenFalseReturned(String what) { var scl = readSCL("scl_cleanup_history.scd"); - var hItem = getHItem(scl, "Created"); + var hItem = getHItem(scl, what); assertFalse(processor.shouldRemoveHItem(hItem, new Version("1.0.2"))); } @Test void shouldRemoveHItem_WhenCalledWithSameVersion_ThenTrueReturned() { - var scl = readSCL("scl_cleanup_history.scd"); - var hItem = getHItem(scl, "Updated 1"); - - assertTrue(processor.shouldRemoveHItem(hItem, new Version("1.0.2"))); + executeShouldRemoveHItemWhenCalledThenTrueReturned("Updated 1"); } @Test void shouldRemoveHItem_WhenCalledWithNewerVersion_ThenTrueReturned() { + executeShouldRemoveHItemWhenCalledThenTrueReturned("Updated 2"); + } + + private void executeShouldRemoveHItemWhenCalledThenTrueReturned(String what) { var scl = readSCL("scl_cleanup_history.scd"); - var hItem = getHItem(scl, "Updated 2"); + var hItem = getHItem(scl, what); assertTrue(processor.shouldRemoveHItem(hItem, new Version("1.0.2"))); } From a6cd02ab608b330add6195f894557836802f7727 Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Tue, 8 Nov 2022 15:54:44 +0100 Subject: [PATCH 09/21] Fixed sonar issue. Signed-off-by: Dennis Labordus --- .../data/rest/v1/AbstractServerEndpointAsReaderTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java index e05b16ea..058623f3 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java @@ -29,11 +29,11 @@ protected void testWhenForbiddenToExecute(URI uri) { var container = ContainerProvider.getWebSocketContainer(); var exception = assertThrows(InterruptedIOException.class, () -> container.connectToServer(Client.class, uri)); - assertEquals(exception.getSuppressed().length, 1); - assertEquals(exception.getSuppressed()[0].getClass(), ExecutionException.class); - assertEquals((exception.getSuppressed()[0]).getCause().getClass(), WebSocketClientHandshakeException.class); + assertEquals(1, exception.getSuppressed().length); + assertEquals(ExecutionException.class, exception.getSuppressed()[0].getClass()); + assertEquals(WebSocketClientHandshakeException.class, (exception.getSuppressed()[0]).getCause().getClass()); var wschExp = (WebSocketClientHandshakeException) (exception.getSuppressed()[0]).getCause(); - assertEquals(wschExp.response().status(), HttpResponseStatus.FORBIDDEN); + assertEquals(HttpResponseStatus.FORBIDDEN, wschExp.response().status()); } @ClientEndpoint() From dc5a2cf132fa750983796913f0293429f2f3ec4d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Nov 2022 11:07:05 +0000 Subject: [PATCH 10/21] Bump ubi8/ubi-minimal from 8.6 to 8.7 in /app/src/main/docker Bumps ubi8/ubi-minimal from 8.6 to 8.7. --- updated-dependencies: - dependency-name: ubi8/ubi-minimal dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- app/src/main/docker/Dockerfile-basex.jvm | 2 +- app/src/main/docker/Dockerfile-basex.native | 2 +- app/src/main/docker/Dockerfile-postgresql.jvm | 2 +- app/src/main/docker/Dockerfile-postgresql.native | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/docker/Dockerfile-basex.jvm b/app/src/main/docker/Dockerfile-basex.jvm index 0e014d4f..e64be699 100644 --- a/app/src/main/docker/Dockerfile-basex.jvm +++ b/app/src/main/docker/Dockerfile-basex.jvm @@ -21,7 +21,7 @@ # docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/app-jvm # ### -FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6 +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7 ARG JAVA_PACKAGE=java-17-openjdk-headless ARG RUN_JAVA_VERSION=1.3.8 diff --git a/app/src/main/docker/Dockerfile-basex.native b/app/src/main/docker/Dockerfile-basex.native index 51548a10..6f39b21f 100644 --- a/app/src/main/docker/Dockerfile-basex.native +++ b/app/src/main/docker/Dockerfile-basex.native @@ -14,7 +14,7 @@ # docker run -i --rm -p 8080:8080 quarkus/app # ### -FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6 +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7 WORKDIR /work/ RUN chown 1001 /work \ && chmod "g+rwX" /work \ diff --git a/app/src/main/docker/Dockerfile-postgresql.jvm b/app/src/main/docker/Dockerfile-postgresql.jvm index 2781babf..6f53f4eb 100644 --- a/app/src/main/docker/Dockerfile-postgresql.jvm +++ b/app/src/main/docker/Dockerfile-postgresql.jvm @@ -21,7 +21,7 @@ # docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" quarkus/app-jvm # ### -FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6 +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7 ARG JAVA_PACKAGE=java-17-openjdk-headless ARG RUN_JAVA_VERSION=1.3.8 diff --git a/app/src/main/docker/Dockerfile-postgresql.native b/app/src/main/docker/Dockerfile-postgresql.native index 4853d8c1..89b835e6 100644 --- a/app/src/main/docker/Dockerfile-postgresql.native +++ b/app/src/main/docker/Dockerfile-postgresql.native @@ -14,7 +14,7 @@ # docker run -i --rm -p 8080:8080 quarkus/app # ### -FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6 +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7 WORKDIR /work/ RUN chown 1001 /work \ && chmod "g+rwX" /work \ From b90cd0d721343ffd0f4748c1f374c54a411da7e3 Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Wed, 9 Nov 2022 17:36:14 +0100 Subject: [PATCH 11/21] Split rest and websocket implementations between 2 packages, different models. And also add 2 get websocket endpoints. Signed-off-by: Dennis Labordus --- .../event/CompasSclDataEventHandler.java | 29 ++- .../event/model}/CreateEventRequest.java | 2 +- .../event/model/GetEventRequest.java | 33 +++ .../event/model/GetVersionEventRequest.java | 40 ++++ .../event/model}/UpdateEventRequest.java | 2 +- .../v1/CompasSclCreateServerEndpoint.java | 24 +- .../v1/CompasSclGetServerEndpoint.java | 63 ++++++ .../v1/CompasSclGetVersionServerEndpoint.java | 65 ++++++ .../v1/CompasSclUpdateServerEndpoint.java | 33 ++- .../v1/decoder}/CreateRequestDecoder.java | 4 +- .../v1/decoder}/CreateResponseDecoder.java | 4 +- .../v1/decoder/GetRequestDecoder.java | 20 ++ .../v1/decoder/GetResponseDecoder.java | 20 ++ .../v1/decoder/GetVersionRequestDecoder.java | 20 ++ .../v1/decoder}/UpdateRequestDecoder.java | 4 +- .../v1/decoder}/UpdateResponseDecoder.java | 4 +- .../v1/encoder}/CreateRequestEncoder.java | 4 +- .../v1/encoder}/CreateResponseEncoder.java | 4 +- .../v1/encoder/GetRequestEncoder.java | 15 ++ .../v1/encoder/GetResponseEncoder.java | 15 ++ .../v1/encoder/GetVersionRequestEncoder.java | 15 ++ .../v1/encoder}/UpdateRequestEncoder.java | 4 +- .../v1/encoder}/UpdateResponseEncoder.java | 4 +- .../websocket/v1/model/CreateRequest.java | 60 +++++ .../websocket/v1/model/CreateResponse.java | 29 +++ .../data/websocket/v1/model/GetRequest.java | 31 +++ .../data/websocket/v1/model/GetResponse.java | 30 +++ .../websocket/v1/model/GetVersionRequest.java | 44 ++++ .../websocket/v1/model/UpdateRequest.java | 75 +++++++ .../websocket/v1/model/UpdateResponse.java | 30 +++ .../data/websocket/v1/model/package-info.java | 10 + app/src/main/resources/application.properties | 48 +++- .../rest/v1/model/AbstractPojoTester.java | 4 +- .../event/CompasSclDataEventHandlerTest.java | 212 ++++++++++++------ .../event/model}/CreateEventRequestTest.java | 2 +- .../event/model/GetEventRequestTest.java | 46 ++++ .../model/GetVersionEventRequestTest.java | 49 ++++ .../event/model}/UpdateEventRequestTest.java | 2 +- .../AbstractServerEndpointAsReaderTest.java | 10 +- ...asSclCreateServerEndpointAsEditorTest.java | 20 +- ...asSclCreateServerEndpointAsReaderTest.java | 2 +- ...asSclUpdateServerEndpointAsEditorTest.java | 24 +- ...asSclUpdateServerEndpointAsReaderTest.java | 6 +- .../v1/decoder}/CreateRequestDecoderTest.java | 10 +- .../decoder}/CreateResponseDecoderTest.java | 10 +- .../v1/decoder/GetRequestDecoderTest.java | 56 +++++ .../v1/decoder/GetResponseDecoderTest.java | 55 +++++ .../decoder/GetVersionRequestDecoderTest.java | 60 +++++ .../v1/decoder}/UpdateRequestDecoderTest.java | 14 +- .../decoder}/UpdateResponseDecoderTest.java | 10 +- .../v1/encoder}/CreateRequestEncoderTest.java | 8 +- .../encoder}/CreateResponseEncoderTest.java | 8 +- .../v1/encoder/GetRequestEncoderTest.java | 47 ++++ .../v1/encoder/GetResponseEncoderTest.java | 45 ++++ .../encoder/GetVersionRequestEncoderTest.java | 51 +++++ .../v1/encoder}/UpdateRequestEncoderTest.java | 13 +- .../encoder}/UpdateResponseEncoderTest.java | 8 +- .../v1/model/AbstractPojoTester.java | 32 +++ .../websocket/v1/model/CreateRequestTest.java | 11 + .../v1/model/CreateResponseTest.java | 11 + .../websocket/v1/model/GetRequestTest.java | 11 + .../websocket/v1/model/GetResponseTest.java | 11 + .../v1/model/GetVersionRequestTest.java | 11 + .../websocket/v1/model/UpdateRequestTest.java | 11 + .../v1/model/UpdateResponseTest.java | 11 + 65 files changed, 1466 insertions(+), 200 deletions(-) rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1 => websocket}/event/CompasSclDataEventHandler.java (55%) rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1/event => websocket/event/model}/CreateEventRequest.java (94%) create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/GetEventRequest.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/GetVersionEventRequest.java rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1/event => websocket/event/model}/UpdateEventRequest.java (95%) rename app/src/main/java/org/lfenergy/compas/scl/data/{rest => websocket}/v1/CompasSclCreateServerEndpoint.java (75%) create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java rename app/src/main/java/org/lfenergy/compas/scl/data/{rest => websocket}/v1/CompasSclUpdateServerEndpoint.java (72%) rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/decoder}/CreateRequestDecoder.java (80%) rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/decoder}/CreateResponseDecoder.java (80%) create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoder.java rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/decoder}/UpdateRequestDecoder.java (80%) rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/decoder}/UpdateResponseDecoder.java (80%) rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/encoder}/CreateRequestEncoder.java (77%) rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/encoder}/CreateResponseEncoder.java (77%) create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoder.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoder.java rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/encoder}/UpdateRequestEncoder.java (77%) rename app/src/main/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/encoder}/UpdateResponseEncoder.java (77%) create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequest.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequest.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/package-info.java rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1 => websocket}/event/CompasSclDataEventHandlerTest.java (50%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1/event => websocket/event/model}/CreateEventRequestTest.java (96%) create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/GetEventRequestTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/GetVersionEventRequestTest.java rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1/event => websocket/event/model}/UpdateEventRequestTest.java (97%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest => websocket}/v1/AbstractServerEndpointAsReaderTest.java (79%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest => websocket}/v1/CompasSclCreateServerEndpointAsEditorTest.java (80%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest => websocket}/v1/CompasSclCreateServerEndpointAsReaderTest.java (91%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest => websocket}/v1/CompasSclUpdateServerEndpointAsEditorTest.java (76%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest => websocket}/v1/CompasSclUpdateServerEndpointAsReaderTest.java (72%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/decoder}/CreateRequestDecoderTest.java (86%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/decoder}/CreateResponseDecoderTest.java (83%) create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/decoder}/UpdateRequestDecoderTest.java (81%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/decoder}/UpdateResponseDecoderTest.java (83%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/encoder}/CreateRequestEncoderTest.java (84%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/encoder}/CreateResponseEncoderTest.java (81%) create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoderTest.java rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/encoder}/UpdateRequestEncoderTest.java (79%) rename app/src/test/java/org/lfenergy/compas/scl/data/{rest/v1/websocket => websocket/v1/encoder}/UpdateResponseEncoderTest.java (81%) create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/AbstractPojoTester.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequestTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponseTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequestTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponseTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequestTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequestTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponseTest.java diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandler.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandler.java similarity index 55% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandler.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandler.java index 9dd1fa45..530a7a2c 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandler.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandler.java @@ -1,13 +1,18 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.event; +package org.lfenergy.compas.scl.data.websocket.event; import io.quarkus.vertx.ConsumeEvent; import org.lfenergy.compas.core.websocket.WebsocketHandler; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.data.websocket.event.model.CreateEventRequest; +import org.lfenergy.compas.scl.data.websocket.event.model.GetEventRequest; +import org.lfenergy.compas.scl.data.websocket.event.model.GetVersionEventRequest; +import org.lfenergy.compas.scl.data.websocket.event.model.UpdateEventRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @@ -34,6 +39,24 @@ public void createWebsocketsEvent(CreateEventRequest request) { }); } + @ConsumeEvent(value = "get-ws") + public void getWebsocketsEvent(GetEventRequest request) { + new WebsocketHandler().execute(request.getSession(), () -> { + var response = new GetResponse(); + response.setSclData(compasSclDataService.findByUUID(request.getType(), request.getId())); + return response; + }); + } + + @ConsumeEvent(value = "get-version-ws") + public void getVersionWebsocketsEvent(GetVersionEventRequest request) { + new WebsocketHandler().execute(request.getSession(), () -> { + var response = new GetResponse(); + response.setSclData(compasSclDataService.findByUUID(request.getType(), request.getId(), request.getVersion())); + return response; + }); + } + @ConsumeEvent(value = "update-ws", blocking = true) public void updateWebsocketsEvent(UpdateEventRequest request) { new WebsocketHandler().execute(request.getSession(), () -> { diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/CreateEventRequest.java similarity index 94% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequest.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/CreateEventRequest.java index 6965d752..2582a2ee 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/CreateEventRequest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.event; +package org.lfenergy.compas.scl.data.websocket.event.model; import org.lfenergy.compas.scl.extensions.model.SclFileType; diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/GetEventRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/GetEventRequest.java new file mode 100644 index 00000000..ea3d4e8b --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/GetEventRequest.java @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.event.model; + +import org.lfenergy.compas.scl.extensions.model.SclFileType; + +import javax.websocket.Session; +import java.util.UUID; + +public class GetEventRequest { + private final Session session; + private final SclFileType type; + private final UUID id; + + public GetEventRequest(Session session, SclFileType type, UUID id) { + this.session = session; + this.type = type; + this.id = id; + } + + public Session getSession() { + return session; + } + + public SclFileType getType() { + return type; + } + + public UUID getId() { + return id; + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/GetVersionEventRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/GetVersionEventRequest.java new file mode 100644 index 00000000..1675f37a --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/GetVersionEventRequest.java @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.event.model; + +import org.lfenergy.compas.scl.data.model.Version; +import org.lfenergy.compas.scl.extensions.model.SclFileType; + +import javax.websocket.Session; +import java.util.UUID; + +public class GetVersionEventRequest { + private final Session session; + private final SclFileType type; + private final UUID id; + private final Version version; + + public GetVersionEventRequest(Session session, SclFileType type, UUID id, Version version) { + this.session = session; + this.type = type; + this.id = id; + this.version = version; + } + + public Session getSession() { + return session; + } + + public SclFileType getType() { + return type; + } + + public UUID getId() { + return id; + } + + public Version getVersion() { + return version; + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/UpdateEventRequest.java similarity index 95% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequest.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/UpdateEventRequest.java index 0bc694f3..7442950a 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/model/UpdateEventRequest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.event; +package org.lfenergy.compas.scl.data.websocket.event.model; import org.lfenergy.compas.scl.data.model.ChangeSetType; import org.lfenergy.compas.scl.extensions.model.SclFileType; diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java similarity index 75% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpoint.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java index e921dc16..76859d52 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpoint.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java @@ -1,17 +1,17 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1; +package org.lfenergy.compas.scl.data.websocket.v1; import io.quarkus.security.Authenticated; import io.vertx.mutiny.core.eventbus.EventBus; import org.eclipse.microprofile.jwt.JsonWebToken; import org.lfenergy.compas.core.websocket.ErrorResponseEncoder; import org.lfenergy.compas.scl.data.rest.UserInfoProperties; -import org.lfenergy.compas.scl.data.rest.v1.event.CreateEventRequest; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest; -import org.lfenergy.compas.scl.data.rest.v1.websocket.CreateRequestDecoder; -import org.lfenergy.compas.scl.data.rest.v1.websocket.CreateResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.event.model.CreateEventRequest; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.CreateRequestDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.CreateResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateRequest; import org.lfenergy.compas.scl.extensions.model.SclFileType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,16 +33,16 @@ public class CompasSclCreateServerEndpoint { private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclCreateServerEndpoint.class); private final EventBus eventBus; + private final JsonWebToken jsonWebToken; + private final UserInfoProperties userInfoProperties; @Inject - JsonWebToken jsonWebToken; - - @Inject - UserInfoProperties userInfoProperties; - - @Inject - public CompasSclCreateServerEndpoint(EventBus eventBus) { + public CompasSclCreateServerEndpoint(EventBus eventBus, + JsonWebToken jsonWebToken, + UserInfoProperties userInfoProperties) { this.eventBus = eventBus; + this.jsonWebToken = jsonWebToken; + this.userInfoProperties = userInfoProperties; } @OnOpen diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java new file mode 100644 index 00000000..df325765 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1; + +import io.quarkus.security.Authenticated; +import io.vertx.mutiny.core.eventbus.EventBus; +import org.lfenergy.compas.core.websocket.ErrorResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.event.model.GetEventRequest; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetRequestDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; +import org.lfenergy.compas.scl.extensions.model.SclFileType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.websocket.*; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; + +import static org.lfenergy.compas.scl.data.rest.Constants.TYPE_PATH_PARAM; + +@Authenticated +@ApplicationScoped +@ServerEndpoint(value = "/scl-ws/v1/{" + TYPE_PATH_PARAM + "}/get", + decoders = {GetRequestDecoder.class}, + encoders = {GetResponseEncoder.class, ErrorResponseEncoder.class}) +public class CompasSclGetServerEndpoint { + private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclGetServerEndpoint.class); + + private final EventBus eventBus; + + @Inject + public CompasSclGetServerEndpoint(EventBus eventBus) { + this.eventBus = eventBus; + } + + @OnOpen + public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.debug("Starting session {} for type {}.", session.getId(), type); + } + + @OnMessage + public void onGetMessage(Session session, + GetRequest request, + @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.info("Message from session {} for type {}.", session.getId(), type); + + eventBus.send("get-ws", new GetEventRequest(session, SclFileType.valueOf(type), request.getId())); + } + + @OnError + public void onError(Session session, @PathParam(TYPE_PATH_PARAM) String type, Throwable throwable) { + LOGGER.warn("Error with session {} for type {}.", session.getId(), type, throwable); + } + + @OnClose + public void onClose(Session session, @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.debug("Closing session {} for type {}.", session.getId(), type); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java new file mode 100644 index 00000000..afdfa5df --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1; + +import io.quarkus.security.Authenticated; +import io.vertx.mutiny.core.eventbus.EventBus; +import org.lfenergy.compas.core.websocket.ErrorResponseEncoder; +import org.lfenergy.compas.scl.data.model.Version; +import org.lfenergy.compas.scl.data.websocket.event.model.GetVersionEventRequest; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetVersionRequestDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; +import org.lfenergy.compas.scl.extensions.model.SclFileType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.websocket.*; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; + +import static org.lfenergy.compas.scl.data.rest.Constants.TYPE_PATH_PARAM; + +@Authenticated +@ApplicationScoped +@ServerEndpoint(value = "/scl-ws/v1/{" + TYPE_PATH_PARAM + "}/get-version", + decoders = {GetVersionRequestDecoder.class}, + encoders = {GetResponseEncoder.class, ErrorResponseEncoder.class}) +public class CompasSclGetVersionServerEndpoint { + private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclGetVersionServerEndpoint.class); + + private final EventBus eventBus; + + @Inject + public CompasSclGetVersionServerEndpoint(EventBus eventBus) { + this.eventBus = eventBus; + } + + @OnOpen + public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.debug("Starting session {} for type {}.", session.getId(), type); + } + + @OnMessage + public void onGetVersionMessage(Session session, + GetVersionRequest request, + @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.info("Message from session {} for type {}.", session.getId(), type); + + eventBus.send("get-version-ws", new GetVersionEventRequest(session, SclFileType.valueOf(type), + request.getId(), new Version(request.getVersion()))); + } + + @OnError + public void onError(Session session, @PathParam(TYPE_PATH_PARAM) String type, Throwable throwable) { + LOGGER.warn("Error with session {} for type {}.", session.getId(), type, throwable); + } + + @OnClose + public void onClose(Session session, @PathParam(TYPE_PATH_PARAM) String type) { + LOGGER.debug("Closing session {} for type {}.", session.getId(), type); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java similarity index 72% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpoint.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java index 9143d60c..6350bf77 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpoint.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java @@ -1,17 +1,17 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1; +package org.lfenergy.compas.scl.data.websocket.v1; import io.quarkus.security.Authenticated; import io.vertx.mutiny.core.eventbus.EventBus; import org.eclipse.microprofile.jwt.JsonWebToken; import org.lfenergy.compas.core.websocket.ErrorResponseEncoder; import org.lfenergy.compas.scl.data.rest.UserInfoProperties; -import org.lfenergy.compas.scl.data.rest.v1.event.UpdateEventRequest; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest; -import org.lfenergy.compas.scl.data.rest.v1.websocket.UpdateRequestDecoder; -import org.lfenergy.compas.scl.data.rest.v1.websocket.UpdateResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.event.model.UpdateEventRequest; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.UpdateRequestDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.UpdateResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateRequest; import org.lfenergy.compas.scl.extensions.model.SclFileType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,30 +21,28 @@ import javax.websocket.*; import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; -import java.util.UUID; -import static org.lfenergy.compas.scl.data.rest.Constants.ID_PATH_PARAM; import static org.lfenergy.compas.scl.data.rest.Constants.TYPE_PATH_PARAM; @Authenticated @ApplicationScoped -@ServerEndpoint(value = "/scl-ws/v1/{" + TYPE_PATH_PARAM + "}/update/{" + ID_PATH_PARAM + "}", +@ServerEndpoint(value = "/scl-ws/v1/{" + TYPE_PATH_PARAM + "}/update", decoders = {UpdateRequestDecoder.class}, encoders = {UpdateResponseEncoder.class, ErrorResponseEncoder.class}) public class CompasSclUpdateServerEndpoint { private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclUpdateServerEndpoint.class); private final EventBus eventBus; + private final JsonWebToken jsonWebToken; + private final UserInfoProperties userInfoProperties; @Inject - JsonWebToken jsonWebToken; - - @Inject - UserInfoProperties userInfoProperties; - - @Inject - public CompasSclUpdateServerEndpoint(EventBus eventBus) { + public CompasSclUpdateServerEndpoint(EventBus eventBus, + JsonWebToken jsonWebToken, + UserInfoProperties userInfoProperties) { this.eventBus = eventBus; + this.jsonWebToken = jsonWebToken; + this.userInfoProperties = userInfoProperties; } @OnOpen @@ -54,15 +52,14 @@ public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { @OnMessage public void onUpdateMessage(Session session, UpdateRequest request, - @PathParam(TYPE_PATH_PARAM) String type, - @PathParam(ID_PATH_PARAM) String id) { + @PathParam(TYPE_PATH_PARAM) String type) { LOGGER.info("Message from session {} for type {}.", session.getId(), type); String who = jsonWebToken.getClaim(userInfoProperties.who()); LOGGER.trace("Username used for Who {}", who); eventBus.send("update-ws", new UpdateEventRequest( - session, SclFileType.valueOf(type), UUID.fromString(id), request.getChangeSetType(), + session, SclFileType.valueOf(type), request.getId(), request.getChangeSetType(), who, request.getComment(), request.getSclData())); } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoder.java similarity index 80% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoder.java index bdec45ec..46215ff8 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoder.java @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.decoder; import org.lfenergy.compas.core.websocket.AbstractDecoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateRequest; public class CreateRequestDecoder extends AbstractDecoder { @Override diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoder.java similarity index 80% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoder.java index e2c44374..82a5f7a5 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoder.java @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.decoder; import org.lfenergy.compas.core.websocket.AbstractDecoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; public class CreateResponseDecoder extends AbstractDecoder { @Override diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoder.java new file mode 100644 index 00000000..23a0377b --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoder.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.decoder; + +import org.lfenergy.compas.core.websocket.AbstractDecoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; + +public class GetRequestDecoder extends AbstractDecoder { + @Override + public boolean willDecode(String message) { + return (message != null); + } + + @Override + public GetRequest decode(String message) { + return WebsocketSupport.decode(message, GetRequest.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoder.java new file mode 100644 index 00000000..c24fbb26 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoder.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.decoder; + +import org.lfenergy.compas.core.websocket.AbstractDecoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; + +public class GetResponseDecoder extends AbstractDecoder { + @Override + public boolean willDecode(String message) { + return (message != null); + } + + @Override + public GetResponse decode(String message) { + return WebsocketSupport.decode(message, GetResponse.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoder.java new file mode 100644 index 00000000..539c20c7 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoder.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.decoder; + +import org.lfenergy.compas.core.websocket.AbstractDecoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; + +public class GetVersionRequestDecoder extends AbstractDecoder { + @Override + public boolean willDecode(String message) { + return (message != null); + } + + @Override + public GetVersionRequest decode(String message) { + return WebsocketSupport.decode(message, GetVersionRequest.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoder.java similarity index 80% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoder.java index b193dcba..72047ddf 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoder.java @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.decoder; import org.lfenergy.compas.core.websocket.AbstractDecoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateRequest; public class UpdateRequestDecoder extends AbstractDecoder { @Override diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoder.java similarity index 80% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoder.java index a3c66156..0aabd610 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoder.java @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.decoder; import org.lfenergy.compas.core.websocket.AbstractDecoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; public class UpdateResponseDecoder extends AbstractDecoder { @Override diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoder.java similarity index 77% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoder.java index 9d85a5a2..d96d9934 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoder.java @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.encoder; import org.lfenergy.compas.core.websocket.AbstractEncoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateRequest; public class CreateRequestEncoder extends AbstractEncoder { @Override diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoder.java similarity index 77% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoder.java index 7ca3a472..e8ecafc9 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoder.java @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.encoder; import org.lfenergy.compas.core.websocket.AbstractEncoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; public class CreateResponseEncoder extends AbstractEncoder { @Override diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoder.java new file mode 100644 index 00000000..67f3f0c7 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoder.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.encoder; + +import org.lfenergy.compas.core.websocket.AbstractEncoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; + +public class GetRequestEncoder extends AbstractEncoder { + @Override + public String encode(GetRequest jaxbObject) { + return WebsocketSupport.encode(jaxbObject, GetRequest.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoder.java new file mode 100644 index 00000000..fa9fd865 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoder.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.encoder; + +import org.lfenergy.compas.core.websocket.AbstractEncoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; + +public class GetResponseEncoder extends AbstractEncoder { + @Override + public String encode(GetResponse jaxbObject) { + return WebsocketSupport.encode(jaxbObject, GetResponse.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoder.java new file mode 100644 index 00000000..05beac39 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoder.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.encoder; + +import org.lfenergy.compas.core.websocket.AbstractEncoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; + +public class GetVersionRequestEncoder extends AbstractEncoder { + @Override + public String encode(GetVersionRequest jaxbObject) { + return WebsocketSupport.encode(jaxbObject, GetVersionRequest.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoder.java similarity index 77% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoder.java index cb6782d9..1b2b735d 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoder.java @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.encoder; import org.lfenergy.compas.core.websocket.AbstractEncoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateRequest; public class UpdateRequestEncoder extends AbstractEncoder { @Override diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoder.java similarity index 77% rename from app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoder.java index e223a01b..4aba712b 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoder.java @@ -1,11 +1,11 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.encoder; import org.lfenergy.compas.core.websocket.AbstractEncoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; public class UpdateResponseEncoder extends AbstractEncoder { @Override diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java new file mode 100644 index 00000000..c82ae419 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.scl.data.websocket.v1.model; + +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.lfenergy.compas.core.commons.constraint.FilenameValid; + +import javax.validation.constraints.NotBlank; +import javax.xml.bind.annotation.*; + +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +@Schema(description = "Request to create a new entry in the database containing the SCL Element content.") +@XmlType(name = "CreateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "CreateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlAccessorType(XmlAccessType.FIELD) +public class CreateRequest { + @FilenameValid + @Schema(description = "The name that will be stored as Private Element and can later be used to determine the filename.", + example = "STATION-0012312") + @XmlElement(name = "Name", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) + private String name; + + @Schema(description = "Comment that will be added to the new history record.", example = "New substation configuration for X") + @XmlElement(name = "Comment", namespace = SCL_DATA_SERVICE_V1_NS_URI) + private String comment; + + @Schema(description = "The XML Content of the SCL added as CDATA. The content should contain a XML according to the IEC 61850 standard.", + example = "....]]") + @NotBlank + @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI) + private String sclData; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getSclData() { + return sclData; + } + + public void setSclData(String sclData) { + this.sclData = sclData; + } +} + diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java new file mode 100644 index 00000000..7990be6b --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.model; + +import org.eclipse.microprofile.openapi.annotations.media.Schema; + +import javax.xml.bind.annotation.*; + +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +@Schema(description = "Response from creating a new entry in the database containing the SCL Element content.") +@XmlType(name = "CreateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "CreateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlAccessorType(XmlAccessType.FIELD) +public class CreateResponse { + @Schema(description = "The XML Content of the updated SCL added to the database. The content contains a XML according to the IEC 61850 standard.", + example = "....]]") + @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) + private String sclData; + + public String getSclData() { + return sclData; + } + + public void setSclData(String sclData) { + this.sclData = sclData; + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequest.java new file mode 100644 index 00000000..66bbde2a --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequest.java @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.scl.data.websocket.v1.model; + +import org.eclipse.microprofile.openapi.annotations.media.Schema; + +import javax.xml.bind.annotation.*; +import java.util.UUID; + +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +@Schema(description = "Request for retrieving a SCL from the database.") +@XmlType(name = "GetWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "GetWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlAccessorType(XmlAccessType.FIELD) +public class GetRequest { + @Schema(description = "The ID of the SCL File.", + example = "f7b98f4d-3fe4-4df2-8533-d7f0c1800344") + @XmlElement(name = "Id", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) + private UUID id; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java new file mode 100644 index 00000000..2fb2118a --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.scl.data.websocket.v1.model; + +import org.eclipse.microprofile.openapi.annotations.media.Schema; + +import javax.xml.bind.annotation.*; + +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +@Schema(description = "Response from retrieving a SCL from the database containing the SCL Content.") +@XmlType(name = "GetWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "GetWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlAccessorType(XmlAccessType.FIELD) +public class GetResponse { + @Schema(description = "The XML Content of the retrieved SCL from the database. The content contains a XML according to the IEC 61850 standard.", + example = "....]]") + @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) + private String sclData; + + public String getSclData() { + return sclData; + } + + public void setSclData(String sclData) { + this.sclData = sclData; + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequest.java new file mode 100644 index 00000000..074d1bd3 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequest.java @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.scl.data.websocket.v1.model; + +import org.eclipse.microprofile.openapi.annotations.media.Schema; + +import javax.xml.bind.annotation.*; +import java.util.UUID; + +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +@Schema(description = "Request for retrieving a SCL from the database.") +@XmlType(name = "GetVersionWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "GetVersionWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlAccessorType(XmlAccessType.FIELD) +public class GetVersionRequest { + @Schema(description = "The ID of the SCL File.", + example = "f7b98f4d-3fe4-4df2-8533-d7f0c1800344") + @XmlElement(name = "Id", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) + private UUID id; + + @Schema(description = "The version of the SCL File.", + example = "1.2.3") + @XmlElement(name = "Version", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) + private String version; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java new file mode 100644 index 00000000..7b15f3fa --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java @@ -0,0 +1,75 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.scl.data.websocket.v1.model; + +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.lfenergy.compas.scl.data.model.ChangeSetType; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.xml.bind.annotation.*; +import java.util.UUID; + +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +@Schema(description = "Request to update an existing entry in the database containing the SCL Element content. " + + "A new version is created and the old version is also kept.") +@XmlType(name = "UpdateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "UpdateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlAccessorType(XmlAccessType.FIELD) +public class UpdateRequest { + @Schema(description = "The ID of the SCL File.", + example = "f7b98f4d-3fe4-4df2-8533-d7f0c1800344") + @XmlElement(name = "Id", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) + private UUID id; + + @NotNull(message = "{org.lfenergy.compas.changeset.notnull.message}") + @Schema(description = "Indicates what kind of change to determine the new version.", + example = "MAJOR") + @XmlElement(name = "ChangeSet", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) + private ChangeSetType changeSetType; + + @Schema(description = "Comment that will be added to the new history record.", example = "Renamed substation names") + @XmlElement(name = "Comment", namespace = SCL_DATA_SERVICE_V1_NS_URI) + private String comment; + + @Schema(description = "The XML Content of the SCL added as CDATA. The content should contain a XML according to the IEC 61850 standard.", + example = "....]]") + @NotBlank + @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI) + private String sclData; + + public UUID getId() { + return id; + } + + public void setId(UUID id) { + this.id = id; + } + + public ChangeSetType getChangeSetType() { + return changeSetType; + } + + public void setChangeSetType(ChangeSetType changeSetType) { + this.changeSetType = changeSetType; + } + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getSclData() { + return sclData; + } + + public void setSclData(String sclData) { + this.sclData = sclData; + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java new file mode 100644 index 00000000..c8002d5a --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 + +package org.lfenergy.compas.scl.data.websocket.v1.model; + +import org.eclipse.microprofile.openapi.annotations.media.Schema; + +import javax.xml.bind.annotation.*; + +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +@Schema(description = "Response from updating a new entry in the database containing the SCL Element content.") +@XmlType(name = "UpdateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "UpdateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlAccessorType(XmlAccessType.FIELD) +public class UpdateResponse { + @Schema(description = "The XML Content of the updated SCL added to the database. The content contains a XML according to the IEC 61850 standard.", + example = "....]]") + @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) + private String sclData; + + public String getSclData() { + return sclData; + } + + public void setSclData(String sclData) { + this.sclData = sclData; + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/package-info.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/package-info.java new file mode 100644 index 00000000..68f35f72 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/package-info.java @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +@XmlSchema(xmlns = {@XmlNs(prefix = "sds", namespaceURI = SCL_DATA_SERVICE_V1_NS_URI)}) +package org.lfenergy.compas.scl.data.websocket.v1.model; + +import javax.xml.bind.annotation.XmlNs; +import javax.xml.bind.annotation.XmlSchema; + +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; diff --git a/app/src/main/resources/application.properties b/app/src/main/resources/application.properties index 08342b81..9556ce66 100644 --- a/app/src/main/resources/application.properties +++ b/app/src/main/resources/application.properties @@ -56,9 +56,13 @@ quarkus.http.auth.permission.SSD_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.SSD_DELETE_DELETE.policy=SSD_DELETE quarkus.http.auth.permission.SSD_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.SSD_READ_GET_WS.paths=/compas-scl-data-service/scl-ws/v1/SSD/get +quarkus.http.auth.permission.SSD_READ_GET_WS.policy=SSD_READ +quarkus.http.auth.permission.SSD_READ_GET_VERSION_WS.paths=/compas-scl-data-service/scl-ws/v1/SSD/get-version +quarkus.http.auth.permission.SSD_READ_GET_VERSION_WS.policy=SSD_READ quarkus.http.auth.permission.SSD_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/SSD/create quarkus.http.auth.permission.SSD_CREATE_POST_WS.policy=SSD_CREATE -quarkus.http.auth.permission.SSD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/SSD/update/* +quarkus.http.auth.permission.SSD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/SSD/update quarkus.http.auth.permission.SSD_UPDATE_PUT_WS.policy=SSD_UPDATE quarkus.http.auth.policy.IID_READ.roles-allowed=IID_READ @@ -78,9 +82,13 @@ quarkus.http.auth.permission.IID_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.IID_DELETE_DELETE.policy=IID_DELETE quarkus.http.auth.permission.IID_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.IID_READ_GET_WS.paths=/compas-scl-data-service/scl-ws/v1/IID/get +quarkus.http.auth.permission.IID_READ_GET_WS.policy=IID_READ +quarkus.http.auth.permission.IID_READ_GET_VERSION_WS.paths=/compas-scl-data-service/scl-ws/v1/IID/get-version +quarkus.http.auth.permission.IID_READ_GET_VERSION_WS.policy=IID_READ quarkus.http.auth.permission.IID_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/IID/create quarkus.http.auth.permission.IID_CREATE_POST_WS.policy=IID_CREATE -quarkus.http.auth.permission.IID_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/IID/update/* +quarkus.http.auth.permission.IID_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/IID/update quarkus.http.auth.permission.IID_UPDATE_PUT_WS.policy=IID_UPDATE quarkus.http.auth.policy.ICD_READ.roles-allowed=ICD_READ @@ -100,9 +108,13 @@ quarkus.http.auth.permission.ICD_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.ICD_DELETE_DELETE.policy=ICD_DELETE quarkus.http.auth.permission.ICD_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.ICD_READ_GET_WS.paths=/compas-scl-data-service/scl-ws/v1/ICD/get +quarkus.http.auth.permission.ICD_READ_GET_WS.policy=ICD_READ +quarkus.http.auth.permission.ICD_READ_GET_VERSION_WS.paths=/compas-scl-data-service/scl-ws/v1/ICD/get-version +quarkus.http.auth.permission.ICD_READ_GET_VERSION_WS.policy=ICD_READ quarkus.http.auth.permission.ICD_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/ICD/create quarkus.http.auth.permission.ICD_CREATE_POST_WS.policy=ICD_CREATE -quarkus.http.auth.permission.ICD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/ICD/update/* +quarkus.http.auth.permission.ICD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/ICD/update quarkus.http.auth.permission.ICD_UPDATE_PUT_WS.policy=ICD_UPDATE quarkus.http.auth.policy.SCD_READ.roles-allowed=SCD_READ @@ -122,9 +134,13 @@ quarkus.http.auth.permission.SCD_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.SCD_DELETE_DELETE.policy=SCD_DELETE quarkus.http.auth.permission.SCD_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.SCD_READ_GET_WS.paths=/compas-scl-data-service/scl-ws/v1/SCD/get +quarkus.http.auth.permission.SCD_READ_GET_WS.policy=SCD_READ +quarkus.http.auth.permission.SCD_READ_GET_VERSION_WS.paths=/compas-scl-data-service/scl-ws/v1/SCD/get-version +quarkus.http.auth.permission.SCD_READ_GET_VERSION_WS.policy=SCD_READ quarkus.http.auth.permission.SCD_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/SCD/create quarkus.http.auth.permission.SCD_CREATE_POST_WS.policy=SCD_CREATE -quarkus.http.auth.permission.SCD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/SCD/update/* +quarkus.http.auth.permission.SCD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/SCD/update quarkus.http.auth.permission.SCD_UPDATE_PUT_WS.policy=SCD_UPDATE quarkus.http.auth.policy.CID_READ.roles-allowed=CID_READ @@ -144,9 +160,13 @@ quarkus.http.auth.permission.CID_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.CID_DELETE_DELETE.policy=CID_DELETE quarkus.http.auth.permission.CID_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.CID_READ_GET_WS.paths=/compas-scl-data-service/scl-ws/v1/CID/get +quarkus.http.auth.permission.CID_READ_GET_WS.policy=CID_READ +quarkus.http.auth.permission.CID_READ_GET_VERSION_WS.paths=/compas-scl-data-service/scl-ws/v1/CID/get-version +quarkus.http.auth.permission.CID_READ_GET_VERSION_WS.policy=CID_READ quarkus.http.auth.permission.CID_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/CID/create quarkus.http.auth.permission.CID_CREATE_POST_WS.policy=CID_CREATE -quarkus.http.auth.permission.CID_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/CID/update/* +quarkus.http.auth.permission.CID_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/CID/update quarkus.http.auth.permission.CID_UPDATE_PUT_WS.policy=CID_UPDATE quarkus.http.auth.policy.SED_READ.roles-allowed=SED_READ @@ -166,9 +186,13 @@ quarkus.http.auth.permission.SED_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.SED_DELETE_DELETE.policy=SED_DELETE quarkus.http.auth.permission.SED_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.SED_READ_GET_WS.paths=/compas-scl-data-service/scl-ws/v1/SED/get +quarkus.http.auth.permission.SED_READ_GET_WS.policy=SED_READ +quarkus.http.auth.permission.SED_READ_GET_VERSION_WS.paths=/compas-scl-data-service/scl-ws/v1/SED/get-version +quarkus.http.auth.permission.SED_READ_GET_VERSION_WS.policy=SED_READ quarkus.http.auth.permission.SED_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/SED/create quarkus.http.auth.permission.SED_CREATE_POST_WS.policy=SED_CREATE -quarkus.http.auth.permission.SED_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/SED/update/* +quarkus.http.auth.permission.SED_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/SED/update quarkus.http.auth.permission.SED_UPDATE_PUT_WS.policy=SED_UPDATE quarkus.http.auth.policy.ISD_READ.roles-allowed=ISD_READ @@ -188,9 +212,13 @@ quarkus.http.auth.permission.ISD_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.ISD_DELETE_DELETE.policy=ISD_DELETE quarkus.http.auth.permission.ISD_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.ISD_READ_GET_WS.paths=/compas-scl-data-service/scl-ws/v1/ISD/get +quarkus.http.auth.permission.ISD_READ_GET_WS.policy=ISD_READ +quarkus.http.auth.permission.ISD_READ_GET_VERSION_WS.paths=/compas-scl-data-service/scl-ws/v1/ISD/get-version +quarkus.http.auth.permission.ISD_READ_GET_VERSION_WS.policy=ISD_READ quarkus.http.auth.permission.ISD_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/ISD/create quarkus.http.auth.permission.ISD_CREATE_POST_WS.policy=ISD_CREATE -quarkus.http.auth.permission.ISD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/ISD/update/* +quarkus.http.auth.permission.ISD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/ISD/update quarkus.http.auth.permission.ISD_UPDATE_PUT_WS.policy=ISD_UPDATE quarkus.http.auth.policy.STD_READ.roles-allowed=STD_READ @@ -210,7 +238,11 @@ quarkus.http.auth.permission.STD_DELETE_DELETE.paths=/compas-scl-data-service/sc quarkus.http.auth.permission.STD_DELETE_DELETE.policy=STD_DELETE quarkus.http.auth.permission.STD_DELETE_DELETE.methods=DELETE +quarkus.http.auth.permission.STD_READ_GET_WS.paths=/compas-scl-data-service/scl-ws/v1/STD/get +quarkus.http.auth.permission.STD_READ_GET_WS.policy=STD_READ +quarkus.http.auth.permission.STD_READ_GET_VERSION_WS.paths=/compas-scl-data-service/scl-ws/v1/STD/get-version +quarkus.http.auth.permission.STD_READ_GET_VERSION_WS.policy=STD_READ quarkus.http.auth.permission.STD_CREATE_POST_WS.paths=/compas-scl-data-service/scl-ws/v1/STD/create quarkus.http.auth.permission.STD_CREATE_POST_WS.policy=STD_CREATE -quarkus.http.auth.permission.STD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/STD/update/* +quarkus.http.auth.permission.STD_UPDATE_PUT_WS.paths=/compas-scl-data-service/scl-ws/v1/STD/update quarkus.http.auth.permission.STD_UPDATE_PUT_WS.policy=STD_UPDATE diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/model/AbstractPojoTester.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/model/AbstractPojoTester.java index 13d6824c..52639a40 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/model/AbstractPojoTester.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/model/AbstractPojoTester.java @@ -16,10 +16,10 @@ abstract class AbstractPojoTester { void validateSettersAndGetters() { var personPojo = PojoClassFactory.getPojoClass(getClassToBeTested()); var validator = ValidatorBuilder.create() - // Lets make sure that we have a getter and a setter for every field defined. + // Let's make sure that we have a getter and a setter for every field defined. .with(new GetterMustExistRule()) .with(new SetterMustExistRule()) - // Lets also validate that they are behaving as expected + // Let's also validate that they are behaving as expected .with(new SetterTester()) .with(new GetterTester()) .build(); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandlerTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java similarity index 50% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandlerTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java index 626ecd3b..da58fd2d 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CompasSclDataEventHandlerTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java @@ -1,16 +1,22 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.event; +package org.lfenergy.compas.scl.data.websocket.event; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.lfenergy.compas.core.commons.exception.CompasException; import org.lfenergy.compas.core.commons.model.ErrorResponse; import org.lfenergy.compas.scl.data.model.ChangeSetType; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.model.Version; import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.data.websocket.event.model.CreateEventRequest; +import org.lfenergy.compas.scl.data.websocket.event.model.GetEventRequest; +import org.lfenergy.compas.scl.data.websocket.event.model.GetVersionEventRequest; +import org.lfenergy.compas.scl.data.websocket.event.model.UpdateEventRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; import org.lfenergy.compas.scl.extensions.model.SclFileType; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; @@ -43,21 +49,14 @@ void createWebsocketsEvent_WhenCalled_ThenCreateResponseReturned() { var comment = "Some comment"; var sclData = "Some SCL Data"; - var session = Mockito.mock(Session.class); - var async = Mockito.mock(RemoteEndpoint.Async.class); - when(session.getAsyncRemote()).thenReturn(async); + var session = mockSession(); var request = new CreateEventRequest(session, type, name, who, comment, sclData); - when(service.create(type, name, who, comment, sclData)).thenReturn(sclData); eventHandler.createWebsocketsEvent(request); - verify(session, times(1)).getAsyncRemote(); - ArgumentCaptor captor = ArgumentCaptor.forClass(CreateResponse.class); - verify(async, times(1)).sendObject(captor.capture()); - var response = captor.getValue(); + var response = verifyResponse(session, CreateResponse.class); assertEquals(sclData, response.getSclData()); - verify(service, times(1)).create(type, name, who, comment, sclData); } @@ -70,25 +69,14 @@ void createWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenError var sclData = "Some SCL Data"; var errorMessage = "Some Error"; - var session = Mockito.mock(Session.class); - var async = Mockito.mock(RemoteEndpoint.Async.class); - when(session.getAsyncRemote()).thenReturn(async); + var session = mockSession(); var request = new CreateEventRequest(session, type, name, who, comment, sclData); - when(service.create(type, name, who, comment, sclData)) .thenThrow(new CompasException(DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage)); eventHandler.createWebsocketsEvent(request); - verify(session, times(1)).getAsyncRemote(); - ArgumentCaptor captor = ArgumentCaptor.forClass(ErrorResponse.class); - verify(async, times(1)).sendObject(captor.capture()); - var response = captor.getValue(); - assertEquals(1, response.getErrorMessages().size()); - var message = response.getErrorMessages().get(0); - assertEquals(DUPLICATE_SCL_NAME_ERROR_CODE, message.getCode()); - assertEquals(errorMessage, message.getMessage()); - + verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage); verify(service, times(1)).create(type, name, who, comment, sclData); } @@ -101,27 +89,119 @@ void createWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErro var sclData = "Some SCL Data"; var errorMessage = "Some Error"; - var session = Mockito.mock(Session.class); - var async = Mockito.mock(RemoteEndpoint.Async.class); - when(session.getAsyncRemote()).thenReturn(async); + var session = mockSession(); var request = new CreateEventRequest(session, type, name, who, comment, sclData); - when(service.create(type, name, who, comment, sclData)).thenThrow(new RuntimeException(errorMessage)); eventHandler.createWebsocketsEvent(request); - verify(session, times(1)).getAsyncRemote(); - ArgumentCaptor captor = ArgumentCaptor.forClass(ErrorResponse.class); - verify(async, times(1)).sendObject(captor.capture()); - var response = captor.getValue(); - assertEquals(1, response.getErrorMessages().size()); - var message = response.getErrorMessages().get(0); - assertEquals(WEBSOCKET_GENERAL_ERROR_CODE, message.getCode()); - assertEquals(errorMessage, message.getMessage()); - + verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage); verify(service, times(1)).create(type, name, who, comment, sclData); } + @Test + void getWebsocketsEvent_WhenCalled_ThenGetResponseReturned() { + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var sclData = "Some SCL Data"; + + var session = mockSession(); + var request = new GetEventRequest(session, type, id); + when(service.findByUUID(type, id)).thenReturn(sclData); + + eventHandler.getWebsocketsEvent(request); + + var response = verifyResponse(session, GetResponse.class); + assertEquals(sclData, response.getSclData()); + verify(service, times(1)).findByUUID(type, id); + } + + @Test + void getWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenErrorResponseReturned() { + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var errorMessage = "Some Error"; + + var session = mockSession(); + var request = new GetEventRequest(session, type, id); + when(service.findByUUID(type, id)) + .thenThrow(new CompasException(DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage)); + + eventHandler.getWebsocketsEvent(request); + + verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage); + verify(service, times(1)).findByUUID(type, id); + } + + @Test + void getWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErrorResponseReturned() { + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var errorMessage = "Some Error"; + + var session = mockSession(); + var request = new GetEventRequest(session, type, id); + when(service.findByUUID(type, id)).thenThrow(new RuntimeException(errorMessage)); + + eventHandler.getWebsocketsEvent(request); + + verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage); + verify(service, times(1)).findByUUID(type, id); + } + + @Test + void getVersionWebsocketsEvent_WhenCalled_ThenGetResponseReturned() { + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var sclData = "Some SCL Data"; + var version = new Version("1.2.3"); + + var session = mockSession(); + var request = new GetVersionEventRequest(session, type, id, version); + when(service.findByUUID(type, id, version)).thenReturn(sclData); + + eventHandler.getVersionWebsocketsEvent(request); + + var response = verifyResponse(session, GetResponse.class); + assertEquals(sclData, response.getSclData()); + verify(service, times(1)).findByUUID(type, id, version); + } + + @Test + void getVersionWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenErrorResponseReturned() { + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var version = new Version("1.2.3"); + var errorMessage = "Some Error"; + + var session = mockSession(); + var request = new GetVersionEventRequest(session, type, id, version); + when(service.findByUUID(type, id, version)) + .thenThrow(new CompasException(DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage)); + + eventHandler.getVersionWebsocketsEvent(request); + + verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage); + verify(service, times(1)).findByUUID(type, id, version); + } + + @Test + void getVersionWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErrorResponseReturned() { + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var version = new Version("1.2.3"); + var errorMessage = "Some Error"; + + var session = mockSession(); + var request = new GetVersionEventRequest(session, type, id, version); + when(service.findByUUID(type, id, version)).thenThrow(new RuntimeException(errorMessage)); + + eventHandler.getVersionWebsocketsEvent(request); + + verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage); + verify(service, times(1)).findByUUID(type, id, version); + } + @Test void updateWebsocketsEvent_WhenCalled_ThenUpdateResponseReturned() { var type = SclFileType.CID; @@ -131,21 +211,14 @@ void updateWebsocketsEvent_WhenCalled_ThenUpdateResponseReturned() { var comment = "Some comment"; var sclData = "Some SCL Data"; - var session = Mockito.mock(Session.class); - var async = Mockito.mock(RemoteEndpoint.Async.class); - when(session.getAsyncRemote()).thenReturn(async); + var session = mockSession(); var request = new UpdateEventRequest(session, type, id, cst, who, comment, sclData); - when(service.update(type, id, cst, who, comment, sclData)).thenReturn(sclData); eventHandler.updateWebsocketsEvent(request); - verify(session, times(1)).getAsyncRemote(); - ArgumentCaptor captor = ArgumentCaptor.forClass(UpdateResponse.class); - verify(async, times(1)).sendObject(captor.capture()); - var response = captor.getValue(); + var response = verifyResponse(session, UpdateResponse.class); assertEquals(sclData, response.getSclData()); - verify(service, times(1)).update(type, id, cst, who, comment, sclData); } @@ -159,25 +232,14 @@ void updateWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenError var sclData = "Some SCL Data"; var errorMessage = "Some Error"; - var session = Mockito.mock(Session.class); - var async = Mockito.mock(RemoteEndpoint.Async.class); - when(session.getAsyncRemote()).thenReturn(async); + var session = mockSession(); var request = new UpdateEventRequest(session, type, id, cst, who, comment, sclData); - when(service.update(type, id, cst, who, comment, sclData)) .thenThrow(new CompasException(DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage)); eventHandler.updateWebsocketsEvent(request); - verify(session, times(1)).getAsyncRemote(); - ArgumentCaptor captor = ArgumentCaptor.forClass(ErrorResponse.class); - verify(async, times(1)).sendObject(captor.capture()); - var response = captor.getValue(); - assertEquals(1, response.getErrorMessages().size()); - var message = response.getErrorMessages().get(0); - assertEquals(DUPLICATE_SCL_NAME_ERROR_CODE, message.getCode()); - assertEquals(errorMessage, message.getMessage()); - + verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage); verify(service, times(1)).update(type, id, cst, who, comment, sclData); } @@ -191,24 +253,38 @@ void updateWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErro var sclData = "Some SCL Data"; var errorMessage = "Some Error"; - var session = Mockito.mock(Session.class); - var async = Mockito.mock(RemoteEndpoint.Async.class); - when(session.getAsyncRemote()).thenReturn(async); + var session = mockSession(); var request = new UpdateEventRequest(session, type, id, cst, who, comment, sclData); - when(service.update(type, id, cst, who, comment, sclData)).thenThrow(new RuntimeException(errorMessage)); eventHandler.updateWebsocketsEvent(request); + verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage); + verify(service, times(1)).update(type, id, cst, who, comment, sclData); + } + + private Session mockSession() { + var session = Mockito.mock(Session.class); + var async = Mockito.mock(RemoteEndpoint.Async.class); + when(session.getAsyncRemote()).thenReturn(async); + return session; + } + + private T verifyResponse(Session session, Class responseClass) { + verify(session, times(1)).getAsyncRemote(); + ArgumentCaptor captor = ArgumentCaptor.forClass(responseClass); + verify(session.getAsyncRemote(), times(1)).sendObject(captor.capture()); + return captor.getValue(); + } + + private void verifyErrorResponse(Session session, String errorCode, String errorMessage) { verify(session, times(1)).getAsyncRemote(); ArgumentCaptor captor = ArgumentCaptor.forClass(ErrorResponse.class); - verify(async, times(1)).sendObject(captor.capture()); + verify(session.getAsyncRemote(), times(1)).sendObject(captor.capture()); var response = captor.getValue(); assertEquals(1, response.getErrorMessages().size()); var message = response.getErrorMessages().get(0); - assertEquals(WEBSOCKET_GENERAL_ERROR_CODE, message.getCode()); + assertEquals(errorCode, message.getCode()); assertEquals(errorMessage, message.getMessage()); - - verify(service, times(1)).update(type, id, cst, who, comment, sclData); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/CreateEventRequestTest.java similarity index 96% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequestTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/CreateEventRequestTest.java index 8489d792..0c250f5c 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/CreateEventRequestTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/CreateEventRequestTest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.event; +package org.lfenergy.compas.scl.data.websocket.event.model; import com.openpojo.reflection.impl.PojoClassFactory; import com.openpojo.validation.ValidatorBuilder; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/GetEventRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/GetEventRequestTest.java new file mode 100644 index 00000000..e9240bcd --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/GetEventRequestTest.java @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.event.model; + +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.extensions.model.SclFileType; +import org.mockito.Mockito; + +import javax.websocket.Session; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class GetEventRequestTest { + @Test + void constructor_WhenCalledWith3Arguments_ThenValuesSet() { + var session = Mockito.mock(Session.class); + var type = SclFileType.CID; + var id = UUID.randomUUID(); + + var result = new GetEventRequest(session, type, id); + + assertEquals(session, result.getSession()); + assertEquals(type, result.getType()); + assertEquals(id, result.getId()); + } + + @Test + void validateSettersAndGetters() { + var personPojo = PojoClassFactory.getPojoClass(UpdateEventRequest.class); + var validator = ValidatorBuilder.create() + // Let's make sure that we have a getter for every field defined. + .with(new GetterMustExistRule()) + // Let's also validate that they are behaving as expected + .with(new GetterTester()) + .build(); + + // Start the Test + validator.validate(personPojo); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/GetVersionEventRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/GetVersionEventRequestTest.java new file mode 100644 index 00000000..1e2a9a29 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/GetVersionEventRequestTest.java @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.event.model; + +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.model.Version; +import org.lfenergy.compas.scl.extensions.model.SclFileType; +import org.mockito.Mockito; + +import javax.websocket.Session; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class GetVersionEventRequestTest { + @Test + void constructor_WhenCalledWith3Arguments_ThenValuesSet() { + var session = Mockito.mock(Session.class); + var type = SclFileType.CID; + var id = UUID.randomUUID(); + var version = new Version("1.2.3"); + + var result = new GetVersionEventRequest(session, type, id, version); + + assertEquals(session, result.getSession()); + assertEquals(type, result.getType()); + assertEquals(id, result.getId()); + assertEquals(version, result.getVersion()); + } + + @Test + void validateSettersAndGetters() { + var personPojo = PojoClassFactory.getPojoClass(UpdateEventRequest.class); + var validator = ValidatorBuilder.create() + // Let's make sure that we have a getter for every field defined. + .with(new GetterMustExistRule()) + // Let's also validate that they are behaving as expected + .with(new GetterTester()) + .build(); + + // Start the Test + validator.validate(personPojo); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/UpdateEventRequestTest.java similarity index 97% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequestTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/UpdateEventRequestTest.java index fb57933e..ada45ffc 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/event/UpdateEventRequestTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/model/UpdateEventRequestTest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.event; +package org.lfenergy.compas.scl.data.websocket.event.model; import com.openpojo.reflection.impl.PojoClassFactory; import com.openpojo.validation.ValidatorBuilder; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTest.java similarity index 79% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTest.java index 058623f3..a38060f3 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/AbstractServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTest.java @@ -1,13 +1,11 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1; +package org.lfenergy.compas.scl.data.websocket.v1; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakeException; import io.quarkus.test.security.TestSecurity; -import io.quarkus.test.security.jwt.Claim; -import io.quarkus.test.security.jwt.JwtSecurity; import javax.websocket.ClientEndpoint; import javax.websocket.ContainerProvider; @@ -20,10 +18,6 @@ import static org.lfenergy.compas.scl.data.rest.Constants.READ_ROLE; @TestSecurity(user = "test-editor", roles = {"SCD_" + READ_ROLE}) -@JwtSecurity(claims = { - // Default the claim "name" is configured for Who, so we will set this claim for the test. - @Claim(key = "name", value = CompasSclDataResourceAsEditorTest.USERNAME) -}) public abstract class AbstractServerEndpointAsReaderTest { protected void testWhenForbiddenToExecute(URI uri) { var container = ContainerProvider.getWebSocketContainer(); @@ -37,6 +31,6 @@ protected void testWhenForbiddenToExecute(URI uri) { } @ClientEndpoint() - private static class Client { + static class Client { } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java similarity index 80% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsEditorTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java index a698b114..44eec496 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1; +package org.lfenergy.compas.scl.data.websocket.v1; import io.quarkus.test.common.http.TestHTTPResource; import io.quarkus.test.junit.QuarkusTest; @@ -10,11 +10,11 @@ import io.quarkus.test.security.jwt.Claim; import io.quarkus.test.security.jwt.JwtSecurity; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; -import org.lfenergy.compas.scl.data.rest.v1.websocket.CreateRequestEncoder; -import org.lfenergy.compas.scl.data.rest.v1.websocket.CreateResponseDecoder; import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.CreateResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.CreateRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; import org.lfenergy.compas.scl.extensions.model.SclFileType; import javax.websocket.ClientEndpoint; @@ -34,9 +34,11 @@ @TestSecurity(user = "test-editor", roles = {"SCD_" + CREATE_ROLE}) @JwtSecurity(claims = { // Default the claim "name" is configured for Who, so we will set this claim for the test. - @Claim(key = "name", value = CompasSclDataResourceAsEditorTest.USERNAME) + @Claim(key = "name", value = CompasSclCreateServerEndpointAsEditorTest.USERNAME) }) class CompasSclCreateServerEndpointAsEditorTest { + public static final String USERNAME = "Test Editor"; + private static final LinkedBlockingDeque sclDataQueue = new LinkedBlockingDeque<>(); @InjectMock @@ -58,7 +60,7 @@ void createSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { request.setComment(comment); request.setSclData(sclData); - when(service.create(sclFileTye, name, CompasSclDataResourceAsEditorTest.USERNAME, comment, sclData)) + when(service.create(sclFileTye, name, USERNAME, comment, sclData)) .thenReturn(sclData); try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(Client.class, uri)) { @@ -67,12 +69,12 @@ void createSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { var updatedSclData = sclDataQueue.poll(10, TimeUnit.SECONDS); assertEquals(sclData, updatedSclData); assertEquals(0, sclDataQueue.size()); - verify(service, times(1)).create(sclFileTye, name, CompasSclDataResourceAsEditorTest.USERNAME, comment, sclData); + verify(service, times(1)).create(sclFileTye, name, USERNAME, comment, sclData); } } @ClientEndpoint(decoders = CreateResponseDecoder.class) - private static class Client { + static class Client { @OnMessage public void onMessage(CreateResponse response) { sclDataQueue.add(response.getSclData()); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsReaderTest.java similarity index 91% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsReaderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsReaderTest.java index 17b3a32a..9d0d8d18 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclCreateServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsReaderTest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1; +package org.lfenergy.compas.scl.data.websocket.v1; import io.quarkus.test.common.http.TestHTTPResource; import io.quarkus.test.junit.QuarkusTest; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java similarity index 76% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsEditorTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java index 3b90cc84..8201911c 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1; +package org.lfenergy.compas.scl.data.websocket.v1; import io.quarkus.test.common.http.TestHTTPResource; import io.quarkus.test.junit.QuarkusTest; @@ -11,11 +11,11 @@ import io.quarkus.test.security.jwt.JwtSecurity; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.model.ChangeSetType; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; -import org.lfenergy.compas.scl.data.rest.v1.websocket.UpdateRequestEncoder; -import org.lfenergy.compas.scl.data.rest.v1.websocket.UpdateResponseDecoder; import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.UpdateResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.UpdateRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; import org.lfenergy.compas.scl.extensions.model.SclFileType; import javax.websocket.ClientEndpoint; @@ -36,17 +36,18 @@ @TestSecurity(user = "test-editor", roles = {"SCD_" + UPDATE_ROLE}) @JwtSecurity(claims = { // Default the claim "name" is configured for Who, so we will set this claim for the test. - @Claim(key = "name", value = CompasSclDataResourceAsEditorTest.USERNAME) + @Claim(key = "name", value = CompasSclUpdateServerEndpointAsEditorTest.USERNAME) }) class CompasSclUpdateServerEndpointAsEditorTest { private static final LinkedBlockingDeque sclDataQueue = new LinkedBlockingDeque<>(); - private static final String ID_VALUE = "9bb30944-8c85-4509-97ec-365381c355ef"; + public static final String USERNAME = "Test Editor"; + private static final UUID ID_VALUE = UUID.fromString("9bb30944-8c85-4509-97ec-365381c355ef"); @InjectMock private CompasSclDataService service; - @TestHTTPResource("/scl-ws/v1/SCD/update/" + ID_VALUE) + @TestHTTPResource("/scl-ws/v1/SCD/update") private URI uri; @Test @@ -58,11 +59,12 @@ void updateSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { var sclData = readSCL(); var request = new UpdateRequest(); + request.setId(ID_VALUE); request.setChangeSetType(cst); request.setComment(comment); request.setSclData(sclData); - when(service.update(sclFileTye, UUID.fromString(ID_VALUE), cst, CompasSclDataResourceAsEditorTest.USERNAME, comment, sclData)) + when(service.update(sclFileTye, ID_VALUE, cst, USERNAME, comment, sclData)) .thenReturn(sclData); try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(Client.class, uri)) { @@ -71,12 +73,12 @@ void updateSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { var updatedSclData = sclDataQueue.poll(10, TimeUnit.SECONDS); assertEquals(sclData, updatedSclData); assertEquals(0, sclDataQueue.size()); - verify(service, times(1)).update(sclFileTye, UUID.fromString(ID_VALUE), cst, CompasSclDataResourceAsEditorTest.USERNAME, comment, sclData); + verify(service, times(1)).update(sclFileTye, ID_VALUE, cst, USERNAME, comment, sclData); } } @ClientEndpoint(decoders = UpdateResponseDecoder.class) - private static class Client { + static class Client { @OnMessage public void onMessage(UpdateResponse response) { sclDataQueue.add(response.getSclData()); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsReaderTest.java similarity index 72% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsReaderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsReaderTest.java index 1565c843..0b8e9e31 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclUpdateServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsReaderTest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1; +package org.lfenergy.compas.scl.data.websocket.v1; import io.quarkus.test.common.http.TestHTTPResource; import io.quarkus.test.junit.QuarkusTest; @@ -11,9 +11,7 @@ @QuarkusTest class CompasSclUpdateServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTest { - private static final String ID_VALUE = "9bb30944-8c85-4509-97ec-365381c355ef"; - - @TestHTTPResource("/scl-ws/v1/SCD/update/" + ID_VALUE) + @TestHTTPResource("/scl-ws/v1/SCD/update") private URI uri; @Test diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoderTest.java similarity index 86% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoderTest.java index 764edad9..f887876b 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoderTest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.decoder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -29,11 +29,11 @@ void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var name = "Some name"; var comment = "Some comment"; var message = "" - + "" + + "" + "" + name + "" + "" + comment + "" + "" - + ""; + + ""; var result = decoder.decode(message); @@ -46,8 +46,8 @@ void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { @Test void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { var message = "" - + "" - + ""; + + "" + + ""; var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoderTest.java similarity index 83% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoderTest.java index f6d3221e..f8e5c7d5 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoderTest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.decoder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -27,9 +27,9 @@ void init() { void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var sclData = "Some SCL Data"; var message = "" - + "" + + "" + "" - + ""; + + ""; var result = decoder.decode(message); @@ -40,8 +40,8 @@ void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { @Test void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { var message = "" - + "" - + ""; + + "" + + ""; var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java new file mode 100644 index 00000000..97c8a6a0 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.decoder; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.core.commons.exception.CompasException; + +import javax.xml.bind.UnmarshalException; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; +import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class GetRequestDecoderTest { + private GetRequestDecoder decoder; + + @BeforeEach + void init() { + decoder = new GetRequestDecoder(); + decoder.init(null); + } + + @Test + void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { + var id = UUID.randomUUID(); + var message = "" + + "" + + "" + id + "" + + ""; + + var result = decoder.decode(message); + + assertNotNull(result); + assertEquals(id, result.getId()); + } + + @Test + void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { + var message = "" + + "" + + ""; + + var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); + assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); + assertEquals(UnmarshalException.class, exception.getCause().getClass()); + } + + @AfterEach + void destroy() { + decoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java new file mode 100644 index 00000000..40de3aba --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java @@ -0,0 +1,55 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.decoder; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.core.commons.exception.CompasException; + +import javax.xml.bind.UnmarshalException; + +import static org.junit.jupiter.api.Assertions.*; +import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class GetResponseDecoderTest { + private GetResponseDecoder decoder; + + @BeforeEach + void init() { + decoder = new GetResponseDecoder(); + decoder.init(null); + } + + @Test + void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { + var sclData = "Some SCL Data"; + var message = "" + + "" + + "" + + ""; + + var result = decoder.decode(message); + + assertNotNull(result); + assertEquals(sclData, result.getSclData()); + } + + @Test + void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { + var message = "" + + "" + + ""; + + var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); + assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); + assertEquals(UnmarshalException.class, exception.getCause().getClass()); + } + + @AfterEach + void destroy() { + decoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java new file mode 100644 index 00000000..e7945b2e --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.decoder; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.core.commons.exception.CompasException; +import org.lfenergy.compas.scl.data.model.Version; + +import javax.xml.bind.UnmarshalException; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; +import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class GetVersionRequestDecoderTest { + private GetVersionRequestDecoder decoder; + + @BeforeEach + void init() { + decoder = new GetVersionRequestDecoder(); + decoder.init(null); + } + + @Test + void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { + var id = UUID.randomUUID(); + var version = new Version("1.2.3"); + var message = "" + + "" + + "" + id + "" + + "" + version + "" + + ""; + + var result = decoder.decode(message); + + assertNotNull(result); + assertEquals(id, result.getId()); + assertEquals(version.toString(), result.getVersion()); + } + + @Test + void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { + var message = "" + + "" + + ""; + + var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); + assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); + assertEquals(UnmarshalException.class, exception.getCause().getClass()); + } + + @AfterEach + void destroy() { + decoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoderTest.java similarity index 81% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoderTest.java index d321bdf9..47340418 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoderTest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.decoder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -10,6 +10,7 @@ import org.lfenergy.compas.scl.data.model.ChangeSetType; import javax.xml.bind.UnmarshalException; +import java.util.UUID; import static org.junit.jupiter.api.Assertions.*; import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; @@ -27,18 +28,21 @@ void init() { @Test void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var sclData = "Some SCL Data"; + var id = UUID.randomUUID(); var cst = ChangeSetType.MAJOR; var comment = "Some comment"; var message = "" - + "" + + "" + + "" + id + "" + "" + cst + "" + "" + comment + "" + "" - + ""; + + ""; var result = decoder.decode(message); assertNotNull(result); + assertEquals(id, result.getId()); assertEquals(cst, result.getChangeSetType()); assertEquals(comment, result.getComment()); assertEquals(sclData, result.getSclData()); @@ -47,8 +51,8 @@ void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { @Test void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { var message = "" - + "" - + ""; + + "" + + ""; var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoderTest.java similarity index 83% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoderTest.java index b6c3ee3f..6c248735 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoderTest.java @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.decoder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -27,9 +27,9 @@ void init() { void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var sclData = "Some SCL Data"; var message = "" - + "" + + "" + "" - + ""; + + ""; var result = decoder.decode(message); @@ -40,8 +40,8 @@ void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { @Test void decode_WhenCalledWithWrongXMLType_ThenExceptionThrown() { var message = "" - + "" - + ""; + + "" + + ""; var exception = assertThrows(CompasException.class, () -> decoder.decode(message)); assertEquals(WEBSOCKET_DECODER_ERROR_CODE, exception.getErrorCode()); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoderTest.java similarity index 84% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoderTest.java index 53c977a5..79115dd3 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateRequestEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoderTest.java @@ -1,12 +1,12 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.encoder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateRequest; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -35,11 +35,11 @@ void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var result = encoder.encode(request); var expectedResult = "" + - "" + + "" + "" + name + "" + "" + comment + "" + "" + sclData + "" + - ""; + ""; assertNotNull(result); assertEquals(expectedResult, result); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoderTest.java similarity index 81% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoderTest.java index 0f84d24f..ddb38b92 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/CreateResponseEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoderTest.java @@ -1,12 +1,12 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.encoder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -31,9 +31,9 @@ void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var result = encoder.encode(request); var expectedResult = "" + - "" + + "" + "" + sclData + "" + - ""; + ""; assertNotNull(result); assertEquals(expectedResult, result); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoderTest.java new file mode 100644 index 00000000..0102a675 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoderTest.java @@ -0,0 +1,47 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.encoder; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class GetRequestEncoderTest { + private GetRequestEncoder encoder; + + @BeforeEach + void init() { + encoder = new GetRequestEncoder(); + encoder.init(null); + } + + @Test + void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { + var id = UUID.randomUUID(); + + var request = new GetRequest(); + request.setId(id); + + var result = encoder.encode(request); + + var expectedResult = "" + + "" + + "" + id + "" + + ""; + assertNotNull(result); + assertEquals(expectedResult, result); + } + + @AfterEach + void destroy() { + encoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoderTest.java new file mode 100644 index 00000000..738581bc --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoderTest.java @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.encoder; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class GetResponseEncoderTest { + private GetResponseEncoder encoder; + + @BeforeEach + void init() { + encoder = new GetResponseEncoder(); + encoder.init(null); + } + + @Test + void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { + var sclData = "Some SCL Data"; + + var request = new GetResponse(); + request.setSclData(sclData); + + var result = encoder.encode(request); + + var expectedResult = "" + + "" + + "" + sclData + "" + + ""; + assertNotNull(result); + assertEquals(expectedResult, result); + } + + @AfterEach + void destroy() { + encoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoderTest.java new file mode 100644 index 00000000..67c1d528 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoderTest.java @@ -0,0 +1,51 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.encoder; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.model.Version; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; + +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; + +class GetVersionRequestEncoderTest { + private GetVersionRequestEncoder encoder; + + @BeforeEach + void init() { + encoder = new GetVersionRequestEncoder(); + encoder.init(null); + } + + @Test + void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { + var id = UUID.randomUUID(); + var version = new Version("1.2.3"); + + var request = new GetVersionRequest(); + request.setId(id); + request.setVersion(version.toString()); + + var result = encoder.encode(request); + + var expectedResult = "" + + "" + + "" + id + "" + + "" + version + "" + + ""; + assertNotNull(result); + assertEquals(expectedResult, result); + } + + @AfterEach + void destroy() { + encoder.destroy(); + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoderTest.java similarity index 79% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoderTest.java index 79d2cfed..2128f1a9 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateRequestEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoderTest.java @@ -1,13 +1,15 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.encoder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.model.ChangeSetType; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateRequest; + +import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -25,10 +27,12 @@ void init() { @Test void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var sclData = "Some SCL Data"; + var id = UUID.randomUUID(); var cst = ChangeSetType.MAJOR; var comment = "Some comment"; var request = new UpdateRequest(); + request.setId(id); request.setChangeSetType(cst); request.setComment(comment); request.setSclData(sclData); @@ -36,11 +40,12 @@ void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var result = encoder.encode(request); var expectedResult = "" + - "" + + "" + + "" + id + "" + "" + cst + "" + "" + comment + "" + "" + sclData + "" + - ""; + ""; assertNotNull(result); assertEquals(expectedResult, result); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoderTest.java similarity index 81% rename from app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoderTest.java index 3ae446bc..dbca0579 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/websocket/UpdateResponseEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoderTest.java @@ -1,12 +1,12 @@ // SPDX-FileCopyrightText: 2022 Alliander N.V. // // SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.rest.v1.websocket; +package org.lfenergy.compas.scl.data.websocket.v1.encoder; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -31,9 +31,9 @@ void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var result = encoder.encode(request); var expectedResult = "" + - "" + + "" + "" + sclData + "" + - ""; + ""; assertNotNull(result); assertEquals(expectedResult, result); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/AbstractPojoTester.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/AbstractPojoTester.java new file mode 100644 index 00000000..8165a364 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/AbstractPojoTester.java @@ -0,0 +1,32 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.model; + +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import org.junit.jupiter.api.Test; + +abstract class AbstractPojoTester { + @Test + void validateSettersAndGetters() { + var personPojo = PojoClassFactory.getPojoClass(getClassToBeTested()); + var validator = ValidatorBuilder.create() + // Let's make sure that we have a getter and a setter for every field defined. + .with(new GetterMustExistRule()) + .with(new SetterMustExistRule()) + // Let's also validate that they are behaving as expected + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + + // Start the Test + validator.validate(personPojo); + } + + protected abstract Class getClassToBeTested(); +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequestTest.java new file mode 100644 index 00000000..a989831f --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequestTest.java @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.model; + +class CreateRequestTest extends AbstractPojoTester { + @Override + protected Class getClassToBeTested() { + return CreateRequest.class; + } +} \ No newline at end of file diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponseTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponseTest.java new file mode 100644 index 00000000..cb73fb0e --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponseTest.java @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.model; + +class CreateResponseTest extends AbstractPojoTester { + @Override + protected Class getClassToBeTested() { + return CreateResponse.class; + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequestTest.java new file mode 100644 index 00000000..f02e799c --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequestTest.java @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.model; + +class GetRequestTest extends AbstractPojoTester { + @Override + protected Class getClassToBeTested() { + return GetRequest.class; + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponseTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponseTest.java new file mode 100644 index 00000000..2ad70750 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponseTest.java @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.model; + +class GetResponseTest extends AbstractPojoTester { + @Override + protected Class getClassToBeTested() { + return GetResponse.class; + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequestTest.java new file mode 100644 index 00000000..947eb4a3 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequestTest.java @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.model; + +class GetVersionRequestTest extends AbstractPojoTester { + @Override + protected Class getClassToBeTested() { + return GetVersionRequest.class; + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequestTest.java new file mode 100644 index 00000000..e407e7bf --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequestTest.java @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.model; + +class UpdateRequestTest extends AbstractPojoTester { + @Override + protected Class getClassToBeTested() { + return UpdateRequest.class; + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponseTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponseTest.java new file mode 100644 index 00000000..b6be5735 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponseTest.java @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.model; + +class UpdateResponseTest extends AbstractPojoTester { + @Override + protected Class getClassToBeTested() { + return UpdateResponse.class; + } +} From 0dcf2299f504f34eeca89a1832eaf667f2dfbab7 Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Wed, 9 Nov 2022 17:45:38 +0100 Subject: [PATCH 12/21] Returned testcases that are still needed Signed-off-by: Dennis Labordus --- .../v1/decoder/CreateRequestDecoderTest.java | 11 +++++++++++ .../v1/decoder/CreateResponseDecoderTest.java | 11 +++++++++++ .../websocket/v1/decoder/GetRequestDecoderTest.java | 11 +++++++++++ .../websocket/v1/decoder/GetResponseDecoderTest.java | 11 +++++++++++ .../v1/decoder/GetVersionRequestDecoderTest.java | 11 +++++++++++ .../v1/decoder/UpdateRequestDecoderTest.java | 11 +++++++++++ .../v1/decoder/UpdateResponseDecoderTest.java | 11 +++++++++++ 7 files changed, 77 insertions(+) diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoderTest.java index f887876b..685d68e0 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoderTest.java @@ -23,6 +23,17 @@ void init() { decoder.init(null); } + @Test + void willDecode_WhenCalledWithString_ThenTrueReturned() { + assertTrue(decoder.willDecode("")); + assertTrue(decoder.willDecode("Some text")); + } + + @Test + void willDecode_WhenCalledWithNull_ThenFalseReturned() { + assertFalse(decoder.willDecode(null)); + } + @Test void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var sclData = "Some SCL Data"; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoderTest.java index f8e5c7d5..385510c1 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoderTest.java @@ -23,6 +23,17 @@ void init() { decoder.init(null); } + @Test + void willDecode_WhenCalledWithString_ThenTrueReturned() { + assertTrue(decoder.willDecode("")); + assertTrue(decoder.willDecode("Some text")); + } + + @Test + void willDecode_WhenCalledWithNull_ThenFalseReturned() { + assertFalse(decoder.willDecode(null)); + } + @Test void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var sclData = "Some SCL Data"; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java index 97c8a6a0..6f3811dc 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java @@ -24,6 +24,17 @@ void init() { decoder.init(null); } + @Test + void willDecode_WhenCalledWithString_ThenTrueReturned() { + assertTrue(decoder.willDecode("")); + assertTrue(decoder.willDecode("Some text")); + } + + @Test + void willDecode_WhenCalledWithNull_ThenFalseReturned() { + assertFalse(decoder.willDecode(null)); + } + @Test void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var id = UUID.randomUUID(); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java index 40de3aba..d929da83 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java @@ -23,6 +23,17 @@ void init() { decoder.init(null); } + @Test + void willDecode_WhenCalledWithString_ThenTrueReturned() { + assertTrue(decoder.willDecode("")); + assertTrue(decoder.willDecode("Some text")); + } + + @Test + void willDecode_WhenCalledWithNull_ThenFalseReturned() { + assertFalse(decoder.willDecode(null)); + } + @Test void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var sclData = "Some SCL Data"; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java index e7945b2e..7236fe01 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java @@ -25,6 +25,17 @@ void init() { decoder.init(null); } + @Test + void willDecode_WhenCalledWithString_ThenTrueReturned() { + assertTrue(decoder.willDecode("")); + assertTrue(decoder.willDecode("Some text")); + } + + @Test + void willDecode_WhenCalledWithNull_ThenFalseReturned() { + assertFalse(decoder.willDecode(null)); + } + @Test void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var id = UUID.randomUUID(); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoderTest.java index 47340418..3aea12d0 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoderTest.java @@ -25,6 +25,17 @@ void init() { decoder.init(null); } + @Test + void willDecode_WhenCalledWithString_ThenTrueReturned() { + assertTrue(decoder.willDecode("")); + assertTrue(decoder.willDecode("Some text")); + } + + @Test + void willDecode_WhenCalledWithNull_ThenFalseReturned() { + assertFalse(decoder.willDecode(null)); + } + @Test void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var sclData = "Some SCL Data"; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoderTest.java index 6c248735..16ba18f8 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoderTest.java @@ -23,6 +23,17 @@ void init() { decoder.init(null); } + @Test + void willDecode_WhenCalledWithString_ThenTrueReturned() { + assertTrue(decoder.willDecode("")); + assertTrue(decoder.willDecode("Some text")); + } + + @Test + void willDecode_WhenCalledWithNull_ThenFalseReturned() { + assertFalse(decoder.willDecode(null)); + } + @Test void decode_WhenCalledWithCorrectRequestXML_ThenStringConvertedToObject() { var sclData = "Some SCL Data"; From 32c76b619562ba5a7956e8400b6ed04e7abd4ab1 Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Thu, 10 Nov 2022 10:01:04 +0100 Subject: [PATCH 13/21] Updated CoMPAS Core version. Signed-off-by: Dennis Labordus --- .../v1/CompasSclCreateServerEndpoint.java | 10 +-- .../v1/CompasSclGetServerEndpoint.java | 10 +-- .../v1/CompasSclGetVersionServerEndpoint.java | 2 + .../v1/CompasSclUpdateServerEndpoint.java | 10 +-- .../websocket/v1/model/CreateRequest.java | 48 ++----------- .../websocket/v1/model/CreateResponse.java | 19 ++--- .../data/websocket/v1/model/GetResponse.java | 19 ++--- .../websocket/v1/model/UpdateRequest.java | 45 +----------- .../websocket/v1/model/UpdateResponse.java | 19 ++--- .../AbstractServerEndpointAsEditorTest.java | 20 ++++++ .../AbstractServerEndpointAsReaderTest.java | 2 +- .../v1/AbstractServerEndpointTest.java | 63 +++++++++++++++++ ...asSclCreateServerEndpointAsEditorTest.java | 36 ++-------- ...ompasSclGetServerEndpointAsEditorTest.java | 68 ++++++++++++++++++ ...ompasSclGetServerEndpointAsReaderTest.java | 66 ++++++++++++++++++ ...lGetVersionServerEndpointAsEditorTest.java | 69 +++++++++++++++++++ ...lGetVersionServerEndpointAsReaderTest.java | 69 +++++++++++++++++++ ...asSclUpdateServerEndpointAsEditorTest.java | 44 +++--------- pom.xml | 2 +- 19 files changed, 416 insertions(+), 205 deletions(-) create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsEditorTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java index 76859d52..2a7b89c9 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java @@ -22,6 +22,7 @@ import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; +import static org.lfenergy.compas.core.websocket.WebsocketSupport.handleException; import static org.lfenergy.compas.scl.data.rest.Constants.TYPE_PATH_PARAM; @Authenticated @@ -47,12 +48,12 @@ public CompasSclCreateServerEndpoint(EventBus eventBus, @OnOpen public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { - LOGGER.debug("Starting session {} for type {}.", session.getId(), type); + LOGGER.debug("Starting (create) session {} for type {}.", session.getId(), type); } @OnMessage public void onCreateMessage(Session session, CreateRequest request, @PathParam(TYPE_PATH_PARAM) String type) { - LOGGER.info("Message from session {} for type {}.", session.getId(), type); + LOGGER.info("Message (create) from session {} for type {}.", session.getId(), type); String who = jsonWebToken.getClaim(userInfoProperties.who()); LOGGER.trace("Username used for Who {}", who); @@ -63,11 +64,12 @@ public void onCreateMessage(Session session, CreateRequest request, @PathParam(T @OnError public void onError(Session session, @PathParam(TYPE_PATH_PARAM) String type, Throwable throwable) { - LOGGER.warn("Error with session {} for type {}.", session.getId(), type, throwable); + LOGGER.warn("Error (create) with session {} for type {}.", session.getId(), type, throwable); + handleException(session, throwable); } @OnClose public void onClose(Session session, @PathParam(TYPE_PATH_PARAM) String type) { - LOGGER.debug("Closing session {} for type {}.", session.getId(), type); + LOGGER.debug("Closing (create) session {} for type {}.", session.getId(), type); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java index df325765..84fbc66a 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java @@ -20,6 +20,7 @@ import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; +import static org.lfenergy.compas.core.websocket.WebsocketSupport.handleException; import static org.lfenergy.compas.scl.data.rest.Constants.TYPE_PATH_PARAM; @Authenticated @@ -39,25 +40,26 @@ public CompasSclGetServerEndpoint(EventBus eventBus) { @OnOpen public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { - LOGGER.debug("Starting session {} for type {}.", session.getId(), type); + LOGGER.debug("Starting (get) session {} for type {}.", session.getId(), type); } @OnMessage public void onGetMessage(Session session, GetRequest request, @PathParam(TYPE_PATH_PARAM) String type) { - LOGGER.info("Message from session {} for type {}.", session.getId(), type); + LOGGER.info("Message (get) from session {} for type {}.", session.getId(), type); eventBus.send("get-ws", new GetEventRequest(session, SclFileType.valueOf(type), request.getId())); } @OnError public void onError(Session session, @PathParam(TYPE_PATH_PARAM) String type, Throwable throwable) { - LOGGER.warn("Error with session {} for type {}.", session.getId(), type, throwable); + LOGGER.warn("Error (get) with session {} for type {}.", session.getId(), type, throwable); + handleException(session, throwable); } @OnClose public void onClose(Session session, @PathParam(TYPE_PATH_PARAM) String type) { - LOGGER.debug("Closing session {} for type {}.", session.getId(), type); + LOGGER.debug("Closing (get) session {} for type {}.", session.getId(), type); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java index afdfa5df..3b4b9dc9 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java @@ -21,6 +21,7 @@ import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; +import static org.lfenergy.compas.core.websocket.WebsocketSupport.handleException; import static org.lfenergy.compas.scl.data.rest.Constants.TYPE_PATH_PARAM; @Authenticated @@ -56,6 +57,7 @@ public void onGetVersionMessage(Session session, @OnError public void onError(Session session, @PathParam(TYPE_PATH_PARAM) String type, Throwable throwable) { LOGGER.warn("Error with session {} for type {}.", session.getId(), type, throwable); + handleException(session, throwable); } @OnClose diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java index 6350bf77..f096c823 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java @@ -22,6 +22,7 @@ import javax.websocket.server.PathParam; import javax.websocket.server.ServerEndpoint; +import static org.lfenergy.compas.core.websocket.WebsocketSupport.handleException; import static org.lfenergy.compas.scl.data.rest.Constants.TYPE_PATH_PARAM; @Authenticated @@ -47,13 +48,13 @@ public CompasSclUpdateServerEndpoint(EventBus eventBus, @OnOpen public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { - LOGGER.debug("Starting session {} for type {}.", session.getId(), type); + LOGGER.debug("Starting (update) session {} for type {}.", session.getId(), type); } @OnMessage public void onUpdateMessage(Session session, UpdateRequest request, @PathParam(TYPE_PATH_PARAM) String type) { - LOGGER.info("Message from session {} for type {}.", session.getId(), type); + LOGGER.info("Message (update) from session {} for type {}.", session.getId(), type); String who = jsonWebToken.getClaim(userInfoProperties.who()); LOGGER.trace("Username used for Who {}", who); @@ -65,11 +66,12 @@ public void onUpdateMessage(Session session, UpdateRequest request, @OnError public void onError(Session session, @PathParam(TYPE_PATH_PARAM) String type, Throwable throwable) { - LOGGER.warn("Error with session {} for type {}.", session.getId(), type, throwable); + LOGGER.warn("Error (update) with session {} for type {}.", session.getId(), type, throwable); + handleException(session, throwable); } @OnClose public void onClose(Session session, @PathParam(TYPE_PATH_PARAM) String type) { - LOGGER.debug("Closing session {} for type {}.", session.getId(), type); + LOGGER.debug("Closing (update) session {} for type {}.", session.getId(), type); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java index c82ae419..1105db49 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java @@ -5,10 +5,11 @@ package org.lfenergy.compas.scl.data.websocket.v1.model; import org.eclipse.microprofile.openapi.annotations.media.Schema; -import org.lfenergy.compas.core.commons.constraint.FilenameValid; -import javax.validation.constraints.NotBlank; -import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @@ -16,45 +17,6 @@ @XmlType(name = "CreateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "CreateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class CreateRequest { - @FilenameValid - @Schema(description = "The name that will be stored as Private Element and can later be used to determine the filename.", - example = "STATION-0012312") - @XmlElement(name = "Name", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) - private String name; - - @Schema(description = "Comment that will be added to the new history record.", example = "New substation configuration for X") - @XmlElement(name = "Comment", namespace = SCL_DATA_SERVICE_V1_NS_URI) - private String comment; - - @Schema(description = "The XML Content of the SCL added as CDATA. The content should contain a XML according to the IEC 61850 standard.", - example = "....]]") - @NotBlank - @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI) - private String sclData; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - this.comment = comment; - } - - public String getSclData() { - return sclData; - } - - public void setSclData(String sclData) { - this.sclData = sclData; - } +public class CreateRequest extends org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest { } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java index 7990be6b..febf25dd 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java @@ -5,7 +5,10 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema; -import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @@ -13,17 +16,5 @@ @XmlType(name = "CreateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "CreateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class CreateResponse { - @Schema(description = "The XML Content of the updated SCL added to the database. The content contains a XML according to the IEC 61850 standard.", - example = "....]]") - @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) - private String sclData; - - public String getSclData() { - return sclData; - } - - public void setSclData(String sclData) { - this.sclData = sclData; - } +public class CreateResponse extends org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse { } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java index 2fb2118a..bb25aa25 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java @@ -6,7 +6,10 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema; -import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @@ -14,17 +17,5 @@ @XmlType(name = "GetWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "GetWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class GetResponse { - @Schema(description = "The XML Content of the retrieved SCL from the database. The content contains a XML according to the IEC 61850 standard.", - example = "....]]") - @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) - private String sclData; - - public String getSclData() { - return sclData; - } - - public void setSclData(String sclData) { - this.sclData = sclData; - } +public class GetResponse extends org.lfenergy.compas.scl.data.rest.v1.model.GetResponse { } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java index 7b15f3fa..c08d8c87 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java @@ -5,10 +5,7 @@ package org.lfenergy.compas.scl.data.websocket.v1.model; import org.eclipse.microprofile.openapi.annotations.media.Schema; -import org.lfenergy.compas.scl.data.model.ChangeSetType; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; import javax.xml.bind.annotation.*; import java.util.UUID; @@ -19,28 +16,12 @@ @XmlType(name = "UpdateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "UpdateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class UpdateRequest { +public class UpdateRequest extends org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest { @Schema(description = "The ID of the SCL File.", example = "f7b98f4d-3fe4-4df2-8533-d7f0c1800344") @XmlElement(name = "Id", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) private UUID id; - @NotNull(message = "{org.lfenergy.compas.changeset.notnull.message}") - @Schema(description = "Indicates what kind of change to determine the new version.", - example = "MAJOR") - @XmlElement(name = "ChangeSet", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) - private ChangeSetType changeSetType; - - @Schema(description = "Comment that will be added to the new history record.", example = "Renamed substation names") - @XmlElement(name = "Comment", namespace = SCL_DATA_SERVICE_V1_NS_URI) - private String comment; - - @Schema(description = "The XML Content of the SCL added as CDATA. The content should contain a XML according to the IEC 61850 standard.", - example = "....]]") - @NotBlank - @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI) - private String sclData; - public UUID getId() { return id; } @@ -48,28 +29,4 @@ public UUID getId() { public void setId(UUID id) { this.id = id; } - - public ChangeSetType getChangeSetType() { - return changeSetType; - } - - public void setChangeSetType(ChangeSetType changeSetType) { - this.changeSetType = changeSetType; - } - - public String getComment() { - return comment; - } - - public void setComment(String comment) { - this.comment = comment; - } - - public String getSclData() { - return sclData; - } - - public void setSclData(String sclData) { - this.sclData = sclData; - } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java index c8002d5a..8e72ae50 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java @@ -6,7 +6,10 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema; -import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @@ -14,17 +17,5 @@ @XmlType(name = "UpdateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "UpdateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class UpdateResponse { - @Schema(description = "The XML Content of the updated SCL added to the database. The content contains a XML according to the IEC 61850 standard.", - example = "....]]") - @XmlElement(name = "SclData", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) - private String sclData; - - public String getSclData() { - return sclData; - } - - public void setSclData(String sclData) { - this.sclData = sclData; - } +public class UpdateResponse extends org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse { } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsEditorTest.java new file mode 100644 index 00000000..a0b5a734 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsEditorTest.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1; + +import io.quarkus.test.security.TestSecurity; +import io.quarkus.test.security.jwt.Claim; +import io.quarkus.test.security.jwt.JwtSecurity; + +import static org.lfenergy.compas.scl.data.rest.Constants.*; + +@TestSecurity(user = "test-editor", roles = {"SCD_" + READ_ROLE, "SCD_" + CREATE_ROLE, "SCD_" + UPDATE_ROLE}) +@JwtSecurity(claims = { + // Default the claim "name" is configured for Who, so we will set this claim for the test. + @Claim(key = "name", value = AbstractServerEndpointAsEditorTest.USERNAME) +}) +public abstract class AbstractServerEndpointAsEditorTest extends AbstractServerEndpointTest { + public static final String USERNAME = "Test Editor"; + +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTest.java index a38060f3..2e21f3d2 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTest.java @@ -18,7 +18,7 @@ import static org.lfenergy.compas.scl.data.rest.Constants.READ_ROLE; @TestSecurity(user = "test-editor", roles = {"SCD_" + READ_ROLE}) -public abstract class AbstractServerEndpointAsReaderTest { +public abstract class AbstractServerEndpointAsReaderTest extends AbstractServerEndpointTest { protected void testWhenForbiddenToExecute(URI uri) { var container = ContainerProvider.getWebSocketContainer(); var exception = assertThrows(InterruptedIOException.class, () -> container.connectToServer(Client.class, uri)); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java new file mode 100644 index 00000000..1616ca9f --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1; + +import org.lfenergy.compas.core.commons.model.ErrorMessage; +import org.lfenergy.compas.core.commons.model.ErrorResponse; +import org.lfenergy.compas.core.websocket.ErrorResponseDecoder; + +import javax.websocket.ClientEndpoint; +import javax.websocket.ContainerProvider; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import java.io.IOException; +import java.net.URI; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; + +public class AbstractServerEndpointTest { + protected static final LinkedBlockingDeque sclDataQueue = new LinkedBlockingDeque<>(); + protected static final LinkedBlockingDeque errorQueue = new LinkedBlockingDeque<>(); + + void testWhenCalledWithInvalidTextThenExceptionThrown(URI uri) throws Exception { + try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(CompasSclCreateServerEndpointAsEditorTest.ErrorClient.class, uri)) { + session.getAsyncRemote().sendText("Invalid Message"); + + assertErrorResponse(WEBSOCKET_DECODER_ERROR_CODE); + } + } + + protected void assertErrorResponse(String expectedErrorCode) throws InterruptedException { + var errorMessage = errorQueue.poll(10, TimeUnit.SECONDS); + assertEquals(expectedErrorCode, errorMessage.getCode()); + assertEquals(0, errorQueue.size()); + } + + protected void assertSclData(String expectedSclData) throws InterruptedException { + var returnedSclData = sclDataQueue.poll(10, TimeUnit.SECONDS); + assertEquals(expectedSclData, returnedSclData); + assertEquals(0, sclDataQueue.size()); + } + + protected String readSCL() throws IOException { + try (var inputStream = getClass().getResourceAsStream("/scl/icd_import_ied_test.scd")) { + assert inputStream != null; + + return new String(inputStream.readAllBytes()); + } + } + + @ClientEndpoint(decoders = ErrorResponseDecoder.class) + static class ErrorClient { + @OnMessage + public void onMessage(ErrorResponse response) { + if (response.getErrorMessages().size() > 0) { + errorQueue.addAll(response.getErrorMessages()); + } + } + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java index 44eec496..ef4be838 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java @@ -6,9 +6,6 @@ import io.quarkus.test.common.http.TestHTTPResource; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.mockito.InjectMock; -import io.quarkus.test.security.TestSecurity; -import io.quarkus.test.security.jwt.Claim; -import io.quarkus.test.security.jwt.JwtSecurity; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.service.CompasSclDataService; import org.lfenergy.compas.scl.data.websocket.v1.decoder.CreateResponseDecoder; @@ -21,26 +18,12 @@ import javax.websocket.ContainerProvider; import javax.websocket.OnMessage; import javax.websocket.Session; -import java.io.IOException; import java.net.URI; -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.TimeUnit; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.lfenergy.compas.scl.data.rest.Constants.CREATE_ROLE; import static org.mockito.Mockito.*; @QuarkusTest -@TestSecurity(user = "test-editor", roles = {"SCD_" + CREATE_ROLE}) -@JwtSecurity(claims = { - // Default the claim "name" is configured for Who, so we will set this claim for the test. - @Claim(key = "name", value = CompasSclCreateServerEndpointAsEditorTest.USERNAME) -}) -class CompasSclCreateServerEndpointAsEditorTest { - public static final String USERNAME = "Test Editor"; - - private static final LinkedBlockingDeque sclDataQueue = new LinkedBlockingDeque<>(); - +class CompasSclCreateServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTest { @InjectMock private CompasSclDataService service; @@ -66,13 +49,16 @@ void createSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(Client.class, uri)) { session.getAsyncRemote().sendText(encoder.encode(request)); - var updatedSclData = sclDataQueue.poll(10, TimeUnit.SECONDS); - assertEquals(sclData, updatedSclData); - assertEquals(0, sclDataQueue.size()); + assertSclData(sclData); verify(service, times(1)).create(sclFileTye, name, USERNAME, comment, sclData); } } + @Test + void createSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception { + testWhenCalledWithInvalidTextThenExceptionThrown(uri); + } + @ClientEndpoint(decoders = CreateResponseDecoder.class) static class Client { @OnMessage @@ -80,12 +66,4 @@ public void onMessage(CreateResponse response) { sclDataQueue.add(response.getSclData()); } } - - private String readSCL() throws IOException { - try (var inputStream = getClass().getResourceAsStream("/scl/icd_import_ied_test.scd")) { - assert inputStream != null; - - return new String(inputStream.readAllBytes()); - } - } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java new file mode 100644 index 00000000..0289e137 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java @@ -0,0 +1,68 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1; + +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.extensions.model.SclFileType; + +import javax.websocket.ClientEndpoint; +import javax.websocket.ContainerProvider; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import java.net.URI; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.*; + +@QuarkusTest +class CompasSclGetServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTest { + @InjectMock + private CompasSclDataService service; + + @TestHTTPResource("/scl-ws/v1/SCD/get") + private URI uri; + + @Test + void getSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { + var encoder = new GetRequestEncoder(); + var sclFileTye = SclFileType.SCD; + var id = UUID.randomUUID(); + var sclData = readSCL(); + + var request = new GetRequest(); + request.setId(id); + + when(service.findByUUID(sclFileTye, id)).thenReturn(sclData); + + try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(Client.class, uri)) { + session.getAsyncRemote().sendText(encoder.encode(request)); + + assertSclData(sclData); + verify(service, times(1)).findByUUID(sclFileTye, id); + } + } + + @Test + void getSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception { + testWhenCalledWithInvalidTextThenExceptionThrown(uri); + } + + @ClientEndpoint(decoders = GetResponseDecoder.class) + static class Client { + @OnMessage + public void onMessage(GetResponse response) { + sclDataQueue.add(response.getSclData()); + } + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java new file mode 100644 index 00000000..6bc44bf7 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1; + +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.extensions.model.SclFileType; + +import javax.websocket.ClientEndpoint; +import javax.websocket.ContainerProvider; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import java.net.URI; +import java.util.UUID; + +import static org.mockito.Mockito.*; + +@QuarkusTest +class CompasSclGetServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTest { + @InjectMock + private CompasSclDataService service; + + @TestHTTPResource("/scl-ws/v1/SCD/get") + private URI uri; + + @Test + void getSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { + var encoder = new GetRequestEncoder(); + var sclFileTye = SclFileType.SCD; + var id = UUID.randomUUID(); + var sclData = readSCL(); + + var request = new GetRequest(); + request.setId(id); + + when(service.findByUUID(sclFileTye, id)).thenReturn(sclData); + + try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(Client.class, uri)) { + session.getAsyncRemote().sendText(encoder.encode(request)); + + assertSclData(sclData); + verify(service, times(1)).findByUUID(sclFileTye, id); + } + } + + @Test + void getSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception { + testWhenCalledWithInvalidTextThenExceptionThrown(uri); + } + + @ClientEndpoint(decoders = GetResponseDecoder.class) + static class Client { + @OnMessage + public void onMessage(GetResponse response) { + sclDataQueue.add(response.getSclData()); + } + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java new file mode 100644 index 00000000..d4ce1fd6 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1; + +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.model.Version; +import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetVersionRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; +import org.lfenergy.compas.scl.extensions.model.SclFileType; + +import javax.websocket.ClientEndpoint; +import javax.websocket.ContainerProvider; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import java.net.URI; +import java.util.UUID; + +import static org.mockito.Mockito.*; + +@QuarkusTest +class CompasSclGetVersionServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTest { + @InjectMock + private CompasSclDataService service; + + @TestHTTPResource("/scl-ws/v1/SCD/get-version") + private URI uri; + + @Test + void getVersionSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { + var encoder = new GetVersionRequestEncoder(); + var sclFileTye = SclFileType.SCD; + var id = UUID.randomUUID(); + var version = new Version("1.2.3"); + var sclData = readSCL(); + + var request = new GetVersionRequest(); + request.setId(id); + request.setVersion(version.toString()); + + when(service.findByUUID(sclFileTye, id, version)).thenReturn(sclData); + + try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(Client.class, uri)) { + session.getAsyncRemote().sendText(encoder.encode(request)); + + assertSclData(sclData); + verify(service, times(1)).findByUUID(sclFileTye, id, version); + } + } + + @Test + void getSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception { + testWhenCalledWithInvalidTextThenExceptionThrown(uri); + } + + @ClientEndpoint(decoders = GetResponseDecoder.class) + static class Client { + @OnMessage + public void onMessage(GetResponse response) { + sclDataQueue.add(response.getSclData()); + } + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java new file mode 100644 index 00000000..11b28589 --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java @@ -0,0 +1,69 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1; + +import io.quarkus.test.common.http.TestHTTPResource; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.mockito.InjectMock; +import org.junit.jupiter.api.Test; +import org.lfenergy.compas.scl.data.model.Version; +import org.lfenergy.compas.scl.data.service.CompasSclDataService; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetVersionRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; +import org.lfenergy.compas.scl.extensions.model.SclFileType; + +import javax.websocket.ClientEndpoint; +import javax.websocket.ContainerProvider; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import java.net.URI; +import java.util.UUID; + +import static org.mockito.Mockito.*; + +@QuarkusTest +class CompasSclGetVersionServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTest { + @InjectMock + private CompasSclDataService service; + + @TestHTTPResource("/scl-ws/v1/SCD/get-version") + private URI uri; + + @Test + void getVersionSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { + var encoder = new GetVersionRequestEncoder(); + var sclFileTye = SclFileType.SCD; + var id = UUID.randomUUID(); + var version = new Version("1.2.3"); + var sclData = readSCL(); + + var request = new GetVersionRequest(); + request.setId(id); + request.setVersion(version.toString()); + + when(service.findByUUID(sclFileTye, id, version)).thenReturn(sclData); + + try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(Client.class, uri)) { + session.getAsyncRemote().sendText(encoder.encode(request)); + + assertSclData(sclData); + verify(service, times(1)).findByUUID(sclFileTye, id, version); + } + } + + @Test + void getSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception { + testWhenCalledWithInvalidTextThenExceptionThrown(uri); + } + + @ClientEndpoint(decoders = GetResponseDecoder.class) + static class Client { + @OnMessage + public void onMessage(GetResponse response) { + sclDataQueue.add(response.getSclData()); + } + } +} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java index 8201911c..cc4e9d65 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java @@ -6,9 +6,6 @@ import io.quarkus.test.common.http.TestHTTPResource; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.mockito.InjectMock; -import io.quarkus.test.security.TestSecurity; -import io.quarkus.test.security.jwt.Claim; -import io.quarkus.test.security.jwt.JwtSecurity; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.model.ChangeSetType; import org.lfenergy.compas.scl.data.service.CompasSclDataService; @@ -22,28 +19,13 @@ import javax.websocket.ContainerProvider; import javax.websocket.OnMessage; import javax.websocket.Session; -import java.io.IOException; import java.net.URI; import java.util.UUID; -import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.TimeUnit; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.lfenergy.compas.scl.data.rest.Constants.UPDATE_ROLE; import static org.mockito.Mockito.*; @QuarkusTest -@TestSecurity(user = "test-editor", roles = {"SCD_" + UPDATE_ROLE}) -@JwtSecurity(claims = { - // Default the claim "name" is configured for Who, so we will set this claim for the test. - @Claim(key = "name", value = CompasSclUpdateServerEndpointAsEditorTest.USERNAME) -}) -class CompasSclUpdateServerEndpointAsEditorTest { - private static final LinkedBlockingDeque sclDataQueue = new LinkedBlockingDeque<>(); - - public static final String USERNAME = "Test Editor"; - private static final UUID ID_VALUE = UUID.fromString("9bb30944-8c85-4509-97ec-365381c355ef"); - +class CompasSclUpdateServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTest { @InjectMock private CompasSclDataService service; @@ -54,29 +36,33 @@ class CompasSclUpdateServerEndpointAsEditorTest { void updateSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { var encoder = new UpdateRequestEncoder(); var sclFileTye = SclFileType.SCD; + var id = UUID.randomUUID(); var cst = ChangeSetType.PATCH; var comment = "Some comment"; var sclData = readSCL(); var request = new UpdateRequest(); - request.setId(ID_VALUE); + request.setId(id); request.setChangeSetType(cst); request.setComment(comment); request.setSclData(sclData); - when(service.update(sclFileTye, ID_VALUE, cst, USERNAME, comment, sclData)) + when(service.update(sclFileTye, id, cst, USERNAME, comment, sclData)) .thenReturn(sclData); try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(Client.class, uri)) { session.getAsyncRemote().sendText(encoder.encode(request)); - var updatedSclData = sclDataQueue.poll(10, TimeUnit.SECONDS); - assertEquals(sclData, updatedSclData); - assertEquals(0, sclDataQueue.size()); - verify(service, times(1)).update(sclFileTye, ID_VALUE, cst, USERNAME, comment, sclData); + assertSclData(sclData); + verify(service, times(1)).update(sclFileTye, id, cst, USERNAME, comment, sclData); } } + @Test + void createSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception { + testWhenCalledWithInvalidTextThenExceptionThrown(uri); + } + @ClientEndpoint(decoders = UpdateResponseDecoder.class) static class Client { @OnMessage @@ -84,12 +70,4 @@ public void onMessage(UpdateResponse response) { sclDataQueue.add(response.getSclData()); } } - - private String readSCL() throws IOException { - try (var inputStream = getClass().getResourceAsStream("/scl/icd_import_ied_test.scd")) { - assert inputStream != null; - - return new String(inputStream.readAllBytes()); - } - } } diff --git a/pom.xml b/pom.xml index a28e2aeb..862d9836 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ SPDX-License-Identifier: Apache-2.0 3.0.0-M7 3.2.0 - 0.10.0 + 0.10.1 2.13.4.Final 2.3.7 From b4aa346e2d213f71d38c4f45a41f2a2020ee33cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 10 Nov 2022 11:03:15 +0000 Subject: [PATCH 14/21] Bump quarkus.platform.version from 2.13.4.Final to 2.14.0.Final Bumps `quarkus.platform.version` from 2.13.4.Final to 2.14.0.Final. Updates `quarkus-universe-bom` from 2.13.4.Final to 2.14.0.Final - [Release notes](https://github.com/quarkusio/quarkus-platform/releases) - [Commits](https://github.com/quarkusio/quarkus-platform/compare/2.13.4.Final...2.14.0.Final) Updates `quarkus-maven-plugin` from 2.13.4.Final to 2.14.0.Final --- updated-dependencies: - dependency-name: io.quarkus:quarkus-universe-bom dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: io.quarkus:quarkus-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bdfb52a2..c2453086 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ SPDX-License-Identifier: Apache-2.0 0.9.3 - 2.13.4.Final + 2.14.0.Final 2.3.7 3.0 2.0.3 From 643602f878b5d5d1ab09db97657c72053a511994 Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Thu, 10 Nov 2022 12:48:53 +0100 Subject: [PATCH 15/21] Small change in test class. Signed-off-by: Dennis Labordus --- .../scl/data/websocket/v1/AbstractServerEndpointTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java index 1616ca9f..260ef1d4 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java @@ -24,7 +24,7 @@ public class AbstractServerEndpointTest { protected static final LinkedBlockingDeque errorQueue = new LinkedBlockingDeque<>(); void testWhenCalledWithInvalidTextThenExceptionThrown(URI uri) throws Exception { - try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(CompasSclCreateServerEndpointAsEditorTest.ErrorClient.class, uri)) { + try (Session session = ContainerProvider.getWebSocketContainer().connectToServer(ErrorClient.class, uri)) { session.getAsyncRemote().sendText("Invalid Message"); assertErrorResponse(WEBSOCKET_DECODER_ERROR_CODE); From 9aefe9a40d3d1a40525a966872609e693e13728f Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Thu, 10 Nov 2022 13:01:28 +0100 Subject: [PATCH 16/21] Fixed test and renamed model and encoder/decoder. Signed-off-by: Dennis Labordus --- .../scl/data/rest/v1/model/CreateRequest.java | 2 +- .../data/rest/v1/model/CreateResponse.java | 2 +- .../scl/data/rest/v1/model/GetResponse.java | 2 +- .../scl/data/rest/v1/model/UpdateRequest.java | 2 +- .../data/rest/v1/model/UpdateResponse.java | 2 +- .../event/CompasSclDataEventHandler.java | 22 +++++++++---------- .../v1/CompasSclCreateServerEndpoint.java | 12 +++++----- .../v1/CompasSclGetServerEndpoint.java | 12 +++++----- .../v1/CompasSclGetVersionServerEndpoint.java | 12 +++++----- .../v1/CompasSclUpdateServerEndpoint.java | 12 +++++----- ...coder.java => CreateWsRequestDecoder.java} | 8 +++---- .../v1/decoder/CreateWsResponseDecoder.java | 20 +++++++++++++++++ ...r.java => GetVersionWsRequestDecoder.java} | 8 +++---- ...tDecoder.java => GetWsRequestDecoder.java} | 8 +++---- ...Decoder.java => GetWsResponseDecoder.java} | 8 +++---- .../v1/decoder/UpdateRequestDecoder.java | 20 ----------------- .../v1/decoder/UpdateResponseDecoder.java | 20 ----------------- ...coder.java => UpdateWsRequestDecoder.java} | 8 +++---- .../v1/decoder/UpdateWsResponseDecoder.java | 20 +++++++++++++++++ ...coder.java => CreateWsRequestEncoder.java} | 8 +++---- .../v1/encoder/CreateWsResponseEncoder.java | 15 +++++++++++++ ...r.java => GetVersionWsRequestEncoder.java} | 8 +++---- ...eEncoder.java => GetWsRequestEncoder.java} | 8 +++---- ...Encoder.java => GetWsResponseEncoder.java} | 8 +++---- .../v1/encoder/UpdateRequestEncoder.java | 15 ------------- .../v1/encoder/UpdateResponseEncoder.java | 15 ------------- ...coder.java => UpdateWsRequestEncoder.java} | 8 +++---- .../v1/encoder/UpdateWsResponseEncoder.java | 15 +++++++++++++ ...reateRequest.java => CreateWsRequest.java} | 2 +- ...ateResponse.java => CreateWsResponse.java} | 2 +- ...nRequest.java => GetVersionWsRequest.java} | 2 +- .../{GetRequest.java => GetWsRequest.java} | 2 +- .../{GetResponse.java => GetWsResponse.java} | 2 +- ...pdateRequest.java => UpdateWsRequest.java} | 2 +- ...ateResponse.java => UpdateWsResponse.java} | 2 +- .../v1/CompasSclDataResourceAsEditorTest.java | 8 +++---- .../v1/CompasSclDataResourceAsReaderTest.java | 4 ++-- .../event/CompasSclDataEventHandlerTest.java | 14 ++++++------ ...asSclCreateServerEndpointAsEditorTest.java | 16 +++++++------- ...ompasSclGetServerEndpointAsEditorTest.java | 17 +++++++------- ...ompasSclGetServerEndpointAsReaderTest.java | 16 +++++++------- ...lGetVersionServerEndpointAsEditorTest.java | 16 +++++++------- ...lGetVersionServerEndpointAsReaderTest.java | 16 +++++++------- ...asSclUpdateServerEndpointAsEditorTest.java | 16 +++++++------- ...t.java => CreateWsRequestDecoderTest.java} | 6 ++--- ....java => CreateWsResponseDecoderTest.java} | 6 ++--- ...va => GetVersionWsRequestDecoderTest.java} | 6 ++--- ...Test.java => GetWsRequestDecoderTest.java} | 6 ++--- ...est.java => GetWsResponseDecoderTest.java} | 6 ++--- ...t.java => UpdateWsRequestDecoderTest.java} | 6 ++--- ....java => UpdateWsResponseDecoderTest.java} | 6 ++--- ...t.java => CreateWsRequestEncoderTest.java} | 10 ++++----- ....java => CreateWsResponseEncoderTest.java} | 10 ++++----- ...va => GetVersionWsRequestEncoderTest.java} | 10 ++++----- ...Test.java => GetWsRequestEncoderTest.java} | 10 ++++----- ...est.java => GetWsResponseEncoderTest.java} | 10 ++++----- ...t.java => UpdateWsRequestEncoderTest.java} | 12 +++++----- ....java => UpdateWsResponseEncoderTest.java} | 10 ++++----- ...uestTest.java => CreateWsRequestTest.java} | 4 ++-- ...estTest.java => CreateWsResponseTest.java} | 4 ++-- ...Test.java => GetVersionWsRequestTest.java} | 4 ++-- ...esponseTest.java => GetWsRequestTest.java} | 4 ++-- ...equestTest.java => GetWsResponseTest.java} | 4 ++-- .../v1/model/UpdateResponseTest.java | 11 ---------- ...onseTest.java => UpdateWsRequestTest.java} | 4 ++-- .../v1/model/UpdateWsResponseTest.java | 11 ++++++++++ 66 files changed, 298 insertions(+), 299 deletions(-) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{CreateResponseDecoder.java => CreateWsRequestDecoder.java} (58%) create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsResponseDecoder.java rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{GetVersionRequestDecoder.java => GetVersionWsRequestDecoder.java} (66%) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{GetRequestDecoder.java => GetWsRequestDecoder.java} (60%) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{CreateRequestDecoder.java => GetWsResponseDecoder.java} (60%) delete mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoder.java delete mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoder.java rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{GetResponseDecoder.java => UpdateWsRequestDecoder.java} (58%) create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsResponseDecoder.java rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{CreateResponseEncoder.java => CreateWsRequestEncoder.java} (50%) create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsResponseEncoder.java rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{GetVersionRequestEncoder.java => GetVersionWsRequestEncoder.java} (59%) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{GetResponseEncoder.java => GetWsRequestEncoder.java} (52%) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{CreateRequestEncoder.java => GetWsResponseEncoder.java} (53%) delete mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoder.java delete mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoder.java rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{GetRequestEncoder.java => UpdateWsRequestEncoder.java} (50%) create mode 100644 app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsResponseEncoder.java rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/{CreateRequest.java => CreateWsRequest.java} (89%) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/{CreateResponse.java => CreateWsResponse.java} (89%) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/{GetVersionRequest.java => GetVersionWsRequest.java} (97%) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/{GetRequest.java => GetWsRequest.java} (97%) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/{GetResponse.java => GetWsResponse.java} (89%) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/{UpdateRequest.java => UpdateWsRequest.java} (91%) rename app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/{UpdateResponse.java => UpdateWsResponse.java} (89%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{CreateRequestDecoderTest.java => CreateWsRequestDecoderTest.java} (95%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{CreateResponseDecoderTest.java => CreateWsResponseDecoderTest.java} (94%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{GetVersionRequestDecoderTest.java => GetVersionWsRequestDecoderTest.java} (94%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{GetRequestDecoderTest.java => GetWsRequestDecoderTest.java} (94%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{GetResponseDecoderTest.java => GetWsResponseDecoderTest.java} (94%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{UpdateRequestDecoderTest.java => UpdateWsRequestDecoderTest.java} (95%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/{UpdateResponseDecoderTest.java => UpdateWsResponseDecoderTest.java} (94%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{CreateRequestEncoderTest.java => CreateWsRequestEncoderTest.java} (85%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{CreateResponseEncoderTest.java => CreateWsResponseEncoderTest.java} (82%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{GetVersionRequestEncoderTest.java => GetVersionWsRequestEncoderTest.java} (88%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{GetRequestEncoderTest.java => GetWsRequestEncoderTest.java} (83%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{GetResponseEncoderTest.java => GetWsResponseEncoderTest.java} (83%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{UpdateRequestEncoderTest.java => UpdateWsRequestEncoderTest.java} (87%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/{UpdateResponseEncoderTest.java => UpdateWsResponseEncoderTest.java} (82%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/{CreateRequestTest.java => CreateWsRequestTest.java} (69%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/{GetRequestTest.java => CreateWsResponseTest.java} (69%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/{GetVersionRequestTest.java => GetVersionWsRequestTest.java} (68%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/{GetResponseTest.java => GetWsRequestTest.java} (71%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/{UpdateRequestTest.java => GetWsResponseTest.java} (70%) delete mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponseTest.java rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/{CreateResponseTest.java => UpdateWsRequestTest.java} (69%) create mode 100644 app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsResponseTest.java diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java index 117b35d5..75131494 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java @@ -16,7 +16,7 @@ import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @Schema(description = "Request to create a new entry in the database containing the SCL Element content.") -@XmlRootElement(name = "CreateRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "CreateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) public class CreateRequest { @FilenameValid diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateResponse.java index b7593a22..dfdde196 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateResponse.java @@ -13,7 +13,7 @@ import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @Schema(description = "Response from creating a new entry in the database containing the SCL Element content.") -@XmlRootElement(name = "CreateResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "CreateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) public class CreateResponse { @Schema(description = "The XML Content of the updated SCL added to the database. The content contains a XML according to the IEC 61850 standard.", diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/GetResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/GetResponse.java index 89042351..d68ac60b 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/GetResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/GetResponse.java @@ -14,7 +14,7 @@ import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @Schema(description = "Response from retrieving a SCL from the database containing the SCL Content.") -@XmlRootElement(name = "GetResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "GetWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) public class GetResponse { @Schema(description = "The XML Content of the retrieved SCL from the database. The content contains a XML according to the IEC 61850 standard.", diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java index f64bc37c..4bb88de5 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java @@ -18,7 +18,7 @@ @Schema(description = "Request to update an existing entry in the database containing the SCL Element content. " + "A new version is created and the old version is also kept.") -@XmlRootElement(name = "UpdateRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "UpdateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) public class UpdateRequest { @NotNull(message = "{org.lfenergy.compas.changeset.notnull.message}") diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateResponse.java index a30a3e39..09dc4ad2 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateResponse.java @@ -14,7 +14,7 @@ import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @Schema(description = "Response from updating a new entry in the database containing the SCL Element content.") -@XmlRootElement(name = "UpdateResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "UpdateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) public class UpdateResponse { @Schema(description = "The XML Content of the updated SCL added to the database. The content contains a XML according to the IEC 61850 standard.", diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandler.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandler.java index 530a7a2c..2528e203 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandler.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandler.java @@ -10,9 +10,9 @@ import org.lfenergy.compas.scl.data.websocket.event.model.GetEventRequest; import org.lfenergy.compas.scl.data.websocket.event.model.GetVersionEventRequest; import org.lfenergy.compas.scl.data.websocket.event.model.UpdateEventRequest; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsResponse; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @@ -31,8 +31,8 @@ public CompasSclDataEventHandler(CompasSclDataService compasSclDataService) { @ConsumeEvent(value = "create-ws", blocking = true) public void createWebsocketsEvent(CreateEventRequest request) { - new WebsocketHandler().execute(request.getSession(), () -> { - var response = new CreateResponse(); + new WebsocketHandler().execute(request.getSession(), () -> { + var response = new CreateWsResponse(); response.setSclData(compasSclDataService.create(request.getType(), request.getName(), request.getWho(), request.getComment(), request.getSclData())); return response; @@ -41,8 +41,8 @@ public void createWebsocketsEvent(CreateEventRequest request) { @ConsumeEvent(value = "get-ws") public void getWebsocketsEvent(GetEventRequest request) { - new WebsocketHandler().execute(request.getSession(), () -> { - var response = new GetResponse(); + new WebsocketHandler().execute(request.getSession(), () -> { + var response = new GetWsResponse(); response.setSclData(compasSclDataService.findByUUID(request.getType(), request.getId())); return response; }); @@ -50,8 +50,8 @@ public void getWebsocketsEvent(GetEventRequest request) { @ConsumeEvent(value = "get-version-ws") public void getVersionWebsocketsEvent(GetVersionEventRequest request) { - new WebsocketHandler().execute(request.getSession(), () -> { - var response = new GetResponse(); + new WebsocketHandler().execute(request.getSession(), () -> { + var response = new GetWsResponse(); response.setSclData(compasSclDataService.findByUUID(request.getType(), request.getId(), request.getVersion())); return response; }); @@ -59,8 +59,8 @@ public void getVersionWebsocketsEvent(GetVersionEventRequest request) { @ConsumeEvent(value = "update-ws", blocking = true) public void updateWebsocketsEvent(UpdateEventRequest request) { - new WebsocketHandler().execute(request.getSession(), () -> { - var response = new UpdateResponse(); + new WebsocketHandler().execute(request.getSession(), () -> { + var response = new UpdateWsResponse(); response.setSclData(compasSclDataService.update(request.getType(), request.getId(), request.getChangeSetType(), request.getWho(), request.getComment(), request.getSclData())); return response; diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java index 2a7b89c9..3f520550 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpoint.java @@ -9,9 +9,9 @@ import org.lfenergy.compas.core.websocket.ErrorResponseEncoder; import org.lfenergy.compas.scl.data.rest.UserInfoProperties; import org.lfenergy.compas.scl.data.websocket.event.model.CreateEventRequest; -import org.lfenergy.compas.scl.data.websocket.v1.decoder.CreateRequestDecoder; -import org.lfenergy.compas.scl.data.websocket.v1.encoder.CreateResponseEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.CreateWsRequestDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.CreateWsResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsRequest; import org.lfenergy.compas.scl.extensions.model.SclFileType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,8 +28,8 @@ @Authenticated @ApplicationScoped @ServerEndpoint(value = "/scl-ws/v1/{" + TYPE_PATH_PARAM + "}/create", - decoders = {CreateRequestDecoder.class}, - encoders = {CreateResponseEncoder.class, ErrorResponseEncoder.class}) + decoders = {CreateWsRequestDecoder.class}, + encoders = {CreateWsResponseEncoder.class, ErrorResponseEncoder.class}) public class CompasSclCreateServerEndpoint { private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclCreateServerEndpoint.class); @@ -52,7 +52,7 @@ public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { } @OnMessage - public void onCreateMessage(Session session, CreateRequest request, @PathParam(TYPE_PATH_PARAM) String type) { + public void onCreateMessage(Session session, CreateWsRequest request, @PathParam(TYPE_PATH_PARAM) String type) { LOGGER.info("Message (create) from session {} for type {}.", session.getId(), type); String who = jsonWebToken.getClaim(userInfoProperties.who()); diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java index 84fbc66a..1f5fa11a 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpoint.java @@ -7,9 +7,9 @@ import io.vertx.mutiny.core.eventbus.EventBus; import org.lfenergy.compas.core.websocket.ErrorResponseEncoder; import org.lfenergy.compas.scl.data.websocket.event.model.GetEventRequest; -import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetRequestDecoder; -import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetResponseEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetWsRequestDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetWsResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsRequest; import org.lfenergy.compas.scl.extensions.model.SclFileType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,8 +26,8 @@ @Authenticated @ApplicationScoped @ServerEndpoint(value = "/scl-ws/v1/{" + TYPE_PATH_PARAM + "}/get", - decoders = {GetRequestDecoder.class}, - encoders = {GetResponseEncoder.class, ErrorResponseEncoder.class}) + decoders = {GetWsRequestDecoder.class}, + encoders = {GetWsResponseEncoder.class, ErrorResponseEncoder.class}) public class CompasSclGetServerEndpoint { private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclGetServerEndpoint.class); @@ -45,7 +45,7 @@ public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { @OnMessage public void onGetMessage(Session session, - GetRequest request, + GetWsRequest request, @PathParam(TYPE_PATH_PARAM) String type) { LOGGER.info("Message (get) from session {} for type {}.", session.getId(), type); diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java index 3b4b9dc9..7d7b361a 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpoint.java @@ -8,9 +8,9 @@ import org.lfenergy.compas.core.websocket.ErrorResponseEncoder; import org.lfenergy.compas.scl.data.model.Version; import org.lfenergy.compas.scl.data.websocket.event.model.GetVersionEventRequest; -import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetVersionRequestDecoder; -import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetResponseEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetVersionWsRequestDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetWsResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionWsRequest; import org.lfenergy.compas.scl.extensions.model.SclFileType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,8 +27,8 @@ @Authenticated @ApplicationScoped @ServerEndpoint(value = "/scl-ws/v1/{" + TYPE_PATH_PARAM + "}/get-version", - decoders = {GetVersionRequestDecoder.class}, - encoders = {GetResponseEncoder.class, ErrorResponseEncoder.class}) + decoders = {GetVersionWsRequestDecoder.class}, + encoders = {GetWsResponseEncoder.class, ErrorResponseEncoder.class}) public class CompasSclGetVersionServerEndpoint { private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclGetVersionServerEndpoint.class); @@ -46,7 +46,7 @@ public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { @OnMessage public void onGetVersionMessage(Session session, - GetVersionRequest request, + GetVersionWsRequest request, @PathParam(TYPE_PATH_PARAM) String type) { LOGGER.info("Message from session {} for type {}.", session.getId(), type); diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java index f096c823..d0db47bc 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpoint.java @@ -9,9 +9,9 @@ import org.lfenergy.compas.core.websocket.ErrorResponseEncoder; import org.lfenergy.compas.scl.data.rest.UserInfoProperties; import org.lfenergy.compas.scl.data.websocket.event.model.UpdateEventRequest; -import org.lfenergy.compas.scl.data.websocket.v1.decoder.UpdateRequestDecoder; -import org.lfenergy.compas.scl.data.websocket.v1.encoder.UpdateResponseEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.UpdateWsRequestDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.UpdateWsResponseEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsRequest; import org.lfenergy.compas.scl.extensions.model.SclFileType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,8 +28,8 @@ @Authenticated @ApplicationScoped @ServerEndpoint(value = "/scl-ws/v1/{" + TYPE_PATH_PARAM + "}/update", - decoders = {UpdateRequestDecoder.class}, - encoders = {UpdateResponseEncoder.class, ErrorResponseEncoder.class}) + decoders = {UpdateWsRequestDecoder.class}, + encoders = {UpdateWsResponseEncoder.class, ErrorResponseEncoder.class}) public class CompasSclUpdateServerEndpoint { private static final Logger LOGGER = LoggerFactory.getLogger(CompasSclUpdateServerEndpoint.class); @@ -52,7 +52,7 @@ public void onOpen(Session session, @PathParam(TYPE_PATH_PARAM) String type) { } @OnMessage - public void onUpdateMessage(Session session, UpdateRequest request, + public void onUpdateMessage(Session session, UpdateWsRequest request, @PathParam(TYPE_PATH_PARAM) String type) { LOGGER.info("Message (update) from session {} for type {}.", session.getId(), type); diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsRequestDecoder.java similarity index 58% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsRequestDecoder.java index 82a5f7a5..c0af36cb 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsRequestDecoder.java @@ -5,16 +5,16 @@ import org.lfenergy.compas.core.websocket.AbstractDecoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsRequest; -public class CreateResponseDecoder extends AbstractDecoder { +public class CreateWsRequestDecoder extends AbstractDecoder { @Override public boolean willDecode(String message) { return (message != null); } @Override - public CreateResponse decode(String message) { - return WebsocketSupport.decode(message, CreateResponse.class); + public CreateWsRequest decode(String message) { + return WebsocketSupport.decode(message, CreateWsRequest.class); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsResponseDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsResponseDecoder.java new file mode 100644 index 00000000..980a85d9 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsResponseDecoder.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.decoder; + +import org.lfenergy.compas.core.websocket.AbstractDecoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsResponse; + +public class CreateWsResponseDecoder extends AbstractDecoder { + @Override + public boolean willDecode(String message) { + return (message != null); + } + + @Override + public CreateWsResponse decode(String message) { + return WebsocketSupport.decode(message, CreateWsResponse.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionWsRequestDecoder.java similarity index 66% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionWsRequestDecoder.java index 539c20c7..91359c57 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionWsRequestDecoder.java @@ -5,16 +5,16 @@ import org.lfenergy.compas.core.websocket.AbstractDecoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionWsRequest; -public class GetVersionRequestDecoder extends AbstractDecoder { +public class GetVersionWsRequestDecoder extends AbstractDecoder { @Override public boolean willDecode(String message) { return (message != null); } @Override - public GetVersionRequest decode(String message) { - return WebsocketSupport.decode(message, GetVersionRequest.class); + public GetVersionWsRequest decode(String message) { + return WebsocketSupport.decode(message, GetVersionWsRequest.class); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsRequestDecoder.java similarity index 60% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsRequestDecoder.java index 23a0377b..6972d5ec 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsRequestDecoder.java @@ -5,16 +5,16 @@ import org.lfenergy.compas.core.websocket.AbstractDecoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsRequest; -public class GetRequestDecoder extends AbstractDecoder { +public class GetWsRequestDecoder extends AbstractDecoder { @Override public boolean willDecode(String message) { return (message != null); } @Override - public GetRequest decode(String message) { - return WebsocketSupport.decode(message, GetRequest.class); + public GetWsRequest decode(String message) { + return WebsocketSupport.decode(message, GetWsRequest.class); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsResponseDecoder.java similarity index 60% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsResponseDecoder.java index 46215ff8..b591ace2 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsResponseDecoder.java @@ -5,16 +5,16 @@ import org.lfenergy.compas.core.websocket.AbstractDecoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; -public class CreateRequestDecoder extends AbstractDecoder { +public class GetWsResponseDecoder extends AbstractDecoder { @Override public boolean willDecode(String message) { return (message != null); } @Override - public CreateRequest decode(String message) { - return WebsocketSupport.decode(message, CreateRequest.class); + public GetWsResponse decode(String message) { + return WebsocketSupport.decode(message, GetWsResponse.class); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoder.java deleted file mode 100644 index 72047ddf..00000000 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoder.java +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Alliander N.V. -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.websocket.v1.decoder; - -import org.lfenergy.compas.core.websocket.AbstractDecoder; -import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateRequest; - -public class UpdateRequestDecoder extends AbstractDecoder { - @Override - public boolean willDecode(String message) { - return (message != null); - } - - @Override - public UpdateRequest decode(String message) { - return WebsocketSupport.decode(message, UpdateRequest.class); - } -} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoder.java deleted file mode 100644 index 0aabd610..00000000 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoder.java +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Alliander N.V. -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.websocket.v1.decoder; - -import org.lfenergy.compas.core.websocket.AbstractDecoder; -import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; - -public class UpdateResponseDecoder extends AbstractDecoder { - @Override - public boolean willDecode(String message) { - return (message != null); - } - - @Override - public UpdateResponse decode(String message) { - return WebsocketSupport.decode(message, UpdateResponse.class); - } -} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsRequestDecoder.java similarity index 58% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsRequestDecoder.java index c24fbb26..1a922e85 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsRequestDecoder.java @@ -5,16 +5,16 @@ import org.lfenergy.compas.core.websocket.AbstractDecoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsRequest; -public class GetResponseDecoder extends AbstractDecoder { +public class UpdateWsRequestDecoder extends AbstractDecoder { @Override public boolean willDecode(String message) { return (message != null); } @Override - public GetResponse decode(String message) { - return WebsocketSupport.decode(message, GetResponse.class); + public UpdateWsRequest decode(String message) { + return WebsocketSupport.decode(message, UpdateWsRequest.class); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsResponseDecoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsResponseDecoder.java new file mode 100644 index 00000000..32f2b754 --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsResponseDecoder.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.decoder; + +import org.lfenergy.compas.core.websocket.AbstractDecoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsResponse; + +public class UpdateWsResponseDecoder extends AbstractDecoder { + @Override + public boolean willDecode(String message) { + return (message != null); + } + + @Override + public UpdateWsResponse decode(String message) { + return WebsocketSupport.decode(message, UpdateWsResponse.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsRequestEncoder.java similarity index 50% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsRequestEncoder.java index e8ecafc9..ba68c56a 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsRequestEncoder.java @@ -5,11 +5,11 @@ import org.lfenergy.compas.core.websocket.AbstractEncoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsRequest; -public class CreateResponseEncoder extends AbstractEncoder { +public class CreateWsRequestEncoder extends AbstractEncoder { @Override - public String encode(CreateResponse jaxbObject) { - return WebsocketSupport.encode(jaxbObject, CreateResponse.class); + public String encode(CreateWsRequest jaxbObject) { + return WebsocketSupport.encode(jaxbObject, CreateWsRequest.class); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsResponseEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsResponseEncoder.java new file mode 100644 index 00000000..ed87efde --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsResponseEncoder.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.encoder; + +import org.lfenergy.compas.core.websocket.AbstractEncoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsResponse; + +public class CreateWsResponseEncoder extends AbstractEncoder { + @Override + public String encode(CreateWsResponse jaxbObject) { + return WebsocketSupport.encode(jaxbObject, CreateWsResponse.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionWsRequestEncoder.java similarity index 59% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionWsRequestEncoder.java index 05beac39..22809767 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionWsRequestEncoder.java @@ -5,11 +5,11 @@ import org.lfenergy.compas.core.websocket.AbstractEncoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionWsRequest; -public class GetVersionRequestEncoder extends AbstractEncoder { +public class GetVersionWsRequestEncoder extends AbstractEncoder { @Override - public String encode(GetVersionRequest jaxbObject) { - return WebsocketSupport.encode(jaxbObject, GetVersionRequest.class); + public String encode(GetVersionWsRequest jaxbObject) { + return WebsocketSupport.encode(jaxbObject, GetVersionWsRequest.class); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsRequestEncoder.java similarity index 52% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsRequestEncoder.java index fa9fd865..80bf74ef 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsRequestEncoder.java @@ -5,11 +5,11 @@ import org.lfenergy.compas.core.websocket.AbstractEncoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsRequest; -public class GetResponseEncoder extends AbstractEncoder { +public class GetWsRequestEncoder extends AbstractEncoder { @Override - public String encode(GetResponse jaxbObject) { - return WebsocketSupport.encode(jaxbObject, GetResponse.class); + public String encode(GetWsRequest jaxbObject) { + return WebsocketSupport.encode(jaxbObject, GetWsRequest.class); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsResponseEncoder.java similarity index 53% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsResponseEncoder.java index d96d9934..2803cf5d 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsResponseEncoder.java @@ -5,11 +5,11 @@ import org.lfenergy.compas.core.websocket.AbstractEncoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; -public class CreateRequestEncoder extends AbstractEncoder { +public class GetWsResponseEncoder extends AbstractEncoder { @Override - public String encode(CreateRequest jaxbObject) { - return WebsocketSupport.encode(jaxbObject, CreateRequest.class); + public String encode(GetWsResponse jaxbObject) { + return WebsocketSupport.encode(jaxbObject, GetWsResponse.class); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoder.java deleted file mode 100644 index 1b2b735d..00000000 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoder.java +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Alliander N.V. -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.websocket.v1.encoder; - -import org.lfenergy.compas.core.websocket.AbstractEncoder; -import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateRequest; - -public class UpdateRequestEncoder extends AbstractEncoder { - @Override - public String encode(UpdateRequest jaxbObject) { - return WebsocketSupport.encode(jaxbObject, UpdateRequest.class); - } -} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoder.java deleted file mode 100644 index 4aba712b..00000000 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoder.java +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Alliander N.V. -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.websocket.v1.encoder; - -import org.lfenergy.compas.core.websocket.AbstractEncoder; -import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; - -public class UpdateResponseEncoder extends AbstractEncoder { - @Override - public String encode(UpdateResponse jaxbObject) { - return WebsocketSupport.encode(jaxbObject, UpdateResponse.class); - } -} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsRequestEncoder.java similarity index 50% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoder.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsRequestEncoder.java index 67f3f0c7..b3b8b710 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoder.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsRequestEncoder.java @@ -5,11 +5,11 @@ import org.lfenergy.compas.core.websocket.AbstractEncoder; import org.lfenergy.compas.core.websocket.WebsocketSupport; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsRequest; -public class GetRequestEncoder extends AbstractEncoder { +public class UpdateWsRequestEncoder extends AbstractEncoder { @Override - public String encode(GetRequest jaxbObject) { - return WebsocketSupport.encode(jaxbObject, GetRequest.class); + public String encode(UpdateWsRequest jaxbObject) { + return WebsocketSupport.encode(jaxbObject, UpdateWsRequest.class); } } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsResponseEncoder.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsResponseEncoder.java new file mode 100644 index 00000000..4c5cbfdc --- /dev/null +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsResponseEncoder.java @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2022 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.encoder; + +import org.lfenergy.compas.core.websocket.AbstractEncoder; +import org.lfenergy.compas.core.websocket.WebsocketSupport; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsResponse; + +public class UpdateWsResponseEncoder extends AbstractEncoder { + @Override + public String encode(UpdateWsResponse jaxbObject) { + return WebsocketSupport.encode(jaxbObject, UpdateWsResponse.class); + } +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsRequest.java similarity index 89% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsRequest.java index 1105db49..3748261b 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsRequest.java @@ -17,6 +17,6 @@ @XmlType(name = "CreateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "CreateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class CreateRequest extends org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest { +public class CreateWsRequest extends org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest { } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsResponse.java similarity index 89% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsResponse.java index febf25dd..7a330bc3 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsResponse.java @@ -16,5 +16,5 @@ @XmlType(name = "CreateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "CreateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class CreateResponse extends org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse { +public class CreateWsResponse extends org.lfenergy.compas.scl.data.rest.v1.model.CreateResponse { } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionWsRequest.java similarity index 97% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequest.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionWsRequest.java index 074d1bd3..adb35382 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionWsRequest.java @@ -15,7 +15,7 @@ @XmlType(name = "GetVersionWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "GetVersionWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class GetVersionRequest { +public class GetVersionWsRequest { @Schema(description = "The ID of the SCL File.", example = "f7b98f4d-3fe4-4df2-8533-d7f0c1800344") @XmlElement(name = "Id", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsRequest.java similarity index 97% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequest.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsRequest.java index 66bbde2a..0adc19ba 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsRequest.java @@ -15,7 +15,7 @@ @XmlType(name = "GetWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "GetWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class GetRequest { +public class GetWsRequest { @Schema(description = "The ID of the SCL File.", example = "f7b98f4d-3fe4-4df2-8533-d7f0c1800344") @XmlElement(name = "Id", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsResponse.java similarity index 89% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsResponse.java index bb25aa25..50c51a4d 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsResponse.java @@ -17,5 +17,5 @@ @XmlType(name = "GetWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "GetWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class GetResponse extends org.lfenergy.compas.scl.data.rest.v1.model.GetResponse { +public class GetWsResponse extends org.lfenergy.compas.scl.data.rest.v1.model.GetResponse { } diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsRequest.java similarity index 91% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsRequest.java index c08d8c87..9429a93a 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsRequest.java @@ -16,7 +16,7 @@ @XmlType(name = "UpdateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "UpdateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class UpdateRequest extends org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest { +public class UpdateWsRequest extends org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest { @Schema(description = "The ID of the SCL File.", example = "f7b98f4d-3fe4-4df2-8533-d7f0c1800344") @XmlElement(name = "Id", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsResponse.java similarity index 89% rename from app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java rename to app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsResponse.java index 8e72ae50..8e67b561 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsResponse.java @@ -17,5 +17,5 @@ @XmlType(name = "UpdateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlRootElement(name = "UpdateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) -public class UpdateResponse extends org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse { +public class UpdateWsResponse extends org.lfenergy.compas.scl.data.rest.v1.model.UpdateResponse { } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java index d27ebf15..ecf8a151 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java @@ -117,7 +117,7 @@ void findByUUID_WhenCalled_ThenSCLResponseRetrieved() throws IOException { var xmlPath = response.xmlPath() .using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI)); - assertEquals(scl, xmlPath.get("GetResponse.SclData")); + assertEquals(scl, xmlPath.get("GetWsResponse.SclData")); verify(compasSclDataService, times(1)).findByUUID(type, uuid); } @@ -142,7 +142,7 @@ void findByUUIDAndVersion_WhenCalled_ThenSCLResponseRetrieved() throws IOExcepti var xmlPath = response.xmlPath() .using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI)); - assertEquals(scl, xmlPath.get("GetResponse.SclData")); + assertEquals(scl, xmlPath.get("GetWsResponse.SclData")); verify(compasSclDataService, times(1)).findByUUID(type, uuid, version); } @@ -170,7 +170,7 @@ void create_WhenCalled_ThenServiceCalledAndUUIDRetrieved() throws IOException { .extract() .response(); - assertEquals(scl, response.xmlPath().getString("CreateResponse.SclData")); + assertEquals(scl, response.xmlPath().getString("CreateWsResponse.SclData")); verify(compasSclDataService, times(1)).create(type, name, USERNAME, comment, scl); } @@ -227,7 +227,7 @@ void update_WhenCalled_ThenServiceCalledAndNewUUIDRetrieved() throws IOException .extract() .response(); - assertEquals(scl, response.xmlPath().getString("CreateResponse.SclData")); + assertEquals(scl, response.xmlPath().getString("CreateWsResponse.SclData")); verify(compasSclDataService, times(1)).update(type, uuid, changeSetType, USERNAME, comment, scl); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java index f638417c..0b400983 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java @@ -109,7 +109,7 @@ void findByUUID_WhenCalled_ThenSCLResponseRetrieved() throws IOException { var xmlPath = response.xmlPath() .using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI)); - assertEquals(scl, xmlPath.get("GetResponse.SclData")); + assertEquals(scl, xmlPath.get("GetWsResponse.SclData")); verify(compasSclDataService, times(1)).findByUUID(type, uuid); } @@ -134,7 +134,7 @@ void findByUUIDAndVersion_WhenCalled_ThenSCLResponseRetrieved() throws IOExcepti var xmlPath = response.xmlPath() .using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI)); - assertEquals(scl, xmlPath.get("GetResponse.SclData")); + assertEquals(scl, xmlPath.get("GetWsResponse.SclData")); verify(compasSclDataService, times(1)).findByUUID(type, uuid, version); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java index da58fd2d..bebcec22 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java @@ -14,9 +14,9 @@ import org.lfenergy.compas.scl.data.websocket.event.model.GetEventRequest; import org.lfenergy.compas.scl.data.websocket.event.model.GetVersionEventRequest; import org.lfenergy.compas.scl.data.websocket.event.model.UpdateEventRequest; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsResponse; import org.lfenergy.compas.scl.extensions.model.SclFileType; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; @@ -55,7 +55,7 @@ void createWebsocketsEvent_WhenCalled_ThenCreateResponseReturned() { eventHandler.createWebsocketsEvent(request); - var response = verifyResponse(session, CreateResponse.class); + var response = verifyResponse(session, CreateWsResponse.class); assertEquals(sclData, response.getSclData()); verify(service, times(1)).create(type, name, who, comment, sclData); } @@ -111,7 +111,7 @@ void getWebsocketsEvent_WhenCalled_ThenGetResponseReturned() { eventHandler.getWebsocketsEvent(request); - var response = verifyResponse(session, GetResponse.class); + var response = verifyResponse(session, GetWsResponse.class); assertEquals(sclData, response.getSclData()); verify(service, times(1)).findByUUID(type, id); } @@ -162,7 +162,7 @@ void getVersionWebsocketsEvent_WhenCalled_ThenGetResponseReturned() { eventHandler.getVersionWebsocketsEvent(request); - var response = verifyResponse(session, GetResponse.class); + var response = verifyResponse(session, GetWsResponse.class); assertEquals(sclData, response.getSclData()); verify(service, times(1)).findByUUID(type, id, version); } @@ -217,7 +217,7 @@ void updateWebsocketsEvent_WhenCalled_ThenUpdateResponseReturned() { eventHandler.updateWebsocketsEvent(request); - var response = verifyResponse(session, UpdateResponse.class); + var response = verifyResponse(session, UpdateWsResponse.class); assertEquals(sclData, response.getSclData()); verify(service, times(1)).update(type, id, cst, who, comment, sclData); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java index ef4be838..fa77d524 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java @@ -8,10 +8,10 @@ import io.quarkus.test.junit.mockito.InjectMock; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.service.CompasSclDataService; -import org.lfenergy.compas.scl.data.websocket.v1.decoder.CreateResponseDecoder; -import org.lfenergy.compas.scl.data.websocket.v1.encoder.CreateRequestEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateRequest; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.CreateWsResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.CreateWsRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsResponse; import org.lfenergy.compas.scl.extensions.model.SclFileType; import javax.websocket.ClientEndpoint; @@ -32,13 +32,13 @@ class CompasSclCreateServerEndpointAsEditorTest extends AbstractServerEndpointAs @Test void createSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { - var encoder = new CreateRequestEncoder(); + var encoder = new CreateWsRequestEncoder(); var sclFileTye = SclFileType.SCD; var name = "Some name"; var comment = "Some comment"; var sclData = readSCL(); - var request = new CreateRequest(); + var request = new CreateWsRequest(); request.setName(name); request.setComment(comment); request.setSclData(sclData); @@ -59,10 +59,10 @@ void createSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception testWhenCalledWithInvalidTextThenExceptionThrown(uri); } - @ClientEndpoint(decoders = CreateResponseDecoder.class) + @ClientEndpoint(decoders = CreateWsResponseDecoder.class) static class Client { @OnMessage - public void onMessage(CreateResponse response) { + public void onMessage(CreateWsResponse response) { sclDataQueue.add(response.getSclData()); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java index 0289e137..e88c6caa 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java @@ -8,10 +8,10 @@ import io.quarkus.test.junit.mockito.InjectMock; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.service.CompasSclDataService; -import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetResponseDecoder; -import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetRequestEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetWsResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetWsRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; import org.lfenergy.compas.scl.extensions.model.SclFileType; import javax.websocket.ClientEndpoint; @@ -20,7 +20,6 @@ import javax.websocket.Session; import java.net.URI; import java.util.UUID; -import java.util.concurrent.TimeUnit; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; @@ -35,12 +34,12 @@ class CompasSclGetServerEndpointAsEditorTest extends AbstractServerEndpointAsEdi @Test void getSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { - var encoder = new GetRequestEncoder(); + var encoder = new GetWsRequestEncoder(); var sclFileTye = SclFileType.SCD; var id = UUID.randomUUID(); var sclData = readSCL(); - var request = new GetRequest(); + var request = new GetWsRequest(); request.setId(id); when(service.findByUUID(sclFileTye, id)).thenReturn(sclData); @@ -58,10 +57,10 @@ void getSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception { testWhenCalledWithInvalidTextThenExceptionThrown(uri); } - @ClientEndpoint(decoders = GetResponseDecoder.class) + @ClientEndpoint(decoders = GetWsResponseDecoder.class) static class Client { @OnMessage - public void onMessage(GetResponse response) { + public void onMessage(GetWsResponse response) { sclDataQueue.add(response.getSclData()); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java index 6bc44bf7..d863bae6 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java @@ -8,10 +8,10 @@ import io.quarkus.test.junit.mockito.InjectMock; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.service.CompasSclDataService; -import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetResponseDecoder; -import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetRequestEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetWsResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetWsRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; import org.lfenergy.compas.scl.extensions.model.SclFileType; import javax.websocket.ClientEndpoint; @@ -33,12 +33,12 @@ class CompasSclGetServerEndpointAsReaderTest extends AbstractServerEndpointAsRea @Test void getSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { - var encoder = new GetRequestEncoder(); + var encoder = new GetWsRequestEncoder(); var sclFileTye = SclFileType.SCD; var id = UUID.randomUUID(); var sclData = readSCL(); - var request = new GetRequest(); + var request = new GetWsRequest(); request.setId(id); when(service.findByUUID(sclFileTye, id)).thenReturn(sclData); @@ -56,10 +56,10 @@ void getSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception { testWhenCalledWithInvalidTextThenExceptionThrown(uri); } - @ClientEndpoint(decoders = GetResponseDecoder.class) + @ClientEndpoint(decoders = GetWsResponseDecoder.class) static class Client { @OnMessage - public void onMessage(GetResponse response) { + public void onMessage(GetWsResponse response) { sclDataQueue.add(response.getSclData()); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java index d4ce1fd6..8e0bc3b6 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java @@ -9,10 +9,10 @@ import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.model.Version; import org.lfenergy.compas.scl.data.service.CompasSclDataService; -import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetResponseDecoder; -import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetVersionRequestEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetWsResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetVersionWsRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionWsRequest; import org.lfenergy.compas.scl.extensions.model.SclFileType; import javax.websocket.ClientEndpoint; @@ -34,13 +34,13 @@ class CompasSclGetVersionServerEndpointAsEditorTest extends AbstractServerEndpoi @Test void getVersionSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { - var encoder = new GetVersionRequestEncoder(); + var encoder = new GetVersionWsRequestEncoder(); var sclFileTye = SclFileType.SCD; var id = UUID.randomUUID(); var version = new Version("1.2.3"); var sclData = readSCL(); - var request = new GetVersionRequest(); + var request = new GetVersionWsRequest(); request.setId(id); request.setVersion(version.toString()); @@ -59,10 +59,10 @@ void getSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception { testWhenCalledWithInvalidTextThenExceptionThrown(uri); } - @ClientEndpoint(decoders = GetResponseDecoder.class) + @ClientEndpoint(decoders = GetWsResponseDecoder.class) static class Client { @OnMessage - public void onMessage(GetResponse response) { + public void onMessage(GetWsResponse response) { sclDataQueue.add(response.getSclData()); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java index 11b28589..28651b96 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java @@ -9,10 +9,10 @@ import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.model.Version; import org.lfenergy.compas.scl.data.service.CompasSclDataService; -import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetResponseDecoder; -import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetVersionRequestEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetWsResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetVersionWsRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionWsRequest; import org.lfenergy.compas.scl.extensions.model.SclFileType; import javax.websocket.ClientEndpoint; @@ -34,13 +34,13 @@ class CompasSclGetVersionServerEndpointAsReaderTest extends AbstractServerEndpoi @Test void getVersionSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { - var encoder = new GetVersionRequestEncoder(); + var encoder = new GetVersionWsRequestEncoder(); var sclFileTye = SclFileType.SCD; var id = UUID.randomUUID(); var version = new Version("1.2.3"); var sclData = readSCL(); - var request = new GetVersionRequest(); + var request = new GetVersionWsRequest(); request.setId(id); request.setVersion(version.toString()); @@ -59,10 +59,10 @@ void getSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception { testWhenCalledWithInvalidTextThenExceptionThrown(uri); } - @ClientEndpoint(decoders = GetResponseDecoder.class) + @ClientEndpoint(decoders = GetWsResponseDecoder.class) static class Client { @OnMessage - public void onMessage(GetResponse response) { + public void onMessage(GetWsResponse response) { sclDataQueue.add(response.getSclData()); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java index cc4e9d65..38659025 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java @@ -9,10 +9,10 @@ import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.model.ChangeSetType; import org.lfenergy.compas.scl.data.service.CompasSclDataService; -import org.lfenergy.compas.scl.data.websocket.v1.decoder.UpdateResponseDecoder; -import org.lfenergy.compas.scl.data.websocket.v1.encoder.UpdateRequestEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateRequest; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.decoder.UpdateWsResponseDecoder; +import org.lfenergy.compas.scl.data.websocket.v1.encoder.UpdateWsRequestEncoder; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsResponse; import org.lfenergy.compas.scl.extensions.model.SclFileType; import javax.websocket.ClientEndpoint; @@ -34,14 +34,14 @@ class CompasSclUpdateServerEndpointAsEditorTest extends AbstractServerEndpointAs @Test void updateSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { - var encoder = new UpdateRequestEncoder(); + var encoder = new UpdateWsRequestEncoder(); var sclFileTye = SclFileType.SCD; var id = UUID.randomUUID(); var cst = ChangeSetType.PATCH; var comment = "Some comment"; var sclData = readSCL(); - var request = new UpdateRequest(); + var request = new UpdateWsRequest(); request.setId(id); request.setChangeSetType(cst); request.setComment(comment); @@ -63,10 +63,10 @@ void createSCL_WhenCalledWithInvalidText_ThenExceptionThrown() throws Exception testWhenCalledWithInvalidTextThenExceptionThrown(uri); } - @ClientEndpoint(decoders = UpdateResponseDecoder.class) + @ClientEndpoint(decoders = UpdateWsResponseDecoder.class) static class Client { @OnMessage - public void onMessage(UpdateResponse response) { + public void onMessage(UpdateWsResponse response) { sclDataQueue.add(response.getSclData()); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsRequestDecoderTest.java similarity index 95% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsRequestDecoderTest.java index 685d68e0..f0253a10 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateRequestDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsRequestDecoderTest.java @@ -14,12 +14,12 @@ import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class CreateRequestDecoderTest { - private CreateRequestDecoder decoder; +class CreateWsRequestDecoderTest { + private CreateWsRequestDecoder decoder; @BeforeEach void init() { - decoder = new CreateRequestDecoder(); + decoder = new CreateWsRequestDecoder(); decoder.init(null); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsResponseDecoderTest.java similarity index 94% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsResponseDecoderTest.java index 385510c1..3d2e26d5 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateResponseDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/CreateWsResponseDecoderTest.java @@ -14,12 +14,12 @@ import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class CreateResponseDecoderTest { - private CreateResponseDecoder decoder; +class CreateWsResponseDecoderTest { + private CreateWsResponseDecoder decoder; @BeforeEach void init() { - decoder = new CreateResponseDecoder(); + decoder = new CreateWsResponseDecoder(); decoder.init(null); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionWsRequestDecoderTest.java similarity index 94% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionWsRequestDecoderTest.java index 7236fe01..11d957d8 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionRequestDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetVersionWsRequestDecoderTest.java @@ -16,12 +16,12 @@ import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class GetVersionRequestDecoderTest { - private GetVersionRequestDecoder decoder; +class GetVersionWsRequestDecoderTest { + private GetVersionWsRequestDecoder decoder; @BeforeEach void init() { - decoder = new GetVersionRequestDecoder(); + decoder = new GetVersionWsRequestDecoder(); decoder.init(null); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsRequestDecoderTest.java similarity index 94% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsRequestDecoderTest.java index 6f3811dc..58fcd263 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetRequestDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsRequestDecoderTest.java @@ -15,12 +15,12 @@ import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class GetRequestDecoderTest { - private GetRequestDecoder decoder; +class GetWsRequestDecoderTest { + private GetWsRequestDecoder decoder; @BeforeEach void init() { - decoder = new GetRequestDecoder(); + decoder = new GetWsRequestDecoder(); decoder.init(null); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsResponseDecoderTest.java similarity index 94% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsResponseDecoderTest.java index d929da83..fe1deb4d 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetResponseDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/GetWsResponseDecoderTest.java @@ -14,12 +14,12 @@ import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class GetResponseDecoderTest { - private GetResponseDecoder decoder; +class GetWsResponseDecoderTest { + private GetWsResponseDecoder decoder; @BeforeEach void init() { - decoder = new GetResponseDecoder(); + decoder = new GetWsResponseDecoder(); decoder.init(null); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsRequestDecoderTest.java similarity index 95% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsRequestDecoderTest.java index 3aea12d0..4beb9d89 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateRequestDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsRequestDecoderTest.java @@ -16,12 +16,12 @@ import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class UpdateRequestDecoderTest { - private UpdateRequestDecoder decoder; +class UpdateWsRequestDecoderTest { + private UpdateWsRequestDecoder decoder; @BeforeEach void init() { - decoder = new UpdateRequestDecoder(); + decoder = new UpdateWsRequestDecoder(); decoder.init(null); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsResponseDecoderTest.java similarity index 94% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsResponseDecoderTest.java index 16ba18f8..55ca2a67 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateResponseDecoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/decoder/UpdateWsResponseDecoderTest.java @@ -14,12 +14,12 @@ import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class UpdateResponseDecoderTest { - private UpdateResponseDecoder decoder; +class UpdateWsResponseDecoderTest { + private UpdateWsResponseDecoder decoder; @BeforeEach void init() { - decoder = new UpdateResponseDecoder(); + decoder = new UpdateWsResponseDecoder(); decoder.init(null); } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsRequestEncoderTest.java similarity index 85% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsRequestEncoderTest.java index 79115dd3..e9085761 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateRequestEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsRequestEncoderTest.java @@ -6,18 +6,18 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsRequest; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class CreateRequestEncoderTest { - private CreateRequestEncoder encoder; +class CreateWsRequestEncoderTest { + private CreateWsRequestEncoder encoder; @BeforeEach void init() { - encoder = new CreateRequestEncoder(); + encoder = new CreateWsRequestEncoder(); encoder.init(null); } @@ -27,7 +27,7 @@ void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var name = "Some name"; var comment = "Some comment"; - var request = new CreateRequest(); + var request = new CreateWsRequest(); request.setName(name); request.setComment(comment); request.setSclData(sclData); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsResponseEncoderTest.java similarity index 82% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsResponseEncoderTest.java index ddb38b92..4e312084 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateResponseEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/CreateWsResponseEncoderTest.java @@ -6,18 +6,18 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl.data.websocket.v1.model.CreateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.CreateWsResponse; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class CreateResponseEncoderTest { - private CreateResponseEncoder encoder; +class CreateWsResponseEncoderTest { + private CreateWsResponseEncoder encoder; @BeforeEach void init() { - encoder = new CreateResponseEncoder(); + encoder = new CreateWsResponseEncoder(); encoder.init(null); } @@ -25,7 +25,7 @@ void init() { void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var sclData = "Some SCL Data"; - var request = new CreateResponse(); + var request = new CreateWsResponse(); request.setSclData(sclData); var result = encoder.encode(request); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionWsRequestEncoderTest.java similarity index 88% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionWsRequestEncoderTest.java index 67c1d528..df8e8ddf 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionRequestEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetVersionWsRequestEncoderTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.model.Version; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionWsRequest; import java.util.UUID; @@ -15,12 +15,12 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class GetVersionRequestEncoderTest { - private GetVersionRequestEncoder encoder; +class GetVersionWsRequestEncoderTest { + private GetVersionWsRequestEncoder encoder; @BeforeEach void init() { - encoder = new GetVersionRequestEncoder(); + encoder = new GetVersionWsRequestEncoder(); encoder.init(null); } @@ -29,7 +29,7 @@ void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var id = UUID.randomUUID(); var version = new Version("1.2.3"); - var request = new GetVersionRequest(); + var request = new GetVersionWsRequest(); request.setId(id); request.setVersion(version.toString()); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsRequestEncoderTest.java similarity index 83% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsRequestEncoderTest.java index 0102a675..eafe034f 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetRequestEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsRequestEncoderTest.java @@ -6,7 +6,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsRequest; import java.util.UUID; @@ -14,12 +14,12 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class GetRequestEncoderTest { - private GetRequestEncoder encoder; +class GetWsRequestEncoderTest { + private GetWsRequestEncoder encoder; @BeforeEach void init() { - encoder = new GetRequestEncoder(); + encoder = new GetWsRequestEncoder(); encoder.init(null); } @@ -27,7 +27,7 @@ void init() { void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var id = UUID.randomUUID(); - var request = new GetRequest(); + var request = new GetWsRequest(); request.setId(id); var result = encoder.encode(request); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsResponseEncoderTest.java similarity index 83% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsResponseEncoderTest.java index 738581bc..1770a984 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetResponseEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/GetWsResponseEncoderTest.java @@ -6,18 +6,18 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class GetResponseEncoderTest { - private GetResponseEncoder encoder; +class GetWsResponseEncoderTest { + private GetWsResponseEncoder encoder; @BeforeEach void init() { - encoder = new GetResponseEncoder(); + encoder = new GetWsResponseEncoder(); encoder.init(null); } @@ -25,7 +25,7 @@ void init() { void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var sclData = "Some SCL Data"; - var request = new GetResponse(); + var request = new GetWsResponse(); request.setSclData(sclData); var result = encoder.encode(request); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsRequestEncoderTest.java similarity index 87% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsRequestEncoderTest.java index 2128f1a9..5e2a3e30 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateRequestEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsRequestEncoderTest.java @@ -7,7 +7,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.lfenergy.compas.scl.data.model.ChangeSetType; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsRequest; import java.util.UUID; @@ -15,12 +15,12 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class UpdateRequestEncoderTest { - private UpdateRequestEncoder encoder; +class UpdateWsRequestEncoderTest { + private UpdateWsRequestEncoder encoder; @BeforeEach void init() { - encoder = new UpdateRequestEncoder(); + encoder = new UpdateWsRequestEncoder(); encoder.init(null); } @@ -31,7 +31,7 @@ void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var cst = ChangeSetType.MAJOR; var comment = "Some comment"; - var request = new UpdateRequest(); + var request = new UpdateWsRequest(); request.setId(id); request.setChangeSetType(cst); request.setComment(comment); @@ -41,10 +41,10 @@ void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var expectedResult = "" + "" + - "" + id + "" + "" + cst + "" + "" + comment + "" + "" + sclData + "" + + "" + id + "" + ""; assertNotNull(result); assertEquals(expectedResult, result); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsResponseEncoderTest.java similarity index 82% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsResponseEncoderTest.java index dbca0579..ce703078 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateResponseEncoderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/encoder/UpdateWsResponseEncoderTest.java @@ -6,18 +6,18 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateResponse; +import org.lfenergy.compas.scl.data.websocket.v1.model.UpdateWsResponse; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; -class UpdateResponseEncoderTest { - private UpdateResponseEncoder encoder; +class UpdateWsResponseEncoderTest { + private UpdateWsResponseEncoder encoder; @BeforeEach void init() { - encoder = new UpdateResponseEncoder(); + encoder = new UpdateWsResponseEncoder(); encoder.init(null); } @@ -25,7 +25,7 @@ void init() { void encode_WhenCalledWithRequest_ThenRequestConvertedToString() { var sclData = "Some SCL Data"; - var request = new UpdateResponse(); + var request = new UpdateWsResponse(); request.setSclData(sclData); var result = encoder.encode(request); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsRequestTest.java similarity index 69% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequestTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsRequestTest.java index a989831f..77e4a130 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateRequestTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsRequestTest.java @@ -3,9 +3,9 @@ // SPDX-License-Identifier: Apache-2.0 package org.lfenergy.compas.scl.data.websocket.v1.model; -class CreateRequestTest extends AbstractPojoTester { +class CreateWsRequestTest extends AbstractPojoTester { @Override protected Class getClassToBeTested() { - return CreateRequest.class; + return CreateWsRequest.class; } } \ No newline at end of file diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsResponseTest.java similarity index 69% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequestTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsResponseTest.java index f02e799c..3ae73849 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetRequestTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateWsResponseTest.java @@ -3,9 +3,9 @@ // SPDX-License-Identifier: Apache-2.0 package org.lfenergy.compas.scl.data.websocket.v1.model; -class GetRequestTest extends AbstractPojoTester { +class CreateWsResponseTest extends AbstractPojoTester { @Override protected Class getClassToBeTested() { - return GetRequest.class; + return CreateWsResponse.class; } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionWsRequestTest.java similarity index 68% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequestTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionWsRequestTest.java index 947eb4a3..8f7c493d 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionRequestTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionWsRequestTest.java @@ -3,9 +3,9 @@ // SPDX-License-Identifier: Apache-2.0 package org.lfenergy.compas.scl.data.websocket.v1.model; -class GetVersionRequestTest extends AbstractPojoTester { +class GetVersionWsRequestTest extends AbstractPojoTester { @Override protected Class getClassToBeTested() { - return GetVersionRequest.class; + return GetVersionWsRequest.class; } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponseTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsRequestTest.java similarity index 71% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponseTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsRequestTest.java index 2ad70750..a78ca3f2 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetResponseTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsRequestTest.java @@ -3,9 +3,9 @@ // SPDX-License-Identifier: Apache-2.0 package org.lfenergy.compas.scl.data.websocket.v1.model; -class GetResponseTest extends AbstractPojoTester { +class GetWsRequestTest extends AbstractPojoTester { @Override protected Class getClassToBeTested() { - return GetResponse.class; + return GetWsRequest.class; } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequestTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsResponseTest.java similarity index 70% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequestTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsResponseTest.java index e407e7bf..1ae4eb93 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateRequestTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsResponseTest.java @@ -3,9 +3,9 @@ // SPDX-License-Identifier: Apache-2.0 package org.lfenergy.compas.scl.data.websocket.v1.model; -class UpdateRequestTest extends AbstractPojoTester { +class GetWsResponseTest extends AbstractPojoTester { @Override protected Class getClassToBeTested() { - return UpdateRequest.class; + return GetWsResponse.class; } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponseTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponseTest.java deleted file mode 100644 index b6be5735..00000000 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateResponseTest.java +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Alliander N.V. -// -// SPDX-License-Identifier: Apache-2.0 -package org.lfenergy.compas.scl.data.websocket.v1.model; - -class UpdateResponseTest extends AbstractPojoTester { - @Override - protected Class getClassToBeTested() { - return UpdateResponse.class; - } -} diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponseTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsRequestTest.java similarity index 69% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponseTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsRequestTest.java index cb73fb0e..3eb59399 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/CreateResponseTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsRequestTest.java @@ -3,9 +3,9 @@ // SPDX-License-Identifier: Apache-2.0 package org.lfenergy.compas.scl.data.websocket.v1.model; -class CreateResponseTest extends AbstractPojoTester { +class UpdateWsRequestTest extends AbstractPojoTester { @Override protected Class getClassToBeTested() { - return CreateResponse.class; + return UpdateWsRequest.class; } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsResponseTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsResponseTest.java new file mode 100644 index 00000000..5ab6d28b --- /dev/null +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsResponseTest.java @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2021 Alliander N.V. +// +// SPDX-License-Identifier: Apache-2.0 +package org.lfenergy.compas.scl.data.websocket.v1.model; + +class UpdateWsResponseTest extends AbstractPojoTester { + @Override + protected Class getClassToBeTested() { + return UpdateWsResponse.class; + } +} From 6b5e0c7ab7e1c6770addb7f2423f5b0d776d0a0d Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Thu, 10 Nov 2022 15:18:31 +0100 Subject: [PATCH 17/21] Fixed wrong XML Tag Names. Signed-off-by: Dennis Labordus --- .../lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java | 2 +- .../lfenergy/compas/scl/data/rest/v1/model/CreateResponse.java | 2 +- .../org/lfenergy/compas/scl/data/rest/v1/model/GetResponse.java | 2 +- .../lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java | 2 +- .../lfenergy/compas/scl/data/rest/v1/model/UpdateResponse.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java index 75131494..117b35d5 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateRequest.java @@ -16,7 +16,7 @@ import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @Schema(description = "Request to create a new entry in the database containing the SCL Element content.") -@XmlRootElement(name = "CreateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "CreateRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) public class CreateRequest { @FilenameValid diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateResponse.java index dfdde196..b7593a22 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/CreateResponse.java @@ -13,7 +13,7 @@ import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @Schema(description = "Response from creating a new entry in the database containing the SCL Element content.") -@XmlRootElement(name = "CreateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "CreateResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) public class CreateResponse { @Schema(description = "The XML Content of the updated SCL added to the database. The content contains a XML according to the IEC 61850 standard.", diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/GetResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/GetResponse.java index d68ac60b..89042351 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/GetResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/GetResponse.java @@ -14,7 +14,7 @@ import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @Schema(description = "Response from retrieving a SCL from the database containing the SCL Content.") -@XmlRootElement(name = "GetWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "GetResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) public class GetResponse { @Schema(description = "The XML Content of the retrieved SCL from the database. The content contains a XML according to the IEC 61850 standard.", diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java index 4bb88de5..f64bc37c 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateRequest.java @@ -18,7 +18,7 @@ @Schema(description = "Request to update an existing entry in the database containing the SCL Element content. " + "A new version is created and the old version is also kept.") -@XmlRootElement(name = "UpdateWsRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "UpdateRequest", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) public class UpdateRequest { @NotNull(message = "{org.lfenergy.compas.changeset.notnull.message}") diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateResponse.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateResponse.java index 09dc4ad2..a30a3e39 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateResponse.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UpdateResponse.java @@ -14,7 +14,7 @@ import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_DATA_SERVICE_V1_NS_URI; @Schema(description = "Response from updating a new entry in the database containing the SCL Element content.") -@XmlRootElement(name = "UpdateWsResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) +@XmlRootElement(name = "UpdateResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI) @XmlAccessorType(XmlAccessType.FIELD) public class UpdateResponse { @Schema(description = "The XML Content of the updated SCL added to the database. The content contains a XML according to the IEC 61850 standard.", From 4e79a854de91630997025bac5a367e30f6de6b08 Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Thu, 10 Nov 2022 15:31:22 +0100 Subject: [PATCH 18/21] Small improvements. Signed-off-by: Dennis Labordus --- .../compas/scl/data/rest/v1/CompasSclDataResource.java | 2 +- .../scl/data/websocket/v1/model/GetVersionWsRequest.java | 4 ++++ .../compas/scl/data/websocket/v1/model/GetWsRequest.java | 2 ++ .../compas/scl/data/websocket/v1/model/UpdateWsRequest.java | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResource.java b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResource.java index 8dbdcffe..4d13bbc1 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResource.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResource.java @@ -135,4 +135,4 @@ public Uni deleteVersion(@PathParam(TYPE_PATH_PARAM) SclFileType type, compasSclDataService.delete(type, id, version); return Uni.createFrom().nullItem(); } -} \ No newline at end of file +} diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionWsRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionWsRequest.java index adb35382..e050ce6f 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionWsRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetVersionWsRequest.java @@ -6,6 +6,8 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import javax.xml.bind.annotation.*; import java.util.UUID; @@ -18,11 +20,13 @@ public class GetVersionWsRequest { @Schema(description = "The ID of the SCL File.", example = "f7b98f4d-3fe4-4df2-8533-d7f0c1800344") + @NotNull @XmlElement(name = "Id", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) private UUID id; @Schema(description = "The version of the SCL File.", example = "1.2.3") + @NotBlank @XmlElement(name = "Version", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) private String version; diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsRequest.java index 0adc19ba..764807e4 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/GetWsRequest.java @@ -6,6 +6,7 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema; +import javax.validation.constraints.NotNull; import javax.xml.bind.annotation.*; import java.util.UUID; @@ -18,6 +19,7 @@ public class GetWsRequest { @Schema(description = "The ID of the SCL File.", example = "f7b98f4d-3fe4-4df2-8533-d7f0c1800344") + @NotNull @XmlElement(name = "Id", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) private UUID id; diff --git a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsRequest.java b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsRequest.java index 9429a93a..b3b42769 100644 --- a/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsRequest.java +++ b/app/src/main/java/org/lfenergy/compas/scl/data/websocket/v1/model/UpdateWsRequest.java @@ -6,6 +6,7 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema; +import javax.validation.constraints.NotNull; import javax.xml.bind.annotation.*; import java.util.UUID; @@ -19,6 +20,7 @@ public class UpdateWsRequest extends org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest { @Schema(description = "The ID of the SCL File.", example = "f7b98f4d-3fe4-4df2-8533-d7f0c1800344") + @NotNull @XmlElement(name = "Id", namespace = SCL_DATA_SERVICE_V1_NS_URI, required = true) private UUID id; From 4fab6e58fcca4f0fe1c2a652a52bf14a5517fc38 Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Thu, 10 Nov 2022 15:37:19 +0100 Subject: [PATCH 19/21] Small sonar issue fixed. Signed-off-by: Dennis Labordus --- ...st.java => AbstractServerEndpointAsEditorTestSupport.java} | 4 ++-- ...st.java => AbstractServerEndpointAsReaderTestSupport.java} | 2 +- ...dpointTest.java => AbstractServerEndpointTestSupport.java} | 2 +- .../v1/CompasSclCreateServerEndpointAsEditorTest.java | 2 +- .../v1/CompasSclCreateServerEndpointAsReaderTest.java | 2 +- .../websocket/v1/CompasSclGetServerEndpointAsEditorTest.java | 3 +-- .../websocket/v1/CompasSclGetServerEndpointAsReaderTest.java | 2 +- .../v1/CompasSclGetVersionServerEndpointAsEditorTest.java | 4 ++-- .../v1/CompasSclGetVersionServerEndpointAsReaderTest.java | 4 ++-- .../v1/CompasSclUpdateServerEndpointAsEditorTest.java | 2 +- .../v1/CompasSclUpdateServerEndpointAsReaderTest.java | 2 +- 11 files changed, 14 insertions(+), 15 deletions(-) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/{AbstractServerEndpointAsEditorTest.java => AbstractServerEndpointAsEditorTestSupport.java} (84%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/{AbstractServerEndpointAsReaderTest.java => AbstractServerEndpointAsReaderTestSupport.java} (93%) rename app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/{AbstractServerEndpointTest.java => AbstractServerEndpointTestSupport.java} (98%) diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsEditorTestSupport.java similarity index 84% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsEditorTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsEditorTestSupport.java index a0b5a734..22d0f38a 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsEditorTestSupport.java @@ -12,9 +12,9 @@ @TestSecurity(user = "test-editor", roles = {"SCD_" + READ_ROLE, "SCD_" + CREATE_ROLE, "SCD_" + UPDATE_ROLE}) @JwtSecurity(claims = { // Default the claim "name" is configured for Who, so we will set this claim for the test. - @Claim(key = "name", value = AbstractServerEndpointAsEditorTest.USERNAME) + @Claim(key = "name", value = AbstractServerEndpointAsEditorTestSupport.USERNAME) }) -public abstract class AbstractServerEndpointAsEditorTest extends AbstractServerEndpointTest { +public abstract class AbstractServerEndpointAsEditorTestSupport extends AbstractServerEndpointTestSupport { public static final String USERNAME = "Test Editor"; } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTestSupport.java similarity index 93% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTestSupport.java index 2e21f3d2..58722723 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointAsReaderTestSupport.java @@ -18,7 +18,7 @@ import static org.lfenergy.compas.scl.data.rest.Constants.READ_ROLE; @TestSecurity(user = "test-editor", roles = {"SCD_" + READ_ROLE}) -public abstract class AbstractServerEndpointAsReaderTest extends AbstractServerEndpointTest { +public abstract class AbstractServerEndpointAsReaderTestSupport extends AbstractServerEndpointTestSupport { protected void testWhenForbiddenToExecute(URI uri) { var container = ContainerProvider.getWebSocketContainer(); var exception = assertThrows(InterruptedIOException.class, () -> container.connectToServer(Client.class, uri)); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTestSupport.java similarity index 98% rename from app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java rename to app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTestSupport.java index 260ef1d4..6a4ad521 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/AbstractServerEndpointTestSupport.java @@ -19,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_DECODER_ERROR_CODE; -public class AbstractServerEndpointTest { +public class AbstractServerEndpointTestSupport { protected static final LinkedBlockingDeque sclDataQueue = new LinkedBlockingDeque<>(); protected static final LinkedBlockingDeque errorQueue = new LinkedBlockingDeque<>(); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java index fa77d524..51c786c2 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java @@ -23,7 +23,7 @@ import static org.mockito.Mockito.*; @QuarkusTest -class CompasSclCreateServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTest { +class CompasSclCreateServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport { @InjectMock private CompasSclDataService service; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsReaderTest.java index 9d0d8d18..5074709d 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsReaderTest.java @@ -10,7 +10,7 @@ import java.net.URI; @QuarkusTest -class CompasSclCreateServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTest { +class CompasSclCreateServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTestSupport { @TestHTTPResource("/scl-ws/v1/SCD/create") private URI uri; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java index e88c6caa..d194512b 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java @@ -21,11 +21,10 @@ import java.net.URI; import java.util.UUID; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.*; @QuarkusTest -class CompasSclGetServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTest { +class CompasSclGetServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport { @InjectMock private CompasSclDataService service; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java index d863bae6..f4fdf135 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java @@ -24,7 +24,7 @@ import static org.mockito.Mockito.*; @QuarkusTest -class CompasSclGetServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTest { +class CompasSclGetServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTestSupport { @InjectMock private CompasSclDataService service; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java index 8e0bc3b6..abfeb596 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java @@ -11,8 +11,8 @@ import org.lfenergy.compas.scl.data.service.CompasSclDataService; import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetWsResponseDecoder; import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetVersionWsRequestEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionWsRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; import org.lfenergy.compas.scl.extensions.model.SclFileType; import javax.websocket.ClientEndpoint; @@ -25,7 +25,7 @@ import static org.mockito.Mockito.*; @QuarkusTest -class CompasSclGetVersionServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTest { +class CompasSclGetVersionServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport { @InjectMock private CompasSclDataService service; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java index 28651b96..5a599212 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java @@ -11,8 +11,8 @@ import org.lfenergy.compas.scl.data.service.CompasSclDataService; import org.lfenergy.compas.scl.data.websocket.v1.decoder.GetWsResponseDecoder; import org.lfenergy.compas.scl.data.websocket.v1.encoder.GetVersionWsRequestEncoder; -import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; import org.lfenergy.compas.scl.data.websocket.v1.model.GetVersionWsRequest; +import org.lfenergy.compas.scl.data.websocket.v1.model.GetWsResponse; import org.lfenergy.compas.scl.extensions.model.SclFileType; import javax.websocket.ClientEndpoint; @@ -25,7 +25,7 @@ import static org.mockito.Mockito.*; @QuarkusTest -class CompasSclGetVersionServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTest { +class CompasSclGetVersionServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTestSupport { @InjectMock private CompasSclDataService service; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java index 38659025..addce908 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java @@ -25,7 +25,7 @@ import static org.mockito.Mockito.*; @QuarkusTest -class CompasSclUpdateServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTest { +class CompasSclUpdateServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport { @InjectMock private CompasSclDataService service; diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsReaderTest.java index 0b8e9e31..d0829e9c 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsReaderTest.java @@ -10,7 +10,7 @@ import java.net.URI; @QuarkusTest -class CompasSclUpdateServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTest { +class CompasSclUpdateServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTestSupport { @TestHTTPResource("/scl-ws/v1/SCD/update") private URI uri; From 9a4053f350e6de5b11cc3f366bc9a7235702c3dc Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Tue, 15 Nov 2022 07:40:35 +0100 Subject: [PATCH 20/21] Latest version of CoMPAS Core and disabled native build. Signed-off-by: Dennis Labordus --- .github/workflows/build-project.yml | 2 +- .github/workflows/release-project.yml | 2 +- app/src/main/resources/application.properties | 6 ++++++ pom.xml | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-project.yml b/.github/workflows/build-project.yml index a7d51d65..95370327 100644 --- a/.github/workflows/build-project.yml +++ b/.github/workflows/build-project.yml @@ -51,7 +51,7 @@ jobs: servers: '[{ "id": "github-packages-compas", "username": "OWNER", "password": "${{ secrets.GITHUB_TOKEN }}" }]' - name: Build with Maven (Pull Request) if: ${{ github.event_name == 'pull_request' }} - run: ./mvnw -s custom_maven_settings.xml -B -Pnative-image clean verify + run: ./mvnw -s custom_maven_settings.xml -B -Pjvm-image clean verify - name: Build with Maven (Push) if: ${{ github.event_name == 'push' }} run: ./mvnw -s custom_maven_settings.xml -B clean verify diff --git a/.github/workflows/release-project.yml b/.github/workflows/release-project.yml index e9fb31d6..20a4fd38 100644 --- a/.github/workflows/release-project.yml +++ b/.github/workflows/release-project.yml @@ -60,6 +60,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Deploy with Maven to GitHub Packages and Docker Hub - run: ./mvnw -B -s custom_maven_settings.xml -Pnative-image,release clean deploy + run: ./mvnw -B -s custom_maven_settings.xml -Pjvm-image,release clean deploy env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/app/src/main/resources/application.properties b/app/src/main/resources/application.properties index 9556ce66..e4ee87b5 100644 --- a/app/src/main/resources/application.properties +++ b/app/src/main/resources/application.properties @@ -15,6 +15,12 @@ quarkus.log.level = INFO quarkus.log.category."org.lfenergy.compas.scl.data".level = INFO # Add scanning these dependencies for scanning, also used by native compilation. +quarkus.index-dependency.hibernate-validator.group-id=org.hibernate.validator +quarkus.index-dependency.hibernate-validator.artifact-id=hibernate-validator + +quarkus.index-dependency.websocket-commons.group-id = org.lfenergy.compas.core +quarkus.index-dependency.websocket-commons.artifact-id = websocket-commons + quarkus.index-dependency.rest-commons.group-id = org.lfenergy.compas.core quarkus.index-dependency.rest-commons.artifact-id = rest-commons diff --git a/pom.xml b/pom.xml index 6d8ea6f5..ae730342 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ SPDX-License-Identifier: Apache-2.0 3.0.0-M7 3.2.0 - 0.10.1 + 0.10.2 2.14.0.Final 2.3.7 From 3e83d949830081b65a952e728e93598e26cb4e1b Mon Sep 17 00:00:00 2001 From: Dennis Labordus Date: Tue, 15 Nov 2022 07:55:38 +0100 Subject: [PATCH 21/21] Remove code (times(1)) that is not needed in test files. Signed-off-by: Dennis Labordus --- .../v1/CompasSclDataResourceAsEditorTest.java | 16 +++---- .../v1/CompasSclDataResourceAsReaderTest.java | 8 ++-- .../event/CompasSclDataEventHandlerTest.java | 35 ++++++++-------- ...asSclCreateServerEndpointAsEditorTest.java | 5 ++- ...ompasSclGetServerEndpointAsEditorTest.java | 5 ++- ...ompasSclGetServerEndpointAsReaderTest.java | 5 ++- ...lGetVersionServerEndpointAsEditorTest.java | 5 ++- ...lGetVersionServerEndpointAsReaderTest.java | 5 ++- ...asSclUpdateServerEndpointAsEditorTest.java | 5 ++- .../service/CompasSclDataServiceTest.java | 42 +++++++++---------- 10 files changed, 69 insertions(+), 62 deletions(-) diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java index ecf8a151..34dc5252 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsEditorTest.java @@ -69,7 +69,7 @@ void list_WhenCalled_ThenItemResponseRetrieved() { assertEquals(name, xmlPath.get("ListResponse.Item[0].Name")); assertEquals(version, xmlPath.get("ListResponse.Item[0].Version")); assertEquals(labels.get(0), xmlPath.get("ListResponse.Item[0].Label")); - verify(compasSclDataService, times(1)).list(type); + verify(compasSclDataService).list(type); } @Test @@ -95,7 +95,7 @@ void listVersionsByUUID_WhenCalled_ThenItemResponseRetrieved() { assertEquals(uuid.toString(), xmlPath.get("VersionsResponse.HistoryItem[0].Id")); assertEquals(name, xmlPath.get("VersionsResponse.HistoryItem[0].Name")); assertEquals(version, xmlPath.get("VersionsResponse.HistoryItem[0].Version")); - verify(compasSclDataService, times(1)).listVersionsByUUID(type, uuid); + verify(compasSclDataService).listVersionsByUUID(type, uuid); } @Test @@ -118,7 +118,7 @@ void findByUUID_WhenCalled_ThenSCLResponseRetrieved() throws IOException { var xmlPath = response.xmlPath() .using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI)); assertEquals(scl, xmlPath.get("GetWsResponse.SclData")); - verify(compasSclDataService, times(1)).findByUUID(type, uuid); + verify(compasSclDataService).findByUUID(type, uuid); } @Test @@ -143,7 +143,7 @@ void findByUUIDAndVersion_WhenCalled_ThenSCLResponseRetrieved() throws IOExcepti var xmlPath = response.xmlPath() .using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI)); assertEquals(scl, xmlPath.get("GetWsResponse.SclData")); - verify(compasSclDataService, times(1)).findByUUID(type, uuid, version); + verify(compasSclDataService).findByUUID(type, uuid, version); } @Test @@ -171,7 +171,7 @@ void create_WhenCalled_ThenServiceCalledAndUUIDRetrieved() throws IOException { .response(); assertEquals(scl, response.xmlPath().getString("CreateWsResponse.SclData")); - verify(compasSclDataService, times(1)).create(type, name, USERNAME, comment, scl); + verify(compasSclDataService).create(type, name, USERNAME, comment, scl); } @Test @@ -228,7 +228,7 @@ void update_WhenCalled_ThenServiceCalledAndNewUUIDRetrieved() throws IOException .response(); assertEquals(scl, response.xmlPath().getString("CreateWsResponse.SclData")); - verify(compasSclDataService, times(1)).update(type, uuid, changeSetType, USERNAME, comment, scl); + verify(compasSclDataService).update(type, uuid, changeSetType, USERNAME, comment, scl); } @Test @@ -245,7 +245,7 @@ void deleteAll_WhenCalled_ThenServiceCalled() { .then() .statusCode(204); - verify(compasSclDataService, times(1)).delete(type, uuid); + verify(compasSclDataService).delete(type, uuid); } @Test @@ -264,7 +264,7 @@ void deleteVersion_WhenCalled_ThenServiceCalled() { .then() .statusCode(204); - verify(compasSclDataService, times(1)).delete(type, uuid, version); + verify(compasSclDataService).delete(type, uuid, version); } private String readSCL() throws IOException { diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java index 0b400983..3a4a86b4 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasSclDataResourceAsReaderTest.java @@ -61,7 +61,7 @@ void list_WhenCalled_ThenItemResponseRetrieved() { assertEquals(name, xmlPath.get("ListResponse.Item[0].Name")); assertEquals(version, xmlPath.get("ListResponse.Item[0].Version")); assertEquals(labels.get(0), xmlPath.get("ListResponse.Item[0].Label")); - verify(compasSclDataService, times(1)).list(type); + verify(compasSclDataService).list(type); } @Test @@ -87,7 +87,7 @@ void listVersionsByUUID_WhenCalled_ThenItemResponseRetrieved() { assertEquals(uuid.toString(), xmlPath.get("VersionsResponse.HistoryItem[0].Id")); assertEquals(name, xmlPath.get("VersionsResponse.HistoryItem[0].Name")); assertEquals(version, xmlPath.get("VersionsResponse.HistoryItem[0].Version")); - verify(compasSclDataService, times(1)).listVersionsByUUID(type, uuid); + verify(compasSclDataService).listVersionsByUUID(type, uuid); } @Test @@ -110,7 +110,7 @@ void findByUUID_WhenCalled_ThenSCLResponseRetrieved() throws IOException { var xmlPath = response.xmlPath() .using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI)); assertEquals(scl, xmlPath.get("GetWsResponse.SclData")); - verify(compasSclDataService, times(1)).findByUUID(type, uuid); + verify(compasSclDataService).findByUUID(type, uuid); } @Test @@ -135,7 +135,7 @@ void findByUUIDAndVersion_WhenCalled_ThenSCLResponseRetrieved() throws IOExcepti var xmlPath = response.xmlPath() .using(xmlPathConfig().declaredNamespace("scl", SCL_NS_URI)); assertEquals(scl, xmlPath.get("GetWsResponse.SclData")); - verify(compasSclDataService, times(1)).findByUUID(type, uuid, version); + verify(compasSclDataService).findByUUID(type, uuid, version); } @Test diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java index bebcec22..39f9192d 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/event/CompasSclDataEventHandlerTest.java @@ -31,7 +31,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.lfenergy.compas.core.commons.exception.CompasErrorCode.WEBSOCKET_GENERAL_ERROR_CODE; import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.DUPLICATE_SCL_NAME_ERROR_CODE; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class CompasSclDataEventHandlerTest { @@ -57,7 +58,7 @@ void createWebsocketsEvent_WhenCalled_ThenCreateResponseReturned() { var response = verifyResponse(session, CreateWsResponse.class); assertEquals(sclData, response.getSclData()); - verify(service, times(1)).create(type, name, who, comment, sclData); + verify(service).create(type, name, who, comment, sclData); } @Test @@ -77,7 +78,7 @@ void createWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenError eventHandler.createWebsocketsEvent(request); verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage); - verify(service, times(1)).create(type, name, who, comment, sclData); + verify(service).create(type, name, who, comment, sclData); } @Test @@ -96,7 +97,7 @@ void createWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErro eventHandler.createWebsocketsEvent(request); verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage); - verify(service, times(1)).create(type, name, who, comment, sclData); + verify(service).create(type, name, who, comment, sclData); } @Test @@ -113,7 +114,7 @@ void getWebsocketsEvent_WhenCalled_ThenGetResponseReturned() { var response = verifyResponse(session, GetWsResponse.class); assertEquals(sclData, response.getSclData()); - verify(service, times(1)).findByUUID(type, id); + verify(service).findByUUID(type, id); } @Test @@ -130,7 +131,7 @@ void getWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenErrorRes eventHandler.getWebsocketsEvent(request); verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage); - verify(service, times(1)).findByUUID(type, id); + verify(service).findByUUID(type, id); } @Test @@ -146,7 +147,7 @@ void getWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErrorRe eventHandler.getWebsocketsEvent(request); verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage); - verify(service, times(1)).findByUUID(type, id); + verify(service).findByUUID(type, id); } @Test @@ -164,7 +165,7 @@ void getVersionWebsocketsEvent_WhenCalled_ThenGetResponseReturned() { var response = verifyResponse(session, GetWsResponse.class); assertEquals(sclData, response.getSclData()); - verify(service, times(1)).findByUUID(type, id, version); + verify(service).findByUUID(type, id, version); } @Test @@ -182,7 +183,7 @@ void getVersionWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenE eventHandler.getVersionWebsocketsEvent(request); verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage); - verify(service, times(1)).findByUUID(type, id, version); + verify(service).findByUUID(type, id, version); } @Test @@ -199,7 +200,7 @@ void getVersionWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_Then eventHandler.getVersionWebsocketsEvent(request); verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage); - verify(service, times(1)).findByUUID(type, id, version); + verify(service).findByUUID(type, id, version); } @Test @@ -219,7 +220,7 @@ void updateWebsocketsEvent_WhenCalled_ThenUpdateResponseReturned() { var response = verifyResponse(session, UpdateWsResponse.class); assertEquals(sclData, response.getSclData()); - verify(service, times(1)).update(type, id, cst, who, comment, sclData); + verify(service).update(type, id, cst, who, comment, sclData); } @Test @@ -240,7 +241,7 @@ void updateWebsocketsEvent_WhenCalledAndCompasExceptionThrownByService_ThenError eventHandler.updateWebsocketsEvent(request); verifyErrorResponse(session, DUPLICATE_SCL_NAME_ERROR_CODE, errorMessage); - verify(service, times(1)).update(type, id, cst, who, comment, sclData); + verify(service).update(type, id, cst, who, comment, sclData); } @Test @@ -260,7 +261,7 @@ void updateWebsocketsEvent_WhenCalledAndRuntimeExceptionThrownByService_ThenErro eventHandler.updateWebsocketsEvent(request); verifyErrorResponse(session, WEBSOCKET_GENERAL_ERROR_CODE, errorMessage); - verify(service, times(1)).update(type, id, cst, who, comment, sclData); + verify(service).update(type, id, cst, who, comment, sclData); } private Session mockSession() { @@ -271,16 +272,16 @@ private Session mockSession() { } private T verifyResponse(Session session, Class responseClass) { - verify(session, times(1)).getAsyncRemote(); + verify(session).getAsyncRemote(); ArgumentCaptor captor = ArgumentCaptor.forClass(responseClass); - verify(session.getAsyncRemote(), times(1)).sendObject(captor.capture()); + verify(session.getAsyncRemote()).sendObject(captor.capture()); return captor.getValue(); } private void verifyErrorResponse(Session session, String errorCode, String errorMessage) { - verify(session, times(1)).getAsyncRemote(); + verify(session).getAsyncRemote(); ArgumentCaptor captor = ArgumentCaptor.forClass(ErrorResponse.class); - verify(session.getAsyncRemote(), times(1)).sendObject(captor.capture()); + verify(session.getAsyncRemote()).sendObject(captor.capture()); var response = captor.getValue(); assertEquals(1, response.getErrorMessages().size()); var message = response.getErrorMessages().get(0); diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java index 51c786c2..eabfa8e1 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclCreateServerEndpointAsEditorTest.java @@ -20,7 +20,8 @@ import javax.websocket.Session; import java.net.URI; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @QuarkusTest class CompasSclCreateServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport { @@ -50,7 +51,7 @@ void createSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { session.getAsyncRemote().sendText(encoder.encode(request)); assertSclData(sclData); - verify(service, times(1)).create(sclFileTye, name, USERNAME, comment, sclData); + verify(service).create(sclFileTye, name, USERNAME, comment, sclData); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java index d194512b..101d3ff1 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsEditorTest.java @@ -21,7 +21,8 @@ import java.net.URI; import java.util.UUID; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @QuarkusTest class CompasSclGetServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport { @@ -47,7 +48,7 @@ void getSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { session.getAsyncRemote().sendText(encoder.encode(request)); assertSclData(sclData); - verify(service, times(1)).findByUUID(sclFileTye, id); + verify(service).findByUUID(sclFileTye, id); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java index f4fdf135..fa63b88a 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetServerEndpointAsReaderTest.java @@ -21,7 +21,8 @@ import java.net.URI; import java.util.UUID; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @QuarkusTest class CompasSclGetServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTestSupport { @@ -47,7 +48,7 @@ void getSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { session.getAsyncRemote().sendText(encoder.encode(request)); assertSclData(sclData); - verify(service, times(1)).findByUUID(sclFileTye, id); + verify(service).findByUUID(sclFileTye, id); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java index abfeb596..41da1179 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsEditorTest.java @@ -22,7 +22,8 @@ import java.net.URI; import java.util.UUID; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @QuarkusTest class CompasSclGetVersionServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport { @@ -50,7 +51,7 @@ void getVersionSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception session.getAsyncRemote().sendText(encoder.encode(request)); assertSclData(sclData); - verify(service, times(1)).findByUUID(sclFileTye, id, version); + verify(service).findByUUID(sclFileTye, id, version); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java index 5a599212..23037003 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclGetVersionServerEndpointAsReaderTest.java @@ -22,7 +22,8 @@ import java.net.URI; import java.util.UUID; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @QuarkusTest class CompasSclGetVersionServerEndpointAsReaderTest extends AbstractServerEndpointAsReaderTestSupport { @@ -50,7 +51,7 @@ void getVersionSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception session.getAsyncRemote().sendText(encoder.encode(request)); assertSclData(sclData); - verify(service, times(1)).findByUUID(sclFileTye, id, version); + verify(service).findByUUID(sclFileTye, id, version); } } diff --git a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java index addce908..04c397f1 100644 --- a/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java +++ b/app/src/test/java/org/lfenergy/compas/scl/data/websocket/v1/CompasSclUpdateServerEndpointAsEditorTest.java @@ -22,7 +22,8 @@ import java.net.URI; import java.util.UUID; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; @QuarkusTest class CompasSclUpdateServerEndpointAsEditorTest extends AbstractServerEndpointAsEditorTestSupport { @@ -54,7 +55,7 @@ void updateSCL_WhenCalled_ThenExpectedResponseIsRetrieved() throws Exception { session.getAsyncRemote().sendText(encoder.encode(request)); assertSclData(sclData); - verify(service, times(1)).update(sclFileTye, id, cst, USERNAME, comment, sclData); + verify(service).update(sclFileTye, id, cst, USERNAME, comment, sclData); } } diff --git a/service/src/test/java/org/lfenergy/compas/scl/data/service/CompasSclDataServiceTest.java b/service/src/test/java/org/lfenergy/compas/scl/data/service/CompasSclDataServiceTest.java index 926d487d..919bc92b 100644 --- a/service/src/test/java/org/lfenergy/compas/scl/data/service/CompasSclDataServiceTest.java +++ b/service/src/test/java/org/lfenergy/compas/scl/data/service/CompasSclDataServiceTest.java @@ -60,7 +60,7 @@ void list_WhenCalled_ThenRepositoryIsCalled() { var result = compasSclDataService.list(SCL_TYPE); assertNotNull(result); - verify(compasSclDataRepository, times(1)).list(SCL_TYPE); + verify(compasSclDataRepository).list(SCL_TYPE); } @Test @@ -74,7 +74,7 @@ void listVersionsByUUID_WhenCalledAndRepositoryReturnItemList_ThenListIsReturned assertNotNull(result); assertEquals(expectedResult.size(), result.size()); assertEquals(expectedResult.get(0), result.get(0)); - verify(compasSclDataRepository, times(1)).listVersionsByUUID(SCL_TYPE, uuid); + verify(compasSclDataRepository).listVersionsByUUID(SCL_TYPE, uuid); } @Test @@ -86,7 +86,7 @@ void listVersionsByUUID_WhenCalledAndRepositoryReturnsEmptyList_ThenExceptionIsT compasSclDataService.listVersionsByUUID(SCL_TYPE, uuid); }); assertEquals(NO_DATA_FOUND_ERROR_CODE, exception.getErrorCode()); - verify(compasSclDataRepository, times(1)).listVersionsByUUID(SCL_TYPE, uuid); + verify(compasSclDataRepository).listVersionsByUUID(SCL_TYPE, uuid); } @Test @@ -97,7 +97,7 @@ void findByUUID_WhenCalledWithoutVersion_ThenRepositoryIsCalled() throws IOExcep var result = compasSclDataService.findByUUID(SCL_TYPE, uuid); assertNotNull(result); - verify(compasSclDataRepository, times(1)).findByUUID(SCL_TYPE, uuid); + verify(compasSclDataRepository).findByUUID(SCL_TYPE, uuid); } @Test @@ -109,7 +109,7 @@ void findByUUID_WhenCalledWithVersion_ThenRepositoryIsCalled() throws IOExceptio var result = compasSclDataService.findByUUID(SCL_TYPE, uuid, version); assertNotNull(result); - verify(compasSclDataRepository, times(1)).findByUUID(SCL_TYPE, uuid, version); + verify(compasSclDataRepository).findByUUID(SCL_TYPE, uuid, version); } @Test @@ -128,8 +128,8 @@ void create_WhenCalledWithOutCompasExtension_ThenSCLReturnedWithCorrectCompasExt assertNotNull(scl); assertCompasExtension(scl, name); assertHistoryItem(scl, 2, INITIAL_VERSION, comment); - verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), any(UUID.class), eq(name), anyString(), eq(INITIAL_VERSION), eq(who), eq(emptyList())); - verify(compasSclDataRepository, times(1)).hasDuplicateSclName(SCL_TYPE, name); + verify(compasSclDataRepository).create(eq(SCL_TYPE), any(UUID.class), eq(name), anyString(), eq(INITIAL_VERSION), eq(who), eq(emptyList())); + verify(compasSclDataRepository).hasDuplicateSclName(SCL_TYPE, name); } @Test @@ -149,8 +149,8 @@ void create_WhenCalledWithCompasExtension_ThenSCLReturnedWithCorrectCompasExtens assertNotNull(scl); assertCompasExtension(scl, name); assertHistoryItem(scl, 2, INITIAL_VERSION, comment); - verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), any(UUID.class), eq(name), anyString(), eq(INITIAL_VERSION), eq(who), eq(emptyList())); - verify(compasSclDataRepository, times(1)).hasDuplicateSclName(SCL_TYPE, name); + verify(compasSclDataRepository).create(eq(SCL_TYPE), any(UUID.class), eq(name), anyString(), eq(INITIAL_VERSION), eq(who), eq(emptyList())); + verify(compasSclDataRepository).hasDuplicateSclName(SCL_TYPE, name); } @Test @@ -166,7 +166,7 @@ void create_WhenCalledWithDuplicateSclName_ThenCompasExceptionThrown() throws IO compasSclDataService.create(SCL_TYPE, name, who, comment, scl); }); assertEquals(DUPLICATE_SCL_NAME_ERROR_CODE, exception.getErrorCode()); - verify(compasSclDataRepository, times(1)).hasDuplicateSclName(SCL_TYPE, name); + verify(compasSclDataRepository).hasDuplicateSclName(SCL_TYPE, name); } @Test @@ -202,8 +202,8 @@ void update_WhenCalledWithoutCompasElements_ThenSCLReturnedWithCorrectCompasExte assertNotNull(scl); assertCompasExtension(scl, previousName); assertHistoryItem(scl, 4, nextVersion, null); - verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(previousName), anyString(), eq(nextVersion), eq(who), eq(emptyList())); - verify(compasSclDataRepository, times(1)).findMetaInfoByUUID(SCL_TYPE, uuid); + verify(compasSclDataRepository).create(eq(SCL_TYPE), eq(uuid), eq(previousName), anyString(), eq(nextVersion), eq(who), eq(emptyList())); + verify(compasSclDataRepository).findMetaInfoByUUID(SCL_TYPE, uuid); verify(compasSclDataRepository, never()).hasDuplicateSclName(SCL_TYPE, previousName); } @@ -229,9 +229,9 @@ void update_WhenCalledWithCompasElementsAndNewName_ThenSCLReturnedWithCorrectCom assertNotNull(scl); assertCompasExtension(scl, newName); assertHistoryItem(scl, 4, nextVersion, null); - verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(newName), anyString(), eq(nextVersion), eq(who), eq(emptyList())); - verify(compasSclDataRepository, times(1)).findMetaInfoByUUID(SCL_TYPE, uuid); - verify(compasSclDataRepository, times(1)).hasDuplicateSclName(SCL_TYPE, newName); + verify(compasSclDataRepository).create(eq(SCL_TYPE), eq(uuid), eq(newName), anyString(), eq(nextVersion), eq(who), eq(emptyList())); + verify(compasSclDataRepository).findMetaInfoByUUID(SCL_TYPE, uuid); + verify(compasSclDataRepository).hasDuplicateSclName(SCL_TYPE, newName); } @Test @@ -252,8 +252,8 @@ void update_WhenCalledWithCompasElementsAndDuplicateNewName_ThenCompasExceptionT compasSclDataService.update(SCL_TYPE, uuid, changeSet, who, null, scl); }); assertEquals(DUPLICATE_SCL_NAME_ERROR_CODE, exception.getErrorCode()); - verify(compasSclDataRepository, times(1)).findMetaInfoByUUID(SCL_TYPE, uuid); - verify(compasSclDataRepository, times(1)).hasDuplicateSclName(SCL_TYPE, newName); + verify(compasSclDataRepository).findMetaInfoByUUID(SCL_TYPE, uuid); + verify(compasSclDataRepository).hasDuplicateSclName(SCL_TYPE, newName); } @Test @@ -276,8 +276,8 @@ void update_WhenCalledWithCompasElementsAndSameName_ThenSCLReturnedWithCorrectCo assertNotNull(scl); assertCompasExtension(scl, previousName); assertHistoryItem(scl, 4, nextVersion, null); - verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(previousName), anyString(), eq(nextVersion), eq(who), eq(emptyList())); - verify(compasSclDataRepository, times(1)).findMetaInfoByUUID(SCL_TYPE, uuid); + verify(compasSclDataRepository).create(eq(SCL_TYPE), eq(uuid), eq(previousName), anyString(), eq(nextVersion), eq(who), eq(emptyList())); + verify(compasSclDataRepository).findMetaInfoByUUID(SCL_TYPE, uuid); verify(compasSclDataRepository, never()).hasDuplicateSclName(SCL_TYPE, previousName); } @@ -303,7 +303,7 @@ void delete_WhenCalledWithoutVersion_ThenRepositoryIsCalled() { compasSclDataService.delete(SCL_TYPE, uuid); - verify(compasSclDataRepository, times(1)).delete(SCL_TYPE, uuid); + verify(compasSclDataRepository).delete(SCL_TYPE, uuid); } @Test @@ -315,7 +315,7 @@ void delete_WhenCalledWithVersion_ThenRepositoryIsCalled() { compasSclDataService.delete(SCL_TYPE, uuid, version); - verify(compasSclDataRepository, times(1)).delete(SCL_TYPE, uuid, version); + verify(compasSclDataRepository).delete(SCL_TYPE, uuid, version); } @Test