Beispiel #1
0
  /** To be overridden.. */
  public void onClose(T modelItem) {
    if (dialog == null) return;

    if (modelItem == null) {
      SoapUI.getSettings().setString(valuesSettingID, dialog.getValues().toXml());
    } else {
      modelItem.getSettings().setString(valuesSettingID, dialog.getValues().toXml());
    }
  }
 protected void buildDialog() {
   dialog = ADialogBuilder.buildDialog(SensitiveInformationConfigDialog.class);
   dialog.setBooleanValue(SensitiveInformationConfigDialog.INCLUDE_GLOBAL, includeGlobal);
   dialog.setBooleanValue(
       SensitiveInformationConfigDialog.INCLUDE_PROJECT_SPECIFIC, includeProjectSpecific);
   dialog
       .getFormField(SensitiveInformationConfigDialog.TOKENS)
       .setProperty("component", getForm());
 }
  protected void createTransfer(XmlTreeNode tn) {
    if (dialog == null) buildDialog();

    this.treeNode = tn;

    StringToStringMap values = dialog.show(initValues());
    if (dialog.getReturnValue() == XFormDialog.OK_OPTION) {
      createTransfer(values);
    }
  }
  @Override
  public void perform(WsdlTestSuite testSuite, Object param) {

    if (IntegrationUtils.forceSaveProject(testSuite.getProject())) {

      if (!StartLoadUI.testCajoConnection()) {
        if (UISupport.confirm(
            StartLoadUI.LOADUI_LAUNCH_QUESTION, StartLoadUI.LOADUI_LAUNCH_TITLE)) {
          StartLoadUI.launchLoadUI();
        }
        return;
      }

      XFormDialog dialog = ADialogBuilder.buildDialog(TestSuiteForm.class);

      dialog.setOptions(TestSuiteForm.LOADUIPROJECT, IntegrationUtils.getAvailableProjects());
      if (!StringUtils.isNullOrEmpty(IntegrationUtils.getOpenedProjectName())) {
        dialog.setValue(TestSuiteForm.LOADUIPROJECT, IntegrationUtils.getOpenedProjectName());
      } else {
        dialog.setValue(TestSuiteForm.LOADUIPROJECT, IntegrationUtils.CREATE_NEW_OPTION);
      }
      List<String> testSuiteLoadTests = new ArrayList<String>();
      for (TestCase testCase : testSuite.getTestCaseList()) {
        for (LoadTest loadTest : testCase.getLoadTestList()) {
          testSuiteLoadTests.add(testCase.getName() + " - " + loadTest.getName());
        }
      }
      String[] names = new String[testSuiteLoadTests.size()];
      for (int c = 0; c < names.length; c++) {
        names[c] = testSuiteLoadTests.get(c);
      }
      dialog.setOptions(TestSuiteForm.LOADTESTS, names);
      if (dialog.show()) {
        if (dialog.getReturnValue() == XFormDialog.OK_OPTION) {
          String loadUIProject = dialog.getValue(TestSuiteForm.LOADUIPROJECT);
          String openedProjectName = IntegrationUtils.getOpenedProjectName();
          if (!StringUtils.isNullOrEmpty(openedProjectName)
              && !loadUIProject.equals(openedProjectName)
              && IntegrationUtils.checkOpenedLoadUIProjectForClose()) {
            return;
          }
          String[] soapuiLoadTests =
              StringUtils.toStringArray(
                  ((XFormMultiSelectList) dialog.getFormField(TestSuiteForm.LOADTESTS))
                      .getSelectedOptions());
          if (soapuiLoadTests.length == 0) {
            UISupport.showErrorMessage("No LoadTests selected.");
            return;
          }
          try {
            IntegrationUtils.exportMultipleLoadTestToLoadUI(
                testSuite, soapuiLoadTests, loadUIProject);
          } catch (IOException e) {
            UISupport.showInfoMessage("Error while opening selected loadUI project");
            return;
          }
        }
      }
    }
  }
  private StringToStringMap initValues() {
    StringToStringMap values = new StringToStringMap();

    dialog.setOptions(SOURCE_STEP, getSourceSteps());
    dialog.setOptions(SOURCE_PROPERTY, getSourceProperties());

    values.put(TRANSFER_STEP, findPropertyTransfer());
    values.put(TRANSFER_NAME, treeNode.getDomNode().getLocalName());

    String xpath = XmlUtils.createXPath(treeNode.getDomNode());
    values.put(TARGET_XPATH, xpath);
    values.put(CURRENT_VALUE, getCurrentValue(xpath));

    return values;
  }
  public boolean configure() {
    if (dialog == null) buildDialog();

    StringToStringMap values = new StringToStringMap();
    values.put(CONTENT, token);
    values.put(IGNORE_CASE, ignoreCase);
    values.put(USE_REGEX, useRegEx);

    values = dialog.show(values);
    if (dialog.getReturnValue() == XFormDialog.OK_OPTION) {
      token = values.get(CONTENT);
      ignoreCase = values.getBoolean(IGNORE_CASE);
      useRegEx = values.getBoolean(USE_REGEX);
    }

    setConfiguration(createConfiguration());
    return true;
  }
  @Override
  public boolean configure() {
    if (dialog == null) buildDialog();
    if (dialog.show()) {
      assertionSpecificExposureList = createListFromTable();
      includeProjectSpecific =
          Boolean.valueOf(
              dialog
                  .getFormField(SensitiveInformationConfigDialog.INCLUDE_PROJECT_SPECIFIC)
                  .getValue());
      includeGlobal =
          Boolean.valueOf(
              dialog.getFormField(SensitiveInformationConfigDialog.INCLUDE_GLOBAL).getValue());
      setConfiguration(createConfiguration());

      return true;
    }
    return false;
  }
  public void perform(SecurityTest securityTest, Object param) {
    if (dialog == null) {
      XFormDialogBuilder builder = XFormFactory.createDialogBuilder("SecurityTest Options");
      form = builder.createForm("Basic");
      form.addCheckBox(FAIL_ON_ERROR, "Fail on error")
          .addFormFieldListener(
              new XFormFieldListener() {

                public void valueChanged(XFormField sourceField, String newValue, String oldValue) {
                  form.getFormField(FAIL_SECURITYTEST_ON_ERROR)
                      .setEnabled(!Boolean.parseBoolean(newValue));
                }
              });
      form.addCheckBox(FAIL_SECURITYTEST_ON_ERROR, "Fail SecurityTest if it has failed TestSteps");

      dialog =
          builder.buildDialog(
              builder.buildOkCancelHelpActions(HelpUrls.SECURITYTESTEDITOR_HELP_URL),
              "Specify general options for this SecurityTest",
              UISupport.OPTIONS_ICON);
    }

    StringToStringMap values = new StringToStringMap();

    values.put(FAIL_ON_ERROR, String.valueOf(securityTest.getFailOnError()));
    values.put(
        FAIL_SECURITYTEST_ON_ERROR, String.valueOf(securityTest.getFailSecurityTestOnScanErrors()));
    values = dialog.show(values);

    if (dialog.getReturnValue() == XFormDialog.OK_OPTION) {
      try {
        securityTest.setFailOnError(Boolean.parseBoolean(values.get(FAIL_ON_ERROR)));
        securityTest.setFailSecurityTestOnScanErrors(
            Boolean.parseBoolean(values.get(FAIL_SECURITYTEST_ON_ERROR)));

      } catch (Exception e1) {
        UISupport.showErrorMessage(e1.getMessage());
      }
    }
  }
