diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java index 9190266fb3..a04fbdf1a5 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java @@ -29,6 +29,7 @@ import org.eclipse.edc.spi.query.Criterion; import org.eclipse.edc.spi.query.QuerySpec; import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration.ControlplaneConfig.EndpointConfig; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.springframework.beans.factory.annotation.Qualifier; @@ -53,8 +54,11 @@ public List getContractAgreements(final String... contractAgr throws ContractAgreementException { final QuerySpec querySpec = buildQuerySpec(contractAgreementIds); + + final EndpointConfig endpoint = config.getControlplane().getEndpoint(); + final String contractAgreements = endpoint.getContractAgreements(); final ResponseEntity edcContractAgreementListResponseEntity = edcRestTemplate.postForEntity( - config.getControlplane().getEndpoint().getContractAgreements() + EDC_REQUEST_SUFFIX, querySpec, + endpoint.getData() + contractAgreements + EDC_REQUEST_SUFFIX, querySpec, EdcContractAgreementsResponse.class); final EdcContractAgreementsResponse contractAgreementListWrapper = edcContractAgreementListResponseEntity.getBody(); @@ -68,9 +72,10 @@ public List getContractAgreements(final String... contractAgr } public ContractNegotiation getContractAgreementNegotiation(final String contractAgreementId) { + final EndpointConfig endpoint = config.getControlplane().getEndpoint(); + final String contractAgreements = endpoint.getContractAgreements(); final ResponseEntity contractNegotiationResponseEntity = edcRestTemplate.getForEntity( - config.getControlplane().getEndpoint().getContractAgreements() + "/" + contractAgreementId - + "/negotiation", ContractNegotiation.class); + endpoint.getData() + contractAgreements + "/" + contractAgreementId + "/negotiation", ContractNegotiation.class); return contractNegotiationResponseEntity.getBody(); } diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java index 38e14d5677..ab0eea1fd0 100644 --- a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java @@ -41,6 +41,7 @@ import org.mockito.Answers; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; @@ -50,13 +51,16 @@ class EdcContractAgreementServiceTest { @Mock private RestTemplate restTemplate; - @Mock(answer = Answers.RETURNS_DEEP_STUBS) + @Spy private EdcConfiguration edcConfiguration; private EdcContractAgreementService edcContractAgreementService; @BeforeEach void setUp() { + edcConfiguration.getControlplane().setEndpoint(new EdcConfiguration.ControlplaneConfig.EndpointConfig()); + edcConfiguration.getControlplane().getEndpoint().setData("https://irs-consumer-controlplane.dev.demo.net/data/management"); + edcConfiguration.getControlplane().getEndpoint().setContractAgreements("/v2/contractagreements"); this.edcContractAgreementService = new EdcContractAgreementService(edcConfiguration, restTemplate); } @@ -64,8 +68,6 @@ void setUp() { void shouldReturnContractAgreements() throws ContractAgreementException { //GIVEN String[] contractAgreementIds = { "contractAgreementId" }; - when(edcConfiguration.getControlplane().getEndpoint().getContractAgreements()).thenReturn( - "/v2/contractagreements"); final ContractAgreement contractAgreement = ContractAgreement.Builder.newInstance() .id("id") @@ -88,7 +90,7 @@ void shouldReturnContractAgreements() throws ContractAgreementException { //THEN Mockito.verify(restTemplate) - .postForEntity(eq("/v2/contractagreements/request"), any(), + .postForEntity(eq("https://irs-consumer-controlplane.dev.demo.net/data/management/v2/contractagreements/request"), any(), eq(EdcContractAgreementsResponse.class)); assertNotNull(contractAgreements); } @@ -97,8 +99,6 @@ void shouldReturnContractAgreements() throws ContractAgreementException { void shouldThrowContractAgreementExceptionWhenResponseBodyIsEmtpy() { //GIVEN String[] contractAgreementIds = { "contractAgreementId" }; - when(edcConfiguration.getControlplane().getEndpoint().getContractAgreements()).thenReturn( - "/v2/contractagreements"); when(restTemplate.postForEntity(anyString(), any(), eq(EdcContractAgreementsResponse.class))).thenReturn( ResponseEntity.ok().build()); @@ -109,7 +109,7 @@ void shouldThrowContractAgreementExceptionWhenResponseBodyIsEmtpy() { //THEN Mockito.verify(restTemplate) - .postForEntity(eq("/v2/contractagreements/request"), any(), + .postForEntity(eq("https://irs-consumer-controlplane.dev.demo.net/data/management/v2/contractagreements/request"), any(), eq(EdcContractAgreementsResponse.class)); assertEquals("Empty message body on edc response: <200 OK OK,[]>", contractAgreementException.getMessage()); } @@ -118,8 +118,6 @@ void shouldThrowContractAgreementExceptionWhenResponseBodyIsEmtpy() { void shouldReturnContractAgreementNegotiation() { //GIVEN String contractAgreementId = "contractAgreementId"; - when(edcConfiguration.getControlplane().getEndpoint().getContractAgreements()).thenReturn( - "/v2/contractagreements"); final ContractNegotiation contractAgreementNegotiationMock = ContractNegotiation.Builder.newInstance() .id("id") @@ -136,7 +134,7 @@ void shouldReturnContractAgreementNegotiation() { //THEN Mockito.verify(restTemplate) - .getForEntity("/v2/contractagreements/contractAgreementId/negotiation", + .getForEntity("https://irs-consumer-controlplane.dev.demo.net/data/management/v2/contractagreements/contractAgreementId/negotiation", ContractNegotiation.class); assertNotNull(contractAgreementNegotiation); }