From ed7fcdf57ea2049182f44a7bda0274165059499a Mon Sep 17 00:00:00 2001 From: Jaro Hartmann Date: Mon, 17 Apr 2023 17:04:17 +0200 Subject: [PATCH] feat(charts):[TRI-1213] Adjust test structure to IRS Code standards --- .../discovery/EdcDiscoveryClientImplTest.java | 19 ++++++++++++++----- .../ess/discovery/EdcDiscoveryFacadeTest.java | 12 ++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ess/src/test/java/org/eclipse/tractusx/ess/discovery/EdcDiscoveryClientImplTest.java b/ess/src/test/java/org/eclipse/tractusx/ess/discovery/EdcDiscoveryClientImplTest.java index c297438a84..22c484e1b5 100644 --- a/ess/src/test/java/org/eclipse/tractusx/ess/discovery/EdcDiscoveryClientImplTest.java +++ b/ess/src/test/java/org/eclipse/tractusx/ess/discovery/EdcDiscoveryClientImplTest.java @@ -39,11 +39,12 @@ class EdcDiscoveryClientImplTest { private final RestTemplate restTemplate = mock(RestTemplate.class); - private final EdcDiscoveryClient bpdmClient = new EdcDiscoveryClientImpl(restTemplate, + private final EdcDiscoveryClient edcDiscoveryClient = new EdcDiscoveryClientImpl(restTemplate, "url/api/administration/connectors/discovery"); @Test void shouldCallExternalServiceOnceAndGetEdcAddressResponse() { + // Arrange final String bpn = "BPNS000000000DDD"; final EdcAddressResponse[] mockResponse = new EdcAddressResponse[] { EdcAddressResponse.builder() .bpn(bpn) @@ -53,8 +54,10 @@ void shouldCallExternalServiceOnceAndGetEdcAddressResponse() { }; doReturn(mockResponse).when(restTemplate).postForObject(any(), any(), eq(EdcAddressResponse[].class)); - final List edcAddressResponse = List.of(bpdmClient.getEdcBaseUrl(bpn)); + // Act + final List edcAddressResponse = List.of(edcDiscoveryClient.getEdcBaseUrl(bpn)); + // Assert assertThat(edcAddressResponse).isNotNull().hasSize(1); assertThat(edcAddressResponse.get(0).getBpn()).isEqualTo(bpn); assertThat(edcAddressResponse.get(0).getConnectorEndpoint()).isNotEmpty(); @@ -63,6 +66,7 @@ void shouldCallExternalServiceOnceAndGetEdcAddressResponse() { @Test void shouldCallExternalServiceWithTwoEndpointsOnceAndGetEdcAddressResponse() { + // Arrange final String bpn = "BPNS000000000DDD"; final EdcAddressResponse[] mockResponse = new EdcAddressResponse[] { EdcAddressResponse.builder() .bpn(bpn) @@ -72,8 +76,10 @@ void shouldCallExternalServiceWithTwoEndpointsOnceAndGetEdcAddressResponse() { }; doReturn(mockResponse).when(restTemplate).postForObject(any(), any(), eq(EdcAddressResponse[].class)); - final List edcAddressResponse = List.of(bpdmClient.getEdcBaseUrl(bpn)); + // Act + final List edcAddressResponse = List.of(edcDiscoveryClient.getEdcBaseUrl(bpn)); + // Assert assertThat(edcAddressResponse).isNotNull().hasSize(1); assertThat(edcAddressResponse.get(0).getBpn()).isEqualTo(bpn); assertThat(edcAddressResponse.get(0).getConnectorEndpoint()).hasSize(2); @@ -84,12 +90,15 @@ void shouldCallExternalServiceWithTwoEndpointsOnceAndGetEdcAddressResponse() { @Test void shouldReturnNullWhenRestTemplateReturnsNull() { + // Arrange final String bpn = "BPNS000000000DDD"; doReturn(null).when(restTemplate).postForObject(any(), any(), eq(EdcAddressResponse[].class)); - final EdcAddressResponse[] edcBaseUrl = bpdmClient.getEdcBaseUrl(bpn); - assertThat(edcBaseUrl).isNull(); + // Act + final EdcAddressResponse[] edcBaseUrl = edcDiscoveryClient.getEdcBaseUrl(bpn); + // Assert + assertThat(edcBaseUrl).isNull(); verify(this.restTemplate, times(1)).postForObject(any(), any(), eq(EdcAddressResponse[].class)); } } diff --git a/ess/src/test/java/org/eclipse/tractusx/ess/discovery/EdcDiscoveryFacadeTest.java b/ess/src/test/java/org/eclipse/tractusx/ess/discovery/EdcDiscoveryFacadeTest.java index abb1def1f2..efad58258a 100644 --- a/ess/src/test/java/org/eclipse/tractusx/ess/discovery/EdcDiscoveryFacadeTest.java +++ b/ess/src/test/java/org/eclipse/tractusx/ess/discovery/EdcDiscoveryFacadeTest.java @@ -41,44 +41,56 @@ class EdcDiscoveryFacadeTest { @Test void shouldReturnEdcBaseUrl() { + // Arrange final String bpn = "BPNS000000000DDD"; final String url = "http://edc-url"; when(edcDiscoveryMockConfig.getMockEdcAddress()).thenReturn(Map.of(bpn, List.of(url))); + // Act final Optional edcBaseUrl = edcDiscoveryFacade.getEdcBaseUrl(bpn); + // Assert assertThat(edcBaseUrl).isNotEmpty().contains(url); } @Test void shouldReturnEdcBaseUrls() { + // Arrange final String bpn = "BPNS000000000DDD"; final String url1 = "http://edc-url1"; final String url2 = "http://edc-url2"; when(edcDiscoveryMockConfig.getMockEdcAddress()).thenReturn(Map.of(bpn, List.of(url1, url2))); + // Act final Optional edcBaseUrl = edcDiscoveryFacade.getEdcBaseUrl(bpn); + // Assert assertThat(edcBaseUrl).isNotEmpty().contains(url1); } @Test void shouldReturnResponseWithEmptyConnectorEndpointList() { + // Arrange when(edcDiscoveryMockConfig.getMockEdcAddress()).thenReturn(Map.of()); + // Act final Optional edcBaseUrl = edcDiscoveryFacade.getEdcBaseUrl("not_existing"); + // Assert assertThat(edcBaseUrl).isEmpty(); } @Test void shouldReturnEmptyOptionalWhenClientReturnsNull() { + // Arrange final EdcDiscoveryClientLocalStub clientMock = mock(EdcDiscoveryClientLocalStub.class); final EdcDiscoveryFacade edcDiscoveryFacade = new EdcDiscoveryFacade(clientMock); when(clientMock.getEdcBaseUrl(anyString())).thenReturn(null); + // Act final Optional edcBaseUrl = edcDiscoveryFacade.getEdcBaseUrl("not_existing"); + // Assert assertThat(edcBaseUrl).isEmpty(); }