@Test
  public void testSetAmount2() throws Exception {
    System.out.println("setAmount2");

    /* Set up a new loan */
    Loan target = new Loan();

    /* get the setAmount method details */
    Method method = Loan.class.getDeclaredMethod("setAmount", double.class);

    /* make the field assessible */
    method.setAccessible(true);

    /* invoke the method setAmount with the value 3000.0 */
    method.invoke(target, 3000.0);

    /*access the field loanAmount and check its value is set the 3000.0*/
    Class secretClass = target.getClass();
    Field f = secretClass.getDeclaredField("loanAmount");
    f.setAccessible(true);

    double result = f.getDouble(target);

    assertEquals("The amounts should be equal", 3000.00, result, 0.0);
  }
 protected void invokeKey(String name) throws Exception {
   if (!needsKey) return;
   BehaviorSkinBase skin = (BehaviorSkinBase) getView().getSkin();
   BehaviorBase behavior = skin.getBehavior();
   Class<? extends BehaviorBase> behaviorClass = behavior.getClass();
   Field field = behaviorClass.getDeclaredField(name);
   field.setAccessible(true);
   field.set(behavior, true);
 }
  @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."));
    // test add matchItem
    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."));
  }
Пример #4
0
  private Object getValueOfField(String fieldname, Class<?> sourceClass, Object source) {
    String sourceClassName = sourceClass.getName();

    Field field = null;
    try {
      field = sourceClass.getDeclaredField(fieldname);
      field.setAccessible(true);
    } catch (SecurityException e) {
      fail(
          "Unable to retrieve "
              + fieldname
              + " field from "
              + sourceClassName
              + ": "
              + e.getCause());
    } catch (NoSuchFieldException e) {
      fail(
          "Unable to retrieve "
              + fieldname
              + " field from "
              + sourceClassName
              + ": "
              + e.getCause());
    }

    assertNotNull("." + fieldname + " field is null!?!", field);
    Object fieldValue = null;
    try {
      fieldValue = field.get(source);
    } catch (IllegalArgumentException e) {
      fail(
          "Unable to retrieve value of "
              + fieldname
              + " from "
              + sourceClassName
              + ": "
              + e.getCause());
    } catch (IllegalAccessException e) {
      fail(
          "Unable to retrieve value of "
              + fieldname
              + " from "
              + sourceClassName
              + ": "
              + e.getCause());
    }
    return fieldValue;
  }
  @Test
  public void testSetPeriod() throws Exception {
    System.out.println("test setPeriod()");

    Loan target = new Loan();

    Method method = Loan.class.getDeclaredMethod("setPeriod", int.class);

    method.setAccessible(true);

    method.invoke(target, 2);

    Class secretClass = target.getClass();
    Field f = secretClass.getDeclaredField("numberOfPayments");
    f.setAccessible(true);

    int result = f.getInt(target);

    assertEquals("The number of payments should be equal", 24, result);
  }
  /** Accessing a private field Test of loanamount, of class Loan. */
  @Test
  public void testSetAmount1() throws Exception {
    System.out.println("setAmount1");
    Loan target = new Loan(4000.0, 10.0, 5);

    /*creat secret class */
    Class secretClass = target.getClass();

    /* The the private field */
    Field f = secretClass.getDeclaredField("loanAmount");

    /*Set tha field to accessible */
    f.setAccessible(true);
    System.out.println("The value in f is " + f.get(target));

    /*get the value of the field */
    double result = f.getDouble(target);

    /*Assert the value is correct */
    assertEquals("The amounts should be equal", 4000.00, result, 0.0);
  }
