Пример #1
0
  @Test
  public void subscribeMessageTest() throws Exception {

    Subscription subscription = getSampleSubscriptionPojo();

    Document generatedSubscriptinDoc =
        RequestMessageBuilderUtilities.createSubscriptionRequest(subscription);

    String subQualId =
        XmlUtils.xPathStringSearch(
            generatedSubscriptinDoc,
            "//submsg-ext:SubscriptionQualifierIdentification/nc:IdentificationID");

    String sGeneratedSubscriptionDoc = XmlUtils.getStringFromNode(generatedSubscriptinDoc);

    String sExpectedXmlSubDoc =
        XmlUtils.getRootNodeAsString(
            "src/test/resources/xml/subscriptionRequest/Arrest_Subscription_Document.xml");
    sExpectedXmlSubDoc = sExpectedXmlSubDoc.replace("@SUB_QUAL_ID@", subQualId);

    Diff diff = new Diff(sExpectedXmlSubDoc, sGeneratedSubscriptionDoc);
    DetailedDiff detailDiff = new DetailedDiff(diff);
    List<Difference> diffList = detailDiff.getAllDifferences();
    int diffCount = diffList.size();

    Assert.assertEquals(detailDiff.toString(), 0, diffCount);
  }
Пример #2
0
  /**
   * Get differences between doms.
   *
   * @param controlDom The control dom.
   * @param testDom The test dom.
   * @param ignoreAttributes The list of attributes to ignore.
   * @return The differences.
   */
  @SuppressWarnings("unchecked")
  public static List<Difference> getDifferences(
      String controlDom, String testDom, final List<String> ignoreAttributes) {
    try {
      Diff d = new Diff(Helper.getDocument(controlDom), Helper.getDocument(testDom));
      DetailedDiff dd = new DetailedDiff(d);
      dd.overrideDifferenceListener(
          new DifferenceListener() {

            @Override
            public void skippedComparison(Node control, Node test) {}

            @Override
            public int differenceFound(Difference difference) {
              if (difference.getControlNodeDetail() == null
                  || difference.getControlNodeDetail().getNode() == null
                  || difference.getTestNodeDetail() == null
                  || difference.getTestNodeDetail().getNode() == null) {
                return RETURN_ACCEPT_DIFFERENCE;
              }
              if (ignoreAttributes.contains(difference.getTestNodeDetail().getNode().getNodeName())
                  || ignoreAttributes.contains(
                      difference.getControlNodeDetail().getNode().getNodeName())) {
                return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
              }
              return RETURN_ACCEPT_DIFFERENCE;
            }
          });

      return dd.getAllDifferences();
    } catch (Exception e) {
      LOGGER.error("Error with getDifferences: " + e.getMessage(), e);
    }
    return null;
  }
  private void verifyResponse(Document response, Document template)
      throws IOException, TransformerException {
    DetailedDiff dd = new DetailedDiff(new Diff(response, template));
    dd.overrideElementQualifier(new NetconfXmlUnitRecursiveQualifier());

    printDocument(response);
    printDocument(template);

    assertTrue(dd.toString(), dd.similar());
  }
  @Test
  public void testAudioMD_noMD5() throws Exception {

    Fits fits = new Fits();

    // First generate the FITS output
    File input = new File("testfiles/test.wav");
    FitsOutput fitsOut = fits.examine(input);

    XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
    String actualXmlStr = serializer.outputString(fitsOut.getFitsXml());

    // Read in the expected XML file
    Scanner scan = new Scanner(new File("testfiles/output/FITS_test_wav_NO_MD5.xml"));
    String expectedXmlStr = scan.useDelimiter("\\Z").next();
    scan.close();

    // Set up XMLUnit
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setNormalizeWhitespace(true);

    Diff diff = new Diff(expectedXmlStr, actualXmlStr);

    // Initialize attributes or elements to ignore for difference checking
    diff.overrideDifferenceListener(
        new IgnoreNamedElementsDifferenceListener(
            "version",
            "toolversion",
            "dateModified",
            "fslastmodified",
            "lastmodified",
            "startDate",
            "startTime",
            "timestamp",
            "fitsExecutionTime",
            "executionTime",
            "filepath",
            "location"));

    DetailedDiff detailedDiff = new DetailedDiff(diff);

    // Display any Differences
    List<Difference> diffs = detailedDiff.getAllDifferences();
    if (!diff.identical()) {
      StringBuffer differenceDescription = new StringBuffer();
      differenceDescription.append(diffs.size()).append(" differences");

      System.out.println(differenceDescription.toString());
      for (Difference difference : diffs) {
        System.out.println(difference.toString());
      }
    }

    assertTrue("Differences in XML", diff.identical());
  }
 protected boolean checkDocs(Document doc1, Document doc2) {
   XMLUnit.setIgnoreAttributeOrder(true);
   XMLUnit.setIgnoreWhitespace(true);
   DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(doc1, doc2));
   boolean result = diff.similar();
   if (!result) {
     for (Difference d : (List<Difference>) diff.getAllDifferences()) {
       System.out.println(d);
     }
   }
   return result;
 }
 /**
  * Gets the diff.
  *
  * @param objectXML the object XML
  * @param exampleXML the example XML
  * @return the detailed diff
  * @throws SAXException the sAX exception
  * @throws IOException Signals that an I/O exception has occurred.
  */
 @SuppressWarnings("unchecked")
 private DetailedDiff getDiff(StringWriter objectXML, StringBuffer exampleXML)
     throws SAXException, IOException {
   DetailedDiff myDiff =
       new DetailedDiff(XMLUnit.compareXML(exampleXML.toString(), objectXML.toString()));
   List<Difference> allDifferences = myDiff.getAllDifferences();
   if (allDifferences.size() > 0) {
     for (Difference d : allDifferences) {
       System.err.println(d);
     }
   }
   return myDiff;
 }
