Java 类org.dom4j.util.NodeComparator 实例源码

项目:cacheonix-core    文件:Dom4jAccessorTest.java   
public void testCompanyElementGeneration() throws Throwable {
    Setter idSetter = PropertyAccessorFactory.getPropertyAccessor( generateIdProperty(), EntityMode.DOM4J )
            .getSetter( null, null );
    Setter nameSetter = PropertyAccessorFactory.getPropertyAccessor( generateNameProperty(), EntityMode.DOM4J )
            .getSetter( null, null );
    Setter textSetter = PropertyAccessorFactory.getPropertyAccessor( generateTextProperty(), EntityMode.DOM4J )
            .getSetter( null, null );
    Setter accountIdSetter = PropertyAccessorFactory.getPropertyAccessor(
            generateAccountIdProperty(), EntityMode.DOM4J
    )
            .getSetter( null, null );

    Element root = generateRootTestElement();

    idSetter.set( root, new Long( 123 ), getSFI() );
    textSetter.set( root, "description...", getSFI() );
    nameSetter.set( root, "JBoss", getSFI() );
    accountIdSetter.set( root, new Long( 456 ), getSFI() );

    assertTrue( "DOMs not equal", new NodeComparator().compare( DOM, root ) == 0 );
}
项目:orbeon-forms    文件:NonLazyUserDataElement.java   
/**
 * @return A clone.  The clone will have parent == null but will have any necessary namespace
 *         declarations this element's ancestors.
 */
public Object clone() {
    final NonLazyUserDataElement ret = cloneInternal();
    org.dom4j.Element anstr = getParent();
    done : if ( anstr != null ) {
        final NodeComparator nc = new NodeComparator();
        final java.util.TreeSet nsSet = new java.util.TreeSet( nc );

        do {
            final java.util.List sibs = anstr.content();
            for ( final java.util.Iterator itr = sibs.iterator(); itr.hasNext(); ) {
                final org.dom4j.Node sib = ( org.dom4j.Node )itr.next();
                if ( sib.getNodeType() != org.dom4j.Node.NAMESPACE_NODE ) continue;
                nsSet.add( sib );
            }
            anstr = anstr.getParent();
        }
        while ( anstr != null ); 
        if ( nsSet.isEmpty() ) break done;
        for ( final java.util.Iterator itr = nsSet.iterator(); itr.hasNext(); ) {
            final org.dom4j.Namespace ns = ( org.dom4j.Namespace )itr.next();
            final String pfx = ns.getPrefix();
            if ( ret.getNamespaceForPrefix( pfx ) != null ) continue;
            ret.add( ns );
        }
    }
    return ret;
}
项目:dls-repository-stack    文件:RemoveDuplicateElementsTransform.java   
/**
 * Private method that decides if two elements are equal. They are equal
 * only if their names are the same, their namespace prefix and attributes
 * are the same. Attributes is an option though that can be turned off for 
 * comparison
 * @param element1
 * @param element2
 * @return
 */
private boolean elementsAreEqual(Element element1,
        Element element2) {
    boolean elementsEqual = false;
    if(!this.ignoreAttributes)
    {   
        NodeComparator comparator = new NodeComparator();
        if(element1.getName().equals(element2.getName()) &&
                element1.getText().equals(element2.getText())&&
                element1.getNamespacePrefix().equals(
                        element2.getNamespacePrefix()))
        {
            if(!this.ignoreAttributes)
            {
                int c1 = element1.attributeCount();
                int c2 = element2.attributeCount();
                int answer = c1 - c2;

                // to be duplicate the attribute count must be the same
                // too
                if (answer == 0) {
                    elementsEqual = true;
                    for (int i = 0; i < c1; i++) {
                        Attribute a1 = element1.attribute(i);
                        Attribute a2 = element2.attribute(a1.getQName());
                        answer = comparator.compare(a1, a2);

                        if (answer != 0) 
                        {
                            elementsEqual = false;
                            break;
                        }
                    }
                }
            }
            else
                elementsEqual = true;
        }
        if ( comparator.compare( element1, 
                element2 ) == 0 ) {
            elementsEqual = true;
        }
    }
    else
    {
        if(element1.getName().equals(element2.getName()) &&
                element1.getText().equals(element2.getText())&&
                element1.getNamespacePrefix().equals(
                        element2.getNamespacePrefix()))
        {
            elementsEqual = true;
        }
    }
    return elementsEqual;

}
项目:validatar    文件:JUnitFormatterTest.java   
@Test
public void testWriteReport() throws IOException, DocumentException {
    Map<String, String> paramMap = new HashMap<>();
    paramMap.put("DATE", "20140807");

    ParseManager manager = new ParseManager(new String[0]);

    List<TestSuite> testSuites = manager.load((new File("src/test/resources/sample-tests/")));
    ParseManager.deParametrize(testSuites, paramMap);

    Assert.assertEquals(testSuites.size(), 3);

    TestSuite simpleExamples = testSuites.stream().filter(s -> "Simple examples".equals(s.name)).findFirst().get();
    Query failingQuery = simpleExamples.queries.get(2);
    failingQuery.setFailure("Query had a typo");
    com.yahoo.validatar.common.Test test = simpleExamples.tests.get(1);
    test.setFailed();
    test.addMessage("Sample fail message");

    TestSuite validatarExamples = testSuites.stream().filter(s -> "Validatar Example".equals(s.name)).findFirst().get();
    test = validatarExamples.tests.get(0);
    test.setFailed();
    test.addMessage("Another multiline \nfail \nmessage");

    // Generate the test report file
    String[] args = {"--report-file", "target/JUnitOutputTest.xml"};
    JUnitFormatter jUnitFormatter = new JUnitFormatter();
    jUnitFormatter.setup(args);
    jUnitFormatter.writeReport(testSuites);

    // Diff the test report file, and the expected output
    String output = new String(Files.readAllBytes(Paths.get("target/JUnitOutputTest.xml")));
    Document outputDOM = DocumentHelper.parseText(output);

    String expectedOutput = new String(Files.readAllBytes(Paths.get("src/test/resources/ExpectedJUnitOutput.xml")));
    Document expectedOutputDom = DocumentHelper.parseText(expectedOutput);

    NodeComparator comparator = new NodeComparator();
    if (comparator.compare(expectedOutputDom, outputDOM) != 0) {
        Assert.fail("The generated XML does not match expected XML!");
    }
}