示例#1
0
  public void actionPerformed(ActionEvent e) {
    String[] oldData = getData();

    if (e.getSource() == addButton) {
      String value = UISupport.prompt("Specify value to add", "Add..", defaultValue);
      if (value != null) {
        listModel.addElement(value);
        firePropertyChange("options", oldData, getData());
      }
    } else {
      int selectedIndex = list.getSelectedIndex();

      if (e.getSource() == removeButton && selectedIndex != -1) {
        Object elm = listModel.getElementAt(selectedIndex);
        if (UISupport.confirm("Remove [" + elm.toString() + "] from list", "Remove")) {
          listModel.remove(selectedIndex);
          firePropertyChange("options", oldData, getData());
        }
      } else if (e.getSource() == editButton && selectedIndex != -1) {
        String elm = (String) listModel.getElementAt(selectedIndex);
        String value = UISupport.prompt("Specify value", "Edit..", elm);

        if (value != null) {
          listModel.setElementAt(value, selectedIndex);
          firePropertyChange("options", oldData, getData());
        }
      }
    }
  }
示例#2
0
  public void perform(WsdlTestCase testCase, Object param) {
    String name =
        UISupport.prompt("Specify name of TestCase", "Rename TestCase", testCase.getName());
    if (name == null || name.equals(testCase.getName())) return;
    while (testCase.getTestSuite().getTestCaseByName(name.trim()) != null) {
      name =
          UISupport.prompt(
              "Specify unique name of TestCase", "Rename TestCase", testCase.getName());
      if (name == null || name.equals(testCase.getName())) return;
    }

    testCase.setName(name);
  }
示例#3
0
 public void perform(WsdlProject project, Object param) {
   if (project.isRemote()) {
     String path = UISupport.prompt("Reload remote project URL", getName(), project.getPath());
     if (path != null) {
       try {
         project.reload(path);
       } catch (SoapUIException ex) {
         UISupport.showErrorMessage(ex);
       }
     }
   } else {
     File file =
         UISupport.getFileDialogs()
             .open(
                 this,
                 "Reload Project",
                 ".xml",
                 "SoapUI Project Files (*.xml)",
                 project.getPath());
     if (file != null) {
       try {
         project.reload(file.getAbsolutePath());
       } catch (SoapUIException ex) {
         UISupport.showErrorMessage(ex);
       }
     }
   }
 }
 public void actionPerformed(ActionEvent e) {
   String[] types = LoadTestAssertionRegistry.getAvailableAssertions();
   String type =
       (String) UISupport.prompt("Select assertion type to add", "Add Assertion", types);
   if (type != null) {
     loadTest.addAssertion(type, LoadTestAssertion.ANY_TEST_STEP, true);
   }
 }
示例#5
0
    public void actionPerformed(ActionEvent e) {
      String name = UISupport.prompt("Specify unique property name", "Add Property", "");
      if (StringUtils.hasContent(name)) {
        if (holder.hasProperty(name)) {
          UISupport.showErrorMessage("Property name [" + name + "] already exists..");
          return;
        }

        ((MutableTestPropertyHolder) holder).addProperty(name);
      }
    }
示例#6
0
  @SuppressWarnings("unchecked")
  private BindingTuple findBinding(WsdlContext newContext) throws Exception {
    BindingTuple tuple = new BindingTuple();
    tuple.context = newContext;

    // start by finding the old binding in the new definition
    Definition definition = newContext.getDefinition();
    Map serviceMap = definition.getAllServices();
    Iterator<String> i = serviceMap.keySet().iterator();
    while (i.hasNext()) {
      tuple.service = (Service) serviceMap.get(i.next());
      Map portMap = tuple.service.getPorts();

      Iterator i2 = portMap.keySet().iterator();
      while (i2.hasNext()) {
        tuple.port = (Port) portMap.get(i2.next());
        if (tuple.port.getBinding().getQName().equals(getBindingName())) {
          tuple.binding = tuple.port.getBinding();
        }
      }

      if (tuple.binding != null) break;
      tuple.service = null;
    }

    if (tuple.service == null && tuple.binding == null) {
      tuple.binding = definition.getBinding(getBindingName());
    }

    // missing matching binding, prompt for new one to use instead (will
    // happen if binding has been renamed)
    if (tuple.binding == null) {
      Map bindings = definition.getAllBindings();

      Object retval =
          UISupport.prompt(
              "Missing matching binding ["
                  + getBindingName()
                  + "] in definition, select new\nbinding to map to",
              "Map Binding",
              bindings.keySet().toArray());

      if (retval == null) return null;

      tuple.binding = (Binding) bindings.get(retval);
    }

    return tuple;
  }
    @Override
    public void actionPerformed(ActionEvent arg0) {
      String newToken = "";
      while (newToken.trim().length() == 0) {
        newToken = UISupport.prompt("Enter token", "New Token", newToken);

        if (newToken == null) {
          return;
        }

        if (newToken.trim().length() == 0) {
          UISupport.showErrorMessage("Enter token name!");
        }
      }

      String newValue = "";
      newValue = UISupport.prompt("Enter description", "New Description", newValue);

      if (newValue == null) {
        newValue = "";
      }

      sensitiveInformationTableModel.addToken(newToken, newValue);
    }
  public void perform(WsdlProject project, Object param) {
    String url = UISupport.prompt("Enter WSDL URL", "Add WSDL from URL", "");
    if (url == null) return;

    try {
      Boolean createRequests =
          UISupport.confirmOrCancel("Create default requests for all operations", "Import WSDL");
      if (createRequests == null) return;

      Interface[] ifaces = WsdlInterfaceFactory.importWsdl(project, url, createRequests);
      if (ifaces != null && ifaces.length > 0) UISupport.select(ifaces[0]);
    } catch (Exception ex) {
      UISupport.showErrorMessage(ex.getMessage() + ":" + ex.getCause());
    }
  }
