use of org.onap.sdc.toscaparser.api.RequirementAssignment in project so by onap.
the class ToscaResourceInstallerTest method testProcessVNFCGroupSequence.
@Test
public void testProcessVNFCGroupSequence() {
List<Group> groupList = new ArrayList<>();
Group group1 = mock(Group.class);
NodeTemplate node1 = mock(NodeTemplate.class);
List<NodeTemplate> nodeList1 = new ArrayList<>();
nodeList1.add(node1);
doReturn("VfcInstanceGroup..0").when(group1).getName();
doReturn(nodeList1).when(group1).getMemberNodes();
doReturn("deviceV3").when(node1).getName();
Group group2 = mock(Group.class);
NodeTemplate node2 = mock(NodeTemplate.class);
List<NodeTemplate> nodeList2 = new ArrayList<>();
nodeList2.add(node2);
doReturn("VfcInstanceGroup..1").when(group2).getName();
doReturn(nodeList2).when(group2).getMemberNodes();
RequirementAssignments requirements2 = mock(RequirementAssignments.class);
RequirementAssignment requirement2 = mock(RequirementAssignment.class);
List<RequirementAssignment> requirementCollection2 = new ArrayList<>();
requirementCollection2.add(requirement2);
doReturn(requirementCollection2).when(requirements2).getAll();
doReturn("deviceV3").when(requirement2).getNodeTemplateName();
doReturn("SiteV2").when(node2).getName();
Group group3 = mock(Group.class);
NodeTemplate node3 = mock(NodeTemplate.class);
List<NodeTemplate> nodeList3 = new ArrayList<>();
nodeList3.add(node3);
doReturn("VfcInstanceGroup..2").when(group3).getName();
doReturn(nodeList3).when(group3).getMemberNodes();
RequirementAssignments requirements3 = mock(RequirementAssignments.class);
RequirementAssignment requirement3 = mock(RequirementAssignment.class);
List<RequirementAssignment> requirementCollection3 = new ArrayList<>();
requirementCollection3.add(requirement3);
doReturn(requirementCollection3).when(requirements3).getAll();
doReturn("SiteV2").when(requirement3).getNodeTemplateName();
doReturn("siteWanV2").when(node3).getName();
groupList.add(group1);
groupList.add(group2);
groupList.add(group3);
doReturn(csarHelper).when(toscaResourceStructure).getSdcCsarHelper();
ToscaResourceInstaller installer = new ToscaResourceInstaller();
Method[] methods = installer.getClass().getDeclaredMethods();
Method testMethod = null;
for (Method method : methods) {
String name = method.getName();
if (name.equals("processVNFCGroupSequence")) {
method.setAccessible(true);
testMethod = method;
}
}
if (null != testMethod) {
try {
Object seqResult = testMethod.invoke(installer, toscaResourceStructure, groupList);
if (seqResult instanceof List) {
String resultStr = ((List<String>) seqResult).stream().collect(Collectors.joining(","));
assertEquals(((List<String>) seqResult).size(), 3);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
use of org.onap.sdc.toscaparser.api.RequirementAssignment in project so by onap.
the class ToscaResourceInstaller method processVNFCGroupSequence.
private List<String> processVNFCGroupSequence(ToscaResourceStructure toscaResourceStructure, List<IEntityDetails> groupEntityDetails) {
if (CollectionUtils.isEmpty(groupEntityDetails)) {
return Collections.emptyList();
}
ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
List<String> strSequence = new ArrayList<>(groupEntityDetails.size());
List<IEntityDetails> tempEntityList = new ArrayList<>(groupEntityDetails.size());
List<IEntityDetails> entities = new ArrayList<>();
tempEntityList.addAll(groupEntityDetails);
for (IEntityDetails vnfcEntityDetails : groupEntityDetails) {
List<IEntityDetails> vnfcMemberNodes = vnfcEntityDetails.getMemberNodes();
boolean hasRequirements = false;
for (IEntityDetails vnfcDetails : vnfcMemberNodes) {
List<RequirementAssignment> requirements = vnfcDetails.getRequirements();
if (requirements != null && !requirements.isEmpty()) {
hasRequirements = true;
break;
}
}
if (!hasRequirements) {
strSequence.add(vnfcEntityDetails.getName());
tempEntityList.remove(vnfcEntityDetails);
entities.addAll(vnfcMemberNodes);
}
}
getVNFCGroupSequenceList(strSequence, tempEntityList, entities, iSdcCsarHelper);
return strSequence;
}
Aggregations