This is an automated email from the ASF dual-hosted git repository. jamesbognar pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push: new 26d1910 Tests. 26d1910 is described below commit 26d191052206458efb904d337cf1aab17408bb7a Author: JamesBognar <james.bog...@salesforce.com> AuthorDate: Thu Jun 25 14:59:14 2020 -0400 Tests. --- .../a/rttests/RoundTripBeanInheritanceTest.java | 6 +- .../apache/juneau/a/rttests/RoundTripDTOsTest.java | 6 +- .../apache/juneau/a/rttests/RoundTripEnumTest.java | 5 +- .../juneau/a/rttests/RoundTripTrimStringsTest.java | 18 +++--- .../java/org/apache/juneau/dto/atom/AtomTest.java | 10 ++-- .../apache/juneau/dto/cognos/CognosXmlTest.java | 4 +- .../java/org/apache/juneau/html/CommonTest.java | 12 ++-- .../java/org/apache/juneau/jena/CommonTest.java | 16 +++--- .../java/org/apache/juneau/jena/CommonXmlTest.java | 6 +- .../java/org/apache/juneau/jena/RdfParserTest.java | 3 +- .../test/java/org/apache/juneau/jena/RdfTest.java | 11 ++-- .../java/org/apache/juneau/json/CommonTest.java | 12 ++-- .../java/org/apache/juneau/oapi/OpenApiTest.java | 64 +++++++++++----------- .../org/apache/juneau/testutils/TestUtils.java | 8 --- .../java/org/apache/juneau/uon/Common_UonTest.java | 12 ++-- .../juneau/urlencoding/Common_UrlEncodingTest.java | 12 ++-- .../java/org/apache/juneau/xml/CommonTest.java | 12 ++-- .../org/apache/juneau/xml/XmlCollapsedTest.java | 11 ++-- .../java/org/apache/juneau/xml/XmlContentTest.java | 46 ++++++++-------- .../apache/juneau/xml/XmlIgnoreCommentsTest.java | 10 ++-- .../juneau/assertions/FluentObjectAssertion.java | 56 ++++++++++++++++++- .../juneau/rest/client2/RestClient_Test.java | 19 ++++--- 22 files changed, 205 insertions(+), 154 deletions(-) diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java index 456cd9c..2c88f15 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java @@ -12,7 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.a.rttests; -import static org.apache.juneau.testutils.TestUtils.*; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.junit.runners.MethodSorters.*; import org.apache.juneau.parser.*; @@ -43,7 +43,7 @@ public class RoundTripBeanInheritanceTest extends RoundTripTest { A2 t1 = new A2(), t2; t1.init(); t2 = roundTrip(t1, A2.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); A3 t3 = new A3(); t3.init(); @@ -145,7 +145,7 @@ public class RoundTripBeanInheritanceTest extends RoundTripTest { public void testBeanInheritance2() throws Exception { B1 t1 = new B1().init(), t2; t2 = roundTrip(t1, B1.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); } public static class B1 extends B2 { diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripDTOsTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripDTOsTest.java index f10ff06..b3cb18d 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripDTOsTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripDTOsTest.java @@ -12,7 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.a.rttests; -import static org.apache.juneau.testutils.TestUtils.*; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.junit.runners.MethodSorters.*; import org.apache.juneau.dto.jsonschema.*; @@ -38,13 +38,13 @@ public class RoundTripDTOsTest extends RoundTripTest { public void testJsonSchema1() throws Exception { JsonSchema s = JsonSchemaTest.getTest1(); JsonSchema s2 = roundTrip(s, JsonSchema.class); - assertEqualObjects(s, s2); + assertObject(s).jsonSameAs(s2); } @Test public void testJsonSchema2() throws Exception { JsonSchema s = JsonSchemaTest.getTest2(); JsonSchema s2 = roundTrip(s, JsonSchema.class); - assertEqualObjects(s, s2); + assertObject(s).jsonSameAs(s2); } } diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripEnumTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripEnumTest.java index cf119dc..9d38da3 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripEnumTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripEnumTest.java @@ -12,6 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.a.rttests; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.testutils.TestUtils.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; @@ -110,7 +111,7 @@ public class RoundTripEnumTest extends RoundTripTest { public void testBeansWithEnumA() throws Exception { A t1 = new A().init(), t2; t2 = roundTrip(t1, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); assertEquals(AEnum.FOO, t2.f3[0]); assertNull(t2.f3[1]); assertEquals(AEnum.FOO, t2.f4[0][0]); @@ -122,7 +123,7 @@ public class RoundTripEnumTest extends RoundTripTest { public void testBeansWithEnumB() throws Exception { B t1 = new B().init(), t2; t2 = roundTrip(t1, B.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); assertEquals(BEnum.FOO, t2.f3[0]); assertNull(t2.f3[1]); assertEquals(BEnum.FOO, t2.f4[0][0]); diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTrimStringsTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTrimStringsTest.java index bc42092..30c5db9 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTrimStringsTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/a/rttests/RoundTripTrimStringsTest.java @@ -12,7 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.a.rttests; -import static org.apache.juneau.testutils.TestUtils.*; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.junit.runners.MethodSorters.*; import org.apache.juneau.collections.*; @@ -47,30 +47,30 @@ public class RoundTripTrimStringsTest extends RoundTripTest { in = " foo bar "; e = "foo bar"; a = p.parse(s2.serialize(in), String.class); - assertEqualObjects(e, a); + assertObject(e).jsonSameAs(a); a = p2.parse(s.serialize(in), String.class); - assertEqualObjects(e, a); + assertObject(e).jsonSameAs(a); in = OMap.ofJson("{' foo ': ' bar '}"); e = OMap.ofJson("{foo:'bar'}"); a = p.parse(s2.serialize(in), OMap.class); - assertEqualObjects(e, a); + assertObject(e).jsonSameAs(a); a = p2.parse(s.serialize(in), OMap.class); - assertEqualObjects(e, a); + assertObject(e).jsonSameAs(a); in = new OList("[' foo ', {' foo ': ' bar '}]"); e = new OList("['foo',{foo:'bar'}]"); a = p.parse(s2.serialize(in), OList.class); - assertEqualObjects(e, a); + assertObject(e).jsonSameAs(a); a = p2.parse(s.serialize(in), OList.class); - assertEqualObjects(e, a); + assertObject(e).jsonSameAs(a); in = new A().init1(); e = new A().init2(); a = p.parse(s2.serialize(in), A.class); - assertEqualObjects(e, a); + assertObject(e).jsonSameAs(a); a = p2.parse(s.serialize(in), A.class); - assertEqualObjects(e, a); + assertObject(e).jsonSameAs(a); } public static class A { diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/dto/atom/AtomTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/dto/atom/AtomTest.java index 78c5443..86fa4c9 100644 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/dto/atom/AtomTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/dto/atom/AtomTest.java @@ -12,8 +12,8 @@ // *************************************************************************************************************************** package org.apache.juneau.dto.atom; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.dto.atom.AtomBuilder.*; -import static org.apache.juneau.testutils.TestUtils.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; @@ -101,7 +101,7 @@ public class AtomTest { r = s.serialize(f); assertEquals(expected, r); f2 = p.parse(r, Feed.class); - assertEqualObjects(f, f2); + assertObject(f).jsonSameAs(f2); } @Test @@ -146,7 +146,7 @@ public class AtomTest { r = s.serialize(f); assertEquals(expected, r); f2 = p.parse(r, Feed.class); - assertEqualObjects(f, f2); + assertObject(f).jsonSameAs(f2); } @Test @@ -191,7 +191,7 @@ public class AtomTest { r = s.serialize(f); assertEquals(expected, r); f2 = p.parse(r, Feed.class); - assertEqualObjects(f, f2); + assertObject(f).jsonSameAs(f2); } @Test @@ -201,6 +201,6 @@ public class AtomTest { Feed f = createFeed(), f2; r = f.toString(); f2 = p.parse(r, Feed.class); - assertEqualObjects(f, f2); + assertObject(f).jsonSameAs(f2); } } diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/dto/cognos/CognosXmlTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/dto/cognos/CognosXmlTest.java index bc411c8..1a5f5e4 100644 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/dto/cognos/CognosXmlTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/dto/cognos/CognosXmlTest.java @@ -12,7 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.dto.cognos; -import static org.apache.juneau.testutils.TestUtils.*; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; @@ -90,7 +90,7 @@ public class CognosXmlTest { // Make sure we can parse it back into a POJO. DataSet ds2 = XmlParser.DEFAULT.parse(out, DataSet.class); - assertEqualObjects(ds, ds2); + assertObject(ds).jsonSameAs(ds2); } public static class Item { diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/html/CommonTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/html/CommonTest.java index 0946947..d5fa370 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/html/CommonTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/html/CommonTest.java @@ -12,9 +12,9 @@ // *************************************************************************************************************************** package org.apache.juneau.html; -import static org.apache.juneau.testutils.TestUtils.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.assertions.ThrowableAssertion.*; import java.net.*; @@ -43,13 +43,13 @@ public class CommonTest { String r = s.build().serialize(t1); assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>s1</td><td><null/></td></tr><tr><td>s2</td><td>s2</td></tr></table>", r); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s = HtmlSerializer.create().sq().addKeyValueTableHeaders(); r = s.build().serialize(t1); assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>s2</td><td>s2</td></tr></table>", r); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); } public static class A { @@ -75,7 +75,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>f1</td><td><table><tr><th>key</th><th>value</th></tr></table></td></tr><tr><td>f2</td><td><table><tr><th>key</th><th>value</th></tr><tr><td>f2a</td><td><null/></td></tr><tr><td>f2b</td><td><table><tr><th>key</th><th>value</th></tr><tr><td>s2</td><td>s2</td></tr></table></td></tr></table></td></tr></table>", r); t2 = p.parse(r, B.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyMaps(); r = s.build().serialize(t1); @@ -108,7 +108,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("<table><tr><th>key</th><th>value</th></tr><tr><td>f1</td><td><ul></ul></td></tr><tr><td>f2</td><td><table _type='array'><tr><th>s1</th><th>s2</th></tr><tr><null/></tr><tr><td><null/></td><td>s2</td></tr></table></td></tr></table>", r); t2 = p.parse(r, C.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); @@ -160,7 +160,7 @@ public class CommonTest { r); t2 = p.parse(r, D.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/CommonTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/CommonTest.java index 9c05663..af3113c 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/CommonTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/CommonTest.java @@ -12,10 +12,10 @@ // *************************************************************************************************************************** package org.apache.juneau.jena; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.assertions.StringAssertion.*; import static org.apache.juneau.assertions.ThrowableAssertion.*; import static org.apache.juneau.jena.RdfCommon.*; -import static org.apache.juneau.testutils.TestUtils.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; @@ -56,13 +56,13 @@ public class CommonTest { String r = s.build().serialize(t1); assertEquals("<rdf:Description><jp:s2>s2</jp:s2></rdf:Description>", strip(r)); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.keepNullProperties(); r = s.build().serialize(t1); assertEquals("<rdf:Description><jp:s1 rdf:resource='http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'/><jp:s2>s2</jp:s2></rdf:Description>", strip(r)); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); } public static class A { @@ -88,7 +88,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("<rdf:Description><jp:f1 rdf:parseType='Resource'></jp:f1><jp:f2 rdf:parseType='Resource'><jp:f2a rdf:resource='http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'/><jp:f2b rdf:parseType='Resource'><jp:s2>s2</jp:s2></jp:f2b></jp:f2></rdf:Description>", strip(r)); t2 = p.parse(r, B.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyMaps(); r = s.build().serialize(t1); @@ -121,7 +121,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("<rdf:Description><jp:f1><rdf:Seq/></jp:f1><jp:f2><rdf:Seq><rdf:li rdf:resource='http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'/><rdf:li rdf:parseType='Resource'><jp:s2>s2</jp:s2></rdf:li></rdf:Seq></jp:f2></rdf:Description>", strip(r)); t2 = p.parse(r, C.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); @@ -155,7 +155,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("<rdf:Description><jp:f1><rdf:Seq/></jp:f1><jp:f2><rdf:Seq><rdf:li rdf:resource='http://www.w3.org/1999/02/22-rdf-syntax-ns#nil'/><rdf:li rdf:parseType='Resource'><jp:s2>s2</jp:s2></rdf:li></rdf:Seq></jp:f2></rdf:Description>", strip(r)); t2 = p.parse(r, D.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); @@ -188,7 +188,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("<rdf:Description><jp:x1 rdf:parseType='Resource'><jp:f1>1</jp:f1></jp:x1><jp:x2 rdf:parseType='Resource'><jp:f1>1</jp:f1></jp:x2><jp:x3><rdf:Seq><rdf:li rdf:parseType='Resource'><jp:f1>1</jp:f1></rdf:li></rdf:Seq></jp:x3><jp:x4><rdf:Seq><rdf:li rdf:parseType='Resource'><jp:f1>1</jp:f1></rdf:li></rdf:Seq></jp:x4><jp:x5><rdf:Seq><rdf:li rdf:parseType='Resource'><jp:f1>1</jp:f1></rdf:li></rdf:Seq></jp:x5><jp:x6><rdf:Seq><rdf:li rdf:parseType='Resource'><jp:f1>1</jp:f1></rdf: [...] t2 = p.parse(r, E1.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); } public static class E1 { @@ -231,7 +231,7 @@ public class CommonTest { String r = s.build().serialize(l1); assertEquals("<rdf:Seq><rdf:li rdf:parseType='Resource'><jp:x1><rdf:Seq><rdf:li rdf:parseType='Resource'><jp:x2>2</jp:x2></rdf:li></rdf:Seq></jp:x1><jp:x2>2</jp:x2></rdf:li></rdf:Seq>", strip(r)); l2 = p.parse(r, LinkedList.class, F.class); - assertEqualObjects(l1, l2); + assertObject(l1).jsonSameAs(l2); } public static class F { diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/CommonXmlTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/CommonXmlTest.java index 0ea18bb..3d36931 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/CommonXmlTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/CommonXmlTest.java @@ -12,8 +12,8 @@ // *************************************************************************************************************************** package org.apache.juneau.jena; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.jena.RdfCommon.*; -import static org.apache.juneau.testutils.TestUtils.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; @@ -51,7 +51,7 @@ public class CommonXmlTest { r = s.build().serialize(t1); assertEquals("<rdf:Description rdf:about='http://foo'><jp:name>bar</jp:name></rdf:Description>", strip(r)); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); } public static class A { @@ -79,7 +79,7 @@ public class CommonXmlTest { r = s.build().serialize(t1); assertEquals("<rdf:Description rdf:about='http://foo'><jp:url2 rdf:resource='http://foo/2'/></rdf:Description>", strip(r)); t2 = p.parse(r, B.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); } public static class B { diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/RdfParserTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/RdfParserTest.java index fd99a47..45a5087 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/RdfParserTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/RdfParserTest.java @@ -12,6 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.jena; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.jena.RdfCommon.*; import static org.apache.juneau.testutils.TestUtils.*; import static org.junit.Assert.*; @@ -82,7 +83,7 @@ public class RdfParserTest { A a2 = RdfXmlParser.DEFAULT.parse(rdfXml, A.class); - assertEqualObjects(a, a2); + assertObject(a).jsonSameAs(a2); OMap m = RdfXmlParser.DEFAULT.parse(rdfXml, OMap.class); String json = SimpleJsonSerializer.DEFAULT_READABLE.serialize(m); diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/RdfTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/RdfTest.java index 0ad2020..68415cf 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/RdfTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/jena/RdfTest.java @@ -12,6 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.jena; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.jena.RdfCommon.*; import static org.apache.juneau.testutils.TestUtils.*; import static org.junit.runners.MethodSorters.*; @@ -65,7 +66,7 @@ public class RdfTest { assertXmlEquals(expected, rdfXml); a2 = p.parse(rdfXml, A.class); - assertEqualObjects(a, a2); + assertObject(a).jsonSameAs(a2); //------------------------------------------------------------------------------------------------------------- // Explicit sequence @@ -93,7 +94,7 @@ public class RdfTest { assertXmlEquals(expected, rdfXml); a2 = p.parse(rdfXml, A.class); - assertEqualObjects(a, a2); + assertObject(a).jsonSameAs(a2); //------------------------------------------------------------------------------------------------------------- // Bag @@ -121,7 +122,7 @@ public class RdfTest { assertXmlEquals(expected, rdfXml); a2 = p.parse(rdfXml, A.class); - assertEqualObjects(a, a2); + assertObject(a).jsonSameAs(a2); //------------------------------------------------------------------------------------------------------------- // List @@ -151,7 +152,7 @@ public class RdfTest { assertXmlEquals(expected, rdfXml); a2 = p.parse(rdfXml, A.class); - assertEqualObjects(a, a2); + assertObject(a).jsonSameAs(a2); //------------------------------------------------------------------------------------------------------------- // Multi-properties @@ -173,7 +174,7 @@ public class RdfTest { // Note - Must specify collection format on parser for it to be able to understand this layout. p = RdfParser.create().xml().collectionFormat(RdfCollectionFormat.MULTI_VALUED).build(); a2 = p.parse(rdfXml, A.class); - assertEqualObjects(a, a2); + assertObject(a).jsonSameAs(a2); } @Rdf(prefix="a", namespace="http://ns/") diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/json/CommonTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/json/CommonTest.java index 86f87a3..4a192ea 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/json/CommonTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/json/CommonTest.java @@ -12,8 +12,8 @@ // *************************************************************************************************************************** package org.apache.juneau.json; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.assertions.ThrowableAssertion.*; -import static org.apache.juneau.testutils.TestUtils.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; @@ -41,13 +41,13 @@ public class CommonTest { String r = s.build().serialize(t1); assertEquals("{s2:'s2'}", r); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.keepNullProperties(); r = s.build().serialize(t1); assertEquals("{s1:null,s2:'s2'}", r); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); } public static class A { @@ -73,7 +73,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("{f1:{},f2:{f2a:null,f2b:{s2:'s2'}}}", r); t2 = p.parse(r, B.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyMaps(); r = s.build().serialize(t1); @@ -106,7 +106,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("{f1:[],f2:[null,{s2:'s2'}]}", r); t2 = p.parse(r, C.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); @@ -139,7 +139,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("{f1:[],f2:[null,{s2:'s2'}]}", r); t2 = p.parse(r, D.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/oapi/OpenApiTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/oapi/OpenApiTest.java index 800789d..5adcf9b 100644 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/oapi/OpenApiTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/oapi/OpenApiTest.java @@ -14,7 +14,7 @@ package org.apache.juneau.oapi; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; -import static org.apache.juneau.testutils.TestUtils.*; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.httppart.HttpPartSchema.*; import java.time.*; @@ -656,13 +656,13 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("123", s); int[] r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); in = new int[]{123,456}; s = serialize(ps, in); assertEquals("123,456", s); r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -676,14 +676,14 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("123", s); int[][][] r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); int[][][] in2 = {{{1,2},{3,4}},{{5,6},{7,8}}}; in = in2; s = serialize(ps, in); assertEquals("1\\\\\\,2\\,3\\\\\\,4,5\\\\\\,6\\,7\\\\\\,8", s); r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @@ -707,13 +707,13 @@ public class OpenApiTest { SimpleJson.DEFAULT.println(in); assertEquals("a", s); F04 r = parse(ps, s, F04.class); - assertEqualObjects(in.toStringArray(), r.toStringArray()); + assertObject(in.toStringArray()).jsonSameAs(r.toStringArray()); in = new F04("a","b"); s = serialize(ps, in); assertEquals("a,b", s); r = parse(ps, s, F04.class); - assertEqualObjects(in.toStringArray(), r.toStringArray()); + assertObject(in.toStringArray()).jsonSameAs(r.toStringArray()); } @Test @@ -723,13 +723,13 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("@(123)", s); int[] r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); in = new int[]{123,456}; s = serialize(ps, in); assertEquals("@(123,456)", s); r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -739,14 +739,14 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("@(@(@(123)))", s); int[][][] r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); int[][][] in2 = {{{1,2},{3,4}},{{5,6},{7,8}}}; in = in2; s = serialize(ps, in); assertEquals("@(@(@(1,2),@(3,4)),@(@(5,6),@(7,8)))", s); r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -756,13 +756,13 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("123", s); int[] r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); in = new int[]{123,456}; s = serialize(ps, in); assertEquals("123|456", s); r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -772,14 +772,14 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("123", s); int[][][] r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); int[][][] in2 = {{{1,2},{3,4}},{{5,6},{7,8}}}; in = in2; s = serialize(ps, in); assertEquals("1\\\\,2,3\\\\,4|5\\\\,6,7\\\\,8", s); r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -789,13 +789,13 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("123", s); int[] r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); in = new int[]{123,456}; s = serialize(ps, in); assertEquals("123 456", s); r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -805,14 +805,14 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("123", s); int[][][] r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); int[][][] in2 = {{{1,2},{3,4}},{{5,6},{7,8}}}; in = in2; s = serialize(ps, in); assertEquals("1\\,2,3\\,4 5\\,6,7\\,8", s); r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -822,13 +822,13 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("123", s); int[] r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); in = new int[]{123,456}; s = serialize(ps, in); assertEquals("123\t456", s); r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -838,14 +838,14 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("123", s); int[][][] r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); int[][][] in2 = {{{1,2},{3,4}},{{5,6},{7,8}}}; in = in2; s = serialize(ps, in); assertEquals("1\\,2,3\\,4\t5\\,6,7\\,8", s); r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -855,13 +855,13 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("123", s); int[] r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); in = new int[]{123,456}; s = serialize(ps, in); assertEquals("123,456", s); r = parse(ps, s, int[].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -871,14 +871,14 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("123", s); int[][][] r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); int[][][] in2 = {{{1,2},{3,4}},{{5,6},{7,8}}}; in = in2; s = serialize(ps, in); assertEquals("1\\\\\\,2\\,3\\\\\\,4,5\\\\\\,6\\,7\\\\\\,8", s); r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @@ -893,7 +893,7 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("1 2|3 4,5 6|7 8", s); int[][][] r = parse(ps, s, int[][][].class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } //------------------------------------------------------------------------------------------------------------------ @@ -907,13 +907,13 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("a=b", s); OMap r = parse(ps, s, OMap.class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); in = OMap.of("a","b","c","d"); s = serialize(ps, in); assertEquals("a=b,c=d", s); r = parse(ps, s, OMap.class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } @Test @@ -928,12 +928,12 @@ public class OpenApiTest { String s = serialize(ps, in); assertEquals("a=b\\=c\\\\\\=d", s); OMap r = parse(ps, s, OMap.class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); in = OMap.of("a",OMap.of("b",OMap.of("c","d"),"e",OMap.of("f","g"))); s = serialize(ps, in); assertEquals("a=b\\=c\\\\\\=d\\,e\\=f\\\\\\=g", s); r = parse(ps, s, OMap.class); - assertEqualObjects(in, r); + assertObject(in).jsonSameAs(r); } } diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/testutils/TestUtils.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/testutils/TestUtils.java index 307df95..9f0c365 100644 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/testutils/TestUtils.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/testutils/TestUtils.java @@ -66,14 +66,6 @@ public class TestUtils { /** * Verifies that two objects are equivalent. * Does this by doing a string comparison after converting both to JSON. - */ - public static final void assertEqualObjects(Object o1, Object o2) throws SerializeException { - assertEqualObjects(o1, o2, false); - } - - /** - * Verifies that two objects are equivalent. - * Does this by doing a string comparison after converting both to JSON. * @param sort If <jk>true</jk> sort maps and collections before comparison. */ public static final void assertEqualObjects(Object o1, Object o2, boolean sort) throws SerializeException { diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java index 5440272..7c5ef46 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/uon/Common_UonTest.java @@ -12,8 +12,8 @@ // *************************************************************************************************************************** package org.apache.juneau.uon; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.assertions.ThrowableAssertion.*; -import static org.apache.juneau.testutils.TestUtils.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; @@ -42,13 +42,13 @@ public class Common_UonTest { String r = s.build().serialize(t1); assertEquals("(s2=s2)", r); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.keepNullProperties(); r = s.build().serialize(t1); assertEquals("(s1=null,s2=s2)", r); t2 = pe.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); } public static class A { @@ -73,7 +73,7 @@ public class Common_UonTest { r = s.build().serialize(t1); assertEquals("(f1=(),f2=(f2a=null,f2b=(s2=s2)))", r); t2 = pe.parse(r, B.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyMaps(); r = s.build().serialize(t1); @@ -105,7 +105,7 @@ public class Common_UonTest { r = s.build().serialize(t1); assertEquals("(f1=@(),f2=@(null,(s2=s2)))", r); t2 = pe.parse(r, C.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); @@ -137,7 +137,7 @@ public class Common_UonTest { r = s.build().serialize(t1); assertEquals("(f1=@(),f2=@(null,(s2=s2)))", r); t2 = pe.parse(r, D.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java index 019e8f1..b1f2285 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/urlencoding/Common_UrlEncodingTest.java @@ -12,8 +12,8 @@ // *************************************************************************************************************************** package org.apache.juneau.urlencoding; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.assertions.ThrowableAssertion.*; -import static org.apache.juneau.testutils.TestUtils.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; @@ -41,13 +41,13 @@ public class Common_UrlEncodingTest { String r = s.build().serialize(t1); assertEquals("s2=s2", r); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.keepNullProperties(); r = s.build().serialize(t1); assertEquals("s1=null&s2=s2", r); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); } public static class A { @@ -72,7 +72,7 @@ public class Common_UrlEncodingTest { r = s.build().serialize(t1); assertEquals("f1=()&f2=(f2a=null,f2b=(s2=s2))", r); t2 = p.parse(r, B.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyMaps(); r = s.build().serialize(t1); @@ -104,7 +104,7 @@ public class Common_UrlEncodingTest { r = s.build().serialize(t1); assertEquals("f1=@()&f2=@(null,(s2=s2))", r); t2 = p.parse(r, C.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); @@ -136,7 +136,7 @@ public class Common_UrlEncodingTest { r = s.build().serialize(t1); assertEquals("f1=@()&f2=@(null,(s2=s2))", r); t2 = p.parse(r, D.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/CommonTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/CommonTest.java index edfc75e..3789627 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/CommonTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/CommonTest.java @@ -12,8 +12,8 @@ // *************************************************************************************************************************** package org.apache.juneau.xml; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.assertions.ThrowableAssertion.*; -import static org.apache.juneau.testutils.TestUtils.*; import static org.apache.juneau.xml.annotation.XmlFormat.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; @@ -45,13 +45,13 @@ public class CommonTest { String r = s.build().serialize(t1); assertEquals("<object><s2>s2</s2></object>", r); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.keepNullProperties(); r = s.build().serialize(t1); assertEquals("<object><s1 _type='null'/><s2>s2</s2></object>", r); t2 = p.parse(r, A.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); } public static class A { @@ -77,7 +77,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("<object><f1/><f2><f2a _type='null'/><f2b><s2>s2</s2></f2b></f2></object>", r); t2 = p.parse(r, B.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyMaps(); r = s.build().serialize(t1); @@ -110,7 +110,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("<object><f1></f1><f2><null/><object><s2>s2</s2></object></f2></object>", r); t2 = p.parse(r, C.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); @@ -143,7 +143,7 @@ public class CommonTest { r = s.build().serialize(t1); assertEquals("<object><f1></f1><f2><null/><object><s2>s2</s2></object></f2></object>", r); t2 = p.parse(r, D.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); s.trimEmptyCollections(); r = s.build().serialize(t1); diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlCollapsedTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlCollapsedTest.java index 3cdebcb..591b634 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlCollapsedTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlCollapsedTest.java @@ -12,6 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.xml; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.testutils.TestUtils.*; import static org.apache.juneau.xml.annotation.XmlFormat.*; import static org.junit.Assert.*; @@ -273,14 +274,14 @@ public class XmlCollapsedTest { r = s.serialize(t1); assertEquals("<object><xf1>x1</xf1><xf1>x2</xf1></object>", r); t2 = p.parse(r, FA.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); validateXml(t1, s); t1 = FB.newInstance(); r = s.serialize(t1); assertEquals("<object><xf1>x1</xf1><xf1>x2</xf1></object>", r); t2 = p.parse(r, FB.class); - assertEqualObjects(t1, t2); + assertObject(t1).jsonSameAs(t2); validateXml(t1, s); } @@ -341,7 +342,7 @@ public class XmlCollapsedTest { // Note that existing fields should be reused and appended to. t2 = p.parse(xml, G.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); validateXml(t, s); } @@ -375,7 +376,7 @@ public class XmlCollapsedTest { // Note that existing fields should be reused and appended to. t2 = p.parse(xml, H.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); validateXml(t, s); } @@ -414,7 +415,7 @@ public class XmlCollapsedTest { // Note that existing fields should be reused and appended to. t2 = p.parse(xml, G.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); validateXml(t, s); } diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlContentTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlContentTest.java index f5194e0..0388354 100755 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlContentTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlContentTest.java @@ -12,7 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.xml; -import static org.apache.juneau.testutils.TestUtils.*; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.xml.annotation.XmlFormat.*; import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; @@ -51,7 +51,7 @@ public class XmlContentTest { r = sw.toString(); assertEquals("<A f1='f1' nil='true'></A>", r); t2 = p.parse(r, A.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); sw = new StringWriter(); session = s2.createSession(SerializerSessionArgs.create()); @@ -59,7 +59,7 @@ public class XmlContentTest { r = sw.toString(); assertEquals("<A f1='f1' nil='true'></A>\n", r); t2 = p.parse(r, A.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); //------------------------------------------------------------------------------------------------------------- // Normal text @@ -69,12 +69,12 @@ public class XmlContentTest { r = s1.serialize(t); assertEquals("<A f1='f1'>foobar</A>", r); t2 = p.parse(r, A.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); r = s2.serialize(t); assertEquals("<A f1='f1'>foobar</A>\n", r); t2 = p.parse(r, A.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); //------------------------------------------------------------------------------------------------------------- // Special characters @@ -84,12 +84,12 @@ public class XmlContentTest { r = s1.serialize(t); assertEquals("<A f1='f1'>~!@#$%^&*()_+`-={}|[]\\:\";'<>?,.

	_x0008_</A>", r); t2 = p.parse(r, A.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); r = s2.serialize(t); assertEquals("<A f1='f1'>~!@#$%^&*()_+`-={}|[]\\:\";'<>?,.

	_x0008_</A>\n", r); t2 = p.parse(r, A.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); //------------------------------------------------------------------------------------------------------------- // Leading spaces @@ -99,12 +99,12 @@ public class XmlContentTest { r = s1.serialize(t); assertEquals("<A f1='f1'>_x0020_ foobar</A>", r); t2 = p.parse(r, A.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); r = s2.serialize(t); assertEquals("<A f1='f1'>_x0020_ foobar</A>\n", r); t2 = p.parse(r, A.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); //------------------------------------------------------------------------------------------------------------- // Trailing spaces @@ -114,12 +114,12 @@ public class XmlContentTest { r = s1.serialize(t); assertEquals("<A f1='f1'>foobar _x0020_</A>", r); t2 = p.parse(r, A.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); r = s2.serialize(t); assertEquals("<A f1='f1'>foobar _x0020_</A>\n", r); t2 = p.parse(r, A.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); } @Bean(typeName="A") @@ -159,7 +159,7 @@ public class XmlContentTest { r = sw.toString(); assertEquals("<A f1='f1' nil='true'></A>", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); sw = new StringWriter(); session = s2.createSession(SerializerSessionArgs.create()); @@ -167,7 +167,7 @@ public class XmlContentTest { r = sw.toString(); assertEquals("<A f1='f1' nil='true'></A>\n", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); //------------------------------------------------------------------------------------------------------------- // Normal text @@ -177,12 +177,12 @@ public class XmlContentTest { r = s1.serialize(t); assertEquals("<A f1='f1'>foobar</A>", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); r = s2.serialize(t); assertEquals("<A f1='f1'>foobar</A>\n", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); //------------------------------------------------------------------------------------------------------------- // Normal XML @@ -192,12 +192,12 @@ public class XmlContentTest { r = s1.serialize(t); assertEquals("<A f1='f1'><xxx>foobar<yyy>baz</yyy>foobar</xxx></A>", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); r = s2.serialize(t); assertEquals("<A f1='f1'><xxx>foobar<yyy>baz</yyy>foobar</xxx></A>\n", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); //------------------------------------------------------------------------------------------------------------- // Normal XML with leading and trailing space @@ -207,12 +207,12 @@ public class XmlContentTest { r = s1.serialize(t); assertEquals("<A f1='f1'>_x0020_ <xxx>foobar<yyy>baz</yyy>foobar</xxx> _x0020_</A>", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); r = s2.serialize(t); assertEquals("<A f1='f1'>_x0020_ <xxx>foobar<yyy>baz</yyy>foobar</xxx> _x0020_</A>\n", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); //------------------------------------------------------------------------------------------------------------- // XML with attributes @@ -222,12 +222,12 @@ public class XmlContentTest { r = s1.serialize(t); assertEquals("<A f1='f1'><xxx x=\"x\">foobar</xxx></A>", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); r = s2.serialize(t); assertEquals("<A f1='f1'><xxx x=\"x\">foobar</xxx></A>\n", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); //------------------------------------------------------------------------------------------------------------- // XML with embedded entities @@ -237,12 +237,12 @@ public class XmlContentTest { r = s1.serialize(t); assertEquals("<A f1='f1'><xxx x=\"x\">foo&lt;&gt;bar</xxx></A>", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); r = s2.serialize(t); assertEquals("<A f1='f1'><xxx x=\"x\">foo&lt;&gt;bar</xxx></A>\n", r); t2 = p.parse(r, B.class); - assertEqualObjects(t, t2); + assertObject(t).jsonSameAs(t2); } @Bean(typeName="A") diff --git a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlIgnoreCommentsTest.java b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlIgnoreCommentsTest.java index c63aa88..05ef4f2 100644 --- a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlIgnoreCommentsTest.java +++ b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/xml/XmlIgnoreCommentsTest.java @@ -12,6 +12,7 @@ // *************************************************************************************************************************** package org.apache.juneau.xml; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.junit.runners.MethodSorters.*; import java.text.*; @@ -20,7 +21,6 @@ import java.util.*; import org.apache.juneau.*; import org.apache.juneau.annotation.*; import org.apache.juneau.collections.*; -import org.apache.juneau.testutils.*; import org.apache.juneau.xml.annotation.*; import org.junit.*; import org.junit.runner.*; @@ -695,7 +695,7 @@ public class XmlIgnoreCommentsTest { public void testNoComment() throws Exception { try { Object actual = XmlParser.DEFAULT.parse(input.replace("|", ""), type); - TestUtils.assertEqualObjects(expected, actual); + assertObject(expected).jsonSameAs(actual); } catch (ComparisonFailure e) { throw new ComparisonFailure(MessageFormat.format("Test ''{0}'' failed with comparison error", label), e.getExpected(), e.getActual()); } catch (Exception e) { @@ -707,7 +707,7 @@ public class XmlIgnoreCommentsTest { public void testNormalComment() throws Exception { try { Object actual = XmlParser.DEFAULT.parse(input.replace("|", "<!--x-->"), type); - TestUtils.assertEqualObjects(expected, actual); + assertObject(expected).jsonSameAs(actual); } catch (ComparisonFailure e) { throw new ComparisonFailure(MessageFormat.format("Test ''{0}'' failed with comparison error", label), e.getExpected(), e.getActual()); } catch (Exception e) { @@ -720,7 +720,7 @@ public class XmlIgnoreCommentsTest { try { Object actual = XmlParser.DEFAULT.parse(input.replace("|", " \n <!-- \n x \n --> \n "), type); if (! skipWsTests) - TestUtils.assertEqualObjects(expected, actual); + assertObject(expected).jsonSameAs(actual); } catch (ComparisonFailure e) { throw new ComparisonFailure(MessageFormat.format("Test ''{0}'' failed with comparison error", label), e.getExpected(), e.getActual()); } catch (Exception e) { @@ -733,7 +733,7 @@ public class XmlIgnoreCommentsTest { try { Object actual = XmlParser.DEFAULT.parse(input.replace("|", " \n <!-- \n x \n --> \n \n <!-- \n x \n --> \n "), type); if (! skipWsTests) - TestUtils.assertEqualObjects(expected, actual); + assertObject(expected).jsonSameAs(actual); } catch (ComparisonFailure e) { throw new ComparisonFailure(MessageFormat.format("Test ''{0}'' failed with comparison error", label), e.getExpected(), e.getActual()); } catch (Exception e) { diff --git a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java index 1dc00f2..a21ec97 100644 --- a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java +++ b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/assertions/FluentObjectAssertion.java @@ -13,7 +13,9 @@ package org.apache.juneau.assertions; import org.apache.juneau.internal.*; +import org.apache.juneau.json.*; import org.apache.juneau.reflect.*; +import org.apache.juneau.serializer.*; /** * Used for fluent assertion calls. @@ -23,9 +25,23 @@ import org.apache.juneau.reflect.*; @FluentSetters(returns="FluentObjectAssertion<R>") public class FluentObjectAssertion<R> extends FluentAssertion<R> { - @SuppressWarnings("unused") private final Object o; + private static JsonSerializer JSON = JsonSerializer.create() + .ssq() + .keepNullProperties() + .addBeanTypes().addRootType() + .build(); + + private static JsonSerializer SORTEDJSON = JsonSerializer.create() + .ssq() + .sortCollections() + .sortMaps() + .keepNullProperties() + .addBeanTypes().addRootType() + .build(); + + /** * Constructor. * @@ -52,6 +68,44 @@ public class FluentObjectAssertion<R> extends FluentAssertion<R> { return returns(); } + /** + * Verifies that two objects are equivalent after converting them both to JSON. + * + * @param o The object to compare against. + * @return The response object (for method chaining). + * @throws AssertionError If assertion failed. + */ + public R jsonSameAs(Object o) throws AssertionError { + try { + String s1 = JSON.serialize(this.o); + String s2 = JSON.serialize(o); + if (! StringUtils.isEquals(s1, s2)) + throw error("Unexpected JSON comparison.\n\tExpected=[{0}]\n\tActual=[{1}]", s2, s1); + } catch (SerializeException e) { + throw new RuntimeException(e); + } + return returns(); + } + + /** + * Verifies that two objects are equivalent after converting them both to sorted JSON. + * + * @param o The object to compare against. + * @return The response object (for method chaining). + * @throws AssertionError If assertion failed. + */ + public R jsonSameAsSorted(Object o) { + try { + String s1 = SORTEDJSON.serialize(this.o); + String s2 = SORTEDJSON.serialize(o); + if (! StringUtils.isEquals(s1, s2)) + throw error("Unexpected JSON comparison.\n\tExpected=[{0}]\n\tActual=[{1}]", s2, s1); + } catch (SerializeException e) { + throw new RuntimeException(e); + } + return returns(); + } + // <FluentSetters> @Override /* GENERATED - Assertion */ diff --git a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Test.java b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Test.java index b356b5f..83d2715 100644 --- a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Test.java +++ b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Test.java @@ -16,6 +16,7 @@ import static org.junit.Assert.*; import static org.junit.runners.MethodSorters.*; import static org.apache.juneau.rest.client2.RestClient.*; import static org.apache.juneau.testutils.TestUtils.*; +import static org.apache.juneau.assertions.ObjectAssertion.*; import static org.apache.juneau.assertions.ThrowableAssertion.*; import static org.apache.juneau.httppart.HttpPartSchema.*; @@ -1605,7 +1606,7 @@ public class RestClient_Test { ABean b = rc.post("/echoBody", bean).run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class); - assertEqualObjects(b, bean); + assertObject(b).jsonSameAs(bean); } @Test @@ -1615,10 +1616,10 @@ public class RestClient_Test { rc.post("/echoBody", bean).run().assertBody().is("{f:1}"); ABean b = rc.post("/echoBody", bean).accept("text/xml").contentType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class); - assertEqualObjects(b, bean); + assertObject(b).jsonSameAs(bean); b = rc.post("/echoBody", bean).accept("text/json").contentType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().as(ABean.class); - assertEqualObjects(b, bean); + assertObject(b).jsonSameAs(bean); } @Test @@ -1627,13 +1628,13 @@ public class RestClient_Test { ABean b = rc.post("/echoBody", bean).run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class); - assertEqualObjects(b, bean); + assertObject(b).jsonSameAs(bean); rc = MockRestClient.create(A.class).serializer(XmlSerializer.DEFAULT).parser(XmlParser.DEFAULT).build(); b = rc.post("/echoBody", bean).run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class); - assertEqualObjects(b, bean); + assertObject(b).jsonSameAs(bean); try { MockRestClient.create(A.class).prependTo(RESTCLIENT_serializers, String.class).build(); fail(); @@ -1668,20 +1669,20 @@ public class RestClient_Test { rc.post("/echoBody", bean).run().assertBody().is("{f:1}"); ABean b = rc.post("/echoBody", bean).accept("text/xml").contentType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class); - assertEqualObjects(b, bean); + assertObject(b).jsonSameAs(bean); b = rc.post("/echoBody", bean).accept("text/json").contentType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().as(ABean.class); - assertEqualObjects(b, bean); + assertObject(b).jsonSameAs(bean); rc = MockRestClient.create(A.class).serializers(XmlSerializer.DEFAULT,JsonSerializer.DEFAULT).parsers(XmlParser.DEFAULT,JsonParser.DEFAULT).build(); rc.post("/echoBody", bean).run().assertBody().is("{f:1}"); b = rc.post("/echoBody", bean).accept("text/xml").contentType("text/xml").run().cacheBody().assertBody().is("<object><f>1</f></object>").getBody().as(ABean.class); - assertEqualObjects(b, bean); + assertObject(b).jsonSameAs(bean); b = rc.post("/echoBody", bean).accept("text/json").contentType("text/json").run().cacheBody().assertBody().is("{\"f\":1}").getBody().as(ABean.class); - assertEqualObjects(b, bean); + assertObject(b).jsonSameAs(bean); } @Rest(partSerializer=K12a.class, partParser=K12b.class)