regression unit test for getServicesByOwningEntityId 49/101049/4
authorEylon Malin <eylon.malin@intl.att.com>
Mon, 3 Feb 2020 14:06:22 +0000 (16:06 +0200)
committerEylon Malin <eylon.malin@intl.att.com>
Mon, 3 Feb 2020 20:41:57 +0000 (22:41 +0200)
Issue-ID: VID-758
Change-Id: I4e080b6d775feb890f597b1db006e00f8108a987
Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java
vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
vid-app-common/src/test/java/org/onap/vid/services/AaiServiceTest.java
vid-app-common/src/test/resources/responses/aai/listServicesByOwningEntity.json [new file with mode: 0644]
vid-automation/src/main/java/vid/automation/test/test/SearchExistingInstanceTest.java

index be77e2b..1baca9f 100644 (file)
@@ -143,7 +143,7 @@ public class AaiClient implements AaiClientInterface {
     }
 
     @Override
-    public AaiResponse getServicesByOwningEntityId(List<String> owningEntityIds){
+    public AaiResponse<OwningEntityResponse> getServicesByOwningEntityId(List<String> owningEntityIds){
         Response resp = doAaiGet(getUrlFromLIst("business/owning-entities?", "owning-entity-id=", owningEntityIds), false);
         return processAaiResponse(resp, OwningEntityResponse.class, null);
     }
index 5b36828..b39b809 100644 (file)
@@ -29,6 +29,7 @@ import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironme
 import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
 import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
 import org.onap.vid.aai.model.ModelVer;
+import org.onap.vid.aai.model.OwningEntityResponse;
 import org.onap.vid.aai.model.PortDetailsTranslator;
 import org.onap.vid.aai.model.Properties;
 import org.onap.vid.aai.model.ResourceType;
@@ -53,7 +54,7 @@ public interface AaiClientInterface extends ProbeInterface {
 
     AaiResponse getServices();
 
-    AaiResponse getServicesByOwningEntityId(List<String> owningEntityIds);
+    AaiResponse<OwningEntityResponse> getServicesByOwningEntityId(List<String> owningEntityIds);
 
     AaiResponse<GetTenantsResponse[]> getTenants(String globalCustomerId, String serviceType);
 
index 9db8233..a992519 100644 (file)
@@ -173,7 +173,7 @@ public class AaiServiceImpl implements AaiService {
         }
     }
 
-    private List<ServiceInstanceSearchResult> getServicesByOwningEntityId(List<String> owningEntities, RoleValidator roleValidator) {
+    List<ServiceInstanceSearchResult> getServicesByOwningEntityId(List<String> owningEntities, RoleValidator roleValidator) {
         AaiResponse<OwningEntityResponse> owningEntityResponse = aaiClient.getServicesByOwningEntityId(owningEntities);
         List<ServiceInstanceSearchResult> serviceInstanceSearchResultList = new ArrayList<>();
         if (owningEntityResponse.getT() != null) {
index 12774f4..663d862 100644 (file)
 
 package org.onap.vid.services;
 
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
+import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.arrayWithSize;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.nullValue;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
@@ -34,6 +37,7 @@ import static org.testng.Assert.assertNotNull;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -50,13 +54,17 @@ 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.OwningEntityResponse;
 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.model.ServiceInstanceSearchResult;
 import org.onap.vid.model.aaiTree.AAITreeNode;
 import org.onap.vid.roles.RoleValidator;
 import org.onap.vid.roles.RoleValidatorFactory;
+import org.onap.vid.roles.WithPermissionProperties;
+import org.onap.vid.testUtils.TestUtils;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
@@ -276,4 +284,25 @@ public class AaiServiceTest {
         }
     }
 
+    @Test
+    public void testGetServicesByOwningEntityId() {
+        List<String>  owningEntityIds = ImmutableList.of("43b8a85a-0421-4265-9069-117dd6526b8a", "26dcc4aa-725a-447d-8346-aa26dfaa4eb7");
+        RoleValidator roleValidator  = mock(RoleValidator.class);
+
+        OwningEntityResponse owningEntityResponse = TestUtils.readJsonResourceFileAsObject("/responses/aai/listServicesByOwningEntity.json", OwningEntityResponse.class);
+        when(roleValidator.isServicePermitted(any(WithPermissionProperties.class))).thenReturn(true);
+        when(aaiClientInterface.getServicesByOwningEntityId(owningEntityIds)).thenReturn(new AaiResponse<>(owningEntityResponse, "", 200));
+        List<ServiceInstanceSearchResult> result = aaiService.getServicesByOwningEntityId(owningEntityIds, roleValidator);
+
+
+        ServiceInstanceSearchResult expected1 = new ServiceInstanceSearchResult(
+            "af9d52f9-13b2-4657-a198-463677f82dc0", "256cddb4-3aa1-43cc-a08f-315bb50b275e", "MSO-dev-service-type", "xbghrftgr_shani", null, null, null, null, true);
+        ServiceInstanceSearchResult expected2 = new ServiceInstanceSearchResult(
+            "49769492-5def-4c89-8e73-b236f958fa40", "e02fd6f2-7fc2-434b-a92d-15abdb24b68d", "JUST-another-service-type", "fghghfhgf",  null, null, null, null, true);
+        ServiceInstanceSearchResult expected3 = new ServiceInstanceSearchResult(
+            "1d8fd482-2f53-4d62-a7bd-20e4bab14c45", "256cddb4-3aa1-43cc-a08f-315bb50b275e", "MSO-dev-service-type", "Bryant", null, null, null, null, true);
+
+        assertThat(result, jsonEquals(ImmutableList.of(expected1, expected2, expected3)).when(IGNORING_ARRAY_ORDER).whenIgnoringPaths("[*].subscriberName")); //ignore in array
+    }
+
 }
diff --git a/vid-app-common/src/test/resources/responses/aai/listServicesByOwningEntity.json b/vid-app-common/src/test/resources/responses/aai/listServicesByOwningEntity.json
new file mode 100644 (file)
index 0000000..a97a74a
--- /dev/null
@@ -0,0 +1,97 @@
+{
+  "owning-entity": [
+    {
+      "owning-entity-id": "43b8a85a-0421-4265-9069-117dd6526b8a",
+      "owning-entity-name": "Melissa",
+      "resource-version": "1527418700853",
+      "relationship-list": {
+        "relationship": [
+          {
+            "related-to": "service-instance",
+            "relationship-label": "org.onap.relationships.inventory.BelongsTo",
+            "related-link": "/aai/v12/business/customers/customer/256cddb4-3aa1-43cc-a08f-315bb50b275e/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/af9d52f9-13b2-4657-a198-463677f82dc0",
+            "relationship-data": [
+              {
+                "relationship-key": "customer.global-customer-id",
+                "relationship-value": "256cddb4-3aa1-43cc-a08f-315bb50b275e"
+              },
+              {
+                "relationship-key": "service-subscription.service-type",
+                "relationship-value": "MSO-dev-service-type"
+              },
+              {
+                "relationship-key": "service-instance.service-instance-id",
+                "relationship-value": "af9d52f9-13b2-4657-a198-463677f82dc0"
+              }
+            ],
+            "related-to-property": [
+              {
+                "property-key": "service-instance.service-instance-name",
+                "property-value": "xbghrftgr_shani"
+              }
+            ]
+          },
+          {
+            "related-to": "service-instance",
+            "relationship-label": "org.onap.relationships.inventory.BelongsTo",
+            "related-link": "/aai/v12/business/customers/customer/e02fd6f2-7fc2-434b-a92d-15abdb24b68d/service-subscriptions/service-subscription/JUST-another-service-type/service-instances/service-instance/49769492-5def-4c89-8e73-b236f958fa40",
+            "relationship-data": [
+              {
+                "relationship-key": "customer.global-customer-id",
+                "relationship-value": "e02fd6f2-7fc2-434b-a92d-15abdb24b68d"
+              },
+              {
+                "relationship-key": "service-subscription.service-type",
+                "relationship-value": "JUST-another-service-type"
+              },
+              {
+                "relationship-key": "service-instance.service-instance-id",
+                "relationship-value": "49769492-5def-4c89-8e73-b236f958fa40"
+              }
+            ],
+            "related-to-property": [
+              {
+                "property-key": "service-instance.service-instance-name",
+                "property-value": "fghghfhgf"
+              }
+            ]
+          }
+        ]
+      }
+    },
+    {
+      "owning-entity-id": "26dcc4aa-725a-447d-8346-aa26dfaa4eb7",
+      "owning-entity-name": "Kobe",
+      "resource-version": "1527418700844",
+      "relationship-list": {
+        "relationship": [
+          {
+            "related-to": "service-instance",
+            "relationship-label": "org.onap.relationships.inventory.BelongsTo",
+            "related-link": "/aai/v12/business/customers/customer/256cddb4-3aa1-43cc-a08f-315bb50b275e/service-subscriptions/service-subscription/MSO-dev-service-type/service-instances/service-instance/1d8fd482-2f53-4d62-a7bd-20e4bab14c45",
+            "relationship-data": [
+              {
+                "relationship-key": "customer.global-customer-id",
+                "relationship-value": "256cddb4-3aa1-43cc-a08f-315bb50b275e"
+              },
+              {
+                "relationship-key": "service-subscription.service-type",
+                "relationship-value": "MSO-dev-service-type"
+              },
+              {
+                "relationship-key": "service-instance.service-instance-id",
+                "relationship-value": "1d8fd482-2f53-4d62-a7bd-20e4bab14c45"
+              }
+            ],
+            "related-to-property": [
+              {
+                "property-key": "service-instance.service-instance-name",
+                "property-value": "Bryant"
+              }
+            ]
+          }
+        ]
+      }
+    }
+  ]
+}
\ No newline at end of file
index b1d31f8..abeffca 100644 (file)
@@ -1,7 +1,10 @@
 package vid.automation.test.test;
 
-import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
+import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 import vid.automation.test.Constants;
@@ -12,9 +15,6 @@ import vid.automation.test.sections.SideMenu;
 import vid.automation.test.services.BulkRegistration;
 import vid.automation.test.services.SimulatorApi;
 
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
 public class SearchExistingInstanceTest extends VidBaseTestCase {
 
     public static final String serviceIdOeWirelineProjectX1 = "7e4f8130-5dee-47c4-8770-1abc5f5ded83";
@@ -27,7 +27,7 @@ public class SearchExistingInstanceTest extends VidBaseTestCase {
     }
 
     @Test
-    private void testSearchExistingInstanceByOwningEntitySingleValue() {
+    public void testSearchExistingInstanceByOwningEntitySingleValue() {
         SearchExistingPage searchExistingPage = new SearchExistingPage();
         SideMenu.navigateToSearchExistingPage();
         searchExistingPage.searchByOwningEntity("Melissa");