Skip to content

Commit

Permalink
Merge pull request #454 from catenax-ng/feature/420-add-contractagree…
Browse files Browse the repository at this point in the history
…ments

feature: 420 fix base url in EdcContractAgreementService
  • Loading branch information
mkanal authored Feb 29, 2024
2 parents 2325052 + 2cd24cc commit 22c71bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,8 +54,11 @@ public List<ContractAgreement> getContractAgreements(final String... contractAgr
throws ContractAgreementException {

final QuerySpec querySpec = buildQuerySpec(contractAgreementIds);

final EndpointConfig endpoint = config.getControlplane().getEndpoint();
final String contractAgreements = endpoint.getContractAgreements();
final ResponseEntity<EdcContractAgreementsResponse> 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();
Expand All @@ -68,9 +72,10 @@ public List<ContractAgreement> getContractAgreements(final String... contractAgr
}

public ContractNegotiation getContractAgreementNegotiation(final String contractAgreementId) {
final EndpointConfig endpoint = config.getControlplane().getEndpoint();
final String contractAgreements = endpoint.getContractAgreements();
final ResponseEntity<ContractNegotiation> contractNegotiationResponseEntity = edcRestTemplate.getForEntity(
config.getControlplane().getEndpoint().getContractAgreements() + "/" + contractAgreementId
+ "/negotiation", ContractNegotiation.class);
endpoint.getData() + contractAgreements + "/" + contractAgreementId + "/negotiation", ContractNegotiation.class);
return contractNegotiationResponseEntity.getBody();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,22 +51,23 @@ 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);
}

@Test
void shouldReturnContractAgreements() throws ContractAgreementException {
//GIVEN
String[] contractAgreementIds = { "contractAgreementId" };
when(edcConfiguration.getControlplane().getEndpoint().getContractAgreements()).thenReturn(
"/v2/contractagreements");

final ContractAgreement contractAgreement = ContractAgreement.Builder.newInstance()
.id("id")
Expand All @@ -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);
}
Expand All @@ -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());
Expand All @@ -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());
}
Expand All @@ -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")
Expand All @@ -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);
}
Expand Down

0 comments on commit 22c71bc

Please sign in to comment.