示例#1
0
  public void actionPerformed(ActionEvent e) {
    boolean createOptional =
        request
            .getSettings()
            .getBoolean(WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS);
    if (!createOptional) {
      Boolean create =
          UISupport.confirmOrCancel("Create optional elements in schema?", "Create Request");
      if (create == null) return;

      createOptional = create.booleanValue();
    }

    WsdlOperation wsdlOperation = (WsdlOperation) request.getOperation();
    String req = wsdlOperation.createRequest(createOptional);
    if (req == null) {
      UISupport.showErrorMessage("Request creation failed");
      return;
    }

    if (request.getRequestContent() != null && request.getRequestContent().trim().length() > 0) {
      if (UISupport.confirm("Keep existing values", "Recreate Request")) {
        req =
            SoapUtils.transferSoapHeaders(
                request.getRequestContent(), req, wsdlOperation.getInterface().getSoapVersion());

        req = XmlUtils.transferValues(request.getRequestContent(), req);
      }
    }

    request.setRequestContent(req);
  }
  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);
      }
    }
  }