/**
   * Test method for {@link
   * org.eclipse.wst.sse.sieditor.ui.v2.wsdl.controller.SIFormPageController#editOperationTypeTriggered(org.eclipse.wst.sse.sieditor.ui.v2.nodes.ITreeNode,
   * org.eclipse.wst.sse.sieditor.model.wsdl.api.OperationType)} .
   *
   * @throws CoreException
   * @throws IOException
   */
  @Test
  public final void testEditOperationTypeTriggered() throws IOException, CoreException {
    IWsdlModelRoot wsdlRoot =
        getWSDLModelRoot(
            org.eclipse.wst.sse.sieditor.test.model.Constants.DATA_PUBLIC_SELF_KESHAV
                + "Documentation.wsdl",
            "Documentation.wsdl"); //$NON-NLS-1$ //$NON-NLS-2$
    TestSIFormPageController sifpc = new TestSIFormPageController(wsdlRoot, false);
    sifpc.isEditAllowed = Boolean.valueOf(false);

    StatusUtils.isUnderJunitExecution = true;
    long statusCalls = StatusUtils.getShowStatusDialog_calls();

    IServiceInterface serviceInterface =
        wsdlRoot.getDescription().getAllInterfaces().iterator().next();
    ServiceInterfaceNode siNode = new ServiceInterfaceNode(null, serviceInterface, sifpc);
    OperationNode operationNodeToEdit = (OperationNode) siNode.getChildren()[0];

    OperationType oldType = operationNodeToEdit.getModelObject().getOperationStyle();
    OperationType newType = OperationType.ASYNCHRONOUS;
    assertNotSame(newType, oldType);

    sifpc.editOperationTypeTriggered(operationNodeToEdit, newType);

    assertEquals(oldType, operationNodeToEdit.getModelObject().getOperationStyle());
    assertEquals(1, StatusUtils.getShowStatusDialog_calls() - statusCalls);

    sifpc.isEditAllowed = Boolean.valueOf(true);
    statusCalls = StatusUtils.getShowStatusDialog_calls();

    sifpc.editOperationTypeTriggered(operationNodeToEdit, newType);

    assertEquals(newType, operationNodeToEdit.getModelObject().getOperationStyle());
    assertEquals(0, StatusUtils.getShowStatusDialog_calls() - statusCalls);
  }
  /**
   * Test method for {@link
   * org.eclipse.wst.sse.sieditor.ui.v2.wsdl.controller.SIFormPageController#editItemNameTriggered(org.eclipse.wst.sse.sieditor.ui.v2.nodes.ITreeNode,
   * java.lang.String)} .
   *
   * @throws CoreException
   * @throws IOException
   */
  @Test
  public final void testEditItemNameTriggered() throws IOException, CoreException {
    IWsdlModelRoot wsdlRoot =
        getWSDLModelRoot(
            org.eclipse.wst.sse.sieditor.test.model.Constants.DATA_PUBLIC_SELF_KESHAV
                + "Documentation.wsdl",
            "Documentation.wsdl"); //$NON-NLS-1$ //$NON-NLS-2$
    TestSIFormPageController sifpc = new TestSIFormPageController(wsdlRoot, false);
    sifpc.isEditAllowed = Boolean.valueOf(false);

    StatusUtils.isUnderJunitExecution = true;
    long statusCalls = StatusUtils.getShowStatusDialog_calls();

    IServiceInterface serviceInterface =
        wsdlRoot.getDescription().getAllInterfaces().iterator().next();
    ServiceInterfaceNode siNode = new ServiceInterfaceNode(null, serviceInterface, sifpc);

    String oldName = siNode.getDisplayName();
    String newName = "NewServiceInterfaceName"; // $NON-NLS-1$

    sifpc.editItemNameTriggered(siNode, newName);

    assertEquals(oldName, siNode.getDisplayName());
    assertEquals(1, StatusUtils.getShowStatusDialog_calls() - statusCalls);

    sifpc.isEditAllowed = Boolean.valueOf(true);
    statusCalls = StatusUtils.getShowStatusDialog_calls();

    sifpc.editItemNameTriggered(siNode, newName);

    assertEquals(newName, siNode.getDisplayName());
    assertEquals(0, StatusUtils.getShowStatusDialog_calls() - statusCalls);
  }
  /**
   * Test method for {@link
   * org.eclipse.wst.sse.sieditor.ui.v2.wsdl.controller.SIFormPageController#deleteItemTriggered(org.eclipse.wst.sse.sieditor.ui.v2.nodes.ITreeNode)}
   * .
   *
   * @throws CoreException
   * @throws IOException
   */
  @Test
  public final void testDeleteItemTriggered() throws IOException, CoreException {
    IWsdlModelRoot wsdlRoot =
        getWSDLModelRoot(
            org.eclipse.wst.sse.sieditor.test.model.Constants.DATA_PUBLIC_SELF_KESHAV
                + "Documentation.wsdl",
            "Documentation.wsdl"); //$NON-NLS-1$
    TestSIFormPageController sifpc = new TestSIFormPageController(wsdlRoot, false);
    sifpc.isEditAllowed = Boolean.valueOf(true);

    StatusUtils.isUnderJunitExecution = true;
    long statusCalls = StatusUtils.getShowStatusDialog_calls();

    IServiceInterface serviceInterface =
        wsdlRoot.getDescription().getAllInterfaces().iterator().next();
    ServiceInterfaceNode serviceInterfaceNode =
        new ServiceInterfaceNode(null, serviceInterface, sifpc);
    sifpc.getTreeNodeMapper().addToNodeMap(serviceInterface, serviceInterfaceNode);

    OperationNode operationNode = (OperationNode) serviceInterfaceNode.getChildren()[0];

    ParameterNode inputParameterNode = (ParameterNode) operationNode.getChildren()[0];

    FaultNode faultNode = (FaultNode) operationNode.getChildren()[2];

    sifpc.isEditAllowed = Boolean.valueOf(false);
    ArrayList<ITreeNode> nodes = new ArrayList<ITreeNode>();
    nodes.add(faultNode);
    nodes.add(inputParameterNode);
    nodes.add(operationNode);
    nodes.add(serviceInterfaceNode);
    sifpc.deleteItemsTriggered(nodes);

    assertEquals(serviceInterface, wsdlRoot.getDescription().getAllInterfaces().iterator().next());
    assertEquals(operationNode, serviceInterfaceNode.getChildren()[0]);
    assertEquals(inputParameterNode, operationNode.getChildren()[0]);
    assertEquals(faultNode, operationNode.getChildren()[2]);

    sifpc.isEditAllowed = Boolean.valueOf(true);

    sifpc.deleteItemsTriggered(nodes);

    assertEquals(0, wsdlRoot.getDescription().getAllInterfaces().size());
  }
  /**
   * Test method for {@link
   * org.eclipse.wst.sse.sieditor.ui.v2.wsdl.controller.SIFormPageController#editParameterTypeTriggered(ITreeNode,
   * IType)} .
   *
   * @throws CoreException
   * @throws IOException
   */
  @Test
  public final void testEditParameterTypeTriggered() throws IOException, CoreException {
    IWsdlModelRoot wsdlRoot =
        getWSDLModelRoot(
            org.eclipse.wst.sse.sieditor.test.model.Constants.DATA_PUBLIC_SELF_KESHAV
                + "Documentation.wsdl",
            "Documentation.wsdl"); //$NON-NLS-1$ //$NON-NLS-2$
    TestSIFormPageController sifpc = new TestSIFormPageController(wsdlRoot, false);
    sifpc.isEditAllowed = Boolean.valueOf(false);

    StatusUtils.isUnderJunitExecution = true;
    long statusCalls = StatusUtils.getShowStatusDialog_calls();

    IType newType =
        wsdlRoot
            .getDescription()
            .getContainedSchemas()
            .get(0)
            .getAllContainedTypes()
            .iterator()
            .next();

    IServiceInterface service = wsdlRoot.getDescription().getAllInterfaces().iterator().next();
    ServiceInterfaceNode serviceInterfaceNode = new ServiceInterfaceNode(null, service, sifpc);
    ParameterNode parameterNode =
        (ParameterNode) ((ITreeNode) serviceInterfaceNode.getChildren()[0]).getChildren()[0];
    IParameter parameterToChange = (IParameter) parameterNode.getModelObject();

    IType oldType = parameterToChange.getType();

    sifpc.editParameterTypeTriggered(parameterNode, newType);

    assertEquals(oldType, parameterToChange.getType());
    assertEquals(1, StatusUtils.getShowStatusDialog_calls() - statusCalls);

    sifpc.isEditAllowed = Boolean.valueOf(true);
    statusCalls = StatusUtils.getShowStatusDialog_calls();

    sifpc.editParameterTypeTriggered(parameterNode, newType);

    assertEquals(newType, parameterToChange.getType());
    assertEquals(0, StatusUtils.getShowStatusDialog_calls() - statusCalls);
  }
  /**
   * Test method for {@link
   * org.eclipse.wst.sse.sieditor.ui.v2.wsdl.controller.SIFormPageController#addNewParameter(org.eclipse.wst.sse.sieditor.ui.v2.nodes.ITreeNode,
   * org.eclipse.wst.sse.sieditor.ui.v2.wsdltree.nodes.OperationCategory)} .
   *
   * @throws CoreException
   * @throws IOException
   */
  @Test
  public final void testAddNewParameter() throws IOException, CoreException {
    // just any wsdl
    IWsdlModelRoot wsdlRoot =
        getWSDLModelRoot(
            org.eclipse.wst.sse.sieditor.test.model.Constants.DATA_PUBLIC_SELF_KESHAV
                + "Documentation.wsdl",
            "Documentation.wsdl"); //$NON-NLS-1$
    TestSIFormPageController sifpc = new TestSIFormPageController(wsdlRoot, false);
    sifpc.isEditAllowed = Boolean.valueOf(true);

    StatusUtils.isUnderJunitExecution = true;
    long statusCalls = StatusUtils.getShowStatusDialog_calls();

    IServiceInterface serviceInterface =
        wsdlRoot.getDescription().getAllInterfaces().iterator().next();
    ServiceInterfaceNode siNode = new ServiceInterfaceNode(null, serviceInterface, sifpc);
    sifpc.getTreeNodeMapper().addToNodeMap(serviceInterface, siNode);

    OperationNode operationNode = (OperationNode) siNode.getChildren()[0];

    int paramCount = operationNode.getModelObject().getAllInputParameters().size();

    sifpc.addNewParameter(operationNode, OperationCategory.INPUT);

    assertEquals(0, StatusUtils.getShowStatusDialog_calls() - statusCalls);
    assertEquals(paramCount + 1, operationNode.getModelObject().getAllInputParameters().size());

    // with a readOnly controller
    sifpc.isEditAllowed = Boolean.valueOf(false);

    statusCalls = StatusUtils.getShowStatusDialog_calls();
    paramCount = operationNode.getModelObject().getAllInputParameters().size();

    sifpc.addNewParameter(operationNode, OperationCategory.INPUT);

    assertEquals(1, StatusUtils.getShowStatusDialog_calls() - statusCalls);
    assertEquals(paramCount, operationNode.getModelObject().getAllInputParameters().size());
  }