aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/test/java
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2018-08-10 17:39:33 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2018-08-10 17:39:33 -0400
commitea59a688ce8d31426a830500a164b891bc180b54 (patch)
tree506a51718c2e8f00b72a0c5950e91bb15449311c /common/src/test/java
parent6f6ff2d81cde79a129e40846f1e3bd33848595d8 (diff)
Handle special aai case better
corrected error handling in aai client for service instances updated the exception logic for si's that are not found adhere to mapNotFoundToEmpty in special case Issue-ID: SO-851 Change-Id: I3843733553143dae046c1ae944a3bfd71ac5170c Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'common/src/test/java')
-rw-r--r--common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java99
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java44
2 files changed, 126 insertions, 17 deletions
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java
new file mode 100644
index 0000000000..efd60a36a8
--- /dev/null
+++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java
@@ -0,0 +1,99 @@
+package org.onap.so.client.aai;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import java.util.List;
+import java.util.Optional;
+
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.client.aai.entities.uri.ServiceInstanceUri;
+import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+
+public class AAIResourcesClientWithServiceInstanceUriTest {
+
+ @Rule
+ public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8443));
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private ServiceInstanceUri uri;
+ @Before
+ public void setUp() {
+ wireMockRule.stubFor(get(urlMatching("/aai/v[0-9]+/nodes.*"))
+ .willReturn(aResponse()
+ .withStatus(404)
+ .withHeader("Content-Type", "application/json")
+ .withHeader("Mock", "true")));
+
+ uri = spy((ServiceInstanceUri)AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "id"));
+ doReturn(createClient()).when(uri).getResourcesClient();
+ }
+
+ @Test
+ public void getWithClass() {
+ AAIResourcesClient client = createClient();
+ Optional<String> result = client.get(String.class, uri);
+
+ assertThat(result.isPresent(), equalTo(false));
+ }
+
+ @Test
+ public void getFullResponse() {
+ AAIResourcesClient client = createClient();
+ Response result = client.getFullResponse(uri);
+ assertThat(result.getStatus(), equalTo(Status.NOT_FOUND.getStatusCode()));
+ }
+
+ @Test
+ public void getWithGenericType() {
+ AAIResourcesClient client = createClient();
+ Optional<List<String>> result = client.get(new GenericType<List<String>>() {}, uri);
+ assertThat(result.isPresent(), equalTo(false));
+ }
+
+ @Test
+ public void getAAIWrapper() {
+ AAIResourcesClient client = createClient();
+ AAIResultWrapper result = client.get(uri);
+ assertThat(result.isEmpty(), equalTo(true));
+ }
+
+ @Test
+ public void getWithException() {
+ AAIResourcesClient client = createClient();
+ this.thrown.expect(IllegalArgumentException.class);
+ AAIResultWrapper result = client.get(uri, IllegalArgumentException.class);
+ }
+
+ @Test
+ public void existsTest() {
+ AAIResourcesClient client = createClient();
+ doReturn(uri).when(uri).clone();
+ boolean result = client.exists(uri);
+ assertThat(result, equalTo(false));
+ }
+ private AAIResourcesClient createClient() {
+ AAIResourcesClient client = spy(new AAIResourcesClient());
+ doReturn(new DefaultAAIPropertiesImpl()).when(client).getRestProperties();
+ return client;
+ }
+}
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
index 73720f55c2..2cd7848cfa 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUriTest.java
@@ -21,10 +21,9 @@
package org.onap.so.client.aai.entities.uri;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
-import static com.github.tomakehurst.wiremock.client.WireMock.containing;
-import static com.github.tomakehurst.wiremock.client.WireMock.put;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
@@ -43,14 +42,16 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Optional;
+import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.UriBuilder;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.onap.so.client.aai.AAIQueryClient;
-import org.onap.so.client.graphinventory.Format;
-import org.onap.so.client.aai.entities.CustomQuery;
+import org.mockito.Matchers;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException;
@@ -155,9 +156,11 @@ public class ServiceInstanceUriTest {
ServiceInstanceUri instance = new ServiceInstanceUri("key3");
ServiceInstanceUri spy = spy(instance);
- AAIQueryClient mockQueryClient = mock(AAIQueryClient.class);
- when(mockQueryClient.query(any(Format.class), any(CustomQuery.class))).thenReturn(content);
- when(spy.getQueryClient()).thenReturn(mockQueryClient);
+ AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class);
+ AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
+ when(mockResourcesClient.get(Matchers.<AAIResourceUri>any(AAIResourceUri.class), Matchers.<Class<NotFoundException>>any())).thenReturn(wrapper);
+ when(wrapper.getJson()).thenReturn(content);
+ when(spy.getResourcesClient()).thenReturn(mockResourcesClient);
exception.expect(GraphInventoryUriComputationException.class);
spy.build();
@@ -176,17 +179,24 @@ public class ServiceInstanceUriTest {
public void noVertexFound() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
ServiceInstanceUri instance = new ServiceInstanceUri("key3");
ServiceInstanceUri spy = spy(instance);
- AAIQueryClient client = mock(AAIQueryClient.class);
- when(client.query(any(Format.class), any(CustomQuery.class))).thenReturn("{\"results\":[]}");
- doReturn(client).when(spy).getQueryClient();
- stubFor(put(urlMatching("/aai/v[0-9]+/query.*"))
- .withRequestBody(containing("key3"))
+ AAIResourcesClient client = createClient();
+ doReturn(client).when(spy).getResourcesClient();
+ /*AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
+ when(client.get(Matchers.<AAIResourceUri>any(AAIResourceUri.class), Matchers.<Class<NotFoundException>>any())).thenReturn(wrapper);
+ when(wrapper.getJson()).thenReturn("{\"results\":[]}");
+ doReturn(client).when(spy).getResourcesClient();*/
+ stubFor(get(urlPathMatching("/aai/v[0-9]+/nodes/service-instances/service-instance/key3"))
.willReturn(aResponse()
- .withStatus(400)
+ .withStatus(404)
.withHeader("Content-Type", "application/json")
.withBodyFile("")));
- exception.expect(GraphInventoryUriComputationException.class);
- exception.expectMessage(containsString("NotFoundException"));
+ exception.expect(NotFoundException.class);
spy.build();
}
+
+ private AAIResourcesClient createClient() {
+ AAIResourcesClient client = spy(new AAIResourcesClient());
+ doReturn(new DefaultAAIPropertiesImpl()).when(client).getRestProperties();
+ return client;
+ }
}