[SDC] Onboarding 1710 rebase.
[sdc.git] / openecomp-be / lib / openecomp-sdc-enrichment-lib / openecomp-sdc-enrichment-impl / src / test / java / org / openecomp / sdc / enrichment / impl / tosca / ComponentQuestionnaireDataTest.java
1 package org.openecomp.sdc.enrichment.impl.tosca;
2
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;
14
15 import java.util.ArrayList;
16 import java.util.HashMap;
17 import java.util.List;
18 import java.util.Map;
19
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;
28
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);
33
34   @Mock
35   private ComponentDao componentDaoMock;
36
37   @Mock
38   private ComponentDependencyModelDao componentDependencyDaoMock;
39
40   @InjectMocks
41   private static ComponentQuestionnaireData componentQuestionnaireData;
42
43   @BeforeMethod
44   public void setUp() throws Exception {
45     MockitoAnnotations.initMocks(this);
46   }
47
48   @Test
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" +
57         "}");
58     componentEntity.setQuestionnaireData
59         ("{\"highAvailabilityAndLoadBalancing\":{\"isComponentMandatory\" : \"NO\"," +
60             "\"highAvailabilityMode\":\"geo-activeactive\"},\"compute\":{\"numOfVMs\" " +
61             ":{\"maximum\" : 5, \"minimum\" : 0}}}");
62
63     List<ComponentEntity> entitites = new ArrayList<ComponentEntity>();
64     entitites.add(componentEntity);
65
66     doReturn(entitites).when(componentDaoMock).listCompositionAndQuestionnaire(VSP_ID, VERSION01);
67
68     final Map<String, Map<String, Object>> propertiesfromCompQuestionnaire =
69         componentQuestionnaireData.getPropertiesfromCompQuestionnaire(VSP_ID, VERSION01);
70
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);
79
80     final Map<String, String> sourceToTargetComponent =
81         componentQuestionnaireData.getSourceToTargetComponent();
82
83     Assert.assertEquals("be", sourceToTargetComponent.get("ID1"));
84   }
85
86
87   @Test
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");
93
94     ComponentDependencyModelEntity targetComponent = new ComponentDependencyModelEntity(VSP_ID,
95         VERSION01,"ID2" );
96     targetComponent.setSourceComponentId("Comp1");
97     targetComponent.setTargetComponentId("Comp3");
98     targetComponent.setRelation("dependsOn");
99
100     List<ComponentDependencyModelEntity> entitites = new ArrayList<ComponentDependencyModelEntity>();
101     entitites.add(sourceComponent);
102     entitites.add(targetComponent);
103
104     doReturn(entitites).when(componentDependencyDaoMock).list(new ComponentDependencyModelEntity
105         (VSP_ID, VERSION01, null));
106
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);
113
114     List<String> expectedTargets =  new ArrayList<String>();
115     expectedTargets.add("be"); expectedTargets.add("smp");
116
117     Assert.assertEquals(dependencies.get("fe"), expectedTargets);
118
119
120
121   }
122
123 }