示例#9
0
  public WsdlMessageAssertion addWsdlAssertion(String assertionLabel) {
    try {
      TestAssertionConfig assertionConfig = assertableConfig.addNewAssertion();
      assertionConfig.setType(
          TestAssertionRegistry.getInstance().getAssertionTypeForName(assertionLabel));

      String name = assertionLabel;
      while (getAssertionByName(name.trim()) != null) {
        name =
            UISupport.prompt(
                "Specify unique name of Assertion",
                "Rename Assertion",
                assertionLabel
                    + " "
                    + (getAssertionsOfType(
                            TestAssertionRegistry.getInstance()
                                .getAssertionClassType(assertionConfig))
                        .size()));
        if (name == null) {
          return null;
        }
      }
      WsdlMessageAssertion assertion = addWsdlAssertion(assertionConfig);
      if (assertion == null) return null;

      assertionConfig.setName(name);
      assertion.updateConfig(assertionConfig);

      if (assertion != null) {
        fireAssertionAdded(assertion);
      }

      return assertion;
    } catch (Exception e) {
      SoapUI.logError(e);
      return null;
    }
  }
示例#10
0
  public void perform(WsdlTestCase testCase, Object param) {
    if (dialog == null) {
      dialog = ADialogBuilder.buildDialog(Form.class);
      dialog
          .getFormField(Form.PROJECT)
          .addFormFieldListener(
              new XFormFieldListener() {

                public void valueChanged(XFormField sourceField, String newValue, String oldValue) {
                  if (newValue.equals(CREATE_NEW_OPTION))
                    dialog.setOptions(Form.TESTSUITE, new String[] {CREATE_NEW_OPTION});
                  else {
                    Project project = SoapUI.getWorkspace().getProjectByName(newValue);
                    dialog.setOptions(
                        Form.TESTSUITE,
                        ModelSupport.getNames(
                            project.getTestSuiteList(), new String[] {CREATE_NEW_OPTION}));
                  }
                }
              });
      dialog
          .getFormField(Form.CLONE_DESCRIPTION)
          .addFormFieldListener(
              new XFormFieldListener() {

                public void valueChanged(XFormField sourceField, String newValue, String oldValue) {
                  if (dialog.getBooleanValue(Form.CLONE_DESCRIPTION)) {
                    dialog.getFormField(Form.DESCRIPTION).setEnabled(false);
                  } else {
                    dialog.getFormField(Form.DESCRIPTION).setEnabled(true);
                  }
                }
              });
    }

    dialog.setBooleanValue(Form.MOVE, false);
    dialog.setBooleanValue(Form.CLONE_DESCRIPTION, true);
    dialog.getFormField(Form.DESCRIPTION).setEnabled(false);
    dialog.setValue(Form.DESCRIPTION, testCase.getDescription());
    dialog.setValue(Form.NAME, "Copy of " + testCase.getName());
    WorkspaceImpl workspace = testCase.getTestSuite().getProject().getWorkspace();
    dialog.setOptions(
        Form.PROJECT,
        ModelSupport.getNames(workspace.getOpenProjectList(), new String[] {CREATE_NEW_OPTION}));

    dialog.setValue(Form.PROJECT, testCase.getTestSuite().getProject().getName());

    dialog.setOptions(
        Form.TESTSUITE,
        ModelSupport.getNames(
            testCase.getTestSuite().getProject().getTestSuiteList(),
            new String[] {CREATE_NEW_OPTION}));

    dialog.setValue(Form.TESTSUITE, testCase.getTestSuite().getName());
    boolean hasLoadTests = testCase.getLoadTestCount() > 0;
    dialog.setBooleanValue(Form.CLONE_LOADTESTS, hasLoadTests);
    dialog.getFormField(Form.CLONE_LOADTESTS).setEnabled(hasLoadTests);

    if (dialog.show()) {
      String targetProjectName = dialog.getValue(Form.PROJECT);
      String targetTestSuiteName = dialog.getValue(Form.TESTSUITE);
      String name = dialog.getValue(Form.NAME);

      WsdlProject project = testCase.getTestSuite().getProject();
      WsdlTestSuite targetTestSuite = null;
      Set<Interface> requiredInterfaces = new HashSet<Interface>();

      // to another project project?
      if (!targetProjectName.equals(project.getName())) {
        // get required interfaces
        for (int y = 0; y < testCase.getTestStepCount(); y++) {
          WsdlTestStep testStep = testCase.getTestStepAt(y);
          requiredInterfaces.addAll(testStep.getRequiredInterfaces());
        }

        project = (WsdlProject) workspace.getProjectByName(targetProjectName);
        if (project == null) {
          targetProjectName = UISupport.prompt("Enter name for new Project", "Clone TestCase", "");
          if (targetProjectName == null) return;

          try {
            project = workspace.createProject(targetProjectName, null);
          } catch (SoapUIException e) {
            UISupport.showErrorMessage(e);
          }

          if (project == null) return;
        }

        if (requiredInterfaces.size() > 0 && project.getInterfaceCount() > 0) {
          Map<String, Interface> bindings = new HashMap<String, Interface>();
          for (Interface iface : requiredInterfaces) {
            bindings.put(iface.getTechnicalId(), iface);
          }

          for (Interface iface : project.getInterfaceList()) {
            bindings.remove(iface.getTechnicalId());
          }

          requiredInterfaces.retainAll(bindings.values());
        }

        if (requiredInterfaces.size() > 0) {
          String msg =
              "Target project [" + targetProjectName + "] is missing required Interfaces;\r\n\r\n";
          for (Interface iface : requiredInterfaces) {
            msg += iface.getName() + " [" + iface.getTechnicalId() + "]\r\n";
          }
          msg += "\r\nThese will be cloned to the targetProject as well";

          if (!UISupport.confirm(msg, "Clone TestCase")) return;

          for (Interface iface : requiredInterfaces) {
            project.importInterface((AbstractInterface<?>) iface, true, true);
          }
        }
      }

      targetTestSuite = project.getTestSuiteByName(targetTestSuiteName);
      if (targetTestSuite == null) {
        targetTestSuiteName =
            UISupport.prompt(
                "Specify name for new TestSuite",
                "Clone TestCase",
                "Copy of " + testCase.getTestSuite().getName());
        if (targetTestSuiteName == null) return;

        targetTestSuite = project.addNewTestSuite(targetTestSuiteName);
      }

      boolean move = dialog.getBooleanValue(Form.MOVE);
      WsdlTestCase newTestCase =
          targetTestSuite.importTestCase(
              testCase, name, -1, dialog.getBooleanValue(Form.CLONE_LOADTESTS), !move);
      UISupport.select(newTestCase);

      if (move) {
        testCase.getTestSuite().removeTestCase(testCase);
      }
      boolean cloneDescription = dialog.getBooleanValue(Form.CLONE_DESCRIPTION);
      if (!cloneDescription) {
        newTestCase.setDescription(dialog.getValue(Form.DESCRIPTION));
      }
    }
  }
