package org.openecomp.sdc.enrichment.impl.tosca; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static org.mockito.Mockito.doReturn; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_FUNCTION; import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_NAMING_CODE; public class ComponentQuestionnaireDataTest { private static String VSP_ID = "vspId"; public static final Version VERSION01 = new Version(0, 1); private static final Version VERSION10 = new Version(1, 0); @Mock private ComponentDao componentDaoMock; @Mock private ComponentDependencyModelDao componentDependencyDaoMock; @InjectMocks private static ComponentQuestionnaireData componentQuestionnaireData; @BeforeMethod public void setUp() throws Exception { MockitoAnnotations.initMocks(this); } @Test public void testGetData() { ComponentEntity componentEntity = new ComponentEntity(VSP_ID, VERSION01,"ID1" ); componentEntity.setCompositionData("{\n" + " \"name\": \"org.openecomp.resource.vfc.nodes.heat.be\",\n" + " \"displayName\": \"be\",\n" + " \"vfcCode\": \"be_1\",\n" + " \"nfcCode\": \"code\",\n" + " \"nfcFunction\": \"desc\"\n" + "}"); componentEntity.setQuestionnaireData ("{\"highAvailabilityAndLoadBalancing\":{\"isComponentMandatory\" : \"NO\"," + "\"highAvailabilityMode\":\"geo-activeactive\"},\"compute\":{\"numOfVMs\" " + ":{\"maximum\" : 5, \"minimum\" : 0}}}"); List entitites = new ArrayList(); entitites.add(componentEntity); doReturn(entitites).when(componentDaoMock).listCompositionAndQuestionnaire(VSP_ID, VERSION01); final Map> propertiesfromCompQuestionnaire = componentQuestionnaireData.getPropertiesfromCompQuestionnaire(VSP_ID, VERSION01); final Map be = propertiesfromCompQuestionnaire.get("be"); Assert.assertEquals(be.get(VFC_NAMING_CODE) , "be_1"); Assert.assertEquals(be.get(VFC_CODE), "code"); Assert.assertEquals(be.get(VFC_FUNCTION), "desc"); Assert.assertEquals(be.get(MANDATORY) ,"NO"); Assert.assertEquals(be.get(HIGH_AVAIL_MODE) ,"geo-activeactive"); Assert.assertEquals(be.get(MIN_INSTANCES) ,null); Assert.assertEquals(be.get(MAX_INSTANCES) ,5); final Map sourceToTargetComponent = componentQuestionnaireData.getSourceToTargetComponent(); Assert.assertEquals("be", sourceToTargetComponent.get("ID1")); } @Test public void testPopulateDepnendency() { ComponentDependencyModelEntity sourceComponent = new ComponentDependencyModelEntity(VSP_ID, VERSION01,"ID1" ); sourceComponent.setSourceComponentId("Comp1"); sourceComponent.setTargetComponentId("Comp2"); sourceComponent.setRelation("dependsOn"); ComponentDependencyModelEntity targetComponent = new ComponentDependencyModelEntity(VSP_ID, VERSION01,"ID2" ); targetComponent.setSourceComponentId("Comp1"); targetComponent.setTargetComponentId("Comp3"); targetComponent.setRelation("dependsOn"); List entitites = new ArrayList(); entitites.add(sourceComponent); entitites.add(targetComponent); doReturn(entitites).when(componentDependencyDaoMock).list(new ComponentDependencyModelEntity (VSP_ID, VERSION01, null)); final Map sourceToTargetComponent = new HashMap(); sourceToTargetComponent.put("Comp1", "fe"); sourceToTargetComponent.put("Comp2", "be"); sourceToTargetComponent.put("Comp3", "smp"); final Map> dependencies = componentQuestionnaireData.populateDependencies(VSP_ID, VERSION01, sourceToTargetComponent); List expectedTargets = new ArrayList(); expectedTargets.add("be"); expectedTargets.add("smp"); Assert.assertEquals(dependencies.get("fe"), expectedTargets); } }