Skip to content

Commit

Permalink
feat(irs-testing):[#344] Fix code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-jhartmann committed Jan 29, 2024
1 parent d1fd503 commit a262bab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}

Expand All @@ -46,7 +49,7 @@ public static MappingBuilder postEdcDiscovery200() {

public static MappingBuilder postEdcDiscovery200(final String bpn, final List<String> 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<String> connectorEndpoints) {
Expand All @@ -64,7 +67,7 @@ public static String edcDiscoveryResponse(final String bpn, final List<String> 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) {
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand All @@ -66,7 +68,7 @@ public static MappingBuilder getShellDescriptor200(final String urlRegex) {
final List<String> submodelDescriptors = List.of(batch, singleLevelBomAsBuilt, materialForRecycling);
final List<String> 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)));
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> shellIds) {
Expand All @@ -182,10 +185,11 @@ public static String lookupShellsResponse(final List<String> 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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand All @@ -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))));
Expand Down Expand Up @@ -238,5 +241,4 @@ private static String createAtomicConstraint(final String leftOperand, final Str
"odrl:rightOperand": "%s"
}""".formatted(leftOperand, rightOperand);
}

}
}

0 comments on commit a262bab

Please sign in to comment.