UpdateTemplateDefinitionLang { public String createAbstractConnection(String name, String type, List<String> endnodes, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList){ AbstractConnectionBuilder connectionBuilder = new AbstractConnectionBuilder(); ConnectionId connectionId = new ConnectionId(UUID.randomUUID().toString()); connectionBuilder.setKey(new AbstractConnectionKey(connectionId)) .setConnectionId(connectionId) .setConnectionName(new ConnectionName(name)) .setConnectionType(new ConnectionType(type)); List<EndNode> endNodeList = new LinkedList<EndNode>(); if (abstractNodes.isEmpty()){ return "There are nodes exist."; } else { long order = 0L; for (String endNode : endnodes){ if (!abstractNodes.containsKey(new NodeName(endNode))){ return "The endnode " + endNode + " is not exit."; } else { EndNodeBuilder endNodeBuilder = new EndNodeBuilder(); endNodeBuilder.setKey(new EndNodeKey(abstractNodes.get(new NodeName(endNode)).getNodeId())) .setNodeId(abstractNodes.get(new NodeName(endNode)).getNodeId()) .setOrder(order); order++; endNodeList.add(endNodeBuilder.build()); } } } connectionBuilder.setEndNode(endNodeList.isEmpty()?null:endNodeList); if (!propertyList.isEmpty()){ List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property> properties = new LinkedList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property>(); for (String propertyName : propertyList.keySet()){ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.PropertyBuilder builder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.PropertyBuilder(); builder.setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.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()); } connectionBuilder.setProperty(properties); } abstractConnections.put(new ConnectionName(name),connectionBuilder.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 testCreateAbstractConnection() throws Exception { String name = new String("name"); String type = NEMOConstants.host; String endNode = new String("endNode"); String propertyName = new String("propertyName"); String ValueName = new String("valuename"); String Value = NEMOConstants.string; List<String> endnodes = new ArrayList<String>(); NodeName nodeName = mock(NodeName.class); NodeId nodeId = mock(NodeId.class); AbstractNode abstractNode = mock(AbstractNode.class); LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); LinkedHashMap<String, LinkedHashMap<String,String>> propertyList = new LinkedHashMap<String, LinkedHashMap<String, String>>(); Map<NodeName, AbstractNode> abstractNodes = new HashMap<NodeName, AbstractNode>(); abstractNodes.put(nodeName, abstractNode); endnodes.add(endNode); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractConnection(name, type, endnodes, propertyList).equals("There are nodes exist.")); field_abstractNodes.set(updateTemplateDefinitionLang, abstractNodes); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractConnection(name, type, endnodes, propertyList).equals("The endnode " + endNode + " is not exit.")); abstractNodes.clear(); abstractNodes.put(new NodeName(endNode), abstractNode); when(abstractNode.getNodeId()).thenReturn(nodeId); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractConnection(name, type, endnodes, propertyList) == null); propertyList.put(propertyName, values); values.put(ValueName,Value); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractConnection(name, type, endnodes, propertyList) == null); values.clear(); values.put("11", NEMOConstants.integer); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractConnection(name, type, endnodes, propertyList) == null); values.clear(); values.put("1,1", NEMOConstants.range); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractConnection(name, type, endnodes, propertyList) == null); }