Beispiel #9
0
  public boolean configure() {
    if (dialog == null) buildDialog();

    StringToStringMap values = new StringToStringMap();
    values.put(ASSERT_ACTION, assertWsaAction);
    values.put(ASSERT_TO, assertWsaTo);
    values.put(ASSERT_REPLY_TO, assertWsaReplyTo);
    values.put(ASSERT_MESSAGE_ID, assertWsaMessageId);
    // values.put(ASSERT_RELATES_TO, assertWsaRelatesTo);
    // values.put(ASSERT_REPLY_TO_REF_PARAMS, assertReplyToRefParams);
    // values.put(ASSERT_FAULT_TO_REF_PARAMS, assertFaultToRefParams);

    values = dialog.show(values);
    if (dialog.getReturnValue() == XFormDialog.OK_OPTION) {
      assertWsaAction = values.getBoolean(ASSERT_ACTION);
      assertWsaTo = values.getBoolean(ASSERT_TO);
      assertWsaReplyTo = values.getBoolean(ASSERT_REPLY_TO);
      assertWsaMessageId = values.getBoolean(ASSERT_MESSAGE_ID);
      // assertWsaRelatesTo = values.getBoolean(ASSERT_RELATES_TO);
      // assertReplyToRefParams = values
      // .getBoolean(ASSERT_REPLY_TO_REF_PARAMS);
      // assertFaultToRefParams = values
      // .getBoolean(ASSERT_FAULT_TO_REF_PARAMS);
    }

    wsaAssertionConfiguration =
        new WsaAssertionConfiguration(
            assertWsaAction,
            assertWsaTo,
            assertWsaReplyTo,
            assertWsaMessageId,
            false,
            false,
            false);
    setConfiguration(createConfiguration());
    return true;
  }
