UpdateTemplateDefinition { private String checkOperationTemplate(AbstractOperation operation, Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap){ Map<ParameterName, ConditionParameterDefinition> conditionParameterDefinitionMap = getDefinitions.getConditionParameterDefinition(); Map<ActionName, ActionDefinition> actionDefinitionMap = getDefinitions.getActionDefinition(); List<ConditionSegment> conditionSegmentList = operation.getConditionSegment(); List<Action> actionList = operation.getAction(); if (conditionSegmentList!=null){ for (ConditionSegment conditionSegment : conditionSegmentList){ if (conditionParameterDefinitionMap.containsKey(conditionSegment.getConditionParameterName())){ if (conditionSegment.getConditionParameterTargetValue()!=null){ ConditionParameterDefinition definition = conditionParameterDefinitionMap.get(conditionSegment.getConditionParameterName()); ConditionParameterDefinition.ParameterValueType type = definition.getParameterValueType(); if (type.getIntValue()==0){ String valuePrameter = conditionSegment.getConditionParameterTargetValue().getStringValue(); TemplateParameter.ParameterValueType valueType = parameterValueTypeMap.get(new ParameterName(valuePrameter)); if (valueType!=null){ if (type.getIntValue()!=valueType.getIntValue()){ return "The condition " + conditionSegment.getConditionParameterName().getValue() +" type is not right."; } } } } } else { return "The Condition " + conditionSegment.getConditionParameterName().getValue() + " is not defined."; } } } if (actionList!=null){ for (Action action : actionList){ if (actionDefinitionMap.containsKey(action.getActionName())){ if (action.getParameterValues()!=null){ ActionDefinition actionDefinition = actionDefinitionMap.get(action.getActionName()); ActionDefinition.ParameterValueType type = actionDefinition.getParameterValueType(); if (type.getIntValue()==0){ List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue> stringValues = action.getParameterValues().getStringValue(); for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue stringValue : stringValues){ TemplateParameter.ParameterValueType valueType = parameterValueTypeMap.get(new ParameterName(stringValue.getValue())); if (valueType!=null){ if (type.getIntValue()!=valueType.getIntValue()){ return "The action " + action.getActionName().getValue() +" type is not right."; } } } } } } else { return "The action " + action.getActionName().getValue() + " is not defined."; } } } return null; } UpdateTemplateDefinition(DataBroker dataBroker, TenantManage tenantManage); String checkTemplateDefinition(UserId userId, TemplateDefinition templateDefinition);  }
@Test public void testCheckOperationTemplate() throws Exception{ method = class1.getDeclaredMethod("checkOperationTemplate",new Class[]{ AbstractOperation.class, Map.class }); method.setAccessible(true); field = class1.getDeclaredField("getDefinitions"); field.setAccessible(true); GetDefinitions getDefinitions = mock(GetDefinitions.class); Action action = mock(Action.class); ActionName actionName = mock(ActionName.class); ActionDefinition actionDefinition = mock(ActionDefinition.class); AbstractOperation operation = mock(AbstractOperation.class); ConditionSegment conditionSegment = mock(ConditionSegment.class); ParameterName parameterName = mock(ParameterName.class); ParameterValues parameterValues = mock(ParameterValues.class); ConditionParameterName conditionParameterName = mock(ConditionParameterName.class); ConditionParameterDefinition definition = mock(ConditionParameterDefinition.class); ConditionParameterDefinition conditionParameterDefinition = mock(ConditionParameterDefinition.class); ConditionParameterTargetValue conditionParameterTargetValue = mock(ConditionParameterTargetValue.class); ConditionParameterDefinition.ParameterValueType type = ConditionParameterDefinition.ParameterValueType.String; TemplateParameter.ParameterValueType valueType = TemplateParameter.ParameterValueType.Int; ActionDefinition.ParameterValueType type1 = ActionDefinition.ParameterValueType.String; org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue stringValue = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue.class); List<Action> actionList = new ArrayList<Action>(); List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue> stringValues = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue>(); List<ConditionSegment> conditionSegmentList = new ArrayList<ConditionSegment>(); Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap = new HashMap<ParameterName, TemplateParameter.ParameterValueType>(); Map<ActionName, ActionDefinition> actionDefinitionMap = new HashMap<ActionName, ActionDefinition>(); Map<ParameterName, ConditionParameterDefinition> conditionParameterDefinitionMap = mock(Map.class); field.set(updateTemplateDefinition, getDefinitions); conditionSegmentList.add(conditionSegment); parameterValueTypeMap.put(new ParameterName("ParameterName"), valueType); conditionParameterDefinitionMap.put(parameterName, conditionParameterDefinition); when(getDefinitions.getActionDefinition()).thenReturn(actionDefinitionMap); when(getDefinitions.getConditionParameterDefinition()).thenReturn(conditionParameterDefinitionMap); when(operation.getConditionSegment()) .thenReturn(null) .thenReturn(conditionSegmentList); when(operation.getAction()) .thenReturn(null) .thenReturn(actionList); Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null); when(conditionSegment.getConditionParameterName()) .thenReturn(conditionParameterName); when(conditionParameterDefinitionMap.containsKey(conditionSegment.getConditionParameterName())) .thenReturn(false) .thenReturn(true); when(parameterName.getValue()).thenReturn("test"); Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap).equals("The Condition " + conditionSegment.getConditionParameterName().getValue() + " is not defined.")); when(conditionSegment.getConditionParameterTargetValue()) .thenReturn(null) .thenReturn(conditionParameterTargetValue); Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null); when(conditionParameterDefinitionMap.get(conditionSegment.getConditionParameterName())).thenReturn(definition); when(definition.getParameterValueType()) .thenReturn(ConditionParameterDefinition.ParameterValueType.Int) .thenReturn(type); Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null); when(conditionParameterTargetValue.getStringValue()).thenReturn("ParameterName"); Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap).equals("The condition " + conditionSegment.getConditionParameterName().getValue() + " type is not right.")); conditionSegmentList.clear(); actionList.add(action); stringValues.add(stringValue); when(action.getActionName()).thenReturn(actionName); when(actionName.getValue()).thenReturn("test"); Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap).equals("The action " + action.getActionName().getValue() + " is not defined.")); actionDefinitionMap.put(actionName, actionDefinition); when(action.getParameterValues()) .thenReturn(null) .thenReturn(parameterValues); Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap) == null); when(actionDefinition.getParameterValueType()).thenReturn(type1); when(parameterValues.getStringValue()).thenReturn(stringValues); when(stringValue.getValue()).thenReturn("ParameterName"); Assert.assertTrue(method.invoke(updateTemplateDefinition, operation, parameterValueTypeMap).equals("The action " + action.getActionName().getValue() +" type is not right.")); }