Skip to content

Commit

Permalink
feat(impl):[#370] fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-ext-kmassalski committed Feb 2, 2024
1 parent 75a1632 commit ae63bea
Showing 1 changed file with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand All @@ -59,7 +61,9 @@
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.tractusx.irs.component.Shell;
import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor;
import org.eclipse.tractusx.irs.data.StringMapper;
import org.eclipse.tractusx.irs.edc.client.configuration.JsonLdConfiguration;
import org.eclipse.tractusx.irs.edc.client.model.EDRAuthCode;
import org.eclipse.tractusx.irs.registryclient.DigitalTwinRegistryKey;
import org.eclipse.tractusx.irs.registryclient.discovery.ConnectorEndpointsService;
import org.eclipse.tractusx.irs.registryclient.discovery.DiscoveryFinderClientImpl;
Expand All @@ -86,12 +90,7 @@ void setUp(WireMockRuntimeInfo wireMockRuntimeInfo) throws EdcRetrieverException
SHELL_DESCRIPTORS_TEMPLATE, LOOKUP_SHELLS_TEMPLATE);
decentralDigitalTwinRegistryService = new DecentralDigitalTwinRegistryService(connectorEndpointsService,
endpointDataForConnectorsService, decentralDigitalTwinRegistryClient);
final var endpointDataReference = EndpointDataReference.Builder.newInstance()
.endpoint(DATAPLANE_URL)
.authCode("TEST")
.authKey("X-API-KEY")
.properties(Map.of())
.build();
final var endpointDataReference = endpointDataReference("assetId");
when(edcSubmodelFacadeMock.getEndpointReferenceForAsset(any(), any(), any())).thenReturn(endpointDataReference);
}

Expand Down Expand Up @@ -198,4 +197,26 @@ void shouldThrowExceptionOnEmptyShells() {
verify(exactly(1), getRequestedFor(urlPathEqualTo(LOOKUP_SHELLS_PATH)));
verify(exactly(1), getRequestedFor(urlPathMatching(SHELL_DESCRIPTORS_PATH + ".*")));
}

private EndpointDataReference endpointDataReference(final String contractAgreementId) {
return EndpointDataReference.Builder.newInstance()
.authKey("X-API-KEY")
.authCode(edrAuthCode(contractAgreementId))
.properties(
Map.of(JsonLdConfiguration.NAMESPACE_EDC_CID, contractAgreementId))
.endpoint(DATAPLANE_URL)
.build();
}

private String edrAuthCode(final String contractAgreementId) {
final EDRAuthCode edrAuthCode = EDRAuthCode.builder()
.cid(contractAgreementId)
.dad("test")
.exp(9999999999L)
.build();
final String b64EncodedAuthCode = Base64.getUrlEncoder()
.encodeToString(StringMapper.mapToString(edrAuthCode)
.getBytes(StandardCharsets.UTF_8));
return "eyJhbGciOiJSUzI1NiJ9." + b64EncodedAuthCode + ".test";
}
}

0 comments on commit ae63bea

Please sign in to comment.