aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/tosca/ComponentQuestionnaireDataTest.java
blob: d28160422767e2e5ca559b54a1da261d8820beb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package org.openecomp.sdc.enrichment.impl.tosca;

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_NAMING_CODE;

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.VersioningManager;
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;

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("{\"name\": \"org.openecomp.resource.vfc.nodes.heat.be\"," +
        "\"displayName\": \"be\", \"vfcCode\": \"be_1\"}");
    componentEntity.setQuestionnaireData
        ("{\"highAvailabilityAndLoadBalancing\":{\"isComponentMandatory\" : \"NO\"," +
            "\"highAvailabilityMode\":\"geo-activeactive\"},\"compute\":{\"numOfVMs\" " +
            ":{\"maximum\" : 5, \"minimum\" : 0}}}");

    List<ComponentEntity> entitites = new ArrayList<ComponentEntity>();
    entitites.add(componentEntity);

    doReturn(entitites).when(componentDaoMock).listCompositionAndQuestionnaire(VSP_ID, VERSION01);

    final Map<String, Map<String, Object>> propertiesfromCompQuestionnaire =
        componentQuestionnaireData.getPropertiesfromCompQuestionnaire(VSP_ID, VERSION01);

    final Map<String, Object> be = propertiesfromCompQuestionnaire.get("be");
    Assert.assertEquals(be.get(VFC_NAMING_CODE) , "be_1");
    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<String, String> 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<ComponentDependencyModelEntity> entitites = new ArrayList<ComponentDependencyModelEntity>();
    entitites.add(sourceComponent);
    entitites.add(targetComponent);

    doReturn(entitites).when(componentDependencyDaoMock).list(new ComponentDependencyModelEntity
        (VSP_ID, VERSION01, null));

    final Map<String, String> sourceToTargetComponent = new HashMap<String, String>();
    sourceToTargetComponent.put("Comp1", "fe");
    sourceToTargetComponent.put("Comp2", "be");
    sourceToTargetComponent.put("Comp3", "smp");
    final Map<String, List<String>> dependencies =
        componentQuestionnaireData.populateDependencies(VSP_ID, VERSION01, sourceToTargetComponent);

    List<String> expectedTargets =  new ArrayList<String>();
    expectedTargets.add("be"); expectedTargets.add("smp");

    Assert.assertEquals(dependencies.get("fe"), expectedTargets);



  }

}