diff options
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/aai')
5 files changed, 92 insertions, 78 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiClientTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiClientTest.java index 777729c03..7c08e942a 100644 --- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiClientTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiClientTest.java @@ -96,6 +96,7 @@ import org.onap.vid.model.probes.ExternalComponentStatus; import org.onap.vid.model.probes.HttpRequestMetadata; import org.onap.vid.model.probes.StatusMetadata; import org.onap.vid.testUtils.TestUtils; +import org.onap.vid.utils.Logging; import org.onap.vid.utils.Unchecked; import org.springframework.http.HttpMethod; import org.springframework.test.context.ContextConfiguration; @@ -648,7 +649,10 @@ public class AaiClientTest { Response responseMock = mocks.getFakeResponse(); // prepare real AAIRestInterface and AaiClient, and wire mocks - AAIRestInterface aaiRestInterface = new AAIRestInterface(httpsAuthClientMock, mock(ServletRequestHelper.class), mock(SystemPropertyHelper.class)); + AAIRestInterface aaiRestInterface = new AAIRestInterface(httpsAuthClientMock, + mock(ServletRequestHelper.class), + mock(SystemPropertyHelper.class), + mock(Logging.class)); final AaiClient aaiClient = new AaiClient(aaiRestInterface, null, null); when(httpsAuthClientMock.getClient(any())).thenReturn(javaxClientMock); diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java index dd7b26c12..a9fe256c1 100644 --- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java @@ -20,12 +20,17 @@ package org.onap.vid.aai; +import static org.mockito.Mockito.mock; +import static org.mockito.MockitoAnnotations.initMocks; + import com.fasterxml.jackson.core.JsonProcessingException; import com.xebialabs.restito.semantics.Action; import io.joshworks.restclient.http.HttpResponse; import io.joshworks.restclient.http.mapper.ObjectMapper; +import java.io.IOException; import org.assertj.core.api.Assertions; import org.glassfish.grizzly.http.util.HttpStatus; +import org.jetbrains.annotations.NotNull; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.mockito.Mock; @@ -33,15 +38,12 @@ import org.onap.vid.aai.model.ResourceType; import org.onap.vid.client.SyncRestClient; import org.onap.vid.model.SubscriberList; import org.onap.vid.testUtils.StubServerUtil; +import org.onap.vid.utils.Logging; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.IOException; - -import static org.mockito.MockitoAnnotations.initMocks; - public class AaiOverTLSClientServerTest { @Mock @@ -107,8 +109,7 @@ public class AaiOverTLSClientServerTest { @Test public void shouldSearchNodeTypeByName() throws IOException, ParseException { - ObjectMapper objectMapper = getFasterXmlObjectMapper(); - AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", "")); + AaiOverTLSClient aaiOverTLSClient = createAaiOverTLSClient(); serverUtil.prepareGetCall("/nodes/generic-vnfs", new JSONParser().parse(searchNodesQueryResponsePayload), Action.status(HttpStatus.OK_200)); @@ -118,10 +119,19 @@ public class AaiOverTLSClientServerTest { Assertions.assertThat(aaiNodeQueryResponseHttpResponse).isEqualTo(true); } + @NotNull + private AaiOverTLSClient createAaiOverTLSClient() { + return new AaiOverTLSClient( + new SyncRestClient(getFasterXmlObjectMapper(), mock(Logging.class)), + propertySupplier, + serverUtil.constructTargetUrl("http", "") + ); + } + @Test public void shouldGetSubscribers() throws ParseException, JsonProcessingException { ObjectMapper objectMapper = getFasterXmlObjectMapper(); - AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", "")); + AaiOverTLSClient aaiOverTLSClient = createAaiOverTLSClient(); serverUtil.prepareGetCall("/business/customers", new JSONParser().parse(subscribersResponsePayload), Action.status(HttpStatus.OK_200)); diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java index b409c1f46..5de993c73 100644 --- a/vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java @@ -20,30 +20,9 @@ package org.onap.vid.aai; -import org.mockito.Mock; -import org.onap.vid.aai.util.HttpClientMode; -import org.onap.vid.aai.util.HttpsAuthClient; -import org.onap.vid.aai.util.ServletRequestHelper; -import org.onap.vid.aai.util.SystemPropertyHelper; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import java.io.IOException; -import java.security.GeneralSecurityException; -import java.util.UUID; -import java.util.regex.Pattern; - import static org.assertj.core.api.Assertions.assertThat; - -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; @@ -53,6 +32,25 @@ import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.FROM_APP_ID_HEA import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.TRANSACTION_ID_HEADER; import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY; +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.UUID; +import java.util.regex.Pattern; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.mockito.Mock; +import org.onap.vid.aai.util.HttpClientMode; +import org.onap.vid.aai.util.HttpsAuthClient; +import org.onap.vid.aai.util.ServletRequestHelper; +import org.onap.vid.aai.util.SystemPropertyHelper; +import org.onap.vid.utils.Logging; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + public class PombaRestInterfaceTest { private static final String UUID_REGEX = "[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}"; private static final String SAMPLE_APP_ID = "vid"; @@ -81,6 +79,9 @@ public class PombaRestInterfaceTest { @Mock private Response response; + @Mock + private Logging loggingService; + private PombaRestInterface pombaRestInterface; @BeforeMethod @@ -90,7 +91,7 @@ public class PombaRestInterfaceTest { when(requestHelper.extractOrGenerateRequestId()).thenReturn(UUID.randomUUID().toString()); when(authClient.getClient(HttpClientMode.WITH_KEYSTORE)).thenReturn(client); setUpBuilder(); - pombaRestInterface = new PombaRestInterface(authClient, requestHelper, systemPropertyHelper); + pombaRestInterface = new PombaRestInterface(authClient, requestHelper, systemPropertyHelper, loggingService); } @@ -124,4 +125,4 @@ public class PombaRestInterfaceTest { when(builder.post(any(Entity.class))).thenReturn(response); when(response.getStatusInfo()).thenReturn(Response.Status.OK); } -}
\ No newline at end of file +} diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java index e64b2ac55..bf8a5a1bc 100644 --- a/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java @@ -21,42 +21,38 @@ package org.onap.vid.aai.util; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.util.Optional; +import java.util.UUID; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.mockito.Mock; import org.mockito.Mockito; - import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.aai.exceptions.InvalidPropertyException; import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.utils.Logging; import org.onap.vid.utils.Unchecked; import org.springframework.http.HttpMethod; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.util.Optional; -import java.util.UUID; - -import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor; -import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters; -import static javax.ws.rs.core.Response.Status.*; -import static junit.framework.TestCase.assertSame; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - public class AAIRestInterfaceTest { @@ -80,6 +76,9 @@ public class AAIRestInterfaceTest { private Response response; @Mock private SystemPropertyHelper systemPropertyHelper; + @Mock + private Logging loggingService; + private AAIRestInterface testSubject; @@ -99,7 +98,7 @@ public class AAIRestInterfaceTest { } private AAIRestInterface createTestSubject() { - return new AAIRestInterface(Optional.of(client), httpsAuthClient, servletRequestHelper, systemPropertyHelper); + return new AAIRestInterface(Optional.of(client), httpsAuthClient, servletRequestHelper, systemPropertyHelper, loggingService); } @Test diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java index 82bb7275b..c0d3b962f 100644 --- a/vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/ParametrizedAAIRestInterfaceTest.java @@ -20,6 +20,21 @@ package org.onap.vid.aai.util; +import static javax.ws.rs.core.Response.Status.NO_CONTENT; +import static javax.ws.rs.core.Response.Status.OK; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Optional; +import java.util.UUID; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,24 +43,9 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.vid.aai.exceptions.InvalidPropertyException; +import org.onap.vid.utils.Logging; import org.testng.Assert; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; -import java.io.UnsupportedEncodingException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Optional; -import java.util.UUID; - -import static javax.ws.rs.core.Response.Status.NO_CONTENT; -import static javax.ws.rs.core.Response.Status.OK; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - @RunWith(Parameterized.class) public class ParametrizedAAIRestInterfaceTest { @@ -67,6 +67,8 @@ public class ParametrizedAAIRestInterfaceTest { private Response response; @Mock private SystemPropertyHelper systemPropertyHelper; + @Mock + private Logging loggingService; private AAIRestInterface testSubject; private Response.Status status; @@ -93,13 +95,11 @@ public class ParametrizedAAIRestInterfaceTest { } private AAIRestInterface createTestSubject() { - return new AAIRestInterface(Optional.of(client), httpsAuthClient, servletRequestHelper, systemPropertyHelper); + return new AAIRestInterface(Optional.of(client), httpsAuthClient, servletRequestHelper, systemPropertyHelper, loggingService); } @Test - public void testRestDeleteWithValidResponse() throws Exception { - // given - String methodName = "Delete"; + public void testRestDeleteWithValidResponse() { // when when(builder.delete()).thenReturn(response); |