Skip to content

Commit

Permalink
feature: 420 add headers to EdcContractAgreementService
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-lcapellino committed Feb 29, 2024
1 parent e17e1c1 commit a1cca69
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
Expand All @@ -60,7 +59,9 @@ class EdcContractAgreementServiceTest {
@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()
.setData("https://irs-consumer-controlplane.dev.demo.net/data/management");
edcConfiguration.getControlplane().getEndpoint().setContractAgreements("/v2/contractagreements");
this.edcContractAgreementService = new EdcContractAgreementService(edcConfiguration, restTemplate);
}
Expand All @@ -80,19 +81,20 @@ void shouldReturnContractAgreements() throws ContractAgreementException {
.build();
final EdcContractAgreementsResponse edcContractAgreementsResponse = EdcContractAgreementsResponse.builder()
.contractAgreementList(
List.of(contractAgreement))
List.of(contractAgreement))
.build();
when(restTemplate.exchange(anyString(),eq(HttpMethod.POST), any(), eq(EdcContractAgreementsResponse.class))).thenReturn(
ResponseEntity.ok(edcContractAgreementsResponse));
when(restTemplate.exchange(anyString(), eq(HttpMethod.POST), any(),
eq(EdcContractAgreementsResponse.class))).thenReturn(ResponseEntity.ok(edcContractAgreementsResponse));

//WHEN
final List<ContractAgreement> contractAgreements = edcContractAgreementService.getContractAgreements(
contractAgreementIds);

//THEN
Mockito.verify(restTemplate)
.exchange(eq("https://irs-consumer-controlplane.dev.demo.net/data/management/v2/contractagreements/request"), any(), any(),
eq(EdcContractAgreementsResponse.class));
.exchange(
eq("https://irs-consumer-controlplane.dev.demo.net/data/management/v2/contractagreements/request"),
any(), any(), eq(EdcContractAgreementsResponse.class));
assertNotNull(contractAgreements);
}

Expand All @@ -101,7 +103,7 @@ void shouldThrowContractAgreementExceptionWhenResponseBodyIsEmtpy() {
//GIVEN
String[] contractAgreementIds = { "contractAgreementId" };

when(restTemplate.exchange(anyString(),any(), any(), eq(EdcContractAgreementsResponse.class))).thenReturn(
when(restTemplate.exchange(anyString(), any(), any(), eq(EdcContractAgreementsResponse.class))).thenReturn(
ResponseEntity.ok().build());

//WHEN
Expand All @@ -110,8 +112,9 @@ void shouldThrowContractAgreementExceptionWhenResponseBodyIsEmtpy() {

//THEN
Mockito.verify(restTemplate)
.exchange(eq("https://irs-consumer-controlplane.dev.demo.net/data/management/v2/contractagreements/request"),any(), any(),
eq(EdcContractAgreementsResponse.class));
.exchange(
eq("https://irs-consumer-controlplane.dev.demo.net/data/management/v2/contractagreements/request"),
any(), any(), eq(EdcContractAgreementsResponse.class));
assertEquals("Empty message body on edc response: <200 OK OK,[]>", contractAgreementException.getMessage());
}

Expand All @@ -126,7 +129,7 @@ void shouldReturnContractAgreementNegotiation() {
.counterPartyAddress("")
.protocol("")
.build();
when(restTemplate.exchange(anyString(),any(),any(), eq(ContractNegotiation.class))).thenReturn(
when(restTemplate.exchange(anyString(), any(), any(), eq(ContractNegotiation.class))).thenReturn(
ResponseEntity.ok(contractAgreementNegotiationMock));

//WHEN
Expand All @@ -135,9 +138,9 @@ void shouldReturnContractAgreementNegotiation() {

//THEN
Mockito.verify(restTemplate)
.exchange(eq("https://irs-consumer-controlplane.dev.demo.net/data/management/v2/contractagreements/contractAgreementId/negotiation"),
any(),any(),
eq(ContractNegotiation.class));
.exchange(
eq("https://irs-consumer-controlplane.dev.demo.net/data/management/v2/contractagreements/contractAgreementId/negotiation"),
any(), any(), eq(ContractNegotiation.class));
assertNotNull(contractAgreementNegotiation);
}
}

0 comments on commit a1cca69

Please sign in to comment.