@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;
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  private SoapUIAMFConnection getConnection(AMFRequest amfRequest) throws Exception {
    SoapUIAMFConnection amfConnection = null;
    if (isAuthorisationEnabled(amfRequest) && (context.getModelItem() instanceof WsdlTestCase)) {
      if ((amfConnection = (SoapUIAMFConnection) context.getProperty(AMF_CONNECTION)) != null) {
        return amfConnection;
      } else {
        throw new Exception("amf session connection error! ");
      }
    } else if (isAuthorisationEnabled(amfRequest)
        && (context.getModelItem() instanceof AMFRequestTestStep)) {
      String endpoint = context.expand(getTestCaseConfig(amfRequest).getAmfEndpoint());
      String username = context.expand(getTestCaseConfig(amfRequest).getAmfLogin());
      String password = context.expand(getTestCaseConfig(amfRequest).getAmfPassword());

      if (StringUtils.hasContent(endpoint) && StringUtils.hasContent(username)) {
        credentials = new AMFCredentials(endpoint, username, password, context);
        amfConnection = credentials.login();
      } else {
        amfConnection = new SoapUIAMFConnection();
        amfConnection.connect(context.expand(amfRequest.getEndpoint()));
      }

      context.setProperty(AMF_CONNECTION, amfConnection);
      return amfConnection;
    } else {
      amfConnection = new SoapUIAMFConnection();
      amfConnection.connect(context.expand(amfRequest.getEndpoint()));
      return amfConnection;
    }
  }
Ejemplo n.º 3
0
  protected void addPropertyExpansions(PropertyExpansionsResult result) {
    if (StringUtils.hasContent(config.getUsername())) {
      result.extractAndAddAll("username");
    }

    if (StringUtils.hasContent(config.getPassword())) {
      result.extractAndAddAll("password");
    }
  }
Ejemplo n.º 4
0
  public static String extractHttpHeaderParameter(String headerString, String parameterName) {
    if (!StringUtils.hasContent(headerString) || !StringUtils.hasContent(parameterName))
      return null;

    int ix = headerString.indexOf(parameterName + "=\"");
    if (ix > 0) {
      int ix2 = headerString.indexOf('"', ix + parameterName.length() + 2);
      if (ix2 > ix) return headerString.substring(ix + parameterName.length() + 2, ix2);
    }

    return null;
  }
Ejemplo n.º 5
0
  protected void createGetMethod(String url) {
    getMethod = new HttpGet(url);
    getMethod.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, true);
    state.setAttribute(ClientContext.CREDS_PROVIDER, new WsdlCredentialsProvider());

    if (SoapUI.getSettings().getBoolean(HttpSettings.AUTHENTICATE_PREEMPTIVELY)) {
      if (!StringUtils.isNullOrEmpty(getUsername()) && !StringUtils.isNullOrEmpty(getPassword())) {
        UsernamePasswordCredentials creds =
            new UsernamePasswordCredentials(getUsername(), getPassword());
        getMethod.addHeader(BasicScheme.authenticate(creds, "utf-8", false));
      }
    }
  }
Ejemplo n.º 6
0
  private void processElement(SchemaParticle sp, XmlCursor xmlc, boolean mixed) {
    // cast as schema local element
    SchemaLocalElement element = (SchemaLocalElement) sp;

    // Add comment about type
    addElementTypeAndRestricionsComment(element, xmlc);

    // / ^ -> <elemenname></elem>^
    if (_soapEnc) xmlc.insertElement(element.getName().getLocalPart()); // soap
    // encoded?
    // drop
    // namespaces.
    else xmlc.insertElement(element.getName().getLocalPart(), element.getName().getNamespaceURI());
    // / -> <elem>^</elem>
    // processAttributes( sp.getType(), xmlc );

    xmlc.toPrevToken();
    // -> <elem>stuff^</elem>

    String[] values = null;
    if (multiValues != null) values = multiValues.get(element.getName());
    if (values != null) xmlc.insertChars(StringUtils.join(values, ","));
    else if (sp.isDefault()) xmlc.insertChars(sp.getDefaultText());
    else createSampleForType(element.getType(), xmlc);
    // -> <elem>stuff</elem>^
    xmlc.toNextToken();
  }
