/*- * ============LICENSE_START======================================================= * sdc-tosca * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= */ package org.onap.sdc.impl; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.toscaparser.api.CapabilityAssignments; import org.onap.sdc.toscaparser.api.CapabilityAssignment; import org.onap.sdc.toscaparser.api.NodeTemplate; import org.onap.sdc.toscaparser.api.RequirementAssignments; import org.junit.jupiter.api.Test; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @ExtendWith({SdcToscaParserBasicTest.class}) class ToscaParserReqAndCapTest extends SdcToscaParserBasicTest { //region getCapabilitiesOf @Test public void testGetCapabilitiesOfNodeTemplate() { List vfs = fdntCsarHelper.getServiceVfList(); CapabilityAssignments capabilityAssignments = fdntCsarHelper.getCapabilitiesOf(vfs.get(0)); assertNotNull(capabilityAssignments); assertEquals(13, capabilityAssignments.getAll().size()); assertNotNull(capabilityAssignments.getCapabilityByName("DNT_FW_RHRG.binding_DNT_FW_INT_DNS_TRUSTED_RVMI")); assertEquals(6, capabilityAssignments.getCapabilitiesByType("tosca.capabilities.network.Bindable").getAll().size()); } @Test public void testGetCapabilitiesOfNull() { CapabilityAssignments capabilityAssignments = fdntCsarHelper.getCapabilitiesOf(null); assertNull(capabilityAssignments); } //endregion //region getRequirementsOf @Test public void testGetRequirementsOfNodeTemplate() { List vfs = fdntCsarHelper.getServiceVfList(); List cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); RequirementAssignments requirementAssignments = fdntCsarHelper.getRequirementsOf(cps.get(0)); assertNotNull(requirementAssignments); assertEquals(1, requirementAssignments.getAll().size()); assertEquals("DNT_FW_RHRG", requirementAssignments.getRequirementsByName("binding").getAll().get(0).getNodeTemplateName()); } @Test public void testGetRequirementsOfNull() { RequirementAssignments requirementAssignments = fdntCsarHelper.getRequirementsOf(null); assertNull(requirementAssignments); } //endregion //region getCapabilityPropertyLeafValue @Test public void testGetCapabilityPropertyLeafValue() { NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER"); assertNotNull(capabilityAssignment); String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "max_instances#type"); assertEquals("integer", propValue); } @Test public void testGetCapabilityHierarchyPropertyLeafValue() { NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.endpoint_DNT_FW_SERVER"); assertNotNull(capabilityAssignment); String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "ports#entry_schema#type"); assertEquals("PortSpec", propValue); } @Test public void testGetCapabilityDummyPropertyLeafValue() { NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER"); assertNotNull(capabilityAssignment); String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, "dummy"); assertNull(propValue); } @Test public void testGetCapabilityNullPropertyLeafValue() { NodeTemplate vf = fdntCsarHelper.getServiceNodeTemplateByNodeName("FDNT 1"); CapabilityAssignment capabilityAssignment = vf.getCapabilities().getCapabilityByName("DNT_FW_RHRG.scalable_DNT_FW_SERVER"); assertNotNull(capabilityAssignment); String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(capabilityAssignment, null); assertNull(propValue); } @Test public void testGetNullCapabilityPropertyLeafValue() { String propValue = fdntCsarHelper.getCapabilityPropertyLeafValue(null, "max_instances#type"); assertNull(propValue); } //endregion //QA tests region for US 319197 -port mirroring- //get-CapabilitiesOf (All Types) @Test public void getServiceNodeTemplateCapabilitiesOfTypeVF() { List serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF); CapabilityAssignments capabilitiesOfVF = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVfList.get(0)); assertEquals(capabilitiesOfVF.getAll().size(),12); assertNotNull(capabilitiesOfVF.getCapabilityByName("neutronport0.network.incoming.packets.rate")); } @Test public void getServiceNodeTemplateCapabilitiesOfTypeExVL() { List serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL"); CapabilityAssignments capabilitiesOfExtVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceExtVlList.get(0)); assertEquals(capabilitiesOfExtVL.getAll().size(),2); assertNotNull(capabilitiesOfExtVL.getCapabilityByName("virtual_linkable").getProperties()); } @Test public void getServiceNodeTemplateCapabilitiesOfTypeVL() { List serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network"); CapabilityAssignments capabilitiesOfVL = QAServiceForToscaParserTests.getCapabilitiesOf(serviceVlList.get(0)); assertEquals(capabilitiesOfVL.getAll().size(),2); assertNotNull(capabilitiesOfVL.getCapabilityByName("link").getProperties()); } @Test public void getServiceNodeTemplateCapabilitiesOfTypeCP() { List serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); CapabilityAssignments capabilitiesOfCP = QAServiceForToscaParserTests.getCapabilitiesOf(serviceCpList.get(0)); assertEquals(capabilitiesOfCP.getAll().size(),2); assertNotNull(capabilitiesOfCP.getCapabilityByName("internal_connectionPoint")); } @Test public void getServiceNodeTemplateCapabilitiesOfTypePNF() { List servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF); CapabilityAssignments capabilitiesOfPnf = QAServiceForToscaParserTests.getCapabilitiesOf(servicePnfs.get(0)); assertEquals(capabilitiesOfPnf.getAll().size(),1); assertNotNull(capabilitiesOfPnf.getCapabilityByName("feature")); } //get-RequirementsOf (All Types)----------------------------- @Test public void getServiceNodeTemplateRequirementsOfTypeVF() { List serviceVfList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.VF); RequirementAssignments requirementsOfVF = QAServiceForToscaParserTests.getRequirementsOf(serviceVfList.get(6)); assertEquals(requirementsOfVF.getAll().size(),3); // RequirementAssignments requirementsByName = assertEquals(requirementsOfVF.getRequirementsByName("dependency").getAll().size(),2 ); //check that API return empty list if requirement property not exist. assertEquals(requirementsOfVF.getRequirementsByName("blabla").getAll().size(),0); } @Test public void getServiceNodeTemplateRequirementsOfTypeExVL() { List serviceExtVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("org.openecomp.resource.vl.extVL"); RequirementAssignments requirementsOfExtVL = QAServiceForToscaParserTests.getRequirementsOf(serviceExtVlList.get(0)); assertEquals(requirementsOfExtVL.getAll().size(),1); } @Test public void getServiceNodeTemplateRequirementsOfTypeVL() { List serviceVlList = QAServiceForToscaParserTests.getServiceNodeTemplatesByType("tosca.nodes.network.Network"); RequirementAssignments requirementsOfVL = QAServiceForToscaParserTests.getRequirementsOf(serviceVlList.get(1)); assertEquals(requirementsOfVL.getAll().size(),2); assertNotNull(requirementsOfVL.getRequirementsByName("dependency")); } @Test public void getServiceNodeTemplateRequirementsOfTypeCP() { List serviceCpList = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); RequirementAssignments requirementsOfCP = QAServiceForToscaParserTests.getRequirementsOf(serviceCpList.get(0)); assertEquals(requirementsOfCP.getAll().size(),2); assertEquals(requirementsOfCP.getRequirementsByName("virtualBinding").getAll().size(),1); } @Test public void getServiceNodeTemplateRequirementsOfTypePNF() { List servicePnfs = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.PNF); RequirementAssignments requirementsOfPnf = QAServiceForToscaParserTests.getRequirementsOf(servicePnfs.get(0)); assertEquals(requirementsOfPnf.getAll().size(),2); assertNotNull(requirementsOfPnf.getRequirementsByName("feature")); } //QA end region for US 319197 -port mirroring // Added by QA CapabilityAssignments @Test public void testGetCapabilitiesByType() { List vfs = resolveGetInputCsarQA.getServiceVfList(); CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); assertNotNull(capabilityAssignments); CapabilityAssignments capabilitiesByType = capabilityAssignments.getCapabilitiesByType("tosca.capabilities.Scalable"); int capsQty = capabilitiesByType.getAll().size(); assertEquals(1, capsQty); CapabilityAssignment capabilityByName = capabilitiesByType.getCapabilityByName("abstract_pd_server.scalable_pd_server"); assertNotNull(capabilityByName); } @Test public void testGetCapabilityByName() { List vfs = resolveGetInputCsarQA.getServiceVfList(); CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); assertNotNull(capabilityAssignments); CapabilityAssignment capabilityByName = capabilityAssignments.getCapabilityByName("abstract_pd_server.disk.iops_pd_server"); assertNotNull(capabilityByName); String capName = capabilityByName.getName(); assertEquals(capName, "abstract_pd_server.disk.iops_pd_server"); } @Test public void testGetCapabilitiesGetAll() { List vfs = resolveGetInputCsarQA.getServiceVfList(); CapabilityAssignments capabilityAssignments = resolveGetInputCsarQA.getCapabilitiesOf(vfs.get(0)); assertNotNull(capabilityAssignments); int capsAssignmentSize = capabilityAssignments.getAll().size(); assertEquals(65, capsAssignmentSize); } // Added by QA RequirementsAssignments @Test public void testGetRequirementsByName() { List vfs = resolveReqsCapsCsarQA.getServiceVfList(); List cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0)); assertNotNull(requirementAssignments); assertEquals(2, requirementAssignments.getAll().size()); assertEquals("DNT_FW_RHRG2", requirementAssignments.getRequirementsByName("binding").getAll().get(1).getNodeTemplateName()); } @Test public void testRequirementAssignmentGetNodeGetCapability() { List vfs = resolveReqsCapsCsarQA.getServiceVfList(); List cps = resolveReqsCapsCsarQA.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); RequirementAssignments requirementAssignments = resolveReqsCapsCsarQA.getRequirementsOf(cps.get(0)); assertNotNull(requirementAssignments); String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName(); String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName(); assertEquals(nodeTemplateName, "DNT_FW_RHRG"); assertNull(capabilityName); } @Test public void testRequirementAssignmentGetCapability() { List cps = QAServiceForToscaParserTests.getServiceNodeTemplateBySdcType(SdcTypes.CP); RequirementAssignments requirementAssignments = QAServiceForToscaParserTests.getRequirementsOf(cps.get(0)); assertNotNull(requirementAssignments); String nodeTemplateName = requirementAssignments.getAll().get(0).getNodeTemplateName(); String capabilityName = requirementAssignments.getAll().get(0).getCapabilityName(); assertEquals(nodeTemplateName, "ExtVL 0"); assertEquals(capabilityName,"tosca.capabilities.network.Linkable"); } @Test public void testGetCapabilityProperties() { List vfs = fdntCsarHelper.getServiceVfList(); List cps = fdntCsarHelper.getNodeTemplateBySdcType(vfs.get(0), SdcTypes.CP); CapabilityAssignments capabilityAssignments = cps.get(0).getCapabilities(); assertNotNull(capabilityAssignments); assertEquals(12, capabilityAssignments.getAll().size()); CapabilityAssignment xxxCapability = capabilityAssignments.getCapabilityByName("xxx"); //GetInput property - resolved in any case String getInputProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "DeploymentFlavor"); assertEquals("{aaa=bbb}", getInputProp); //Simple property String simpleProp = fdntCsarHelper.getCapabilityPropertyLeafValue(xxxCapability, "distribution"); assertEquals("rhel", simpleProp); } }