Remove this useless eq(...) invocation
[so.git] / adapters / mso-adapter-utils / src / test / java / org / onap / so / openstack / utils / MsoHeatUtilsTest.java
index 4f7fed7..85219c3 100644 (file)
@@ -36,7 +36,6 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -46,6 +45,13 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.Spy;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.db.catalog.beans.HeatTemplate;
+import org.onap.so.db.catalog.beans.NetworkResource;
+import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
+import org.onap.so.db.catalog.beans.VfModule;
+import org.onap.so.db.catalog.beans.VfModuleCustomization;
+import org.onap.so.db.catalog.client.CatalogDbClient;
 import org.onap.so.db.request.beans.CloudApiRequests;
 import org.onap.so.db.request.beans.InfraActiveRequests;
 import org.onap.so.db.request.client.RequestsDbClient;
@@ -53,6 +59,7 @@ import org.onap.so.openstack.beans.CreateStackRequest;
 import org.onap.so.openstack.exceptions.MsoException;
 import org.onap.so.openstack.exceptions.MsoOpenstackException;
 import org.onap.so.openstack.exceptions.MsoStackAlreadyExists;
+import org.slf4j.MDC;
 import org.springframework.core.env.Environment;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.woorea.openstack.base.client.OpenStackResponseException;
@@ -63,6 +70,7 @@ import com.woorea.openstack.heat.StackResource.DeleteStack;
 import com.woorea.openstack.heat.model.CreateStackParam;
 import com.woorea.openstack.heat.model.Resources;
 import com.woorea.openstack.heat.model.Stack;
+import java.util.UUID;
 
 @RunWith(MockitoJUnitRunner.class)
 public class MsoHeatUtilsTest extends MsoHeatUtils {
@@ -101,12 +109,21 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
     @Mock
     private CreateStack mockCreateStack;
 
+    @Mock
+    private CatalogDbClient catalogDbClient;
+
     private String cloudSiteId = "cloudSiteId";
     private String tenantId = "tenantId";
 
+    private String getRequestId() {
+        return MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
+    }
+
     @Before
     public void setup() {
         doReturn("15").when(env).getProperty("org.onap.so.adapters.po.pollInterval", "15");
+        String requestId = UUID.randomUUID().toString();
+        MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
     }
 
     @Test
@@ -117,6 +134,7 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
         stack.setStackStatus("CREATE_IN_PROGRESS");
         stack.setStackStatusReason("Stack Finished");
 
+        String requestId = getRequestId();
         Stack latestStack = new Stack();
         latestStack.setId("id");
         latestStack.setStackName("stackName");
@@ -125,7 +143,7 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
         doReturn(latestStack).when(heatUtils).queryHeatStack(isA(Heat.class), eq("stackName/id"));
         doReturn(heatClient).when(heatUtils).getHeatClient(cloudSiteId, tenantId);
         Stack actual = heatUtils.pollStackForStatus(1, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false);
-        Mockito.verify(stackStatusHandler, times(1)).updateStackStatus(latestStack);
+        Mockito.verify(stackStatusHandler, times(1)).updateStackStatus(latestStack, requestId);
         Mockito.verify(heatUtils, times(1)).queryHeatStack(isA(Heat.class), eq("stackName/id"));
         assertEquals(true, actual != null);
     }
@@ -137,12 +155,13 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
         stack.setStackName("stackName");
         stack.setStackStatus("CREATE_IN_PROGRESS");
         stack.setStackStatusReason("Stack Finished");
-        doNothing().when(stackStatusHandler).updateStackStatus(stack);
+        String requestId = getRequestId();
+        doNothing().when(stackStatusHandler).updateStackStatus(stack, requestId);
         doReturn(stack).when(heatUtils).queryHeatStack(isA(Heat.class), eq("stackName/id"));
         doReturn(heatClient).when(heatUtils).getHeatClient(cloudSiteId, tenantId);
         doReturn("61").when(env).getProperty("org.onap.so.adapters.po.pollInterval", "15");
         Stack actual = heatUtils.pollStackForStatus(1, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false);
