2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.impl;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.onap.sdc.tosca.parser.api.IEntityDetails;
26 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
27 import org.onap.sdc.tosca.parser.elements.queries.EntityQuery;
28 import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery;
29 import org.onap.sdc.tosca.parser.enums.SdcTypes;
30 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
31 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
32 import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
33 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
34 import org.onap.sdc.toscaparser.api.RequirementAssignment;
37 import java.util.List;
39 import java.util.stream.Collectors;
41 import static org.junit.Assert.assertEquals;
42 import static org.junit.Assert.assertTrue;
44 public class GetEntityPortMirroringTest {
46 private final static String cap0 = "vepdg5afn0.vlb_1.port_mirroring_vlb_gn_vepdg_fn_5_RVMI";
47 private final static String cap1 = "radcomfnvlbavf11_3_3vepdg0.abstract_vlbagentbase_eph_aff.port_mirroring_vlbagentbase_eph_aff_vlbagentbase_eph_aff_int_pktmirror_1_port";
48 private static ISdcCsarHelper helper = null;
51 public static void setUpClass() {
53 URL resource = GetEntityPortMirroringTest.class.getClassLoader()
54 .getResource("csars/service-JennnyVepdgPortMirroringTest-csar.csar");
55 if (resource != null) {
56 helper = SdcToscaParserFactory.getInstance().getSdcCsarHelper(resource.getFile());
59 } catch (SdcToscaParserException e) {
65 public void getServiceConfigurations() {
66 EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.CONFIGURATION)
68 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
71 List<IEntityDetails> entities = helper.getEntity(entityQuery, topologyTemplateQuery, false);
73 assertEquals(1, entities.size());
74 assertEquals("54308d8b-21ca-40a1-bd3e-efde64791605", entities.get(0).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
75 assertEquals("Port Mirroring Configuration", entities.get(0).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
76 assertEquals(2, entities.get(0).getRequirements().size());
77 assertTrue(entities.get(0).getProperties().isEmpty());
78 assertEquals(1, entities.get(0).getCapabilities().size());
82 public void getServiceProxyOnService() {
83 EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.SERVICE_PROXY)
85 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
88 List<IEntityDetails> entities = helper.getEntity(entityQuery, topologyTemplateQuery, false);
90 assertEquals(2, entities.size());
91 assertTrue("vEPDG-5A-FN SVC Service Proxy".equals(entities.get(0).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)) ||
92 "vEPDG-5A-FN SVC Service Proxy".equals(entities.get(1).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
93 assertTrue("Radcom FN vLBA SVC 11_3_3 vEPDG Service Proxy".equals(entities.get(0).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)) ||
94 "Radcom FN vLBA SVC 11_3_3 vEPDG Service Proxy".equals(entities.get(1).getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
96 assertTrue(entities.get(0).getRequirements().isEmpty());
97 assertTrue(entities.get(0).getProperties().isEmpty());
98 assertEquals(940, entities.get(0).getCapabilities().size());
99 assertEquals(197, entities.get(1).getCapabilities().size());
103 public void getCapabilityForCOnfigurationRequirementOnService() {
104 EntityQuery entityQueryC = EntityQuery.newBuilder(SdcTypes.CONFIGURATION)
107 EntityQuery entityQueryS = EntityQuery.newBuilder(SdcTypes.SERVICE_PROXY)
109 TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
112 List<IEntityDetails> configurationNodes = helper.getEntity(entityQueryC, topologyTemplateQuery, false);
113 List<IEntityDetails> proxyNodes = helper.getEntity(entityQueryS, topologyTemplateQuery, false);
115 assertEquals(2, proxyNodes.size());
116 assertEquals(1, configurationNodes.size());
118 List<RequirementAssignment> reqMap = configurationNodes.get(0).getRequirements();
119 assertEquals(cap0, reqMap.stream().filter(f -> f.getName().equals("source")).findAny().get().getCapabilityName());
120 assertEquals(cap1, reqMap.stream().filter(f -> f.getName().equals("collector")).findAny().get().getCapabilityName());
122 assertTrue(isCapabilityFound(proxyNodes.get(0), cap0));
123 assertTrue(isCapabilityFound(proxyNodes.get(1), cap1));
126 private boolean isCapabilityFound(IEntityDetails nodeDetails, String capName) {
127 List<CapabilityAssignment> assignments = nodeDetails.getCapabilities();
128 CapabilityAssignment capabilityAssignment = assignments.stream().filter(f -> f.getDefinition().getName().equals(capName)).findAny().orElse(null);
129 return capabilityAssignment != null;