protected void createTransfer(StringToStringMap values) {
    String propertyTransfer = values.get(TRANSFER_STEP);

    WsdlTestCase testCase = (WsdlTestCase) request.getTestCase();
    TransferResponseValuesTestStep transferStep =
        (TransferResponseValuesTestStep) testCase.getTestStepByName(propertyTransfer);

    if (transferStep == null) {
      int index = testCase.getIndexOfTestStep(request.getRequestStep());
      transferStep =
          (TransferResponseValuesTestStep)
              testCase.insertTestStep(
                  TransferValuesStepFactory.TRANSFER_TYPE, propertyTransfer, index);
    }

    if (transferStep == null) {
      UISupport.showErrorMessage("Missing transfer step [" + propertyTransfer + "]");
      return;
    }

    PropertyTransfer transfer = transferStep.getTransferByName(values.get(TRANSFER_NAME));
    if (transfer == null) transfer = transferStep.addTransfer(values.get(TRANSFER_NAME));

    transfer.setTargetStepName(request.getRequestStep().getName());
    transfer.setTargetPropertyName("Request");
    transfer.setTargetPath(values.get(TARGET_XPATH));

    String sourceStepName = values.get(SOURCE_STEP);
    transfer.setSourceStepName(sourceStepName);

    TestStep sourceStep = testCase.getTestStepByName(sourceStepName);
    if (sourceStep == null) {
      sourceStep =
          (WsdlPropertiesTestStep)
              testCase.insertTestStep(PropertiesStepFactory.PROPERTIES_TYPE, sourceStepName, 0);
    }

    String sourcePropertyName = values.get(SOURCE_PROPERTY);

    if (sourceStep.getProperty(sourcePropertyName) == null
        && sourceStep instanceof WsdlPropertiesTestStep) {
      ((WsdlPropertiesTestStep) sourceStep).addProperty(sourcePropertyName);
    }

    transfer.setSourcePropertyName(sourcePropertyName);

    if (values.getBoolean(OPEN_EDITOR)) {
      TransferResponseValuesDesktopPanel panel =
          (TransferResponseValuesDesktopPanel) UISupport.showDesktopPanel(transferStep);

      panel.selectTransfer(transfer);
    }
  }
  private Object[] getSourceSteps() {
    List<TestStep> steps = request.getTestCase().getTestStepList();
    List<String> result = new ArrayList<String>();
    result.add(null);

    for (TestStep step : steps) {
      if (!(step instanceof TransferResponseValuesTestStep) && step != request.getRequestStep()) {
        result.add(step.getName());
      }
    }

    return result.toArray();
  }
Exemple #3
0
  private void getAllMessages(ModelItem modelItem, List<AbstractWsdlModelItem<?>> list) {
    if (modelItem instanceof AbstractHttpRequestInterface<?>) {
      AbstractHttpRequest<?> wsdlRequest = (AbstractHttpRequest<?>) modelItem;
      if (wsdlRequest.getOperation().getInterface() == this) list.add(wsdlRequest);
    } else if (modelItem instanceof WsdlTestRequestStep) {
      WsdlTestRequestStep testRequestStep = (WsdlTestRequestStep) modelItem;
      WsdlTestRequest testRequest = testRequestStep.getTestRequest();
      if (testRequest != null
          && testRequest.getOperation() != null
          && testRequest.getOperation().getInterface() == this) list.add(testRequest);
    } else if (modelItem instanceof WsdlMockResponse) {
      WsdlMockResponse mockResponse = (WsdlMockResponse) modelItem;
      if (mockResponse.getMockOperation() != null
          && mockResponse.getMockOperation().getOperation() != null
          && mockResponse.getMockOperation().getOperation().getInterface() == this)
        list.add(mockResponse);
    }

    // Traverse the ModelItem hierarchy.
    for (ModelItem child : modelItem.getChildren()) {
      getAllMessages(child, list);
    }
  }
  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();
  }
  private String findPropertyTransfer() {
    int ix = request.getTestCase().getIndexOfTestStep(request.getRequestStep());
    int ix2 = ix + 1;

    while (ix2 < request.getTestCase().getTestStepCount()) {
      if (request.getTestCase().getTestStepAt(ix2) instanceof TransferResponseValuesTestStep)
        return request.getTestCase().getTestStepAt(ix2).getName();

      ix2++;
    }

    ix2 = 0;
    while (ix2 < ix) {
      if (request.getTestCase().getTestStepAt(ix2) instanceof TransferResponseValuesTestStep)
        return request.getTestCase().getTestStepAt(ix2).getName();

      ix2++;
    }

    return null;
  }
  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);
      }
    }
  }