-        Mockito.verify(stackStatusHandler, times(1)).updateStackStatus(stack);
+        Mockito.verify(stackStatusHandler, times(1)).updateStackStatus(stack, requestId);
         Mockito.verify(heatUtils, times(1)).queryHeatStack(isA(Heat.class), eq("stackName/id"));
         assertEquals(true, actual != null);
     }
@@ -154,11 +173,12 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
         stack.setStackName("stackName");
         stack.setStackStatus("CREATE_IN_PROGRESS");
         stack.setStackStatusReason("Stack Finished");
-        doNothing().when(stackStatusHandler).updateStackStatus(stack);
+        String requestId = getRequestId();
+        doNothing().when(stackStatusHandler).updateStackStatus(stack, requestId);
         doReturn(stack).when(heatUtils).queryHeatStack(isA(Heat.class), eq("stackName/id"));
         doReturn(heatClient).when(heatUtils).getHeatClient(cloudSiteId, tenantId);
         Stack actual = heatUtils.pollStackForStatus(1, stack, "CREATE_IN_PROGRESS", cloudSiteId, tenantId, false);
-        Mockito.verify(stackStatusHandler, times(5)).updateStackStatus(stack);
+        Mockito.verify(stackStatusHandler, times(5)).updateStackStatus(stack, requestId);
         Mockito.verify(heatUtils, times(5)).queryHeatStack(isA(Heat.class), eq("stackName/id"));
         assertEquals(true, actual != null);
     }
@@ -417,7 +437,9 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
         CreateStackParam createStackParam = new CreateStackParam();
         createStackParam.setStackName("stackName");
 
+        String requestId = getRequestId();
         doReturn(heatClient).when(heatUtils).getHeatClient(cloudSiteId, tenantId);
+        doNothing().when(heatUtils).saveStackRequest(eq(createStackParam), isNull(), eq("stackName"));
         doReturn(stackResource).when(heatClient).getStacks();
         doReturn(mockCreateStack).when(stackResource).create(createStackParam);
 
@@ -425,7 +447,7 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
 
         heatUtils.createStack(createStackParam, cloudSiteId, tenantId);
         Mockito.verify(stackResource, times(1)).create(createStackParam);
-        Mockito.verify(heatUtils, times(1)).saveStackRequest(eq(createStackParam), isNull(), eq("stackName"));
+        Mockito.verify(heatUtils, times(1)).saveStackRequest(createStackParam, requestId, "stackName");
         Mockito.verify(heatClient, times(1)).getStacks();
         Mockito.verify(stackResource, times(1)).create(createStackParam);
     }
@@ -552,4 +574,38 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
         Mockito.verify(heatUtils, times(0)).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId);
     }
 
+    @Test
+    public void testGetVfHeatTimeoutValue() {
+
+        VfModuleCustomization vfmc = new VfModuleCustomization();
+        VfModule vf = new VfModule();
+        HeatTemplate heat = new HeatTemplate();
+        heat.setTimeoutMinutes(110);
+        vf.setModuleHeatTemplate(heat);
+        vfmc.setVfModule(vf);
+
+        Mockito.when(catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID("uuid")).thenReturn(vfmc);
+
+        int timeout = heatUtils.getVfHeatTimeoutValue("uuid", false);
+        assertEquals(110, timeout);
+        Mockito.verify(catalogDbClient, times(1)).getVfModuleCustomizationByModelCuztomizationUUID("uuid");
+    }
+
+    @Test
+    public void testGetNetworkHeatTimeoutValue() {
+
+        NetworkResourceCustomization mc = new NetworkResourceCustomization();
+        NetworkResource nr = new NetworkResource();
+        HeatTemplate heat = new HeatTemplate();
+        heat.setTimeoutMinutes(110);
+        nr.setHeatTemplate(heat);
+        mc.setNetworkResource(nr);
+
+        Mockito.when(catalogDbClient.getNetworkResourceCustomizationByModelCustomizationUUID("uuid")).thenReturn(mc);
+
+        int timeout = heatUtils.getNetworkHeatTimeoutValue("uuid", "type");
+        assertEquals(110, timeout);
+        Mockito.verify(catalogDbClient, times(1)).getNetworkResourceCustomizationByModelCustomizationUUID("uuid");
+    }
+
 }