1 package org.openecomp.sdc.enrichment.impl.tosca;
3 import org.mockito.InjectMocks;
4 import org.mockito.Mock;
5 import org.mockito.MockitoAnnotations;
6 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
7 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
9 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
10 import org.openecomp.sdc.versioning.dao.types.Version;
11 import org.testng.Assert;
12 import org.testng.annotations.BeforeMethod;
13 import org.testng.annotations.Test;
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
20 import static org.mockito.Mockito.doReturn;
21 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE;
22 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY;
23 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES;
24 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES;
25 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE;
26 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_FUNCTION;
27 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_NAMING_CODE;
29 public class ComponentQuestionnaireDataTest {
30 private static String VSP_ID = "vspId";
31 public static final Version VERSION01 = new Version(0, 1);
32 private static final Version VERSION10 = new Version(1, 0);
35 private ComponentDao componentDaoMock;
38 private ComponentDependencyModelDao componentDependencyDaoMock;
41 private static ComponentQuestionnaireData componentQuestionnaireData;
44 public void setUp() throws Exception {
45 MockitoAnnotations.initMocks(this);
49 public void testGetData() {
50 ComponentEntity componentEntity = new ComponentEntity(VSP_ID, VERSION01,"ID1" );
51 componentEntity.setCompositionData("{\n" +
52 " \"name\": \"org.openecomp.resource.vfc.nodes.heat.be\",\n" +
53 " \"displayName\": \"be\",\n" +
54 " \"vfcCode\": \"be_1\",\n" +
55 " \"nfcCode\": \"code\",\n" +
56 " \"nfcFunction\": \"desc\"\n" +
58 componentEntity.setQuestionnaireData
59 ("{\"highAvailabilityAndLoadBalancing\":{\"isComponentMandatory\" : \"NO\"," +
60 "\"highAvailabilityMode\":\"geo-activeactive\"},\"compute\":{\"numOfVMs\" " +
61 ":{\"maximum\" : 5, \"minimum\" : 0}}}");
63 List<ComponentEntity> entitites = new ArrayList<ComponentEntity>();
64 entitites.add(componentEntity);
66 doReturn(entitites).when(componentDaoMock).listCompositionAndQuestionnaire(VSP_ID, VERSION01);
68 final Map<String, Map<String, Object>> propertiesfromCompQuestionnaire =
69 componentQuestionnaireData.getPropertiesfromCompQuestionnaire(VSP_ID, VERSION01);
71 final Map<String, Object> be = propertiesfromCompQuestionnaire.get("be");
72 Assert.assertEquals(be.get(VFC_NAMING_CODE) , "be_1");
73 Assert.assertEquals(be.get(VFC_CODE), "code");
74 Assert.assertEquals(be.get(VFC_FUNCTION), "desc");
75 Assert.assertEquals(be.get(MANDATORY) ,"NO");
76 Assert.assertEquals(be.get(HIGH_AVAIL_MODE) ,"geo-activeactive");
77 Assert.assertEquals(be.get(MIN_INSTANCES) ,null);
78 Assert.assertEquals(be.get(MAX_INSTANCES) ,5);
80 final Map<String, String> sourceToTargetComponent =
81 componentQuestionnaireData.getSourceToTargetComponent();
83 Assert.assertEquals("be", sourceToTargetComponent.get("ID1"));
88 public void testPopulateDepnendency() {
89 ComponentDependencyModelEntity sourceComponent = new ComponentDependencyModelEntity(VSP_ID, VERSION01,"ID1" );
90 sourceComponent.setSourceComponentId("Comp1");
91 sourceComponent.setTargetComponentId("Comp2");
92 sourceComponent.setRelation("dependsOn");
94 ComponentDependencyModelEntity targetComponent = new ComponentDependencyModelEntity(VSP_ID,
96 targetComponent.setSourceComponentId("Comp1");
97 targetComponent.setTargetComponentId("Comp3");
98 targetComponent.setRelation("dependsOn");
100 List<ComponentDependencyModelEntity> entitites = new ArrayList<ComponentDependencyModelEntity>();
101 entitites.add(sourceComponent);
102 entitites.add(targetComponent);
104 doReturn(entitites).when(componentDependencyDaoMock).list(new ComponentDependencyModelEntity
105 (VSP_ID, VERSION01, null));
107 final Map<String, String> sourceToTargetComponent = new HashMap<String, String>();
108 sourceToTargetComponent.put("Comp1", "fe");
109 sourceToTargetComponent.put("Comp2", "be");
110 sourceToTargetComponent.put("Comp3", "smp");
111 final Map<String, List<String>> dependencies =
112 componentQuestionnaireData.populateDependencies(VSP_ID, VERSION01, sourceToTargetComponent);
114 List<String> expectedTargets = new ArrayList<String>();
115 expectedTargets.add("be"); expectedTargets.add("smp");
117 Assert.assertEquals(dependencies.get("fe"), expectedTargets);