You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2017/03/10 16:51:28 UTC
[32/34] incubator-juneau git commit: Add builder classes for all
serializers and parsers.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/BeanMapTest.java
----------------------------------------------------------------------
diff --git a/juneau-core-test/src/test/java/org/apache/juneau/BeanMapTest.java b/juneau-core-test/src/test/java/org/apache/juneau/BeanMapTest.java
index 0b328db..a254525 100755
--- a/juneau-core-test/src/test/java/org/apache/juneau/BeanMapTest.java
+++ b/juneau-core-test/src/test/java/org/apache/juneau/BeanMapTest.java
@@ -22,6 +22,7 @@ import org.apache.juneau.html.*;
import org.apache.juneau.json.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.transforms.*;
+import org.apache.juneau.uon.*;
import org.apache.juneau.urlencoding.*;
import org.apache.juneau.utils.*;
import org.apache.juneau.xml.*;
@@ -30,11 +31,11 @@ import org.junit.*;
@SuppressWarnings({"unchecked","rawtypes","serial","javadoc"})
public class BeanMapTest {
- JsonSerializer serializer = JsonSerializer.DEFAULT_LAX.clone();
+ JsonSerializer serializer = JsonSerializer.DEFAULT_LAX;
- BeanContext bc = ContextFactory.create()
- .addToBeanDictionary(MyBeanDictionaryMap.class)
- .addPojoSwaps(CalendarSwap.ISO8601DTZ.class)
+ BeanContext bc = PropertyStore.create()
+ .setBeanDictionary(MyBeanDictionaryMap.class)
+ .setPojoSwaps(CalendarSwap.ISO8601DTZ.class)
.getBeanContext();
BeanSession session = bc.createSession();
@@ -478,7 +479,7 @@ public class BeanMapTest {
m.put("b", new D2());
assertEquals("default", t.b.s);
- JsonParser p = new JsonParser().addToBeanDictionary(D2.class);
+ JsonParser p = new JsonParserBuilder().beanDictionary(D2.class).build();
m.put("lb1", new ObjectList("[{_type:'D2',s:'foobar'}]", p));
assertEquals(ObjectList.class.getName(), t.lb1.getClass().getName());
assertEquals(D2.class.getName(), t.lb1.get(0).getClass().getName());
@@ -664,7 +665,7 @@ public class BeanMapTest {
assertEquals(HEnum.THREE, t7.getEnum2());
// Create instance directly from JSON.
- JsonParser p = new JsonParser().addToBeanDictionary(H.class);
+ JsonParser p = new JsonParserBuilder().beanDictionary(H.class).build();
t7 = (H)p.parse("{_type:'H',enum1:'THREE',enum2:'ONE'}", Object.class);
assertEquals("{_type:'H',enum1:'THREE',enum2:'ONE'}", serializer.serialize(t7));
assertEquals(HEnum.THREE, t7.enum1);
@@ -956,7 +957,7 @@ public class BeanMapTest {
// JSON
String json = "{baz:789,foo:123,bar:456}";
- p = new JsonParser().setIgnoreUnknownBeanProperties(true);
+ p = new JsonParserBuilder().ignoreUnknownBeanProperties(true).build();
t = p.parse(json, O.class);
assertEquals(123, t.foo);
@@ -970,7 +971,7 @@ public class BeanMapTest {
// XML
String xml = "<object><baz type='number'>789</baz><foo type='number'>123</foo><bar type='number'>456</bar></object>";
- p = new XmlParser().setIgnoreUnknownBeanProperties(true);
+ p = new XmlParserBuilder().ignoreUnknownBeanProperties(true).build();
t = p.parse(xml, O.class);
assertEquals(123, t.foo);
@@ -984,7 +985,7 @@ public class BeanMapTest {
// HTML
String html = "<table _type='object'><tr><th><string>key</string></th><th><string>value</string></th></tr><tr><td><string>baz</string></td><td><number>789</number></td></tr><tr><td><string>foo</string></td><td><number>123</number></td></tr><tr><td><string>bar</string></td><td><number>456</number></td></tr></table>";
- p = new HtmlParser().setIgnoreUnknownBeanProperties(true);
+ p = new HtmlParserBuilder().ignoreUnknownBeanProperties(true).build();
t = p.parse(html, O.class);
assertEquals(123, t.foo);
@@ -998,12 +999,12 @@ public class BeanMapTest {
// UON
String uon = "(baz=789,foo=123,bar=456)";
- p = new UonParser().setIgnoreUnknownBeanProperties(true);
+ p = new UonParserBuilder().ignoreUnknownBeanProperties(true).build();
t = p.parse(uon, O.class);
assertEquals(123, t.foo);
try {
- p = new UonParser();
+ p = UonParser.DEFAULT;
t = p.parse(json, O.class);
fail("Expected exception never occurred");
} catch (Exception e) {
@@ -1012,12 +1013,12 @@ public class BeanMapTest {
// URL-Encoding
String urlencoding = "baz=789&foo=123&bar=456";
- p = new UrlEncodingParser().setIgnoreUnknownBeanProperties(true);
+ p = new UrlEncodingParserBuilder().ignoreUnknownBeanProperties(true).build();
t = p.parse(urlencoding, O.class);
assertEquals(123, t.foo);
try {
- p = new UrlEncodingParser();
+ p = UrlEncodingParser.DEFAULT;
t = p.parse(json, O.class);
fail("Expected exception never occurred");
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/ClassMetaTest.java
----------------------------------------------------------------------
diff --git a/juneau-core-test/src/test/java/org/apache/juneau/ClassMetaTest.java b/juneau-core-test/src/test/java/org/apache/juneau/ClassMetaTest.java
index 10a02a9..e01e5d5 100755
--- a/juneau-core-test/src/test/java/org/apache/juneau/ClassMetaTest.java
+++ b/juneau-core-test/src/test/java/org/apache/juneau/ClassMetaTest.java
@@ -115,7 +115,7 @@ public class ClassMetaTest {
BeanContext bc;
ClassMeta<?> ooo, hi1, hc1, hi2, hc2;
- bc = ContextFactory.create().getBeanContext();
+ bc = PropertyStore.create().getBeanContext();
ooo = bc.getClassMeta(Object.class);
hi1 = bc.getClassMeta(HI1.class);
hc1 = bc.getClassMeta(HC1.class);
@@ -137,7 +137,7 @@ public class ClassMetaTest {
assertEquals(hi2.getSerializedClassMeta().getInnerClass(), HI2.class);
assertEquals(hc2.getSerializedClassMeta().getInnerClass(), HC2.class);
- bc = ContextFactory.create().addPojoSwaps(HI1Swap.class).getBeanContext();
+ bc = PropertyStore.create().setPojoSwaps(HI1Swap.class).getBeanContext();
ooo = bc.getClassMeta(Object.class);
hi1 = bc.getClassMeta(HI1.class);
hc1 = bc.getClassMeta(HC1.class);
@@ -159,7 +159,7 @@ public class ClassMetaTest {
assertEquals(hi2.getSerializedClassMeta().getInnerClass(), Map.class);
assertEquals(hc2.getSerializedClassMeta().getInnerClass(), Map.class);
- bc = ContextFactory.create().addPojoSwaps(HC1Swap.class).getBeanContext();
+ bc = PropertyStore.create().setPojoSwaps(HC1Swap.class).getBeanContext();
ooo = bc.getClassMeta(Object.class);
hi1 = bc.getClassMeta(HI1.class);
hc1 = bc.getClassMeta(HC1.class);
@@ -181,7 +181,7 @@ public class ClassMetaTest {
assertEquals(hi2.getSerializedClassMeta().getInnerClass(), HI2.class);
assertEquals(hc2.getSerializedClassMeta().getInnerClass(), Map.class);
- bc = ContextFactory.create().addPojoSwaps(HI2Swap.class).getBeanContext();
+ bc = PropertyStore.create().setPojoSwaps(HI2Swap.class).getBeanContext();
ooo = bc.getClassMeta(Object.class);
hi1 = bc.getClassMeta(HI1.class);
hc1 = bc.getClassMeta(HC1.class);
@@ -203,7 +203,7 @@ public class ClassMetaTest {
assertEquals(hi2.getSerializedClassMeta().getInnerClass(), Map.class);
assertEquals(hc2.getSerializedClassMeta().getInnerClass(), Map.class);
- bc = ContextFactory.create().addPojoSwaps(HC2Swap.class).getBeanContext();
+ bc = PropertyStore.create().setPojoSwaps(HC2Swap.class).getBeanContext();
ooo = bc.getClassMeta(Object.class);
hi1 = bc.getClassMeta(HI1.class);
hc1 = bc.getClassMeta(HC1.class);
@@ -225,7 +225,7 @@ public class ClassMetaTest {
assertEquals(hi2.getSerializedClassMeta().getInnerClass(), HI2.class);
assertEquals(hc2.getSerializedClassMeta().getInnerClass(), Map.class);
- bc = ContextFactory.create().addPojoSwaps(HI1Swap.class,HC1Swap.class,HI2Swap.class,HC2Swap.class).getBeanContext();
+ bc = PropertyStore.create().setPojoSwaps(HI1Swap.class,HC1Swap.class,HI2Swap.class,HC2Swap.class).getBeanContext();
ooo = bc.getClassMeta(Object.class);
hi1 = bc.getClassMeta(HI1.class);
hc1 = bc.getClassMeta(HC1.class);
@@ -247,7 +247,7 @@ public class ClassMetaTest {
assertEquals(hi2.getSerializedClassMeta().getInnerClass(), Map.class);
assertEquals(hc2.getSerializedClassMeta().getInnerClass(), Map.class);
- bc = ContextFactory.create().addPojoSwaps(HC2Swap.class,HI2Swap.class,HC1Swap.class,HI1Swap.class).getBeanContext();
+ bc = PropertyStore.create().setPojoSwaps(HC2Swap.class,HI2Swap.class,HC1Swap.class,HI1Swap.class).getBeanContext();
ooo = bc.getClassMeta(Object.class);
hi1 = bc.getClassMeta(HI1.class);
hc1 = bc.getClassMeta(HC1.class);
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/ComboTest.java
----------------------------------------------------------------------
diff --git a/juneau-core-test/src/test/java/org/apache/juneau/ComboTest.java b/juneau-core-test/src/test/java/org/apache/juneau/ComboTest.java
index cb4b935..4b89c8e 100644
--- a/juneau-core-test/src/test/java/org/apache/juneau/ComboTest.java
+++ b/juneau-core-test/src/test/java/org/apache/juneau/ComboTest.java
@@ -12,37 +12,22 @@
// ***************************************************************************************************************************
package org.apache.juneau;
-import static org.junit.Assert.assertEquals;
+import static org.apache.juneau.jena.Constants.*;
+import static org.junit.Assert.*;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
-import org.apache.juneau.html.HtmlParser;
-import org.apache.juneau.html.HtmlSerializer;
-import org.apache.juneau.jena.RdfParser;
-import org.apache.juneau.jena.RdfSerializer;
-import org.apache.juneau.json.JsonParser;
-import org.apache.juneau.json.JsonSerializer;
-import org.apache.juneau.msgpack.MsgPackParser;
-import org.apache.juneau.msgpack.MsgPackSerializer;
-import org.apache.juneau.parser.InputStreamParser;
-import org.apache.juneau.parser.Parser;
-import org.apache.juneau.parser.ReaderParser;
-import org.apache.juneau.serializer.OutputStreamSerializer;
-import org.apache.juneau.serializer.Serializer;
-import org.apache.juneau.serializer.WriterSerializer;
-import org.apache.juneau.urlencoding.UonParser;
-import org.apache.juneau.urlencoding.UonSerializer;
-import org.apache.juneau.urlencoding.UrlEncodingParser;
-import org.apache.juneau.urlencoding.UrlEncodingSerializer;
-import org.apache.juneau.xml.XmlParser;
-import org.apache.juneau.xml.XmlSerializer;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
+import org.apache.juneau.html.*;
+import org.apache.juneau.jena.*;
+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.*;
+import org.junit.runners.*;
/**
* Superclass for tests that verify results against all supported content types.
@@ -297,8 +282,8 @@ public abstract class ComboTest {
//--------------------------------------------------------------------------------
// JSON - 't' property
//--------------------------------------------------------------------------------
- WriterSerializer sJsonT = JsonSerializer.DEFAULT_LAX.clone().setBeanTypePropertyName("t");
- ReaderParser pJsonT = JsonParser.DEFAULT.clone().setBeanTypePropertyName("t");
+ WriterSerializer sJsonT = new JsonSerializerBuilder().simple().beanTypePropertyName("t").build();
+ ReaderParser pJsonT = new JsonParserBuilder().beanTypePropertyName("t").build();
@Test
public void serializeJsonT() throws Exception {
@@ -345,8 +330,8 @@ public abstract class ComboTest {
//--------------------------------------------------------------------------------
// XML - 't' property
//--------------------------------------------------------------------------------
- WriterSerializer sXmlT = XmlSerializer.DEFAULT_SQ.clone().setBeanTypePropertyName("t");
- ReaderParser pXmlT = XmlParser.DEFAULT.clone().setBeanTypePropertyName("t");
+ WriterSerializer sXmlT = new XmlSerializerBuilder().sq().beanTypePropertyName("t").build();
+ ReaderParser pXmlT = new XmlParserBuilder().beanTypePropertyName("t").build();
@Test
public void serializeXmlT() throws Exception {
@@ -409,8 +394,8 @@ public abstract class ComboTest {
//--------------------------------------------------------------------------------
// HTML - 't' property
//--------------------------------------------------------------------------------
- WriterSerializer sHtmlT = HtmlSerializer.DEFAULT_SQ.clone().setBeanTypePropertyName("t");
- ReaderParser pHtmlT = HtmlParser.DEFAULT.clone().setBeanTypePropertyName("t");
+ WriterSerializer sHtmlT = new HtmlSerializerBuilder().sq().beanTypePropertyName("t").build();
+ ReaderParser pHtmlT = new HtmlParserBuilder().beanTypePropertyName("t").build();
@Test
public void serializeHtmlT() throws Exception {
@@ -457,8 +442,8 @@ public abstract class ComboTest {
//--------------------------------------------------------------------------------
// UON - 't' property
//--------------------------------------------------------------------------------
- WriterSerializer sUonT = UonSerializer.DEFAULT.clone().setBeanTypePropertyName("t");
- ReaderParser pUonT = UonParser.DEFAULT.clone().setBeanTypePropertyName("t");
+ WriterSerializer sUonT = new UonSerializerBuilder().beanTypePropertyName("t").build();
+ ReaderParser pUonT = new UonParserBuilder().beanTypePropertyName("t").build();
@Test
public void serializeUonT() throws Exception {
@@ -505,8 +490,8 @@ public abstract class ComboTest {
//--------------------------------------------------------------------------------
// UrlEncoding - 't' property
//--------------------------------------------------------------------------------
- WriterSerializer sUrlEncodingT = UrlEncodingSerializer.DEFAULT.clone().setBeanTypePropertyName("t");
- ReaderParser pUrlEncodingT = UrlEncodingParser.DEFAULT.clone().setBeanTypePropertyName("t");
+ WriterSerializer sUrlEncodingT = new UrlEncodingSerializerBuilder().beanTypePropertyName("t").build();
+ ReaderParser pUrlEncodingT = new UrlEncodingParserBuilder().beanTypePropertyName("t").build();
@Test
public void serializeUrlEncodingT() throws Exception {
@@ -558,8 +543,8 @@ public abstract class ComboTest {
//--------------------------------------------------------------------------------
// MsgPack - 't' property
//--------------------------------------------------------------------------------
- OutputStreamSerializer sMsgPackT = MsgPackSerializer.DEFAULT.clone().setBeanTypePropertyName("t");
- InputStreamParser pMsgPackT = MsgPackParser.DEFAULT.clone().setBeanTypePropertyName("t");
+ OutputStreamSerializer sMsgPackT = new MsgPackSerializerBuilder().beanTypePropertyName("t").build();
+ InputStreamParser pMsgPackT = new MsgPackParserBuilder().beanTypePropertyName("t").build();
@Test
public void serializeMsgPackT() throws Exception {
@@ -595,8 +580,8 @@ public abstract class ComboTest {
//--------------------------------------------------------------------------------
// RdfXml - 't' property
//--------------------------------------------------------------------------------
- WriterSerializer sRdfXmlT = RdfSerializer.DEFAULT_XMLABBREV.clone().setBeanTypePropertyName("t");
- ReaderParser pRdfXmlT = RdfParser.DEFAULT_XML.clone().setBeanTypePropertyName("t");
+ WriterSerializer sRdfXmlT = new RdfSerializerBuilder().language(LANG_RDF_XML_ABBREV).beanTypePropertyName("t").build();
+ ReaderParser pRdfXmlT = new RdfParserBuilder().beanTypePropertyName("t").build();
@Test
public void serializeRdfXmlT() throws Exception {
@@ -611,7 +596,7 @@ public abstract class ComboTest {
//--------------------------------------------------------------------------------
// RdfXml - Readable
//--------------------------------------------------------------------------------
- WriterSerializer sRdfXmlR = RdfSerializer.DEFAULT_XMLABBREV.clone().setUseWhitespace(true);
+ WriterSerializer sRdfXmlR = new RdfSerializerBuilder().language(LANG_RDF_XML_ABBREV).ws().build();
ReaderParser pRdfXmlR = RdfParser.DEFAULT_XML;
@Test
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/ContextFactoryTest.java
----------------------------------------------------------------------
diff --git a/juneau-core-test/src/test/java/org/apache/juneau/ContextFactoryTest.java b/juneau-core-test/src/test/java/org/apache/juneau/ContextFactoryTest.java
deleted file mode 100644
index f48b825..0000000
--- a/juneau-core-test/src/test/java/org/apache/juneau/ContextFactoryTest.java
+++ /dev/null
@@ -1,823 +0,0 @@
-// ***************************************************************************************************************************
-// * 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 ContextFactoryTest {
-
- //====================================================================================================
- // testSimpleProperties()
- //====================================================================================================
- @Test
- public void testSimpleProperties() {
- ContextFactory f = ContextFactory.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() {
- ContextFactory f = ContextFactory.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() {
- ContextFactory f = ContextFactory.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() {
- ContextFactory f = ContextFactory.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 {
- ContextFactory f1 = ContextFactory.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);}});
-
- ContextFactory f2 = ContextFactory.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");
-
- ContextFactory.PropertyMap p1 = f1.getPropertyMap("A");
- ContextFactory.PropertyMap p2 = f2.getPropertyMap("A");
- assertEquals(p1.hashCode(), p2.hashCode());
- }
-
- @SuppressWarnings("unchecked")
- private static class ConversionTest {
- ContextFactory config = ContextFactory.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 config property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'java.lang.Class'. Value=true.")
- .test(TestEnum.class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=true.")
- .test(String[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'java.lang.String[]'. Value=true.")
- .test(Class[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'java.lang.Class[]'. Value=true.")
- .test(TestEnum[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.Boolean' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=true.")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'java.lang.Class'. Value=123.")
- .test(TestEnum.class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=123.")
- .test(String[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'java.lang.String[]'. Value=123.")
- .test(Class[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'java.lang.Class[]'. Value=123.")
- .test(TestEnum[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.Integer' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=123.")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config property 'A.a'. Invalid data conversion from type 'java.lang.Class' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value='java.lang.String'.")
- .test(String[].class, "Could not retrieve config 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 config 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 config property 'A.a'. Invalid data conversion from type 'java.lang.Class' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value='java.lang.String'.")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'java.lang.Class'. Value='foo'.")
- .test(TestEnum.class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value='foo'.")
- .test(String[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'java.lang.String[]'. Value='foo'.")
- .test(Class[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'java.lang.Class[]'. Value='foo'.")
- .test(TestEnum[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'java.lang.String' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value='foo'.")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum' to type 'int'. Value='ONE'.")
- .test(String.class, "'ONE'")
- .test(Class.class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum' to type 'java.lang.Class'. Value='ONE'.")
- .test(TestEnum.class, "'ONE'")
- .test(String[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum' to type 'java.lang.String[]'. Value='ONE'.")
- .test(Class[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum' to type 'java.lang.Class[]'. Value='ONE'.")
- .test(TestEnum[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value='ONE'.")
- .testMap(String.class, String.class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value='ONE'.")
- .testMap(Class.class, Class.class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$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 config 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 config 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 config property 'A.a'. Invalid data conversion from type 'java.lang.String[]' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=['foo','bar'].")
- .test(String[].class, "['foo','bar']")
- .test(Class[].class, "Could not retrieve config 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 config property 'A.a'. Invalid data conversion from type 'java.lang.String[]' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=['foo','bar'].")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config 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 config property 'A.a'. Invalid data conversion from type 'java.lang.Class[]' to type 'org.apache.juneau.ContextFactoryTest$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 config property 'A.a'. Invalid data conversion from type 'java.lang.Class[]' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=['java.lang.String','java.lang.Integer'].")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum[]' to type 'int'. Value=['ONE','TWO'].")
- .test(String.class, "'[\\'ONE\\',\\'TWO\\']'")
- .test(Class.class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum[]' to type 'java.lang.Class'. Value=['ONE','TWO'].")
- .test(TestEnum.class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum[]' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=['ONE','TWO'].")
- .test(String[].class, "['ONE','TWO']")
- .test(Class[].class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum[]' to type 'java.lang.Class[]'. Value=['ONE','TWO'].")
- .test(TestEnum[].class, "['ONE','TWO']")
- .testMap(String.class, String.class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$TestEnum[]' to type 'java.util.LinkedHashMap<java.lang.String,java.lang.String>'. Value=['ONE','TWO'].")
- .testMap(Class.class, Class.class, "Could not retrieve config property 'A.a'. Invalid data conversion from type 'org.apache.juneau.ContextFactoryTest$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 config 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 config 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 config property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value={foo:'bar'}.")
- .test(String[].class, "Could not retrieve config 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 config 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 config property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value={foo:'bar'}.")
- .testMap(String.class, String.class, "{foo:'bar'}")
- .testMap(Class.class, Class.class, "Could not retrieve config 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 config 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 config 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 config property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value={'java.lang.String':'java.lang.Integer'}.")
- .test(String[].class, "Could not retrieve config 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 config 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 config property 'A.a'. Invalid data conversion from type 'java.util.LinkedHashMap' to type 'org.apache.juneau.ContextFactoryTest$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 config 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 config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=[true].")
- .test(String[].class, "['true']")
- .test(Class[].class, "Could not retrieve config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=[true].")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=[123].")
- .test(String[].class, "['123']")
- .test(Class[].class, "Could not retrieve config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=[123].")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=['java.lang.String'].")
- .test(String[].class, "['java.lang.String']")
- .test(Class[].class, "['java.lang.String']")
- .test(TestEnum[].class, "Could not retrieve config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=['java.lang.String'].")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=['foo'].")
- .test(String[].class, "['foo']")
- .test(Class[].class, "Could not retrieve config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=['foo'].")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=['ONE'].")
- .test(String[].class, "['ONE']")
- .test(Class[].class, "Could not retrieve config 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 config 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 config 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 config 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 config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=['bar','foo'].")
- .test(String[].class, "['bar','foo']")
- .test(Class[].class, "Could not retrieve config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=['bar','foo'].")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=['java.lang.Integer','java.lang.String'].")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=['ONE','TWO'].")
- .test(String[].class, "['ONE','TWO']")
- .test(Class[].class, "Could not retrieve config 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 config 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 config 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 config 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 config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=[{foo:'bar'}].")
- .test(String[].class, "['{foo:\\'bar\\'}']")
- .test(Class[].class, "Could not retrieve config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=[{foo:'bar'}].")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value=[{'java.lang.String':'java.lang.Integer'}].")
- .test(String[].class, "['{\\'java.lang.String\\':\\'java.lang.Integer\\'}']")
- .test(Class[].class, "Could not retrieve config 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 config property 'A.a.set'. Invalid data conversion from type 'java.util.concurrent.ConcurrentSkipListSet' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value=[{'java.lang.String':'java.lang.Integer'}].")
- .testMap(String.class, String.class, "Could not retrieve config 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 config 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 config 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 config 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 config 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.ContextFactoryTest$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.ContextFactoryTest$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 config 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 config 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 config property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value={foo:'bar'}.")
- .test(String[].class, "Could not retrieve config 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 config 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 config property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'org.apache.juneau.ContextFactoryTest$TestEnum[]'. Value={foo:'bar'}.")
- .testMap(String.class, String.class, "{foo:'bar'}")
- .testMap(Class.class, Class.class, "Could not retrieve config 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 config 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 config 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 config property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'org.apache.juneau.ContextFactoryTest$TestEnum'. Value={'java.lang.String':'java.lang.Integer'}.")
- .test(String[].class, "Could not retrieve config 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 config 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 config property 'A.a.map'. Invalid data conversion from type 'java.util.Collections$SynchronizedMap' to type 'org.apache.juneau.ContextFactoryTest$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");
-
- ContextFactory f = ContextFactory.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/DataConversionTest.java
----------------------------------------------------------------------
diff --git a/juneau-core-test/src/test/java/org/apache/juneau/DataConversionTest.java b/juneau-core-test/src/test/java/org/apache/juneau/DataConversionTest.java
index d3d8ed1..be7c264 100755
--- a/juneau-core-test/src/test/java/org/apache/juneau/DataConversionTest.java
+++ b/juneau-core-test/src/test/java/org/apache/juneau/DataConversionTest.java
@@ -144,7 +144,7 @@ public class DataConversionTest {
@Test
public void testObjectSwaps() throws Exception {
String s = "Jan 12, 2001";
- BeanSession session = ContextFactory.create().addPojoSwaps(CalendarSwap.DateMedium.class).getBeanContext().createSession();
+ BeanSession session = PropertyStore.create().setPojoSwaps(CalendarSwap.DateMedium.class).getBeanContext().createSession();
Calendar c = session.convertToType(s, GregorianCalendar.class);
assertEquals(2001, c.get(Calendar.YEAR));
c = session.convertToType(s, Calendar.class);
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/IgnoredClassesTest.java
----------------------------------------------------------------------
diff --git a/juneau-core-test/src/test/java/org/apache/juneau/IgnoredClassesTest.java b/juneau-core-test/src/test/java/org/apache/juneau/IgnoredClassesTest.java
index 28674f3..e22d86d 100755
--- a/juneau-core-test/src/test/java/org/apache/juneau/IgnoredClassesTest.java
+++ b/juneau-core-test/src/test/java/org/apache/juneau/IgnoredClassesTest.java
@@ -41,24 +41,24 @@ public class IgnoredClassesTest {
@Test
public void testIgnorePackages() throws Exception {
A a = new A();
- JsonSerializer s = new JsonSerializer.Simple();
- assertEquals("{f1:'isBean'}", s.serialize(a));
- s.addNotBeanPackages("org.apache.juneau");
- assertEquals("'isNotBean'", s.serialize(a));
+ JsonSerializerBuilder s = new JsonSerializerBuilder().simple();
+ assertEquals("{f1:'isBean'}", s.build().serialize(a));
+ s.notBeanPackages("org.apache.juneau");
+ assertEquals("'isNotBean'", s.build().serialize(a));
s.removeNotBeanPackages("org.apache.juneau");
- assertEquals("{f1:'isBean'}", s.serialize(a));
- s.addNotBeanPackages("org.apache.juneau.*");
- assertEquals("'isNotBean'", s.serialize(a));
+ assertEquals("{f1:'isBean'}", s.build().serialize(a));
+ s.notBeanPackages("org.apache.juneau.*");
+ assertEquals("'isNotBean'", s.build().serialize(a));
s.removeNotBeanPackages("org.apache.juneau.*");
- assertEquals("{f1:'isBean'}", s.serialize(a));
- s.addNotBeanPackages("org.apache.juneau.*");
- assertEquals("'isNotBean'", s.serialize(a));
+ assertEquals("{f1:'isBean'}", s.build().serialize(a));
+ s.notBeanPackages("org.apache.juneau.*");
+ assertEquals("'isNotBean'", s.build().serialize(a));
s.removeNotBeanPackages("org.apache.juneau.*");
- assertEquals("{f1:'isBean'}", s.serialize(a));
- s.addNotBeanPackages("org.apache.juneau");
- assertEquals("'isNotBean'", s.serialize(a));
- s.addNotBeanPackages("org.apache.juneau.x");
- assertEquals("'isNotBean'", s.serialize(a));
+ assertEquals("{f1:'isBean'}", s.build().serialize(a));
+ s.notBeanPackages("org.apache.juneau");
+ assertEquals("'isNotBean'", s.build().serialize(a));
+ s.notBeanPackages("org.apache.juneau.x");
+ assertEquals("'isNotBean'", s.build().serialize(a));
}
public static class A {
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/MediaRangeTest.java
----------------------------------------------------------------------
diff --git a/juneau-core-test/src/test/java/org/apache/juneau/MediaRangeTest.java b/juneau-core-test/src/test/java/org/apache/juneau/MediaRangeTest.java
index f3fd216..882ca6a 100644
--- a/juneau-core-test/src/test/java/org/apache/juneau/MediaRangeTest.java
+++ b/juneau-core-test/src/test/java/org/apache/juneau/MediaRangeTest.java
@@ -12,15 +12,14 @@
// ***************************************************************************************************************************
package org.apache.juneau;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
-import java.util.Arrays;
-import java.util.Collection;
+import java.util.*;
-import org.apache.juneau.json.JsonSerializer;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.apache.juneau.json.*;
+import org.junit.*;
+import org.junit.runner.*;
+import org.junit.runners.*;
/**
* Verifies that the MediaRange and MediaType classes parse and sort Accept headers correctly.
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/95e832e1/juneau-core-test/src/test/java/org/apache/juneau/PojoSwapTest.java
----------------------------------------------------------------------
diff --git a/juneau-core-test/src/test/java/org/apache/juneau/PojoSwapTest.java b/juneau-core-test/src/test/java/org/apache/juneau/PojoSwapTest.java
index d9b7944..5fa73b2 100755
--- a/juneau-core-test/src/test/java/org/apache/juneau/PojoSwapTest.java
+++ b/juneau-core-test/src/test/java/org/apache/juneau/PojoSwapTest.java
@@ -29,8 +29,8 @@ public class PojoSwapTest {
//====================================================================================================
@Test
public void testSameType() throws Exception {
- JsonSerializer s = JsonSerializer.DEFAULT_LAX.clone().addPojoSwaps(ASwap.class);
- JsonParser p = JsonParser.DEFAULT.clone().addPojoSwaps(ASwap.class);
+ JsonSerializer s = new JsonSerializerBuilder().simple().pojoSwaps(ASwap.class).build();
+ JsonParser p = new JsonParserBuilder().pojoSwaps(ASwap.class).build();
String r;
r = s.serialize("foobar");