Пример #1
0
  @Test
  public void testDeleteOperationHandling() throws Exception {
    Class<DeleteOperationLang> class1 = DeleteOperationLang.class;
    Field field = class1.getDeclaredField("deleteOperation");
    field.setAccessible(true);

    UserId userId = mock(UserId.class);
    String operationname = new String("test");
    DeleteOperation deleteOperation = mock(DeleteOperation.class);

    when(tenantManage.getObjectId(userId, operationname))
        .thenReturn(null)
        .thenReturn(new String("00001111-0000-0000-0000-000011112222"));
    Assert.assertTrue(
        deleteOperationLang
            .DeleteOperationHandling(userId, operationname)
            .equals("The operation " + operationname + " is not exist."));
    verify(tenantManage).getObjectId(userId, operationname);

    field.set(deleteOperationLang, deleteOperation);
    when(deleteOperation.DeleteOperationhandling(any(UserId.class), any(OperationId.class)))
        .thenReturn(new String("test"));
    Assert.assertTrue(
        deleteOperationLang.DeleteOperationHandling(userId, operationname).equals("test"));
    verify(tenantManage, times(3)).getObjectId(userId, operationname);
  }
  @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

  }