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 6564e66  RestClient tests.
6564e66 is described below

commit 6564e66acb2b2cc9264b8cf6de2b30f8d013e0b9
Author: JamesBognar <[email protected]>
AuthorDate: Mon Apr 6 20:21:21 2020 -0400

    RestClient tests.
---
 ...t.java => BeanTraversePropertiesComboTest.java} |  88 +++++++++++++++--
 .../java/org/apache/juneau/ComboRoundTripTest.java |  14 ++-
 .../juneau/SerializerPropertiesComboTest.java      | 108 +++++++++++++++++++++
 .../org/apache/juneau/internal/ThrowableUtils.java |   8 +-
 .../juneau/msgpack/MsgPackSerializerSession.java   |  26 +++--
 5 files changed, 223 insertions(+), 21 deletions(-)

diff --git 
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/serializer/BeanTraverseComboTest.java
 
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/BeanTraversePropertiesComboTest.java
similarity index 62%
rename from 
juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/serializer/BeanTraverseComboTest.java
rename to 
juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/BeanTraversePropertiesComboTest.java
index 4d02819..082952e 100644
--- 
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/serializer/BeanTraverseComboTest.java
+++ 
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/BeanTraversePropertiesComboTest.java
@@ -10,12 +10,11 @@
 // * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
express or implied.  See the License for the        *
 // * specific language governing permissions and limitations under the 
License.                                              *
 // 
***************************************************************************************************************************
-package org.apache.juneau.serializer;
+package org.apache.juneau;
 
 import static org.apache.juneau.BeanTraverseContext.*;
 import java.util.*;
 
-import org.apache.juneau.*;
 import org.apache.juneau.collections.*;
 import org.junit.runner.*;
 import org.junit.runners.*;
@@ -25,26 +24,36 @@ import org.junit.runners.*;
  */
 @RunWith(Parameterized.class)
 @SuppressWarnings({})
