aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/sdc/impl/GetEntityPortMirroringTest.java
blob: aa3391059481963a409dff3cbac06dfb8de60c5c (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.onap.sdc.impl;

import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.sdc.tosca.parser.api.IEntityDetails;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.elements.queries.EntityQuery;
import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery;
import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.onap.sdc.toscaparser.api.CapabilityAssignment;
import org.onap.sdc.toscaparser.api.RequirementAssignment;

import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class GetEntityPortMirroringTest {

    private final static String cap0 = "vepdg5afn0.vlb_1.port_mirroring_vlb_gn_vepdg_fn_5_RVMI";
    private final static String cap1 = "radcomfnvlbavf11_3_3vepdg0.abstract_vlbagentbase_eph_aff.port_mirroring_vlbagentbase_eph_aff_vlbagentbase_eph_aff_int_pktmirror_1_port";
    private static ISdcCsarHelper helper = null;

    @BeforeClass
    public static void setUpClass() {
        try {
            URL resource = GetEntityPortMirroringTest.class.getClassLoader()
                    .getResource("csars/service-JennnyVepdgPortMirroringTest-csar.csar");
            if (resource != null) {
                helper = SdcToscaParserFactory.getInstance().getSdcCsarHelper(resource.getFile());
            }

        } catch (SdcToscaParserException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void getServiceConfigurations() {
        EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.CONFIGURATION)
                .build();
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
                .build();

        List<IEntityDetails> entities = helper.getEntity(entityQuery, topologyTemplateQuery, false);

        assertEquals(1, entities.size());
        assertEquals("54308d8b-21ca-40a1-bd3e-efde64791605", entities.get(0).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
        assertEquals("Port Mirroring Configuration", entities.get(0).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
        assertEquals(2, entities.get(0).getRequirements().size());
        assertTrue(entities.get(0).getProperties().isEmpty());
        assertEquals(1, entities.get(0).getCapabilities().size());
    }

    @Test
    public void getServiceProxyOnService() {
        EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.SERVICE_PROXY)
                .build();
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
                .build();

        List<IEntityDetails> entities = helper.getEntity(entityQuery, topologyTemplateQuery, false);

        assertEquals(2, entities.size());
        assertTrue("vEPDG-5A-FN SVC Service Proxy".equals(entities.get(0).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)) ||
                        "vEPDG-5A-FN SVC Service Proxy".equals(entities.get(1).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
        assertTrue("Radcom FN vLBA SVC 11_3_3 vEPDG Service Proxy".equals(entities.get(0).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)) ||
                "Radcom FN vLBA SVC 11_3_3 vEPDG Service Proxy".equals(entities.get(1).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));

        assertTrue(entities.get(0).getRequirements().isEmpty());
        assertTrue(entities.get(0).getProperties().isEmpty());
        assertEquals(940, entities.get(0).getCapabilities().size());
        assertEquals(197, entities.get(1).getCapabilities().size());
    }

    @Test
    public void getCapabilityForCOnfigurationRequirementOnService() {
        EntityQuery entityQueryC = EntityQuery.newBuilder(SdcTypes.CONFIGURATION)
                .build();

        EntityQuery entityQueryS = EntityQuery.newBuilder(SdcTypes.SERVICE_PROXY)
                .build();
        TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
                .build();

        List<IEntityDetails> configurationNodes = helper.getEntity(entityQueryC, topologyTemplateQuery, false);
        List<IEntityDetails> proxyNodes = helper.getEntity(entityQueryS, topologyTemplateQuery, false);

        assertEquals(2, proxyNodes.size());
        assertEquals(1, configurationNodes.size());

        Map<String, RequirementAssignment> reqMap = configurationNodes.get(0).getRequirements();
        assertEquals(cap0, reqMap.get("source").getCapabilityName());
        assertEquals(cap1, reqMap.get("collector").getCapabilityName());

        assertTrue(isCapabilityFound(proxyNodes.get(0), cap0));
        assertTrue(isCapabilityFound(proxyNodes.get(1), cap1));
    }

    private boolean isCapabilityFound(IEntityDetails nodeDetails, String capName) {
        List<CapabilityAssignment> assignments = nodeDetails.getCapabilities()
                .values()
                .stream()
                .filter(ca->capName.equals(ca.getDefinition()
                        .getName()))
                .collect(Collectors.toList());
        return assignments.size() == 1;
    }
}