Ejemplo n.º 7
0
  protected String getWsdlUrl(StringToStringMap values, T modelItem) {
    String wsdl = values.get(WSDL);
    boolean useCached = values.getBoolean(CACHED_WSDL);

    if (modelItem instanceof AbstractInterface) {
      AbstractInterface<?> iface = (AbstractInterface<?>) modelItem;

      boolean hasDefinition = StringUtils.hasContent(iface.getDefinition());
      if (wsdl == null && !useCached && hasDefinition) {
        return PathUtils.expandPath(iface.getDefinition(), iface);
      }

      if (!hasDefinition || (useCached && iface.getDefinitionContext().isCached())) {
        try {
          File tempFile = File.createTempFile("tempdir", null);
          String path = tempFile.getAbsolutePath();
          tempFile.delete();
          wsdl = iface.getDefinitionContext().export(path);

          // CachedWsdlLoader loader = (CachedWsdlLoader)
          // iface.createWsdlLoader();
          // wsdl = loader.saveDefinition(path);
        } catch (Exception e) {
          SoapUI.logError(e);
        }
      }
    }

    return wsdl;
  }
Ejemplo n.º 8
0
  private String normalize(String string) {

    if (!StringUtils.isNullOrEmpty(string)) {
      string = string.replaceAll("\r\n", "\n");
    }
    return string;
  }
Ejemplo n.º 9
0
  public String createXmlRepresentation(TypedContent typedContent) {
    String content = typedContent == null ? null : typedContent.getContentAsString();
    if (!StringUtils.hasContent(content)) {
      return "<xml/>";
    }

    try {
      // XmlObject.Factory.parse( new ByteArrayInputStream(
      // content.getBytes() ) );
      XmlUtils.createXmlObject(new ByteArrayInputStream(content.getBytes()));
      return content;
    } catch (Exception e) {
      // fall through, this wasn't xml
    }

    try {
      Tidy tidy = new Tidy();
      tidy.setXmlOut(true);
      tidy.setShowWarnings(false);
      tidy.setErrout(new PrintWriter(new StringWriter()));
      // tidy.setQuiet(true);
      tidy.setNumEntities(true);
      tidy.setQuoteNbsp(true);
      tidy.setFixUri(false);

      Document document = tidy.parseDOM(new ByteArrayInputStream(content.getBytes()), null);
      StringWriter writer = new StringWriter();
      XmlUtils.serializePretty(document, writer);
      return writer.toString();
    } catch (Throwable e) {
      SoapUI.logError(e);
    }
    return null;
  }
