diff --git a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DiscoveryServiceWiremockConfig.java b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DiscoveryServiceWiremockConfig.java index db505bf240..6377a0d3d2 100644 --- a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DiscoveryServiceWiremockConfig.java +++ b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DiscoveryServiceWiremockConfig.java @@ -37,6 +37,9 @@ public final class DiscoveryServiceWiremockConfig { public static final String DISCOVERY_HOST = "http://discovery.finder"; public static final String EDC_DISCOVERY_URL = DISCOVERY_HOST + EDC_DISCOVERY_PATH; public static final String DISCOVERY_FINDER_URL = DISCOVERY_HOST + DISCOVERY_FINDER_PATH; + public static final int STATUS_CODE_OK = 200; + public static final int STATUS_CODE_NOT_FOUND = 404; + private DiscoveryServiceWiremockConfig() { } @@ -46,7 +49,7 @@ public static MappingBuilder postEdcDiscovery200() { public static MappingBuilder postEdcDiscovery200(final String bpn, final List edcUrls) { return post(urlPathEqualTo(EDC_DISCOVERY_PATH)).willReturn( - responseWithStatus(200).withBody(edcDiscoveryResponse(bpn, edcUrls))); + responseWithStatus(STATUS_CODE_OK).withBody(edcDiscoveryResponse(bpn, edcUrls))); } public static String edcDiscoveryResponse(final String bpn, final List connectorEndpoints) { @@ -64,7 +67,7 @@ public static String edcDiscoveryResponse(final String bpn, final List c public static MappingBuilder postDiscoveryFinder200() { return post(urlPathEqualTo(DISCOVERY_FINDER_PATH)).willReturn( - responseWithStatus(200).withBody(discoveryFinderResponse(EDC_DISCOVERY_URL))); + responseWithStatus(STATUS_CODE_OK).withBody(discoveryFinderResponse(EDC_DISCOVERY_URL))); } public static String discoveryFinderResponse(final String discoveryFinderUrl) { @@ -84,10 +87,10 @@ public static String discoveryFinderResponse(final String discoveryFinderUrl) { } public static MappingBuilder postDiscoveryFinder404() { - return post(urlPathEqualTo(DISCOVERY_FINDER_PATH)).willReturn(responseWithStatus(404)); + return post(urlPathEqualTo(DISCOVERY_FINDER_PATH)).willReturn(responseWithStatus(STATUS_CODE_NOT_FOUND)); } public static MappingBuilder postEdcDiscovery404() { - return post(urlPathEqualTo(EDC_DISCOVERY_PATH)).willReturn(responseWithStatus(404)); + return post(urlPathEqualTo(EDC_DISCOVERY_PATH)).willReturn(responseWithStatus(STATUS_CODE_NOT_FOUND)); } } diff --git a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockConfig.java b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockConfig.java index a4f743d578..692c4dd798 100644 --- a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockConfig.java +++ b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/DtrWiremockConfig.java @@ -40,6 +40,8 @@ public final class DtrWiremockConfig { public static final String LOOKUP_SHELLS_PATH = "/lookup/shells"; public static final String PUBLIC_LOOKUP_SHELLS_PATH = DATAPLANE_PUBLIC_PATH + LOOKUP_SHELLS_PATH; public static final String LOOKUP_SHELLS_TEMPLATE = LOOKUP_SHELLS_PATH + "?assetIds={assetIds}"; + public static final int STATUS_CODE_OK = 200; + public static final int STATUS_CODE_NOT_FOUND = 404; private DtrWiremockConfig() { } @@ -66,7 +68,7 @@ public static MappingBuilder getShellDescriptor200(final String urlRegex) { final List submodelDescriptors = List.of(batch, singleLevelBomAsBuilt, materialForRecycling); final List specificAssetIds = List.of(specificAssetId("manufacturerId", "BPNL00000003B0Q0"), specificAssetId("batchId", "BID12345678")); - return get(urlPathMatching(urlRegex)).willReturn(responseWithStatus(200).withBody( + return get(urlPathMatching(urlRegex)).willReturn(responseWithStatus(STATUS_CODE_OK).withBody( assetAdministrationShellResponse(submodelDescriptors, "urn:uuid:7e4541ea-bb0f-464c-8cb3-021abccbfaf5", "EngineeringPlastics", "urn:uuid:9ce43b21-75e3-4cea-b13e-9a34f4f6822a", specificAssetIds))); } @@ -111,6 +113,7 @@ public static String specificAssetId(final String key, final String value) { """.formatted(key, value); } + @SuppressWarnings("PMD.UseObjectForClearerAPI") // used only for testing public static String submodelDescriptor(final String dataplaneUrl, final String assetId, final String dspEndpoint, final String idShort, final String submodelDescriptorId, final String semanticId) { final String href = dataplaneUrl + "/" + submodelDescriptorId; @@ -161,13 +164,13 @@ public static MappingBuilder getLookupShells200() { } public static MappingBuilder getLookupShells200(final String lookupShellsPath) { - return get(urlPathEqualTo(lookupShellsPath)).willReturn(responseWithStatus(200).withBody( + return get(urlPathEqualTo(lookupShellsPath)).willReturn(responseWithStatus(STATUS_CODE_OK).withBody( lookupShellsResponse(List.of("urn:uuid:21f7ebea-fa8a-410c-a656-bd9082e67dcf")))); } public static MappingBuilder getLookupShells200Empty() { return get(urlPathMatching(LOOKUP_SHELLS_PATH + ".*")).willReturn( - responseWithStatus(200).withBody(lookupShellsResponse(List.of()))); + responseWithStatus(STATUS_CODE_OK).withBody(lookupShellsResponse(List.of()))); } public static String lookupShellsResponse(final List shellIds) { @@ -182,10 +185,11 @@ public static String lookupShellsResponse(final List shellIds) { } public static MappingBuilder getLookupShells404() { - return get(urlPathEqualTo(LOOKUP_SHELLS_PATH)).willReturn(responseWithStatus(404)); + return get(urlPathEqualTo(LOOKUP_SHELLS_PATH)).willReturn(responseWithStatus(STATUS_CODE_NOT_FOUND)); } public static MappingBuilder getShellDescriptor404() { - return get(urlPathMatching(SHELL_DESCRIPTORS_PATH + ".*")).willReturn(responseWithStatus(404)); + return get(urlPathMatching(SHELL_DESCRIPTORS_PATH + ".*")).willReturn( + responseWithStatus(STATUS_CODE_NOT_FOUND)); } -} \ No newline at end of file +} diff --git a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockConfig.java b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockConfig.java index 6c3453b6f5..9ef6e5862d 100644 --- a/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockConfig.java +++ b/irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/SubmodelFacadeWiremockConfig.java @@ -47,6 +47,7 @@ public final class SubmodelFacadeWiremockConfig { public static final String EDC_PROVIDER_DUMMY_URL = "https://edc.io/api/v1/dsp"; public static final String IRS_INTERNAL_CALLBACK_URL = "https://irs.test/internal/endpoint-data-reference"; public static final String EDC_PROVIDER_BPN = "BPNL00000003CRHK"; + public static final int STATUS_CODE_OK = 200; private SubmodelFacadeWiremockConfig() { } @@ -57,35 +58,37 @@ public static String prepareNegotiation() { "5a7ab616-989f-46ae-bdf2-32027b9f6ee6-31b614f5-ec14-4ed2-a509-e7b7780083e7"); } + @SuppressWarnings("PMD.UseObjectForClearerAPI") // used only for testing public static String prepareNegotiation(final String negotiationId, final String transferProcessId, final String contractAgreementId, final String edcAssetId) { - stubFor(post(urlPathEqualTo(PATH_CATALOG)).willReturn(WireMockConfig.responseWithStatus(200) + stubFor(post(urlPathEqualTo(PATH_CATALOG)).willReturn(WireMockConfig.responseWithStatus(STATUS_CODE_OK) .withBody(getCatalogResponse(edcAssetId, "USE", EDC_PROVIDER_BPN)))); stubFor(post(urlPathEqualTo(PATH_NEGOTIATE)).willReturn( - WireMockConfig.responseWithStatus(200).withBody(startNegotiationResponse(negotiationId)))); + WireMockConfig.responseWithStatus(STATUS_CODE_OK).withBody(startNegotiationResponse(negotiationId)))); final String negotiationState = "FINALIZED"; stubFor(get(urlPathEqualTo(PATH_NEGOTIATE + "/" + negotiationId)).willReturn( - WireMockConfig.responseWithStatus(200) + WireMockConfig.responseWithStatus(STATUS_CODE_OK) .withBody(getNegotiationConfirmedResponse(negotiationId, negotiationState, contractAgreementId)))); stubFor(get(urlPathEqualTo(PATH_NEGOTIATE + "/" + negotiationId + PATH_STATE)).willReturn( - WireMockConfig.responseWithStatus(200).withBody(getNegotiationStateResponse(negotiationState)))); + WireMockConfig.responseWithStatus(STATUS_CODE_OK) + .withBody(getNegotiationStateResponse(negotiationState)))); - stubFor(post(urlPathEqualTo(PATH_TRANSFER)).willReturn( - WireMockConfig.responseWithStatus(200).withBody(startTransferProcessResponse(transferProcessId)) + stubFor(post(urlPathEqualTo(PATH_TRANSFER)).willReturn(WireMockConfig.responseWithStatus(STATUS_CODE_OK) + .withBody(startTransferProcessResponse( + transferProcessId)) )); final String transferProcessState = "COMPLETED"; stubFor(get(urlPathEqualTo(PATH_TRANSFER + "/" + transferProcessId + PATH_STATE)).willReturn( - WireMockConfig.responseWithStatus(200).withBody(getTransferProcessStateResponse(transferProcessState)) - - )); + WireMockConfig.responseWithStatus(STATUS_CODE_OK) + .withBody(getTransferProcessStateResponse(transferProcessState)))); stubFor(get(urlPathEqualTo(PATH_TRANSFER + "/" + transferProcessId)).willReturn( - WireMockConfig.responseWithStatus(200) + WireMockConfig.responseWithStatus(STATUS_CODE_OK) .withBody( getTransferConfirmedResponse(transferProcessId, transferProcessState, edcAssetId, contractAgreementId)))); @@ -238,5 +241,4 @@ private static String createAtomicConstraint(final String leftOperand, final Str "odrl:rightOperand": "%s" }""".formatted(leftOperand, rightOperand); } - -} \ No newline at end of file +}