Merge "JUnit tests for MsoMulticloudUtils"
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / client / sdnc / mapper / NetworkTopologyOperationRequestMapperTest.java
index 307fe28..1bfa78a 100644 (file)
@@ -23,15 +23,23 @@ package org.onap.so.client.sdnc.mapper;
 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.HashMap;
+import java.util.Map;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
@@ -45,10 +53,9 @@ import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
 
-import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkOperationInformation;
-import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
+@RunWith(MockitoJUnitRunner.class)
 public class NetworkTopologyOperationRequestMapperTest {
 
        private final static String JSON_FILE_LOCATION = "src/test/resources/__files/BuildingBlocks/";
@@ -59,6 +66,12 @@ public class NetworkTopologyOperationRequestMapperTest {
        private RequestContext requestContext;
        private L3Network network;
        private CloudRegion cloudRegion;
+       
+       @Spy
+       private GeneralTopologyObjectMapper generalTopologyObjectMapper;
+       
+       @InjectMocks
+       private NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
 
        @Before
        public void before() {
@@ -93,10 +106,11 @@ public class NetworkTopologyOperationRequestMapperTest {
                serviceInstance.setCollection(networkCollection);
                //
                requestContext = new RequestContext();
-               HashMap<String, String> userParams = new HashMap<String, String>();
+               Map<String, Object> userParams = new HashMap<>();
                userParams.put("key1", "value1");
                requestContext.setUserParams(userParams);
                requestContext.setProductFamilyId("productFamilyId");
+               requestContext.setMsoRequestId("MsoRequestId");
 
                network = new L3Network();
                network.setNetworkId("TEST_NETWORK_ID");
@@ -115,7 +129,6 @@ public class NetworkTopologyOperationRequestMapperTest {
        @Test
        public void createGenericResourceApiNetworkOperationInformationTest() throws Exception {
 
-               NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
                GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
                                SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
                                requestContext, cloudRegion);
@@ -127,12 +140,27 @@ public class NetworkTopologyOperationRequestMapperTest {
 
                assertThat(networkSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId")
                                .ignoring("requestInformation.requestId"));
+               assertEquals("MsoRequestId", networkSDNCrequest.getRequestInformation().getRequestId());
        }
+       
+       @Test
+       public void createGenericResourceApiNetworkOperationInformationReqContextNullTest() throws Exception {
 
+               RequestContext rc = new RequestContext();
+               rc.setMsoRequestId(null);
+               GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
+                               SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
+                               rc, cloudRegion);
+               assertNotNull(networkSDNCrequest.getRequestInformation().getRequestId());
+               GenericResourceApiNetworkOperationInformation networkSDNCrequest2 = mapper.reqMapper(
+                               SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
+                               null, cloudRegion);
+               assertNotNull(networkSDNCrequest2.getRequestInformation().getRequestId());
+       }
+       
        @Test
        public void reqMapperTest() throws Exception {
 
-               NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
                GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
                                SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer,
                                requestContext, cloudRegion);
@@ -143,7 +171,6 @@ public class NetworkTopologyOperationRequestMapperTest {
 
        @Test
        public void reqMapperNoCollectionTest() throws Exception {
-               NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
                GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(
                                SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstanceNoCollection, customer,
                                requestContext, cloudRegion);
@@ -154,7 +181,7 @@ public class NetworkTopologyOperationRequestMapperTest {
        @Test
        public void createGenericResourceApiNetworkOperationInformation_UnassignTest() throws Exception {
 
-               NetworkTopologyOperationRequestMapper mapperUnassign = new NetworkTopologyOperationRequestMapper();
+               NetworkTopologyOperationRequestMapper mapperUnassign = mapper;
                GenericResourceApiNetworkOperationInformation networkSDNCrequestUnassign = mapperUnassign.reqMapper(
                                SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, GenericResourceApiRequestActionEnumeration.DELETENETWORKINSTANCE, network, serviceInstance, customer,
                                requestContext, cloudRegion);
@@ -166,13 +193,13 @@ public class NetworkTopologyOperationRequestMapperTest {
 
                assertThat(reqMapperUnassign, sameBeanAs(networkSDNCrequestUnassign).ignoring("sdncRequestHeader.svcRequestId")
                                .ignoring("requestInformation.requestId"));
-
+               assertEquals("MsoRequestId", networkSDNCrequestUnassign.getRequestInformation().getRequestId());
+               
        }
        
        @Test
        public void createGenericResourceApiNetworkOperationInformationNoNetworkNameTest() throws Exception {
 
-               NetworkTopologyOperationRequestMapper mapper = new NetworkTopologyOperationRequestMapper();
                //set network name NULL
                network.setNetworkName(null);
                GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper(