UpdateTemplateDefinition { private String checkConnectionTemplate(AbstractConnection connection, Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap){ Map<ConnectionType, ConnectionDefinition> connDefinitions = getDefinitions.getConnectionDefinition(); if (connDefinitions.containsKey(connection.getConnectionType())){ ConnectionDefinition connectionDefinition = connDefinitions.get(connection.getConnectionType()); List<PropertyDefinition> propertyDefinitions = connectionDefinition.getPropertyDefinition(); Map<PropertyName, PropertyDefinition> connPropertyDefinition = new HashMap<PropertyName, PropertyDefinition>(); if (propertyDefinitions != null){ for (PropertyDefinition propertyDefinition : propertyDefinitions){ connPropertyDefinition.put(propertyDefinition.getPropertyName(),propertyDefinition); } } if (connection.getProperty()!=null){ for (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property property : connection.getProperty()){ if (connPropertyDefinition.containsKey(property.getPropertyName())){ PropertyDefinition.PropertyValueType type = connPropertyDefinition.get(property.getPropertyName()).getPropertyValueType(); if (type.getIntValue()==0){ List<StringValue> stringValues = property.getPropertyValues().getStringValue(); for (StringValue stringValue : stringValues){ TemplateParameter.ParameterValueType valueType = parameterValueTypeMap.get(new ParameterName(stringValue.getValue())); if (valueType!=null){ if (type.getIntValue()!= valueType.getIntValue()){ return "The property " + property.getPropertyName().getValue() + " type is not right."; } } } } } else { return "The property name " + property.getPropertyName().getValue() + " is not defined."; } } } } else { return "The connection type " + connection.getConnectionType().getValue() + " is not defined."; } return null; } UpdateTemplateDefinition(DataBroker dataBroker, TenantManage tenantManage); String checkTemplateDefinition(UserId userId, TemplateDefinition templateDefinition);  }
@Test public void testCheckConnectionTemplate() throws Exception{ method = class1.getDeclaredMethod("checkConnectionTemplate", new Class[]{ AbstractConnection.class, Map.class }); method.setAccessible(true); field = class1.getDeclaredField("getDefinitions"); field.setAccessible(true); GetDefinitions getDefinitions = mock(GetDefinitions.class); AbstractConnection connection = mock(AbstractConnection.class); ConnectionDefinition connectionDefinition = mock(ConnectionDefinition.class); ConnectionType connectionType = mock(ConnectionType.class); PropertyDefinition propertyDefinition = mock(PropertyDefinition.class); PropertyName propertyName = mock(PropertyName.class); PropertyValues propertyValues = mock(PropertyValues.class); StringValue stringValue = mock(StringValue.class); PropertyDefinition.PropertyValueType type = PropertyDefinition.PropertyValueType.String; TemplateParameter.ParameterValueType valueType = TemplateParameter.ParameterValueType.Int; org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property property = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property.class); List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property> properties = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property>(); List<PropertyDefinition> propertyDefinitions = new ArrayList<PropertyDefinition>(); List<StringValue> stringValues = new ArrayList<StringValue>(); Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap = new HashMap<ParameterName, TemplateParameter.ParameterValueType>(); Map<ConnectionType, ConnectionDefinition> connDefinitions = new HashMap<ConnectionType, ConnectionDefinition>(); field.set(updateTemplateDefinition, getDefinitions); propertyDefinitions.add(propertyDefinition); properties.add(property); stringValues.add(stringValue); parameterValueTypeMap.put(new ParameterName("ParameterName"), valueType); when(getDefinitions.getConnectionDefinition()).thenReturn(connDefinitions); when(connection.getConnectionType()).thenReturn(connectionType); when(connectionType.getValue()).thenReturn("test"); Assert.assertTrue(method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap).equals("The connection type " + connection.getConnectionType().getValue() + " is not defined.")); connDefinitions.put(connectionType, connectionDefinition); when(connectionDefinition.getPropertyDefinition()).thenReturn(propertyDefinitions); when(propertyDefinition.getPropertyName()).thenReturn(propertyName); when(connection.getProperty()) .thenReturn(null) .thenReturn(properties); Assert.assertTrue(method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap) == null); when(property.getPropertyName()) .thenReturn(mock(PropertyName.class)) .thenReturn(propertyName); when(propertyName.getValue()).thenReturn("test"); Assert.assertTrue(method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap).equals("The property name " + property.getPropertyName().getValue() + " is not defined.")); Assert.assertTrue(type.getIntValue() == 0); when(propertyDefinition.getPropertyValueType()) .thenReturn(PropertyDefinition.PropertyValueType.Int) .thenReturn(type); Assert.assertTrue(method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap) == null); verify(propertyDefinition).getPropertyValueType(); when(property.getPropertyValues()).thenReturn(propertyValues); when(propertyValues.getStringValue()).thenReturn(stringValues); when(stringValue.getValue()).thenReturn(new String("ParameterName")); Assert.assertTrue(parameterValueTypeMap.get(new ParameterName("ParameterName")) == valueType); Assert.assertTrue(method.invoke(updateTemplateDefinition, connection, parameterValueTypeMap).equals("The property " + property.getPropertyName().getValue() + " type is not right.")); verify(stringValue).getValue(); }