Beispiel #10
0
  public void perform(T target, Object param) {
    this.valuesSettingID = this.getClass().getName() + "@values";
    if (target == null) this.valuesSettingID += "-global";
    else this.valuesSettingID += "-local";

    modelItem = target;

    // Could reuse the dialog in Swing, but not in Eclipse.
    // if( dialog == null )
    dialog = buildDialog((T) target);

    if (dialog == null) {
      try {
        generate(initValues((T) target, param), UISupport.getToolHost(), (T) target);
      } catch (Exception e1) {
        UISupport.showErrorMessage(e1);
      }
    } else {
      StringToStringMap values = initValues((T) target, param);

      dialog.setValues(values);
      dialog.setVisible(true);
    }
  }
  public boolean configure() {
    if (dialog == null) {
      buildDialog();
    }

    StringToStringMap values = new StringToStringMap();

    values.put(NAME_FIELD, getName());
    values.put(MINIMUM_REQUESTS_FIELD, String.valueOf(minRequests));
    values.put(MAX_AVERAGE_FIELD, String.valueOf(maxAverage));
    values.put(TEST_STEP_FIELD, getTargetStep());
    values.put(MAX_ERRORS_FIELD, String.valueOf(maxErrors));
    values.put(SAMPLE_INTERVAL_FIELD, String.valueOf(sampleInterval));

    dialog.setOptions(TEST_STEP_FIELD, getTargetStepOptions(true));
    values = dialog.show(values);

    if (dialog.getReturnValue() == XFormDialog.OK_OPTION) {
      try {
        minRequests = Integer.parseInt(values.get(MINIMUM_REQUESTS_FIELD));
        maxAverage = Integer.parseInt(values.get(MAX_AVERAGE_FIELD));
        maxErrors = Integer.parseInt(values.get(MAX_ERRORS_FIELD));
        sampleInterval = Integer.parseInt(values.get(SAMPLE_INTERVAL_FIELD));
        setName(values.get(NAME_FIELD));
        setTargetStep(values.get(TEST_STEP_FIELD));
      } catch (Exception e) {
        UISupport.showErrorMessage(e.getMessage());
      }

      updateConfiguration();

      return true;
    }

    return false;
  }
  public void perform(RestService target, Object param) {
    try {
      if (dialog == null) {
        dialog = ADialogBuilder.buildDialog(Form.class);
      }

      Settings settings = target.getSettings();
      dialog.setValue(Form.OUTPUT_FOLDER, settings.getString(REPORT_DIRECTORY_SETTING, ""));

      if (!dialog.show()) {
        return;
      }

      settings.setString(REPORT_DIRECTORY_SETTING, dialog.getValue(Form.OUTPUT_FOLDER));

      final File reportDirectory = new File(settings.getString(REPORT_DIRECTORY_SETTING, ""));
      String reportDirAbsolutePath = reportDirectory.getAbsolutePath();
      String filename = reportDirAbsolutePath + File.separatorChar + "report.xml";
      String reportUrl = transform(target, reportDirAbsolutePath, filename);
      Tools.openURL(reportUrl);
    } catch (Exception e) {
      UISupport.showErrorMessage(e);
    }
  }
  private Object[] getSourceProperties() {
    if (dialog == null) return new Object[] {null};

    String sourceStep = dialog.getValues().get(SOURCE_STEP);
    TestStep testStep = request.getTestCase().getTestStepByName(sourceStep);
    if (testStep == null) return new Object[] {null};

    StringList result = new StringList();
    result.addAll(testStep.getPropertyNames());

    if (testStep instanceof WsdlPropertiesTestStep) {
      result.add(0, null);
    }

    return result.toArray();
  }
  private Object[] getPropertyTransfers() {
    if (dialog == null) return new Object[] {null};

    String targetStep = dialog.getValues().get(TRANSFER_STEP);
    TransferResponseValuesTestStep testStep =
        (TransferResponseValuesTestStep) request.getTestCase().getTestStepByName(targetStep);

    if (testStep == null) return new Object[] {null};

    StringList result = new StringList();
    result.add(null);

    for (int c = 0; c < testStep.getTransferCount(); c++) {
      result.add(testStep.getTransferAt(c).getName());
    }

    return result.toArray();
  }
  public boolean onClose(boolean canCancel) {
    getModelItem().removePropertyChangeListener(WsdlRunTestCaseTestStep.TARGET_TESTCASE, this);

    WsdlTestCase targetTestCase = getModelItem().getTargetTestCase();
    if (targetTestCase != null) {
      targetTestCase.removePropertyChangeListener(WsdlTestCase.NAME_PROPERTY, this);
      targetTestCase.getTestSuite().removePropertyChangeListener(WsdlTestCase.NAME_PROPERTY, this);
    }

    testRunLog.release();
    if (optionsDialog != null) {
      optionsDialog.release();
      optionsDialog = null;
    }

    propertiesTable.release();
    inspectorPanel.release();

    return release();
  }
