コード例 #1
0
  @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

  }
コード例 #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."));
  }