Пример #7
0
  private void compareXmlFiles(String path, ElementQualifier qualifier) throws BrutException {
    DetailedDiff diff;
    try {
      Reader control = new FileReader(new File(sTestOrigDir, path));
      Reader test = new FileReader(new File(sTestNewDir, path));

      diff = new DetailedDiff(new Diff(control, test));
    } catch (SAXException | IOException ex) {
      throw new BrutException(ex);
    }

    if (qualifier != null) {
      diff.overrideElementQualifier(qualifier);
    }

    assertTrue(path + ": " + diff.getAllDifferences().toString(), diff.similar());
  }
  @Test
  public void testTransform() throws Exception {
    ArrayList<URL> tmapList = new ArrayList<URL>();
    URL tmap = TMapProcessor.class.getResource("tmap1.xml");
    tmapList.add(tmap);
    TMapProcessor proc = new TMapProcessor(tmapList);

    Document inputDocument = loadMessage("messageIn.xml");
    OpenEngSBMessage inputMessage = new OpenEngSBMessage(inputDocument);
    OpenEngSBMessage outputMessage = proc.transform(inputMessage);

    Document expectedDocument = loadMessage("messageOut.xml");
    Document realDocument = outputMessage.toXML();

    DetailedDiff myDiff =
        new DetailedDiff(new Diff(expectedDocument.asXML(), realDocument.asXML()));
    Assert.assertTrue(myDiff.toString(), myDiff.similar());
  }
Пример #9
0
 public void testCS_08RequiredNull() throws Exception {
   //		final String input = "<statusCode xmlns=\""+HL7_URI+"\" code=\"\" codeSystem=\"1.2.3.4\"/>";
   //		final String output = "<statusCode xmlns=\""+HL7_URI+"\" code=\"\"
   // codeSystem=\"1.2.3.4\"/>";
   final String input =
       "<statusCode xmlns=\""
           + HL7_URI
           + "\" codeSystemName=\"String\" codeSystem=\"Text\" codeSystemVersion=\"String\" code=\"\"/>";
   final String output = "<statusCode xmlns=\"" + HL7_URI + "\" code=\"\"/>";
   InputStream is = new ByteArrayInputStream(input.getBytes());
   CS value = (CS) StandaloneDataTypeContentHandler.parseValue(is, datatype);
   String fromXML = getXMLForValue(value, "statusCode");
   DetailedDiff detailedDiff =
       CommonTestUtils.getInstance()
           .doDiff(output, fromXML, new ElementNameAndAttributeQualifier());
   assertEquals("testCS_08RequiredNull ", 0, detailedDiff.getAllDifferences().size());
   //		assertXMLEqual(output, getXMLForValue(value, "statusCode"));
 }