Beispiel #16
0
  protected StringToStringMap initValues(T modelItem, Object param) {
    String settingValues =
        modelItem == null
            ? SoapUI.getSettings().getString(valuesSettingID, null)
            : modelItem.getSettings().getString(valuesSettingID, null);

    StringToStringMap result =
        settingValues == null ? new StringToStringMap() : StringToStringMap.fromXml(settingValues);

    if (modelItem instanceof WsdlInterface) {
      initWSDL(result, (WsdlInterface) modelItem);
    }

    if (dialog != null && modelItem != null) {
      String projectRoot = modelItem.getSettings().getString(ProjectSettings.PROJECT_ROOT, null);
      if (projectRoot != null)
        dialog.setFormFieldProperty(ProjectSettings.PROJECT_ROOT, projectRoot);
    }

    return result;
  }
  @Override
  public void perform(RestMockService mockService, Object param) {
    XFormDialog dialog = ADialogBuilder.buildDialog(Form.class);
    dialog.setOptions(Form.HTTP_METHOD, RestRequestInterface.HttpMethod.getMethodsAsStringArray());
    dialog.setValue(Form.HTTP_METHOD, RestRequestInterface.HttpMethod.GET.name());

    JTextFieldFormField formField = (JTextFieldFormField) dialog.getFormField(Form.RESOURCE_PATH);
    formField.getComponent().requestFocus();

    while (dialog.show()) {
      String resourcePath = dialog.getValue(Form.RESOURCE_PATH);
      String httpMethod = dialog.getValue(Form.HTTP_METHOD);

      if (StringUtils.hasContent(resourcePath)) {
        mockService.addEmptyMockAction(
            RestRequestInterface.HttpMethod.valueOf(httpMethod), resourcePath);
        break;
      }
      UISupport.showInfoMessage("The resource path can not be empty");
    }
  }
  @Override
  public void release() {
    if (dialog != null) dialog.release();

    super.release();
  }
  public void perform(WsdlTestRequestStep target, Object param) {
    this.testStep = target;

    if (dialog == null) {
      dialog = ADialogBuilder.buildDialog(Form.class);
      dialog
          .getFormField(Form.INTERFACE)
          .addFormFieldListener(
              new XFormFieldListener() {

                public void valueChanged(XFormField sourceField, String newValue, String oldValue) {
                  WsdlProject project = testStep.getTestCase().getTestSuite().getProject();
                  dialog.setOptions(
                      Form.OPERATION,
                      ModelSupport.getNames(
                          project.getInterfaceByName(newValue).getOperationList()));
                  dialog.setValue(Form.OPERATION, testStep.getOperationName());
                }
              });

      dialog
          .getFormField(Form.RECREATE_REQUEST)
          .addFormFieldListener(
              new XFormFieldListener() {

                public void valueChanged(XFormField sourceField, String newValue, String oldValue) {
                  boolean enabled = Boolean.parseBoolean(newValue);

                  dialog.getFormField(Form.CREATE_OPTIONAL).setEnabled(enabled);
                  dialog.getFormField(Form.KEEP_EXISTING).setEnabled(enabled);
                }
              });

      dialog.getFormField(Form.CREATE_OPTIONAL).setEnabled(false);
      dialog.getFormField(Form.KEEP_EXISTING).setEnabled(false);
    }

    WsdlProject project = target.getTestCase().getTestSuite().getProject();
    dialog.setOptions(
        Form.INTERFACE,
        ModelSupport.getNames(
            project.getInterfaceList(),
            new ModelSupport.InterfaceTypeFilter(WsdlInterfaceFactory.WSDL_TYPE)));
    dialog.setValue(Form.INTERFACE, target.getInterfaceName());

    dialog.setOptions(
        Form.OPERATION,
        ModelSupport.getNames(
            project.getInterfaceByName(target.getInterfaceName()).getOperationList()));
    dialog.setValue(Form.OPERATION, target.getOperationName());
    dialog.setValue(Form.NAME, target.getName());

    if (dialog.show()) {
      String ifaceName = dialog.getValue(Form.INTERFACE);
      String operationName = dialog.getValue(Form.OPERATION);

      WsdlInterface iface = (WsdlInterface) project.getInterfaceByName(ifaceName);
      WsdlOperation operation = iface.getOperationByName(operationName);
      target.setOperation(operation);

      String name = dialog.getValue(Form.NAME).trim();
      if (name.length() > 0 && !target.getName().equals(name)) target.setName(name);

      if (dialog.getBooleanValue(Form.RECREATE_REQUEST)) {
        String req = operation.createRequest(dialog.getBooleanValue(Form.CREATE_OPTIONAL));
        if (req == null) {
          UISupport.showErrorMessage("Request creation failed");
          return;
        }

        WsdlTestRequest request = target.getTestRequest();
        if (dialog.getBooleanValue(Form.KEEP_EXISTING)) {
          req = XmlUtils.transferValues(request.getRequestContent(), req);
        }

        request.setRequestContent(req);
      }
    }
  }
