aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiClientTest.java90
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java199
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java89
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java12
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java2
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java24
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java12
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java40
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/ClientCredentialsFilterTest.java4
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/PromiseEcompRequestIdFilterTest.java9
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controllers/ChangeManagementControllerTest.java10
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controllers/HealthCheckControllerTest.java120
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controllers/MaintenanceControllerTest.java29
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controllers/PromiseEcompRequestIdFilterTest.java9
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controllers/VidControllerTest.java389
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/dao/FnAppDoaImplTest.java126
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/impl/JobWorkerTest.java2
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java40
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestIdTest.java17
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/scheduler/SchedulerRestInterfaceTest.java2
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java32
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java45
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java65
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/CategoryParameterServiceImplTest.java34
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceImplTest.java22
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java10
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java4
27 files changed, 893 insertions, 544 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 76d1d4aff..201ec0981 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
@@ -33,6 +33,7 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
import org.onap.vid.aai.model.AaiNodeQueryResponse;
+import org.onap.vid.aai.model.PortDetailsTranslator;
import org.onap.vid.aai.model.ResourceType;
import org.onap.vid.aai.util.AAIRestInterface;
import org.onap.vid.aai.util.HttpsAuthClient;
@@ -71,13 +72,12 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalToIgnoringCase;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
import static org.testng.Assert.*;
@ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
@@ -88,19 +88,19 @@ public class AaiClientTest {
private ServletContext servletContext;
@BeforeMethod
- public void initMocks(){
+ public void initMocks() {
aaiClientMock = mock(AaiClient.class);
aaiClientMock.logger = mock(EELFLoggerDelegate.class);
servletContext = mock(ServletContext.class);
when(servletContext.getRealPath(any(String.class))).thenReturn("");
- when(aaiClientMock.doAaiGet(any(String.class),any(Boolean.class))).thenReturn(null);
+ when(aaiClientMock.doAaiGet(any(String.class), any(Boolean.class))).thenReturn(null);
}
@DataProvider
public static Object[][] logicalLinkData() {
- return new Object[][] {
+ return new Object[][]{
{"", "network/logical-links/logical-link/"},
{"link", "network/logical-links/logical-link/link"}
};
@@ -111,21 +111,26 @@ public class AaiClientTest {
when(aaiClientMock.getLogicalLink(any(String.class))).thenCallRealMethod();
aaiClientMock.getLogicalLink(link);
- Mockito.verify(aaiClientMock).doAaiGet(argThat(equalToIgnoringCase(expectedUrl)),any(Boolean.class));
+ Mockito.verify(aaiClientMock).doAaiGet(argThat(s -> equalsIgnoreCase(s, expectedUrl)), any(Boolean.class));
}
@DataProvider
public static Object[][] subscribersResults() {
- return new Object[][] {
- {new SubscriberList(new ArrayList<Subscriber>() {{ add(new Subscriber()); add(new Subscriber()); }}), true},
- {new SubscriberList(new ArrayList<Subscriber>() {{ add(new Subscriber()); }}), true},
+ return new Object[][]{
+ {new SubscriberList(new ArrayList<Subscriber>() {{
+ add(new Subscriber());
+ add(new Subscriber());
+ }}), true},
+ {new SubscriberList(new ArrayList<Subscriber>() {{
+ add(new Subscriber());
+ }}), true},
{new SubscriberList(new ArrayList<Subscriber>()), false}
};
}
@Test(dataProvider = "subscribersResults")
- public void testProbeAaiGetAllSubscribers_returnsTwoToZeroSubscribers_ResultsAsExpected(SubscriberList subscribers, boolean isAvailable){
- ExternalComponentStatus expectedStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.AAI,isAvailable, new HttpRequestMetadata(
+ public void testProbeAaiGetAllSubscribers_returnsTwoToZeroSubscribers_ResultsAsExpected(SubscriberList subscribers, boolean isAvailable) {
+ ExternalComponentStatus expectedStatus = new ExternalComponentStatus(ExternalComponentStatus.Component.AAI, isAvailable, new HttpRequestMetadata(
HttpMethod.GET,
200,
"url",
@@ -138,9 +143,9 @@ public class AaiClientTest {
HttpMethod.GET, "url", new AaiResponse<>(subscribers, null, 200),
"rawData"));
Mockito.when(aaiClientMock.probeAaiGetAllSubscribers()).thenCallRealMethod();
- ExternalComponentStatus result = aaiClientMock.probeAaiGetAllSubscribers();
- assertThat(statusDataReflected(result),is(statusDataReflected(expectedStatus)));
- assertThat(requestMetadataReflected(result.getMetadata()),is(requestMetadataReflected(expectedStatus.getMetadata())));
+ ExternalComponentStatus result = aaiClientMock.probeAaiGetAllSubscribers();
+ assertThat(statusDataReflected(result), is(statusDataReflected(expectedStatus)));
+ assertThat(requestMetadataReflected(result.getMetadata()), is(requestMetadataReflected(expectedStatus.getMetadata())));
}
//serialize fields except of fields we cannot know ahead of time
@@ -159,12 +164,12 @@ public class AaiClientTest {
@DataProvider
public static Object[][] rawData() {
return new Object[][]{
- {"errorMessage", }, {""}, {null}
+ {"errorMessage",}, {""}, {null}
};
}
@Test(dataProvider = "rawData")
- public void testProbeAaiGetFullSubscribersWithNullResponse_returnsNotAvailableWithErrorRawData(String rawData){
+ public void testProbeAaiGetFullSubscribersWithNullResponse_returnsNotAvailableWithErrorRawData(String rawData) {
Mockito.when(aaiClientMock.getAllSubscribers(true)).thenReturn(
new AaiResponseWithRequestInfo<>(HttpMethod.GET, "url", null,
rawData));
@@ -175,7 +180,7 @@ public class AaiClientTest {
@DataProvider
public static Object[][] exceptions() {
- return new Object[][] {
+ return new Object[][]{
{"NullPointerException", "errorMessage",
new ExceptionWithRequestInfo(HttpMethod.GET, "url",
"errorMessage", null, new NullPointerException())},
@@ -188,7 +193,7 @@ public class AaiClientTest {
}
@Test(dataProvider = "exceptions")
- public void testProbeAaiGetFullSubscribersWithNullResponse_returnsNotAvailableWithErrorRawData(String description, String expectedRawData, Exception exception){
+ public void testProbeAaiGetFullSubscribersWithNullResponse_returnsNotAvailableWithErrorRawData(String description, String expectedRawData, Exception exception) {
Mockito.when(aaiClientMock.getAllSubscribers(true)).thenThrow(exception);
ExternalComponentStatus result = callProbeAaiGetAllSubscribersAndAssertNotAvailable();
if (exception instanceof ExceptionWithRequestInfo) {
@@ -200,7 +205,7 @@ public class AaiClientTest {
private ExternalComponentStatus callProbeAaiGetAllSubscribersAndAssertNotAvailable() {
Mockito.when(aaiClientMock.probeAaiGetAllSubscribers()).thenCallRealMethod();
- ExternalComponentStatus result = aaiClientMock.probeAaiGetAllSubscribers();
+ ExternalComponentStatus result = aaiClientMock.probeAaiGetAllSubscribers();
assertFalse(result.isAvailable());
return result;
}
@@ -209,7 +214,7 @@ public class AaiClientTest {
@Test
public void getTenants_Arguments_Are_Null_Or_Empty() {
- when(aaiClientMock.getTenants(any(String.class), any(String.class))).thenCallRealMethod();
+ when(aaiClientMock.getTenants(any(), any())).thenCallRealMethod();
AaiResponse response = aaiClientMock.getTenants("", "");
@@ -227,7 +232,7 @@ public class AaiClientTest {
when(aaiClientMock.getTenants(any(String.class), any(String.class))).thenCallRealMethod();
Response generalEmptyResponse = mock(Response.class);
- when(aaiClientMock.doAaiGet(any(String.class),any(Boolean.class))).thenReturn(generalEmptyResponse);
+ when(aaiClientMock.doAaiGet(any(String.class), any(Boolean.class))).thenReturn(generalEmptyResponse);
AaiResponse response = aaiClientMock.getTenants("subscriberId", "serviceType");
@@ -263,14 +268,14 @@ public class AaiClientTest {
});
- when(aaiClientMock.doAaiGet(any(String.class),any(Boolean.class))).thenReturn(generalEmptyResponse);
+ when(aaiClientMock.doAaiGet(any(String.class), any(Boolean.class))).thenReturn(generalEmptyResponse);
AaiResponse<GetTenantsResponse[]> response = aaiClientMock.getTenants("subscriberId", "serviceType");
- Assert.assertTrue(response.t.length> 0);
+ Assert.assertTrue(response.t.length > 0);
}
- final String tenantResponseRaw ="" +
+ final String tenantResponseRaw = "" +
"{" +
"\"service-type\": \"VIRTUAL USP\"," +
"\"resource-version\": \"1494001841964\"," +
@@ -301,7 +306,7 @@ public class AaiClientTest {
@DataProvider
public static Object[][] resourceTypesProvider() {
- return new Object[][] {
+ return new Object[][]{
{"service-instance", ResourceType.SERVICE_INSTANCE},
{"generic-vnf", ResourceType.GENERIC_VNF},
{"vf-module", ResourceType.VF_MODULE}
@@ -313,9 +318,9 @@ public class AaiClientTest {
String link = "/aai/v12/business/customers/customer/a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb/service-subscriptions/service-subscription/Nimbus/service-instances/service-instance/7131d483-b450-406f-8e30-0c650645fc67";
String json =
"{\"result-data\": [{" +
- "\"resource-type\": \""+resourceType+"\"," +
- "\"resource-link\": \""+ link+ "\"" +
- "}]}";
+ "\"resource-type\": \"" + resourceType + "\"," +
+ "\"resource-link\": \"" + link + "\"" +
+ "}]}";
AaiNodeQueryResponse nodeQueryResponse = new ObjectMapper().readValue(json, AaiNodeQueryResponse.class);
assertThat(nodeQueryResponse.resultData.get(0).resourceLink, equalTo(link));
@@ -323,7 +328,7 @@ public class AaiClientTest {
}
@Test
- public void aaiNodeQueryEmptyResponseDeserializationTest() throws IOException{
+ public void aaiNodeQueryEmptyResponseDeserializationTest() throws IOException {
String json = "{}";
AaiNodeQueryResponse nodeQueryResponse = new ObjectMapper().readValue(json, AaiNodeQueryResponse.class);
assertNull(nodeQueryResponse.resultData);
@@ -331,7 +336,7 @@ public class AaiClientTest {
@DataProvider
public static Object[][] nameAndResourceTypeProvider() {
- return new Object[][] {
+ return new Object[][]{
{"SRIOV_SVC", ResourceType.SERVICE_INSTANCE, "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:SRIOV_SVC"},
{"b1707vidnf", ResourceType.GENERIC_VNF, "search/nodes-query?search-node-type=generic-vnf&filter=vnf-name:EQUALS:b1707vidnf"},
{"connectivity_test", ResourceType.VF_MODULE, "search/nodes-query?search-node-type=vf-module&filter=vf-module-name:EQUALS:connectivity_test"},
@@ -460,6 +465,25 @@ public class AaiClientTest {
assertFalse(propagateExceptions, "calling doAaiGet when propagateExceptions is 'true' must result with an exception (in this test)");
}
+ @Test
+ public void shouldProperlyReadResponseOnceWhenSubscribersAreNotPresent() {
+ AAIRestInterface restInterface = mock(AAIRestInterface.class);
+ PortDetailsTranslator portDetailsTranslator = mock(PortDetailsTranslator.class);
+ Response response = mock(Response.class);
+ when(response.getStatus()).thenReturn(404);
+ when(response.readEntity(String.class)).thenReturn("sampleEntity");
+ when(response.getStatusInfo()).thenReturn(Response.Status.NOT_FOUND);
+ ResponseWithRequestInfo responseWithRequestInfo = new ResponseWithRequestInfo(response, "test", HttpMethod.GET);
+ when(restInterface.RestGet(eq("VidAaiController"), any(String.class),
+ eq("business/customers?subscriber-type=INFRA&depth=0"), eq(false), eq(true))).thenReturn(responseWithRequestInfo);
+ AaiClient aaiClient = new AaiClient(restInterface, portDetailsTranslator);
+
+
+ aaiClient.getAllSubscribers(true);
+
+ verify(response).readEntity(String.class);
+ }
+
@FunctionalInterface
public interface UncheckedBiConsumer<T, U> extends BiConsumer<T, U> {
@Override
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
new file mode 100644
index 000000000..d4f59e7da
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java
@@ -0,0 +1,199 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2018 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.vid.aai;
+
+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 org.assertj.core.api.Assertions;
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.vid.aai.model.AaiNodeQueryResponse;
+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 java.io.IOException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AaiOverTLSClientServerTest {
+
+ @Mock
+ private AaiOverTLSPropertySupplier propertySupplier;
+
+ private static StubServerUtil serverUtil;
+
+ private String searchNodesQueryResponsePayload =
+ "{\n"
+ + "\"result-data\": [\n"
+ + " {\n"
+ + "\"resource-type\": \"generic-vnf\",\n"
+ + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/6eac8e69-c98d-4ac5-ab90-69fe0cabda76\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"resource-type\": \"generic-vnf\",\n"
+ + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/e3766bc5-40a7-4dbe-9d4a-1d8c8f284913\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"resource-type\": \"generic-vnf\",\n"
+ + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/6aa153ee-6637-4b49-beb5-a5e756e00393\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"resource-type\": \"generic-vnf\",\n"
+ + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/5a981c30-de25-4ea9-98fa-ed398f13ea41\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"resource-type\": \"generic-vnf\",\n"
+ + "\"resource-link\": \"/aai/v13/network/generic-vnfs/generic-vnf/b0ef2271-8ac0-4268-b9a5-09cb50c20c85\"\n"
+ + "}\n"
+ + "],\n"
+ + "}";
+
+ private String subscribersResponsePayload =
+ "{\n"
+ + "\"customer\": [\n"
+ + " {\n"
+ + "\"global-customer-id\": \"DemoCust_752df078-d8e9-4731-abf6-8ae7348075bb\",\n"
+ + "\"subscriber-name\": \"DemoCust_752df078-d8e9-4731-abf6-8ae7348075bb\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536158347585\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"global-customer-id\": \"DemoCust_62bf43a3-4888-4c82-ae98-3ebc3d782761\",\n"
+ + "\"subscriber-name\": \"DemoCust_62bf43a3-4888-4c82-ae98-3ebc3d782761\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536240894581\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"global-customer-id\": \"DemoCust_e84256d6-ef3e-4a28-9741-9987019c3a8f\",\n"
+ + "\"subscriber-name\": \"DemoCust_e84256d6-ef3e-4a28-9741-9987019c3a8f\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536330956393\"\n"
+ + "},\n"
+ + " {\n"
+ + "\"global-customer-id\": \"ETE_Customer_377bb124-2638-4025-a315-cdae04f52bce\",\n"
+ + "\"subscriber-name\": \"ETE_Customer_377bb124-2638-4025-a315-cdae04f52bce\",\n"
+ + "\"subscriber-type\": \"INFRA\",\n"
+ + "\"resource-version\": \"1536088625538\"\n"
+ + "}\n"
+ + "],\n"
+ + "}";
+
+ @BeforeClass
+ public static void setUpClass(){
+ serverUtil = new StubServerUtil();
+ serverUtil.runServer();
+ }
+
+ @AfterClass
+ public static void tearDown(){
+ serverUtil.stopServer();
+ }
+
+ @Test
+ public void shouldSearchNodeTypeByName() throws IOException, ParseException {
+ ObjectMapper objectMapper = getFasterXmlObjectMapper();
+ AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", ""));
+
+ serverUtil.prepareGetCall("/search/nodes-query", new JSONParser().parse(searchNodesQueryResponsePayload), Action.status(HttpStatus.OK_200));
+
+ HttpResponse<AaiNodeQueryResponse> aaiNodeQueryResponseHttpResponse = aaiOverTLSClient
+ .searchNodeTypeByName("any", ResourceType.GENERIC_VNF);
+
+ AaiNodeQueryResponse body = aaiNodeQueryResponseHttpResponse.getBody();
+ Assertions.assertThat(body.resultData.size()).isEqualTo(5);
+ Assertions.assertThat(aaiNodeQueryResponseHttpResponse.getStatus()).isEqualTo(200);
+ }
+
+ @Test
+ public void shouldGetSubscribers() throws ParseException, JsonProcessingException {
+ ObjectMapper objectMapper = getCodehausObjectMapper();
+ AaiOverTLSClient aaiOverTLSClient = new AaiOverTLSClient(new SyncRestClient(objectMapper), propertySupplier, serverUtil.constructTargetUrl("http", ""));
+
+ serverUtil.prepareGetCall("/business/customers", new JSONParser().parse(subscribersResponsePayload), Action.status(HttpStatus.OK_200));
+
+ HttpResponse<SubscriberList> allSubscribers = aaiOverTLSClient.getAllSubscribers();
+
+ SubscriberList subscriberList = allSubscribers.getBody();
+ Assertions.assertThat(subscriberList.customer.size()).isEqualTo(4);
+ Assertions.assertThat(allSubscribers.getStatus()).isEqualTo(200);
+ }
+
+ private ObjectMapper getCodehausObjectMapper() {
+ return new ObjectMapper() {
+
+ org.codehaus.jackson.map.ObjectMapper om = new org.codehaus.jackson.map.ObjectMapper();
+
+ @Override
+ public <T> T readValue(String s, Class<T> aClass) {
+ try {
+ return om.readValue(s, aClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String writeValue(Object o) {
+ try {
+ return om.writeValueAsString(o);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ }
+
+ private ObjectMapper getFasterXmlObjectMapper() {
+ return new ObjectMapper() {
+
+ com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
+
+ @Override
+ public <T> T readValue(String s, Class<T> aClass) {
+ try {
+ return om.readValue(s, aClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String writeValue(Object o) {
+ try {
+ return om.writeValueAsString(o);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ }
+
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java
new file mode 100644
index 000000000..f281e84b6
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2018 Nokia Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.vid.aai;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.vid.aai.model.AaiNodeQueryResponse;
+import org.onap.vid.aai.model.ResourceType;
+import org.onap.vid.client.SyncRestClient;
+import org.onap.vid.model.SubscriberList;
+
+import java.util.Collections;
+import java.util.Map;
+
+import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.ArgumentMatchers.eq;
+
+@RunWith(MockitoJUnitRunner.class)
+public class AaiOverTLSClientTest {
+
+ private static final String SEARCH_NODES_QUERY_SEARCH_NODE_TYPE = "search/nodes-query?search-node-type=generic-vnf&filter=vnf-name:EQUALS:name";
+ private static final String SUBSCRIBERS = "business/customers?subscriber-type=INFRA&depth=0";
+ private AaiOverTLSClient aaiRestClient;
+
+ @Mock
+ private SyncRestClient syncRestClient;
+ @Mock
+ private AaiOverTLSPropertySupplier propertySupplier;
+
+ @Before
+ public void setUp() {
+ aaiRestClient = new AaiOverTLSClient(syncRestClient, propertySupplier);
+ }
+
+ @Test
+ public void testSearchNodeTypeByName() {
+ mockPropertyReader();
+
+ aaiRestClient.searchNodeTypeByName("name", ResourceType.GENERIC_VNF);
+ Mockito.verify(syncRestClient).get(contains(SEARCH_NODES_QUERY_SEARCH_NODE_TYPE),
+ eq(getHeaders()), eq(Collections.emptyMap()), eq(AaiNodeQueryResponse.class));
+ }
+
+ @Test
+ public void testGetAllSubscribers(){
+ mockPropertyReader();
+
+ aaiRestClient.getAllSubscribers();
+ Mockito.verify(syncRestClient).get(contains(SUBSCRIBERS),
+ eq(getHeaders()), eq(Collections.emptyMap()), eq(SubscriberList.class));
+ }
+
+ private void mockPropertyReader() {
+ Mockito.when(propertySupplier.getPassword()).thenReturn("Pass");
+ Mockito.when(propertySupplier.getUsername()).thenReturn("User");
+ Mockito.when(propertySupplier.getRequestId()).thenReturn("1");
+ Mockito.when(propertySupplier.getRandomUUID()).thenReturn("2");
+ }
+
+ private Map<String,String> getHeaders(){
+ return ImmutableMap.<String, String>builder().put("Authorization", "Basic VXNlcjpQYXNz").
+ put("X-FromAppId", "VidAaiController").put("Accept", "application/json").put("X-ECOMP-RequestID", "1").
+ put("X-TransactionId", "2").put("Content-Type", "application/json").build();
+ }
+
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java
index f000dc801..ce957ab67 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java
@@ -21,21 +21,11 @@
package org.onap.vid.aai.util;
-import org.junit.Before;
-import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.onap.vid.aai.exceptions.HttpClientBuilderException;
+import org.mockito.junit.MockitoJUnitRunner;
import javax.net.ssl.SSLContext;
-import java.util.Optional;
-
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class HttpsAuthClientTest {
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 cd2b8ff28..7fad9019c 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
@@ -25,7 +25,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.onap.vid.aai.exceptions.InvalidPropertyException;
import org.testng.Assert;
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java
index 1282a6f78..e1c5e923b 100644
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java
+++ b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java
@@ -15,8 +15,8 @@ import org.onap.sdc.toscaparser.api.NodeTemplate;
import org.onap.vid.asdc.AsdcCatalogException;
import org.onap.vid.asdc.AsdcClient;
import org.onap.vid.asdc.local.LocalAsdcClient;
-import org.onap.vid.model.*;
import org.onap.vid.controllers.ToscaParserMockHelper;
+import org.onap.vid.model.*;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -196,6 +196,28 @@ public class ToscaParserImpl2Test {
JsonAssert.assertJsonEquals(expectedConfigurations, actualConfigurations);
}
+ @Test
+ public void modelWithAnnotatedInputWithTwoProperties_vfModuleGetsTheInput() throws Exception {
+ final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper("90fe6842-aa76-4b68-8329-5c86ff564407", "empty.json");
+ final ServiceModel serviceModel = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid()));
+
+ assertJsonStringEqualsIgnoreNulls("{ vfModules: { 201712488_adiodvpe10..201712488AdiodVpe1..ADIOD_vRE_BV..module-1: { inputs: { 201712488_adiodvpe10_availability_zone_0: { } } } } }", om.writeValueAsString(serviceModel));
+ }
+
+ @Test
+ public void modelWithNfNamingWithToValues_ecompGeneratedNamingIsExtracted() throws Exception {
+ final ToscaParserMockHelper mockHelper = new ToscaParserMockHelper("90fe6842-aa76-4b68-8329-5c86ff564407", "empty.json");
+ final ServiceModel serviceModel = toscaParserImpl2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid()));
+
+ assertJsonStringEqualsIgnoreNulls("" +
+ "{ vnfs: " +
+ " { \"201712-488_ADIOD-vPE-1 0\": " +
+ " { properties: { " +
+ " ecomp_generated_naming: \"true\", " +
+ " nf_naming: \"{naming_policy=SDNC_Policy.Config_MS_1806SRIOV_VPE_ADIoDJson, ecomp_generated_naming=true}\" " +
+ "} } } }", om.writeValueAsString(serviceModel));
+ }
+
private void setPprobeServiceProxy(Map<String, PortMirroringConfig> expectedConfigurations){
//Port Mirroring Configuration By Policy 0 doesn't contains pProbe.
// But due to sdc design if pProbe not exists parser expects to get it from other source.
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java
index c1d6ab78a..642569c73 100644
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/asdc/rest/SdcRestClientTest.java
@@ -25,7 +25,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.onap.vid.asdc.AsdcCatalogException;
import org.onap.vid.asdc.beans.Service;
import org.onap.vid.client.SyncRestClient;
@@ -37,9 +37,7 @@ import java.util.UUID;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyMapOf;
-import static org.mockito.Matchers.matches;
+import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -82,7 +80,7 @@ public class SdcRestClientTest {
@Test
public void shouldReturnServiceForGivenUUID() throws AsdcCatalogException {
String url = String.format(METADATA_URL_REGEX, randomId);
- when(mockedSyncRestClient.get(matches(url), anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), any())).thenReturn(httpResponse);
+ when(mockedSyncRestClient.get(matches(url), anyMap(), anyMap(), any())).thenReturn(httpResponse);
when(httpResponse.getBody()).thenReturn(sampleService);
Service service = restClient.getService(randomId);
@@ -94,7 +92,7 @@ public class SdcRestClientTest {
@Test(expected = AsdcCatalogException.class)
public void shouldRaiseAsdcExceptionWhenClientFails() throws AsdcCatalogException {
String url = String.format(METADATA_URL_REGEX, randomId);
- when(mockedSyncRestClient.get(matches(url), anyMapOf(String.class, String.class), anyMapOf(String.class, String.class), any())).thenThrow(new RuntimeException());
+ when(mockedSyncRestClient.get(matches(url), anyMap(), anyMap(), any())).thenThrow(new RuntimeException());
restClient.getService(randomId);
}
@@ -119,7 +117,7 @@ public class SdcRestClientTest {
@Test(expected = AsdcCatalogException.class)
public void shouldRaiseAsdcExceptionWhenDownloadFails() throws AsdcCatalogException {
String url = String.format(MODEL_URL_REGEX, randomId);
- when(mockedSyncRestClient.getStream(matches(url), anyMapOf(String.class, String.class), anyMapOf(String.class, String.class))).thenThrow(new RuntimeException());
+ when(mockedSyncRestClient.getStream(matches(url), anyMap(), anyMap())).thenThrow(new RuntimeException());
restClient.getServiceToscaModel(randomId);
diff --git a/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java b/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
index 56ac28d2e..c1ac6a219 100644
--- a/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
+++ b/vid-app-common/src/test/java/org/onap/vid/config/JobCommandsConfigWithMockedMso.java
@@ -21,13 +21,19 @@
package org.onap.vid.config;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
import org.hibernate.SessionFactory;
import org.mockito.Mockito;
import org.onap.portalsdk.core.service.DataAccessService;
-import org.onap.vid.aai.AaiClientInterface;
+import org.onap.vid.aai.AaiOverTLSClient;
+import org.onap.vid.aai.AaiOverTLSClientInterface;
+import org.onap.vid.aai.AaiOverTLSPropertySupplier;
import org.onap.vid.aai.util.HttpsAuthClient;
import org.onap.vid.aai.util.SSLContextProvider;
import org.onap.vid.aai.util.SystemPropertyHelper;
+import org.onap.vid.client.SyncRestClient;
import org.onap.vid.job.JobAdapter;
import org.onap.vid.job.JobsBrokerService;
import org.onap.vid.job.command.InProgressStatusCommand;
@@ -84,12 +90,40 @@ public class JobCommandsConfigWithMockedMso {
}
@Bean
+ public AaiOverTLSClientInterface AaiOverTLSClient(){
+ io.joshworks.restclient.http.mapper.ObjectMapper objectMapper = new io.joshworks.restclient.http.mapper.ObjectMapper() {
+
+ ObjectMapper om = new ObjectMapper();
+
+ @Override
+ public <T> T readValue(String s, Class<T> aClass) {
+ try {
+ return om.readValue(s, aClass);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public String writeValue(Object o) {
+ try {
+ return om.writeValueAsString(o);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+
+ return new AaiOverTLSClient(new SyncRestClient(objectMapper), new AaiOverTLSPropertySupplier());
+ }
+
+ @Bean
public AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic(DataAccessService dataAccessService,
JobAdapter jobAdapter,
JobsBrokerService jobsBrokerService,
SessionFactory sessionFactory,
- AaiClientInterface aaiClient) {
- return new AsyncInstantiationBusinessLogicImpl(dataAccessService, jobAdapter, jobsBrokerService, sessionFactory, aaiClient);
+ AaiOverTLSClientInterface aaiOverTLSClientInterface) {
+ return new AsyncInstantiationBusinessLogicImpl(dataAccessService, jobAdapter, jobsBrokerService, sessionFactory, aaiOverTLSClientInterface);
}
@Bean
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/ClientCredentialsFilterTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/ClientCredentialsFilterTest.java
index 61f18f54a..113bf2bf9 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/ClientCredentialsFilterTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/ClientCredentialsFilterTest.java
@@ -13,7 +13,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
/**
@@ -71,7 +71,7 @@ public class ClientCredentialsFilterTest {
FilterChain chain = Mockito.mock(FilterChain.class);
- Mockito.when(filter.verifyClientCredentials(any(String.class),any(String.class))).thenReturn(clientVerified);
+ Mockito.when(filter.verifyClientCredentials(any(),any())).thenReturn(clientVerified);
Mockito.doNothing().when(response).sendError(401);
Mockito.doCallRealMethod().when(filter).doFilter(request,response,chain);
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/PromiseEcompRequestIdFilterTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/PromiseEcompRequestIdFilterTest.java
index 3bcb2d005..4f42171b5 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/PromiseEcompRequestIdFilterTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/PromiseEcompRequestIdFilterTest.java
@@ -19,11 +19,12 @@ import java.io.IOException;
import java.util.*;
import java.util.function.Function;
+import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.onap.portalsdk.core.util.SystemProperties.ECOMP_REQUEST_ID;
@Test
@@ -130,8 +131,8 @@ public class PromiseEcompRequestIdFilterTest {
private HttpServletRequest createMockedHttpServletRequest(Map<String, String> requestHeaders) {
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
requestHeaders.forEach((k, v) -> {
- Mockito.when(servletRequest.getHeader(argThat(equalToIgnoringCase(k)))).thenReturn(v);
- Mockito.when(servletRequest.getHeaders(argThat(equalToIgnoringCase(k)))).then(returnEnumerationAnswer(v));
+ Mockito.when(servletRequest.getHeader(argThat(s -> equalsIgnoreCase(s, k)))).thenReturn(v);
+ Mockito.when(servletRequest.getHeaders(argThat(s -> equalsIgnoreCase(s, k)))).then(returnEnumerationAnswer(v));
});
Mockito.when(servletRequest.getHeaderNames()).then(returnEnumerationAnswer(requestHeaders.keySet()));
return servletRequest;
diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/ChangeManagementControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/ChangeManagementControllerTest.java
index 317bd978c..58406a662 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controllers/ChangeManagementControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controllers/ChangeManagementControllerTest.java
@@ -1,23 +1,19 @@
package org.onap.vid.controllers;
-import java.util.Collection;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.codehaus.jackson.map.ObjectMapper;
import org.json.simple.JSONArray;
import org.junit.Test;
import org.onap.vid.changeManagement.ChangeManagementRequest;
import org.onap.vid.changeManagement.GetVnfWorkflowRelationRequest;
import org.onap.vid.changeManagement.VnfWorkflowRelationRequest;
import org.onap.vid.mso.MsoResponseWrapperInterface;
-import org.onap.vid.services.ChangeManagementService;
import org.onap.vid.services.ChangeManagementServiceImpl;
-import org.onap.vid.services.WorkflowService;
import org.onap.vid.services.WorkflowServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Collection;
+
public class ChangeManagementControllerTest {
private ChangeManagementController createTestSubject() {
diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/HealthCheckControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/HealthCheckControllerTest.java
index 6055bc390..4894f35ea 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controllers/HealthCheckControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controllers/HealthCheckControllerTest.java
@@ -3,65 +3,99 @@ package org.onap.vid.controllers;
import org.apache.log4j.BasicConfigurator;
import org.junit.Before;
import org.junit.Test;
-import org.onap.vid.controllers.HealthCheckController.HealthStatus;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.vid.dao.FnAppDoaImpl;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import java.sql.SQLException;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.BDDMockito.given;
+import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
+import static org.springframework.http.HttpStatus.OK;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-
+@RunWith(MockitoJUnitRunner.class)
public class HealthCheckControllerTest {
- private HealthCheckController testSubject;
- private MockMvc mockMvc;
+ private static final String ERROR_MESSAGE = "error message";
+ private HealthCheckController testSubject;
+ private MockMvc mockMvc;
+
+ @Mock
+ private FnAppDoaImpl fnAppDoa;
- @Before
- public void setUp() {
- testSubject = new HealthCheckController();
- BasicConfigurator.configure();
- mockMvc = MockMvcBuilders.standaloneSetup(testSubject).build();
- }
+ @Before
+ public void setUp() {
+ testSubject = new HealthCheckController(fnAppDoa);
+ BasicConfigurator.configure();
+ mockMvc = MockMvcBuilders.standaloneSetup(testSubject).build();
+ }
- @Test
- public void testGetProfileCount() throws Exception {
- String driver = "";
- String URL = "";
- String username = "";
- String password = "";
- int result;
+ @Test
+ public void getHealthCheckStatusForIDNS_shouldReturnSuccess_whenNoExceptionIsThrown() throws Exception {
+ databaseConnectionEstablished();
+ mockMvc.perform(get("/healthCheck")
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.statusCode").value(OK.value()))
+ .andExpect(jsonPath("$.detailedMsg").value("health check succeeded"));
+ }
- // default test
- result = testSubject.getProfileCount(driver, URL, username, password);
- }
+ @Test
+ public void getHealthCheckStatusForIDNS_shouldReturnErrorCode_whenExceptionIsThrown() throws Exception {
+ databaseNotAccessible();
+ mockMvc.perform(get("/healthCheck")
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.statusCode").value(INTERNAL_SERVER_ERROR.value()))
+ .andExpect(jsonPath("$.detailedMsg").value("health check failed: " + ERROR_MESSAGE));
+ }
- @Test
- public void testGethealthCheckStatusforIDNS() throws Exception {
- HealthStatus result;
+ @Test
+ public void getHealthCheck_shouldReturnSuccess_whenNoExceptionIsThrown() throws Exception {
+ databaseConnectionEstablished();
+ mockMvc.perform(get("/rest/healthCheck/{User-Agent}/{X-ECOMP-RequestID}", "userAgent", "requestId")
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.statusCode").value(OK.value()))
+ .andExpect(jsonPath("$.detailedMsg").value("health check succeeded"))
+ .andExpect(jsonPath("$.date").isString());
+ }
- // default test
- result = testSubject.gethealthCheckStatusforIDNS();
- }
+ @Test
+ public void getHealthCheck_shouldReturnErrorCode_whenExceptionIsThrown() throws Exception {
+ databaseNotAccessible();
+ mockMvc.perform(get("/rest/healthCheck/{User-Agent}/{X-ECOMP-RequestID}", "userAgent", "requestId")
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.statusCode").value(INTERNAL_SERVER_ERROR.value()))
+ .andExpect(jsonPath("$.detailedMsg").value("health check failed: " + ERROR_MESSAGE));
+ }
- @Test
- public void testGetHealthCheck() throws Exception {
- String UserAgent = "";
- String ECOMPRequestID = "";
- HealthStatus result;
+ @Test
+ public void getCommitInfo_shouldReturnCommitData_whenCorrectPropertiesFileExists() throws Exception {
+ mockMvc.perform(get("/commitInfo")
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath("$.commitId").value("123"))
+ .andExpect(jsonPath("$.commitMessageShort").value("Test short commit message"))
+ .andExpect(jsonPath("$.commitTime").value("1999-09-12T13:48:55+0200"));
+ }
- // default test
- result = testSubject.getHealthCheck(UserAgent, ECOMPRequestID);
- }
+ private void databaseConnectionEstablished() throws SQLException {
+ given(fnAppDoa.getProfileCount(anyString(), anyString(), anyString()))
+ .willReturn(0);
+ }
- @Test
- public void testCommitInfoEndpoint() throws Exception {
- mockMvc.perform(get("/commitInfo")
- .accept(MediaType.APPLICATION_JSON))
- .andExpect(status().isOk())
- .andExpect(jsonPath("$.commitId").value("123987"))
- .andExpect(jsonPath("$.commitMessageShort").value("Test short commit message"))
- .andExpect(jsonPath("$.commitTime").value("1999-09-12T13:48:55+0200"));
- }
+ private void databaseNotAccessible() throws SQLException {
+ given(fnAppDoa.getProfileCount(anyString(), anyString(), anyString()))
+ .willThrow(new SQLException(ERROR_MESSAGE));
+ }
} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/MaintenanceControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/MaintenanceControllerTest.java
index 7bdd6b863..3a9d88f07 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controllers/MaintenanceControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controllers/MaintenanceControllerTest.java
@@ -22,22 +22,8 @@ package org.onap.vid.controllers;
* ============LICENSE_END=========================================================
*/
-import static org.mockito.BDDMockito.given;
-import static org.mockito.BDDMockito.then;
-import static org.mockito.BDDMockito.willThrow;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.times;
-import static org.onap.vid.model.CategoryParameter.Family.PARAMETER_STANDARDIZATION;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import java.util.Collections;
-import java.util.function.BiFunction;
-import javax.ws.rs.ForbiddenException;
import org.apache.log4j.BasicConfigurator;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Before;
@@ -45,7 +31,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.onap.vid.category.AddCategoryOptionResponse;
import org.onap.vid.category.AddCategoryOptionsRequest;
import org.onap.vid.category.CategoryParameterOptionRep;
@@ -61,6 +47,19 @@ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilde
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import javax.ws.rs.ForbiddenException;
+import java.util.Collections;
+import java.util.function.BiFunction;
+
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.BDDMockito.*;
+import static org.mockito.Mockito.times;
+import static org.onap.vid.model.CategoryParameter.Family.PARAMETER_STANDARDIZATION;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
@RunWith(MockitoJUnitRunner.class)
public class MaintenanceControllerTest {
diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/PromiseEcompRequestIdFilterTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/PromiseEcompRequestIdFilterTest.java
index 77dba37e9..f17403955 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controllers/PromiseEcompRequestIdFilterTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controllers/PromiseEcompRequestIdFilterTest.java
@@ -19,11 +19,12 @@ import java.io.IOException;
import java.util.*;
import java.util.function.Function;
+import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.onap.portalsdk.core.util.SystemProperties.ECOMP_REQUEST_ID;
@Test
@@ -130,8 +131,8 @@ public class PromiseEcompRequestIdFilterTest {
private HttpServletRequest createMockedHttpServletRequest(Map<String, String> requestHeaders) {
HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class);
requestHeaders.forEach((k, v) -> {
- Mockito.when(servletRequest.getHeader(argThat(equalToIgnoringCase(k)))).thenReturn(v);
- Mockito.when(servletRequest.getHeaders(argThat(equalToIgnoringCase(k)))).then(returnEnumerationAnswer(v));
+ Mockito.when(servletRequest.getHeader(argThat(s -> equalsIgnoreCase(s, k)))).thenReturn(v);
+ Mockito.when(servletRequest.getHeaders(argThat(s -> equalsIgnoreCase(s, k)))).then(returnEnumerationAnswer(v));
});
Mockito.when(servletRequest.getHeaderNames()).then(returnEnumerationAnswer(requestHeaders.keySet()));
return servletRequest;
diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/VidControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/VidControllerTest.java
index 4e2d994e6..198680afc 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controllers/VidControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controllers/VidControllerTest.java
@@ -1,189 +1,204 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Modifications Copyright 2018 Nokia
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.vid.controllers;
-//import com.fasterxml.jackson.databind.ObjectMapper;
-//import net.javacrumbs.jsonunit.JsonAssert;
-//import org.apache.commons.io.IOUtils;
-//import org.onap.vid.asdc.AsdcCatalogException;
-//import org.onap.vid.asdc.AsdcClient;
-//import org.onap.vid.asdc.parser.ToscaParserImpl2;
-//import org.onap.vid.model.*;
-//import org.onap.portalsdk.core.util.SystemProperties;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.mock.web.MockServletContext;
-//import org.springframework.test.context.ContextConfiguration;
-//import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
-//import org.springframework.test.context.web.WebAppConfiguration;
-//import org.testng.Assert;
-//import org.testng.annotations.Test;
-//
-//import static org.onap.vid.testUtils.TestUtils.assertJsonStringEqualsIgnoreNulls;
-//
-//import java.io.IOException;
-//import java.io.InputStream;
-//import java.nio.file.Path;
-//import java.util.Map;
-//import java.util.UUID;
-//
-////import org.junit.Assert;
-////import org.junit.Ignore;
-////import org.junit.Test;
-////import org.junit.runner.RunWith;
-////import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-//
-//@ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
-////@RunWith(SpringJUnit4ClassRunner.class)
-//@WebAppConfiguration
-//
-//public class VidControllerTest extends AbstractTestNGSpringContextTests {
-//
-// @Autowired
-// MockServletContext context;
-// @Autowired
-// private AsdcClient asdcClient;
-// private ToscaParserImpl2 p2 = new ToscaParserImpl2();
-// private ObjectMapper om = new ObjectMapper();
-//
-//
-// @Test
-// public void assertEqualsBetweenServices() throws Exception {
-// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
-// Service expectedService = mockHelper.getNewServiceModel().getService();
-// Service actualService = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getService();
-// assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedService), om.writeValueAsString(actualService));
-// }
-// }
-//
-//// @Test
-//// public void assertEqualBetweenObjects() throws Exception {
-//// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
-//// final Path csarPath = getCsarPath(mockHelper.getUuid());
-//// System.out.println("Comparing for csar " + csarPath);
-//// ServiceModel actualServiceModel = p2.makeServiceModel(csarPath, getServiceByUuid(mockHelper.getUuid()));
-//// assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(mockHelper.getNewServiceModel()), om.writeValueAsString(actualServiceModel));
-//// }
-//// }
-//
-//// @Test
-//// public void assertEqualsBetweenNetworkNodes() throws Exception {
-//// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
-//// Map<String, Network> expectedNetworksMap = mockHelper.getNewServiceModel().getNetworks();
-//// Map<String, Network> actualNetworksMap = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getNetworks();
-//// for (Map.Entry<String, Network> entry : expectedNetworksMap.entrySet()) {
-//// Network expectedNetwork = entry.getValue();
-//// Network actualNetwork = actualNetworksMap.get(entry.getKey());
-//// Assert.assertEquals(expectedNetwork.getModelCustomizationName(), actualNetwork.getModelCustomizationName());
-//// verifyBaseNodeProperties(expectedNetwork, actualNetwork);
-//// compareProperties(expectedNetwork.getProperties(), actualNetwork.getProperties());
-//// }
-//// }
-//// }
-//
-// //Because we are not supporting the old flow, the JSON are different by definition.
-// @Test
-// public void assertEqualsBetweenVnfsOfTosca() throws Exception {
-// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
-// Map<String, VNF> expectedVnfsMap = mockHelper.getNewServiceModel().getVnfs();
-// Map<String, VNF> actualVnfsMap = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVnfs();
-// for (Map.Entry<String, VNF> entry : expectedVnfsMap.entrySet()) {
-// VNF expectedVnf = entry.getValue();
-// VNF actualVnf = actualVnfsMap.get(entry.getKey());
-// //need to uncomment these after 1806 merge
-// //verifyBaseNodeProperties(expectedVnf, actualVnf);
-// Assert.assertEquals(expectedVnf.getModelCustomizationName(), actualVnf.getModelCustomizationName());
-// //compareProperties(expectedVnf.getProperties(), actualVnf.getProperties());
-// //assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedVnf), om.writeValueAsString(actualVnf));
-// }
-// }
-// }
-//
-// @Test
-// public void assertEqualsBetweenVolumeGroups() throws Exception {
-// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
-// Map<String, VolumeGroup> actualVolumeGroups = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVolumeGroups();
-// Map<String, VolumeGroup> expectedVolumeGroups = mockHelper.getNewServiceModel().getVolumeGroups();
-// JsonAssert.assertJsonEquals(actualVolumeGroups, expectedVolumeGroups);
-// }
-// }
-//
-// @Test
-// public void assertEqualsBetweenVfModules() throws Exception {
-// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
-// Map<String, VfModule> actualVfModules = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getVfModules();
-// Map<String, VfModule> expectedVfModules = mockHelper.getNewServiceModel().getVfModules();
-// //need to uncomment after 1906 merge
-// //JsonAssert.assertJsonEquals(actualVfModules, expectedVfModules);
-// }
-// }
-//
-// /*@Test
-// public void assertEqualsBetweenPolicyConfigurationNodes() throws Exception {
-// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
-// Map<String, PortMirroringConfig> actualConfigurations = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getConfigurations();
-// Map<String, PortMirroringConfig> expectedConfigurations = mockHelper.getNewServiceModel().getConfigurations();
-// JsonAssert.assertJsonEquals(actualConfigurations, expectedConfigurations);
-// }
-// }*/
-//
-// @Test
-// public void assertEqualsBetweenServiceProxyNodes() throws Exception {
-// for (ToscaParserMockHelper mockHelper : getExpectedServiceModel()) {
-// Map<String, ServiceProxy> actualServiceProxies = p2.makeServiceModel(getCsarPath(mockHelper.getUuid()), getServiceByUuid(mockHelper.getUuid())).getServiceProxies();
-// Map<String, ServiceProxy> expectedServiceProxies = mockHelper.getNewServiceModel().getServiceProxies();
-// JsonAssert.assertJsonEquals(actualServiceProxies, expectedServiceProxies);
-// }
-// }
-//
-// private void verifyBaseNodeProperties(Node expectedNode, Node actualNode) {
-// Assert.assertEquals(expectedNode.getName(), actualNode.getName());
-// Assert.assertEquals(expectedNode.getCustomizationUuid(), actualNode.getCustomizationUuid());
-// Assert.assertEquals(expectedNode.getDescription(), actualNode.getDescription());
-// Assert.assertEquals(expectedNode.getInvariantUuid(), actualNode.getInvariantUuid());
-// Assert.assertEquals(expectedNode.getUuid(), actualNode.getUuid());
-// Assert.assertEquals(expectedNode.getVersion(), actualNode.getVersion());
-// }
-//
-// private void compareProperties(Map<String, String> expectedProperties, Map<String, String> actualProperties) {
-// for (Map.Entry<String, String> property : expectedProperties.entrySet()) {
-// String expectedValue = property.getValue();
-// String key = property.getKey();
-// String actualValue = actualProperties.get(key);
-// Assert.assertEquals(expectedValue, actualValue);
-// }
-// }
-//
-// private ToscaParserMockHelper[] getExpectedServiceModel() throws IOException {
-// ToscaParserMockHelper[] mockHelpers = {
-// new ToscaParserMockHelper(Constants.vlUuid, Constants.vlFilePath),
-// new ToscaParserMockHelper(Constants.vfUuid, Constants.vfFilePath),
-// new ToscaParserMockHelper(Constants.configurationUuid, Constants.configurationFilePath),
-// };
-// for (ToscaParserMockHelper mockHelper : mockHelpers) {
-// InputStream jsonFile = VidControllerTest.class.getClassLoader().getResourceAsStream(mockHelper.getFilePath());
-// String expectedJsonAsString = IOUtils.toString(jsonFile);
-// NewServiceModel newServiceModel1 = om.readValue(expectedJsonAsString, NewServiceModel.class);
-// mockHelper.setNewServiceModel(newServiceModel1);
-// }
-// return mockHelpers;
-// }
-//
-// private Path getCsarPath(String uuid) throws AsdcCatalogException {
-// return asdcClient.getServiceToscaModel(UUID.fromString(uuid));
-// }
-//
-// private org.onap.vid.asdc.beans.Service getServiceByUuid(String uuid) throws AsdcCatalogException {
-// return asdcClient.getService(UUID.fromString(uuid));
-// }
-//
-// public class Constants {
-// public static final String configurationUuid = "ee6d61be-4841-4f98-8f23-5de9da846ca7";
-// public static final String configurationFilePath = "policy-configuration-csar.JSON";
-// static final String vfUuid = "48a52540-8772-4368-9cdb-1f124ea5c931";
-// static final String vlUuid = "cb49608f-5a24-4789-b0f7-2595473cb997";
-// // public static final String PNFUuid = "68101369-6f08-4e99-9a28-fa6327d344f3";
-// static final String vfFilePath = "vf-csar.JSON";
-// static final String vlFilePath = "vl-csar.JSON";
-//// public static final String PNFFilePath = "/Users/Oren/Git/Att/vid_internal/vid-app-common/src/main/resources/pnf.csar";
-//
-// }
-//
-//} \ No newline at end of file
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.apache.log4j.BasicConfigurator;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.vid.asdc.AsdcCatalogException;
+import org.onap.vid.asdc.beans.SecureServices;
+import org.onap.vid.asdc.beans.Service;
+import org.onap.vid.asdc.beans.ServiceBuilder;
+import org.onap.vid.model.*;
+import org.onap.vid.model.PombaInstance.PombaRequest;
+import org.onap.vid.model.PombaInstance.ServiceInstance;
+import org.onap.vid.roles.RoleProvider;
+import org.onap.vid.services.AaiService;
+import org.onap.vid.services.PombaService;
+import org.onap.vid.services.VidService;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+import javax.ws.rs.core.MediaType;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.IntStream;
+
+import static java.util.stream.Collectors.toMap;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.Matchers.not;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.then;
+import static org.mockito.Mockito.times;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+@RunWith(MockitoJUnitRunner.class)
+public class VidControllerTest {
+
+ public static final String REST_MODELS_SERVICES = "/rest/models/services";
+ public static final String REST_MODELS_SERVICES_UUID = "/rest/models/services/{uuid}";
+ public static final String REST_MODELS_RESET = "/rest/models/reset";
+ public static final String REST_MODELS_SERVICES_VERIFY_SERVICE = "/rest/models/services/verifyService";
+ @Mock
+ private VidService vidService;
+ @Mock
+ private AaiService aaiService;
+ @Mock
+ private RoleProvider roleProvider;
+ @Mock
+ private PombaService pombaService;
+
+ private VidController vidController;
+ private MockMvc mockMvc;
+ private ObjectMapper objectMapper;
+
+ private String uuid1;
+ private String uuid2;
+ private String uuid3;
+
+ @Before
+ public void setUp() {
+ vidController = new VidController(vidService, aaiService, roleProvider, pombaService);
+ BasicConfigurator.configure();
+ mockMvc = MockMvcBuilders.standaloneSetup(vidController).build();
+ objectMapper = new ObjectMapper();
+
+ uuid1 = UUID.randomUUID().toString();
+ uuid2 = UUID.randomUUID().toString();
+ uuid3 = UUID.randomUUID().toString();
+ }
+
+ @Test
+ public void getServices_shouldReturnService_whenServiceExists() throws Exception {
+ List<Service> services = ImmutableList.of(createService(uuid1, 1), createService(uuid2, 2), createService(uuid3, 3));
+
+ given(aaiService.getServicesByDistributionStatus()).willReturn(services);
+
+ SecureServices secureServices = new SecureServices();
+ secureServices.setServices(services);
+ secureServices.setReadOnly(false);
+
+ mockMvc.perform(get(REST_MODELS_SERVICES)
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(secureServices)));
+ }
+
+ @Test
+ public void getService_shouldReturnService_whenNoExceptionIsThrown() throws Exception {
+ ServiceModel model = expectedServiceModel(uuid1);
+
+ given(vidService.getService(uuid1)).willReturn(model);
+
+ mockMvc.perform(get(REST_MODELS_SERVICES_UUID, uuid1)
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(objectMapper.writeValueAsString(model)));
+ }
+
+ @Test
+ public void getService_shouldThrow_whenAsdcCatalogExceptionIsThrown() throws Exception {
+ String testUuid = UUID.randomUUID().toString();
+
+ given(vidService.getService(testUuid)).willThrow(new AsdcCatalogException("error msg"));
+
+ mockMvc.perform(get(REST_MODELS_SERVICES_UUID, testUuid)
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isServiceUnavailable());
+ }
+
+ @Test
+ public void invalidateServiceModelCache_shouldReturnAccepted() throws Exception {
+ mockMvc.perform(post(REST_MODELS_RESET)
+ .contentType(MediaType.APPLICATION_JSON))
+ .andExpect(status().isAccepted());
+
+ then(vidService).should(times(1)).invalidateServiceCache();
+ }
+
+ @Test
+ public void verifyServiceInstance_shouldReturnOk() throws Exception {
+ PombaRequest pombaRequest = new PombaRequest();
+ pombaRequest.serviceInstanceList = ImmutableList.of(new ServiceInstance());
+
+ mockMvc.perform(post(REST_MODELS_SERVICES_VERIFY_SERVICE)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(pombaRequest)))
+ .andExpect(status().isOk());
+
+ ArgumentCaptor<PombaRequest> argumentCaptor = ArgumentCaptor.forClass(PombaRequest.class);
+ then(pombaService).should(times(1)).verify(argumentCaptor.capture());
+
+ assertThat(pombaRequest).isEqualToComparingFieldByFieldRecursively(argumentCaptor.getValue());
+ }
+
+ private ServiceModel expectedServiceModel(String uuid) {
+ final ServiceModel serviceModel = getModelsByUuid().get(uuid);
+ Assert.assertThat(serviceModel, is(not(nullValue())));
+ return serviceModel;
+ }
+
+ private Service createService(String uuid, int i) {
+ return new ServiceBuilder().setUuid(uuid).setInvariantUUID("invariantUUID" + i)
+ .setCategory("category" + i).setVersion("version" + i).setName("name" + i)
+ .setDistributionStatus("distStatus" + i).setToscaModelURL("toscaModelUrl" + i).build();
+ }
+
+ private ServiceModel createServiceModel(int i) {
+ ServiceModel model = new ServiceModel();
+
+ model.setCollectionResource(ImmutableMap.of("resKey" + i, new CR()));
+ model.setNetworks(ImmutableMap.of("network" + i, new Network()));
+ model.setPnfs(ImmutableMap.of("pnf" + i, new Node()));
+ model.setServiceProxies(ImmutableMap.of("servProxy" + i, new ServiceProxy()));
+ model.setVfModules(ImmutableMap.of("vfmod" + i, new VfModule()));
+ model.setVnfs(ImmutableMap.of("vnf" + i, new VNF()));
+ model.setVolumeGroups(ImmutableMap.of("volgroup" + i, new VolumeGroup()));
+ model.setService(new org.onap.vid.model.Service());
+ return model;
+ }
+
+ private Map<String, ServiceModel> getModelsByUuid() {
+ ServiceModel serviceModel1 = createServiceModel(1);
+ ServiceModel serviceModel2 = createServiceModel(2);
+ ServiceModel serviceModel3 = createServiceModel(3);
+
+ List<ServiceModel> pseudoServiceModels = ImmutableList.of(serviceModel1, serviceModel2, serviceModel3);
+ List<String> uuids = ImmutableList.of(uuid1, uuid2, uuid3);
+ return IntStream.range(0, pseudoServiceModels.size()).boxed()
+ .collect(toMap(i -> uuids.get(i), i -> pseudoServiceModels.get(i)));
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/dao/FnAppDoaImplTest.java b/vid-app-common/src/test/java/org/onap/vid/dao/FnAppDoaImplTest.java
index e7a7e3a37..6d60aa18a 100644
--- a/vid-app-common/src/test/java/org/onap/vid/dao/FnAppDoaImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/dao/FnAppDoaImplTest.java
@@ -1,97 +1,69 @@
package org.onap.vid.dao;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.sql.SQLException;
-import org.junit.Assert;
-import org.junit.Test;
+import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.assertj.core.api.Java6Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.BDDMockito.given;
+@RunWith(MockitoJUnitRunner.class)
public class FnAppDoaImplTest {
- private FnAppDoaImpl createTestSubject() {
- return new FnAppDoaImpl();
- }
+ private FnAppDoaImpl fnAppDoa;
- @Test
- public void testGetConnection() throws Exception {
- String driver2 = "";
- String url = "";
- String username = "";
- String password = "";
- Connection result;
-
- // test 1
- url = null;
- username = null;
- password = null;
- result = FnAppDoaImpl.getConnection(driver2, url, username);
- Assert.assertEquals(null, result);
-
- // test 2
- url = "";
- username = null;
- password = null;
- result = FnAppDoaImpl.getConnection(driver2, url, username);
- Assert.assertEquals(null, result);
-
- // test 3
- username = null;
- url = null;
- password = null;
- result = FnAppDoaImpl.getConnection(driver2, url, username);
- Assert.assertEquals(null, result);
-
- // test 4
- username = "";
- url = null;
- password = null;
- result = FnAppDoaImpl.getConnection(driver2, url, username);
- Assert.assertEquals(null, result);
-
- // test 5
- password = null;
- url = null;
- username = null;
- result = FnAppDoaImpl.getConnection(driver2, url, username);
- Assert.assertEquals(null, result);
-
- // test 6
- password = "";
- url = null;
- username = null;
- result = FnAppDoaImpl.getConnection(driver2, url, username);
- Assert.assertEquals(null, result);
+ @Mock
+ private ConnectionFactory connectionFactory;
+
+ @Mock
+ private Connection connection;
+
+ @Mock
+ private PreparedStatement preparedStatement;
+
+ @Mock
+ private ResultSet resultSet;
+
+ private static final String ERROR_MESSAGE = "error message";
+ private static final String QUERY = "select count(*) from fn_app";
+
+ @Before
+ public void setUp() throws SQLException {
+ given(resultSet.next()).willReturn(true);
+ given(resultSet.getInt(1)).willReturn(5);
+ given(preparedStatement.executeQuery()).willReturn(resultSet);
+ given(connectionFactory.getConnection(anyString(), anyString(), anyString())).willReturn(connection);
+ fnAppDoa = new FnAppDoaImpl(connectionFactory);
}
- @Test
- public void testCleanup() throws Exception {
- ResultSet rs = null;
- PreparedStatement st = null;
+ private void okCaseSetUp() throws SQLException {
- // test 1
- rs = null;
- FnAppDoaImpl.cleanup(rs, st, null);
+ given(connection.prepareStatement(QUERY)).willReturn(preparedStatement);
+ }
- // test 2
- st = null;
- FnAppDoaImpl.cleanup(rs, st, null);
+ private void nokCaseSetup() throws SQLException {
+ given(connection.prepareStatement(QUERY)).willThrow(new SQLException(ERROR_MESSAGE));
+ }
- // test 3
- FnAppDoaImpl.cleanup(rs, st, null);
+ @Test
+ public void getProfileCount_shouldReturnNumber_whenNoExceptionIsThrown() throws SQLException {
+ okCaseSetUp();
+ assertThat(fnAppDoa.getProfileCount("anyUrl", "anyUsername", "anyPassword")).isEqualTo(5);
}
@Test
- public void testGetProfileCount() throws Exception {
- FnAppDoaImpl testSubject;
- String driver = "";
- String URL = "";
- String username = "";
- String password = "";
- int result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getProfileCount(driver, URL, username, password);
+ public void getProfileCount_shouldRethrowSQLException() throws SQLException {
+ nokCaseSetup();
+ assertThatThrownBy(() -> fnAppDoa.getProfileCount("anyUrl", "anyUsername", "anyPassword"))
+ .isInstanceOf(SQLException.class).hasMessage(ERROR_MESSAGE);
}
} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/impl/JobWorkerTest.java b/vid-app-common/src/test/java/org/onap/vid/job/impl/JobWorkerTest.java
index b7e8e35a9..e58b6ba03 100644
--- a/vid-app-common/src/test/java/org/onap/vid/job/impl/JobWorkerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/job/impl/JobWorkerTest.java
@@ -19,7 +19,7 @@ import java.util.UUID;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
index 461673224..718e22fb4 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java
@@ -20,25 +20,8 @@
*/
package org.onap.vid.mso;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.onap.vid.mso.MsoBusinessLogicImpl.validateEndpointPath;
-
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -56,6 +39,22 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.togglz.core.manager.FeatureManager;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+import static org.onap.vid.mso.MsoBusinessLogicImpl.validateEndpointPath;
+
@ContextConfiguration(classes = {SystemProperties.class})
@RunWith(SpringJUnit4ClassRunner.class)
public class MsoBusinessLogicImplTest {
@@ -287,7 +286,7 @@ public class MsoBusinessLogicImplTest {
return new String(Files.readAllBytes(path));
}
- private static class MsoRequestWrapperMatcher extends
+ private static class MsoRequestWrapperMatcher implements
ArgumentMatcher<org.onap.vid.changeManagement.RequestDetailsWrapper> {
private final org.onap.vid.changeManagement.RequestDetailsWrapper expectedRequest;
@@ -297,9 +296,8 @@ public class MsoBusinessLogicImplTest {
}
@Override
- public boolean matches(Object argument) {
- org.onap.vid.changeManagement.RequestDetailsWrapper requestDetailsWrapper = (org.onap.vid.changeManagement.RequestDetailsWrapper) argument;
- return expectedRequest.requestDetails.equals(requestDetailsWrapper.requestDetails);
+ public boolean matches(org.onap.vid.changeManagement.RequestDetailsWrapper argument) {
+ return expectedRequest.requestDetails.equals(argument.requestDetails);
}
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestIdTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestIdTest.java
index 909975fb8..197bfe75d 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestIdTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/OutgoingRequestIdTest.java
@@ -2,12 +2,7 @@ package org.onap.vid.mso.rest;
import com.google.common.collect.ImmutableList;
import org.apache.commons.lang3.reflect.FieldUtils;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
-import org.mockito.InjectMocks;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
+import org.mockito.*;
import org.onap.vid.aai.util.AAIRestInterface;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
import org.onap.vid.controller.filter.PromiseEcompRequestIdFilter;
@@ -31,13 +26,9 @@ import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.allOf;
-import static org.hamcrest.Matchers.equalToIgnoringCase;
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.hasToString;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.matchesPattern;
+import static org.hamcrest.Matchers.*;
public class OutgoingRequestIdTest {
@@ -130,7 +121,7 @@ public class OutgoingRequestIdTest {
ArgumentCaptor<Object> argumentCaptor = ArgumentCaptor.forClass(Object.class);
Mockito.verify(fakeBuilder)
.header(
- Matchers.argThat(equalToIgnoringCase(requestIdHeader)),
+ Matchers.argThat(s -> equalsIgnoreCase(s, requestIdHeader)),
argumentCaptor.capture()
);
requestId = argumentCaptor.getValue();
diff --git a/vid-app-common/src/test/java/org/onap/vid/scheduler/SchedulerRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/scheduler/SchedulerRestInterfaceTest.java
index 6390f5800..0655aca9e 100644
--- a/vid-app-common/src/test/java/org/onap/vid/scheduler/SchedulerRestInterfaceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/scheduler/SchedulerRestInterfaceTest.java
@@ -30,7 +30,7 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.junit.MockitoJUnitRunner;
import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.testUtils.StubServerUtil;
import org.testng.annotations.AfterMethod;
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
index ae6c2ccca..efa12f2c0 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
@@ -1,8 +1,28 @@
-package org.onap.vid.services;
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
-import java.util.Collection;
-import java.util.List;
+package org.onap.vid.services;
+import com.google.common.collect.ImmutableList;
+import io.joshworks.restclient.http.HttpResponse;
import org.junit.Assert;
import org.junit.Test;
import org.onap.vid.aai.AaiResponse;
@@ -13,6 +33,8 @@ import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
import org.onap.vid.model.SubscriberList;
import org.onap.vid.roles.RoleValidator;
+import java.util.List;
+
public class AaiServiceImplTest {
private AaiServiceImpl createTestSubject() {
@@ -55,7 +77,7 @@ public class AaiServiceImplTest {
@Test
public void testGetFullSubscriberList_1() throws Exception {
AaiServiceImpl testSubject;
- AaiResponse<SubscriberList> result;
+ HttpResponse<SubscriberList> result;
// default test
try {
@@ -144,7 +166,7 @@ public class AaiServiceImplTest {
@Test
public void testGetVersionByInvariantId() throws Exception {
AaiServiceImpl testSubject;
- List<String> modelInvariantId = null;
+ List<String> modelInvariantId = ImmutableList.of("some invariant id");
// default test
try {
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
index c3d01283d..5ead3fce4 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
@@ -1,8 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.vid.services;
import com.google.common.collect.ImmutableMap;
+import io.joshworks.restclient.http.HttpResponse;
import jersey.repackaged.com.google.common.collect.ImmutableList;
-import org.onap.vid.aai.AaiClientInterface;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.message.BasicStatusLine;
+import org.onap.vid.aai.AaiOverTLSClientInterface;
import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.model.AaiNodeQueryResponse;
import org.onap.vid.aai.model.ResourceType;
@@ -13,15 +40,14 @@ import org.onap.vid.model.serviceInstantiation.VfModule;
import org.onap.vid.model.serviceInstantiation.Vnf;
import org.onap.vid.mso.RestObject;
import org.onap.vid.mso.rest.AsyncRequestStatus;
-import org.onap.vid.services.AsyncInstantiationBusinessLogic;
-import org.onap.vid.services.AsyncInstantiationBusinessLogicTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.togglz.core.manager.FeatureManager;
import javax.inject.Inject;
+import java.io.UnsupportedEncodingException;
import java.util.*;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests {
@@ -48,7 +74,7 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
protected FeatureManager featureManager;
@Inject
- protected AaiClientInterface aaiClient;
+ protected AaiOverTLSClientInterface aaiClient;
public ServiceInstantiation generateMockServiceInstantiationPayload(boolean isPause, Map<String, Vnf> vnfs, int bulkSize, boolean isUserProvidedNaming, String projectName, boolean rollbackOnFailure) {
ModelInfo modelInfo = createModelInfo();
@@ -174,12 +200,15 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
return restObject;
}
- protected void mockAaiClientAnyNameFree() {
+ protected void mockAaiClientAnyNameFree() throws UnsupportedEncodingException {
when(aaiClient.searchNodeTypeByName(any(), any())).thenReturn(aaiNodeQueryResponseNameFree());
}
- protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryResponseNameFree() {
- return new AaiResponse<>(new AaiNodeQueryResponse(null),"", 200);
+ protected HttpResponse<AaiNodeQueryResponse> aaiNodeQueryResponseNameFree() throws UnsupportedEncodingException {
+ org.apache.http.HttpResponse response = new DefaultHttpResponseFactory().newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, null), null);
+ response.setEntity(new StringEntity(""));
+
+ return HttpResponse.fallback(new AaiNodeQueryResponse(null));
}
protected AaiResponse<AaiNodeQueryResponse> aaiNodeQueryBadResponse() {
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
index 3f13c9dff..9711fa858 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
@@ -1,72 +1,9 @@
package org.onap.vid.services;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import jersey.repackaged.com.google.common.collect.ImmutableList;
-import net.javacrumbs.jsonunit.JsonAssert;
-import org.apache.commons.io.IOUtils;
-import org.hibernate.SessionFactory;
-import org.json.JSONException;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.onap.vid.aai.exceptions.InvalidAAIResponseException;
-import org.onap.vid.aai.model.ResourceType;
-import org.onap.vid.changeManagement.RequestDetailsWrapper;
-import org.onap.vid.exceptions.GenericUncheckedException;
-import org.onap.vid.exceptions.MaxRetriesException;
-import org.onap.vid.exceptions.OperationNotAllowedException;
-import org.onap.vid.job.Job;
-import org.onap.vid.job.Job.JobStatus;
-import org.onap.vid.job.JobAdapter;
-import org.onap.vid.job.JobsBrokerService;
-import org.onap.vid.job.impl.JobDaoImpl;
-import org.onap.vid.model.JobAuditStatus;
-import org.onap.vid.model.JobAuditStatus.SourceStatus;
-import org.onap.vid.model.NameCounter;
-import org.onap.vid.model.ServiceInfo;
-import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
-import org.onap.vid.model.serviceInstantiation.Vnf;
-import org.onap.vid.mso.model.ServiceInstantiationRequestDetails;
-import org.onap.vid.mso.rest.AsyncRequestStatus;
-import org.onap.vid.utils.DaoUtils;
+import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.config.DataSourceConfig;
import org.onap.vid.config.MockedAaiClientAndFeatureManagerConfig;
-import org.onap.vid.mso.MsoOperationalEnvironmentTest;
-import org.onap.vid.services.AsyncInstantiationBaseTest;
-import org.onap.portalsdk.core.domain.FusionObject;
-import org.onap.portalsdk.core.service.DataAccessService;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
-import org.testng.Assert;
-import org.testng.annotations.*;
-
-import javax.inject.Inject;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.time.Instant;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.util.*;
-import java.util.Optional;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.*;
-import static org.hamcrest.core.Every.everyItem;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-import static org.onap.vid.job.Job.JobStatus.*;
-import static org.testng.Assert.*;
@ContextConfiguration(classes = {DataSourceConfig.class, SystemProperties.class, MockedAaiClientAndFeatureManagerConfig.class})
public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseTest {
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/CategoryParameterServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/CategoryParameterServiceImplTest.java
index 6ac7b5447..7a4263c7e 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/CategoryParameterServiceImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/CategoryParameterServiceImplTest.java
@@ -20,18 +20,6 @@
*/
package org.onap.vid.services;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.MockitoAnnotations.initMocks;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import javax.ws.rs.ForbiddenException;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.onap.portalsdk.core.service.DataAccessService;
@@ -50,6 +38,16 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
+import javax.ws.rs.ForbiddenException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.*;
+import static org.mockito.MockitoAnnotations.initMocks;
+
public class CategoryParameterServiceImplTest {
private static final String CATEGORY_NAME = "SAMPLE_CATEGORY_NAME";
@@ -89,7 +87,7 @@ public class CategoryParameterServiceImplTest {
Assert.assertTrue(result.getErrors().isEmpty());;
verify(dataAccessService, times(1))
- .saveDomainObject(anyObject(), anyObject());
+ .saveDomainObject(any(), any());
}
@Test
@@ -162,12 +160,12 @@ public class CategoryParameterServiceImplTest {
categoryParameter.getOptions().add(categoryParameterOption);
List<CategoryParameter> aList = createCategoryParametersList(categoryParameter);
- doReturn(aList).when(dataAccessService).getList(anyObject(), anyString(), anyString(), anyObject());
+ doReturn(aList).when(dataAccessService).getList(any(), anyString(), any(), any());
testSubject.deleteCategoryOption(CATEGORY_NAME, categoryParameterOption);
verify(dataAccessService, times(1))
- .deleteDomainObject(anyObject(), anyObject());
+ .deleteDomainObject(any(), any());
}
@Test
@@ -178,7 +176,7 @@ public class CategoryParameterServiceImplTest {
categoryParameter.getOptions().add(categoryParameterOption);
List<CategoryParameter> aList = createCategoryParametersList(categoryParameter);
- doReturn(aList).when(dataAccessService).getList(anyObject(), anyString(), anyString(), anyObject());
+ doReturn(aList).when(dataAccessService).getList(any(), anyString(), any(), any());
CategoryParametersResponse response = testSubject.getCategoryParameters(Family.PARAMETER_STANDARDIZATION);
@@ -186,7 +184,7 @@ public class CategoryParameterServiceImplTest {
Assert.assertTrue(response.getCategoryParameters().containsKey(CATEGORY_NAME));
verify(dataAccessService, times(1))
- .getList(anyObject(), anyString(), anyString(), anyObject());
+ .getList(any(), anyString(), any(), any());
}
@Test
@@ -202,7 +200,7 @@ public class CategoryParameterServiceImplTest {
AddCategoryOptionResponse result = testSubject.updateCategoryParameterOption(CATEGORY_NAME, optionRepExisting);
verify(dataAccessService, times(1))
- .saveDomainObject(anyObject(), anyObject());
+ .saveDomainObject(any(), any());
}
@Test(expectedExceptions = { ForbiddenException.class })
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceImplTest.java
index 157f59c74..00d9e1735 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceImplTest.java
@@ -1,12 +1,12 @@
package org.onap.vid.services;
import org.mockito.*;
+import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.vid.changeManagement.ChangeManagementRequest;
import org.onap.vid.changeManagement.RequestDetails;
import org.onap.vid.mso.MsoBusinessLogic;
import org.onap.vid.mso.MsoResponseWrapperInterface;
import org.onap.vid.scheduler.SchedulerRestInterfaceIfc;
-import org.onap.portalsdk.core.service.DataAccessService;
import org.springframework.http.ResponseEntity;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -54,47 +54,47 @@ public class ChangeManagementServiceImplTest {
@Test
public void doChangeManagement_requestTypeIsUpdate_MsoUpdateVnfIsCalled() throws Exception {
- Mockito.doReturn(Mockito.mock(MsoResponseWrapperInterface.class)).when(msoBusinessLogicMock).updateVnf(Mockito.any(),Mockito.anyString(),Mockito.anyString());
+ Mockito.doReturn(Mockito.mock(MsoResponseWrapperInterface.class)).when(msoBusinessLogicMock).updateVnf(Mockito.any(),Mockito.any(),Mockito.any());
RequestDetails requestDetails = callChangeManagement(ChangeManagementRequest.UPDATE);
ArgumentCaptor<RequestDetails> argumentCaptor = ArgumentCaptor.forClass(RequestDetails.class);
- verify(msoBusinessLogicMock).updateVnf(argumentCaptor.capture(),Mockito.anyString(),Mockito.anyString());
+ verify(msoBusinessLogicMock).updateVnf(argumentCaptor.capture(),Mockito.any(),Mockito.any());
assertEquals(argumentCaptor.getValue().getVnfInstanceId(),requestDetails.getVnfInstanceId());
}
@Test
public void doChangeManagement_requestTypeIsReplace_MsoUpdateVnfIsCalled() throws Exception {
- Mockito.doReturn(Mockito.mock(MsoResponseWrapperInterface.class)).when(msoBusinessLogicMock).replaceVnf(Mockito.any(),Mockito.anyString(),Mockito.anyString());
+ Mockito.doReturn(Mockito.mock(MsoResponseWrapperInterface.class)).when(msoBusinessLogicMock).replaceVnf(Mockito.any(),Mockito.any(),Mockito.any());
RequestDetails requestDetails = callChangeManagement(ChangeManagementRequest.REPLACE);
ArgumentCaptor<RequestDetails> argumentCaptor = ArgumentCaptor.forClass(RequestDetails.class);
- verify(msoBusinessLogicMock).replaceVnf(argumentCaptor.capture(),Mockito.anyString(),Mockito.anyString());
+ verify(msoBusinessLogicMock).replaceVnf(argumentCaptor.capture(),Mockito.any(),Mockito.any());
assertEquals(argumentCaptor.getValue().getVnfInstanceId(),requestDetails.getVnfInstanceId());
}
@Test
public void doChangeManagement_requestTypeIsInPlaceSoftwareUpdate_MsoUpdateVnfIsCalled() throws Exception {
- Mockito.doReturn(Mockito.mock(MsoResponseWrapperInterface.class)).when(msoBusinessLogicMock).updateVnfSoftware(Mockito.any(),Mockito.anyString(),Mockito.anyString());
+ Mockito.doReturn(Mockito.mock(MsoResponseWrapperInterface.class)).when(msoBusinessLogicMock).updateVnfSoftware(Mockito.any(),Mockito.any(),Mockito.any());
RequestDetails requestDetails = callChangeManagement(ChangeManagementRequest.VNF_IN_PLACE_SOFTWARE_UPDATE);
ArgumentCaptor<RequestDetails> argumentCaptor = ArgumentCaptor.forClass(RequestDetails.class);
- verify(msoBusinessLogicMock).updateVnfSoftware(argumentCaptor.capture(),Mockito.anyString(),Mockito.anyString());
+ verify(msoBusinessLogicMock).updateVnfSoftware(argumentCaptor.capture(),Mockito.any(),Mockito.any());
assertEquals(argumentCaptor.getValue().getVnfInstanceId(),requestDetails.getVnfInstanceId());
}
@Test
public void doChangeManagement_requestTypeIsConfigUpdate_MsoUpdateVnfIsCalled() throws Exception {
- Mockito.doReturn(Mockito.mock(MsoResponseWrapperInterface.class)).when(msoBusinessLogicMock).updateVnfConfig(Mockito.any(),Mockito.anyString(),Mockito.anyString());
+ Mockito.doReturn(Mockito.mock(MsoResponseWrapperInterface.class)).when(msoBusinessLogicMock).updateVnfConfig(Mockito.any(),Mockito.any(),Mockito.any());
RequestDetails requestDetails = callChangeManagement(ChangeManagementRequest.CONFIG_UPDATE);
ArgumentCaptor<RequestDetails> argumentCaptor = ArgumentCaptor.forClass(RequestDetails.class);
- verify(msoBusinessLogicMock).updateVnfConfig(argumentCaptor.capture(),Mockito.anyString(),Mockito.anyString());
+ verify(msoBusinessLogicMock).updateVnfConfig(argumentCaptor.capture(),Mockito.any(),Mockito.any());
assertEquals(argumentCaptor.getValue().getVnfInstanceId(),requestDetails.getVnfInstanceId());
}
@@ -106,8 +106,8 @@ public class ChangeManagementServiceImplTest {
updateRequest.setRequestType(requestType);
RequestDetails requestDetails = new RequestDetails();
requestDetails.setVnfInstanceId("vnfFakeId");
- Mockito.doReturn("fakeId").when(changeManagementServiceSpied).extractServiceInstanceId(Mockito.anyObject(),Mockito.anyString());
- Mockito.doReturn(requestDetails).when(changeManagementServiceSpied).findRequestByVnfName(Matchers.anyList(),Mockito.anyString());
+ Mockito.doReturn("fakeId").when(changeManagementServiceSpied).extractServiceInstanceId(Mockito.any(),Mockito.any());
+ Mockito.doReturn(requestDetails).when(changeManagementServiceSpied).findRequestByVnfName(Matchers.any(),Mockito.any());
changeManagementServiceSpied.doChangeManagement(updateRequest,"anyVnfName");
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java
index 8aafda3f0..d849869b0 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java
@@ -24,6 +24,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.joshworks.restclient.http.HttpResponse;
import org.apache.commons.io.IOUtils;
import org.mockito.ArgumentCaptor;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.changeManagement.ChangeManagementRequest;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
import org.onap.vid.client.SyncRestClient;
@@ -37,8 +39,6 @@ import org.onap.vid.mso.rest.RequestDetails;
import org.onap.vid.properties.AsdcClientConfiguration;
import org.onap.vid.scheduler.SchedulerRestInterfaceIfc;
import org.onap.vid.testUtils.RegExMatcher;
-import org.onap.portalsdk.core.service.DataAccessService;
-import org.onap.portalsdk.core.util.SystemProperties;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.context.annotation.Bean;
@@ -54,8 +54,8 @@ import java.net.URL;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
@@ -74,7 +74,7 @@ public class ChangeManagementServiceUnitTest extends AbstractTestNGSpringContext
void testInPlaceSoftwareUpdateRequest() throws Exception {
- doReturn(new HttpResponse<>(anyObject(), RequestReferencesContainer.class, anyObject())).when(restClientUnderTest).post(anyString(), anyObject(), anyObject());
+ doReturn(new HttpResponse<>(any(), RequestReferencesContainer.class, any())).when(restClientUnderTest).post(anyString(), any(), any());
URL requestJsonUrl = this.getClass().getResource("/services/change_management_software_update_request.json");
ChangeManagementRequest changeManagementRequest = objectMapper.readValue(requestJsonUrl, ChangeManagementRequest.class);
diff --git a/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java b/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
index 0460f5325..b4c7828bc 100644
--- a/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
+++ b/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
@@ -22,8 +22,8 @@ import java.util.Iterator;
import java.util.List;
import static fj.parser.Parser.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
/**