[java-opensaml] branch master updated: OSJ-233 - migrate away from legacy xmlunit API
Scott Cantor
cantor.2 at osu.edu
Thu Apr 2 12:44:43 EDT 2020
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=a053009d9821d295be62ae262dc003ab73bc9333
The following commit(s) were added to refs/heads/master by this push:
new a053009 OSJ-233 - migrate away from legacy xmlunit API
a053009 is described below
commit a053009d9821d295be62ae262dc003ab73bc9333
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Apr 2 12:44:40 2020 -0400
OSJ-233 - migrate away from legacy xmlunit API
https://issues.shibboleth.net/jira/browse/OSJ-233
---
.../org/opensaml/core/xml/MarshallingTest.java | 8 +++--
.../opensaml/core/xml/XMLObjectBaseTestCase.java | 13 +++++----
.../org/opensaml/saml/common/RoundTripTest.java | 23 ++++++++-------
.../artifact/impl/BasicSAMLArtifactMapTest.java | 24 +++++++--------
...rageServiceSAMLArtifactMapEntryFactoryTest.java | 26 ++++++++---------
.../impl/StorageServiceSAMLArtifactMapTest.java | 24 +++++++--------
.../java/org/opensaml/soap/WSBaseTestCase.java | 13 ++++-----
.../encoder/http/impl/HTTPSOAP11EncoderTest.java | 23 +++++++++++----
.../wssecurity/impl/WSSecurityObjectsTestCase.java | 34 +++++++++++-----------
9 files changed, 101 insertions(+), 87 deletions(-)
diff --git a/opensaml-core/src/test/java/org/opensaml/core/xml/MarshallingTest.java b/opensaml-core/src/test/java/org/opensaml/core/xml/MarshallingTest.java
index df49423..9babad1 100644
--- a/opensaml-core/src/test/java/org/opensaml/core/xml/MarshallingTest.java
+++ b/opensaml-core/src/test/java/org/opensaml/core/xml/MarshallingTest.java
@@ -23,14 +23,14 @@ import javax.xml.namespace.QName;
import net.shibboleth.utilities.java.support.xml.XMLParserException;
-import org.custommonkey.xmlunit.Diff;
-import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
import org.opensaml.core.xml.io.Marshaller;
import org.opensaml.core.xml.io.MarshallingException;
import org.opensaml.core.xml.mock.SimpleXMLObject;
import org.opensaml.core.xml.mock.SimpleXMLObjectBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.Diff;
/**
* Unit test for marshalling functions.
@@ -152,7 +152,9 @@ public class MarshallingTest extends XMLObjectBaseTestCase {
// Marshall statement (with cached DOM) into SOAP Body element child
Document expectedDocument = parserPool.parse(MarshallingTest.class.getResourceAsStream(expectedDocumentLocation));
Element statementElem = marshaller.marshall(statement, soapBody);
- XMLAssertTestNG.assertXMLIdentical(new Diff(expectedDocument, statementElem.getOwnerDocument()), true);
+ final Diff diff = DiffBuilder.compare(statementElem.getOwnerDocument()).withTest(expectedDocument)
+ .checkForIdentical().build();
+ Assert.assertFalse(diff.hasDifferences(), diff.toString());
Assert.assertNull(response.getDOM(), "Parent of XML fragment DOM was not invalidated during marshalling");
Assert.assertNotNull(statement.getDOM(), "XML fragment DOM was invalidated during marshalling");
}
diff --git a/opensaml-core/src/test/java/org/opensaml/core/xml/XMLObjectBaseTestCase.java b/opensaml-core/src/test/java/org/opensaml/core/xml/XMLObjectBaseTestCase.java
index f211d27..1cbf81b 100644
--- a/opensaml-core/src/test/java/org/opensaml/core/xml/XMLObjectBaseTestCase.java
+++ b/opensaml-core/src/test/java/org/opensaml/core/xml/XMLObjectBaseTestCase.java
@@ -24,8 +24,6 @@ import java.io.InputStream;
import javax.xml.namespace.QName;
-import org.custommonkey.xmlunit.Diff;
-import org.custommonkey.xmlunit.XMLUnit;
import org.opensaml.core.OpenSAMLInitBaseTestCase;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.core.xml.io.Marshaller;
@@ -42,11 +40,12 @@ import org.testng.annotations.BeforeClass;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.Diff;
import net.shibboleth.utilities.java.support.xml.ParserPool;
import net.shibboleth.utilities.java.support.xml.QNameSupport;
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
-import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
import net.shibboleth.utilities.java.support.xml.XMLParserException;
/**
@@ -74,8 +73,6 @@ public abstract class XMLObjectBaseTestCase extends OpenSAMLInitBaseTestCase {
@BeforeClass
protected void initXMLObjectSupport() throws Exception {
- XMLUnit.setIgnoreWhitespace(true);
-
try {
parserPool = XMLObjectProviderRegistrySupport.getParserPool();
builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
@@ -118,7 +115,11 @@ public abstract class XMLObjectBaseTestCase extends OpenSAMLInitBaseTestCase {
if (log.isDebugEnabled()) {
log.debug("Marshalled DOM was " + SerializeSupport.nodeToString(generatedDOM));
}
- XMLAssertTestNG.assertXMLIdentical(failMessage, new Diff(expectedDOM, generatedDOM.getOwnerDocument()), true);
+ final Diff diff = DiffBuilder.compare(expectedDOM).withTest(generatedDOM.getOwnerDocument())
+ .ignoreWhitespace()
+ .checkForIdentical()
+ .build();
+ Assert.assertFalse(diff.hasDifferences(), failMessage);
} catch (Exception e) {
Assert.fail("Marshalling failed with the following error: " + e);
}
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/RoundTripTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/RoundTripTest.java
index 129987a..55fb9b2 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/RoundTripTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/RoundTripTest.java
@@ -17,9 +17,6 @@
package org.opensaml.saml.common;
-import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
-
-import org.custommonkey.xmlunit.Diff;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.core.xml.io.Marshaller;
@@ -30,9 +27,12 @@ import org.opensaml.saml.saml2.metadata.Organization;
import org.opensaml.saml.saml2.metadata.OrganizationDisplayName;
import org.opensaml.saml.saml2.metadata.OrganizationName;
import org.opensaml.saml.saml2.metadata.OrganizationURL;
+import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.w3c.dom.Element;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.Diff;
/**
* Round trip messaging test case.
@@ -94,24 +94,27 @@ public class RoundTripTest extends XMLObjectBaseTestCase {
public void testRoundTrip() throws MarshallingException, UnmarshallingException{
//Marshall the element
- Element orgElement1 = orgMarshaller.marshall(organization);
+ final Element orgElement1 = orgMarshaller.marshall(organization);
// Unmarshall it
- Organization org2 = (Organization) orgUnmarshaller.unmarshall(orgElement1);
+ final Organization org2 = (Organization) orgUnmarshaller.unmarshall(orgElement1);
// Drop DOM and remarshall
org2.releaseDOM();
org2.releaseChildrenDOM(true);
- Element orgElement2 = orgMarshaller.marshall(org2);
- XMLAssertTestNG.assertXMLIdentical(new Diff(orgElement1.getOwnerDocument(), orgElement2.getOwnerDocument()), true);
+ final Element orgElement2 = orgMarshaller.marshall(org2);
+
+ final Diff diff1 = DiffBuilder.compare(orgElement1).withTest(orgElement2).checkForIdentical().build();
+ Assert.assertFalse(diff1.hasDifferences(), diff1.toString());
// Unmarshall again
- Organization org3 = (Organization) orgUnmarshaller.unmarshall(orgElement2);
+ final Organization org3 = (Organization) orgUnmarshaller.unmarshall(orgElement2);
// Drop DOM and remarshall
org3.releaseDOM();
org3.releaseChildrenDOM(true);
- Element orgElement3 = orgMarshaller.marshall(org3);
- XMLAssertTestNG.assertXMLIdentical(new Diff(orgElement1.getOwnerDocument(), orgElement3.getOwnerDocument()), true);
+ final Element orgElement3 = orgMarshaller.marshall(org3);
+ final Diff diff2 = DiffBuilder.compare(orgElement1).withTest(orgElement3).checkForIdentical().build();
+ Assert.assertFalse(diff2.hasDifferences(), diff2.toString());
}
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/BasicSAMLArtifactMapTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/BasicSAMLArtifactMapTest.java
index 178d653..9b69cad 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/BasicSAMLArtifactMapTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/BasicSAMLArtifactMapTest.java
@@ -20,18 +20,16 @@ package org.opensaml.saml.common.binding.artifact.impl;
import java.io.IOException;
import java.time.Duration;
-import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
-
-import org.custommonkey.xmlunit.Diff;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
import org.opensaml.core.xml.io.MarshallingException;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.binding.artifact.SAMLArtifactMap.SAMLArtifactMapEntry;
-import org.opensaml.saml.common.binding.artifact.impl.BasicSAMLArtifactMap;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.Diff;
/**
* Test the storage-backed SAML artifact map implementation.
@@ -45,12 +43,12 @@ public class BasicSAMLArtifactMapTest extends XMLObjectBaseTestCase {
private String rpId = "urn:test:rp";
private SAMLObject samlObject;
- private Document origDocument;
+ private Element origElement;
@BeforeMethod
protected void setUp() throws Exception {
samlObject = (SAMLObject) unmarshallElement("/org/opensaml/saml/saml2/core/ResponseSuccessAuthnAttrib.xml");
- origDocument = samlObject.getDOM().getOwnerDocument();
+ origElement = samlObject.getDOM();
// Drop the DOM for a more realistic test, usually the artifact SAMLObject will be built, not unmarshalled
samlObject.releaseChildrenDOM(true);
samlObject.releaseDOM();
@@ -68,7 +66,7 @@ public class BasicSAMLArtifactMapTest extends XMLObjectBaseTestCase {
Assert.assertTrue(artifactMap.contains(artifact));
- SAMLArtifactMapEntry entry = artifactMap.get(artifact);
+ final SAMLArtifactMapEntry entry = artifactMap.get(artifact);
Assert.assertNotNull(entry);
Assert.assertEquals(entry.getArtifact(), artifact, "Invalid value for artifact");
@@ -76,10 +74,12 @@ public class BasicSAMLArtifactMapTest extends XMLObjectBaseTestCase {
Assert.assertEquals(entry.getRelyingPartyId(), rpId, "Invalid value for relying party ID");
// Test SAMLObject reconstitution
- SAMLObject retrievedObject = entry.getSamlMessage();
- Document newDocument =
- marshallerFactory.getMarshaller(retrievedObject).marshall(retrievedObject).getOwnerDocument();
- XMLAssertTestNG.assertXMLIdentical(new Diff(origDocument, newDocument), true);
+ final SAMLObject retrievedObject = entry.getSamlMessage();
+ final Element newElement =
+ marshallerFactory.getMarshaller(retrievedObject).marshall(retrievedObject);
+
+ final Diff diff = DiffBuilder.compare(origElement).withTest(newElement).checkForIdentical().ignoreWhitespace().build();
+ Assert.assertFalse(diff.hasDifferences(), diff.toString());
}
@Test
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/StorageServiceSAMLArtifactMapEntryFactoryTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/StorageServiceSAMLArtifactMapEntryFactoryTest.java
index 04c7b34..0a17527 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/StorageServiceSAMLArtifactMapEntryFactoryTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/StorageServiceSAMLArtifactMapEntryFactoryTest.java
@@ -19,20 +19,17 @@ package org.opensaml.saml.common.binding.artifact.impl;
import java.io.IOException;
-import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
-
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.Assert;
-import org.w3c.dom.Document;
-import org.custommonkey.xmlunit.Diff;
+import org.w3c.dom.Element;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.Diff;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
import org.opensaml.core.xml.io.MarshallingException;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.binding.artifact.BasicSAMLArtifactMapEntry;
import org.opensaml.saml.common.binding.artifact.SAMLArtifactMap.SAMLArtifactMapEntry;
-import org.opensaml.saml.common.binding.artifact.impl.StorageServiceSAMLArtifactMap;
-import org.opensaml.saml.common.binding.artifact.impl.StorageServiceSAMLArtifactMapEntryFactory;
import org.opensaml.saml.saml1.core.Assertion;
import org.opensaml.saml.saml1.core.Response;
@@ -75,21 +72,22 @@ public class StorageServiceSAMLArtifactMapEntryFactoryTest extends XMLObjectBase
@Test
public void testWithSerialization() throws IOException, MarshallingException {
- SAMLArtifactMapEntry entry = factory.newEntry(artifact, issuerId, rpId, samlObject);
- BasicSAMLArtifactMapEntry basicEntry = (BasicSAMLArtifactMapEntry) entry;
+ final SAMLArtifactMapEntry entry = factory.newEntry(artifact, issuerId, rpId, samlObject);
+ final BasicSAMLArtifactMapEntry basicEntry = (BasicSAMLArtifactMapEntry) entry;
- String s = factory.serialize(basicEntry);
- BasicSAMLArtifactMapEntry newEntry = (BasicSAMLArtifactMapEntry) factory.deserialize(
+ final String s = factory.serialize(basicEntry);
+ final BasicSAMLArtifactMapEntry newEntry = (BasicSAMLArtifactMapEntry) factory.deserialize(
1, StorageServiceSAMLArtifactMap.STORAGE_CONTEXT, basicEntry.getArtifact(), s, null);
Assert.assertEquals(basicEntry.getArtifact(), newEntry.getArtifact());
Assert.assertEquals(basicEntry.getIssuerId(), newEntry.getIssuerId());
Assert.assertEquals(basicEntry.getRelyingPartyId(), newEntry.getRelyingPartyId());
- Document origDocument = samlObject.getDOM().getOwnerDocument();
- origDocument.appendChild(samlObject.getDOM());
- Document newDocument = newEntry.getSamlMessage().getDOM().getOwnerDocument();
- XMLAssertTestNG.assertXMLIdentical(new Diff(origDocument, newDocument), true);
+ final Element origElement = samlObject.getDOM();
+ final Element newElement = newEntry.getSamlMessage().getDOM();
+
+ final Diff diff = DiffBuilder.compare(origElement).withTest(newElement).checkForIdentical().ignoreWhitespace().build();
+ Assert.assertFalse(diff.hasDifferences(), diff.toString());
}
}
\ No newline at end of file
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/StorageServiceSAMLArtifactMapTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/StorageServiceSAMLArtifactMapTest.java
index 38147f2..ea5bd70 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/StorageServiceSAMLArtifactMapTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/artifact/impl/StorageServiceSAMLArtifactMapTest.java
@@ -20,19 +20,17 @@ package org.opensaml.saml.common.binding.artifact.impl;
import java.io.IOException;
import java.time.Duration;
-import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
-
-import org.custommonkey.xmlunit.Diff;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
import org.opensaml.core.xml.io.MarshallingException;
import org.opensaml.saml.common.SAMLObject;
import org.opensaml.saml.common.binding.artifact.SAMLArtifactMap.SAMLArtifactMapEntry;
-import org.opensaml.saml.common.binding.artifact.impl.StorageServiceSAMLArtifactMap;
import org.opensaml.storage.impl.MemoryStorageService;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.Diff;
/**
* Test the storage-backed SAML artifact map implementation.
@@ -47,12 +45,12 @@ public class StorageServiceSAMLArtifactMapTest extends XMLObjectBaseTestCase {
private String rpId = "urn:test:rp";
private SAMLObject samlObject;
- private Document origDocument;
+ private Element origElement;
@BeforeMethod
protected void setUp() throws Exception {
samlObject = (SAMLObject) unmarshallElement("/org/opensaml/saml/saml2/core/ResponseSuccessAuthnAttrib.xml");
- origDocument = samlObject.getDOM().getOwnerDocument();
+ origElement = samlObject.getDOM();
// Drop the DOM for a more realistic test, usually the artifact SAMLObject will be built, not unmarshalled
samlObject.releaseChildrenDOM(true);
samlObject.releaseDOM();
@@ -75,7 +73,7 @@ public class StorageServiceSAMLArtifactMapTest extends XMLObjectBaseTestCase {
Assert.assertTrue(artifactMap.contains(artifact));
- SAMLArtifactMapEntry entry = artifactMap.get(artifact);
+ final SAMLArtifactMapEntry entry = artifactMap.get(artifact);
Assert.assertNotNull(entry);
Assert.assertEquals(entry.getArtifact(), artifact, "Invalid value for artifact");
@@ -83,10 +81,12 @@ public class StorageServiceSAMLArtifactMapTest extends XMLObjectBaseTestCase {
Assert.assertEquals(entry.getRelyingPartyId(), rpId, "Invalid value for relying party ID");
// Test SAMLObject reconstitution
- SAMLObject retrievedObject = entry.getSamlMessage();
- Document newDocument =
- marshallerFactory.getMarshaller(retrievedObject).marshall(retrievedObject).getOwnerDocument();
- XMLAssertTestNG.assertXMLIdentical(new Diff(origDocument, newDocument), true);
+ final SAMLObject retrievedObject = entry.getSamlMessage();
+ final Element newElement =
+ marshallerFactory.getMarshaller(retrievedObject).marshall(retrievedObject);
+
+ final Diff diff = DiffBuilder.compare(origElement).withTest(newElement).checkForIdentical().ignoreWhitespace().build();
+ Assert.assertFalse(diff.hasDifferences(), diff.toString());
}
@Test
diff --git a/opensaml-soap-impl/src/test/java/org/opensaml/soap/WSBaseTestCase.java b/opensaml-soap-impl/src/test/java/org/opensaml/soap/WSBaseTestCase.java
index 433cdb1..c6af884 100644
--- a/opensaml-soap-impl/src/test/java/org/opensaml/soap/WSBaseTestCase.java
+++ b/opensaml-soap-impl/src/test/java/org/opensaml/soap/WSBaseTestCase.java
@@ -21,15 +21,13 @@ package org.opensaml.soap;
import org.testng.Assert;
import javax.xml.namespace.QName;
-import net.shibboleth.utilities.java.support.xml.SerializeSupport;
-
-import org.custommonkey.xmlunit.Diff;
-import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
import org.opensaml.core.xml.io.Marshaller;
import org.opensaml.core.xml.io.Unmarshaller;
import org.w3c.dom.Element;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.Diff;
/**
* WSBaseTestCase is the base test case for the WS-* packages.
@@ -50,7 +48,7 @@ public abstract class WSBaseTestCase extends XMLObjectBaseTestCase {
Element element= marshaller.marshall(object);
Assert.assertNotNull(element);
- System.out.println(SerializeSupport.nodeToString(element));
+ //System.out.println(SerializeSupport.nodeToString(element));
T object2= (T) unmarshaller.unmarshall(element);
Assert.assertNotNull(object2);
@@ -64,14 +62,15 @@ public abstract class WSBaseTestCase extends XMLObjectBaseTestCase {
Element element2= marshaller.marshall(object2);
Assert.assertNotNull(element2);
- System.out.println(SerializeSupport.nodeToString(element2));
+ //System.out.println(SerializeSupport.nodeToString(element2));
// These need to be false, otherwise the test below is invalid
//System.out.println("Element equals: " + element.isSameNode(element2));
//System.out.println("Document equals: " + element.getOwnerDocument().isSameNode(element2.getOwnerDocument()));
// compare XML content
- XMLAssertTestNG.assertXMLIdentical(new Diff(element.getOwnerDocument(), element2.getOwnerDocument()), true);
+ final Diff diff = DiffBuilder.compare(element).withTest(element2).checkForIdentical().build();
+ Assert.assertFalse(diff.hasDifferences(), diff.toString());
return object2;
diff --git a/opensaml-soap-impl/src/test/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11EncoderTest.java b/opensaml-soap-impl/src/test/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11EncoderTest.java
index 0341a22..27f0406 100644
--- a/opensaml-soap-impl/src/test/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11EncoderTest.java
+++ b/opensaml-soap-impl/src/test/java/org/opensaml/soap/soap11/encoder/http/impl/HTTPSOAP11EncoderTest.java
@@ -24,10 +24,8 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
import net.shibboleth.utilities.java.support.xml.XMLParserException;
-import org.custommonkey.xmlunit.Diff;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.XMLObjectBaseTestCase;
import org.opensaml.core.xml.XMLObjectBuilder;
@@ -44,7 +42,6 @@ import org.opensaml.soap.soap11.Fault;
import org.opensaml.soap.soap11.FaultCode;
import org.opensaml.soap.soap11.FaultString;
import org.opensaml.soap.soap11.Header;
-import org.opensaml.soap.soap11.encoder.http.impl.HTTPSOAP11Encoder;
import org.opensaml.soap.util.SOAPSupport;
import org.opensaml.soap.wsaddressing.Action;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -52,6 +49,8 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.Diff;
/**
* Test basic SOAP 1.1 message encoding.
@@ -101,7 +100,11 @@ public class HTTPSOAP11EncoderTest extends XMLObjectBaseTestCase {
String soapMessage = "/org/opensaml/soap/soap11/SOAPNoHeaders.xml";
Envelope controlEnv = (Envelope) parseUnmarshallResource(soapMessage, false);
- XMLAssertTestNG.assertXMLIdentical(new Diff(controlEnv.getDOM().getOwnerDocument(), encodedEnv.getDOM().getOwnerDocument()), true);
+ final Diff diff = DiffBuilder.compare(controlEnv.getDOM()).withTest(encodedEnv.getDOM())
+ .checkForIdentical()
+ .ignoreWhitespace()
+ .build();
+ Assert.assertFalse(diff.hasDifferences(), diff.toString());
}
/**
@@ -154,7 +157,11 @@ public class HTTPSOAP11EncoderTest extends XMLObjectBaseTestCase {
String soapMessage = "/org/opensaml/soap/soap11/SOAPNoHeaders.xml";
Envelope controlEnv = (Envelope) parseUnmarshallResource(soapMessage, false);
- XMLAssertTestNG.assertXMLIdentical(new Diff(controlEnv.getDOM().getOwnerDocument(), encodedEnv.getDOM().getOwnerDocument()), true);
+ final Diff diff = DiffBuilder.compare(controlEnv.getDOM()).withTest(encodedEnv.getDOM())
+ .checkForIdentical()
+ .ignoreWhitespace()
+ .build();
+ Assert.assertFalse(diff.hasDifferences(), diff.toString());
}
/**
@@ -212,7 +219,11 @@ public class HTTPSOAP11EncoderTest extends XMLObjectBaseTestCase {
String soapMessage = "/org/opensaml/soap/soap11/SOAPHeaderMustUnderstand.xml";
Envelope controlEnv = (Envelope) parseUnmarshallResource(soapMessage, false);
- XMLAssertTestNG.assertXMLIdentical(new Diff(controlEnv.getDOM().getOwnerDocument(), encodedEnv.getDOM().getOwnerDocument()), true);
+ final Diff diff = DiffBuilder.compare(controlEnv.getDOM()).withTest(encodedEnv.getDOM())
+ .checkForIdentical()
+ .ignoreWhitespace()
+ .build();
+ Assert.assertFalse(diff.hasDifferences(), diff.toString());
}
/**
diff --git a/opensaml-soap-impl/src/test/java/org/opensaml/soap/wssecurity/impl/WSSecurityObjectsTestCase.java b/opensaml-soap-impl/src/test/java/org/opensaml/soap/wssecurity/impl/WSSecurityObjectsTestCase.java
index 957cffd..205fdff 100644
--- a/opensaml-soap-impl/src/test/java/org/opensaml/soap/wssecurity/impl/WSSecurityObjectsTestCase.java
+++ b/opensaml-soap-impl/src/test/java/org/opensaml/soap/wssecurity/impl/WSSecurityObjectsTestCase.java
@@ -24,8 +24,6 @@ import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
-import org.custommonkey.xmlunit.Diff;
-import net.shibboleth.utilities.java.support.xml.XMLAssertTestNG;
import org.opensaml.core.xml.XMLObject;
import org.opensaml.core.xml.io.Marshaller;
import org.opensaml.soap.WSBaseTestCase;
@@ -46,6 +44,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.xmlunit.builder.DiffBuilder;
+import org.xmlunit.diff.Diff;
/**
* WSSecurityObjectsTestCase is the base test case for the WS-Security
@@ -204,18 +204,18 @@ public class WSSecurityObjectsTestCase extends WSBaseTestCase {
String refId= "UsernameToken-007";
String refDateTimeStr= "2007-12-19T09:53:08.335Z";
- UsernameToken usernameToken= createUsernameToken("test", "test");
+ final UsernameToken usernameToken= createUsernameToken("test", "test");
usernameToken.setWSUId(refId);
- Instant refDateTime= Instant.parse(refDateTimeStr);
- Created usernameCreated = (Created) usernameToken.getUnknownXMLObjects(Created.ELEMENT_NAME).get(0);
+ final Instant refDateTime= Instant.parse(refDateTimeStr);
+ final Created usernameCreated = (Created) usernameToken.getUnknownXMLObjects(Created.ELEMENT_NAME).get(0);
usernameCreated.setDateTime(refDateTime);
// check default password type
- Password password= (Password) usernameToken.getUnknownXMLObjects(Password.ELEMENT_NAME).get(0);
+ final Password password= (Password) usernameToken.getUnknownXMLObjects(Password.ELEMENT_NAME).get(0);
Assert.assertNotNull(password);
Assert.assertEquals(password.getType(), Password.TYPE_PASSWORD_TEXT);
- List<XMLObject> children= usernameToken.getOrderedChildren();
+ final List<XMLObject> children= usernameToken.getOrderedChildren();
Assert.assertEquals(children.size(), 3);
marshallAndUnmarshall(usernameToken);
@@ -225,25 +225,25 @@ public class WSSecurityObjectsTestCase extends WSBaseTestCase {
// unmarshallXML("/data/usernametoken.xml");
// Document refDocument= refUsernameToken.getDOM().getOwnerDocument();
// refUsernameToken.releaseDOM();
- Document refDocument= parseXMLDocument("/org/opensaml/soap/wssecurity/impl/UsernameToken.xml");
+ final Element refElement = parseXMLDocument("/org/opensaml/soap/wssecurity/impl/UsernameToken.xml").getDocumentElement();
//System.out.println("XXX: " + XMLHelper.nodeToString(refDocument.getDocumentElement()));
- Marshaller marshaller= getMarshaller(usernameToken);
- Element element= marshaller.marshall(usernameToken);
- Document document= element.getOwnerDocument();
-
+ final Marshaller marshaller= getMarshaller(usernameToken);
+ final Element element= marshaller.marshall(usernameToken);
+
// compare with XMLUnit
- XMLAssertTestNG.assertXMLIdentical(new Diff(refDocument, document), true);
+ final Diff diff = DiffBuilder.compare(refElement).withTest(element).checkForIdentical().ignoreWhitespace().build();
+ Assert.assertFalse(diff.hasDifferences(), diff.toString());
// unmarshall directly from file
- UsernameToken ut= unmarshallElement("/org/opensaml/soap/wssecurity/impl/UsernameToken.xml");
+ final UsernameToken ut= unmarshallElement("/org/opensaml/soap/wssecurity/impl/UsernameToken.xml");
Assert.assertEquals(ut.getUsername().getValue(), "test");
- Password utPassword = (Password) ut.getUnknownXMLObjects(Password.ELEMENT_NAME).get(0);
+ final Password utPassword = (Password) ut.getUnknownXMLObjects(Password.ELEMENT_NAME).get(0);
Assert.assertNotNull(utPassword);
Assert.assertEquals(utPassword.getValue(), "test");
- Created utCreated = (Created) ut.getUnknownXMLObjects(Created.ELEMENT_NAME).get(0);
+ final Created utCreated = (Created) ut.getUnknownXMLObjects(Created.ELEMENT_NAME).get(0);
Assert.assertNotNull(utCreated);
- Instant created= utCreated.getDateTime();
+ final Instant created= utCreated.getDateTime();
System.out.println(created);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list