Beispiel #20
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));
      }
    }
  }
Beispiel #21
0
    public Credentials getCredentials(final AuthScope authScope) {
      if (authScope == null) {
        throw new IllegalArgumentException("Authentication scope may not be null");
      }

      //	if( cache.containsKey( authScope ) )
      //	{
      //	return cache.get( authScope );
      //	}

      String pw = getPassword();
      if (pw == null) pw = "";

      if (AuthPolicy.NTLM.equalsIgnoreCase(authScope.getScheme())
          || AuthPolicy.SPNEGO.equalsIgnoreCase(authScope.getScheme())) {
        String workstation = "";
        try {
          workstation = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
        }

        if (hasCredentials()) {
          log.info("Returning url credentials");
          return new NTCredentials(getUsername(), pw, workstation, null);
        }

        log.info(
            authScope.getHost() + ":" + authScope.getPort() + " requires Windows authentication");
        if (ntDialog == null) {
          buildNtDialog();
        }

        StringToStringMap values = new StringToStringMap();
        values.put(
            "Info",
            "Authentication required for ["
                + authScope.getHost()
                + ":"
                + authScope.getPort()
                + "]");
        ntDialog.setValues(values);

        if (ntDialog.show()) {
          values = ntDialog.getValues();
          NTCredentials credentials =
              new NTCredentials(
                  values.get("Username"),
                  values.get("Password"),
                  workstation,
                  values.get("Domain"));

          cache.put(authScope, credentials);
          return credentials;
        }
      } else if (AuthPolicy.BASIC.equalsIgnoreCase(authScope.getScheme())
          || AuthPolicy.DIGEST.equalsIgnoreCase(authScope.getScheme())) {
        if (hasCredentials()) {
          log.info("Returning url credentials");
          UsernamePasswordCredentials credentials =
              new UsernamePasswordCredentials(getUsername(), pw);
          cache.put(authScope, credentials);
          return credentials;
        }

        log.info(
            authScope.getHost()
                + ":"
                + authScope.getPort()
                + " requires authentication with the realm '"
                + authScope.getRealm()
                + "'");
        ShowDialog showDialog = new ShowDialog();
        showDialog.values.put(
            "Info",
            "Authentication required for ["
                + authScope.getHost()
                + ":"
                + authScope.getPort()
                + "]");

        UISupport.getUIUtils().runInUIThreadIfSWT(showDialog);
        if (showDialog.result) {
          UsernamePasswordCredentials credentials =
              new UsernamePasswordCredentials(
                  showDialog.values.get("Username"), showDialog.values.get("Password"));
          cache.put(authScope, credentials);
          return credentials;
        }
      }

      return null;
    }
