aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/test/java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java1
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiGetVnfResponseTest.java88
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/OperationalEnvironmentTest.java222
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/SubscriberAaiResponseTest.java36
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/SubscriberFilteredResultsTest.java86
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/SubscriberWithFilterTest.java36
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/model/RelationshipListTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/aai/ServicePropertiesTest.java)43
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/model/ServicePropertiesTest.java93
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/model/VnfResultTest.java84
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java302
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java315
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java28
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/changeManagement/RequestParametersTest.java34
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/changeManagement/UIWorkflowsRequestTest.java33
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/changeManagement/WorkflowRequestDetailTest.java33
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java122
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java144
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java16
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/WorkflowsControllerTest.java140
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/open/HealthCheckControllerTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/controller/HealthCheckControllerTest.java)3
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/open/MaintenanceControllerTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/controller/MaintenanceControllerTest.java)3
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/open/RoleGeneratorControllerTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/controller/RoleGeneratorControllerTest.java)3
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/open/VersionControllerTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/controller/VersionControllerTest.java)3
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/job/command/InstanceGroupCommandTest.java31
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java75
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java17
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java72
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java85
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java29
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskTest.java79
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/roles/AlwaysValidRoleValidatorTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/aai/VnfResultTest.java)48
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByRolesTest.java (renamed from vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorTest.java)16
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java98
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceImplTest.java18
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/ChangeManagementServiceUnitTest.java5
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java116
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowsServiceImplTest.java80
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/WorkflowServiceImplTest.java34
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java34
39 files changed, 1714 insertions, 991 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java
index 8bcadd139..5bdfd1207 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java
@@ -18,7 +18,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.onap.vid.aai;
import com.google.common.collect.ImmutableList;
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiGetVnfResponseTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiGetVnfResponseTest.java
index 5eb47a1ff..9d8734b39 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiGetVnfResponseTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiGetVnfResponseTest.java
@@ -20,34 +20,88 @@
package org.onap.vid.aai;
-import java.util.Map;
+import java.io.IOException;
+import java.util.*;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.junit.Before;
import org.junit.Test;
+import org.onap.vid.aai.model.VnfResult;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
public class AaiGetVnfResponseTest {
- private AaiGetVnfResponse createTestSubject() {
- return new AaiGetVnfResponse();
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final String VNF_RESULT =
+ "{\n" +
+ " \"id\": \"1\",\n" +
+ " \"nodetype\": \"testNodeType\",\n" +
+ " \"url\": \"test/url\",\n" +
+ " \"serviceProperties\": {},\n" +
+ " \"relatedTo\": []\n" +
+ "}\n";
+
+ private static final String AAI_GET_VNF_RESPONSE_TEST = "{ \n" +
+ " \"results\": \n" +
+ " [\n" +
+ VNF_RESULT +
+ " ]\n" +
+ "}";
+
+
+ private AaiGetVnfResponse aaiGetVnfResponse;
+ private VnfResult expectedVnfResult;
+ private List<VnfResult> expectedList;
+
+ @Before
+ public void setUp() throws IOException {
+ expectedVnfResult = OBJECT_MAPPER.readValue(VNF_RESULT, VnfResult.class);
+ expectedList = Collections.singletonList(expectedVnfResult);
+
}
@Test
- public void testGetAdditionalProperties() throws Exception {
- AaiGetVnfResponse testSubject;
- Map<String, Object> result;
+ public void shouldHaveProperSetters() {
+ aaiGetVnfResponse = new AaiGetVnfResponse();
+ aaiGetVnfResponse.setAdditionalProperty("key","value");
+ aaiGetVnfResponse.setResults(expectedList);
+
+ assertEquals(aaiGetVnfResponse.getAdditionalProperties().size(), 1);
+ assertTrue(aaiGetVnfResponse.getAdditionalProperties().containsKey("key"));
+ assertTrue(aaiGetVnfResponse.getAdditionalProperties().containsValue("value"));
+ assertEquals(aaiGetVnfResponse.getResults().size(), 1);
+ assertEquals(aaiGetVnfResponse.getResults().get(0), expectedVnfResult);
+ }
+
+ @Test
+ public void shouldProperlyConvertJsonToAiiGetVnfResponse() throws IOException {
+ aaiGetVnfResponse = OBJECT_MAPPER.readValue(AAI_GET_VNF_RESPONSE_TEST, AaiGetVnfResponse.class);
+ assertThat(aaiGetVnfResponse.getResults(), is(expectedList));
+ }
+
+ @Test
+ public void shouldReturnProperToString(){
+ aaiGetVnfResponse = new AaiGetVnfResponse();
+ aaiGetVnfResponse.setAdditionalProperty("testKey","testValue");
+ aaiGetVnfResponse.setResults(expectedList);
+ Map<String,Object> expectedMap = new HashMap<>();
+ expectedMap.put("testKey", "testValue");
+
+ String expectedOutput = "AaiGetVnfResponse{" +
+ "results=" + expectedList +
+ ", additionalProperties="+expectedMap+"}";
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAdditionalProperties();
+ assertEquals(aaiGetVnfResponse.toString(), expectedOutput);
}
@Test
- public void testSetAdditionalProperty() throws Exception {
- AaiGetVnfResponse testSubject;
- String name = "";
- Object value = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setAdditionalProperty(name, value);
+ public void shouldAddAdditionalProperty(){
+ aaiGetVnfResponse = new AaiGetVnfResponse();
+ aaiGetVnfResponse.setAdditionalProperty("key", "value");
+ assertTrue(aaiGetVnfResponse.getAdditionalProperties().containsKey("key"));
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/OperationalEnvironmentTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/OperationalEnvironmentTest.java
index 76cd21391..c331b3252 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/OperationalEnvironmentTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/OperationalEnvironmentTest.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
@@ -20,190 +21,69 @@
package org.onap.vid.aai;
-import org.junit.Test;
-import org.onap.vid.aai.model.RelationshipList;
-
-public class OperationalEnvironmentTest {
-
- private OperationalEnvironment createTestSubject() {
- return new OperationalEnvironment();
- }
-
- @Test
- public void testGetOperationalEnvironmentId() throws Exception {
- OperationalEnvironment testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOperationalEnvironmentId();
- }
-
- @Test
- public void testSetOperationalEnvironmentId() throws Exception {
- OperationalEnvironment testSubject;
- String operationalEnvironmentId = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setJsonOperationalEnvironmentId(operationalEnvironmentId);
- }
-
- @Test
- public void testGetOperationalEnvironmentName() throws Exception {
- OperationalEnvironment testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOperationalEnvironmentName();
- }
-
- @Test
- public void testSetOperationalEnvironmentName() throws Exception {
- OperationalEnvironment testSubject;
- String operationalEnvironmentName = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setJsonOperationalEnvironmentName(operationalEnvironmentName);
- }
-
- @Test
- public void testGetOperationalEnvironmentType() throws Exception {
- OperationalEnvironment testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOperationalEnvironmentType();
- }
-
- @Test
- public void testSetOperationalEnvironmentType() throws Exception {
- OperationalEnvironment testSubject;
- String operationalEnvironmentType = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setJsonOperationalEnvironmentType(operationalEnvironmentType);
- }
- @Test
- public void testGetOperationalEnvironmentStatus() throws Exception {
- OperationalEnvironment testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getOperationalEnvironmentStatus();
- }
-
- @Test
- public void testSetOperationalEnvironmentStatus() throws Exception {
- OperationalEnvironment testSubject;
- String operationalEnvironmentStatus = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setJsonOperationalEnvironmentStatus(operationalEnvironmentStatus);
- }
-
- @Test
- public void testGetTenantContext() throws Exception {
- OperationalEnvironment testSubject;
- String result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getTenantContext();
- }
-
- @Test
- public void testSetTenantContext() throws Exception {
- OperationalEnvironment testSubject;
- String tenantContext = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setJsonTenantContext(tenantContext);
- }
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Assert;
+import org.onap.vid.aai.model.RelationshipList;
+import org.testng.annotations.Test;
- @Test
- public void testGetWorkloadContext() throws Exception {
- OperationalEnvironment testSubject;
- String result;
+import java.io.IOException;
+import java.util.ArrayList;
- // default test
- testSubject = createTestSubject();
- result = testSubject.getWorkloadContext();
- }
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.assertj.core.api.Assertions.assertThat;
- @Test
- public void testSetWorkloadContext() throws Exception {
- OperationalEnvironment testSubject;
- String workloadContext = "";
- // default test
- testSubject = createTestSubject();
- testSubject.setJsonWorkloadContext(workloadContext);
- }
+public class OperationalEnvironmentTest {
- @Test
- public void testGetResourceVersion() throws Exception {
- OperationalEnvironment testSubject;
- String result;
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
- // default test
- testSubject = createTestSubject();
- result = testSubject.getResourceVersion();
- }
+ private static final String OPERATIONAL_ENVIRONMENT_TEST = "{\n" +
+ "\"operational-environment-id\": \"environmentId\",\n" +
+ "\"operational-environment-name\": \"environmentName\",\n" +
+ "\"operational-environment-type\": \"environmentType\",\n" +
+ "\"operational-environment-status\": \"environmentStatus\",\n" +
+ "\"tenant-context\": \"tenantContext\",\n" +
+ "\"workload-context\": \"workloadContext\",\n" +
+ "\"resource-version\": \"resourceVersion\",\n" +
+ "\"relationship-list\": {\n" +
+ "\"relationship\": []\n" +
+ "}\n" +
+ "}";
@Test
- public void testSetResourceVersion() throws Exception {
- OperationalEnvironment testSubject;
- String resourceVersion = "";
-
- // default test
- testSubject = createTestSubject();
- testSubject.setJsonResourceVersion(resourceVersion);
- }
+ public void shouldCreateProperOperationalEnvironmentWithConstructor(){
+ RelationshipList relationshipList = new RelationshipList();
+ relationshipList.relationship = new ArrayList<>();
- @Test
- public void testGetRelationshipList() throws Exception {
- OperationalEnvironment testSubject;
- RelationshipList result;
+ OperationalEnvironment operationalEnvironment = new OperationalEnvironment("testId",
+ "testEnvName", "testEnvType",
+ "testEnvStatus", "testTenant", "testWorkload",
+ "testResource", relationshipList);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getRelationshipList();
+ assertThat(operationalEnvironment.getOperationalEnvironmentId()).isEqualTo("testId");
+ assertThat(operationalEnvironment.getWorkloadContext()).isEqualTo("testWorkload");
+ assertThat(operationalEnvironment.getRelationshipList().getRelationship()).hasSize(0);
+ assertThat(operationalEnvironment.getResourceVersion()).isEqualTo("testResource");
+ assertThat(operationalEnvironment.getTenantContext()).isEqualTo("testTenant");
+ assertThat(operationalEnvironment.getOperationalEnvironmentType()).isEqualTo("testEnvType");
+ assertThat(operationalEnvironment.getOperationalEnvironmentStatus()).isEqualTo("testEnvStatus");
+ assertThat(operationalEnvironment.getOperationalEnvironmentName()).isEqualTo("testEnvName");
}
@Test
- public void testSetRelationshipList() throws Exception {
- OperationalEnvironment testSubject;
- RelationshipList relationshipList = null;
+ public void shouldProperlyConvertJsonToOperationalEnvironment() throws IOException {
+ OperationalEnvironment operationalEnvironment =
+ OBJECT_MAPPER.readValue(OPERATIONAL_ENVIRONMENT_TEST, OperationalEnvironment.class);
- // default test
- testSubject = createTestSubject();
- testSubject.setJsonRelationshipList(relationshipList);
+ assertThat(operationalEnvironment.getOperationalEnvironmentId()).isEqualTo("environmentId");
+ assertThat(operationalEnvironment.getWorkloadContext()).isEqualTo("workloadContext");
+ assertThat(operationalEnvironment.getRelationshipList().getRelationship()).hasSize(0);
+ assertThat(operationalEnvironment.getResourceVersion()).isEqualTo("resourceVersion");
+ assertThat(operationalEnvironment.getTenantContext()).isEqualTo("tenantContext");
+ assertThat(operationalEnvironment.getOperationalEnvironmentType()).isEqualTo("environmentType");
+ assertThat(operationalEnvironment.getOperationalEnvironmentStatus()).isEqualTo("environmentStatus");
+ assertThat(operationalEnvironment.getOperationalEnvironmentName()).isEqualTo("environmentName");
}
- @Test
- public void testOperationalEnvironment() throws Exception {
- OperationalEnvironment testSubject;
- String operationalEnvironmentId = "";
- String operationalEnvironmentName = "";
- String operationalEnvironmentType = "";
- String operationalEnvironmentStatus = "";
- String tenantContext = "";
- String workloadContext = "";
- String resourceVersion = "";
- RelationshipList relationshipList = null;
-
- // default test
- testSubject = new OperationalEnvironment(operationalEnvironmentId, operationalEnvironmentName,
- operationalEnvironmentType, operationalEnvironmentStatus, tenantContext, workloadContext,
- resourceVersion, relationshipList);
- }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberAaiResponseTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberAaiResponseTest.java
index ef2220c2d..b8dd2cfa7 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberAaiResponseTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberAaiResponseTest.java
@@ -20,23 +20,39 @@
package org.onap.vid.aai;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
+import org.onap.vid.model.Subscriber;
import org.onap.vid.model.SubscriberList;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
public class SubscriberAaiResponseTest {
- private SubscriberAaiResponse createTestSubject() {
- return new SubscriberAaiResponse(new SubscriberList(), "", 0);
- }
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final String SUBSCRIBER_JSON_EXAMPLE = "{\n" +
+ " \"global-customer-id\": \"id\",\n" +
+ " \"subscriber-name\": \"name\",\n" +
+ " \"subscriber-type\": \"type\",\n" +
+ " \"resource-version\": \"version\"\n" +
+ "}";
-
@Test
- public void testGetSubscriberList() throws Exception {
- SubscriberAaiResponse testSubject;
- SubscriberList result;
+ public void shouldGetSubscriberList() throws IOException {
+ Subscriber sampleSubscriber =
+ OBJECT_MAPPER.readValue(SUBSCRIBER_JSON_EXAMPLE, Subscriber.class);
+ List<Subscriber> expectedListOfSubscribers = Arrays.asList(sampleSubscriber);
+ SubscriberList expectedSubscriberList = new SubscriberList(expectedListOfSubscribers);
+ SubscriberAaiResponse subscriberAaiResponse = new SubscriberAaiResponse(expectedSubscriberList, "msg", 200);
+
+ assertEquals(subscriberAaiResponse.getSubscriberList(), expectedSubscriberList);
+ assertEquals(subscriberAaiResponse.getSubscriberList().customer.size(), 1);
+ assertEquals(subscriberAaiResponse.getSubscriberList().customer.get(0), sampleSubscriber);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getSubscriberList();
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberFilteredResultsTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberFilteredResultsTest.java
index 4655292c6..f9668c960 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberFilteredResultsTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberFilteredResultsTest.java
@@ -20,45 +20,89 @@
package org.onap.vid.aai;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Before;
import org.junit.Test;
+import org.onap.vid.model.Subscriber;
import org.onap.vid.model.SubscriberList;
import org.onap.vid.roles.EcompRole;
import org.onap.vid.roles.Role;
import org.onap.vid.roles.RoleValidator;
+import static org.junit.Assert.assertEquals;
+
public class SubscriberFilteredResultsTest {
- private SubscriberFilteredResults createTestSubject() {
- ArrayList<Role> list = new ArrayList<Role>();
- list.add(new Role(EcompRole.READ, "a", "a", "a"));
- RoleValidator rl=new RoleValidator(list);
- SubscriberList sl = new SubscriberList();
- sl.customer = new ArrayList<org.onap.vid.model.Subscriber>();
- sl.customer.add(new org.onap.vid.model.Subscriber());
- return new SubscriberFilteredResults(rl, sl, "OK", 200);
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+ private SubscriberFilteredResults subscriberFilteredResults;
+ private RoleValidator roleValidator;
+ private SubscriberList subscriberList;
+ private SubscriberListWithFilterData subscriberListWithFilterData;
+
+ private static final String SUBSCRIBER_JSON_EXAMPLE = "{\n" +
+ " \"global-customer-id\": \"id\",\n" +
+ " \"subscriber-name\": \"name\",\n" +
+ " \"subscriber-type\": \"type\",\n" +
+ " \"resource-version\": \"version\"\n" +
+ "}";
+
+ @Before
+ public void setUp() throws IOException {
+ createTestSubject();
}
@Test
- public void testGetSubscriberList() throws Exception {
- SubscriberFilteredResults testSubject;
- SubscriberListWithFilterData result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getSubscriberList();
+ public void testGetSubscriberList(){
+ assertEquals(subscriberFilteredResults.getSubscriberList(), subscriberListWithFilterData);
}
@Test
public void testSetSubscriberList() throws Exception {
- SubscriberFilteredResults testSubject;
- SubscriberListWithFilterData subscriberList = null;
+ subscriberList.customer = new ArrayList<>();
+ subscriberList.customer.add(new Subscriber());
+ SubscriberListWithFilterData expectedList = createSubscriberList(subscriberList,roleValidator);
+ subscriberFilteredResults.setSubscriberList(expectedList);
+
+ assertEquals(subscriberFilteredResults.getSubscriberList(), expectedList);
+ }
+
+ private void createTestSubject() throws IOException {
+ prepareRoleValidator();
+ prepareSubscriberList();
+ prepareSubscriberListWithFilterData();
+ createSubscriberFilteredResults();
+ }
+
+ private void createSubscriberFilteredResults() {
+ subscriberFilteredResults =
+ new SubscriberFilteredResults(roleValidator, subscriberList, "OK", 200);
+ subscriberFilteredResults.setSubscriberList(subscriberListWithFilterData);
+ }
+
+ private void prepareSubscriberListWithFilterData() {
+ subscriberListWithFilterData = createSubscriberList(subscriberList, roleValidator);
+ }
+
+ private void prepareRoleValidator() {
+ ArrayList<Role> list = new ArrayList<>();
+ list.add(new Role(EcompRole.READ, "a", "a", "a"));
+ roleValidator = RoleValidator.by(list);
+ }
+
+ private void prepareSubscriberList() throws IOException {
+ Subscriber sampleSubscriber =
+ OBJECT_MAPPER.readValue(SUBSCRIBER_JSON_EXAMPLE, Subscriber.class);
+ List<Subscriber> expectedListOfSubscribers = Collections.singletonList(sampleSubscriber);
+ subscriberList = new SubscriberList(expectedListOfSubscribers);
+ }
- // default test
- testSubject = createTestSubject();
- //testSubject.setSubscriberList(subscriberList);
- testSubject.getSubscriberList();
+ private SubscriberListWithFilterData createSubscriberList(SubscriberList subscriberList,
+ RoleValidator roleValidator){
+ return new SubscriberListWithFilterData(subscriberList,roleValidator);
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberWithFilterTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberWithFilterTest.java
index 2842b08dc..c690b5fa0 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberWithFilterTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/SubscriberWithFilterTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,31 +20,15 @@
package org.onap.vid.aai;
-import org.junit.Test;
-public class SubscriberWithFilterTest {
-
- private SubscriberWithFilter createTestSubject() {
- return new SubscriberWithFilter();
- }
-
- @Test
- public void testGetIsPermitted() throws Exception {
- SubscriberWithFilter testSubject;
- boolean result;
+import org.testng.annotations.Test;
- // default test
- testSubject = createTestSubject();
- result = testSubject.getIsPermitted();
- }
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
- @Test
- public void testSetIsPermitted() throws Exception {
- SubscriberWithFilter testSubject;
- boolean isPermitted = false;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setIsPermitted(isPermitted);
- }
+public class SubscriberWithFilterTest {
+ @Test
+ public void shouldHaveValidGettersAndSetters() {
+ assertThat(SubscriberWithFilter.class, hasValidGettersAndSetters());
+ }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/ServicePropertiesTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/model/RelationshipListTest.java
index 6ff766413..cc57171b8 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/ServicePropertiesTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/model/RelationshipListTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* VID
* ================================================================================
- * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019 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.
@@ -18,37 +18,18 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.vid.aai;
+package org.onap.vid.aai.model;
-import java.util.Map;
-import org.junit.Test;
-import org.onap.vid.aai.model.ServiceProperties;
+import org.testng.annotations.Test;
-public class ServicePropertiesTest {
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
- private ServiceProperties createTestSubject() {
- return new ServiceProperties();
- }
+public class RelationshipListTest {
- @Test
- public void testGetAdditionalProperties() throws Exception {
- ServiceProperties testSubject;
- Map<String, Object> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAdditionalProperties();
- }
-
- @Test
- public void testSetAdditionalProperty() throws Exception {
- ServiceProperties testSubject;
- String name = "";
- Object value = null;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setAdditionalProperty(name, value);
- }
+ @Test
+ public void shouldHaveValidGettersAndSetters() {
+ assertThat(RelationshipList.class, hasValidGettersAndSetters());
+ }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/model/ServicePropertiesTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/model/ServicePropertiesTest.java
new file mode 100644
index 000000000..3eccba9b6
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/model/ServicePropertiesTest.java
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T 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.model;
+
+import java.io.IOException;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.testng.annotations.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ServicePropertiesTest {
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+ private static final String SERVICE_PROPERTIES_JSON = "{\n" +
+ "\"service-instance-id\": \"instanceId\",\n" +
+ "\"service-instance-name\": \"instanceName\",\n" +
+ "\"model-invariant-id\": \"invariantId\",\n" +
+ "\"model-version-id\": \"versionId\",\n" +
+ "\"resource-version\": \"version\",\n" +
+ "\"orchestration-status\": \"status\",\n" +
+ "\"global-customer-id\": \"customerId\",\n" +
+ "\"subscriber-name\": \"subscriberName\",\n" +
+ "\"subscriber-type\": \"subscriberType\",\n" +
+ "\"vnf-id\": \"vnfId\",\n" +
+ "\"vnf-name\": \"vnfName\",\n" +
+ "\"vnf-type\": \"vnfType\",\n" +
+ "\"service-id\": \"serviceId\",\n" +
+ "\"prov-status\": \"provStatus\",\n" +
+ "\"in-maint\": false,\n" +
+ "\"is-closed-loop-disabled\": false,\n" +
+ "\"model-customization-id\": \"customizationId\",\n" +
+ "\"nf-type\": \"nfType\",\n" +
+ "\"nf-function\": \"nfFunction\",\n" +
+ "\"nf-role\": \"nfRole\",\n" +
+ "\"nf-naming-code\": \"namingCode\",\n" +
+ "\"not-listed-property\":\"value\"}"+
+ "}";
+
+
+ @Test
+ public void shouldProperlyConvertJsonToServiceProperties() throws IOException {
+ ServiceProperties serviceProperties = OBJECT_MAPPER.readValue(SERVICE_PROPERTIES_JSON, ServiceProperties.class);
+
+
+ assertThat(serviceProperties.isClosedLoopDisabled).isFalse();
+ assertThat(serviceProperties.globalCustomerId).isEqualTo("customerId");
+ assertThat(serviceProperties.inMaint).isFalse();
+ assertThat(serviceProperties.modelCustomizationId).isEqualTo("customizationId");
+ assertThat(serviceProperties.modelInvariantId).isEqualTo("invariantId");
+ assertThat(serviceProperties.modelVersionId).isEqualTo("versionId");
+ assertThat(serviceProperties.nfRole).isEqualTo("nfRole");
+ assertThat(serviceProperties.nfFunction).isEqualTo("nfFunction");
+ assertThat(serviceProperties.nfType).isEqualTo("nfType");
+ assertThat(serviceProperties.nfNamingCode).isEqualTo("namingCode");
+ assertThat(serviceProperties.serviceId).isEqualTo("serviceId");
+ assertThat(serviceProperties.serviceInstanceName).isEqualTo("instanceName");
+ assertThat(serviceProperties.serviceInstanceId).isEqualTo("instanceId");
+ assertThat(serviceProperties.provStatus).isEqualTo("provStatus");
+ assertThat(serviceProperties.vnfId).isEqualTo("vnfId");
+ assertThat(serviceProperties.vnfName).isEqualTo("vnfName");
+ assertThat(serviceProperties.vnfType).isEqualTo("vnfType");
+ }
+
+ @Test
+ public void shouldAddAdditionalProperty() throws IOException {
+ ServiceProperties serviceProperties = OBJECT_MAPPER.readValue(SERVICE_PROPERTIES_JSON, ServiceProperties.class);
+
+ serviceProperties.setAdditionalProperty("additional", "property");
+
+ assertThat(serviceProperties.getAdditionalProperties())
+ .containsOnlyKeys("not-listed-property","additional")
+ .containsValues("value","property");
+ }
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/model/VnfResultTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/model/VnfResultTest.java
new file mode 100644
index 000000000..075d29f28
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/model/VnfResultTest.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T 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.model;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.Assert;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanEquals;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class VnfResultTest {
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final String VNF_RESULT_JSON = "{\n" +
+ "\"id\": \"sample\",\n" +
+ "\"node-type\": \"sampleNodeType\",\n" +
+ "\"url\": \"sample\",\n" +
+ "\"properties\": {\n" +
+ "\"service-instance-id\": \"sample\",\n" +
+ "\"service-instance-name\": \"sample\",\n" +
+ "\"model-invariant-id\": \"sample\",\n" +
+ "\"model-version-id\": \"sample\",\n" +
+ "\"resource-version\": \"sample\",\n" +
+ "\"orchestration-status\": \"sample\",\n" +
+ "\"global-customer-id\": \"sample\",\n" +
+ "\"subscriber-name\": \"sample\",\n" +
+ "\"subscriber-type\": \"sample\",\n" +
+ "\"vnf-id\": \"sample\",\n" +
+ "\"vnf-name\": \"sample\",\n" +
+ "\"vnf-type\": \"sample\",\n" +
+ "\"service-id\": \"sample\",\n" +
+ "\"prov-status\": \"sample\",\n" +
+ "\"in-maint\": false,\n" +
+ "\"is-closed-loop-disabled\": false,\n" +
+ "\"model-customization-id\": \"sample\",\n" +
+ "\"nf-type\": \"sample\",\n" +
+ "\"nf-function\": \"sample\",\n" +
+ "\"nf-role\": \"sample\",\n" +
+ "\"nf-naming-code\": \"sample\"\n" +
+ "},\n" +
+ "\"related-to\": [{\n" +
+ "\"id\": \"sample\",\n" +
+ "\"relationship-label\": \"sample\",\n" +
+ "\"node-type\": \"sample\",\n" +
+ "\"url\": \"sample\"\n" +
+ "\t}]\n" +
+ "}";
+
+ @Test
+ public void shouldProperlyConvertJsonToVnfResult() throws IOException {
+ VnfResult vnfResult = OBJECT_MAPPER.readValue(VNF_RESULT_JSON, VnfResult.class);
+
+ assertThat(vnfResult.nodeType).isEqualTo("sampleNodeType");
+ assertThat(vnfResult.id).isEqualTo("sample");
+ assertThat(vnfResult.url).isEqualTo("sample");
+ assertThat(vnfResult.relatedTo).hasSize(1);
+ assertThat(vnfResult.properties.globalCustomerId).isEqualTo("sample");
+ assertThat(vnfResult.getAdditionalProperties()).isEmpty();
+ }
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java
index 3ed59ed38..e64b2ac55 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/AAIRestInterfaceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* VID
* ================================================================================
- * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018 - 2019 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.
@@ -20,80 +20,276 @@
package org.onap.vid.aai.util;
-import org.junit.Test;
+
+import org.mockito.Mock;
+import org.mockito.Mockito;
+
+import org.onap.vid.aai.ExceptionWithRequestInfo;
+import org.onap.vid.aai.exceptions.InvalidPropertyException;
+import org.onap.vid.exceptions.GenericUncheckedException;
+import org.onap.vid.utils.Unchecked;
+import org.springframework.http.HttpMethod;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.util.Optional;
+import java.util.UUID;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor;
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static javax.ws.rs.core.Response.Status.*;
+import static junit.framework.TestCase.assertSame;
+import static junit.framework.TestCase.fail;
+import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
public class AAIRestInterfaceTest {
- /*
- TO BE IMPLEMENTED
-
+ private static final String PATH = "path";
+ private static final String HTTP_LOCALHOST = "http://localhost/";
+ @Mock
+ private Client client;
+ @Mock
+ private WebTarget webTarget;
+ @Mock
+ private Invocation.Builder builder;
+ @Mock
+ private Invocation invocation;
+ @Mock
+ private ServletRequestHelper servletRequestHelper;
+ @Mock
+ private HttpsAuthClient httpsAuthClient;
+ @Mock
+ private HttpServletRequest httpServletRequest;
+ @Mock
+ private Response response;
+ @Mock
+ private SystemPropertyHelper systemPropertyHelper;
+
+ private AAIRestInterface testSubject;
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ initMocks(this);
+ mockSystemProperties();
+ testSubject = createTestSubject();
+ when(client.target(HTTP_LOCALHOST+PATH)).thenReturn(webTarget);
+ when(webTarget.request()).thenReturn(builder);
+ when(builder.accept(Mockito.anyString())).thenReturn(builder);
+ when(builder.header(Mockito.anyString(), Mockito.anyString())).thenReturn(builder);
+ when(builder.build(Mockito.anyString())).thenReturn(invocation);
+ when(builder.build(Mockito.anyString(), any(Entity.class))).thenReturn(invocation);
+ when(invocation.invoke()).thenReturn(response);
+ when(servletRequestHelper.extractOrGenerateRequestId()).thenReturn(UUID.randomUUID().toString());
+ }
+
private AAIRestInterface createTestSubject() {
- return new AAIRestInterface("");
+ return new AAIRestInterface(Optional.of(client), httpsAuthClient, servletRequestHelper, systemPropertyHelper);
}
@Test
- public void testEncodeURL() throws Exception {
- AAIRestInterface testSubject;
- String nodeKey = "";
- String result;
+ public void shouldEncodeURL() throws Exception {
+ String nodeKey = "some unusual uri";
+ String nodeKey2 = "some/usual/uri";
+ Assert.assertEquals(testSubject.encodeURL(nodeKey), "some%20unusual%20uri");
+ Assert.assertEquals(testSubject.encodeURL(nodeKey2), "some%2Fusual%2Furi");
+ }
- // default test
- testSubject = createTestSubject();
- result = testSubject.encodeURL(nodeKey);
+ @Test
+ public void shouldSetRestSrvrBaseURL() {
+ String baseUrl = "anything";
+ testSubject.setRestSrvrBaseURL(baseUrl);
+ Assert.assertEquals(testSubject.getRestSrvrBaseURL(), baseUrl);
}
@Test
- public void testSetRestSrvrBaseURL() throws Exception {
- AAIRestInterface testSubject;
- String baseURL = "";
+ public void shouldExecuteRestJsonPutMethodWithResponse200() {
+ // given
+ String payload = "{\"id\": 1}";
+ Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
- // test 1
- testSubject = createTestSubject();
- baseURL = null;
- testSubject.SetRestSrvrBaseURL(baseURL);
+ // when
+ when(response.getStatusInfo()).thenReturn(OK);
+ Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
- // test 2
- testSubject = createTestSubject();
- baseURL = "";
- testSubject.SetRestSrvrBaseURL(baseURL);
+ // then
+ verify(builder).build(HttpMethod.PUT.name(), entity);
+ Assert.assertEquals(response, finalResponse);
+ }
+
+ @Test(expectedExceptions = {ExceptionWithRequestInfo.class})
+ public void shouldFailWhenRestJsonPutMethodExecuted() {
+ // given
+ String payload = "{\"id\": 1}";
+
+ // when
+ when(builder.build(eq(HttpMethod.PUT.name()), any(Entity.class))).thenThrow(new GenericUncheckedException("msg"));
+ testSubject.RestPut("", PATH, payload, false, true);
+
+ //then
}
@Test
- public void testGetRestSrvrBaseURL() throws Exception {
- AAIRestInterface testSubject;
- String result;
+ public void shouldExecuteRestJsonPutMethodWithResponse400() {
+ // given
+ String payload = "{\"id\": 1}";
+ Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
- // default test
- testSubject = createTestSubject();
- result = testSubject.getRestSrvrBaseURL();
+ // when
+ when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
+ when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
+ Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
+
+ // then
+ verify(builder).build(HttpMethod.PUT.name(), entity);
+ Assert.assertEquals(response, finalResponse);
}
+ @Test
+ public void shouldExecuteRestPostMethodWithResponse200() {
+ // given
+ String payload = "{\"id\": 1}";
+ Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
+
+ // when
+ when(builder.post(Mockito.any(Entity.class))).thenReturn(response);
+ when(response.getStatusInfo()).thenReturn(OK);
+ Response finalResponse = testSubject.RestPost("", PATH, payload, false);
+
+ // then
+ verify(builder).post(entity);
+ Assert.assertEquals(response, finalResponse);
+ }
@Test
- public void testRestPut() throws Exception {
- AAIRestInterface testSubject;
- String fromAppId = "";
- String transId = "";
- String path = "";
- String payload = "";
- boolean xml = false;
-
- // default test
- testSubject = createTestSubject();
- testSubject.RestPut(fromAppId, transId, path, payload, xml);
+ public void shouldExecuteRestPostMethodWithResponse400() {
+ // given
+ String payload = "{\"id\": 1}";
+ Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
+
+ // when
+ when(builder.post(Mockito.any(Entity.class))).thenReturn(response);
+ when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
+ when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
+ Response finalResponse = testSubject.RestPost("", PATH, payload, false);
+
+ // then
+ verify(builder).post(entity);
+ Assert.assertEquals(response, finalResponse);
}
@Test
- public void testRestPost() throws Exception {
- AAIRestInterface testSubject;
- String fromAppId = "";
- String transId = "";
- String path = "";
- String payload = "";
- boolean xml = false;
-
- // default test
- testSubject = createTestSubject();
- testSubject.RestPost(fromAppId, transId, path, payload, xml);
- }*/
+ public void shouldFailWhenRestPostMethodExecuted() {
+ // given
+ String payload = "{\"id\": 1}";
+ Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
+
+ // when
+ when(builder.post(Mockito.any(Entity.class))).thenThrow(new RuntimeException());
+ Response finalResponse = testSubject.RestPost("", PATH, payload, false);
+
+ // then
+ verify(builder).post(entity);
+ Assert.assertNull(finalResponse);
+ }
+
+ @Test
+ public void shouldExecuteRestDeleteMethodWithResponse400() {
+ // given
+ // when
+ when(builder.delete()).thenReturn(response);
+ when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
+ String reason = "Any reason";
+ when(response.readEntity(String.class)).thenReturn(reason);
+ when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
+ boolean finalResponse = testSubject.Delete("", "", PATH);
+
+ // then
+ verify(builder).delete();
+ Assert.assertFalse(finalResponse);
+ }
+
+ @Test
+ public void shouldExecuteRestDeleteMethodWithResponse404() {
+ // given
+ // when
+ when(builder.delete()).thenReturn(response);
+ when(response.getStatusInfo()).thenReturn(NOT_FOUND);
+ String reason = "Any reason";
+ when(response.readEntity(String.class)).thenReturn(reason);
+ when(response.getStatus()).thenReturn(NOT_FOUND.getStatusCode());
+ boolean finalResponse = testSubject.Delete("", "", PATH);
+
+ // then
+ verify(builder).delete();
+ Assert.assertFalse(finalResponse);
+ }
+
+ @Test
+ public void shouldFailWhenRestDeleteExecuted() {
+ // given
+ // when
+ when(builder.delete()).thenThrow(new RuntimeException());
+ boolean finalResponse = testSubject.Delete("", "", PATH);
+ // then
+ verify(builder).delete();
+ Assert.assertFalse(finalResponse);
+ }
+
+ @Test
+ public void shouldExecuteRestGetMethodWithResponse200() {
+ // given
+ // when
+ when(response.getStatusInfo()).thenReturn(OK);
+ Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
+
+ // then
+ Assert.assertEquals(response, finalResponse);
+ }
+
+ @Test
+ public void shouldExecuteRestGetMethodWithResponse400() {
+ // given
+ // when
+ when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
+ when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
+ Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
+
+ // then
+ Assert.assertEquals(response, finalResponse);
+ }
+
+ @Test
+ public void shouldFailWhenRestGetMethodExecuted() {
+ // given
+ // when
+ when(builder.build(HttpMethod.GET.name())).thenThrow(new RuntimeException());
+ Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
+
+ // then
+ Assert.assertNull(finalResponse);
+ }
+
+ private void mockSystemProperties() throws UnsupportedEncodingException, InvalidPropertyException {
+ when(systemPropertyHelper.getEncodedCredentials()).thenReturn("someCredentials");
+ when(systemPropertyHelper.getFullServicePath(Mockito.anyString())).thenReturn("http://localhost/path");
+ when(systemPropertyHelper.getFullServicePath(Mockito.any(URI.class))).thenReturn("http://localhost/path");
+ when(systemPropertyHelper.getServiceBasePath(Mockito.anyString())).thenReturn("http://localhost/path");
+ }
+
}
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
deleted file mode 100644
index 3393aa7c1..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
+++ /dev/null
@@ -1,315 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * VID
- * ================================================================================
- * Copyright (C) 2018 - 2019 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.aai.util;
-
-
-import org.mockito.Mock;
-import org.mockito.Mockito;
-
-import org.onap.vid.aai.ExceptionWithRequestInfo;
-import org.onap.vid.aai.exceptions.InvalidPropertyException;
-import org.onap.vid.exceptions.GenericUncheckedException;
-import org.onap.vid.utils.Unchecked;
-import org.springframework.http.HttpMethod;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.util.Optional;
-import java.util.UUID;
-
-import static javax.ws.rs.core.Response.Status.*;
-import static junit.framework.TestCase.fail;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
-
-
-public class SingleAAIRestInterfaceTest {
-
- private static final String PATH = "path";
- private static final String HTTP_LOCALHOST = "http://localhost/";
- @Mock
- private Client client;
- @Mock
- private WebTarget webTarget;
- @Mock
- private Invocation.Builder builder;
- @Mock
- private Invocation invocation;
- @Mock
- private ServletRequestHelper servletRequestHelper;
- @Mock
- private HttpsAuthClient httpsAuthClient;
- @Mock
- private HttpServletRequest httpServletRequest;
- @Mock
- private Response response;
- @Mock
- private SystemPropertyHelper systemPropertyHelper;
-
- private AAIRestInterface testSubject;
-
- @BeforeMethod
- public void setUp() throws Exception {
- initMocks(this);
- mockSystemProperties();
- testSubject = createTestSubject();
- when(client.target(HTTP_LOCALHOST+PATH)).thenReturn(webTarget);
- when(webTarget.request()).thenReturn(builder);
- when(builder.accept(Mockito.anyString())).thenReturn(builder);
- when(builder.header(Mockito.anyString(), Mockito.anyString())).thenReturn(builder);
- when(builder.build(Mockito.anyString())).thenReturn(invocation);
- when(builder.build(Mockito.anyString(), any(Entity.class))).thenReturn(invocation);
- when(invocation.invoke()).thenReturn(response);
- when(servletRequestHelper.extractOrGenerateRequestId()).thenReturn(UUID.randomUUID().toString());
- }
-
- private AAIRestInterface createTestSubject() {
- return new AAIRestInterface(Optional.of(client), httpsAuthClient, servletRequestHelper, systemPropertyHelper);
- }
-
- @Test
- public void testEncodeURL() throws Exception {
- String nodeKey = "some unusual uri";
- Assert.assertEquals(testSubject.encodeURL(nodeKey), "some%20unusual%20uri");
- }
-
- @Test
- public void testSetRestSrvrBaseURLWithNullValue() {
- testSubject.SetRestSrvrBaseURL(null);
- }
-
- @Test
- public void testSetRestSrvrBaseURL() {
- String baseUrl = "anything";
- testSubject.SetRestSrvrBaseURL(baseUrl);
- Assert.assertEquals(testSubject.getRestSrvrBaseURL(), baseUrl);
- }
-
- @Test
- public void testRestJsonPutWithResponse200() {
- // given
- String methodName = "RestPut";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(response.getStatusInfo()).thenReturn(OK);
- Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
-
- // then
- verify(builder).build(HttpMethod.PUT.name(), entity);
- Assert.assertEquals(response, finalResponse);
- }
-
- @Test(expectedExceptions = {ExceptionWithRequestInfo.class})
- public void testFailedRestJsonPut() {
- // given
- String methodName = "RestPut";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(builder.build(eq(HttpMethod.PUT.name()), any(Entity.class))).thenThrow(new GenericUncheckedException("msg"));
- Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
-
- // then
- fail("expected unreachable: exception to be thrown");
- }
-
- @Test
- public void testRestJsonPutWithResponse400() {
- // given
- String methodName = "RestPut";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
- when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
- Response finalResponse = testSubject.RestPut("", PATH, payload, false, true).getResponse();
-
- // then
- verify(builder).build(HttpMethod.PUT.name(), entity);
- Assert.assertEquals(response, finalResponse);
- }
-
- @Test
- public void testRestPostWithResponse200() {
- // given
- String methodName = "RestPost";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(builder.post(Mockito.any(Entity.class))).thenReturn(response);
- when(response.getStatusInfo()).thenReturn(OK);
- Response finalResponse = testSubject.RestPost("", PATH, payload, false);
-
- // then
- verify(builder).post(entity);
- Assert.assertEquals(response, finalResponse);
- }
-
- @Test
- public void testRestPostWithResponse400() {
- // given
- String methodName = "RestPost";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(builder.post(Mockito.any(Entity.class))).thenReturn(response);
- when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
- when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
- Response finalResponse = testSubject.RestPost("", PATH, payload, false);
-
- // then
- verify(builder).post(entity);
- Assert.assertEquals(response, finalResponse);
- }
-
- @Test
- public void testFailedRestPost() {
- // given
- String methodName = "RestPost";
- String payload = "{\"id\": 1}";
- Entity<String> entity = Entity.entity(payload, MediaType.APPLICATION_JSON);
-
- // when
- when(builder.post(Mockito.any(Entity.class))).thenThrow(new RuntimeException());
- Response finalResponse = testSubject.RestPost("", PATH, payload, false);
-
- // then
- verify(builder).post(entity);
- Assert.assertEquals(finalResponse, null);
- }
-
- @Test
- public void testRestDeleteWithResponse400() {
- // given
- String methodName = "Delete";
-
- // when
- when(builder.delete()).thenReturn(response);
- when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
- String reason = "Any reason";
- when(response.readEntity(String.class)).thenReturn(reason);
- when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
- boolean finalResponse = testSubject.Delete("", "", PATH);
-
- // then
- verify(builder).delete();
- Assert.assertFalse(finalResponse);
- }
-
- @Test
- public void testRestDeleteWithResponse404() {
- // given
- String methodName = "Delete";
-
- // when
- when(builder.delete()).thenReturn(response);
- when(response.getStatusInfo()).thenReturn(NOT_FOUND);
- String reason = "Any reason";
- when(response.readEntity(String.class)).thenReturn(reason);
- when(response.getStatus()).thenReturn(NOT_FOUND.getStatusCode());
- boolean finalResponse = testSubject.Delete("", "", PATH);
-
- // then
- verify(builder).delete();
- Assert.assertFalse(finalResponse);
- }
-
- @Test
- public void testFailedRestDelete() {
- // given
- String methodName = "Delete";
-
- // when
- when(builder.delete()).thenThrow(new RuntimeException());
- boolean finalResponse = testSubject.Delete("", "", PATH);
-
- // then
- verify(builder).delete();
- Assert.assertFalse(finalResponse);
- }
-
- @Test
- public void testRestJsonGetWithResponse200() {
- // given
- String methodName = "RestGet";
-
- // when
- when(response.getStatusInfo()).thenReturn(OK);
- Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
-
- // then
- Assert.assertEquals(response, finalResponse);
- }
-
- @Test
- public void testRestJsonGetWithResponse400() {
- // given
- String methodName = "RestGet";
-
- // when
- when(response.getStatusInfo()).thenReturn(BAD_REQUEST);
- when(response.getStatus()).thenReturn(BAD_REQUEST.getStatusCode());
- Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
-
- // then
- Assert.assertEquals(response, finalResponse);
- }
-
- @Test
- public void testFailedRestGet() {
- // given
- String methodName = "RestGet";
-
- // when
- when(builder.build(HttpMethod.GET.name())).thenThrow(new RuntimeException());
- Response finalResponse = testSubject.RestGet("", "", Unchecked.toURI(PATH), false).getResponse();
-
- // then
- Assert.assertEquals(finalResponse, null);
- }
-
- private void mockSystemProperties() throws UnsupportedEncodingException, InvalidPropertyException {
- when(systemPropertyHelper.getEncodedCredentials()).thenReturn("someCredentials");
- when(systemPropertyHelper.getFullServicePath(Mockito.anyString())).thenReturn("http://localhost/path");
- when(systemPropertyHelper.getFullServicePath(Mockito.any(URI.class))).thenReturn("http://localhost/path");
- when(systemPropertyHelper.getServiceBasePath(Mockito.anyString())).thenReturn("http://localhost/path");
- }
-
-}
diff --git a/vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java b/vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java
index 9f1dc84c0..1b50681fc 100644
--- a/vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/bl/AaiServiceTest.java
@@ -20,15 +20,29 @@
package org.onap.vid.bl;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.arrayWithSize;
+import static org.hamcrest.Matchers.equalTo;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.vid.aai.AaiClientInterface;
import org.onap.vid.aai.AaiResponse;
-import org.onap.vid.aai.model.*;
+import org.onap.vid.aai.model.AaiGetPnfResponse;
import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
+import org.onap.vid.aai.model.LogicalLinkResponse;
+import org.onap.vid.aai.model.Relationship;
+import org.onap.vid.aai.model.RelationshipData;
+import org.onap.vid.aai.model.RelationshipList;
+import org.onap.vid.aai.model.ServiceRelationships;
import org.onap.vid.roles.Role;
import org.onap.vid.roles.RoleValidator;
import org.onap.vid.services.AaiServiceImpl;
@@ -36,16 +50,6 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.arrayWithSize;
-import static org.hamcrest.Matchers.equalTo;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-
public class AaiServiceTest {
@InjectMocks
@@ -164,7 +168,7 @@ public class AaiServiceTest {
AaiResponse<GetTenantsResponse[]> aaiResponse = new AaiResponse<>(getTenantsResponses, null, 200);
Mockito.doReturn(aaiResponse).when(aaiClientInterface).getTenants(serviceGlobalCustomerId, serviceServiceType);
Role role = new Role(null, userGlobalCustomerId, userServiceType, userTenantName);
- RoleValidator roleValidator = new RoleValidator(Collections.singletonList(role));
+ RoleValidator roleValidator = RoleValidator.by(Collections.singletonList(role));
AaiResponse<GetTenantsResponse[]> actualTenants = aaiService.getTenants(serviceGlobalCustomerId, serviceServiceType, roleValidator);
assertThat(actualTenants.getT(), arrayWithSize(1));
diff --git a/vid-app-common/src/test/java/org/onap/vid/changeManagement/RequestParametersTest.java b/vid-app-common/src/test/java/org/onap/vid/changeManagement/RequestParametersTest.java
new file mode 100644
index 000000000..8651981e4
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/changeManagement/RequestParametersTest.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2019 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.changeManagement;
+
+import org.testng.annotations.Test;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class RequestParametersTest {
+
+ @Test
+ public void shouldHaveProperSettersAndGetters() {
+ assertThat(RequestParameters.class, hasValidGettersAndSetters());
+ }
+
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/changeManagement/UIWorkflowsRequestTest.java b/vid-app-common/src/test/java/org/onap/vid/changeManagement/UIWorkflowsRequestTest.java
new file mode 100644
index 000000000..cf2a05377
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/changeManagement/UIWorkflowsRequestTest.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2019 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.changeManagement;
+
+import org.testng.annotations.Test;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class UIWorkflowsRequestTest {
+
+ @Test
+ public void shouldHaveProperSettersAndGetters() {
+ assertThat(UIWorkflowsRequest.class, hasValidGettersAndSetters());
+ }
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/changeManagement/WorkflowRequestDetailTest.java b/vid-app-common/src/test/java/org/onap/vid/changeManagement/WorkflowRequestDetailTest.java
new file mode 100644
index 000000000..38f15d7e5
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/changeManagement/WorkflowRequestDetailTest.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2019 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.changeManagement;
+
+import org.testng.annotations.Test;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class WorkflowRequestDetailTest {
+
+ @Test
+ public void shouldHaveProperSettersAndGetters() {
+ assertThat(WorkflowRequestDetail.class, hasValidGettersAndSetters());
+ }
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
index 6d4508dbf..a7676d152 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 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.
@@ -20,57 +21,94 @@
package org.onap.vid.controller;
-import com.google.common.collect.ImmutableList;
+import static org.mockito.BDDMockito.given;
+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.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
-import org.mockito.InjectMocks;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.onap.vid.aai.AaiResponseTranslator;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData;
+import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataError;
+import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataOk;
+import org.onap.vid.aai.model.PortDetailsTranslator.PortDetails;
+import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsError;
+import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsOk;
+import org.onap.vid.aai.util.AAIRestInterface;
+import org.onap.vid.roles.RoleProvider;
import org.onap.vid.services.AaiService;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.util.Map;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
+import org.onap.vid.utils.SystemPropertiesWrapper;
+import org.springframework.http.MediaType;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+@RunWith(MockitoJUnitRunner.class)
public class AaiControllerTest {
- @InjectMocks
- AaiController aaiController = new AaiController();
-
+ private static final String ID_1 = "id1";
+ private static final String ID_2 = "id2";
+ @Mock
+ private AaiService aaiService;
+ @Mock
+ private AAIRestInterface aaiRestInterface;
+ @Mock
+ private RoleProvider roleProvider;
@Mock
- AaiService aaiService;
+ private SystemPropertiesWrapper systemPropertiesWrapper;
- @BeforeMethod
- public void initMocks(){
- MockitoAnnotations.initMocks(this);
+ private MockMvc mockMvc;
+ private AaiController aaiController;
+
+ @Before
+ public void setUp() {
+ aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper);
+ mockMvc = MockMvcBuilders.standaloneSetup(aaiController).build();
}
@Test
- public void getPortMirroringConfigData_givenThreeIds_ReturnsThreeResults() {
-
- final AaiResponseTranslator.PortMirroringConfigDataOk toBeReturnedForA = new AaiResponseTranslator.PortMirroringConfigDataOk("foobar");
- final AaiResponseTranslator.PortMirroringConfigDataError toBeReturnedForB = new AaiResponseTranslator.PortMirroringConfigDataError("foo", "{ baz: qux }");
- final AaiResponseTranslator.PortMirroringConfigDataOk toBeReturnedForC = new AaiResponseTranslator.PortMirroringConfigDataOk("corge");
-
- Mockito
- .doReturn(toBeReturnedForA)
- .doReturn(toBeReturnedForB)
- .doReturn(toBeReturnedForC)
- .when(aaiService).getPortMirroringConfigData(Mockito.anyString());
-
- final Map<String, AaiResponseTranslator.PortMirroringConfigData> result = aaiController.getPortMirroringConfigsData(ImmutableList.of("a", "b", "c"));
-
- assertThat(result, is(ImmutableMap.of(
- "a", toBeReturnedForA,
- "b", toBeReturnedForB,
- "c", toBeReturnedForC
- )));
+ public void getPortMirroringConfigData_givenIds_shouldReturnConfigDataMappedById() throws Exception {
+ PortMirroringConfigDataOk okConfigData = new PortMirroringConfigDataOk("foo");
+ PortMirroringConfigDataError errorConfigData = new PortMirroringConfigDataError("bar", "{ baz: qux }");
+ Map<String, PortMirroringConfigData> expectedJson = ImmutableMap.of(
+ ID_1, okConfigData,
+ ID_2, errorConfigData);
+ given(aaiService.getPortMirroringConfigData(ID_1)).willReturn(okConfigData);
+ given(aaiService.getPortMirroringConfigData(ID_2)).willReturn(errorConfigData);
+
+ mockMvc
+ .perform(get("/aai_getPortMirroringConfigsData")
+ .param("configurationIds", ID_1, ID_2)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(new ObjectMapper().writeValueAsString(expectedJson)));
}
-
-
+ @Test
+ public void getPortMirroringSourcePorts_givenIds_shouldReturnPortDetailsMappedById() throws Exception {
+ PortDetailsOk portDetailsOk = new PortDetailsOk("foo", "testInterface", true);
+ PortDetailsError portDetailsError = new PortDetailsError("bar", "{ baz: qux }");
+ Multimap<String, PortDetails> expectedJson = ImmutableMultimap.of(
+ ID_1, portDetailsOk,
+ ID_2, portDetailsError);
+ given(aaiService.getPortMirroringSourcePorts(ID_1)).willReturn(Lists.newArrayList(portDetailsOk));
+ given(aaiService.getPortMirroringSourcePorts(ID_2)).willReturn(Lists.newArrayList(portDetailsError));
+
+ mockMvc
+ .perform(get("/aai_getPortMirroringSourcePorts")
+ .param("configurationIds", ID_1, ID_2)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().json(new ObjectMapper().writeValueAsString(expectedJson.asMap())));
+ }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java
new file mode 100644
index 000000000..80836d155
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/ControllersUtilsTest.java
@@ -0,0 +1,144 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2019 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.controller;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.then;
+import static org.mockito.Mockito.mock;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.vid.model.ExceptionResponse;
+import org.onap.vid.utils.SystemPropertiesWrapper;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ControllersUtilsTest {
+
+ private static final String USER_ATTRIBUTE = "userAttribute";
+ @Mock
+ private SystemPropertiesWrapper systemPropertiesWrapper;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private HttpServletRequest httpServletRequest;
+
+ @Test
+ public void shouldExtractLoginIdAsUserId_fromHttpServletRequest() {
+ // GIVEN
+ String expectedUserId = "rootUser";
+ given(systemPropertiesWrapper.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).willReturn(USER_ATTRIBUTE);
+ User user = new User();
+ user.setLoginId(expectedUserId);
+ given(httpServletRequest.getSession().getAttribute(USER_ATTRIBUTE)).willReturn(user);
+
+ // WHEN
+ String loginId = new ControllersUtils(systemPropertiesWrapper).extractUserId(httpServletRequest);
+
+ // THEN
+ assertThat(loginId).isEqualTo(expectedUserId);
+ }
+
+ @Test
+ public void shouldExtractOrgUserIdAsUserId_fromHttpServletRequest_whenLoginIdIsNull() {
+ // GIVEN
+ String expectedUserId = "secondUser";
+ given(systemPropertiesWrapper.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).willReturn(USER_ATTRIBUTE);
+ User user = new User();
+ user.setOrgUserId(expectedUserId);
+ given(httpServletRequest.getSession().getAttribute(USER_ATTRIBUTE)).willReturn(user);
+
+ // WHEN
+ String loginId = new ControllersUtils(systemPropertiesWrapper).extractUserId(httpServletRequest);
+
+ // THEN
+ assertThat(loginId).isEqualTo(expectedUserId);
+ }
+
+ @Test
+ public void shouldReturnEmptyString_whenBothLoginIdAndOrgUserIdAreNull() {
+ // GIVEN
+ given(systemPropertiesWrapper.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).willReturn(USER_ATTRIBUTE);
+ given(httpServletRequest.getSession().getAttribute(USER_ATTRIBUTE)).willReturn(new User());
+
+ // WHEN
+ String loginId = new ControllersUtils(systemPropertiesWrapper).extractUserId(httpServletRequest);
+
+ // THEN
+ assertThat(loginId).isEmpty();
+ }
+
+ @Test
+ public void shouldReturnEmptyString_whenSessionIsNull() {
+ // GIVEN
+ given(httpServletRequest.getSession()).willReturn(null);
+
+ // WHEN
+ String loginId = new ControllersUtils(systemPropertiesWrapper).extractUserId(httpServletRequest);
+
+ // THEN
+ assertThat(loginId).isEmpty();
+ }
+
+ @Test
+ public void shouldReturnEmptyString_whenUserIsNull() {
+ // GIVEN
+ given(systemPropertiesWrapper.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).willReturn(USER_ATTRIBUTE);
+ given(httpServletRequest.getSession().getAttribute(USER_ATTRIBUTE)).willReturn(null);
+
+ // WHEN
+ String loginId = new ControllersUtils(systemPropertiesWrapper).extractUserId(httpServletRequest);
+
+ // THEN
+ assertThat(loginId).isEmpty();
+ }
+
+ @Test
+ public void shouldCreateResponseEntity_fromGivenException() {
+ // GIVEN
+ EELFLoggerDelegate eelfLoggerDelegate = mock(EELFLoggerDelegate.class);
+ Response response = mock(Response.class);
+ given(response.getStatus()).willReturn(HttpStatus.OK.value());
+ WebApplicationException webApplicationException = new WebApplicationException("ErrorMessage", response);
+
+ // WHEN
+ ResponseEntity responseEntity = ControllersUtils
+ .handleWebApplicationException(webApplicationException, eelfLoggerDelegate);
+
+ // THEN
+ assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
+ assertThat(responseEntity.getBody())
+ .isInstanceOfSatisfying(ExceptionResponse.class,
+ er -> assertThat(er.getMessage()).isEqualTo("ErrorMessage (Request id: null)"));
+ then(eelfLoggerDelegate).should()
+ .error(EELFLoggerDelegate.errorLogger, "{}: {}", "handleWebApplicationException",
+ ExceptionUtils.getMessage(webApplicationException), webApplicationException);
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java
index abdf31572..36af92c0c 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/ServicePermissionsTest.java
@@ -20,14 +20,6 @@
package org.onap.vid.controller;
-import org.jetbrains.annotations.NotNull;
-import org.onap.vid.aai.model.Permissions;
-import org.onap.vid.roles.RoleProvider;
-import org.onap.vid.roles.RoleValidator;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
@@ -37,6 +29,14 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import org.jetbrains.annotations.NotNull;
+import org.onap.vid.aai.model.Permissions;
+import org.onap.vid.roles.RoleProvider;
+import org.onap.vid.roles.RoleValidator;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
public class ServicePermissionsTest {
@DataProvider
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/WorkflowsControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/WorkflowsControllerTest.java
new file mode 100644
index 000000000..50f78b23d
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/WorkflowsControllerTest.java
@@ -0,0 +1,140 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2019 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.controller;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.joshworks.restclient.http.HttpResponse;
+import io.joshworks.restclient.http.JsonMapper;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.StatusLine;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.message.BasicStatusLine;
+import org.mockito.Mock;
+import org.onap.vid.changeManagement.UIWorkflowsRequest;
+import org.onap.vid.changeManagement.WorkflowRequestDetail;
+import org.onap.vid.mso.MsoUtil;
+import org.onap.vid.mso.model.CloudConfiguration;
+import org.onap.vid.services.ChangeManagementService;
+import org.onap.vid.services.ExternalWorkflowsService;
+import org.onap.vid.services.LocalWorkflowsService;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.ResultActions;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.MediaType;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+public class WorkflowsControllerTest {
+
+ private static final String VID_WORKFLOWS = "/workflows-management/{serviceInstanceId}/{vnfInstanceId}/{workflow_UUID}";
+
+ private MockMvc mockMvc;
+
+ private WorkflowsController workflowsController;
+
+ @Mock
+ private ExternalWorkflowsService externalWorkflowsService;
+
+ @Mock
+ private LocalWorkflowsService localWorkflowsService;
+
+ @Mock
+ private ChangeManagementService changeManagementService;
+
+ @BeforeClass
+ public void setUp(){
+ initMocks(this);
+ workflowsController = new WorkflowsController(externalWorkflowsService,localWorkflowsService,changeManagementService);
+ mockMvc = MockMvcBuilders.standaloneSetup(workflowsController).build();
+ }
+
+ @Test
+ public void shouldProperlyReceivePostRequestFromUI() throws Exception {
+ // given
+ HttpResponse<String> expectedResponse = createOkResponse();
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ UIWorkflowsRequest uiWorkflowsRequest = new UIWorkflowsRequest();
+
+ WorkflowRequestDetail workflowRequestDetail = createWorkflowRequestDetail();
+
+ uiWorkflowsRequest.setRequestDetails(workflowRequestDetail);
+
+ UUID serviceInstanceId = new UUID(1,10);
+ UUID vnfInstanceId = new UUID(2,20);
+ UUID workflow_UUID = new UUID(3,30);
+
+ given(changeManagementService.invokeVnfWorkflow(
+ any(HttpServletRequest.class), eq(uiWorkflowsRequest.getRequestDetails()),eq(serviceInstanceId),eq(vnfInstanceId), eq(workflow_UUID)
+ )).willReturn(MsoUtil.wrapResponse(expectedResponse));
+
+ // when
+ ResultActions response = mockMvc.perform( post(VID_WORKFLOWS,serviceInstanceId,vnfInstanceId,workflow_UUID)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(objectMapper.writeValueAsString(uiWorkflowsRequest)));
+
+ //then
+ response.andExpect(status().isOk());
+ }
+
+ private WorkflowRequestDetail createWorkflowRequestDetail() {
+ WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail();
+ org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters();
+ HashMap<String,String> paramsMap = new HashMap<>();
+ paramsMap.put("testKey1","testValue1");
+ paramsMap.put("testKey2","testValue2");
+
+ List<Map<String,String>> mapArray= new ArrayList<>();
+ mapArray.add(paramsMap);
+ requestParameters.setUserParams(mapArray);
+
+ CloudConfiguration cloudConfiguration = new CloudConfiguration();
+ cloudConfiguration.setCloudOwner("testOwne");
+ cloudConfiguration.setTenantId("testId");
+ cloudConfiguration.setLcpCloudRegionId("testLcpCloudId");
+
+ workflowRequestDetail.setRequestParameters(requestParameters);
+ workflowRequestDetail.setCloudConfiguration(cloudConfiguration);
+ return workflowRequestDetail;
+ }
+
+ private HttpResponse<String> createOkResponse() {
+ StatusLine statusline = new BasicStatusLine(
+ new ProtocolVersion("http",1,1), 200, "acceptResponse");
+
+ org.apache.http.HttpResponse responseBase = new BasicHttpResponse(statusline);
+
+ return new HttpResponse<>(responseBase ,String.class, new JsonMapper());
+ }
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/HealthCheckControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/open/HealthCheckControllerTest.java
index 49e6645bc..76ee5617b 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/HealthCheckControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/open/HealthCheckControllerTest.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.vid.controller;
+package org.onap.vid.controller.open;
import org.apache.log4j.BasicConfigurator;
import org.junit.Before;
@@ -26,6 +26,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.vid.controller.open.HealthCheckController;
import org.onap.vid.dao.FnAppDoaImpl;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/MaintenanceControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/open/MaintenanceControllerTest.java
index b9193810a..3e78828f0 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/MaintenanceControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/open/MaintenanceControllerTest.java
@@ -1,4 +1,4 @@
-package org.onap.vid.controller;
+package org.onap.vid.controller.open;
/*-
* ============LICENSE_START=======================================================
@@ -35,6 +35,7 @@ import org.onap.vid.category.AddCategoryOptionResponse;
import org.onap.vid.category.AddCategoryOptionsRequest;
import org.onap.vid.category.CategoryParameterOptionRep;
import org.onap.vid.category.CategoryParametersResponse;
+import org.onap.vid.controller.open.MaintenanceController;
import org.onap.vid.model.CategoryParameter;
import org.onap.vid.model.CategoryParameterOption;
import org.onap.vid.services.CategoryParameterService;
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/RoleGeneratorControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/open/RoleGeneratorControllerTest.java
index c5b4a55dc..c1509d956 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/RoleGeneratorControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/open/RoleGeneratorControllerTest.java
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.vid.controller;
+package org.onap.vid.controller.open;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -32,6 +32,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.vid.controller.open.RoleGeneratorController;
import org.onap.vid.services.RoleGeneratorService;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/VersionControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/open/VersionControllerTest.java
index f92a26ea7..835ea4a66 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/VersionControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/open/VersionControllerTest.java
@@ -18,8 +18,9 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.vid.controller;
+package org.onap.vid.controller.open;
+import org.onap.vid.controller.open.VersionController;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
diff --git a/vid-app-common/src/test/java/org/onap/vid/job/command/InstanceGroupCommandTest.java b/vid-app-common/src/test/java/org/onap/vid/job/command/InstanceGroupCommandTest.java
index 47ec44ca7..b4a5c64f5 100644
--- a/vid-app-common/src/test/java/org/onap/vid/job/command/InstanceGroupCommandTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/job/command/InstanceGroupCommandTest.java
@@ -20,8 +20,14 @@
package org.onap.vid.job.command;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.only;
+import static org.mockito.Mockito.same;
+import static org.mockito.Mockito.verify;
+
import com.google.common.collect.ImmutableMap;
-import org.apache.commons.beanutils.BeanUtils;
+import java.util.Optional;
import org.mockito.Answers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
@@ -32,19 +38,11 @@ import org.onap.vid.model.serviceInstantiation.InstanceGroup;
import org.onap.vid.mso.RestMsoImplementation;
import org.onap.vid.mso.model.ModelInfo;
import org.onap.vid.services.AsyncInstantiationBusinessLogic;
+import org.onap.vid.testUtils.TestUtils;
import org.springframework.http.HttpMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.Optional;
-import java.util.Set;
-
-import static java.util.function.Function.identity;
-import static java.util.stream.Collectors.toMap;
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.*;
-
public class InstanceGroupCommandTest {
@Mock(answer = Answers.RETURNS_MOCKS)
@@ -73,7 +71,7 @@ public class InstanceGroupCommandTest {
@Test
public void createMyself_callsMso() {
- final ModelInfo serviceModelInfo = setRandomStrings(new ModelInfo());
+ final ModelInfo serviceModelInfo = setStrings(new ModelInfo());
final String serviceInstanceId = "service-instance-id";
final String userId = "ff3223";
@@ -92,14 +90,7 @@ public class InstanceGroupCommandTest {
}
- private ModelInfo setRandomStrings(ModelInfo object) {
- try {
- Set<String> fields = BeanUtils.describe(object).keySet();
- BeanUtils.populate(object,
- fields.stream().collect(toMap(identity(), s -> randomAlphanumeric(4))));
- return object;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ private ModelInfo setStrings(ModelInfo object) {
+ return TestUtils.setStringsInStringProperties(object);
}
}
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 39d777be9..4494f4872 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
@@ -26,6 +26,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.joshworks.restclient.http.HttpResponse;
import org.apache.commons.io.IOUtils;
import org.jetbrains.annotations.NotNull;
+import org.mockito.hamcrest.MockitoHamcrest;
+import org.onap.vid.changeManagement.WorkflowRequestDetail;
+import org.onap.vid.model.SOWorkflowList;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -60,15 +63,22 @@ import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.UUID;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.hasEntry;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
@@ -94,6 +104,12 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
private MsoInterface msoInterface;
@Mock
+ private SOWorkflowList workflowList;
+
+ @Mock
+ private HttpResponse<SOWorkflowList> workflowListResponse;
+
+ @Mock
private RequestDetails msoRequest;
@@ -1329,6 +1345,65 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests {
MsoBusinessLogicImpl.RequestType.fromValue(testValue);
}
+ @Test
+ public void shouldProperlyInvokeVnfWorkflowWithValidParameters() {
+ // given
+ MsoResponseWrapper okResponse = createOkResponse();
+ WorkflowRequestDetail request = createWorkflowRequestDetail();
+ UUID serviceInstanceId = new UUID(1,10);
+ UUID vnfInstanceId = new UUID(2,20);
+ UUID workflow_UUID = new UUID(3,30);
+ String path = "/onap/so/infra/instanceManagement/v1/serviceInstances/"+serviceInstanceId+"/vnfs/"+vnfInstanceId+"/workflows/"+workflow_UUID;
+
+ given(msoInterface.invokeWorkflow(eq(request), eq(path), MockitoHamcrest.argThat(allOf(hasEntry("X-RequestorID", "testRequester"),hasEntry("X-ONAP-PartnerName", "VID"))))).willReturn(okResponse);
+
+ // when
+ MsoResponseWrapper response = msoBusinessLogic.invokeVnfWorkflow(request, "testRequester", serviceInstanceId, vnfInstanceId, workflow_UUID);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(okResponse);
+ }
+
+
+ @Test
+ public void shouldReturnWorkflowListForGivenModelId() {
+ given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse);
+ given(workflowListResponse.getBody()).willReturn(workflowList);
+ given(workflowListResponse.getStatus()).willReturn(HttpStatus.ACCEPTED.value());
+
+ SOWorkflowList workflows = msoBusinessLogic.getWorkflowListByModelId("sampleModelId");
+
+ assertThat(workflows).isEqualTo(workflowList);
+ }
+
+ @Test(expectedExceptions = {MsoBusinessLogicImpl.WorkflowListException.class})
+ public void shouldRaiseExceptionWhenRetrievingWorkflowsFailed() {
+ given(msoInterface.getWorkflowListByModelId(anyString())).willReturn(workflowListResponse);
+ given(workflowListResponse.getStatus()).willReturn(HttpStatus.INTERNAL_SERVER_ERROR.value());
+
+ msoBusinessLogic.getWorkflowListByModelId("sampleModelId");
+ }
+
+ private WorkflowRequestDetail createWorkflowRequestDetail() {
+ WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail();
+ org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters();
+ HashMap<String,String> paramsMap = new HashMap<>();
+ paramsMap.put("testKey1","testValue1");
+ paramsMap.put("testKey2","testValue2");
+
+ List<Map<String,String>> mapArray= new ArrayList<>();
+ mapArray.add(paramsMap);
+ requestParameters.setUserParams(mapArray);
+
+ CloudConfiguration cloudConfiguration = new CloudConfiguration();
+ cloudConfiguration.setCloudOwner("testOwne");
+ cloudConfiguration.setTenantId("testId");
+ cloudConfiguration.setLcpCloudRegionId("testLcpCloudId");
+
+ workflowRequestDetail.setRequestParameters(requestParameters);
+ workflowRequestDetail.setCloudConfiguration(cloudConfiguration);
+ return workflowRequestDetail;
+ }
private OperationalEnvironmentActivateInfo createTestOperationalEnvironmentActivateInfo() {
OperationalEnvironmentController.OperationalEnvironmentActivateBody operationalEnvironmentActivateBody = new OperationalEnvironmentController.OperationalEnvironmentActivateBody(
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
index 4cba53785..102c89ac1 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
@@ -24,11 +24,11 @@ import io.joshworks.restclient.request.HttpRequest;
import org.glassfish.jersey.client.JerseyInvocation;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.aai.util.HttpsAuthClient;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.mso.rest.RequestDetails;
+import org.onap.vid.utils.SystemPropertiesWrapper;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
@@ -72,15 +72,19 @@ public class RestMsoImplementationTest {
@Mock
private JerseyInvocation jerseyInvocation;
+ @Mock
+ private SystemPropertiesWrapper systemProperties;
+
@InjectMocks
- private RestMsoImplementation restMsoImplementation = new RestMsoImplementation(mockHttpsAuthClient);
+ private RestMsoImplementation restMsoImplementation = new RestMsoImplementation(mockHttpsAuthClient, systemProperties);
- String path = "/test_path/";
- String rawData = "test-row-data";
+ private String path = "/test_path/";
+ private String rawData = "test-row-data";
@BeforeClass
public void setUp(){
initMocks(this);
+ when(systemProperties.getProperty(MsoProperties.MSO_PASSWORD)).thenReturn("OBF:1ghz1kfx1j1w1m7w1i271e8q1eas1hzj1m4i1iyy1kch1gdz");
}
@Test
@@ -127,7 +131,8 @@ public class RestMsoImplementationTest {
RestObject<HttpRequest> restObject = new RestObject<>();
prepareMocks("",HttpStatus.ACCEPTED.value(),"");
- when(mockClient.target(SystemProperties.getProperty(MsoProperties.MSO_SERVER_URL))).thenThrow(new MsoTestException("test-target-exception"));
+ when(systemProperties.getProperty(MsoProperties.MSO_SERVER_URL)).thenReturn("SAMPLE_URL");
+ when(mockClient.target("SAMPLE_URL")).thenThrow(new MsoTestException("test-target-exception"));
// when
restMsoImplementation.Get(httpRequest, "", restObject,false);
@@ -418,4 +423,4 @@ public class RestMsoImplementationTest {
}
}
-} \ No newline at end of file
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
index f58462dd6..832aa098a 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientNewTest.java
@@ -20,8 +20,18 @@
*/
package org.onap.vid.mso.rest;
+import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
+import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
+
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xebialabs.restito.server.StubServer;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Properties;
+import java.util.UUID;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -35,19 +45,9 @@ import org.onap.vid.mso.MsoProperties;
import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.MsoResponseWrapperInterface;
import org.onap.vid.mso.RestObject;
+import org.onap.vid.utils.SystemPropertiesWrapper;
import org.springframework.test.context.ContextConfiguration;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Properties;
-import java.util.UUID;
-
-import static org.onap.vid.controller.MsoController.SVC_INSTANCE_ID;
-import static org.onap.vid.controller.MsoController.VNF_INSTANCE_ID;
-
@ContextConfiguration(classes = {SystemProperties.class})
public class MsoRestClientNewTest {
@@ -280,16 +280,39 @@ public class MsoRestClientNewTest {
}
@Test
- public void testGetManualTasks() {
+ public void testGetManualTasksByRequestId() {
String p = props.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ);
String path = p + "/" + UUID.randomUUID();
+ String validResponse = ""
+ + "{ "
+ + " \"taskList\": [ "
+ + " { "
+ + " \"taskId\": \"daf4dd84-b77a-42da-a051-3239b7a9392c\", "
+ + " \"type\": \"fallout\", "
+ + " \"nfRole\": \"vEsmeralda\", "
+ + " \"subscriptionServiceType\": \"Emanuel\", "
+ + " \"originalRequestId\": \"d352c70d-5ef8-4977-9ea8-4c8cbe860422\", "
+ + " \"originalRequestorId\": \"ss835w\", "
+ + " \"errorSource\": \"A&AI\", "
+ + " \"errorCode\": \"404\", "
+ + " \"errorMessage\": \"Failed in A&AI 404\", "
+ + " \"validResponses\": [ "
+ + " \"rollback\", "
+ + " \"abort\", "
+ + " \"skip\", "
+ + " \"resume\", "
+ + " \"retry\" "
+ + " ] "
+ + " } "
+ + " ] "
+ + "}";
try(MsoRestClientTestUtil closure = new MsoRestClientTestUtil(
server,
path,
HttpStatus.OK_200,
- CREATE_INSTANCE_RESPONSE_STR,CREATE_INSTANCE_RESPONSE_STR)) {
- closure.executeGet(msoRestClient()::getManualTasks);
+ validResponse,validResponse)) {
+ closure.executeGet(endpoint -> msoRestClient().getManualTasksByRequestId(null, null, endpoint, null));
}
}
@@ -311,23 +334,6 @@ public class MsoRestClientNewTest {
}
@Test
- public void testGetManualTasksByRequestId() throws Exception {
- MsoRestClientNew testSubject;
- String t = "";
- String sourceId = "";
- String endpoint = "";
- RestObject restObject = null;
- MsoResponseWrapper result;
-
- // default test
- try {
- testSubject = createTestSubject();
- result = testSubject.getManualTasksByRequestId(t, sourceId, endpoint, restObject);
- } catch (Exception e) {
- }
- }
-
- @Test
public void testCompleteManualTask() throws Exception {
MsoRestClientNew testSubject;
RequestDetails requestDetails = null;
@@ -468,10 +474,10 @@ public class MsoRestClientNewTest {
private MsoRestClientNew msoRestClient() {
final WebConfig webConfig = new WebConfig();
- return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper())), baseUrl(),null);
+ return new MsoRestClientNew(new SyncRestClient(webConfig.unirestFasterxmlObjectMapper(new ObjectMapper())), baseUrl(), null, new SystemPropertiesWrapper());
}
private MsoRestClientNew createTestSubject() {
- return new MsoRestClientNew(null, "",null);
+ return new MsoRestClientNew(null, "", null, new SystemPropertiesWrapper());
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
index 7caafed00..050fa0dce 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTest.java
@@ -20,35 +20,51 @@
*/
package org.onap.vid.mso.rest;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
import io.joshworks.restclient.http.HttpResponse;
import io.joshworks.restclient.http.JsonMapper;
import org.apache.http.ProtocolVersion;
import org.apache.http.StatusLine;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicStatusLine;
+import org.jetbrains.annotations.NotNull;
import org.mockito.Mock;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
+import org.onap.vid.changeManagement.RequestParameters;
+import org.onap.vid.changeManagement.WorkflowRequestDetail;
import org.onap.vid.client.SyncRestClient;
import org.onap.vid.controller.LocalWebConfig;
import org.onap.vid.model.RequestReferencesContainer;
+import org.onap.vid.mso.MsoProperties;
import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.MsoResponseWrapperInterface;
import org.onap.vid.mso.MsoUtil;
import org.onap.vid.mso.RestObject;
+import org.onap.vid.mso.model.CloudConfiguration;
import org.onap.vid.mso.model.RequestReferences;
+import org.onap.vid.utils.SystemPropertiesWrapper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import static org.mockito.ArgumentMatchers.any;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
+import static org.mockito.ArgumentMatchers.refEq;
+import static org.mockito.hamcrest.MockitoHamcrest.argThat;
@ContextConfiguration(classes = {LocalWebConfig.class, SystemProperties.class})
@@ -61,14 +77,18 @@ public class MsoRestClientTest {
@Mock
private SyncRestClient client;
+ @Mock
+ private SystemPropertiesWrapper systemProperties;
+
private MsoRestClientNew restClient;
@BeforeClass
private void setUp(){
initMocks(this);
- restClient = new MsoRestClientNew(client,baseUrl,null);
-
+ when(systemProperties.getProperty(MsoProperties.MSO_PASSWORD)).thenReturn("OBF:1ghz1kfx1j1w1m7w1i271e8q1eas1hzj1m4i1iyy1kch1gdz");
+ when(systemProperties.getProperty("app_display_name")).thenReturn("vid");
+ restClient = new MsoRestClientNew(client,baseUrl,null,systemProperties);
}
@Test
@@ -391,22 +411,6 @@ public class MsoRestClientTest {
}
@Test
- public void shouldProperlyGetManualTasks() {
- // given
- String endpoint = "testEndpoint";
- HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
- MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
-
- when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
-
- // when
- MsoResponseWrapper response = restClient.getManualTasks(endpoint);
-
- // then
- assertThat(response).isEqualToComparingFieldByField(expectedResponse);
- }
-
- @Test
public void shouldProperlyGetManualTasksByRequestId() {
// given
RestObject restObject = generateMockMsoRestObject();
@@ -415,8 +419,7 @@ public class MsoRestClientTest {
HttpResponse<String> httpResponse = HttpResponse.fallback("testOkResponse");
MsoResponseWrapper expectedResponse = MsoUtil.wrapResponse(httpResponse);
- /// WUT 'baseUrl+baseUrl+endpoint'
- when( client.get( eq(baseUrl+baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
+ when( client.get( eq(baseUrl+endpoint),anyMap(),anyMap(),eq(String.class) ) ).thenReturn(httpResponse);
// when
MsoResponseWrapper response = restClient.getManualTasksByRequestId(null,null,endpoint,restObject);
@@ -428,7 +431,7 @@ public class MsoRestClientTest {
@Test(expectedExceptions = MsoTestException.class)
public void shouldThrowExceptionWhenGetManualTasksByRequestIdGetsWrongParameter() {
// given
- when( client.get( eq(baseUrl+baseUrl),anyMap(),anyMap(),eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
+ when( client.get( eq(baseUrl),anyMap(),anyMap(),eq(String.class) ) ).thenThrow(new MsoTestException("testsException"));
// when
restClient.getManualTasksByRequestId(null,null,"",null);
@@ -766,6 +769,34 @@ public class MsoRestClientTest {
assertThat(expectedResponse).isEqualToComparingFieldByField(response);
}
+ @Test
+ public void shouldProperlyInvokeWorkflows() {
+ // given
+ String endpoint = "testPath";
+ HttpResponse expectedResponse = createOkResponse();
+
+ WorkflowRequestDetail workflowRequestDetail = MsoRestClientTestUtil.createWorkflowRequestDetail();
+
+ RequestDetailsWrapper<WorkflowRequestDetail> requestDetailsWrapper = new RequestDetailsWrapper<>(workflowRequestDetail);
+
+ UUID requestId = UUID.randomUUID();
+
+ when(client.post(eq(baseUrl + endpoint), argThat(allOf(hasEntry("X-ONAP-RequestID", requestId.toString()),hasEntry("Content-Type", "application/json"))), refEq(requestDetailsWrapper))).
+ thenReturn(expectedResponse);
+
+ Map<String,String> extraHeaders = new HashMap<>();
+ extraHeaders.put("X-ONAP-RequestID",requestId.toString());
+ extraHeaders.put("X-ONAP-PartnerName","VID");
+ extraHeaders.put("X-RequestorID","testRequester");
+
+ // when
+ MsoResponseWrapper response = restClient.invokeWorkflow(workflowRequestDetail, endpoint, extraHeaders);
+
+ // then
+ assertThat(response).isEqualToComparingFieldByField(MsoUtil.wrapResponse(expectedResponse));
+
+ }
+
private class MsoTestException extends RuntimeException{
MsoTestException(String testException) {
super(testException);
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
index 1720e0467..f66235728 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/MsoRestClientTestUtil.java
@@ -31,18 +31,21 @@ import static com.xebialabs.restito.semantics.Condition.method;
import static com.xebialabs.restito.semantics.Condition.post;
import static com.xebialabs.restito.semantics.Condition.uri;
import static com.xebialabs.restito.semantics.Condition.withHeader;
+import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xebialabs.restito.semantics.Action;
import com.xebialabs.restito.server.StubServer;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
-
import org.glassfish.grizzly.http.Method;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.json.JSONObject;
@@ -50,6 +53,7 @@ import org.junit.Assert;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.changeManagement.RelatedInstanceList;
import org.onap.vid.changeManagement.RequestDetailsWrapper;
+import org.onap.vid.changeManagement.WorkflowRequestDetail;
import org.onap.vid.mso.MsoResponseWrapper;
import org.onap.vid.mso.model.CloudConfiguration;
import org.onap.vid.mso.model.ModelInfo;
@@ -116,6 +120,7 @@ class MsoRestClientTestUtil implements AutoCloseable {
MsoResponseWrapper response = func.apply(sampleRequestDetails, endpoint);
Assert.assertEquals(expectedStatus.getStatusCode(), response.getStatus());
+ assertJsonEquals(expectedResponseStr, response.getEntity());
verifyServer(server, endpoint, Method.DELETE);
}
@@ -127,6 +132,7 @@ class MsoRestClientTestUtil implements AutoCloseable {
MsoResponseWrapper response = func.apply(endpoint);
Assert.assertEquals(expectedStatus.getStatusCode(), response.getStatus());
+ assertJsonEquals(expectedResponseStr, response.getEntity());
verifyServer(server, endpoint, Method.GET);
}
@@ -198,6 +204,27 @@ class MsoRestClientTestUtil implements AutoCloseable {
return requestDetails;
}
+ static WorkflowRequestDetail createWorkflowRequestDetail() {
+ WorkflowRequestDetail workflowRequestDetail = new WorkflowRequestDetail();
+ org.onap.vid.changeManagement.RequestParameters requestParameters = new org.onap.vid.changeManagement.RequestParameters();
+ HashMap<String,String> paramsMap = new HashMap<>();
+ paramsMap.put("testKey1","testValue1");
+ paramsMap.put("testKey2","testValue2");
+
+ List<Map<String,String>> mapArray= new ArrayList<>();
+ mapArray.add(paramsMap);
+ requestParameters.setUserParams(mapArray);
+
+ CloudConfiguration cloudConfiguration = new CloudConfiguration();
+ cloudConfiguration.setCloudOwner("testOwne");
+ cloudConfiguration.setTenantId("testId");
+ cloudConfiguration.setLcpCloudRegionId("testLcpCloudId");
+
+ workflowRequestDetail.setRequestParameters(requestParameters);
+ workflowRequestDetail.setCloudConfiguration(cloudConfiguration);
+ return workflowRequestDetail;
+ }
+
private void verifyServer(StubServer server, String endpoint, Method httpMethod) {
verifyHttp(server).once(
method(httpMethod),
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskTest.java
index 5d1e480fe..d78627557 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/rest/TaskTest.java
@@ -20,15 +20,90 @@
package org.onap.vid.mso.rest;
-import org.testng.annotations.Test;
-
import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
+import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableList;
+import java.io.IOException;
+import org.onap.vid.testUtils.TestUtils;
+import org.testng.annotations.Test;
+
public class TaskTest {
+ private final ObjectMapper mapper = new ObjectMapper();
+
+ private String templateTaskJson(String insertion) {
+ return ""
+ + "{ "
+ + " \"taskId\": \"taskId\", "
+ + " \"type\": \"type\", "
+ + " \"nfRole\": \"nfRole\", "
+ + " \"subscriptionServiceType\": \"subscriptionServiceType\", "
+ + " \"originalRequestId\": \"originalRequestId\", "
+ + " \"originalRequestorId\": \"originalRequestorId\", "
+ + " \"buildingBlockName\": \"buildingBlockName\", "
+ + " \"buildingBlockStep\": \"buildingBlockStep\", "
+ + " \"errorSource\": \"errorSource\", "
+ + " \"errorCode\": \"errorCode\", "
+ + " \"errorMessage\": \"errorMessage\", "
+ + insertion
+ + " \"validResponses\": [ "
+ + " \"a\", "
+ + " \"b\", "
+ + " \"c\" "
+ + " ] "
+ + "} ";
+ }
+
+ private final String TASK_JSON = templateTaskJson(""
+ + " \"description\": \"description\", "
+ + " \"timeout\": \"timeout\", "
+ );
+
+ private final String TASK_JSON_WITHOUT_TIMEOUT = templateTaskJson("");
+
+ private Task newTaskWithPopulatedFields() {
+ Task task = TestUtils.setStringsInStringProperties(new Task());
+ task.setValidResponses(ImmutableList.of("a", "b", "c"));
+ return task;
+ }
+
@Test
public void shouldHaveProperSettersAndGetters() {
assertThat(Task.class, hasValidGettersAndSetters());
}
+
+ @Test
+ public void serializeTask() throws IOException {
+ assertThat(
+ mapper.writeValueAsString(newTaskWithPopulatedFields()),
+ jsonEquals(TASK_JSON)
+ );
+ }
+
+ @Test
+ public void deserializeTask() throws IOException {
+ assertThat(
+ mapper.readValue(TASK_JSON, Task.class),
+ is(newTaskWithPopulatedFields())
+ );
+ }
+
+ @Test
+ public void deserializeTaskWithoutTimeout() throws IOException {
+ /*
+ SO may return no timeout, and therefore no description as well
+ */
+ final Task taskWithoutTimeout = newTaskWithPopulatedFields();
+ taskWithoutTimeout.setDescription(null);
+ taskWithoutTimeout.setTimeout(null);
+
+ assertThat(
+ mapper.readValue(TASK_JSON_WITHOUT_TIMEOUT, Task.class),
+ is(taskWithoutTimeout)
+ );
+ }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/VnfResultTest.java b/vid-app-common/src/test/java/org/onap/vid/roles/AlwaysValidRoleValidatorTest.java
index 6f403d9da..363c6ff76 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/VnfResultTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/roles/AlwaysValidRoleValidatorTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -18,36 +18,26 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.vid.aai;
+package org.onap.vid.roles;
-import org.junit.Test;
-import org.onap.vid.aai.model.VnfResult;
+import static org.testng.Assert.assertTrue;
-import java.util.Map;
+import org.testng.annotations.Test;
-public class VnfResultTest {
+public class AlwaysValidRoleValidatorTest {
- private VnfResult createTestSubject() {
- return new VnfResult();
- }
+ @Test
+ public void testIsSubscriberPermitted() {
+ assertTrue(new AlwaysValidRoleValidator().isSubscriberPermitted("any"));
+ }
- @Test
- public void testGetAdditionalProperties() throws Exception {
- VnfResult testSubject;
- Map<String, Object> result;
+ @Test
+ public void testIsServicePermitted() {
+ assertTrue(new AlwaysValidRoleValidator().isServicePermitted("any", "any"));
+ }
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAdditionalProperties();
- }
-
- @Test
- public void testSetAdditionalProperty() throws Exception {
- VnfResult testSubject;
- String name = "";
- Object value = null;
-
- // default test
- testSubject = createTestSubject();
- }
-}
+ @Test
+ public void testIsTenantPermitted() {
+ assertTrue(new AlwaysValidRoleValidator().isTenantPermitted("any", "any", "any"));
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorTest.java b/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByRolesTest.java
index 69ec3458e..9362ec9d7 100644
--- a/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/roles/RoleValidatorByRolesTest.java
@@ -21,18 +21,17 @@
package org.onap.vid.roles;
+import static org.assertj.core.api.Assertions.assertThat;
+
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.Map;
import org.onap.vid.mso.rest.RequestDetails;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.List;
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class RoleValidatorTest {
+public class RoleValidatorByRolesTest {
private static final String SAMPLE_SUBSCRIBER = "sampleSubscriber";
private static final String NOT_MATCHING_SUBSCRIBER = "notMatchingSubscriber";
@@ -47,12 +46,11 @@ public class RoleValidatorTest {
private Map<String, Object> requestParameters = ImmutableMap.of("subscriptionServiceType", SAMPLE_SERVICE_TYPE);
private Map<String, Object> requestDetailsProperties = ImmutableMap.of("subscriberInfo", subscriberInfo, "requestParameters", requestParameters);
private RequestDetails requestDetails;
- private RoleValidator roleValidator;
+ private RoleValidatorByRoles roleValidator;
@BeforeMethod
public void setUp() {
- roleValidator = new RoleValidator(roles);
- roleValidator.enableRoles();
+ roleValidator = new RoleValidatorByRoles(roles);
requestDetails = new RequestDetails();
}
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 23951aa3d..e9f94ca0e 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
@@ -8,9 +8,9 @@
* 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.
@@ -23,24 +23,37 @@ package org.onap.vid.services;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.ws.rs.core.Response;
+import org.jeasy.random.EasyRandom;
+import org.jeasy.random.EasyRandomParameters;
+import org.jeasy.random.randomizers.misc.BooleanRandomizer;
+import org.jeasy.random.randomizers.text.StringRandomizer;
import org.junit.Test;
import org.onap.vid.aai.AaiClientInterface;
import org.onap.vid.aai.AaiGetVnfResponse;
import org.onap.vid.aai.AaiOverTLSClientInterface;
import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.AaiResponseTranslator;
+import org.onap.vid.aai.model.AaiGetServicesRequestModel.GetServicesAAIRespone;
import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
import org.onap.vid.aai.model.VnfResult;
import org.onap.vid.roles.RoleValidator;
+import org.onap.vid.roles.RoleValidatorByRoles;
public class AaiServiceImplTest {
+ private static final long STATIC_SEED = 5336L;
+ private EasyRandomParameters parameters = new EasyRandomParameters()
+ .randomize(String.class, new StringRandomizer(4, 4, STATIC_SEED))
+ .randomize(Boolean.class, new BooleanRandomizer(STATIC_SEED));
+ private EasyRandom modelGenerator = new EasyRandom(parameters);
+
private AaiClientInterface aaiClient = mock(AaiClientInterface.class);
private AaiOverTLSClientInterface aaiSslClient = mock(AaiOverTLSClientInterface.class);
private AaiResponseTranslator aaiResponseTranslator = mock(AaiResponseTranslator.class);
@@ -125,7 +138,7 @@ public class AaiServiceImplTest {
when(response.getT()).thenReturn(new GetTenantsResponse[]{ permittedTenant, unpermittedTenant });
when(aaiClient.getTenants(globalCustomerId, serviceType)).thenReturn(response);
- RoleValidator roleValidator = mock(RoleValidator.class);
+ RoleValidator roleValidator = mock(RoleValidatorByRoles.class);
when(roleValidator.isTenantPermitted(globalCustomerId, serviceType, "permitted_tenant")).thenReturn(true);
when(roleValidator.isTenantPermitted(globalCustomerId, serviceType, "unpermitted_tenant")).thenReturn(false);
@@ -185,4 +198,81 @@ public class AaiServiceImplTest {
assertThat(response).isEqualTo(actual);
assertThat(response.getT().results).containsOnly(genericVnf, serviceInstance);
}
-}
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void getServicesShouldMarkAllServicesAsPermitted() {
+ // given
+ RoleValidator roleValidator = modelGenerator.nextObject(RoleValidatorByRoles.class);
+
+ GetServicesAAIRespone inputPayload = modelGenerator.nextObject(GetServicesAAIRespone.class);
+ assertThat(inputPayload.service.stream().allMatch(service -> service.isPermitted)).isFalse();
+
+ when(aaiClient.getServices()).thenReturn(new AaiResponse<>(inputPayload, "", 200));
+
+ // when
+ AaiResponse<GetServicesAAIRespone> result = aaiService.getServices(roleValidator);
+ GetServicesAAIRespone outputPayload = result.getT();
+
+ // then
+ assertThat(outputPayload.service.stream().allMatch(service -> service.isPermitted)).isTrue();
+ }
+
+ @Test
+ public void shouldGetNodeTemplateInstances() {
+ // given
+ String globalCustomerId = "gcid";
+ String serviceType = "st";
+ String modelVersionId = "mvid";
+ String modelInvariantId = "miid";
+ String cloudRegion = "cr";
+
+ // when
+ aaiService
+ .getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion);
+
+ // then
+ verify(aaiClient)
+ .getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion);
+ }
+
+ @Test
+ public void shouldGetNetworkCollectionDetails() {
+ // given
+ String serviceInstanceId = "siid";
+
+ // when
+ aaiService.getNetworkCollectionDetails(serviceInstanceId);
+
+ // then
+ verify(aaiClient).getNetworkCollectionDetails(serviceInstanceId);
+ }
+
+ @Test
+ public void shouldGetInstanceGroupsByCloudRegion() {
+ // given
+ String cloudOwner = "co";
+ String cloudRegionId = "crid";
+ String networkFunction = "nf";
+
+ // when
+ aaiService.getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction);
+
+ // then
+ verify(aaiClient).getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction);
+ }
+
+ @Test
+ public void getAAIServiceTree() {
+ // given
+ String globalCustomerId = "gcid";
+ String serviceType = "st";
+ String serviceInstanceId = "siid";
+
+ // when
+ aaiService.getAAIServiceTree(globalCustomerId, serviceType, serviceInstanceId);
+
+ // then
+ verify(aaiServiceTree).getServiceInstanceTopology(globalCustomerId, serviceType, serviceInstanceId);
+ }
+} \ No newline at end of file
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 d001d566a..621c31327 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
@@ -27,6 +27,7 @@ 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.vid.utils.SystemPropertiesWrapper;
import org.springframework.http.ResponseEntity;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -38,16 +39,19 @@ import static org.testng.Assert.assertNull;
public class ChangeManagementServiceImplTest {
@Mock
- DataAccessService dataAccessServiceMock;
+ private DataAccessService dataAccessServiceMock;
@Mock
- MsoBusinessLogic msoBusinessLogicMock;
+ private MsoBusinessLogic msoBusinessLogicMock;
@Mock
- SchedulerRestInterfaceIfc schedulerRestInterface;
+ private SchedulerRestInterfaceIfc schedulerRestInterface;
@Mock
- CloudOwnerService cloudOwnerService;
+ private CloudOwnerService cloudOwnerService;
+
+ @Mock
+ private SystemPropertiesWrapper systemPropertiesWrapper;
@BeforeMethod
public void initMocks(){
@@ -56,14 +60,14 @@ public class ChangeManagementServiceImplTest {
@Test
public void doChangeManagement_requestIsNull_returnsNull() throws Exception {
- ChangeManagementServiceImpl changeManagementService = new ChangeManagementServiceImpl(dataAccessServiceMock, msoBusinessLogicMock, schedulerRestInterface, cloudOwnerService);
+ ChangeManagementServiceImpl changeManagementService = new ChangeManagementServiceImpl(dataAccessServiceMock, msoBusinessLogicMock, schedulerRestInterface, cloudOwnerService, systemPropertiesWrapper);
ResponseEntity<String> result = changeManagementService.doChangeManagement(null,"anyString");
assertNull(result);
}
@Test
public void doChangeManagement_currentRequestDetailsIsNull_returnsNull() throws Exception {
- ChangeManagementServiceImpl changeManagementService = new ChangeManagementServiceImpl(dataAccessServiceMock, msoBusinessLogicMock, schedulerRestInterface, cloudOwnerService);
+ ChangeManagementServiceImpl changeManagementService = new ChangeManagementServiceImpl(dataAccessServiceMock, msoBusinessLogicMock, schedulerRestInterface, cloudOwnerService,systemPropertiesWrapper);
ChangeManagementServiceImpl changeManagementServiceSpied = Mockito.spy(changeManagementService);
Mockito.doReturn(null).when(changeManagementServiceSpied).findRequestByVnfName(Matchers.anyList(),Mockito.anyString());
@@ -121,7 +125,7 @@ public class ChangeManagementServiceImplTest {
}
private RequestDetails callChangeManagement(String requestType) throws Exception {
- ChangeManagementServiceImpl changeManagementService = new ChangeManagementServiceImpl(dataAccessServiceMock, msoBusinessLogicMock, schedulerRestInterface, cloudOwnerService);
+ ChangeManagementServiceImpl changeManagementService = new ChangeManagementServiceImpl(dataAccessServiceMock, msoBusinessLogicMock, schedulerRestInterface, cloudOwnerService,systemPropertiesWrapper);
ChangeManagementServiceImpl changeManagementServiceSpied = Mockito.spy(changeManagementService);
ChangeManagementRequest updateRequest = new ChangeManagementRequest();
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 e638605c1..faa7a6a8d 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
@@ -40,6 +40,7 @@ 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.vid.utils.SystemPropertiesWrapper;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.context.annotation.Bean;
@@ -118,8 +119,8 @@ public class ChangeManagementServiceUnitTest extends AbstractTestNGSpringContext
public static class TestMsoConfig extends MsoConfig {
@Bean
- public ChangeManagementService getChangeManagementService(DataAccessService dataAccessService, MsoBusinessLogic msoInterface, SchedulerRestInterfaceIfc schedulerRestInterface, CloudOwnerService cloudOwnerService) {
- return new ChangeManagementServiceImpl(dataAccessService, msoInterface, schedulerRestInterface, cloudOwnerService);
+ public ChangeManagementService getChangeManagementService(DataAccessService dataAccessService, MsoBusinessLogic msoInterface, SchedulerRestInterfaceIfc schedulerRestInterface, CloudOwnerService cloudOwnerService, SystemPropertiesWrapper systemPropertiesWrapper) {
+ return new ChangeManagementServiceImpl(dataAccessService, msoInterface, schedulerRestInterface, cloudOwnerService, systemPropertiesWrapper);
}
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java
deleted file mode 100644
index 160ba97a5..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * VID
- * ================================================================================
- * Copyright (C) 2017 - 2019 AT&T 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.services;
-
-
-
-import com.google.common.collect.Lists;
-import io.joshworks.restclient.http.HttpResponse;
-import java.util.Collections;
-import java.util.List;
-
-import org.assertj.core.api.Assertions;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-import org.onap.vid.model.SOWorkflow;
-import org.onap.vid.model.SOWorkflowParameterDefinition;
-import org.onap.vid.model.SOWorkflowParameterDefinitions;
-import org.onap.vid.model.SOWorkflowType;
-import org.onap.vid.model.SOWorkflows;
-import org.onap.vid.mso.MsoResponseWrapper2;
-import org.onap.vid.mso.rest.MockedWorkflowsRestClient;
-import org.onap.vid.services.ExternalWorkflowsServiceImpl.BadResponseFromMso;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-public class ExternalWorkflowServiceImplTest {
-
- @Mock
- private MockedWorkflowsRestClient client;
- @Mock
- private HttpResponse<SOWorkflows> response;
-
- @Mock
- private HttpResponse<SOWorkflowParameterDefinitions> parameterDefinitionsHttpResponse;
-
-
- @BeforeMethod
- public void init(){
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void shouldReturnWorkflowsOnValidResponse(){
- // given
- ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client);
- Mockito.when(response.getStatus()).thenReturn(200);
- Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz"))));
- MsoResponseWrapper2<SOWorkflows> msoResponseStub = new MsoResponseWrapper2<>(response);
- Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub);
- // when
- List<SOWorkflow> workflows = extWorkflowsService.getWorkflows("test");
- // then
- Mockito.verify(client).getWorkflows("test");
- Assertions.assertThat(workflows.get(0).getName()).isEqualTo("xyz");
- }
-
- @Test(expectedExceptions = BadResponseFromMso.class)
- public void shouldThrowBadResponseOnInvalidResponse(){
- // given
- ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client);
- Mockito.when(response.getStatus()).thenReturn(500);
- Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz"))));
- MsoResponseWrapper2<SOWorkflows> msoResponseStub = new MsoResponseWrapper2<>(response);
- Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub);
- // when
- extWorkflowsService.getWorkflows("test");
- // then throw exception
- }
- @Test
- public void shouldReturnWorkflowParametersOnValidResponse() {
- SOWorkflowParameterDefinitions parameters = new SOWorkflowParameterDefinitions(Collections.singletonList(new SOWorkflowParameterDefinition(1L, "sample", "[0-9]", SOWorkflowType.STRING, true)));
- ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client);
- Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200);
- Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(parameters);
- MsoResponseWrapper2<SOWorkflowParameterDefinitions> msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse);
- Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper);
-
-
- SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L);
-
- Assertions.assertThat(workflowParameterDefinitions).isEqualTo(parameters);
- }
-
- @Test
- public void shouldProperlyHandleEmptyParametersList(){
- ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client);
- Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200);
- Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(new SOWorkflowParameterDefinitions(Lists.newArrayList()));
-
- MsoResponseWrapper2<SOWorkflowParameterDefinitions> msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse);
- Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper);
-
-
- SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L);
- Assertions.assertThat(workflowParameterDefinitions.getParameterDefinitions()).isEmpty();
- }
-}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowsServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowsServiceImplTest.java
new file mode 100644
index 000000000..94771b29e
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowsServiceImplTest.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2019 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.services;
+
+
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.vid.model.ArtifactInfo;
+import org.onap.vid.model.SOWorkflow;
+import org.onap.vid.model.SOWorkflowList;
+import org.onap.vid.model.WorkflowInputParameter;
+import org.onap.vid.model.WorkflowSource;
+import org.onap.vid.model.WorkflowSpecification;
+import org.onap.vid.model.WorkflowSpecificationWrapper;
+import org.onap.vid.mso.MsoBusinessLogic;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.when;
+
+public class ExternalWorkflowsServiceImplTest {
+
+ @Mock
+ private MsoBusinessLogic msoBusinessLogic;
+
+
+ private static final UUID SAMPLE_UUID = UUID.randomUUID();
+
+ @BeforeMethod
+ public void init() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void shouldReturnWorkflowsOnValidResponse() {
+ // given
+ ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(msoBusinessLogic);
+ WorkflowInputParameter parameter = new WorkflowInputParameter("sampleLabel", "text",
+ true, Collections.EMPTY_LIST, "sampleName", "userParams", "description");
+ SOWorkflowList workflowList = createWorkflowList(parameter);
+ SOWorkflow workflow = new SOWorkflow(SAMPLE_UUID.toString(), "sampleName", WorkflowSource.SDC, Collections.singletonList(parameter));
+ when(msoBusinessLogic.getWorkflowListByModelId("test")).thenReturn(workflowList);
+ // when
+ List<SOWorkflow> workflows = extWorkflowsService.getWorkflows("test");
+ // then
+ assertThat(workflows).hasSize(1).contains(workflow);
+ }
+
+ private SOWorkflowList createWorkflowList(WorkflowInputParameter parameter) {
+ ArtifactInfo artifactInfo = new ArtifactInfo("workflow", SAMPLE_UUID.toString(), "sampleArtifactName",
+ "sampleVersion", "sampleDescription", "sampleName", "sampleOperation", "sdc", "vnf");
+ WorkflowSpecification specification = new WorkflowSpecification(artifactInfo, Collections.EMPTY_LIST, Collections.singletonList(parameter));
+ WorkflowSpecificationWrapper wrapper = new WorkflowSpecificationWrapper(specification);
+ return new SOWorkflowList(Collections.singletonList(wrapper));
+ }
+
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/WorkflowServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/WorkflowServiceImplTest.java
index a8ded2719..fa53a9a80 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/WorkflowServiceImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/WorkflowServiceImplTest.java
@@ -3,13 +3,14 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 - 2020 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.
@@ -20,34 +21,23 @@
package org.onap.vid.services;
-import java.util.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import java.util.Arrays;
+import java.util.Collection;
import org.junit.Test;
public class WorkflowServiceImplTest {
- private WorkflowServiceImpl createTestSubject() {
- return new WorkflowServiceImpl();
- }
-
@Test
- public void testGetWorkflowsForVNFs() throws Exception {
- WorkflowServiceImpl testSubject;
- Collection<String> vnfNames = new ArrayList<String>();
- Collection<String> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getWorkflowsForVNFs(vnfNames);
+ public void testGetWorkflowsForVNFs() {
+ Collection<String> result = new WorkflowServiceImpl().getWorkflowsForVNFs(Arrays.asList("VNF1", "VNF2"));
+ assertThat(result).containsExactly("Upgrade", "Clean", "Reinstall");
}
@Test
- public void testGetAllWorkflows() throws Exception {
- WorkflowServiceImpl testSubject;
- Collection<String> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getAllWorkflows();
+ public void testGetAllWorkflows() {
+ Collection<String> result = new WorkflowServiceImpl().getAllWorkflows();
+ assertThat(result).containsExactly("Upgrade", "Clean", "Reinstall", "Dump", "Flush");
}
}
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 3a7d4690d..3d919d72d 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
@@ -20,6 +20,9 @@
package org.onap.vid.testUtils;
+import static java.util.function.Function.identity;
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
import static org.apache.commons.beanutils.PropertyUtils.getPropertyDescriptors;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.RETURNS_DEFAULTS;
@@ -46,6 +49,7 @@ import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.json.JSONArray;
@@ -55,7 +59,6 @@ import org.mockito.MockSettings;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import org.onap.portalsdk.core.domain.support.DomainVo;
import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.vid.asdc.beans.Service;
import org.springframework.mock.env.MockEnvironment;
@@ -131,12 +134,39 @@ public class TestUtils {
valueType);
}
- public static String[] allPropertiesOf(Class<DomainVo> aClass) {
+ public static String[] allPropertiesOf(Class<?> aClass) {
return Arrays.stream(getPropertyDescriptors(aClass))
.map(PropertyDescriptor::getDisplayName)
.toArray(String[]::new);
}
+ private static <T> List<String> allStringPropertiesOf(T object) {
+ return Arrays.stream(getPropertyDescriptors(object.getClass()))
+ .filter(descriptor -> descriptor.getPropertyType().isAssignableFrom(String.class))
+ .map(PropertyDescriptor::getDisplayName)
+ .collect(toList());
+ }
+
+ /**
+ * Sets each String property with a value equal to the name of
+ * the property; e.g.: { name: "name", city: "city" }
+ * @param object
+ * @param <T>
+ * @return The modified object
+ */
+ public static <T> T setStringsInStringProperties(T object) {
+ try {
+ final List<String> stringFields = allStringPropertiesOf(object);
+
+ BeanUtils.populate(object, stringFields.stream()
+ .collect(toMap(identity(), identity())));
+
+ return object;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
public static class JavaxRsClientMocks {
private final javax.ws.rs.client.Client fakeClient;