aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2018-12-31 17:21:27 +0200
committerIttay Stern <ittay.stern@att.com>2019-01-09 20:19:55 +0200
commit6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 (patch)
tree3bd672dff83e3218232cd8665680416b7fc26a5d /vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
parent5ec29ff5e3864f1ba6ecac71f8bffbefa400cf27 (diff)
Merge from ECOMP's repository
Main Features -------------- - Async-Instantiation jobs mechanism major update; still WIP (package `org.onap.vid.job`) - New features in View/Edit: Activate fabric configuration; show related networks; soft delete - Support AAI service-tree traversal (`AAIServiceTree`) - In-memory cache for SDC models and certain A&AI queries (`CacheProviderWithLoadingCache`) - Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA models - Resolve Cloud-Owner values for MSO - Pass X-ONAP headers to MSO Infrastructure -------------- - Remove codehaus' jackson mapper; use soley fasterxml 2.9.7 - Surefire invokes both TestNG and JUnit tests - Support Kotlin source files - AaiController2 which handles errors in a "Spring manner" - Inline generated-sources and remove jsonschema2pojo Quality -------- - Cumulative bug fixes (A&AI API, UI timeouts, and many more) - Many Sonar issues cleaned-up - Some unused classes removed - Minor changes in vid-automation project, allowing some API verification to run Hard Merges ------------ - HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest) - Moved `package org.onap.vid.controllers` to `controller`, without plural -- just to keep semantic sync with ECOMP. Reference commit in ECOMP: 3d1141625 Issue-ID: VID-378 Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java75
1 files changed, 40 insertions, 35 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
index 7fad9019c..b5f8ff942 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
@@ -26,7 +26,11 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.vid.aai.ExceptionWithRequestInfo;
import org.onap.vid.aai.exceptions.InvalidPropertyException;
+import org.onap.vid.exceptions.GenericUncheckedException;
+import org.onap.vid.utils.Unchecked;
+import org.springframework.http.HttpMethod;
import org.testng.Assert;
import javax.servlet.http.HttpServletRequest;
@@ -37,10 +41,14 @@ 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 javax.ws.rs.core.Response.Status.*;
+import static junit.framework.TestCase.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -56,6 +64,8 @@ public class SingleAAIRestInterfaceTest {
@Mock
private Invocation.Builder builder;
@Mock
+ private Invocation invocation;
+ @Mock
private ServletRequestHelper servletRequestHelper;
@Mock
private HttpsAuthClient httpsAuthClient;
@@ -76,6 +86,9 @@ public class SingleAAIRestInterfaceTest {
when(webTarget.request()).thenReturn(builder);
when(builder.accept(Mockito.anyString())).thenReturn(builder);
when(builder.header(Mockito.anyString(), Mockito.anyString())).thenReturn(builder);
+ when(builder.build(Mockito.anyString())).thenReturn(invocation);
+ when(builder.build(Mockito.anyString(), any(Entity.class))).thenReturn(invocation);
+ when(invocation.invoke()).thenReturn(response);
when(servletRequestHelper.extractOrGenerateRequestId()).thenReturn(UUID.randomUUID().toString());
}
@@ -90,70 +103,67 @@ public class SingleAAIRestInterfaceTest {
}
@Test
- public void testSetRestSrvrBaseURLWithNullValue() throws Exception {
+ public void testSetRestSrvrBaseURLWithNullValue() {
testSubject.SetRestSrvrBaseURL(null);
}
@Test
- public void testSetRestSrvrBaseURL() throws Exception {
+ public void testSetRestSrvrBaseURL() {
String baseUrl = "anything";
testSubject.SetRestSrvrBaseURL(baseUrl);
Assert.assertEquals(testSubject.getRestSrvrBaseURL(), baseUrl);
}
@Test
- public void testRestJsonPutWithResponse200() throws Exception {
+ public void testRestJsonPutWithResponse200() {
// given
String methodName = "RestPut";
String payload = "{\"id\": 1}";
Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
// when
- when(builder.put(Mockito.any(Entity.class))).thenReturn(response);
when(response.getStatusInfo()).thenReturn(OK);
- Response finalResponse = testSubject.RestPut("", PATH, payload, false);
+ Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
// then
- verify(builder).put(entity);
+ verify(builder).build(HttpMethod.PUT.name(), entity);
Assert.assertEquals(response, finalResponse);
}
- @Test
- public void testFailedRestJsonPut() throws Exception {
+ @Test(expected = ExceptionWithRequestInfo.class)
+ public void testFailedRestJsonPut() {
// given
String methodName = "RestPut";
String payload = "{\"id\": 1}";
Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
// when
- when(builder.put(Mockito.any(Entity.class))).thenThrow(new RuntimeException());
- Response finalResponse = testSubject.RestPut("", PATH, payload, false);
+ when(builder.build(eq(HttpMethod.PUT.name()), any(Entity.class))).thenThrow(new GenericUncheckedException("msg"));
+ Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
// then
- verify(builder).put(entity);
- Assert.assertEquals(finalResponse, null);
+ fail("expected unreachable: exception to be thrown");
}
@Test
- public void testRestJsonPutWithResponse400() throws Exception {
+ public void testRestJsonPutWithResponse400() {
// given
String methodName = "RestPut";
String payload = "{\"id\": 1}";
Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
// when
- when(builder.put(Mockito.any(Entity.class))).thenReturn(response);
when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
- Response finalResponse = testSubject.RestPut("", PATH, payload, false);
+ Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
// then
- verify(builder).put(entity);
+ verify(builder).build(HttpMethod.PUT.name(), entity);
Assert.assertEquals(response, finalResponse);
}
@Test
- public void testRestPostWithResponse200() throws Exception {
+ public void testRestPostWithResponse200() {
// given
String methodName = "RestPost";
String payload = "{\"id\": 1}";
@@ -170,7 +180,7 @@ public class SingleAAIRestInterfaceTest {
}
@Test
- public void testRestPostWithResponse400() throws Exception {
+ public void testRestPostWithResponse400() {
// given
String methodName = "RestPost";
String payload = "{\"id\": 1}";
@@ -188,7 +198,7 @@ public class SingleAAIRestInterfaceTest {
}
@Test
- public void testFailedRestPost() throws Exception {
+ public void testFailedRestPost() {
// given
String methodName = "RestPost";
String payload = "{\"id\": 1}";
@@ -204,7 +214,7 @@ public class SingleAAIRestInterfaceTest {
}
@Test
- public void testRestDeleteWithResponse400() throws Exception {
+ public void testRestDeleteWithResponse400() {
// given
String methodName = "Delete";
@@ -222,7 +232,7 @@ public class SingleAAIRestInterfaceTest {
}
@Test
- public void testRestDeleteWithResponse404() throws Exception {
+ public void testRestDeleteWithResponse404() {
// given
String methodName = "Delete";
@@ -240,7 +250,7 @@ public class SingleAAIRestInterfaceTest {
}
@Test
- public void testFailedRestDelete() throws Exception {
+ public void testFailedRestDelete() {
// given
String methodName = "Delete";
@@ -254,54 +264,49 @@ public class SingleAAIRestInterfaceTest {
}
@Test
- public void testRestJsonGetWithResponse200() throws Exception {
+ public void testRestJsonGetWithResponse200() {
// given
String methodName = "RestGet";
// when
- when(builder.get()).thenReturn(response);
when(response.getStatusInfo()).thenReturn(OK);
- Response finalResponse = testSubject.RestGet("", "", PATH, false).getResponse();
+ Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
// then
Assert.assertEquals(response, finalResponse);
}
@Test
- public void testRestJsonGetWithResponse400() throws Exception {
+ public void testRestJsonGetWithResponse400() {
// given
String methodName = "RestGet";
// when
- when(builder.get()).thenReturn(response);
when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
- Response finalResponse = testSubject.RestGet("", "", PATH, false).getResponse();
+ Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
// then
Assert.assertEquals(response, finalResponse);
}
@Test
- public void testFailedRestGet() throws Exception {
+ public void testFailedRestGet() {
// given
String methodName = "RestGet";
// when
- when(builder.get()).thenThrow(new RuntimeException());
- Response finalResponse = testSubject.RestGet("", "", PATH, false).getResponse();
+ when(builder.build(HttpMethod.GET.name())).thenThrow(new RuntimeException());
+ Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
// then
Assert.assertEquals(finalResponse, null);
}
private void mockSystemProperties() throws UnsupportedEncodingException, InvalidPropertyException {
- when(systemPropertyHelper.getAAIServerUrl()).thenReturn(Optional.of(HTTP_LOCALHOST));
- when(systemPropertyHelper.getAAIUseClientCert()).thenReturn(Optional.of("cert"));
- when(systemPropertyHelper.getAAIVIDPasswd()).thenReturn(Optional.of("passwd"));
- when(systemPropertyHelper.getAAIVIDUsername()).thenReturn(Optional.of("user"));
when(systemPropertyHelper.getEncodedCredentials()).thenReturn("someCredentials");
when(systemPropertyHelper.getFullServicePath(Mockito.anyString())).thenReturn("http://localhost/path");
+ when(systemPropertyHelper.getFullServicePath(Mockito.any(URI.class))).thenReturn("http://localhost/path");
when(systemPropertyHelper.getServiceBasePath(Mockito.anyString())).thenReturn("http://localhost/path");
}