Beispiel #22
0
 public void closeDialog(T modelItem) {
   onClose(modelItem);
   if (dialog != null) dialog.setVisible(false);
 }
    public void actionPerformed(ActionEvent e) {
      if (dialog == null) {
        dialog = ADialogBuilder.buildDialog(LoadOptionsForm.class);
      }

      Project project = ModelSupport.getModelItemProject(holder.getModelItem());
      if (project != null) {
        FileFormField fileFormField = (FileFormField) dialog.getFormField(LoadOptionsForm.FILE);
        String currentDirectory = extractFileChooserPathForProject(project);
        fileFormField.setCurrentDirectory(currentDirectory);
      }

      dialog
          .getFormField(LoadOptionsForm.DELETEREMAINING)
          .setEnabled(holder instanceof MutableTestPropertyHolder);
      dialog
          .getFormField(LoadOptionsForm.CREATEMISSING)
          .setEnabled(holder instanceof MutableTestPropertyHolder);

      if (dialog.show()) {
        try {
          BufferedReader reader =
              new BufferedReader(new FileReader(dialog.getValue(LoadOptionsForm.FILE)));

          String line = reader.readLine();
          int count = 0;

          Set<String> names = new HashSet<String>(Arrays.asList(holder.getPropertyNames()));

          while (line != null) {
            if (line.trim().length() > 0 && !(line.charAt(0) == '#')) {
              int ix = line.indexOf('=');
              if (ix > 0) {
                String name = line.substring(0, ix).trim();
                String value = line.length() > ix ? line.substring(ix + 1) : "";

                // read multiline value
                if (value.endsWith("\\")) {
                  value = value.substring(0, value.length() - 1);

                  String ln = reader.readLine();
                  while (ln != null && ln.endsWith("\\")) {
                    value += ln.substring(0, ln.length() - 1);
                    ln = reader.readLine();
                  }

                  if (ln != null) {
                    value += ln;
                  }
                  if (ln == null) {
                    break;
                  }
                }

                if (holder.hasProperty(name)) {
                  count++;
                  holder.getProperty(name).setValue(value);
                  holder.setPropertyValue(name, value);
                } else if (dialog.getBooleanValue(LoadOptionsForm.CREATEMISSING)
                    && holder instanceof MutableTestPropertyHolder) {
                  TestProperty prop = ((MutableTestPropertyHolder) holder).addProperty(name);
                  if (!prop.isReadOnly()) {
                    prop.setValue(value);
                    if (prop instanceof RestParameter) {
                      ((RestParameter) prop).setDefaultValue(value);
                    }
                  }
                  count++;
                }

                names.remove(name);
              }
            }

            line = reader.readLine();
          }

          if (dialog.getBooleanValue(LoadOptionsForm.DELETEREMAINING)
              && holder instanceof MutableTestPropertyHolder) {
            for (String name : names) {
              ((MutableTestPropertyHolder) holder).removeProperty(name);
            }
          }

          reader.close();
          UISupport.showInfoMessage("Added/Updated " + count + " properties from file");
        } catch (Exception ex) {
          UISupport.showErrorMessage(ex);
        }
      }
    }