1 package org.openecomp.sdc.enrichment.impl.tosca;
3 import static org.mockito.Mockito.doReturn;
4 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE;
5 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY;
6 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES;
7 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES;
8 import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_NAMING_CODE;
10 import org.mockito.InjectMocks;
11 import org.mockito.Mock;
12 import org.mockito.MockitoAnnotations;
13 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao;
14 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
15 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
16 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
17 import org.openecomp.sdc.versioning.VersioningManager;
18 import org.openecomp.sdc.versioning.dao.types.Version;
19 import org.testng.Assert;
20 import org.testng.annotations.BeforeMethod;
21 import org.testng.annotations.Test;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
28 public class ComponentQuestionnaireDataTest {
29 private static String VSP_ID = "vspId";
30 public static final Version VERSION01 = new Version(0, 1);
31 private static final Version VERSION10 = new Version(1, 0);
34 private ComponentDao componentDaoMock;
37 private ComponentDependencyModelDao componentDependencyDaoMock;
40 private static ComponentQuestionnaireData componentQuestionnaireData;
43 public void setUp() throws Exception {
44 MockitoAnnotations.initMocks(this);
48 public void testGetData() {
49 ComponentEntity componentEntity = new ComponentEntity(VSP_ID, VERSION01,"ID1" );
50 componentEntity.setCompositionData("{\"name\": \"org.openecomp.resource.vfc.nodes.heat.be\"," +
51 "\"displayName\": \"be\", \"vfcCode\": \"be_1\"}");
52 componentEntity.setQuestionnaireData
53 ("{\"highAvailabilityAndLoadBalancing\":{\"isComponentMandatory\" : \"NO\"," +
54 "\"highAvailabilityMode\":\"geo-activeactive\"},\"compute\":{\"numOfVMs\" " +
55 ":{\"maximum\" : 5, \"minimum\" : 0}}}");
57 List<ComponentEntity> entitites = new ArrayList<ComponentEntity>();
58 entitites.add(componentEntity);
60 doReturn(entitites).when(componentDaoMock).listCompositionAndQuestionnaire(VSP_ID, VERSION01);
62 final Map<String, Map<String, Object>> propertiesfromCompQuestionnaire =
63 componentQuestionnaireData.getPropertiesfromCompQuestionnaire(VSP_ID, VERSION01);
65 final Map<String, Object> be = propertiesfromCompQuestionnaire.get("be");
66 Assert.assertEquals(be.get(VFC_NAMING_CODE) , "be_1");
67 Assert.assertEquals(be.get(MANDATORY) ,"NO");
68 Assert.assertEquals(be.get(HIGH_AVAIL_MODE) ,"geo-activeactive");
69 Assert.assertEquals(be.get(MIN_INSTANCES) ,null);
70 Assert.assertEquals(be.get(MAX_INSTANCES) ,5);
72 final Map<String, String> sourceToTargetComponent =
73 componentQuestionnaireData.getSourceToTargetComponent();
75 Assert.assertEquals("be", sourceToTargetComponent.get("ID1"));
80 public void testPopulateDepnendency() {
81 ComponentDependencyModelEntity sourceComponent = new ComponentDependencyModelEntity(VSP_ID, VERSION01,"ID1" );
82 sourceComponent.setSourceComponentId("Comp1");
83 sourceComponent.setTargetComponentId("Comp2");
84 sourceComponent.setRelation("dependsOn");
86 ComponentDependencyModelEntity targetComponent = new ComponentDependencyModelEntity(VSP_ID,
88 targetComponent.setSourceComponentId("Comp1");
89 targetComponent.setTargetComponentId("Comp3");
90 targetComponent.setRelation("dependsOn");
92 List<ComponentDependencyModelEntity> entitites = new ArrayList<ComponentDependencyModelEntity>();
93 entitites.add(sourceComponent);
94 entitites.add(targetComponent);
96 doReturn(entitites).when(componentDependencyDaoMock).list(new ComponentDependencyModelEntity
97 (VSP_ID, VERSION01, null));
99 final Map<String, String> sourceToTargetComponent = new HashMap<String, String>();
100 sourceToTargetComponent.put("Comp1", "fe");
101 sourceToTargetComponent.put("Comp2", "be");
102 sourceToTargetComponent.put("Comp3", "smp");
103 final Map<String, List<String>> dependencies =
104 componentQuestionnaireData.populateDependencies(VSP_ID, VERSION01, sourceToTargetComponent);
106 List<String> expectedTargets = new ArrayList<String>();
107 expectedTargets.add("be"); expectedTargets.add("smp");
109 Assert.assertEquals(dependencies.get("fe"), expectedTargets);