Ejemplo n.º 10
0
  private Param resolveParameter(Param param) {
    String href = param.getHref();
    if (!StringUtils.hasContent(href)) {
      return param;
    }

    try {
      Application app = application;

      if (!href.startsWith("#")) {
        ApplicationDocument applicationDocument = loadReferencedWadl(href);
        app = applicationDocument.getApplication();
      }

      if (app != null) {
        int ix = href.lastIndexOf('#');
        if (ix >= 0) {
          href = href.substring(ix + 1);
        }

        for (Param p : application.getParamList()) {
          if (p.getId().equals(href)) {
            return p;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }
Ejemplo n.º 11
0
  private Representation resolveRepresentation(Representation representation) {
    String href = representation.getHref();
    if (!StringUtils.hasContent(href)) {
      return representation;
    }

    try {
      Application app = application;

      if (!href.startsWith("#")) {
        ApplicationDocument applicationDocument = loadReferencedWadl(href);
        app = applicationDocument.getApplication();
      }

      if (app != null) {
        int ix = href.lastIndexOf('#');
        if (ix >= 0) {
          href = href.substring(ix + 1);
        }

        for (Representation m : application.getRepresentationList()) {
          if (m.getId().equals(href)) {
            return m;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return representation;
  }
Ejemplo n.º 12
0
  private Method resolveMethod(Method method) {
    String href = method.getHref();
    if (!StringUtils.hasContent(href)) {
      return method;
    }

    for (Method m : application.getMethodList()) {
      if (m.getId().equals(href.substring(1))) {
        return m;
      }
    }

    try {
      ApplicationDocument applicationDocument = loadReferencedWadl(href);
      if (applicationDocument != null) {
        int ix = href.lastIndexOf('#');
        if (ix > 0) {
          href = href.substring(ix + 1);
        }

        for (Method m : application.getMethodList()) {
          if (m.getId().equals(href)) {
            return m;
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return method;
  }
Ejemplo n.º 13
0
 private String determineSuggestedDirectory(Project project) {
   String currentDirectory =
       StringUtils.hasContent(project.getResourceRoot())
           ? project.getResourceRoot()
           : project.getPath();
   if (!StringUtils.hasContent(currentDirectory)) {
     return System.getProperty("user.dir", ".");
   } else if (holder.getModelItem() instanceof AbstractWsdlModelItem) {
     String expandedPath =
         PathUtils.expandPath(
             currentDirectory, ((AbstractWsdlModelItem) (holder.getModelItem())));
     return FilenameUtils.normalize(expandedPath);
   } else {
     return currentDirectory;
   }
 }
Ejemplo n.º 14
0
 public String getWssType() {
   String wssPasswordType = endpointConfig.getWssType();
   return StringUtils.isNullOrEmpty(wssPasswordType)
           || WsdlRequest.PW_TYPE_NONE.equals(wssPasswordType)
       ? null
       : wssPasswordType;
 }
Ejemplo n.º 15
0
  public RestMethod(RestResource service, RestMethodConfig methodConfig) {
    super(
        methodConfig,
        service,
        "/"
            + (StringUtils.isNullOrEmpty(methodConfig.getMethod())
                ? "get"
                : methodConfig.getMethod().toLowerCase())
            + "_method.gif");
    this.resource = service;

    if (methodConfig.getParameters() == null) methodConfig.addNewParameters();

    params = new XmlBeansRestParamsTestPropertyHolder(this, methodConfig.getParameters());

    for (RestResourceRepresentationConfig config : methodConfig.getRepresentationList()) {
      RestRepresentation representation = new RestRepresentation(this, config);
      representations.add(representation);
      notifyPropertyChanged("representations", null, representation);
    }

    for (RestRequestConfig config : methodConfig.getRequestList()) {
      RestRequest request = new RestRequest(this, config, false);
      requests.add(request);
      notifyPropertyChanged("childRequests", null, request);
    }

    addTestPropertyListener(testPropertyListener);
  }
Ejemplo n.º 16
0
 private String getFirstTitle(List<Doc> list, String defaultTitle) {
   for (Doc doc : list) {
     if (StringUtils.hasContent(doc.getTitle())) {
       return doc.getTitle();
     }
   }
   return defaultTitle;
 }
Ejemplo n.º 17
0
  public XmlObject getRequestXmlObject() throws XmlException {
    if (requestXmlObject == null && StringUtils.hasContent(getRequestContent()))
      // requestXmlObject = XmlObject.Factory.parse( getRequestContent() );
      requestXmlObject =
          XmlUtils.createXmlObject(getRequestContent(), XmlUtils.createDefaultXmlOptions());

    return requestXmlObject;
  }
 private void init() {
   XmlObjectConfigurationReader reader = new XmlObjectConfigurationReader(getConfiguration());
   includeGlobal = reader.readBoolean(INCLUDE_GLOBAL, true);
   includeProjectSpecific = reader.readBoolean(INCLUDE_PROJECT_SPECIFIC, true);
   assertionSpecificExposureList =
       StringUtils.toStringList(reader.readStrings(ASSERTION_SPECIFIC_EXPOSURE_LIST));
   extractTokenTable();
 }
Ejemplo n.º 19
0
  public String getUsername() {
    String username = config.getUsername();
    if (StringUtils.isNullOrEmpty(username)) {
      username = outgoingWss.getUsername();
    }

    return username;
  }
Ejemplo n.º 20
0
  public String getPassword() {
    String password = config.getPassword();
    if (StringUtils.isNullOrEmpty(password)) {
      password = outgoingWss.getPassword();
    }

    return password;
  }
Ejemplo n.º 21
0
  /**
   * Method for processing policy on interface level it should include processing of all types of
   * policies, but for now there's only Addressing policy implemented
   *
   * @param policy
   * @return this interface changed in a proper way indicated by the policy
   */
  public void processPolicy(Policy policy) throws Exception {

    // default is optional
    // String anonymous = AnonymousTypeConfig.OPTIONAL.toString();
    // if (StringUtils.isNullOrEmpty(interfaceAnonymous) || policyFlag)
    // interfaceAnonymous = AnonymousTypeConfig.OPTIONAL.toString() ;
    // if (StringUtils.isNullOrEmpty(interfaceWsaVersion)|| policyFlag)
    // interfaceWsaVersion = WsaVersionTypeConfig.NONE.toString();
    if (!policyFlag) {
      interfaceAnonymous = AnonymousTypeConfig.OPTIONAL.toString();
      interfaceWsaVersion = WsaVersionTypeConfig.NONE.toString();
    }
    policyFlag = true;

    if (policy != null) {
      List<Addressing> addressingList = policy.getAddressingList();
      List<?> usingAddressingList = policy.getUsingAddressingList();
      for (Addressing addressing : addressingList) {
        policyFlag = true;
        String optional = addressing.getOptional().toString();
        if (StringUtils.isNullOrEmpty(optional)
            || optional.equals("false")
            || (optional.equals("true")
                && SoapUI.getSettings().getBoolean(WsaSettings.ENABLE_FOR_OPTIONAL))) {
          interfaceWsaVersion = WsaVersionTypeConfig.X_200508.toString();
        }
        Policy innerPolicy = addressing.getPolicy();
        if (innerPolicy != null) {
          List<AnonymousResponses> anonymousList = innerPolicy.getAnonymousResponsesList();
          List<NonAnonymousResponses> nonAnonymousList = innerPolicy.getNonAnonymousResponsesList();
          if (anonymousList.size() > 0 && nonAnonymousList.size() > 0) {
            throw new Exception(
                "Wrong addressing policy, anonymousResponses and nonAnonymousResponses can not be specified together");
          }
          if (anonymousList.size() > 0) {
            interfaceAnonymous = AnonymousTypeConfig.REQUIRED.toString();
          } else {
            if (nonAnonymousList.size() > 0) {
              interfaceAnonymous = AnonymousTypeConfig.PROHIBITED.toString();
            }
          }
        }
      }
      if (interfaceWsaVersion == WsaVersionTypeConfig.NONE.toString()
          && !usingAddressingList.isEmpty()) {
        /*
         * UsingAddressing can also be specified insde Policy check
         * http://www.w3.org/TR/ws-addr-wsdl/#id2263339
         */
        interfaceWsaVersion = WsaVersionTypeConfig.X_200508.toString();
      }
    }
    setAnonymous(interfaceAnonymous);
    // set wsaVersion to one from policy only if it was null from wsdl binding
    if (getConfig().getWsaVersion().equals(WsaVersionTypeConfig.NONE)) {
      setWsaVersion(interfaceWsaVersion);
    }
  }
Ejemplo n.º 22
0
  public void onSave() {
    if (config == null) {
      return;
    }

    removeUnusedEndpoints();

    // remove unused
    for (int c = 0; c < config.sizeOfEndpointArray(); c++) {
      EndpointConfig ec = config.getEndpointArray(c);
      if (StringUtils.isNullOrEmpty(ec.getDomain())
          && StringUtils.isNullOrEmpty(ec.getUsername())
          && StringUtils.isNullOrEmpty(ec.getPassword())
          && StringUtils.isNullOrEmpty(ec.getWssType())
          && StringUtils.isNullOrEmpty(ec.getWssTimeToLive())
          && StringUtils.isNullOrEmpty(ec.getIncomingWss())
          && StringUtils.isNullOrEmpty(ec.getOutgoingWss())
          && ec.getMode() == EndpointConfig.Mode.COMPLEMENT) {
        synchronized (defaults) {
          defaults.remove(ec.getStringValue());
          config.removeEndpoint(c);
          c--;
        }
      }
    }

    if (config.sizeOfEndpointArray() == 0) {
      project.getConfig().unsetEndpointStrategy();
      config = null;
    }
  }
Ejemplo n.º 23
0
  public static String ensureEndpointStartsWithProtocol(String endpoint) {
    if (StringUtils.isNullOrEmpty(endpoint)) return endpoint;

    String ep = endpoint.toLowerCase().trim();
    if (!ep.startsWith("http://") && !ep.startsWith("https://") && !ep.startsWith("$"))
      return "http://" + endpoint;

    return endpoint;
  }
Ejemplo n.º 24
0
 private static boolean checkIfJMS(Request request) {
   try {
     String endpoint = request.getEndpoint();
     return StringUtils.hasContent(endpoint)
         && endpoint.startsWith(JMSEndpoint.JMS_ENDPIONT_PREFIX);
   } catch (NullPointerException e) {
     SoapUI.logError(e);
   }
   return false;
 }
Ejemplo n.º 25
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);
      }
    }
Ejemplo n.º 26
0
  public void addSeparator(String label) {
    addSpace(rowSpacing);
    addSpace(rowSpacing);

    layout.appendRow(rowSpec);
    int row = layout.getRowCount();

    if (StringUtils.isNullOrEmpty(label)) panel.add(new JSeparator(), cc.xywh(2, row, 3, 1));
    else panel.add(new JLabel(label), cc.xywh(2, row, 3, 1));

    addSpace(rowSpacing);
  }
  public XmlBeansPropertiesTestPropertyHolder(ModelItem modelItem, PropertiesTypeConfig config) {
    this.modelItem = modelItem;
    this.config = config;

    for (int c = 0; c < config.sizeOfPropertyArray(); c++) {
      PropertyConfig propertyConfig = config.getPropertyArray(c);
      if (StringUtils.hasContent(propertyConfig.getName())) {
        addProperty(propertyConfig, false, null);
      } else {
        config.removeProperty(c);
        c--;
      }
    }
  }
Ejemplo n.º 28
0
  protected void prepareRequestStep(HttpRequestTestStep requestStep) {
    AbstractHttpRequest<?> httpRequest = requestStep.getHttpRequest();
    if (StringUtils.hasContent(endpoint)) {
      httpRequest.setEndpoint(endpoint);
    } else if (StringUtils.hasContent(host)) {
      try {
        String ep = Tools.replaceHost(httpRequest.getEndpoint(), host);
        httpRequest.setEndpoint(ep);
      } catch (Exception e) {
        log.error("Failed to set host on endpoint", e);
      }
    }

    if (StringUtils.hasContent(username)) {
      httpRequest.setUsername(username);
    }

    if (StringUtils.hasContent(password)) {
      httpRequest.setPassword(password);
    }

    if (StringUtils.hasContent(domain)) {
      httpRequest.setDomain(domain);
    }

    if (httpRequest instanceof WsdlRequest) {

      if (wssPasswordType != null && wssPasswordType.length() > 0) {
        ((WsdlRequest) httpRequest)
            .setWssPasswordType(
                wssPasswordType.equals("Digest")
                    ? WsdlTestRequest.PW_TYPE_DIGEST
                    : WsdlTestRequest.PW_TYPE_TEXT);
      }
    }
  }
Ejemplo n.º 29
0
 private Set<String> getResponseStatuses(RestMethod method) {
   Set<String> statuses = new HashSet<>();
   for (RestRepresentation repr : method.getRepresentations()) {
     if (repr.getType() == RestRepresentation.Type.RESPONSE) {
       for (Object item : repr.getStatus()) {
         String status = item.toString();
         if (StringUtils.hasContent(status)) {
           statuses.add(status);
         }
       }
     }
   }
   if (deploymentSetting.proxyIntegration && statuses.isEmpty()) {
     statuses.add(deploymentSetting.defaultResponse);
   }
   return statuses;
 }
    public void actionPerformed(ActionEvent e) {
      if (StringUtils.isNullOrEmpty(testStep.getSource())) {
        UISupport.showErrorMessage("Missing source-file to load from");
        return;
      }

      try {
        boolean createMissing =
            UISupport.confirm("Create missing properties?", "Reload Properties");
        int cnt = testStep.loadProperties(createMissing);
        UISupport.showInfoMessage(
            "Loaded " + cnt + " properties from [" + testStep.getSource() + "]");
      } catch (Exception e1) {
        UISupport.showErrorMessage(
            "Failed to load properties from [" + testStep.getSource() + "]; " + e1);
      }
    }