示例#11
0
    public void drop(DropTargetDropEvent dtde) {
      if (!isAcceptable(dtde.getTransferable(), dtde.getLocation())) {
        dtde.rejectDrop();
      } else {
        try {
          Transferable transferable = dtde.getTransferable();
          Object transferData =
              transferable.getTransferData(transferable.getTransferDataFlavors()[0]);
          if (transferData instanceof PropertyModelItem) {
            dtde.acceptDrop(dtde.getDropAction());
            PropertyModelItem modelItem = (PropertyModelItem) transferData;

            String xpath = modelItem.getXPath();
            if (xpath == null && XmlUtils.seemsToBeXml(modelItem.getProperty().getValue())) {
              xpath =
                  UISupport.selectXPath(
                      "Create PropertyExpansion",
                      "Select XPath below",
                      modelItem.getProperty().getValue(),
                      null);

              if (xpath != null) {
                xpath =
                    PropertyExpansionUtils.shortenXPathForPropertyExpansion(
                        xpath, modelItem.getProperty().getValue());
              }
            }

            PropertyExpansion propertyExpansion =
                new PropertyExpansionImpl(modelItem.getProperty(), xpath);

            Point point = dtde.getLocation();
            int column = getPropertiesTable().columnAtPoint(point);
            int row = getPropertiesTable().rowAtPoint(point);

            if (row == -1) {
              if (holder instanceof MutableTestPropertyHolder) {
                MutableTestPropertyHolder mtph = (MutableTestPropertyHolder) holder;
                String name =
                    UISupport.prompt(
                        "Specify unique name of property",
                        "Add Property",
                        modelItem.getProperty().getName());
                while (name != null && mtph.hasProperty(name)) {
                  name =
                      UISupport.prompt(
                          "Specify unique name of property",
                          "Add Property",
                          modelItem.getProperty().getName());
                }

                if (name != null) {
                  mtph.addProperty(name).setValue(propertyExpansion.toString());
                }
              }
            } else {
              getPropertiesTable().setValueAt(propertyExpansion.toString(), row, column);
            }

            dtde.dropComplete(true);
          }
        } catch (Exception e) {
          SoapUI.logError(e);
        }
      }
    }
