@org.junit.Test public void testGetConnectionProperty() throws Exception { when(propertyconnection.getPropertyName()).thenReturn(propertyName); Assert.assertEquals( intentResolverUtils.getConnectionProperty(propertyListconnection, propertyName), propertyconnection); }
@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"); // test null Assert.assertTrue( method .invoke(updateTemplateDefinition, connection, parameterValueTypeMap) .equals( "The connection type " + connection.getConnectionType().getValue() + " is not defined.")); // test not null 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); // System.out.println((String) method.invoke(updateTemplateDefinition, connection, // parameterValueTypeMap)); // System.out.println("valuetype" + valueType.getIntValue()); Assert.assertTrue( method .invoke(updateTemplateDefinition, connection, parameterValueTypeMap) .equals( "The property " + property.getPropertyName().getValue() + " type is not right.")); verify(stringValue).getValue(); }