UpdateTemplateDefinitionLang { public String createAbstractNode(String name, String type, List<String> subnodes, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList){ AbstractNodeBuilder nodeBuilder = new AbstractNodeBuilder(); NodeId nodeId = null; if (type.equals(NEMOConstants.host)){ Map<PhysicalHostName, PhysicalHost> physicalHostMap = getDefinitions.getPhysicalHost(); if (physicalHostMap.containsKey(new PhysicalHostName(name))){ PhysicalHostId physicalHostId = physicalHostMap.get(new PhysicalHostName(name)).getHostId(); nodeBuilder.setKey(new AbstractNodeKey(new AbstractNodeKey(new NodeId(physicalHostId.getValue())))) .setNodeId(new NodeId(physicalHostId.getValue())); } else { return "The host " + name + " is not exist in physical network."; } } else { nodeId = new NodeId(UUID.randomUUID().toString()); } nodeBuilder.setKey(new AbstractNodeKey(nodeId)); nodeBuilder.setNodeId(nodeId); nodeBuilder.setNodeName(new NodeName(name)); nodeBuilder.setNodeType(new NodeType(type)); if (!subnodes.isEmpty()){ if (abstractNodes.isEmpty()){ return "There are no nodes."; } else { List<SubNode> subNodeList = new LinkedList<SubNode>(); Long order = 0L; for (String nodeName : subnodes){ if (!abstractNodes.containsKey(new NodeName(nodeName))){ return "The subnode " + nodeName + " is not exist."; } else { SubNodeBuilder subNodeBuilder = new SubNodeBuilder(); subNodeBuilder.setKey(new SubNodeKey(abstractNodes.get(new NodeName(nodeName)).getNodeId())) .setNodeId(abstractNodes.get(new NodeName(nodeName)).getNodeId()) .setOrder(order); order++; subNodeList.add(subNodeBuilder.build()); } } nodeBuilder.setSubNode(subNodeList); } } if (!propertyList.isEmpty()){ List<Property> properties = new LinkedList<Property>(); for (String propertyName : propertyList.keySet()){ PropertyBuilder builder = new PropertyBuilder(); builder.setKey(new PropertyKey(new PropertyName(propertyName))) .setPropertyName(new PropertyName(propertyName)); Map<String, String> values = propertyList.get(propertyName); PropertyValuesBuilder valuesBuilder = new PropertyValuesBuilder(); List<StringValue> stringValues = new LinkedList<StringValue>(); List<IntValue> intValues = new LinkedList<IntValue>(); RangeValue rangeValue = null; Long order = 0L; for (String value : values.keySet()){ if (values.get(value).equals(NEMOConstants.string)){ StringValueBuilder stringValueBuilder = new StringValueBuilder(); stringValueBuilder.setKey(new StringValueKey(order,value)) .setOrder(order) .setValue(value); order ++; stringValues.add(stringValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.integer)){ IntValueBuilder intValueBuilder = new IntValueBuilder(); intValueBuilder.setKey(new IntValueKey(order, Long.parseLong(value))) .setOrder(order) .setValue(Long.parseLong(value)); order ++; intValues.add(intValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.range)){ String[] range = value.split(","); RangeValueBuilder rangeValueBuilder = new RangeValueBuilder(); if (Long.parseLong(range[0])<Long.parseLong(range[1])){ rangeValueBuilder.setMin(Long.parseLong(range[0])); rangeValueBuilder.setMax(Long.parseLong(range[1])); } else{ rangeValueBuilder.setMin(Long.parseLong(range[1])); rangeValueBuilder.setMax(Long.parseLong(range[0])); } rangeValue = rangeValueBuilder.build(); } } valuesBuilder.setStringValue(stringValues.isEmpty()?null:stringValues) .setIntValue(intValues.isEmpty()?null:intValues) .setRangeValue(rangeValue); builder.setPropertyValues(valuesBuilder.build()); properties.add(builder.build()); } nodeBuilder.setProperty(properties); } abstractNodes.put(new NodeName(name),nodeBuilder.build()); return null; } UpdateTemplateDefinitionLang(DataBroker dataBroker, TenantManage tenantManage); String templateDefinitionLang(UserId userId, String templateName, LinkedHashMap<String, String> parameters); String createAbstractNode(String name, String type, List<String> subnodes, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList); String createAbstractConnection(String name, String type, List<String> endnodes, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList); String createAbstractFlow(String name,LinkedHashMap<String,LinkedHashMap<String,String>> matches,LinkedHashMap<String,LinkedHashMap<String,String>> propertyList); String createAbstractOperation(String name, String target, String priority, LinkedHashMap<String,LinkedHashMap<String,String>> conditions,LinkedHashMap<String,LinkedHashMap<String,String>>actions);  }
@Test public void testCreateAbstractNode() throws Exception { String name = new String("name"); String type = NEMOConstants.host; List<String> subnodes = new ArrayList<String>(); LinkedHashMap<String, LinkedHashMap<String,String>> propertyList = new LinkedHashMap<String, LinkedHashMap<String, String>>(); GetDefinitions getDefinitions = mock(GetDefinitions.class); String nodeName1 = new String("nodeName"); String propertyName = new String("propertyName"); String ValueName = new String("valuename"); String Value = NEMOConstants.string; NodeName nodeName = new NodeName(nodeName1); AbstractNode abstractNode = mock(AbstractNode.class); PhysicalHostId physicalHostId = mock(PhysicalHostId.class); PhysicalHost physicalHost = mock(PhysicalHost.class); LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); Map<PhysicalHostName, PhysicalHost> physicalHostMap = mock(Map.class); Map<NodeName, AbstractNode> abstractNodes = new HashMap<NodeName, AbstractNode>(); field.set(updateTemplateDefinitionLang, getDefinitions); subnodes.add(nodeName1); when(getDefinitions.getPhysicalHost()).thenReturn(physicalHostMap); when(physicalHostMap.containsKey(any(PhysicalHostName.class))) .thenReturn(false) .thenReturn(true); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractNode(name, type, subnodes, propertyList).equals("The host " + name + " is not exist in physical network.")); when(physicalHostMap.get(any(PhysicalHostName.class))).thenReturn(physicalHost); when(physicalHost.getHostId()).thenReturn(physicalHostId); when(physicalHostId.getValue()).thenReturn("00001111-0000-0000-0000-000011112222"); field_abstractNodes.set(updateTemplateDefinitionLang, abstractNodes); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractNode(name, type, subnodes, propertyList).equals("There are no nodes.")); abstractNodes.put(nodeName, abstractNode); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractNode(name, type, subnodes, propertyList) == null); propertyList.put(propertyName,values); values.put(ValueName,Value); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractNode(name, type, subnodes, propertyList) == null); values.clear(); values.put("11", NEMOConstants.integer); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractNode(name, type, subnodes, propertyList) == null); values.clear(); values.put("1,1", NEMOConstants.range); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractNode(name, type, subnodes, propertyList) == null); type = NEMOConstants.SubNodes; Assert.assertTrue(updateTemplateDefinitionLang.createAbstractNode(name, type, subnodes, propertyList) == null); }