예제 #1
0
  @org.junit.Test
  public void testCheckAllLayer3OperatingMode() throws Exception {

    when(subNode.getNodeId()).thenReturn(nodeId);
    NodeId otherid;
    otherid = mock(NodeId.class);
    when(node.getNodeId()).thenReturn(otherid);
    Assert.assertEquals(
        intentResolverUtils.checkAllLayer3OperatingMode(subNodeList, nodeList), false);

    when(node.getNodeId()).thenReturn(nodeId);
    when(subNode.getNodeId()).thenReturn(nodeId);
    // into getNodeProperty
    when(node.getProperty()).thenReturn(propertyList);
    propertyName = new PropertyName("operating-other");
    when(property.getPropertyName()).thenReturn(propertyName);
    Assert.assertEquals(
        intentResolverUtils.checkAllLayer3OperatingMode(subNodeList, nodeList), false);

    when(node.getNodeId()).thenReturn(nodeId);
    when(subNode.getNodeId()).thenReturn(nodeId);
    when(node.getProperty()).thenReturn(propertyList);
    propertyName = new PropertyName("operating-mode");
    when(property.getPropertyName()).thenReturn(propertyName);
    when(property.getPropertyValues()).thenReturn(propertyValues);
    when(property.getPropertyValues().getStringValue()).thenReturn(stringValueList);
    when(property.getPropertyValues().getStringValue().get(0).getValue())
        .thenReturn(new String("layer3"));

    Assert.assertEquals(
        intentResolverUtils.checkAllLayer3OperatingMode(subNodeList, nodeList), true);
  }
  @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

  }