-public class BeanTraverseComboTest extends ComboRoundTripTest {
+public class BeanTraversePropertiesComboTest extends ComboRoundTripTest {
 
-       public static class Bean {
+       public static class A {
                public int f;
 
-               public static Bean create() {
-                       Bean b = new Bean();
+               public static A create() {
+                       A b = new A();
                        b.f = 1;
                        return b;
                }
        }
 
+       public static class B {
+               public Object f;
+
+               public static B create() {
+                       B b = new B();
+                       b.f = b;
+                       return b;
+               }
+       }
+
        @Parameterized.Parameters
        public static Collection<Object[]> getParameters() {
                return Arrays.asList(new Object[][] {
                        {       /* 0 */
                                new ComboInput<>(
-                                       "TestInitialDepth",
-                                       Bean.class,
-                                       Bean.create(),
+                                       "BEANTRAVERSE_initialDepth",
+                                       A.class,
+                                       A.create(),
                                        /* Json */              "{f:1}",
                                        /* JsonT */             "{f:1}",
                                        /* JsonR */             
"\t\t{\n\t\t\tf: 1\n\t\t}",
@@ -69,10 +78,69 @@ public class BeanTraverseComboTest extends 
ComboRoundTripTest {
                                )
                                .properties(OMap.of(BEANTRAVERSE_initialDepth, 
2))
                        },
+                       {       /* 1 */
+                               new ComboInput<>(
+                                       "BEANTRAVERSE_detectRecursions",
+                                       B.class,
+                                       B.create(),
+                                       /* Json */              "x",
+                                       /* JsonT */             "x",
+                                       /* JsonR */             "x",
+                                       /* Xml */               "x",
+                                       /* XmlT */              "x",
+                                       /* XmlR */              "x",
+                                       /* XmlNs */             "x",
+                                       /* Html */              "x",
+                                       /* HtmlT */             "x",
+                                       /* HtmlR */             "x",
+                                       /* Uon */               "x",
+                                       /* UonT */              "x",
+                                       /* UonR */              "x",
+                                       /* UrlEnc */    "x",
+                                       /* UrlEncT */   "x",
+                                       /* UrlEncR */   "x",
+                                       /* MsgPack */   "x",
+                                       /* MsgPackT */  "x",
+                                       /* RdfXml */    "x",
+                                       /* RdfXmlT */   "x",
+                                       /* RdfXmlR */   "x"
+                               )
+                               
.properties(OMap.of(BEANTRAVERSE_detectRecursions, true))
+                               .exceptionMsg("Recursion occurred")
+                       },
+                       {       /* 2 */
+                               new ComboInput<>(
+                                       "BEANTRAVERSE_ignoreRecursions",
+                                       B.class,
+                                       B.create(),
+                                       /* Json */              "{}",
+                                       /* JsonT */             "{}",
+                                       /* JsonR */             "{\n}",
+                                       /* Xml */               "<object/>",
+                                       /* XmlT */              "<object/>",
+                                       /* XmlR */              "<object/>\n",
+                                       /* XmlNs */             "<object/>",
+                                       /* Html */              
"<table></table>",
+                                       /* HtmlT */             
"<table></table>",
+                                       /* HtmlR */             
"<table>\n</table>\n",
+                                       /* Uon */               "()",
+                                       /* UonT */              "()",
+                                       /* UonR */              "(\n)",
+                                       /* UrlEnc */    "",
+                                       /* UrlEncT */   "",
+                                       /* UrlEncR */   "",
+                                       /* MsgPack */   "80",
+                                       /* MsgPackT */  "80",
+                                       /* RdfXml */    
"<rdf:RDF>\n</rdf:RDF>\n",
+                                       /* RdfXmlT */   
"<rdf:RDF>\n</rdf:RDF>\n",
+                                       /* RdfXmlR */   
"<rdf:RDF>\n</rdf:RDF>\n"
+                               )
+                               
.properties(OMap.of(BEANTRAVERSE_ignoreRecursions, true))
+                       },
                });
        }
 
-       public BeanTraverseComboTest(ComboInput<?> comboInput) {
+       public BeanTraversePropertiesComboTest(ComboInput<?> comboInput) {
                super(comboInput);
        }
 }
diff --git 
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
 
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
index 683adb2..0b43c8a 100644
--- 
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
+++ 
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/ComboRoundTripTest.java
@@ -156,7 +156,7 @@ public abstract class ComboRoundTripTest {
 
                        boolean isRdf = s instanceof RdfSerializer;
 
-                       if ((isRdf && SKIP_RDF_TESTS) || expected.isEmpty() || 
! runTestsSet.contains(testName) ) {
+                       if ((isRdf && SKIP_RDF_TESTS) || 
"SKIP".equals(expected) || ! runTestsSet.contains(testName) ) {
                                System.err.println(comboInput.label + "/" + 
testName + " for "+s.getClass().getSimpleName()+" skipped.");  // NOT DEBUG
                                return;
                        }
@@ -243,6 +243,12 @@ public abstract class ComboRoundTripTest {
                        s = getSerializer(s);
                        p = getParser(p);
 
+                       OMap properties = comboInput.getProperties();
+                       if (properties != null) {
+                               s = s.builder().add(properties).build();
+                               p = p.builder().add(properties).build();
+                       }
+
                        String r = s.serializeToString(comboInput.getInput());
                        Object o = p.parse(r, comboInput.type);
 
@@ -267,6 +273,12 @@ public abstract class ComboRoundTripTest {
                        p = (InputStreamParser)getParser(p);
                        WriterSerializer sJson = 
(WriterSerializer)getSerializer(this.sJson);
 
+                       if (comboInput.getProperties() != null) {
+                               s = 
(OutputStreamSerializer)s.builder().add(comboInput.getProperties()).build();
+                               p = 
(InputStreamParser)p.builder().add(comboInput.getProperties()).build();
+                               sJson = 
(WriterSerializer)sJson.builder().add(comboInput.getProperties()).build();
+                       }
+
                        String r = s.serializeToString(comboInput.getInput());
                        Object o = p.parse(r, comboInput.type);
                        r = sJson.serialize(o);
diff --git 
a/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/SerializerPropertiesComboTest.java
 
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/SerializerPropertiesComboTest.java
new file mode 100644
index 0000000..99bc25a
--- /dev/null
+++ 
b/juneau-core/juneau-core-utest/src/test/java/org/apache/juneau/SerializerPropertiesComboTest.java
@@ -0,0 +1,108 @@
+// 
***************************************************************************************************************************
+// * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements.  See the NOTICE file *
+// * distributed with this work for additional information regarding copyright 
ownership.  The ASF licenses this file        *
+// * to you under the Apache License, Version 2.0 (the "License"); you may not 
use this file except in compliance            *
+// * with the License.  You may obtain a copy of the License at                
                                              *
+// *                                                                           
                                              *
+// *  http://www.apache.org/licenses/LICENSE-2.0                               
                                              *
+// *                                                                           
                                              *
+// * Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an  *
+// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
express or implied.  See the License for the        *
+// * specific language governing permissions and limitations under the 
License.                                              *
+// 
***************************************************************************************************************************
+package org.apache.juneau;
+
+import static org.apache.juneau.serializer.Serializer.*;
+import java.util.*;
+
+import org.apache.juneau.annotation.*;
+import org.apache.juneau.collections.*;
+import org.junit.runner.*;
+import org.junit.runners.*;
+
+/**
+ * Exhaustive serialization tests for BeanTraverseContext properties.
+ */
+@RunWith(Parameterized.class)
+@SuppressWarnings({})
+public class SerializerPropertiesComboTest extends ComboRoundTripTest {
+
+       @Bean(typeName="BwT")
+       public static class BeanWithType {
+               public int f;
+
+               public static BeanWithType create() {
+                       BeanWithType l = new BeanWithType();
+                       l.f = 1;
+                       return l;
+               }
+       }
+
+       @Parameterized.Parameters
+       public static Collection<Object[]> getParameters() {
+               return Arrays.asList(new Object[][] {
+                       {       /* 0 */
+                               new ComboInput<>(
+                                       "SERIALIZER_addBeanTypes",
+                                       OMap.class,
+                                       OMap.of("a", BeanWithType.create()),
+                                       /* Json */              
"{a:{_type:'BwT',f:1}}",
+                                       /* JsonT */             
"{a:{t:'BwT',f:1}}",
+                                       /* JsonR */             "{\n\ta: 
{\n\t\t_type: 'BwT',\n\t\tf: 1\n\t}\n}",
+                                       /* Xml */               "<object><BwT 
_name='a'><f>1</f></BwT></object>",
+                                       /* XmlT */              "<object><BwT 
_name='a'><f>1</f></BwT></object>",
+                                       /* XmlR */              
"<object>\n\t<BwT _name='a'>\n\t\t<f>1</f>\n\t</BwT>\n</object>\n",
+                                       /* XmlNs */             "<object><BwT 
_name='a'><f>1</f></BwT></object>",
+                                       /* Html */              
"<table><tr><td>a</td><td><table 
_type='BwT'><tr><td>f</td><td>1</td></tr></table></td></tr></table>",
+                                       /* HtmlT */             
"<table><tr><td>a</td><td><table 
t='BwT'><tr><td>f</td><td>1</td></tr></table></td></tr></table>",
+                                       /* HtmlR */             
"<table>\n\t<tr>\n\t\t<td>a</td>\n\t\t<td>\n\t\t\t<table 
_type='BwT'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>f</td>\n\t\t\t\t\t<td>1</td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</td>\n\t</tr>\n</table>\n",
+                                       /* Uon */               
"(a=(_type=BwT,f=1))",
+                                       /* UonT */              
"(a=(t=BwT,f=1))",
+                                       /* UonR */              
"(\n\ta=(\n\t\t_type=BwT,\n\t\tf=1\n\t)\n)",
+                                       /* UrlEnc */    "a=(_type=BwT,f=1)",
+                                       /* UrlEncT */   "a=(t=BwT,f=1)",
+                                       /* UrlEncR */   
"a=(\n\t_type=BwT,\n\tf=1\n)",
+                                       /* MsgPack */   
"81A16182A55F74797065A3427754A16601",
+                                       /* MsgPackT */  
"81A16182A174A3427754A16601",
+                                       /* RdfXml */    
"<rdf:RDF>\n<rdf:Description>\n<jp:a 
rdf:parseType='Resource'>\n<jp:_type>BwT</jp:_type>\n<jp:f>1</jp:f>\n</jp:a>\n</rdf:Description>\n</rdf:RDF>\n",
+                                       /* RdfXmlT */   
"<rdf:RDF>\n<rdf:Description>\n<jp:a 
rdf:parseType='Resource'>\n<jp:t>BwT</jp:t>\n<jp:f>1</jp:f>\n</jp:a>\n</rdf:Description>\n</rdf:RDF>\n",
+                                       /* RdfXmlR */   "<rdf:RDF>\n  
<rdf:Description>\n    <jp:a rdf:parseType='Resource'>\n      
<jp:_type>BwT</jp:_type>\n      <jp:f>1</jp:f>\n    </jp:a>\n  
</rdf:Description>\n</rdf:RDF>\n"
+                               )
+                               .properties(OMap.of(SERIALIZER_addBeanTypes, 
true, BEAN_beanDictionary, BeanWithType.class))
+                       },
+                       {       /* 1 */
+                               new ComboInput<>(
+                                       "SERIALIZER_addRootType",
+                                       BeanWithType.class,
+                                       BeanWithType.create(),
+                                       /* Json */              
"{_type:'BwT',f:1}",
+                                       /* JsonT */             "{t:'BwT',f:1}",
+                                       /* JsonR */             "{\n\t_type: 
'BwT',\n\tf: 1\n}",
+                                       /* Xml */               
"<BwT><f>1</f></BwT>",
+                                       /* XmlT */              
"<BwT><f>1</f></BwT>",
+                                       /* XmlR */              
"<BwT>\n\t<f>1</f>\n</BwT>\n",
+                                       /* XmlNs */             
"<BwT><f>1</f></BwT>",
+                                       /* Html */              "<table 
_type='BwT'><tr><td>f</td><td>1</td></tr></table>",
+                                       /* HtmlT */             "<table 
t='BwT'><tr><td>f</td><td>1</td></tr></table>",
+                                       /* HtmlR */             "<table 
_type='BwT'>\n\t<tr>\n\t\t<td>f</td>\n\t\t<td>1</td>\n\t</tr>\n</table>\n",
+                                       /* Uon */               
"(_type=BwT,f=1)",
+                                       /* UonT */              "(t=BwT,f=1)",
+                                       /* UonR */              
"(\n\t_type=BwT,\n\tf=1\n)",
+                                       /* UrlEnc */    "_type=BwT&f=1",
+                                       /* UrlEncT */   "t=BwT&f=1",
+                                       /* UrlEncR */   "_type=BwT\n&f=1",
+                                       /* MsgPack */   
"82A55F74797065A3427754A16601",
+                                       /* MsgPackT */  "82A174A3427754A16601",
+                                       /* RdfXml */    
"<rdf:RDF>\n<rdf:Description>\n<jp:_type>BwT</jp:_type>\n<jp:f>1</jp:f>\n</rdf:Description>\n</rdf:RDF>\n",
+                                       /* RdfXmlT */   
"<rdf:RDF>\n<rdf:Description>\n<jp:t>BwT</jp:t>\n<jp:f>1</jp:f>\n</rdf:Description>\n</rdf:RDF>\n",
+                                       /* RdfXmlR */   "<rdf:RDF>\n  
<rdf:Description>\n    <jp:_type>BwT</jp:_type>\n    <jp:f>1</jp:f>\n  
</rdf:Description>\n</rdf:RDF>\n"
+                               )
+                               .properties(OMap.of(SERIALIZER_addRootType, 
true, BEAN_beanDictionary, BeanWithType.class))
+                       },
+               });
+       }
+
+       public SerializerPropertiesComboTest(ComboInput<?> comboInput) {
+               super(comboInput);
+       }
+}
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
index c3adf5f..a5ea31c 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/internal/ThrowableUtils.java
@@ -90,11 +90,13 @@ public class ThrowableUtils {
         * @throws AssertionError Assertion failed.
         */
        public static void assertExceptionContainsMessage(Throwable t, String 
msg) throws AssertionError {
-               while (t != null) {
-                       if (t.getMessage() != null && 
t.getMessage().contains(msg))
+               Throwable t2 = t;
+               while (t2 != null) {
+                       if (t2.getMessage() != null && 
t2.getMessage().contains(msg))
                                return;
-                       t = t.getCause();
+                       t2 = t2.getCause();
                }
+               t.printStackTrace();
                throw new BasicAssertionError(t, "Throwable did not contain the 
expected message.  Message=[{0}]", msg);
        }
 }
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
index 0efb177..a6e38f0 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/msgpack/MsgPackSerializerSession.java
@@ -86,10 +86,8 @@ public final class MsgPackSerializerSession extends 
OutputStreamSerializerSessio
                boolean isRecursion = aType == null;
 
                // Handle recursion
-               if (aType == null) {
-                       o = null;
-                       aType = object();
-               }
+               if (aType == null)
+                       return out.appendNull();
 
                // Handle Optional<X>
                if (isOptional(aType)) {
@@ -176,9 +174,14 @@ public final class MsgPackSerializerSession extends 
OutputStreamSerializerSessio
                List<BeanPropertyValue> values = 
m.getValues(isTrimNullProperties(), typeName != null ? 
createBeanTypeNameProperty(m, typeName) : null);
 
                int size = values.size();
-               for (BeanPropertyValue p : values)
+               for (BeanPropertyValue p : values) {
                        if (p.getThrown() != null)
                                size--;
+                       // Must handle the case where recursion occurs and 
property is not serialized.
+                       if (isTrimNullProperties() && willRecurse(p))
+                               size--;
+               }
+
                out.startMap(size);
 
                for (BeanPropertyValue p : values) {
@@ -188,15 +191,24 @@ public final class MsgPackSerializerSession extends 
OutputStreamSerializerSessio
                                String key = p.getName();
                                Object value = p.getValue();
                                Throwable t = p.getThrown();
-                               if (t != null)
+                               if (t != null) {
                                        onBeanGetterException(pMeta, t);
-                               else {
+                               } else if (isTrimNullProperties() && 
willRecurse(p)) {
+                                       /* Ignored */
+                               } else {
                                        serializeAnything(out, key, null, null, 
null);
                                        serializeAnything(out, value, cMeta, 
key, pMeta);
                                }
                        }
                }
        }
+       
+       private boolean willRecurse(BeanPropertyValue v) throws 
SerializeException {
+               ClassMeta<?> aType = push2(v.getName(), v.getValue(), 
v.getClassMeta());
+                if (aType != null)
+                        pop();
+                return aType == null;
+       }
 
        private static final class SimpleMapEntry {
                final Object key;

Reply via email to