private void removeUnusedEndpoints() {
    if (config == null) {
      return;
    }

    Set<String> endpoints = new HashSet<String>();

    for (Interface iface : project.getInterfaceList()) {
      endpoints.addAll(Arrays.asList(iface.getEndpoints()));
    }

    StringList keys = new StringList();

    synchronized (defaults) {
      for (String key : defaults.keySet()) {
        if (!endpoints.contains(key)) {
          keys.add(key);
        }
      }

      for (String key : keys) {
        EndpointDefaults def = defaults.remove(key);
        config.getEndpointList().remove(def);
      }
    }
  }
    @Override
    public void interfaceAdded(Interface iface) {
      for (String endpoint : iface.getEndpoints()) {
        // ensure we have defaults
        getEndpointDefaults(endpoint);
      }

      iface.addPropertyChangeListener(AbstractInterface.ENDPOINT_PROPERTY, propertyChangeListener);
    }
  public void release() {
    project.removeProjectListener(projectListener);
    for (Interface iface : project.getInterfaceList()) {
      iface.removePropertyChangeListener(
          AbstractInterface.ENDPOINT_PROPERTY, propertyChangeListener);
    }

    if (configurationPanel != null) {
      configurationPanel.release();
    }
  }
  public void importEndpoints(Interface iface) {
    EndpointStrategy ep = iface.getProject().getEndpointStrategy();
    if (ep instanceof DefaultEndpointStrategy) {
      DefaultEndpointStrategy dep = (DefaultEndpointStrategy) ep;
      String[] endpoints = iface.getEndpoints();

      for (String endpoint : endpoints) {
        getEndpointDefaults(endpoint)
            .getConfig()
            .set(dep.getEndpointDefaults(endpoint).getConfig());
      }
    }
  }
  public void init(Project project) {
    this.project = (WsdlProject) project;
    initConfig();

    project.addProjectListener(projectListener);

    for (Interface iface : project.getInterfaceList()) {
      for (String endpoint : iface.getEndpoints()) {
        // ensure we have defaults
        getEndpointDefaults(endpoint);
      }

      iface.addPropertyChangeListener(AbstractInterface.ENDPOINT_PROPERTY, propertyChangeListener);
    }

    removeUnusedEndpoints();
  }
Esempio n. 6
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));
      }
    }
  }
 @Override
 public void interfaceRemoved(Interface iface) {
   iface.removePropertyChangeListener(
       AbstractInterface.ENDPOINT_PROPERTY, propertyChangeListener);
   removeUnusedEndpoints();
 }
Esempio n. 8
0
 @Override
 public boolean applies(Interface target) {
   Interface iface = (Interface) target;
   return !iface.getProject().hasNature(Project.JBOSSWS_NATURE_ID);
 }