http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/PropertyStoreTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/PropertyStoreTest.java b/juneau-core-test/src/test/java/org/apache/juneau/PropertyStoreTest.java new file mode 100644 index 0000000..9bc6398 --- /dev/null +++ b/juneau-core-test/src/test/java/org/apache/juneau/PropertyStoreTest.java @@ -0,0 +1,823 @@ +// *************************************************************************************************************************** +// * 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.TestUtils.*; +import static org.junit.Assert.*; + +import java.util.*; + +import org.apache.juneau.xml.*; +import org.junit.*; + + +@SuppressWarnings({"rawtypes","javadoc"}) +public class PropertyStoreTest { + + //==================================================================================================== + // testSimpleProperties() + //==================================================================================================== + @Test + public void testSimpleProperties() { + PropertyStore f = PropertyStore.create(); + + f.setProperty("A.f1", "1"); + f.setProperty("A.f2", "2"); + + assertObjectEquals("{'A.f1':'1','A.f2':'2'}", f.getPropertyMap("A").asMap()); + + f.setProperty("B.f3", "3"); + f.setProperty("A.f1", String.class); + f.setProperty("A.f2", 4); + + assertObjectEquals("{'A.f1':'java.lang.String','A.f2':4}", f.getPropertyMap("A").asMap()); + + f.setProperty("A.f2", null); + f.setProperty("A.f2", null); + assertObjectEquals("{'A.f1':'java.lang.String'}", f.getPropertyMap("A").asMap()); + + try { + f.setProperty(null, null); + fail("Exception expected"); + } catch (Exception e) { + assertEquals("Invalid property name specified: 'null'", e.getMessage()); + } + + try { + f.addToProperty("A.f1", "foo"); + fail("Exception expected"); + } catch (Exception e) { + assertEquals("Cannot add value 'foo' (java.lang.String) to property 'A.f1' (SIMPLE).", e.getMessage()); + } + + try { + f.removeFromProperty("A.f1", "foo"); + fail("Exception expected"); + } catch (Exception e) { + assertEquals("Cannot remove value 'foo' (java.lang.String) from property 'A.f1' (SIMPLE).", e.getMessage()); + } + + try { + f.putToProperty("A.f1", "foo", "bar"); + fail("Exception expected"); + } catch (Exception e) { + assertEquals("Cannot put value 'foo'(java.lang.String)->'bar'(java.lang.String) to property 'A.f1' (SIMPLE).", e.getMessage()); + } + + try { + f.putToProperty("A.f1", "foo"); + fail("Exception expected"); + } catch (Exception e) { + assertEquals("Cannot put value 'foo' (java.lang.String) to property 'A.f1' (SIMPLE).", e.getMessage()); + } + } + + //==================================================================================================== + // testSetProperties() + //==================================================================================================== + @Test + public void testSetProperties() { + PropertyStore f = PropertyStore.create(); + String key = "A.f1.set"; + + f.setProperty(key, Arrays.asList(2,3,1)); + assertObjectEquals("[1,2,3]", f.getProperty(key, int[].class, null)); + + f.addToProperty(key, 0); + f.addToProperty(key, new int[]{4,5}); + assertObjectEquals("[0,1,2,3,4,5]", f.getProperty(key, int[].class, null)); + f.addToProperty(key, new HashSet<String>(Arrays.asList("6","7"))); + assertObjectEquals("[0,1,2,3,4,5,6,7]", f.getProperty(key, int[].class, null)); + f.addToProperty(key, new int[]{4,5}); + assertObjectEquals("[0,1,2,3,4,5,6,7]", f.getProperty(key, int[].class, null)); + + f.removeFromProperty(key, 4); + f.removeFromProperty(key, new HashSet<String>(Arrays.asList("1"))); + f.removeFromProperty(key, new String[]{"2","9"}); + assertObjectEquals("[0,3,5,6,7]", f.getProperty(key, int[].class, null)); + assertObjectEquals("['0','3','5','6','7']", f.getProperty(key, String[].class, null)); + + f.setProperty(key, Arrays.asList("foo","bar","baz")); + assertObjectEquals("['bar','baz','foo']", f.getProperty(key, String[].class, null)); + + f.setProperty(key, "[1,2,3]"); + assertObjectEquals("[1,2,3]", f.getProperty(key, int[].class, null)); + + f.setProperty(key, "['1','2','3']"); + assertObjectEquals("[1,2,3]", f.getProperty(key, int[].class, null)); + + try { + f.putToProperty("A.f1.set", "foo"); + fail("Exception expected"); + } catch (Exception e) { + assertEquals("Cannot put value 'foo' (java.lang.String) to property 'A.f1.set' (SET).", e.getMessage()); + } + + try { + f.putToProperty("A.f1.set", "foo", "bar"); + fail("Exception expected"); + } catch (Exception e) { + assertEquals("Cannot put value 'foo'(java.lang.String)->'bar'(java.lang.String) to property 'A.f1.set' (SET).", e.getMessage()); + } + } + + //==================================================================================================== + // testListProperties() + //==================================================================================================== + @Test + public void testListProperties() { + PropertyStore f = PropertyStore.create(); + String key = "A.f1.list"; + + f.setProperty(key, Arrays.asList(2,3,1)); + assertObjectEquals("[2,3,1]", f.getProperty(key, int[].class, null)); + + f.addToProperty(key, 0); + f.addToProperty(key, new int[]{4,5}); + assertObjectEquals("[4,5,0,2,3,1]", f.getProperty(key, int[].class, null)); + f.addToProperty(key, new TreeSet<String>(Arrays.asList("6","7"))); + assertObjectEquals("[6,7,4,5,0,2,3,1]", f.getProperty(key, int[].class, null)); + f.addToProperty(key, new int[]{4,5}); + assertObjectEquals("[4,5,6,7,0,2,3,1]", f.getProperty(key, int[].class, null)); + + f.removeFromProperty(key, 4); + f.removeFromProperty(key, new HashSet<String>(Arrays.asList("1"))); + f.removeFromProperty(key, new String[]{"2","9"}); + assertObjectEquals("[5,6,7,0,3]", f.getProperty(key, int[].class, null)); + assertObjectEquals("['5','6','7','0','3']", f.getProperty(key, String[].class, null)); + + f.setProperty(key, Arrays.asList("foo","bar","baz")); + assertObjectEquals("['foo','bar','baz']", f.getProperty(key, String[].class, null)); + } + + //==================================================================================================== + // testMapProperties() + //==================================================================================================== + @SuppressWarnings("serial") + @Test + public void testMapProperties() { + PropertyStore f = PropertyStore.create(); + String key = "A.f1.map"; + + f.setProperty(key, new HashMap<String,String>(){{put("1","1");put("3","3");put("2","2");}}); + assertObjectEquals("{'1':1,'2':2,'3':3}", f.getMap(key, Integer.class, Integer.class, null)); + + f.setProperty(key, "{'1':1,'2':2,'3':3}"); + assertObjectEquals("{'1':1,'2':2,'3':3}", f.getMap(key, Integer.class, Integer.class, null)); + + f.putToProperty(key, "{'3':4,'4':5,'5':6}"); + assertObjectEquals("{'1':1,'2':2,'3':4,'4':5,'5':6}", f.getMap(key, Integer.class, Integer.class, null)); + } + + //==================================================================================================== + // Hash code and comparison + //==================================================================================================== + @SuppressWarnings({ "serial" }) + @Test + public void testHashCodes() throws Exception { + PropertyStore f1 = PropertyStore.create(); + f1.setProperty("A.a", 1); + f1.setProperty("A.b", true); + f1.setProperty("A.c", String.class); + f1.setProperty("A.d.set", new Object[]{1, true, String.class}); + f1.setProperty("A.e.map", new HashMap<Object,Object>(){{put(true,true);put(1,1);put(String.class,String.class);}}); + + PropertyStore f2 = PropertyStore.create(); + f2.setProperty("A.e.map", new HashMap<Object,Object>(){{put("1","1");put("true","true");put("java.lang.String","java.lang.String");}}); + f2.setProperty("A.d.set", new Object[]{"true","1","java.lang.String"}); + f2.setProperty("A.c", "java.lang.String"); + f2.setProperty("A.b", "true"); + f2.setProperty("A.a", "1"); + + PropertyStore.PropertyMap p1 = f1.getPropertyMap("A"); + PropertyStore.PropertyMap p2 = f2.getPropertyMap("A"); + assertEquals(p1.hashCode(), p2.hashCode()); + } + + @SuppressWarnings("unchecked") + private static class ConversionTest { + PropertyStore config = PropertyStore.create(); + String pName; + Object in; + + private ConversionTest(String pName, Object in) { + this.pName = pName; + this.in = in; + } + + private ConversionTest test(Class c, String expected) { + try { + config.setProperty(pName, in); + assertObjectEquals(expected, config.getProperty(pName, c, null)); + } catch (Exception x) { + assertEquals(expected.toString(), x.getLocalizedMessage()); + } + return this; + } + + private ConversionTest testMap(Class k, Class v, String expected) { + try { + config.setProperty(pName, in); + assertObjectEquals(expected, config.getMap(pName, k, v, null)); + } catch (Exception x) { + assertEquals(expected, x.getLocalizedMessage()); + } + return this; + } + } + + //==================================================================================================== + // Conversions on simple properties + //==================================================================================================== + @Test + @SuppressWarnings({ "serial" }) + public void testConversionsOnSimpleProperties() throws Exception { + String pName = "A.a"; + + //-------------------------------------------------------------------------------- + // boolean + //-------------------------------------------------------------------------------- + new ConversionTest(pName, true) + .test(boolean.class, "true") + .test(int.class, "1") + .test(String.class, "'true'") + .test(Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'java.lang.Class'. Value=true.") + .test(TestEnum.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=true.") + .test(String[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'java.lang.String[]'. Value=true.") + .test(Class[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'java.lang.Class[]'. Value=true.") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=true.") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=true.") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=true.") + ; + + //-------------------------------------------------------------------------------- + // int + //-------------------------------------------------------------------------------- + new ConversionTest(pName, 123) + .test(boolean.class, "true") + .test(int.class, "123") + .test(String.class, "'123'") + .test(Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'java.lang.Class'. Value=123.") + .test(TestEnum.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=123.") + .test(String[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'java.lang.String[]'. Value=123.") + .test(Class[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'java.lang.Class[]'. Value=123.") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=123.") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=123.") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=123.") + ; + + //-------------------------------------------------------------------------------- + // Class + //-------------------------------------------------------------------------------- + new ConversionTest(pName, String.class) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class' to type 'int'. Value='java.lang.String'.") + .test(String.class, "'java.lang.String'") + .test(Class.class, "'java.lang.String'") + .test(TestEnum.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value='java.lang.String'.") + .test(String[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class' to type 'java.lang.String[]'. Value='java.lang.String'.") + .test(Class[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class' to type 'java.lang.Class[]'. Value='java.lang.String'.") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value='java.lang.String'.") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value='java.lang.String'.") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value='java.lang.String'.") + ; + + //-------------------------------------------------------------------------------- + // String + //-------------------------------------------------------------------------------- + new ConversionTest(pName, "foo") + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'int'. Value='foo'.") + .test(String.class, "'foo'") + .test(Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'java.lang.Class'. Value='foo'.") + .test(TestEnum.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value='foo'.") + .test(String[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'java.lang.String[]'. Value='foo'.") + .test(Class[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'java.lang.Class[]'. Value='foo'.") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value='foo'.") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value='foo'.") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value='foo'.") + ; + new ConversionTest(pName, "java.lang.String") + .test(Class.class, "'java.lang.String'") + ; + new ConversionTest(pName, "true") + .test(boolean.class, "true") + ; + new ConversionTest(pName, "ONE") + .test(TestEnum.class, "'ONE'") + ; + new ConversionTest(pName, "123") + .test(int.class, "123") + ; + + //-------------------------------------------------------------------------------- + // enum + //-------------------------------------------------------------------------------- + new ConversionTest(pName, TestEnum.ONE) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum' to type 'int'. Value='ONE'.") + .test(String.class, "'ONE'") + .test(Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum' to type 'java.lang.Class'. Value='ONE'.") + .test(TestEnum.class, "'ONE'") + .test(String[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum' to type 'java.lang.String[]'. Value='ONE'.") + .test(Class[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum' to type 'java.lang.Class[]'. Value='ONE'.") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value='ONE'.") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value='ONE'.") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value='ONE'.") + ; + + //-------------------------------------------------------------------------------- + // String[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new String[]{"foo","bar"}) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String[]' to type 'int'. Value=['foo','bar'].") + .test(String.class, "'[\\'foo\\',\\'bar\\']'") + .test(Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String[]' to type 'java.lang.Class'. Value=['foo','bar'].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String[]' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=['foo','bar'].") + .test(String[].class, "['foo','bar']") + .test(Class[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String[]' to type 'java.lang.Class[]'. Value=['foo','bar'].") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String[]' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=['foo','bar'].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String[]' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=['foo','bar'].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.String[]' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=['foo','bar'].") + ; + new ConversionTest(pName, new String[]{"ONE","TWO"}) + .test(TestEnum[].class, "['ONE','TWO']") + ; + new ConversionTest(pName, new String[]{"true","false"}) + .test(boolean[].class, "[true,false]") + ; + new ConversionTest(pName, new String[]{"java.lang.String","java.lang.Integer"}) + .test(Class[].class, "['java.lang.String','java.lang.Integer']") + ; + + //-------------------------------------------------------------------------------- + // Class[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new Class[]{String.class,Integer.class}) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class[]' to type 'int'. Value=['java.lang.String','java.lang.Integer'].") + .test(String.class, "'[\\'java.lang.String\\',\\'java.lang.Integer\\']'") + .test(Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class[]' to type 'java.lang.Class'. Value=['java.lang.String','java.lang.Integer'].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class[]' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=['java.lang.String','java.lang.Integer'].") + .test(String[].class, "['java.lang.String','java.lang.Integer']") + .test(Class[].class, "['java.lang.String','java.lang.Integer']") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class[]' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=['java.lang.String','java.lang.Integer'].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class[]' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=['java.lang.String','java.lang.Integer'].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.lang.Class[]' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=['java.lang.String','java.lang.Integer'].") + ; + + //-------------------------------------------------------------------------------- + // enum[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new TestEnum[]{TestEnum.ONE,TestEnum.TWO}) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum[]' to type 'int'. Value=['ONE','TWO'].") + .test(String.class, "'[\\'ONE\\',\\'TWO\\']'") + .test(Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum[]' to type 'java.lang.Class'. Value=['ONE','TWO'].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum[]' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=['ONE','TWO'].") + .test(String[].class, "['ONE','TWO']") + .test(Class[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum[]' to type 'java.lang.Class[]'. Value=['ONE','TWO'].") + .test(TestEnum[].class, "['ONE','TWO']") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum[]' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=['ONE','TWO'].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'org.apache.juneau.PropertyStoreTest$TestEnum[]' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=['ONE','TWO'].") + ; + + //-------------------------------------------------------------------------------- + // Map<String,String> + //-------------------------------------------------------------------------------- + LinkedHashMap<String,String> m1 = new LinkedHashMap<String,String>(); + m1.put("foo","bar"); + new ConversionTest(pName, m1) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'int'. Value={foo:'bar'}.") + .test(String.class, "'{foo:\\'bar\\'}'") + .test(Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'java.lang.Class'. Value={foo:'bar'}.") + .test(TestEnum.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value={foo:'bar'}.") + .test(String[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'java.lang.String[]'. Value={foo:'bar'}.") + .test(Class[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'java.lang.Class[]'. Value={foo:'bar'}.") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value={foo:'bar'}.") + .testMap(String.class, String.class, "{foo:'bar'}") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value={foo:'bar'}.") + ; + + //-------------------------------------------------------------------------------- + // Map<Class,Class> + //-------------------------------------------------------------------------------- + LinkedHashMap<Class,Class> m2 = new LinkedHashMap<Class,Class>(); + m2.put(String.class, Integer.class); + new ConversionTest(pName, m2) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'int'. Value={'java.lang.String':'java.lang.Integer'}.") + .test(String.class, "'{\\'java.lang.String\\':\\'java.lang.Integer\\'}'") + .test(Class.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'java.lang.Class'. Value={'java.lang.String':'java.lang.Integer'}.") + .test(TestEnum.class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value={'java.lang.String':'java.lang.Integer'}.") + .test(String[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'java.lang.String[]'. Value={'java.lang.String':'java.lang.Integer'}.") + .test(Class[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'java.lang.Class[]'. Value={'java.lang.String':'java.lang.Integer'}.") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value={'java.lang.String':'java.lang.Integer'}.") + .testMap(String.class, String.class, "{'java.lang.String':'java.lang.Integer'}") + .testMap(Class.class, Class.class, "{'java.lang.String':'java.lang.Integer'}") + ; + + //-------------------------------------------------------------------------------- + // Namespace + //-------------------------------------------------------------------------------- + final Namespace n = new Namespace("foo","bar"); + new ConversionTest(pName, n) + .test(String.class, "'{name:\\'foo\\',uri:\\'bar\\'}'") + .test(Namespace.class, "{name:'foo',uri:'bar'}"); + + //-------------------------------------------------------------------------------- + // Namespace[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new Namespace[]{n}) + .test(String.class, "'[{name:\\'foo\\',uri:\\'bar\\'}]'") + .test(Namespace[].class, "[{name:'foo',uri:'bar'}]"); + + //-------------------------------------------------------------------------------- + // Map<Namespace,Namespace> + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new LinkedHashMap<Namespace,Namespace>(){{put(n,n);}}) + .testMap(Namespace.class, Namespace.class, "{'{name:\\'foo\\',uri:\\'bar\\'}':{name:'foo',uri:'bar'}}") + .testMap(String.class, String.class, "{'{name:\\'foo\\',uri:\\'bar\\'}':'{name:\\'foo\\',uri:\\'bar\\'}'}"); + } + + //==================================================================================================== + // Conversions on set properties + //==================================================================================================== + @Test + @SuppressWarnings({ "serial" }) + public void testConversionsOnSetProperties() throws Exception { + String pName = "A.a.set"; + + //-------------------------------------------------------------------------------- + // boolean + //-------------------------------------------------------------------------------- + new ConversionTest(pName, true) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'int'. Value=[true].") + .test(String.class, "'[true]'") + .test(Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class'. Value=[true].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=[true].") + .test(String[].class, "['true']") + .test(Class[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class[]'. Value=[true].") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=[true].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=[true].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=[true].") + ; + + //-------------------------------------------------------------------------------- + // int + //-------------------------------------------------------------------------------- + new ConversionTest(pName, 123) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'int'. Value=[123].") + .test(String.class, "'[123]'") + .test(Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class'. Value=[123].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=[123].") + .test(String[].class, "['123']") + .test(Class[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class[]'. Value=[123].") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=[123].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=[123].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=[123].") + ; + + //-------------------------------------------------------------------------------- + // Class + //-------------------------------------------------------------------------------- + new ConversionTest(pName, String.class) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'int'. Value=['java.lang.String'].") + .test(String.class, "'[\\'java.lang.String\\']'") + .test(Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class'. Value=['java.lang.String'].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=['java.lang.String'].") + .test(String[].class, "['java.lang.String']") + .test(Class[].class, "['java.lang.String']") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=['java.lang.String'].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=['java.lang.String'].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=['java.lang.String'].") + ; + + //-------------------------------------------------------------------------------- + // String + //-------------------------------------------------------------------------------- + new ConversionTest(pName, "foo") + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'int'. Value=['foo'].") + .test(String.class, "'[\\'foo\\']'") + .test(Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class'. Value=['foo'].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=['foo'].") + .test(String[].class, "['foo']") + .test(Class[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class[]'. Value=['foo'].") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=['foo'].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=['foo'].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=['foo'].") + ; + new ConversionTest(pName, Arrays.asList("java.lang.String")) + .test(Class[].class, "['java.lang.String']") + ; + new ConversionTest(pName, Arrays.asList("true")) + .test(boolean[].class, "[true]") + ; + new ConversionTest(pName, Arrays.asList("ONE")) + .test(TestEnum[].class, "['ONE']") + ; + new ConversionTest(pName, Arrays.asList("123")) + .test(int[].class, "[123]") + ; + + //-------------------------------------------------------------------------------- + // enum + //-------------------------------------------------------------------------------- + new ConversionTest(pName, TestEnum.ONE) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'int'. Value=['ONE'].") + .test(String.class, "'[\\'ONE\\']'") + .test(Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class'. Value=['ONE'].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=['ONE'].") + .test(String[].class, "['ONE']") + .test(Class[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class[]'. Value=['ONE'].") + .test(TestEnum[].class, "['ONE']") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=['ONE'].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=['ONE'].") + ; + + //-------------------------------------------------------------------------------- + // String[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new String[]{"foo","bar"}) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'int'. Value=['bar','foo'].") + .test(String.class, "'[\\'bar\\',\\'foo\\']'") + .test(Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class'. Value=['bar','foo'].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=['bar','foo'].") + .test(String[].class, "['bar','foo']") + .test(Class[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class[]'. Value=['bar','foo'].") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=['bar','foo'].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=['bar','foo'].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=['bar','foo'].") + ; + new ConversionTest(pName, new String[]{"ONE","TWO"}) + .test(TestEnum[].class, "['ONE','TWO']") + ; + new ConversionTest(pName, new String[]{"true","false"}) + .test(boolean[].class, "[false,true]") + ; + new ConversionTest(pName, new String[]{"java.lang.String","java.lang.Integer"}) + .test(Class[].class, "['java.lang.Integer','java.lang.String']") + ; + + //-------------------------------------------------------------------------------- + // Class[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new Class[]{String.class,Integer.class}) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'int'. Value=['java.lang.Integer','java.lang.String'].") + .test(String.class, "'[\\'java.lang.Integer\\',\\'java.lang.String\\']'") + .test(Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class'. Value=['java.lang.Integer','java.lang.String'].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=['java.lang.Integer','java.lang.String'].") + .test(String[].class, "['java.lang.Integer','java.lang.String']") + .test(Class[].class, "['java.lang.Integer','java.lang.String']") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=['java.lang.Integer','java.lang.String'].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=['java.lang.Integer','java.lang.String'].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=['java.lang.Integer','java.lang.String'].") + ; + + //-------------------------------------------------------------------------------- + // enum[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new TestEnum[]{TestEnum.ONE,TestEnum.TWO}) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'int'. Value=['ONE','TWO'].") + .test(String.class, "'[\\'ONE\\',\\'TWO\\']'") + .test(Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class'. Value=['ONE','TWO'].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=['ONE','TWO'].") + .test(String[].class, "['ONE','TWO']") + .test(Class[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class[]'. Value=['ONE','TWO'].") + .test(TestEnum[].class, "['ONE','TWO']") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=['ONE','TWO'].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=['ONE','TWO'].") + ; + + //-------------------------------------------------------------------------------- + // Map<String,String> + //-------------------------------------------------------------------------------- + LinkedHashMap<String,String> m1 = new LinkedHashMap<String,String>(); + m1.put("foo","bar"); + new ConversionTest(pName, m1) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'int'. Value=[{foo:'bar'}].") + .test(String.class, "'[{foo:\\'bar\\'}]'") + .test(Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class'. Value=[{foo:'bar'}].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=[{foo:'bar'}].") + .test(String[].class, "['{foo:\\'bar\\'}']") + .test(Class[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class[]'. Value=[{foo:'bar'}].") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=[{foo:'bar'}].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=[{foo:'bar'}].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=[{foo:'bar'}].") + ; + + //-------------------------------------------------------------------------------- + // Map<Class,Class> + //-------------------------------------------------------------------------------- + LinkedHashMap<Class,Class> m2 = new LinkedHashMap<Class,Class>(); + m2.put(String.class, Integer.class); + new ConversionTest(pName, m2) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'int'. Value=[{'java.lang.String':'java.lang.Integer'}].") + .test(String.class, "'[{\\'java.lang.String\\':\\'java.lang.Integer\\'}]'") + .test(Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class'. Value=[{'java.lang.String':'java.lang.Integer'}].") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value=[{'java.lang.String':'java.lang.Integer'}].") + .test(String[].class, "['{\\'java.lang.String\\':\\'java.lang.Integer\\'}']") + .test(Class[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.lang.Class[]'. Value=[{'java.lang.String':'java.lang.Integer'}].") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value=[{'java.lang.String':'java.lang.Integer'}].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=[{'java.lang.String':'java.lang.Integer'}].") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value=[{'java.lang.String':'java.lang.Integer'}].") + ; + + //-------------------------------------------------------------------------------- + // Namespace + //-------------------------------------------------------------------------------- + final Namespace n = new Namespace("foo","bar"); + new ConversionTest(pName, Arrays.asList(n)) + .test(String.class, "'[{name:\\'foo\\',uri:\\'bar\\'}]'") + .test(Namespace.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.xml.Namespace'. Value=[{name:'foo',uri:'bar'}]."); + + //-------------------------------------------------------------------------------- + // Namespace[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new Namespace[]{n}) + .test(String.class, "'[{name:\\'foo\\',uri:\\'bar\\'}]'") + .test(Namespace[].class, "[{name:'foo',uri:'bar'}]"); + + //-------------------------------------------------------------------------------- + // Map<Namespace,Namespace> + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new LinkedHashMap<Namespace,Namespace>(){{put(n,n);}}) + .testMap(Namespace.class, Namespace.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<org.apache.juneau.xml.Namespace,org.apache.juneau.xml.Namespace>'. Value=[{'{name:\\'foo\\',uri:\\'bar\\'}':{name:'foo',uri:'bar'}}].") + .testMap(String.class, String.class, "Could not retrieve property store property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=[{'{name:\\'foo\\',uri:\\'bar\\'}':{name:'foo',uri:'bar'}}]."); + } + + + //==================================================================================================== + // Conversions on map properties + //==================================================================================================== + @Test + @SuppressWarnings({ "serial" }) + public void testConversionsOnMapProperties() throws Exception { + String pName = "A.a.map"; + + //-------------------------------------------------------------------------------- + // boolean + //-------------------------------------------------------------------------------- + new ConversionTest(pName, true) + .test(boolean.class, "Cannot put value true (java.lang.Boolean) to property 'A.a.map' (MAP).") + ; + + //-------------------------------------------------------------------------------- + // int + //-------------------------------------------------------------------------------- + new ConversionTest(pName, 123) + .test(int.class, "Cannot put value 123 (java.lang.Integer) to property 'A.a.map' (MAP).") + ; + + //-------------------------------------------------------------------------------- + // Class + //-------------------------------------------------------------------------------- + new ConversionTest(pName, String.class) + .test(Class.class, "Cannot put value 'java.lang.String' (java.lang.Class) to property 'A.a.map' (MAP).") + ; + + //-------------------------------------------------------------------------------- + // String + //-------------------------------------------------------------------------------- + new ConversionTest(pName, "foo") + .test(String.class, "Cannot put value 'foo' (java.lang.String) to property 'A.a.map' (MAP).") + ; + + //-------------------------------------------------------------------------------- + // enum + //-------------------------------------------------------------------------------- + new ConversionTest(pName, TestEnum.ONE) + .test(TestEnum.class, "Cannot put value 'ONE' (org.apache.juneau.PropertyStoreTest$TestEnum) to property 'A.a.map' (MAP).") + ; + + //-------------------------------------------------------------------------------- + // String[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new String[]{"foo","bar"}) + .test(String[].class, "Cannot put value ['foo','bar'] (java.lang.String[]) to property 'A.a.map' (MAP).") + ; + + //-------------------------------------------------------------------------------- + // Class[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new Class[]{String.class,Integer.class}) + .test(Class[].class, "Cannot put value ['java.lang.String','java.lang.Integer'] (java.lang.Class[]) to property 'A.a.map' (MAP).") + ; + + //-------------------------------------------------------------------------------- + // enum[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new TestEnum[]{TestEnum.ONE,TestEnum.TWO}) + .test(TestEnum[].class, "Cannot put value ['ONE','TWO'] (org.apache.juneau.PropertyStoreTest$TestEnum[]) to property 'A.a.map' (MAP).") + ; + + //-------------------------------------------------------------------------------- + // Map<String,String> + //-------------------------------------------------------------------------------- + LinkedHashMap<String,String> m1 = new LinkedHashMap<String,String>(); + m1.put("foo","bar"); + new ConversionTest(pName, m1) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'int'. Value={foo:'bar'}.") + .test(String.class, "'{foo:\\'bar\\'}'") + .test(Class.class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'java.lang.Class'. Value={foo:'bar'}.") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value={foo:'bar'}.") + .test(String[].class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'java.lang.String[]'. Value={foo:'bar'}.") + .test(Class[].class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'java.lang.Class[]'. Value={foo:'bar'}.") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value={foo:'bar'}.") + .testMap(String.class, String.class, "{foo:'bar'}") + .testMap(Class.class, Class.class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'java.util.LinkedHashMap<java.lang.Class,java.lang.Class>'. Value={foo:'bar'}.") + ; + + //-------------------------------------------------------------------------------- + // Map<Class,Class> + //-------------------------------------------------------------------------------- + LinkedHashMap<Class,Class> m2 = new LinkedHashMap<Class,Class>(); + m2.put(String.class, Integer.class); + new ConversionTest(pName, m2) + .test(boolean.class, "false") + .test(int.class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'int'. Value={'java.lang.String':'java.lang.Integer'}.") + .test(String.class, "'{\\'java.lang.String\\':\\'java.lang.Integer\\'}'") + .test(Class.class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'java.lang.Class'. Value={'java.lang.String':'java.lang.Integer'}.") + .test(TestEnum.class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'org.apache.juneau.PropertyStoreTest$TestEnum'. Value={'java.lang.String':'java.lang.Integer'}.") + .test(String[].class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'java.lang.String[]'. Value={'java.lang.String':'java.lang.Integer'}.") + .test(Class[].class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'java.lang.Class[]'. Value={'java.lang.String':'java.lang.Integer'}.") + .test(TestEnum[].class, "Could not retrieve property store property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'org.apache.juneau.PropertyStoreTest$TestEnum[]'. Value={'java.lang.String':'java.lang.Integer'}.") + .testMap(String.class, String.class, "{'java.lang.String':'java.lang.Integer'}") + .testMap(Class.class, Class.class, "{'java.lang.String':'java.lang.Integer'}") + ; + + //-------------------------------------------------------------------------------- + // Namespace + //-------------------------------------------------------------------------------- + final Namespace n = new Namespace("foo","bar"); + new ConversionTest(pName, Arrays.asList(n)) + .test(String.class, "Cannot put value [{name:'foo',uri:'bar'}] (java.util.Arrays$ArrayList) to property 'A.a.map' (MAP).") + ; + + //-------------------------------------------------------------------------------- + // Namespace[] + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new Namespace[]{n}) + .test(String.class, "Cannot put value [{name:'foo',uri:'bar'}] (org.apache.juneau.xml.Namespace[]) to property 'A.a.map' (MAP).") + ; + + //-------------------------------------------------------------------------------- + // Map<Namespace,Namespace> + //-------------------------------------------------------------------------------- + new ConversionTest(pName, new LinkedHashMap<Namespace,Namespace>(){{put(n,n);}}) + .testMap(Namespace.class, Namespace.class, "{'{name:\\'foo\\',uri:\\'bar\\'}':{name:'foo',uri:'bar'}}") + .testMap(String.class, String.class, "{'{name:\\'foo\\',uri:\\'bar\\'}':'{name:\\'foo\\',uri:\\'bar\\'}'}"); + } + + public enum TestEnum { + ONE,TWO,TREE; + } + + //==================================================================================================== + // testSystemPropertyDefaults() + //==================================================================================================== + @Test + public void testSystemPropertyDefaults() { + System.setProperty("Foo.f1", "true"); + System.setProperty("Foo.f2", "123"); + System.setProperty("Foo.f3", "TWO"); + + PropertyStore f = PropertyStore.create(); + + assertObjectEquals("true", f.getProperty("Foo.f1", boolean.class, false)); + assertObjectEquals("123", f.getProperty("Foo.f2", int.class, 0)); + assertObjectEquals("'TWO'", f.getProperty("Foo.f3", TestEnum.class, TestEnum.ONE)); + + f.setProperty("Foo.f1", false); + f.setProperty("Foo.f2", 456); + f.setProperty("Foo.f3", TestEnum.TREE); + + assertObjectEquals("false", f.getProperty("Foo.f1", boolean.class, false)); + assertObjectEquals("456", f.getProperty("Foo.f2", int.class, 0)); + assertObjectEquals("'TREE'", f.getProperty("Foo.f3", TestEnum.class, TestEnum.ONE)); + } + +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/TestUtils.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/TestUtils.java b/juneau-core-test/src/test/java/org/apache/juneau/TestUtils.java index a94fcca..ae075e8 100755 --- a/juneau-core-test/src/test/java/org/apache/juneau/TestUtils.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/TestUtils.java @@ -37,21 +37,29 @@ import org.xml.sax.*; @SuppressWarnings({"javadoc"}) public class TestUtils { - private static JsonSerializer js = new JsonSerializer.Simple() - .setTrimNullProperties(false); - - private static JsonSerializer jsSorted = new JsonSerializer.Simple() - .setSortCollections(true) - .setSortMaps(true) - .setTrimNullProperties(false); - - - private static JsonSerializer js2 = new JsonSerializer.Simple() - .addPojoSwaps(IteratorSwap.class, EnumerationSwap.class); - - private static JsonSerializer js3 = new JsonSerializer.Simple() - .addPojoSwaps(IteratorSwap.class, EnumerationSwap.class) - .setSortProperties(true); + private static JsonSerializer js = new JsonSerializerBuilder() + .simple() + .trimNullProperties(false) + .build(); + + private static JsonSerializer jsSorted = new JsonSerializerBuilder() + .simple() + .sortCollections(true) + .sortMaps(true) + .trimNullProperties(false) + .build(); + + + private static JsonSerializer js2 = new JsonSerializerBuilder() + .simple() + .pojoSwaps(IteratorSwap.class, EnumerationSwap.class) + .build(); + + private static JsonSerializer js3 = new JsonSerializerBuilder() + .simple() + .pojoSwaps(IteratorSwap.class, EnumerationSwap.class) + .sortProperties(true) + .build(); /** * Verifies that two objects are equivalent. @@ -219,7 +227,7 @@ public class TestUtils { * Test whitespace and generated schema. */ public static void validateXml(Object o, XmlSerializer s) throws Exception { - s = s.clone().setUseWhitespace(true).setEnableNamespaces(true).setAddNamespaceUrisToRoot(true); + s = s.builder().ws().ns().addNamespaceUrisToRoot(true).build(); String xml = s.serialize(o); String xmlSchema = null; http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/VisibilityTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/VisibilityTest.java b/juneau-core-test/src/test/java/org/apache/juneau/VisibilityTest.java index cff0fcb..3101903 100755 --- a/juneau-core-test/src/test/java/org/apache/juneau/VisibilityTest.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/VisibilityTest.java @@ -27,131 +27,131 @@ public class VisibilityTest { //==================================================================================================== @Test public void testClassDefault() throws Exception { - JsonSerializer s1 = JsonSerializer.DEFAULT_LAX.clone().setBeansRequireSomeProperties(false); - JsonSerializer s2 = JsonSerializer.DEFAULT_LAX.clone().setBeansRequireSomeProperties(false).setBeanClassVisibility(PROTECTED); - JsonSerializer s3 = JsonSerializer.DEFAULT_LAX.clone().setBeansRequireSomeProperties(false).setBeanClassVisibility(Visibility.DEFAULT); - JsonSerializer s4 = JsonSerializer.DEFAULT_LAX.clone().setBeansRequireSomeProperties(false).setBeanClassVisibility(PRIVATE); + JsonSerializerBuilder s1 = new JsonSerializerBuilder().simple().beansRequireSomeProperties(false); + JsonSerializerBuilder s2 = new JsonSerializerBuilder().simple().beansRequireSomeProperties(false).beanClassVisibility(PROTECTED); + JsonSerializerBuilder s3 = new JsonSerializerBuilder().simple().beansRequireSomeProperties(false).beanClassVisibility(Visibility.DEFAULT); + JsonSerializerBuilder s4 = new JsonSerializerBuilder().simple().beansRequireSomeProperties(false).beanClassVisibility(PRIVATE); A1 a1 = A1.create(); String r; - s1.setBeanFieldVisibility(NONE); - s2.setBeanFieldVisibility(NONE); - s3.setBeanFieldVisibility(NONE); - s4.setBeanFieldVisibility(NONE); + s1.beanFieldVisibility(NONE); + s2.beanFieldVisibility(NONE); + s3.beanFieldVisibility(NONE); + s4.beanFieldVisibility(NONE); - r = s1.serialize(a1); + r = s1.build().serialize(a1); assertEquals("{f5:5}", r); - r = s2.serialize(a1); + r = s2.build().serialize(a1); assertEquals("{f5:5}", r); - r = s3.serialize(a1); + r = s3.build().serialize(a1); assertEquals("{f5:5}", r); - r = s4.serialize(a1); + r = s4.build().serialize(a1); assertEquals("{f5:5}", r); - s1.setBeanFieldVisibility(PUBLIC); - s2.setBeanFieldVisibility(PUBLIC); - s3.setBeanFieldVisibility(PUBLIC); - s4.setBeanFieldVisibility(PUBLIC); + s1.beanFieldVisibility(PUBLIC); + s2.beanFieldVisibility(PUBLIC); + s3.beanFieldVisibility(PUBLIC); + s4.beanFieldVisibility(PUBLIC); - r = s1.serialize(a1); + r = s1.build().serialize(a1); assertEquals("{f1:1,f5:5,g2:{f1:1,f5:5},g3:'A3',g4:'A4',g5:'A5'}", r); - r = s2.serialize(a1); + r = s2.build().serialize(a1); assertEquals("{f1:1,f5:5,g2:{f1:1,f5:5},g3:{f1:1,f5:5},g4:'A4',g5:'A5'}", r); - r = s3.serialize(a1); + r = s3.build().serialize(a1); assertEquals("{f1:1,f5:5,g2:{f1:1,f5:5},g3:{f1:1,f5:5},g4:{f1:1,f5:5},g5:'A5'}", r); - r = s4.serialize(a1); + r = s4.build().serialize(a1); assertEquals("{f1:1,f5:5,g2:{f1:1,f5:5},g3:{f1:1,f5:5},g4:{f1:1,f5:5},g5:{f1:1,f5:5}}", r); - s1.setBeanFieldVisibility(PROTECTED); - s2.setBeanFieldVisibility(PROTECTED); - s3.setBeanFieldVisibility(PROTECTED); - s4.setBeanFieldVisibility(PROTECTED); + s1.beanFieldVisibility(PROTECTED); + s2.beanFieldVisibility(PROTECTED); + s3.beanFieldVisibility(PROTECTED); + s4.beanFieldVisibility(PROTECTED); - r = s1.serialize(a1); + r = s1.build().serialize(a1); assertEquals("{f1:1,f2:2,f5:5,g2:{f1:1,f2:2,f5:5},g3:'A3',g4:'A4',g5:'A5'}", r); - r = s2.serialize(a1); + r = s2.build().serialize(a1); assertEquals("{f1:1,f2:2,f5:5,g2:{f1:1,f2:2,f5:5},g3:{f1:1,f2:2,f5:5},g4:'A4',g5:'A5'}", r); - r = s3.serialize(a1); + r = s3.build().serialize(a1); assertEquals("{f1:1,f2:2,f5:5,g2:{f1:1,f2:2,f5:5},g3:{f1:1,f2:2,f5:5},g4:{f1:1,f2:2,f5:5},g5:'A5'}", r); - r = s4.serialize(a1); + r = s4.build().serialize(a1); assertEquals("{f1:1,f2:2,f5:5,g2:{f1:1,f2:2,f5:5},g3:{f1:1,f2:2,f5:5},g4:{f1:1,f2:2,f5:5},g5:{f1:1,f2:2,f5:5}}", r); - s1.setBeanFieldVisibility(Visibility.DEFAULT); - s2.setBeanFieldVisibility(Visibility.DEFAULT); - s3.setBeanFieldVisibility(Visibility.DEFAULT); - s4.setBeanFieldVisibility(Visibility.DEFAULT); + s1.beanFieldVisibility(Visibility.DEFAULT); + s2.beanFieldVisibility(Visibility.DEFAULT); + s3.beanFieldVisibility(Visibility.DEFAULT); + s4.beanFieldVisibility(Visibility.DEFAULT); - r = s1.serialize(a1); + r = s1.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f5:5,g2:{f1:1,f2:2,f3:3,f5:5},g3:'A3',g4:'A4',g5:'A5'}", r); - r = s2.serialize(a1); + r = s2.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f5:5,g2:{f1:1,f2:2,f3:3,f5:5},g3:{f1:1,f2:2,f3:3,f5:5},g4:'A4',g5:'A5'}", r); - r = s3.serialize(a1); + r = s3.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f5:5,g2:{f1:1,f2:2,f3:3,f5:5},g3:{f1:1,f2:2,f3:3,f5:5},g4:{f1:1,f2:2,f3:3,f5:5},g5:'A5'}", r); - r = s4.serialize(a1); + r = s4.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f5:5,g2:{f1:1,f2:2,f3:3,f5:5},g3:{f1:1,f2:2,f3:3,f5:5},g4:{f1:1,f2:2,f3:3,f5:5},g5:{f1:1,f2:2,f3:3,f5:5}}", r); - s1.setBeanFieldVisibility(PRIVATE); - s2.setBeanFieldVisibility(PRIVATE); - s3.setBeanFieldVisibility(PRIVATE); - s4.setBeanFieldVisibility(PRIVATE); + s1.beanFieldVisibility(PRIVATE); + s2.beanFieldVisibility(PRIVATE); + s3.beanFieldVisibility(PRIVATE); + s4.beanFieldVisibility(PRIVATE); - r = s1.serialize(a1); + r = s1.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,f5:5,g2:{f1:1,f2:2,f3:3,f4:4,f5:5},g3:'A3',g4:'A4',g5:'A5'}", r); - r = s2.serialize(a1); + r = s2.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,f5:5,g2:{f1:1,f2:2,f3:3,f4:4,f5:5},g3:{f1:1,f2:2,f3:3,f4:4,f5:5},g4:'A4',g5:'A5'}", r); - r = s3.serialize(a1); + r = s3.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,f5:5,g2:{f1:1,f2:2,f3:3,f4:4,f5:5},g3:{f1:1,f2:2,f3:3,f4:4,f5:5},g4:{f1:1,f2:2,f3:3,f4:4,f5:5},g5:'A5'}", r); - r = s4.serialize(a1); + r = s4.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,f5:5,g2:{f1:1,f2:2,f3:3,f4:4,f5:5},g3:{f1:1,f2:2,f3:3,f4:4,f5:5},g4:{f1:1,f2:2,f3:3,f4:4,f5:5},g5:{f1:1,f2:2,f3:3,f4:4,f5:5}}", r); - s1.setMethodVisibility(NONE); - s2.setMethodVisibility(NONE); - s3.setMethodVisibility(NONE); - s4.setMethodVisibility(NONE); + s1.methodVisibility(NONE); + s2.methodVisibility(NONE); + s3.methodVisibility(NONE); + s4.methodVisibility(NONE); - r = s1.serialize(a1); + r = s1.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,g2:{f1:1,f2:2,f3:3,f4:4},g3:'A3',g4:'A4',g5:'A5'}", r); - r = s2.serialize(a1); + r = s2.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,g2:{f1:1,f2:2,f3:3,f4:4},g3:{f1:1,f2:2,f3:3,f4:4},g4:'A4',g5:'A5'}", r); - r = s3.serialize(a1); + r = s3.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,g2:{f1:1,f2:2,f3:3,f4:4},g3:{f1:1,f2:2,f3:3,f4:4},g4:{f1:1,f2:2,f3:3,f4:4},g5:'A5'}", r); - r = s4.serialize(a1); + r = s4.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,g2:{f1:1,f2:2,f3:3,f4:4},g3:{f1:1,f2:2,f3:3,f4:4},g4:{f1:1,f2:2,f3:3,f4:4},g5:{f1:1,f2:2,f3:3,f4:4}}", r); - s1.setMethodVisibility(PROTECTED); - s2.setMethodVisibility(PROTECTED); - s3.setMethodVisibility(PROTECTED); - s4.setMethodVisibility(PROTECTED); + s1.methodVisibility(PROTECTED); + s2.methodVisibility(PROTECTED); + s3.methodVisibility(PROTECTED); + s4.methodVisibility(PROTECTED); - r = s1.serialize(a1); + r = s1.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6,g2:{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6},g3:'A3',g4:'A4',g5:'A5'}", r); - r = s2.serialize(a1); + r = s2.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6,g2:{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6},g3:{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6},g4:'A4',g5:'A5'}", r); - r = s3.serialize(a1); + r = s3.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6,g2:{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6},g3:{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6},g4:{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6},g5:'A5'}", r); - r = s4.serialize(a1); + r = s4.build().serialize(a1); assertEquals("{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6,g2:{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6},g3:{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6},g4:{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6},g5:{f1:1,f2:2,f3:3,f4:4,f5:5,f6:6}}", r); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/XmlValidatorParser.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/XmlValidatorParser.java b/juneau-core-test/src/test/java/org/apache/juneau/XmlValidatorParser.java index 34a3ff9..ed182dd 100755 --- a/juneau-core-test/src/test/java/org/apache/juneau/XmlValidatorParser.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/XmlValidatorParser.java @@ -30,7 +30,7 @@ import org.apache.juneau.xml.*; public class XmlValidatorParser extends XmlParser { public XmlValidatorParser() { - super(); + super(PropertyStore.create()); } @Override /* Parser */ @@ -66,9 +66,4 @@ public class XmlValidatorParser extends XmlParser { parser.nextTag(); return parser; } - - @Override /* Lockable */ - public XmlValidatorParser clone() { - return (XmlValidatorParser)super.clone(); - } } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/XmlValidatorParserBuilder.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/XmlValidatorParserBuilder.java b/juneau-core-test/src/test/java/org/apache/juneau/XmlValidatorParserBuilder.java new file mode 100644 index 0000000..f7ba051 --- /dev/null +++ b/juneau-core-test/src/test/java/org/apache/juneau/XmlValidatorParserBuilder.java @@ -0,0 +1,26 @@ +// *************************************************************************************************************************** +// * 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 org.apache.juneau.xml.*; + +public class XmlValidatorParserBuilder extends XmlParserBuilder { + + public XmlValidatorParserBuilder() { + super(PropertyStore.create()); + } + + public XmlValidatorParser build() { + return new XmlValidatorParser(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/a/rttests/RoundTripAddClassAttrsTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/a/rttests/RoundTripAddClassAttrsTest.java b/juneau-core-test/src/test/java/org/apache/juneau/a/rttests/RoundTripAddClassAttrsTest.java index cbf7630..d8e2388 100755 --- a/juneau-core-test/src/test/java/org/apache/juneau/a/rttests/RoundTripAddClassAttrsTest.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/a/rttests/RoundTripAddClassAttrsTest.java @@ -24,6 +24,7 @@ import org.apache.juneau.json.*; import org.apache.juneau.msgpack.*; import org.apache.juneau.parser.*; import org.apache.juneau.serializer.*; +import org.apache.juneau.uon.*; import org.apache.juneau.urlencoding.*; import org.apache.juneau.xml.*; import org.junit.*; @@ -41,68 +42,68 @@ public class RoundTripAddClassAttrsTest extends RoundTripTest { return Arrays.asList(new Object[][] { { /* 0 */ "JsonSerializer.DEFAULT/JsonParser.DEFAULT", - new JsonSerializer().setAddBeanTypeProperties(true), - new JsonParser().setUseInterfaceProxies(false), + new JsonSerializerBuilder().addBeanTypeProperties(true), + new JsonParserBuilder().useInterfaceProxies(false), 0 }, { /* 1 */ "JsonSerializer.DEFAULT_LAX/JsonParser.DEFAULT", - new JsonSerializer.Simple().setAddBeanTypeProperties(true), - new JsonParser().setUseInterfaceProxies(false), + new JsonSerializerBuilder().simple().addBeanTypeProperties(true), + new JsonParserBuilder().useInterfaceProxies(false), 0 }, { /* 2 */ "JsonSerializer.DEFAULT_SQ/JsonParser.DEFAULT", - new JsonSerializer.Simple().setAddBeanTypeProperties(true), - new JsonParser().setUseInterfaceProxies(false), + new JsonSerializerBuilder().simple().addBeanTypeProperties(true), + new JsonParserBuilder().useInterfaceProxies(false), 0 }, { /* 3 */ "XmlSerializer.DEFAULT/XmlParser.DEFAULT", - new XmlSerializer().setAddBeanTypeProperties(true), - new XmlParser().setUseInterfaceProxies(false), + new XmlSerializerBuilder().addBeanTypeProperties(true), + new XmlParserBuilder().useInterfaceProxies(false), CHECK_XML_WHITESPACE | VALIDATE_XML }, { /* 4 */ "HtmlSerializer.DEFAULT/HtmlParser.DEFAULT", - new HtmlSerializer().setAddBeanTypeProperties(true), - new HtmlParser().setUseInterfaceProxies(false), + new HtmlSerializerBuilder().addBeanTypeProperties(true), + new HtmlParserBuilder().useInterfaceProxies(false), CHECK_XML_WHITESPACE }, { /* 5 */ "UonSerializer.DEFAULT_ENCODING/UonParser.DEFAULT_DECODING", - new UonSerializer.Encoding().setAddBeanTypeProperties(true), - new UonParser.Decoding().setUseInterfaceProxies(false), + new UonSerializerBuilder().encoding().addBeanTypeProperties(true), + new UonParserBuilder().decoding().useInterfaceProxies(false), 0 }, { /* 6 */ "UonSerializer.DEFAULT/UonParser.DEFAULT", - new UonSerializer().setAddBeanTypeProperties(true), - new UonParser().setUseInterfaceProxies(false), + new UonSerializerBuilder().addBeanTypeProperties(true), + new UonParserBuilder().useInterfaceProxies(false), 0 }, { /* 7 */ "UrlEncodingSerializer.DEFAULT/UrlEncodingParser.DEFAULT", - new UrlEncodingSerializer().setAddBeanTypeProperties(true), - new UrlEncodingParser().setUseInterfaceProxies(false), + new UrlEncodingSerializerBuilder().addBeanTypeProperties(true), + new UrlEncodingParserBuilder().useInterfaceProxies(false), 0 }, { /* 8 */ "RdfSerializer.Xml/RdfParser.Xml", - new RdfSerializer.Xml().setAddBeanTypeProperties(true), - new RdfParser.Xml().setUseInterfaceProxies(false), + new RdfSerializerBuilder().addBeanTypeProperties(true), + new RdfParserBuilder().useInterfaceProxies(false), 0 }, { /* 9 */ "MsgPackSerializer.DEFAULT/MsgPackParser.DEFAULT", - new MsgPackSerializer().setAddBeanTypeProperties(true), - new MsgPackParser().setUseInterfaceProxies(false), + new MsgPackSerializerBuilder().addBeanTypeProperties(true), + new MsgPackParserBuilder().useInterfaceProxies(false), 0 } }); } - public RoundTripAddClassAttrsTest(String label, Serializer s, Parser p, int flags) throws Exception { + public RoundTripAddClassAttrsTest(String label, SerializerBuilder s, ParserBuilder p, int flags) throws Exception { super(label, s, p, flags); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java b/juneau-core-test/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java index 0c4eef6..dfe8dd6 100755 --- a/juneau-core-test/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/a/rttests/RoundTripBeanInheritanceTest.java @@ -27,7 +27,7 @@ import org.junit.*; @SuppressWarnings("javadoc") public class RoundTripBeanInheritanceTest extends RoundTripTest { - public RoundTripBeanInheritanceTest(String label, Serializer s, Parser p, int flags) throws Exception { + public RoundTripBeanInheritanceTest(String label, SerializerBuilder s, ParserBuilder p, int flags) throws Exception { super(label, s, p, flags); }
