Пример #1
0
  private String addDocumentType(Map<String, String> parameters) throws Exception {
    DocumentType docType = new DocumentType();
    docType.setUid(Long.parseLong(parameters.get("uid")));
    docType.setName(parameters.get("name"));
    if (parameters.get("heritedfrom").isEmpty()) {
      docType.setDocumentTypeUid(-1);
    } else {
      docType.setDocumentTypeUid(Long.parseLong(parameters.get("heritedfrom")));
    }

    ArrayList<Map<String, String>> l =
        (ArrayList<Map<String, String>>)
            new JSONDeserializer().deserialize(parameters.get("jsonParameters"));
    List<Meta> metas = new ArrayList<Meta>();
    for (Map metaDatas : l) {
      Meta meta = new Meta();
      meta.setUid(-1);
      meta.setName(String.valueOf(metaDatas.get("name")));
      meta.setMetaType((Integer) metaDatas.get("metaType"));
      if (String.valueOf(metaDatas.get("metaFeedUid")).isEmpty()) {
        meta.setMetaFeedUid(-1L);
      } else {
        meta.setMetaFeedUid(((Integer) metaDatas.get("metaFeedUid")).longValue());
      }
      meta.setDocumentTypeUid(docType.getUid());
      metas.add(meta);
    }
    String xmlStream = XMLGenerators.getDocumentTypeXMLDescriptor(docType, metas);
    studioController.addDocumentType(sessionUid, xmlStream);
    return "";
  }
Пример #2
0
  /**
   * Handle document type definition with validation of publicId and systemId.
   *
   * @param received
   * @param source
   * @param validationContext
   * @param namespaceContext
   */
  private void doDocumentTypeDefinition(
      Node received,
      Node source,
      XmlMessageValidationContext validationContext,
      NamespaceContext namespaceContext,
      TestContext context) {

    Assert.isTrue(
        source instanceof DocumentType,
        "Missing document type definition in expected xml fragment");

    DocumentType receivedDTD = (DocumentType) received;
    DocumentType sourceDTD = (DocumentType) source;

    if (log.isDebugEnabled()) {
      log.debug(
          "Validating document type definition: "
              + receivedDTD.getPublicId()
              + " ("
              + receivedDTD.getSystemId()
              + ")");
    }

    if (!StringUtils.hasText(sourceDTD.getPublicId())) {
      Assert.isNull(
          receivedDTD.getPublicId(),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type public id not equal",
              sourceDTD.getPublicId(),
              receivedDTD.getPublicId()));
    } else if (sourceDTD.getPublicId().trim().equals(CitrusConstants.IGNORE_PLACEHOLDER)) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Document type public id: '"
                + receivedDTD.getPublicId()
                + "' is ignored by placeholder '"
                + CitrusConstants.IGNORE_PLACEHOLDER
                + "'");
      }
    } else {
      Assert.isTrue(
          StringUtils.hasText(receivedDTD.getPublicId())
              && receivedDTD.getPublicId().equals(sourceDTD.getPublicId()),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type public id not equal",
              sourceDTD.getPublicId(),
              receivedDTD.getPublicId()));
    }

    if (!StringUtils.hasText(sourceDTD.getSystemId())) {
      Assert.isNull(
          receivedDTD.getSystemId(),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type system id not equal",
              sourceDTD.getSystemId(),
              receivedDTD.getSystemId()));
    } else if (sourceDTD.getSystemId().trim().equals(CitrusConstants.IGNORE_PLACEHOLDER)) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Document type system id: '"
                + receivedDTD.getSystemId()
                + "' is ignored by placeholder '"
                + CitrusConstants.IGNORE_PLACEHOLDER
                + "'");
      }
    } else {
      Assert.isTrue(
          StringUtils.hasText(receivedDTD.getSystemId())
              && receivedDTD.getSystemId().equals(sourceDTD.getSystemId()),
          ValidationUtils.buildValueMismatchErrorMessage(
              "Document type system id not equal",
              sourceDTD.getSystemId(),
              receivedDTD.getSystemId()));
    }

    validateXmlTree(
        received.getNextSibling(),
        source.getNextSibling(),
        validationContext,
        namespaceContext,
        context);
  }