UpdateTemplateDefinition { private String checkFlowTemplate(AbstractFlow flow, Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap){ Map<MatchItemName, MatchItemDefinition> matchItemDefinitionMap = getDefinitions.getMatchItemDefinition(); List<MatchItem> matchItemList = flow.getMatchItem(); for (MatchItem matchItem : matchItemList){ if (matchItemDefinitionMap.containsKey(matchItem.getMatchItemName())){ MatchItemDefinition matchItemDefinition = matchItemDefinitionMap.get(matchItem.getMatchItemName()); MatchItemDefinition.MatchItemValueType type = matchItemDefinition.getMatchItemValueType(); if (type.getIntValue()==0){ String stringValues = matchItem.getMatchItemValue().getStringValue(); TemplateParameter.ParameterValueType valueType = parameterValueTypeMap.get(new ParameterName(stringValues)); if (valueType!=null){ if (type.getIntValue() != valueType.getIntValue()){ return "The match item " + stringValues+" type is not right."; } } } } else { return "The match item " + matchItem.getMatchItemName().getValue() +" is not defined."; } } return null; } UpdateTemplateDefinition(DataBroker dataBroker, TenantManage tenantManage); String checkTemplateDefinition(UserId userId, TemplateDefinition templateDefinition);  }
@Test public void testCheckFlowTemplate() throws Exception{ method = class1.getDeclaredMethod("checkFlowTemplate",new Class[]{ AbstractFlow.class, Map.class }); method.setAccessible(true); field = class1.getDeclaredField("getDefinitions"); field.setAccessible(true); GetDefinitions getDefinitions = mock(GetDefinitions.class); AbstractFlow flow = mock(AbstractFlow.class); MatchItem matchItem = mock(MatchItem.class); List<MatchItem> matchItemList = new ArrayList<MatchItem>(); MatchItemValue matchItemValue = mock(MatchItemValue.class); MatchItemName matchItemName = mock(MatchItemName.class); MatchItemDefinition matchItemDefinition = mock(MatchItemDefinition.class); MatchItemDefinition.MatchItemValueType type = MatchItemDefinition.MatchItemValueType.String; TemplateParameter.ParameterValueType valueType = TemplateParameter.ParameterValueType.Int; Map<MatchItemName, MatchItemDefinition> matchItemDefinitionMap = new HashMap<MatchItemName, MatchItemDefinition>(); Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap = new HashMap<ParameterName, TemplateParameter.ParameterValueType>(); field.set(updateTemplateDefinition, getDefinitions); parameterValueTypeMap.put(new ParameterName("ParameterName"),valueType); when(getDefinitions.getMatchItemDefinition()).thenReturn(matchItemDefinitionMap); when(flow.getMatchItem()).thenReturn(matchItemList); Assert.assertTrue(method.invoke(updateTemplateDefinition, flow, parameterValueTypeMap) == null); matchItemList.add(matchItem); when(matchItem.getMatchItemName()).thenReturn(matchItemName); when(matchItemName.getValue()).thenReturn("test"); Assert.assertTrue(method.invoke(updateTemplateDefinition, flow, parameterValueTypeMap).equals("The match item " + matchItem.getMatchItemName().getValue() +" is not defined.")); matchItemDefinitionMap.put(matchItemName,matchItemDefinition); Assert.assertTrue(matchItemDefinitionMap.containsKey(matchItemName)); when(matchItemDefinition.getMatchItemValueType()) .thenReturn(MatchItemDefinition.MatchItemValueType.Int) .thenReturn(type); Assert.assertTrue(method.invoke(updateTemplateDefinition, flow, parameterValueTypeMap) == null); when(matchItem.getMatchItemValue()).thenReturn(matchItemValue); when(matchItemValue.getStringValue()).thenReturn("ParameterName"); Assert.assertTrue(method.invoke(updateTemplateDefinition, flow, parameterValueTypeMap).equals("The match item " + "ParameterName" +" type is not right.")); }