Пример #7
0
  @Test
  public void bindingTest() throws Exception {

    // String nativesPath = testOutput + "/build/natives";
    // System.load(nativesPath + "/librofl.so");
    System.loadLibrary("rofl");

    Class<?> clazz = Class.forName("test.BindingTest");

    assertEquals((long) 0xFFFFFFFF, clazz.getDeclaredField("GL_INVALID_INDEX").get(null));
    assertEquals(-0.5f, clazz.getDeclaredField("AL_FLANGER_DEFAULT_FEEDBACK").get(null));

    // TODO fix Exception: ...Caused by: java.lang.UnsatisfiedLinkError:
    // test.BindingTest.arrayTest0(JLjava/lang/Object;I)I
    /*
    // test values
    ByteBuffer dbb = Buffers.newDirectByteBuffer(32);
    ByteBuffer bb  = ByteBuffer.allocate(32).order(ByteOrder.nativeOrder());

    PointerBuffer dpb = PointerBuffer.allocateDirect(32);
    PointerBuffer pb  = PointerBuffer.allocate(32);

    long[] array = new long[] {1,2,3,4,5,6,7,8,9};
    int offset = 0;
    long id = 42;


    // invoke everything public
    Object bindingTest = clazz.newInstance();
    Method[] methods = clazz.getDeclaredMethods();

    for (Method method : methods) {

        // prepare method parameters
        Class<?>[] paramTypes = method.getParameterTypes();
        Object[] paramInstances = new Object[paramTypes.length];

        for (int i = 0; i < paramTypes.length; i++) {
            Class<?> paramType = paramTypes[i];
            if(paramType.isInstance(dbb)) {
                paramInstances[i] = dbb;
            }else if(paramType.isInstance(bb)) {
                paramInstances[i] = bb;
            }else if(paramType.isInstance(dpb)) {
                paramInstances[i] = dpb;
            }else if(paramType.isInstance(pb)) {
                paramInstances[i] = pb;
            }else if(paramType.isPrimitive()) { // TODO primitive types
                paramInstances[i] = offset;
            }else if(paramType.isArray()) {     // TODO array types
                paramInstances[i] = array;
            }
        }

        out.println("invoking: "+method);
        out.println("with params: ");
        for (Object param : paramInstances)
            out.print(param+", ");
        out.println();

        Object result = method.invoke(bindingTest, paramInstances);
        out.println("result: "+result);
        out.println("success");
    }
    */
  }
 private Object getField(String fieldName, Class<?> clazz, Object obj) throws Exception {
   Field field = clazz.getDeclaredField(fieldName);
   field.setAccessible(true);
   return field.get(obj);
 }
  @Test
  public void testCheckTemplateDefinition() throws Exception {
    field = class1.getDeclaredField("getDefinitions");
    field.setAccessible(true);

    GetDefinitions getDefinitions = mock(GetDefinitions.class);
    UserId userId = mock(UserId.class);
    NodeId nodeId = mock(NodeId.class);
    SubNode subNode = mock(SubNode.class);
    EndNode endNode = mock(EndNode.class);
    TemplateDefinition templateDefinition = mock(TemplateDefinition.class);
    TemplateName templateName = mock(TemplateName.class);
    ParameterName parameterName = mock(ParameterName.class);
    AbstractIntents abstractIntents = mock(AbstractIntents.class);
    TemplateParameter.ParameterValueType parameterValueType =
        TemplateParameter.ParameterValueType.Int;
    TemplateParameter templateParameter = mock(TemplateParameter.class);
    AbstractObjects abstractObjects = mock(AbstractObjects.class);
    AbstractNode node = mock(AbstractNode.class);
    AbstractNode node1 = mock(AbstractNode.class);
    NodeType nodeType = mock(NodeType.class);
    NodeDefinition nodeDefinition = mock(NodeDefinition.class);
    AbstractConnection connection = mock(AbstractConnection.class);
    List<PropertyDefinition> propertyDefinitions = new ArrayList<PropertyDefinition>();
    List<TemplateParameter> list = new ArrayList<TemplateParameter>();
    List<AbstractNode> nodeList = new ArrayList<AbstractNode>();
    List<SubNode> subNodeList = new ArrayList<SubNode>();
    List<EndNode> endNodeList = new ArrayList<EndNode>();
    List<AbstractNode> nodeList1 = new ArrayList<AbstractNode>();
    List<AbstractConnection> connectionList = new ArrayList<AbstractConnection>();
    Map<TemplateName, TemplateDefinition> map = mock(Map.class);
    Map<NodeType, NodeDefinition> nodeDefinitions = mock(Map.class);
    Map<ConnectionType, ConnectionDefinition> connDefinitions = mock(Map.class);
    field.set(updateTemplateDefinition, getDefinitions);
    //        nodeDefinitions.put(nodeType, nodeDefinition);
    list.add(templateParameter);
    endNodeList.add(endNode);
    nodeList.add(node);
    nodeList1.add(node1);
    subNodeList.add(subNode);
    connectionList.add(connection);

    when(getDefinitions.getNodeDefinition()).thenReturn(nodeDefinitions);
    when(tenantManage.getTempalteDefinition(userId))
        .thenReturn(map)
        .thenReturn(map)
        .thenReturn(null);
    when(templateDefinition.getTemplateName()).thenReturn(templateName);
    when(templateName.getValue()).thenReturn("test");
    when(map.containsKey(templateDefinition.getTemplateName())).thenReturn(true);
    Assert.assertTrue(
        updateTemplateDefinition
            .checkTemplateDefinition(userId, templateDefinition)
            .equals(
                "The template "
                    + templateDefinition.getTemplateName().getValue()
                    + " has been defined."));
    verify(tenantManage, times(2)).getTempalteDefinition(userId);
    when(templateDefinition.getTemplateParameter()).thenReturn(list);
    when(templateParameter.getParameterName()).thenReturn(parameterName);
    when(templateParameter.getParameterValueType()).thenReturn(parameterValueType);
    when(templateDefinition.getAbstractIntents()).thenReturn(abstractIntents);
    when(abstractIntents.getAbstractObjects()).thenReturn(abstractObjects);
    when(abstractObjects.getAbstractNode()).thenReturn(nodeList);
    when(node.getNodeId()).thenReturn(nodeId);
    when(node.getSubNode()).thenReturn(subNodeList);
    when(subNode.getNodeId()).thenReturn(mock(NodeId.class)).thenReturn(nodeId);
    Assert.assertTrue(
        updateTemplateDefinition
            .checkTemplateDefinition(userId, templateDefinition)
            .equals("The sub node is not defined."));
    // get into method "checkNodeTemplate" args(node,map) map(parameterName,parameterValueType)
    when(node.getNodeType()).thenReturn(nodeType);
    when(nodeDefinitions.containsKey(node.getNodeType())).thenReturn(true);
    when(nodeDefinitions.get(node.getNodeType())).thenReturn(nodeDefinition);
    when(nodeDefinition.getPropertyDefinition()).thenReturn(null);
    when(node.getProperty()).thenReturn(null);
    // return

  }
  @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);
    // test condition
    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."));

    // test action
    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."));
  }
  @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();
  }
  @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."));
  }