Пример #10
0
  @Test
  public final void testRoundtripMapping() {
    try {
      if (inputElement == null) {
        unmarshalInput();
      }
      Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();
      com.wwidesigner.note.Tuning domainTuning =
          mapper.map(inputElement, com.wwidesigner.note.Tuning.class);
      Tuning bindTuning = mapper.map(domainTuning, Tuning.class);

      outputFile = new File(writePath + "mapperTest.xml");
      outputFile.delete();
      bindFactory.marshalToXml(bindTuning, outputFile);
      XmlDiff diff = new XmlDiff(inputFile, outputFile);
      DetailedDiff detailedDiff = new DetailedDiff(diff);
      assertTrue(detailedDiff.toString(), detailedDiff.identical());
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
Пример #11
0
  public void testRoundTrip() throws Exception {
    StringWriter sw = new StringWriter();
    InputStream original = getClass().getClassLoader().getResourceAsStream("testmodel_data.xml");
    XMLUnit.setIgnoreWhitespace(true);
    Collection unmarshalled = (Collection) binding.unmarshal(original);
    setIds(unmarshalled);
    binding.marshal(unmarshalled, sw);

    String expected =
        IOUtils.toString(getClass().getClassLoader().getResourceAsStream("testmodel_data.xml"));

    Diff diff = new Diff(expected, sw.toString());
    DetailedDiff detail = new DetailedDiff(diff);
    detail.overrideElementQualifier(new ElementNameAndAttributeQualifier());
    assertTrue(
        detail.getAllDifferences().toString()
            + ": Original: "
            + expected
            + ", Generated: "
            + sw.toString(),
        detail.similar());
  }
  /**
   * Generate XML.
   *
   * @throws Exception the exception
   */
  @Test
  public void generateXML() throws Exception {
    // Marshal the test object to an XML string
    StringWriter objectXML = new StringWriter();
    marshaller.marshal(tcadcc, objectXML);

    // Read the example XML from src/test/resources
    StringBuffer exampleXML = new StringBuffer();
    File tcaCollectionConfig = getSourceFile();
    assertTrue(
        TcaDataCollectionConfig.TCA_DATACOLLECTION_CONFIG_FILE + " is readable",
        tcaCollectionConfig.canRead());
    BufferedReader reader =
        new BufferedReader(
            new InputStreamReader(new FileInputStream(tcaCollectionConfig), "UTF-8"));
    String line;
    while (true) {
      line = reader.readLine();
      if (line == null) {
        reader.close();
        break;
      }
      exampleXML.append(line).append("\n");
    }
    System.err.println("========================================================================");
    System.err.println("Object XML:");
    System.err.println("========================================================================");
    System.err.print(objectXML.toString());
    System.err.println("========================================================================");
    System.err.println("Example XML:");
    System.err.println("========================================================================");
    System.err.print(exampleXML.toString());
    DetailedDiff myDiff = getDiff(objectXML, exampleXML);
    assertEquals(
        "number of XMLUnit differences between the example XML and the mock object XML is 0",
        0,
        myDiff.getAllDifferences().size());
  }
Пример #13
0
  protected List<Difference> getDifferences(final String xmlA, final String xmlB) {
    DetailedDiff myDiff;
    try {
      myDiff = new DetailedDiff(XMLUnit.compareXML(xmlA, xmlB));
    } catch (final Exception e) {
      throw new RuntimeException(e);
    }
    final List<Difference> retDifferences = new ArrayList<Difference>();
    @SuppressWarnings("unchecked")
    final List<Difference> allDifferences = myDiff.getAllDifferences();
    if (allDifferences.size() > 0) {
      DIFFERENCES:
      for (final Difference d : allDifferences) {
        final NodeDetail controlNodeDetail = d.getControlNodeDetail();
        final String control = controlNodeDetail.getValue();
        final NodeDetail testNodeDetail = d.getTestNodeDetail();
        final String test = testNodeDetail.getValue();

        if (d.getDescription().equals("namespace URI")) {
          if (control != null && !"null".equals(control)) {
            if (ignoreNamespace(control.toLowerCase())) {
              LOG.trace("Ignoring {}: {}", d.getDescription(), d);
              continue DIFFERENCES;
            }
          }
          if (test != null && !"null".equals(test)) {
            if (ignoreNamespace(test.toLowerCase())) {
              LOG.trace("Ignoring {}: {}", d.getDescription(), d);
              continue DIFFERENCES;
            }
          }
        } else if (d.getDescription().equals("namespace prefix")) {
          if (control != null && !"null".equals(control)) {
            if (ignorePrefix(control.toLowerCase())) {
              LOG.trace("Ignoring {}: {}", d.getDescription(), d);
              continue DIFFERENCES;
            }
          }
          if (test != null && !"null".equals(test)) {
            if (ignorePrefix(test.toLowerCase())) {
              LOG.trace("Ignoring {}: {}", d.getDescription(), d);
              continue DIFFERENCES;
            }
          }
        } else if (d.getDescription().equals("xsi:schemaLocation attribute")) {
          LOG.debug(
              "Schema location '{}' does not match.  Ignoring.",
              controlNodeDetail.getValue() == null
                  ? testNodeDetail.getValue()
                  : controlNodeDetail.getValue());
          continue DIFFERENCES;
        }

        if (ignoreDifference(d)) {
          LOG.debug(
              "ignoreDifference matched.  Ignoring difference: {}: {}", d.getDescription(), d);
          continue DIFFERENCES;
        } else {
          LOG.warn("Found difference: {}: {}", d.getDescription(), d);
          retDifferences.add(d);
        }
      }
    }
    return retDifferences;
  }