示例#12
0
  @SuppressWarnings("unchecked")
  public void transferOperations(Binding binding, boolean createRequests) {
    // prepare for transfer of operations/requests
    List<BindingOperation> newOperations =
        new ArrayList<BindingOperation>(binding.getBindingOperations());
    Map<String, WsdlOperation> oldOperations = new HashMap<String, WsdlOperation>();
    for (int c = 0; c < operations.size(); c++)
      oldOperations.put(operations.get(c).getBindingOperationName(), operations.get(c));

    // clear existing from both collections
    for (int c = 0; c < newOperations.size(); c++) {
      BindingOperation newOperation = newOperations.get(c);
      String bindingOperationName = newOperation.getName();
      if (oldOperations.containsKey(bindingOperationName)) {
        log.info("Synchronizing existing operation [" + bindingOperationName + "]");
        WsdlOperation wsdlOperation = oldOperations.get(bindingOperationName);
        WsdlUtils.getAnonymous(wsdlOperation);
        wsdlOperation.initFromBindingOperation(newOperation);
        fireOperationUpdated(wsdlOperation);

        oldOperations.remove(bindingOperationName);
        newOperations.remove(c);
        c--;
      }
    }

    // remove leftover operations
    Iterator<String> i = oldOperations.keySet().iterator();
    while (i.hasNext()) {
      String name = i.next();

      if (newOperations.size() > 0) {
        List<String> list = new ArrayList<String>();
        list.add("none - delete operation");
        for (int c = 0; c < newOperations.size(); c++) list.add(newOperations.get(c).getName());

        String retval =
            (String)
                UISupport.prompt(
                    "Binding operation ["
                        + name
                        + "] not found in new interface, select new\nbinding operation to map to",
                    "Map Operation",
                    list.toArray(),
                    "none/cancel - delete operation");

        int ix = retval == null ? -1 : list.indexOf(retval) - 1;

        // delete operation?
        if (ix < 0) {
          deleteOperation(name);
        }
        // change operation?
        else {
          BindingOperation newOperation = newOperations.get(ix);
          WsdlOperation wsdlOperation = oldOperations.get(name);
          wsdlOperation.initFromBindingOperation(newOperation);
          fireOperationUpdated(wsdlOperation);
          newOperations.remove(ix);
        }

        oldOperations.remove(name);
      } else {
        deleteOperation(name);
        oldOperations.remove(name);
      }

      i = oldOperations.keySet().iterator();
    }

    // add leftover new operations
    if (newOperations.size() > 0) {
      for (int c = 0; c < newOperations.size(); c++) {
        BindingOperation newOperation = newOperations.get(c);
        WsdlOperation wsdlOperation = addNewOperation(newOperation);

        if (createRequests) {
          WsdlRequest request = wsdlOperation.addNewRequest("Request 1");
          try {
            request.setRequestContent(wsdlOperation.createRequest(true));
          } catch (Exception e) {
            SoapUI.logError(e);
          }
        }
      }
    }
  }