UpdateTemplateDefinitionLang { public String createAbstractOperation(String name, String target, String priority, LinkedHashMap<String,LinkedHashMap<String,String>> conditions,LinkedHashMap<String,LinkedHashMap<String,String>>actions){ AbstractOperationBuilder operationBuilder = new AbstractOperationBuilder(); OperationId operationId = new OperationId(UUID.randomUUID().toString()); operationBuilder.setKey(new AbstractOperationKey(operationId)) .setOperationId(operationId) .setOperationName(new OperationName(name)) .setPriority(Long.parseLong(priority)); if (abstractNodes.containsKey(new NodeName(target))){ operationBuilder.setTargetObject(abstractNodes.get(new NodeName(target)).getNodeId()); } else if (abstractConnections.containsKey(new ConnectionName(target))){ operationBuilder.setTargetObject(abstractConnections.get(new ConnectionName(target)).getConnectionId()); } else if (abstractFlows.containsKey(new FlowName(target))){ operationBuilder.setTargetObject(abstractFlows.get(new FlowName(target)).getFlowId()); } if (!conditions.isEmpty()){ List<ConditionSegment> conditionSegmentList = new LinkedList<ConditionSegment>(); long order = 0; for (String conditionName : conditions.keySet()){ String[] condition = conditionName.split(NEMOConstants.comma); ConditionSegmentBuilder conditionSegmentBuilder = new ConditionSegmentBuilder(); ConditionSegmentId conditionSegmentId = new ConditionSegmentId(UUID.randomUUID().toString()); conditionSegmentBuilder.setKey(new ConditionSegmentKey(conditionSegmentId)) .setConditionSegmentId(conditionSegmentId) .setOrder(order); String preRelationOperator = condition[0]; if (preRelationOperator == null){ conditionSegmentBuilder.setPrecursorRelationOperator(ConditionSegment.PrecursorRelationOperator.None); } else if (preRelationOperator.equals(NEMOConstants.not)){ conditionSegmentBuilder.setPrecursorRelationOperator(ConditionSegment.PrecursorRelationOperator.Not); } else if (preRelationOperator.equals(NEMOConstants.and)){ conditionSegmentBuilder.setPrecursorRelationOperator(ConditionSegment.PrecursorRelationOperator.And); } else if (preRelationOperator.equals(NEMOConstants.or)){ conditionSegmentBuilder.setPrecursorRelationOperator(ConditionSegment.PrecursorRelationOperator.Or); } String condtionName = condition[1]; conditionSegmentBuilder.setConditionParameterName(new ConditionParameterName(condtionName)); String matchPattern = condition[2]; if (matchPattern.equals(NEMOConstants.equal)){ conditionSegmentBuilder.setConditionParameterMatchPattern(ConditionSegment.ConditionParameterMatchPattern.Equal); } else if (matchPattern.equals(NEMOConstants.not_equal)){ conditionSegmentBuilder.setConditionParameterMatchPattern(ConditionSegment.ConditionParameterMatchPattern.NotEqual); } else if (matchPattern.equals(NEMOConstants.greater_than)){ conditionSegmentBuilder.setConditionParameterMatchPattern(ConditionSegment.ConditionParameterMatchPattern.GreaterThan); } else if (matchPattern.equals(NEMOConstants.less_than)){ conditionSegmentBuilder.setConditionParameterMatchPattern(ConditionSegment.ConditionParameterMatchPattern.LessThan); } else if (matchPattern.equals(NEMOConstants.not_less_than)){ conditionSegmentBuilder.setConditionParameterMatchPattern(ConditionSegment.ConditionParameterMatchPattern.NotLessThan); } else if (matchPattern.equals(NEMOConstants.not_greater_than)){ conditionSegmentBuilder.setConditionParameterMatchPattern(ConditionSegment.ConditionParameterMatchPattern.NotGreaterThan); } else if (matchPattern.equals(NEMOConstants.between)){ conditionSegmentBuilder.setConditionParameterMatchPattern(ConditionSegment.ConditionParameterMatchPattern.Between); } Map<String, String> targetValue = conditions.get(conditionName); ConditionParameterTargetValueBuilder valueBuilder = new ConditionParameterTargetValueBuilder(); for (String value : targetValue.keySet()){ if (targetValue.get(value).equals(NEMOConstants.string)){ valueBuilder.setStringValue(value); } else if (targetValue.get(value).equals(NEMOConstants.integer)){ valueBuilder.setIntValue(Long.parseLong(value)); } else if (targetValue.get(value).equals(NEMOConstants.range)){ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.condition.segment.condition.parameter.target.value.RangeValueBuilder rangeValueBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.condition.segment.condition.parameter.target.value.RangeValueBuilder(); String[] values = value.split(NEMOConstants.comma); rangeValueBuilder.setMax(Long.parseLong(values[0])>Long.parseLong(values[1])?Long.parseLong(values[0]):Long.parseLong(values[1])) .setMin(Long.parseLong(values[0])<Long.parseLong(values[1])?Long.parseLong(values[0]):Long.parseLong(values[1])); valueBuilder.setRangeValue(rangeValueBuilder.build()); } } conditionSegmentBuilder.setConditionParameterTargetValue(valueBuilder.build()); order ++; conditionSegmentList.add(conditionSegmentBuilder.build()); } operationBuilder.setConditionSegment(conditionSegmentList); } if (!actions.isEmpty()){ List<Action> actionList = new LinkedList<Action>(); Long order = 0L; for (String actionName : actions.keySet()){ ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setKey(new ActionKey(new ActionName(actionName))) .setActionName(new ActionName(actionName)) .setOrder(order); Map<String, String> parameters = actions.get(actionName); if (parameters!=null){ ParameterValuesBuilder parameterValuesBuilder = new ParameterValuesBuilder(); Long valueOrder = 0L; List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue> stringValues = new LinkedList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue>(); List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValue> intValues = new LinkedList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValue>(); org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.RangeValue rangeValue = null; for (String value : parameters.keySet()){ if (parameters.get(value).equals(NEMOConstants.string)){ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValueBuilder valueBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValueBuilder(); valueBuilder.setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValueKey(valueOrder,value)) .setValue(value) .setOrder(valueOrder); valueOrder++; stringValues.add(valueBuilder.build()); } if (parameters.get(value).equals(NEMOConstants.integer)){ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValueBuilder valueBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValueBuilder(); valueBuilder.setKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValueKey(order,Long.parseLong(value))) .setValue(Long.parseLong(value)) .setOrder(valueOrder); valueOrder++; intValues.add(valueBuilder.build()); } if (parameters.get(value).equals(NEMOConstants.range)){ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.RangeValueBuilder rangeValueBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.RangeValueBuilder(); String[] range = value.split(","); valueOrder++; rangeValueBuilder.setMax(Long.parseLong(range[0])>Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])); } } if ((!stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue==null) ||(stringValues.isEmpty()&&!intValues.isEmpty()&&rangeValue==null) ||stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue!=null){ parameterValuesBuilder.setStringValue(stringValues.isEmpty()?null:stringValues) .setIntValue(intValues.isEmpty()?null:intValues) .setRangeValue(rangeValue); actionBuilder.setParameterValues(parameterValuesBuilder.build()); } else { return "The action values are not consistent."; } } actionList.add(actionBuilder.build()); } operationBuilder.setAction(actionList); } abstractOperations.put(new OperationName(name),operationBuilder.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 testCreateAbstractOperation() throws Exception { String name = new String("name"); String target = new String("target"); String priority = new String("1"); LinkedHashMap<String,LinkedHashMap<String,String>> conditions = new LinkedHashMap<String, LinkedHashMap<String, String>>(); LinkedHashMap<String,LinkedHashMap<String,String>>actions = new LinkedHashMap<String, LinkedHashMap<String, String>>(); String conditionName = new String("!,name,=="); String value = new String("value"); String actionName = new String("actionName"); AbstractNode abstractNode = mock(AbstractNode.class); AbstractFlow abstractFlow = mock(AbstractFlow.class); AbstractConnection abstractConnection = mock(AbstractConnection.class); LinkedHashMap<String,String> parameters = new LinkedHashMap<String, String>(); LinkedHashMap<String, String> targetValue = new LinkedHashMap<String, String>(); Map<NodeName, AbstractNode> abstractNodes = mock(Map.class); Map<ConnectionName, AbstractConnection> abstractConnections = mock(Map.class); Map<FlowName, AbstractFlow> abstractFlows = mock(Map.class); field_abstractNodes.set(updateTemplateDefinitionLang, abstractNodes); field_abstractConnections.set(updateTemplateDefinitionLang, abstractConnections); field_abstractFlows.set(updateTemplateDefinitionLang, abstractFlows); when(abstractNodes.containsKey(any(NodeName.class))).thenReturn(true); when(abstractNodes.get(new NodeName(target))).thenReturn(abstractNode); when(abstractNode.getNodeId()).thenReturn(mock(NodeId.class)); when(abstractConnections.containsKey(any(ConnectionName.class))).thenReturn(true); when(abstractConnections.get(new ConnectionName(target))).thenReturn(abstractConnection); when(abstractConnection.getConnectionId()).thenReturn(mock(ConnectionId.class)); when(abstractFlows.containsKey(any(FlowName.class))).thenReturn(true); when(abstractFlows.get(new FlowName(target))).thenReturn(abstractFlow); when(abstractFlow.getFlowId()).thenReturn(mock(FlowId.class)); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); targetValue.put(value,NEMOConstants.string); conditions.put(conditionName, targetValue); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); targetValue.clear(); conditions.clear(); targetValue.put("11", NEMOConstants.integer); conditions.put("&&,name,!=", targetValue); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); targetValue.clear(); conditions.clear(); targetValue.put("1,1", NEMOConstants.range); conditions.put("||,name,>", targetValue); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); targetValue.clear(); conditions.clear(); targetValue.put("1,1", NEMOConstants.range); conditions.put(",name,<", targetValue); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); targetValue.clear(); conditions.clear(); targetValue.put("1,1", NEMOConstants.range); conditions.put(",name,>=", targetValue); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); targetValue.clear(); conditions.clear(); targetValue.put("1,1", NEMOConstants.range); conditions.put(",name,<=", targetValue); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); targetValue.clear(); conditions.clear(); targetValue.put("1,1", NEMOConstants.range); conditions.put(",name,*", targetValue); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); targetValue.clear(); conditions.clear(); targetValue.put("1,1", NEMOConstants.range); conditions.put(",name,==", targetValue); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); parameters.put("string", NEMOConstants.string); actions.put(actionName, parameters); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); actions.clear(); parameters.clear(); parameters.put("11", NEMOConstants.integer); actions.put(actionName, parameters); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions) == null); actions.clear(); parameters.clear(); parameters.put("1,1", NEMOConstants.range); actions.put(actionName,parameters); Assert.assertTrue(updateTemplateDefinitionLang.createAbstractOperation(name, target, priority, conditions, actions).equals("The action values are not consistent.")); }