コード例 #1
0
  @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();
  }
コード例 #2
0
  @Test
  public void testCheckNodeTemplate() throws Exception {
    method =
        class1.getDeclaredMethod("checkNodeTemplate", new Class[] {AbstractNode.class, Map.class});
    method.setAccessible(true);
    field = class1.getDeclaredField("getDefinitions");
    field.setAccessible(true);

    GetDefinitions getDefinitions = mock(GetDefinitions.class);
    AbstractNode node = mock(AbstractNode.class);
    NodeType nodeType = mock(NodeType.class);
    NodeDefinition nodeDefinition = mock(NodeDefinition.class);
    PropertyName propertyName = mock(PropertyName.class);
    Property property = mock(Property.class);
    StringValue stringValue = mock(StringValue.class);
    PropertyValues propertyValues = mock(PropertyValues.class);
    PropertyDefinition.PropertyValueType type = PropertyDefinition.PropertyValueType.String;
    PropertyDefinition propertyDefinition = mock(PropertyDefinition.class);
    TemplateParameter.ParameterValueType valueType = TemplateParameter.ParameterValueType.Int;
    List<Property> properties = new ArrayList<Property>();
    List<StringValue> stringValues = new ArrayList<StringValue>();
    List<PropertyDefinition> propertyDefinitions = new ArrayList<PropertyDefinition>();
    Map<ParameterName, TemplateParameter.ParameterValueType> parameterValueTypeMap =
        new HashMap<ParameterName, TemplateParameter.ParameterValueType>();
    Map<NodeType, NodeDefinition> nodeDefinitions = new HashMap<NodeType, NodeDefinition>();

    parameterValueTypeMap.put(new ParameterName("ParameterName"), valueType);

    field.set(updateTemplateDefinition, getDefinitions);
    when(getDefinitions.getNodeDefinition()).thenReturn(nodeDefinitions);
    when(node.getNodeType()).thenReturn(nodeType);
    when(nodeType.getValue()).thenReturn("test");
    // test null
    Assert.assertTrue(
        method
            .invoke(updateTemplateDefinition, node, parameterValueTypeMap)
            .equals("The node type " + node.getNodeType().getValue() + " is not defined."));
    verify(node, times(3)).getNodeType();
    // test not null
    nodeDefinitions.put(nodeType, nodeDefinition);
    propertyDefinitions.add(propertyDefinition);
    properties.add(property);
    stringValues.add(stringValue);
    Assert.assertTrue(nodeDefinitions.get(nodeType) == nodeDefinition);
    when(nodeDefinition.getPropertyDefinition()).thenReturn(propertyDefinitions);
    when(propertyDefinition.getPropertyName()).thenReturn(propertyName);
    when(propertyName.getValue()).thenReturn("test");
    when(node.getProperty()).thenReturn(null).thenReturn(properties);
    Assert.assertTrue(method.invoke(updateTemplateDefinition, node, parameterValueTypeMap) == null);
    when(property.getPropertyName()).thenReturn(mock(PropertyName.class)).thenReturn(propertyName);
    Assert.assertTrue(
        method
            .invoke(updateTemplateDefinition, node, parameterValueTypeMap)
            .equals(
                "The property name " + property.getPropertyName().getValue() + " is not defined."));
    when(propertyDefinition.getPropertyValueType())
        .thenReturn(PropertyDefinition.PropertyValueType.Int)
        .thenReturn(type);
    //        System.out.println("type" + type.getIntValue());
    Assert.assertTrue(method.invoke(updateTemplateDefinition, node, parameterValueTypeMap) == null);
    when(property.getPropertyValues()).thenReturn(propertyValues);
    when(propertyValues.getStringValue()).thenReturn(stringValues);
    when(stringValue.getValue()).thenReturn(new String("ParameterName"));
    Assert.assertTrue(
        method
            .invoke(updateTemplateDefinition, node, parameterValueTypeMap)
            .equals(
                "The property " + property.getPropertyName().getValue() + " type is not right."));
  }