http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/ComboRoundTripTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/ComboRoundTripTest.java b/juneau-core-test/src/test/java/org/apache/juneau/ComboRoundTripTest.java deleted file mode 100644 index 4da5f1e..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/ComboRoundTripTest.java +++ /dev/null @@ -1,708 +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.jena.Constants.*; -import static org.junit.Assert.*; - -import java.util.*; - -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. - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@SuppressWarnings({"unchecked","rawtypes"}) -public abstract class ComboRoundTripTest { - - /* Parameter template */ -// { -// "MyLabel", -// myInput, -// /* Json */ "xxx", -// /* JsonT */ "xxx", -// /* JsonR */ "xxx", -// /* Xml */ "xxx", -// /* XmlT */ "xxx", -// /* XmlR */ "xxx", -// /* XmlNs */ "xxx", -// /* Html */ "xxx", -// /* HtmlT */ "xxx", -// /* HtmlR */ "xxx", -// /* Uon */ "xxx", -// /* UonT */ "xxx", -// /* UonR */ "xxx", -// /* UrlEnc */ "xxx", -// /* UrlEncT */ "xxx", -// /* UrlEncR */ "xxx", -// /* MsgPack */ "xxx", -// /* MsgPackT */ "xxx", -// /* RdfXml */ "xxx", -// /* RdfXmlT */ "xxx", -// /* RdfXmlR */ "xxx", -// }, - - private final ComboInput comboInput; - - // These are the names of all the tests. - // You can comment out the names here to skip them. - private static final String[] runTests = { - "serializeJson", - "parseJson", - "serializeJsonT", - "parseJsonT", - "serializeJsonR", - "parseJsonR", - "serializeXml", - "parseXml", - "serializeXmlT", - "parseXmlT", - "serializeXmlR", - "parseXmlR", - "serializeXmlNs", - "parseXmlNs", - "serializeHtml", - "parseHtml", - "serializeHtmlT", - "parseHtmlT", - "serializeHtmlR", - "parseHtmlR", - "serializeUon", - "parseUon", - "serializeUonT", - "parseUonT", - "serializeUonR", - "parseUonR", - "serializeUrlEncoding", - "parseUrlEncoding", - "serializeUrlEncodingT", - "parseUrlEncodingT", - "serializeUrlEncodingR", - "parseUrlEncodingR", - "serializeMsgPack", - "parseMsgPack", - "parseMsgPackJsonEquivalency", - "serializeMsgPackT", - "parseMsgPackT", - "parseMsgPackTJsonEquivalency", - "serializeRdfXml", - "parseRdfXml", - "serializeRdfXmlT", - "parseRdfXmlT", - "serializeRdfXmlR", - "parseRdfXmlR", - }; - - private static final Set<String> runTestsSet = new HashSet<String>(Arrays.asList(runTests)); - - private final boolean SKIP_RDF_TESTS = Boolean.getBoolean("skipRdfTests"); - - private Map<Serializer,Serializer> serializerMap = new IdentityHashMap<Serializer,Serializer>(); - private Map<Parser,Parser> parserMap = new IdentityHashMap<Parser,Parser>(); - - public ComboRoundTripTest(ComboInput<?> comboInput) { - this.comboInput = comboInput; - } - - private Serializer getSerializer(Serializer s) throws Exception { - Serializer s2 = serializerMap.get(s); - if (s2 == null) { - s2 = applySettings(s); - serializerMap.put(s, s2); - } - return s2; - } - - private Parser getParser(Parser p) throws Exception { - Parser p2 = parserMap.get(p); - if (p2 == null) { - p2 = applySettings(p); - parserMap.put(p, p2); - } - return p2; - } - - private void testSerialize(String testName, Serializer s, String expected) throws Exception { - try { - s = getSerializer(s); - - boolean isRdf = s instanceof RdfSerializer; - - if ((isRdf && SKIP_RDF_TESTS) || expected.isEmpty() || ! runTestsSet.contains(testName) ) { - System.err.println(comboInput.label + "/" + testName + " for "+s.getClass().getSimpleName()+" skipped."); - return; - } - - String r = s.isWriterSerializer() ? ((WriterSerializer)s).serialize(comboInput.getInput()) : ((OutputStreamSerializer)s).serializeToHex(comboInput.getInput()); - - // Can't control RdfSerializer output well, so manually remove namespace declarations - // double-quotes with single-quotes, and spaces with tabs. - // Also because RDF sucks really bad and can't be expected to produce consistent testable results, - // we must also do an expensive sort-then-compare operation to verify the results. - if (isRdf) - r = r.replaceAll("<rdf:RDF[^>]*>", "<rdf:RDF>").replace('"', '\''); - - // Specifying "xxx" in the expected results will spit out what we should populate the field with. - if (expected.equals("xxx")) { - System.out.println(comboInput.label + "/" + testName + "=\n" + r.replaceAll("\n", "\\\\n").replaceAll("\t", "\\\\t")); // NOT DEBUG - System.out.println(r); - } - - if (isRdf) - TestUtils.assertEqualsAfterSort(expected, r, "{0}/{1} parse-normal failed", comboInput.label, testName); - else - TestUtils.assertEquals(expected, r, "{0}/{1} parse-normal failed", comboInput.label, testName); - - } catch (AssertionError e) { - throw e; - } catch (Exception e) { - e.printStackTrace(); - throw new AssertionError(comboInput.label + "/" + testName + " failed. exception=" + e.getLocalizedMessage()); - } - } - - private void testParse(String testName, Serializer s, Parser p, String expected) throws Exception { - try { - s = getSerializer(s); - p = getParser(p); - - boolean isRdf = s instanceof RdfSerializer; - - if ((isRdf && SKIP_RDF_TESTS) || expected.isEmpty() || ! runTestsSet.contains(testName) ) { - System.err.println(comboInput.label + "/" + testName + " for "+s.getClass().getSimpleName()+" skipped."); - return; - } - - String r = s.isWriterSerializer() ? ((WriterSerializer)s).serialize(comboInput.getInput()) : ((OutputStreamSerializer)s).serializeToHex(comboInput.getInput()); - Object o = p.parse(r, comboInput.type); - r = s.isWriterSerializer() ? ((WriterSerializer)s).serialize(o) : ((OutputStreamSerializer)s).serializeToHex(o); - - if (isRdf) - r = r.replaceAll("<rdf:RDF[^>]*>", "<rdf:RDF>").replace('"', '\''); - - if (isRdf) - TestUtils.assertEqualsAfterSort(expected, r, "{0}/{1} parse-normal failed", comboInput.label, testName); - else - TestUtils.assertEquals(expected, r, "{0}/{1} parse-normal failed", comboInput.label, testName); - - } catch (AssertionError e) { - throw e; - } catch (Exception e) { - throw new Exception(comboInput.label + "/" + testName + " failed.", e); - } - } - - private void testParseVerify(String testName, Serializer s, Parser p) throws Exception { - try { - s = getSerializer(s); - p = getParser(p); - - String r = s.isWriterSerializer() ? ((WriterSerializer)s).serialize(comboInput.getInput()) : ((OutputStreamSerializer)s).serializeToHex(comboInput.getInput()); - Object o = p.parse(r, comboInput.type); - - comboInput.verify(o); - } catch (AssertionError e) { - throw e; - } catch (Exception e) { - throw new Exception(comboInput.label + "/" + testName + " failed.", e); - } - } - - - private void testParseJsonEquivalency(String testName, OutputStreamSerializer s, InputStreamParser p, String expected) throws Exception { - try { - s = (OutputStreamSerializer)getSerializer(s); - p = (InputStreamParser)getParser(p); - WriterSerializer sJson = (WriterSerializer)getSerializer(this.sJson); - - String r = s.serializeToHex(comboInput.getInput()); - Object o = p.parse(r, comboInput.type); - r = sJson.serialize(o); - assertEquals(comboInput.label + "/" + testName + " parse-normal failed on JSON equivalency", expected, r); - } catch (AssertionError e) { - throw e; - } catch (Exception e) { - throw new Exception(comboInput.label + "/" + testName + " failed.", e); - } - } - - protected Serializer applySettings(Serializer s) throws Exception { - return s; - } - - protected Parser applySettings(Parser p) throws Exception { - return p; - } - - //-------------------------------------------------------------------------------- - // JSON - //-------------------------------------------------------------------------------- - WriterSerializer sJson = JsonSerializer.DEFAULT_LAX; - ReaderParser pJson = JsonParser.DEFAULT; - - @Test - public void a11_serializeJson() throws Exception { - testSerialize("serializeJson", sJson, comboInput.json); - } - - @Test - public void a12_parseJson() throws Exception { - testParse("parseJson", sJson, pJson, comboInput.json); - } - - @Test - public void a13_verifyJson() throws Exception { - testParseVerify("verifyJson", sJson, pJson); - } - - //-------------------------------------------------------------------------------- - // JSON - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sJsonT = new JsonSerializerBuilder().simple().beanTypePropertyName("t").build(); - ReaderParser pJsonT = new JsonParserBuilder().beanTypePropertyName("t").build(); - - @Test - public void a21_serializeJsonT() throws Exception { - testSerialize("serializeJsonT", sJsonT, comboInput.jsonT); - } - - @Test - public void a22_parseJsonT() throws Exception { - testParse("parseJsonT", sJsonT, pJsonT, comboInput.jsonT); - } - - @Test - public void a23_verifyJsonT() throws Exception { - testParseVerify("verifyJsonT", sJsonT, pJsonT); - } - - //-------------------------------------------------------------------------------- - // JSON - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sJsonR = JsonSerializer.DEFAULT_LAX_READABLE; - ReaderParser pJsonR = JsonParser.DEFAULT; - - @Test - public void a31_serializeJsonR() throws Exception { - testSerialize("serializeJsonR", sJsonR, comboInput.jsonR); - } - - @Test - public void a32_parseJsonR() throws Exception { - testParse("parseJsonR", sJsonR, pJsonR, comboInput.jsonR); - } - - @Test - public void a33_verifyJsonR() throws Exception { - testParseVerify("verifyJsonR", sJsonR, pJsonR); - } - - //-------------------------------------------------------------------------------- - // XML - //-------------------------------------------------------------------------------- - WriterSerializer sXml = XmlSerializer.DEFAULT_SQ; - ReaderParser pXml = XmlParser.DEFAULT; - - @Test - public void b11_serializeXml() throws Exception { - testSerialize("serializeXml", sXml, comboInput.xml); - } - - @Test - public void b12_parseXml() throws Exception { - testParse("parseXml", sXml, pXml, comboInput.xml); - } - - @Test - public void b13_verifyXml() throws Exception { - testParseVerify("verifyXml", sXml, pXml); - } - - //-------------------------------------------------------------------------------- - // XML - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sXmlT = new XmlSerializerBuilder().sq().beanTypePropertyName("t").build(); - ReaderParser pXmlT = new XmlParserBuilder().beanTypePropertyName("t").build(); - - @Test - public void b21_serializeXmlT() throws Exception { - testSerialize("serializeXmlT", sXmlT, comboInput.xmlT); - } - - @Test - public void b22_parseXmlT() throws Exception { - testParse("parseXmlT", sXmlT, pXmlT, comboInput.xmlT); - } - - @Test - public void b23_verifyXmlT() throws Exception { - testParseVerify("parseXmlTVerify", sXmlT, pXmlT); - } - - //-------------------------------------------------------------------------------- - // XML - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sXmlR = XmlSerializer.DEFAULT_SQ_READABLE; - ReaderParser pXmlR = XmlParser.DEFAULT; - - @Test - public void b31_serializeXmlR() throws Exception { - testSerialize("serializeXmlR", sXmlR, comboInput.xmlR); - } - - @Test - public void b32_parseXmlR() throws Exception { - testParse("parseXmlR", sXmlR, pXmlR, comboInput.xmlR); - } - - @Test - public void b33_verifyXmlR() throws Exception { - testParseVerify("parseXmlRVerify", sXmlR, pXmlR); - } - - //-------------------------------------------------------------------------------- - // XML - Namespaces - //-------------------------------------------------------------------------------- - WriterSerializer sXmlNs = XmlSerializer.DEFAULT_NS_SQ; - ReaderParser pXmlNs = XmlParser.DEFAULT; - - @Test - public void b41_serializeXmlNs() throws Exception { - testSerialize("serializeXmlNs", sXmlNs, comboInput.xmlNs); - } - - @Test - public void b42_parseXmlNs() throws Exception { - testParse("parseXmlNs", sXmlNs, pXmlNs, comboInput.xmlNs); - } - - @Test - public void b43_verifyXmlNs() throws Exception { - testParseVerify("verifyXmlNs", sXmlNs, pXmlNs); - } - - //-------------------------------------------------------------------------------- - // HTML - //-------------------------------------------------------------------------------- - WriterSerializer sHtml = HtmlSerializer.DEFAULT_SQ; - ReaderParser pHtml = HtmlParser.DEFAULT; - - @Test - public void c11_serializeHtml() throws Exception { - testSerialize("serializeHtml", sHtml, comboInput.html); - } - - @Test - public void c12_parseHtml() throws Exception { - testParse("parseHtml", sHtml, pHtml, comboInput.html); - } - - @Test - public void c13_verifyHtml() throws Exception { - testParseVerify("verifyHtml", sHtml, pHtml); - } - - //-------------------------------------------------------------------------------- - // HTML - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sHtmlT = new HtmlSerializerBuilder().sq().beanTypePropertyName("t").build(); - ReaderParser pHtmlT = new HtmlParserBuilder().beanTypePropertyName("t").build(); - - @Test - public void c21_serializeHtmlT() throws Exception { - testSerialize("serializeHtmlT", sHtmlT, comboInput.htmlT); - } - - @Test - public void c22_parseHtmlT() throws Exception { - testParse("parseHtmlT", sHtmlT, pHtmlT, comboInput.htmlT); - } - - @Test - public void c23_verifyHtmlT() throws Exception { - testParseVerify("verifyHtmlT", sHtmlT, pHtmlT); - } - - //-------------------------------------------------------------------------------- - // HTML - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sHtmlR = HtmlSerializer.DEFAULT_SQ_READABLE; - ReaderParser pHtmlR = HtmlParser.DEFAULT; - - @Test - public void c31_serializeHtmlR() throws Exception { - testSerialize("serializeHtmlR", sHtmlR, comboInput.htmlR); - } - - @Test - public void c32_parseHtmlR() throws Exception { - testParse("parseHtmlR", sHtmlR, pHtmlR, comboInput.htmlR); - } - - @Test - public void c33_verifyHtmlR() throws Exception { - testParseVerify("verifyHtmlR", sHtmlR, pHtmlR); - } - - //-------------------------------------------------------------------------------- - // UON - //-------------------------------------------------------------------------------- - WriterSerializer sUon = UonSerializer.DEFAULT; - ReaderParser pUon = UonParser.DEFAULT; - - @Test - public void d11_serializeUon() throws Exception { - testSerialize("serializeUon", sUon, comboInput.uon); - } - - @Test - public void d12_parseUon() throws Exception { - testParse("parseUon", sUon, pUon, comboInput.uon); - } - - @Test - public void d13_verifyUon() throws Exception { - testParseVerify("verifyUon", sUon, pUon); - } - - //-------------------------------------------------------------------------------- - // UON - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sUonT = new UonSerializerBuilder().beanTypePropertyName("t").build(); - ReaderParser pUonT = new UonParserBuilder().beanTypePropertyName("t").build(); - - @Test - public void d21_serializeUonT() throws Exception { - testSerialize("serializeUonT", sUonT, comboInput.uonT); - } - - @Test - public void d22_parseUonT() throws Exception { - testParse("parseUonT", sUonT, pUonT, comboInput.uonT); - } - - @Test - public void d23_verifyUonT() throws Exception { - testParseVerify("verifyUonT", sUonT, pUonT); - } - - //-------------------------------------------------------------------------------- - // UON - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sUonR = UonSerializer.DEFAULT_READABLE; - ReaderParser pUonR = UonParser.DEFAULT; - - @Test - public void d31_serializeUonR() throws Exception { - testSerialize("serializeUonR", sUonR, comboInput.uonR); - } - - @Test - public void d32_parseUonR() throws Exception { - testParse("parseUonR", sUonR, pUonR, comboInput.uonR); - } - - @Test - public void d33_verifyUonR() throws Exception { - testParseVerify("verifyUonR", sUonR, pUonR); - } - - //-------------------------------------------------------------------------------- - // UrlEncoding - //-------------------------------------------------------------------------------- - WriterSerializer sUrlEncoding = UrlEncodingSerializer.DEFAULT; - ReaderParser pUrlEncoding = UrlEncodingParser.DEFAULT; - - @Test - public void e11_serializeUrlEncoding() throws Exception { - testSerialize("serializeUrlEncoding", sUrlEncoding, comboInput.urlEncoding); - } - - @Test - public void e12_parseUrlEncoding() throws Exception { - testParse("parseUrlEncoding", sUrlEncoding, pUrlEncoding, comboInput.urlEncoding); - } - - @Test - public void e13_verifyUrlEncoding() throws Exception { - testParseVerify("verifyUrlEncoding", sUrlEncoding, pUrlEncoding); - } - - //-------------------------------------------------------------------------------- - // UrlEncoding - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sUrlEncodingT = new UrlEncodingSerializerBuilder().beanTypePropertyName("t").build(); - ReaderParser pUrlEncodingT = new UrlEncodingParserBuilder().beanTypePropertyName("t").build(); - - @Test - public void e21_serializeUrlEncodingT() throws Exception { - testSerialize("serializeUrlEncodingT", sUrlEncodingT, comboInput.urlEncodingT); - } - - @Test - public void e22_parseUrlEncodingT() throws Exception { - testParse("parseUrlEncodingT", sUrlEncodingT, pUrlEncodingT, comboInput.urlEncodingT); - } - - @Test - public void e23_verifyUrlEncodingT() throws Exception { - testParseVerify("verifyUrlEncodingT", sUrlEncodingT, pUrlEncodingT); - } - - //-------------------------------------------------------------------------------- - // UrlEncoding - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sUrlEncodingR = UrlEncodingSerializer.DEFAULT_READABLE; - ReaderParser pUrlEncodingR = UrlEncodingParser.DEFAULT; - - @Test - public void e31_serializeUrlEncodingR() throws Exception { - testSerialize("serializeUrlEncodingR", sUrlEncodingR, comboInput.urlEncodingR); - } - - @Test - public void e32_parseUrlEncodingR() throws Exception { - testParse("parseUrlEncodingR", sUrlEncodingR, pUrlEncodingR, comboInput.urlEncodingR); - } - - @Test - public void e33_verifyUrlEncodingR() throws Exception { - testParseVerify("verifyUrlEncodingR", sUrlEncodingR, pUrlEncodingR); - } - - //-------------------------------------------------------------------------------- - // MsgPack - //-------------------------------------------------------------------------------- - OutputStreamSerializer sMsgPack = MsgPackSerializer.DEFAULT; - InputStreamParser pMsgPack = MsgPackParser.DEFAULT; - - @Test - public void f11_serializeMsgPack() throws Exception { - testSerialize("serializeMsgPack", sMsgPack, comboInput.msgPack); - } - - @Test - public void f12_parseMsgPack() throws Exception { - testParse("parseMsgPack", sMsgPack, pMsgPack, comboInput.msgPack); - } - - @Test - public void f13_parseMsgPackJsonEquivalency() throws Exception { - testParseJsonEquivalency("parseMsgPackJsonEquivalency", sMsgPack, pMsgPack, comboInput.json); - } - - @Test - public void f14_verifyMsgPack() throws Exception { - testParseVerify("verifyMsgPack", sMsgPack, pMsgPack); - } - - //-------------------------------------------------------------------------------- - // MsgPack - 't' property - //-------------------------------------------------------------------------------- - OutputStreamSerializer sMsgPackT = new MsgPackSerializerBuilder().beanTypePropertyName("t").build(); - InputStreamParser pMsgPackT = new MsgPackParserBuilder().beanTypePropertyName("t").build(); - - @Test - public void f21_serializeMsgPackT() throws Exception { - testSerialize("serializeMsgPackT", sMsgPackT, comboInput.msgPackT); - } - - @Test - public void f22_parseMsgPackT() throws Exception { - testParse("parseMsgPackT", sMsgPackT, pMsgPackT, comboInput.msgPackT); - } - - @Test - public void f23_parseMsgPackTJsonEquivalency() throws Exception { - testParseJsonEquivalency("parseMsgPackTJsonEquivalency", sMsgPackT, pMsgPackT, comboInput.json); - } - - @Test - public void f24_verifyMsgPackT() throws Exception { - testParseVerify("verifyMsgPackT", sMsgPackT, pMsgPackT); - } - - //-------------------------------------------------------------------------------- - // RdfXml - //-------------------------------------------------------------------------------- - WriterSerializer sRdfXml = RdfSerializer.DEFAULT_XMLABBREV; - ReaderParser pRdfXml = RdfParser.DEFAULT_XML; - - @Test - public void g11_serializeRdfXml() throws Exception { - testSerialize("serializeRdfXml", sRdfXml, comboInput.rdfXml); - } - - @Test - public void g12_parseRdfXml() throws Exception { - testParse("parseRdfXml", sRdfXml, pRdfXml, comboInput.rdfXml); - } - - @Test - public void g13_verifyRdfXml() throws Exception { - testParseVerify("verifyRdfXml", sRdfXml, pRdfXml); - } - - //-------------------------------------------------------------------------------- - // RdfXml - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sRdfXmlT = new RdfSerializerBuilder().language(LANG_RDF_XML_ABBREV).beanTypePropertyName("t").build(); - ReaderParser pRdfXmlT = new RdfParserBuilder().beanTypePropertyName("t").build(); - - @Test - public void g21_serializeRdfXmlT() throws Exception { - testSerialize("serializeRdfXmlT", sRdfXmlT, comboInput.rdfXmlT); - } - - @Test - public void g22_parseRdfXmlT() throws Exception { - testParse("parseRdfXmlT", sRdfXmlT, pRdfXmlT, comboInput.rdfXmlT); - } - - @Test - public void g23_verifyRdfXmlT() throws Exception { - testParseVerify("parseRdfXmlTVerify", sRdfXmlT, pRdfXmlT); - } - - //-------------------------------------------------------------------------------- - // RdfXml - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sRdfXmlR = new RdfSerializerBuilder().language(LANG_RDF_XML_ABBREV).ws().build(); - ReaderParser pRdfXmlR = RdfParser.DEFAULT_XML; - - @Test - public void g31_serializeRdfXmlR() throws Exception { - testSerialize("serializeRdfXmlR", sRdfXmlR, comboInput.rdfXmlR); - } - - @Test - public void g32_parseRdfXmlR() throws Exception { - testParse("parseRdfXmlR", sRdfXmlR, pRdfXmlR, comboInput.rdfXmlR); - } - - @Test - public void g33_verifyRdfXmlR() throws Exception { - testParseVerify("Verify", sRdfXmlR, pRdfXmlR); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/ComboSerializeTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/ComboSerializeTest.java b/juneau-core-test/src/test/java/org/apache/juneau/ComboSerializeTest.java deleted file mode 100644 index 6768d91..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/ComboSerializeTest.java +++ /dev/null @@ -1,367 +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.jena.Constants.*; - -import java.util.*; - -import org.apache.juneau.html.*; -import org.apache.juneau.internal.*; -import org.apache.juneau.jena.*; -import org.apache.juneau.json.*; -import org.apache.juneau.msgpack.*; -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. - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@SuppressWarnings({"rawtypes"}) -public abstract class ComboSerializeTest { - - /* Parameter template */ -// { -// "MyLabel", -// myInput, -// /* Json */ "xxx", -// /* JsonT */ "xxx", -// /* JsonR */ "xxx", -// /* Xml */ "xxx", -// /* XmlT */ "xxx", -// /* XmlR */ "xxx", -// /* XmlNs */ "xxx", -// /* Html */ "xxx", -// /* HtmlT */ "xxx", -// /* HtmlR */ "xxx", -// /* Uon */ "xxx", -// /* UonT */ "xxx", -// /* UonR */ "xxx", -// /* UrlEnc */ "xxx", -// /* UrlEncT */ "xxx", -// /* UrlEncR */ "xxx", -// /* MsgPack */ "xxx", -// /* MsgPackT */ "xxx", -// /* RdfXml */ "xxx", -// /* RdfXmlT */ "xxx", -// /* RdfXmlR */ "xxx", -// }, - - private final ComboInput comboInput; - - // These are the names of all the tests. - // You can comment out the names here to skip them. - private static final String[] runTests = { - "serializeJson", - "serializeJsonT", - "serializeJsonR", - "serializeXml", - "serializeXmlT", - "serializeXmlR", - "serializeXmlNs", - "serializeHtml", - "serializeHtmlT", - "serializeHtmlR", - "serializeUon", - "serializeUonT", - "serializeUonR", - "serializeUrlEncoding", - "serializeUrlEncodingT", - "serializeUrlEncodingR", - "serializeMsgPack", - "serializeMsgPackT", - "serializeRdfXml", - "serializeRdfXmlT", - "serializeRdfXmlR", - }; - - private static final Set<String> runTestsSet = new HashSet<String>(Arrays.asList(runTests)); - - private final boolean SKIP_RDF_TESTS = Boolean.getBoolean("skipRdfTests"); - - private Map<Serializer,Serializer> serializerMap = new IdentityHashMap<Serializer,Serializer>(); - - public ComboSerializeTest(ComboInput<?> comboInput) { - this.comboInput = comboInput; - } - - private Serializer getSerializer(Serializer s) throws Exception { - Serializer s2 = serializerMap.get(s); - if (s2 == null) { - s2 = applySettings(s); - serializerMap.put(s, s2); - } - return s2; - } - - private void testSerialize(String testName, Serializer s, String expected) throws Exception { - try { - s = getSerializer(s); - - boolean isRdf = s instanceof RdfSerializer; - - if ((isRdf && SKIP_RDF_TESTS) || expected.equals("SKIP") || ! runTestsSet.contains(testName) ) { - System.err.println(comboInput.label + "/" + testName + " for "+s.getClass().getSimpleName()+" skipped."); - return; - } - - String r = s.isWriterSerializer() ? ((WriterSerializer)s).serialize(comboInput.getInput()) : ((OutputStreamSerializer)s).serializeToHex(comboInput.getInput()); - - // Can't control RdfSerializer output well, so manually remove namespace declarations - // double-quotes with single-quotes, and spaces with tabs. - // Also because RDF sucks really bad and can't be expected to produce consistent testable results, - // we must also do an expensive sort-then-compare operation to verify the results. - if (isRdf) - r = r.replaceAll("<rdf:RDF[^>]*>", "<rdf:RDF>").replace('"', '\''); - - // Specifying "xxx" in the expected results will spit out what we should populate the field with. - if (expected.equals("xxx")) { - System.out.println(comboInput.label + "/" + testName + "=\n" + r.replaceAll("\n", "\\\\n").replaceAll("\t", "\\\\t")); // NOT DEBUG - System.out.println(r); - if (s instanceof MsgPackSerializer) { - System.out.println("decoded=["+new String(StringUtils.fromHex(r))+"]"); - } - } - - if (isRdf) - TestUtils.assertEqualsAfterSort(expected, r, "{0}/{1} serialize-normal failed", comboInput.label, testName); - else - TestUtils.assertEquals(expected, r, "{0}/{1} serialize-normal failed", comboInput.label, testName); - - } catch (AssertionError e) { - throw e; - } catch (Exception e) { - e.printStackTrace(); - throw new AssertionError(comboInput.label + "/" + testName + " failed. exception=" + e.getLocalizedMessage()); - } - } - - protected Serializer applySettings(Serializer s) throws Exception { - return s; - } - - //-------------------------------------------------------------------------------- - // JSON - //-------------------------------------------------------------------------------- - WriterSerializer sJson = JsonSerializer.DEFAULT_LAX; - - @Test - public void a11_serializeJson() throws Exception { - testSerialize("serializeJson", sJson, comboInput.json); - } - - //-------------------------------------------------------------------------------- - // JSON - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sJsonT = new JsonSerializerBuilder().simple().beanTypePropertyName("t").build(); - - @Test - public void a21_serializeJsonT() throws Exception { - testSerialize("serializeJsonT", sJsonT, comboInput.jsonT); - } - - //-------------------------------------------------------------------------------- - // JSON - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sJsonR = JsonSerializer.DEFAULT_LAX_READABLE; - - @Test - public void a31_serializeJsonR() throws Exception { - testSerialize("serializeJsonR", sJsonR, comboInput.jsonR); - } - - //-------------------------------------------------------------------------------- - // XML - //-------------------------------------------------------------------------------- - WriterSerializer sXml = XmlSerializer.DEFAULT_SQ; - - @Test - public void b11_serializeXml() throws Exception { - testSerialize("serializeXml", sXml, comboInput.xml); - } - - //-------------------------------------------------------------------------------- - // XML - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sXmlT = new XmlSerializerBuilder().sq().beanTypePropertyName("t").build(); - - @Test - public void b21_serializeXmlT() throws Exception { - testSerialize("serializeXmlT", sXmlT, comboInput.xmlT); - } - - //-------------------------------------------------------------------------------- - // XML - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sXmlR = XmlSerializer.DEFAULT_SQ_READABLE; - - @Test - public void b31_serializeXmlR() throws Exception { - testSerialize("serializeXmlR", sXmlR, comboInput.xmlR); - } - - //-------------------------------------------------------------------------------- - // XML - Namespaces - //-------------------------------------------------------------------------------- - WriterSerializer sXmlNs = XmlSerializer.DEFAULT_NS_SQ; - - @Test - public void b41_serializeXmlNs() throws Exception { - testSerialize("serializeXmlNs", sXmlNs, comboInput.xmlNs); - } - - //-------------------------------------------------------------------------------- - // HTML - //-------------------------------------------------------------------------------- - WriterSerializer sHtml = HtmlSerializer.DEFAULT_SQ; - - @Test - public void c11_serializeHtml() throws Exception { - testSerialize("serializeHtml", sHtml, comboInput.html); - } - - //-------------------------------------------------------------------------------- - // HTML - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sHtmlT = new HtmlSerializerBuilder().sq().beanTypePropertyName("t").build(); - - @Test - public void c21_serializeHtmlT() throws Exception { - testSerialize("serializeHtmlT", sHtmlT, comboInput.htmlT); - } - - //-------------------------------------------------------------------------------- - // HTML - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sHtmlR = HtmlSerializer.DEFAULT_SQ_READABLE; - - @Test - public void c31_serializeHtmlR() throws Exception { - testSerialize("serializeHtmlR", sHtmlR, comboInput.htmlR); - } - - //-------------------------------------------------------------------------------- - // UON - //-------------------------------------------------------------------------------- - WriterSerializer sUon = UonSerializer.DEFAULT; - - @Test - public void d11_serializeUon() throws Exception { - testSerialize("serializeUon", sUon, comboInput.uon); - } - - //-------------------------------------------------------------------------------- - // UON - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sUonT = new UonSerializerBuilder().beanTypePropertyName("t").build(); - - @Test - public void d21_serializeUonT() throws Exception { - testSerialize("serializeUonT", sUonT, comboInput.uonT); - } - - //-------------------------------------------------------------------------------- - // UON - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sUonR = UonSerializer.DEFAULT_READABLE; - - @Test - public void d31_serializeUonR() throws Exception { - testSerialize("serializeUonR", sUonR, comboInput.uonR); - } - - //-------------------------------------------------------------------------------- - // UrlEncoding - //-------------------------------------------------------------------------------- - WriterSerializer sUrlEncoding = UrlEncodingSerializer.DEFAULT; - - @Test - public void e11_serializeUrlEncoding() throws Exception { - testSerialize("serializeUrlEncoding", sUrlEncoding, comboInput.urlEncoding); - } - - //-------------------------------------------------------------------------------- - // UrlEncoding - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sUrlEncodingT = new UrlEncodingSerializerBuilder().beanTypePropertyName("t").build(); - - @Test - public void e21_serializeUrlEncodingT() throws Exception { - testSerialize("serializeUrlEncodingT", sUrlEncodingT, comboInput.urlEncodingT); - } - - //-------------------------------------------------------------------------------- - // UrlEncoding - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sUrlEncodingR = UrlEncodingSerializer.DEFAULT_READABLE; - - @Test - public void e31_serializeUrlEncodingR() throws Exception { - testSerialize("serializeUrlEncodingR", sUrlEncodingR, comboInput.urlEncodingR); - } - - //-------------------------------------------------------------------------------- - // MsgPack - //-------------------------------------------------------------------------------- - OutputStreamSerializer sMsgPack = MsgPackSerializer.DEFAULT; - - @Test - public void f11_serializeMsgPack() throws Exception { - testSerialize("serializeMsgPack", sMsgPack, comboInput.msgPack); - } - - //-------------------------------------------------------------------------------- - // MsgPack - 't' property - //-------------------------------------------------------------------------------- - OutputStreamSerializer sMsgPackT = new MsgPackSerializerBuilder().beanTypePropertyName("t").build(); - - @Test - public void f21_serializeMsgPackT() throws Exception { - testSerialize("serializeMsgPackT", sMsgPackT, comboInput.msgPackT); - } - - //-------------------------------------------------------------------------------- - // RdfXml - //-------------------------------------------------------------------------------- - WriterSerializer sRdfXml = RdfSerializer.DEFAULT_XMLABBREV; - - @Test - public void g11_serializeRdfXml() throws Exception { - testSerialize("serializeRdfXml", sRdfXml, comboInput.rdfXml); - } - - //-------------------------------------------------------------------------------- - // RdfXml - 't' property - //-------------------------------------------------------------------------------- - WriterSerializer sRdfXmlT = new RdfSerializerBuilder().language(LANG_RDF_XML_ABBREV).beanTypePropertyName("t").build(); - - @Test - public void g21_serializeRdfXmlT() throws Exception { - testSerialize("serializeRdfXmlT", sRdfXmlT, comboInput.rdfXmlT); - } - - //-------------------------------------------------------------------------------- - // RdfXml - Readable - //-------------------------------------------------------------------------------- - WriterSerializer sRdfXmlR = new RdfSerializerBuilder().language(LANG_RDF_XML_ABBREV).ws().build(); - - @Test - public void g31_serializeRdfXmlR() throws Exception { - testSerialize("serializeRdfXmlR", sRdfXmlR, comboInput.rdfXmlR); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/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 deleted file mode 100755 index be7c264..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/DataConversionTest.java +++ /dev/null @@ -1,155 +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.junit.Assert.*; - -import java.util.*; - -import org.apache.juneau.transforms.*; -import org.junit.*; - -@SuppressWarnings({"unchecked","rawtypes","javadoc"}) -public class DataConversionTest { - - @Before - public void beforeTest() { - TestUtils.setLocale(Locale.US); - } - - @After - public void afterTest() { - TestUtils.unsetLocale(); - } - - //==================================================================================================== - // testBasic - //==================================================================================================== - @Test - public void testBasic() throws Exception { - ObjectMap m = new ObjectMap(); - - // *** Number *** - m.put("x", 123); - assertEquals((int)m.getInt("x"), 123); - assertEquals((long)m.getLong("x"), 123); - - // *** Boolean *** - m.put("x", true); - assertEquals((boolean)m.getBoolean("x"), true); - - // *** Null *** - m.put("x", null); - assertNull(m.getString("x")); - assertNull(m.getInt("x")); - assertNull(m.getLong("x")); - assertNull(m.getBoolean("x")); - assertNull(m.getMap("x")); - assertNull(m.getObjectMap("x")); - assertNull(m.getList("x")); - assertNull(m.getObjectList("x")); - - // *** Map *** - m.put("x", new HashMap()); - assertEquals(m.getString("x"), "{}"); - - // *** ObjectMap *** - m.put("x", new ObjectMap("{foo:123}")); - assertEquals(m.getString("x"), "{foo:123}"); - - // *** Collection *** - Set s = new HashSet(); - s.add(123); - m.put("x", s); - assertEquals(m.getString("x"), "[123]"); - - // *** ObjectList *** - m.put("x", new ObjectList("[123]")); - assertEquals(m.getString("x"), "[123]"); - assertEquals(m.getList("x").size(), 1); - assertEquals(m.getObjectList("x").size(), 1); - - // *** Array *** - m.put("x", new Integer[]{123}); - assertEquals(m.getString("x"), "[123]"); - assertEquals(m.getList("x").size(), 1); - assertEquals(m.getObjectList("x").size(), 1); - - // *** Enum *** - m.put("x", TestEnum.ENUM2); - assertEquals(m.getString("x"), "ENUM2"); - assertFalse(m.getBoolean("x")); - try { - m.getMap("x"); - fail("Invalid conversion from Enum to Map"); - } catch (InvalidDataConversionException e) {} - try { - m.getObjectMap("x"); - fail("Invalid conversion from Enum to ObjectMap"); - } catch (InvalidDataConversionException e) {} - - // *** Not a bean *** - m.put("x", new NotABean("foo")); - assertEquals(m.getString("x"), "foo"); - try { - m.getInt("x"); - fail("Invalid conversion from NotABean to Integer"); - } catch (InvalidDataConversionException e) {} - try { - m.getLong("x"); - fail("Invalid conversion from NotABean to Long"); - } catch (InvalidDataConversionException e) {} - assertFalse(m.getBoolean("x")); - try { - m.getMap("x"); - fail("Invalid conversion from NotABean to Map"); - } catch (InvalidDataConversionException e) {} - try { - m.getObjectMap("x"); - fail("Invalid conversion from NotABean to ObjectMap"); - } catch (InvalidDataConversionException e) {} - - } - - public enum TestEnum { - ENUM0, ENUM1, ENUM2 - } - - public class NotABean { - private String arg; - - public NotABean(String arg) { - this.arg = arg; - } - - @Override /* Object */ - public String toString() { - return arg; - } - } - - //==================================================================================================== - // Data conversions with swaps. - //==================================================================================================== - @Test - public void testObjectSwaps() throws Exception { - String s = "Jan 12, 2001"; - 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); - assertEquals(2001, c.get(Calendar.YEAR)); - s = session.convertToType(c, String.class); - assertEquals("Jan 12, 2001", s); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/DynaBeanComboTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/DynaBeanComboTest.java b/juneau-core-test/src/test/java/org/apache/juneau/DynaBeanComboTest.java deleted file mode 100644 index 9afaaf8..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/DynaBeanComboTest.java +++ /dev/null @@ -1,339 +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 java.util.*; - -import org.apache.juneau.annotation.*; -import org.apache.juneau.parser.*; -import org.apache.juneau.serializer.*; -import org.apache.juneau.transforms.*; -import org.junit.*; -import org.junit.runner.*; -import org.junit.runners.*; - -/** - * Exhaustive serialization tests DynaBean support. - */ -@RunWith(Parameterized.class) -@SuppressWarnings({"javadoc"}) -public class DynaBeanComboTest extends ComboRoundTripTest { - - @Parameterized.Parameters - public static Collection<Object[]> getParameters() { - return Arrays.asList(new Object[][] { - { /* 0 */ - new ComboInput<BeanWithDynaField>( - "BeanWithDynaField", - BeanWithDynaField.class, - new BeanWithDynaField().init(), - /* Json */ "{f1:1,f2a:'a',f2b:'b',f3:3}", - /* JsonT */ "{f1:1,f2a:'a',f2b:'b',f3:3}", - /* JsonR */ "{\n\tf1: 1,\n\tf2a: 'a',\n\tf2b: 'b',\n\tf3: 3\n}", - /* Xml */ "<object><f1>1</f1><f2a>a</f2a><f2b>b</f2b><f3>3</f3></object>", - /* XmlT */ "<object><f1>1</f1><f2a>a</f2a><f2b>b</f2b><f3>3</f3></object>", - /* XmlR */ "<object>\n\t<f1>1</f1>\n\t<f2a>a</f2a>\n\t<f2b>b</f2b>\n\t<f3>3</f3>\n</object>\n", - /* XmlNs */ "<object><f1>1</f1><f2a>a</f2a><f2b>b</f2b><f3>3</f3></object>", - /* Html */ "<table><tr><td>f1</td><td>1</td></tr><tr><td>f2a</td><td>a</td></tr><tr><td>f2b</td><td>b</td></tr><tr><td>f3</td><td>3</td></tr></table>", - /* HtmlT */ "<table><tr><td>f1</td><td>1</td></tr><tr><td>f2a</td><td>a</td></tr><tr><td>f2b</td><td>b</td></tr><tr><td>f3</td><td>3</td></tr></table>", - /* HtmlR */ "<table>\n\t<tr>\n\t\t<td>f1</td>\n\t\t<td>1</td>\n\t</tr>\n\t<tr>\n\t\t<td>f2a</td>\n\t\t<td>a</td>\n\t</tr>\n\t<tr>\n\t\t<td>f2b</td>\n\t\t<td>b</td>\n\t</tr>\n\t<tr>\n\t\t<td>f3</td>\n\t\t<td>3</td>\n\t</tr>\n</table>\n", - /* Uon */ "(f1=1,f2a=a,f2b=b,f3=3)", - /* UonT */ "(f1=1,f2a=a,f2b=b,f3=3)", - /* UonR */ "(\n\tf1=1,\n\tf2a=a,\n\tf2b=b,\n\tf3=3\n)", - /* UrlEnc */ "f1=1&f2a=a&f2b=b&f3=3", - /* UrlEncT */ "f1=1&f2a=a&f2b=b&f3=3", - /* UrlEncR */ "f1=1\n&f2a=a\n&f2b=b\n&f3=3", - /* MsgPack */ "84A2663101A3663261A161A3663262A162A2663303", - /* MsgPackT */ "84A2663101A3663261A161A3663262A162A2663303", - /* RdfXml */ "<rdf:RDF>\n<rdf:Description>\n<jp:f1>1</jp:f1>\n<jp:f2a>a</jp:f2a>\n<jp:f2b>b</jp:f2b>\n<jp:f3>3</jp:f3>\n</rdf:Description>\n</rdf:RDF>\n", - /* RdfXmlT */ "<rdf:RDF>\n<rdf:Description>\n<jp:f1>1</jp:f1>\n<jp:f2a>a</jp:f2a>\n<jp:f2b>b</jp:f2b>\n<jp:f3>3</jp:f3>\n</rdf:Description>\n</rdf:RDF>\n", - /* RdfXmlR */ "<rdf:RDF>\n <rdf:Description>\n <jp:f1>1</jp:f1>\n <jp:f2a>a</jp:f2a>\n <jp:f2b>b</jp:f2b>\n <jp:f3>3</jp:f3>\n </rdf:Description>\n</rdf:RDF>\n" - ) - { - @Override - public void verify(BeanWithDynaField o) { - assertType(BeanWithDynaField.class, o); - } - } - }, - { /* 1 */ - new ComboInput<BeanWithDynaMethods>( - "BeanWithDynaMethods", - BeanWithDynaMethods.class, - new BeanWithDynaMethods().init(), - /* Json */ "{f1:1,f2a:'a',f2b:'b',f3:3}", - /* JsonT */ "{f1:1,f2a:'a',f2b:'b',f3:3}", - /* JsonR */ "{\n\tf1: 1,\n\tf2a: 'a',\n\tf2b: 'b',\n\tf3: 3\n}", - /* Xml */ "<object><f1>1</f1><f2a>a</f2a><f2b>b</f2b><f3>3</f3></object>", - /* XmlT */ "<object><f1>1</f1><f2a>a</f2a><f2b>b</f2b><f3>3</f3></object>", - /* XmlR */ "<object>\n\t<f1>1</f1>\n\t<f2a>a</f2a>\n\t<f2b>b</f2b>\n\t<f3>3</f3>\n</object>\n", - /* XmlNs */ "<object><f1>1</f1><f2a>a</f2a><f2b>b</f2b><f3>3</f3></object>", - /* Html */ "<table><tr><td>f1</td><td>1</td></tr><tr><td>f2a</td><td>a</td></tr><tr><td>f2b</td><td>b</td></tr><tr><td>f3</td><td>3</td></tr></table>", - /* HtmlT */ "<table><tr><td>f1</td><td>1</td></tr><tr><td>f2a</td><td>a</td></tr><tr><td>f2b</td><td>b</td></tr><tr><td>f3</td><td>3</td></tr></table>", - /* HtmlR */ "<table>\n\t<tr>\n\t\t<td>f1</td>\n\t\t<td>1</td>\n\t</tr>\n\t<tr>\n\t\t<td>f2a</td>\n\t\t<td>a</td>\n\t</tr>\n\t<tr>\n\t\t<td>f2b</td>\n\t\t<td>b</td>\n\t</tr>\n\t<tr>\n\t\t<td>f3</td>\n\t\t<td>3</td>\n\t</tr>\n</table>\n", - /* Uon */ "(f1=1,f2a=a,f2b=b,f3=3)", - /* UonT */ "(f1=1,f2a=a,f2b=b,f3=3)", - /* UonR */ "(\n\tf1=1,\n\tf2a=a,\n\tf2b=b,\n\tf3=3\n)", - /* UrlEnc */ "f1=1&f2a=a&f2b=b&f3=3", - /* UrlEncT */ "f1=1&f2a=a&f2b=b&f3=3", - /* UrlEncR */ "f1=1\n&f2a=a\n&f2b=b\n&f3=3", - /* MsgPack */ "84A2663101A3663261A161A3663262A162A2663303", - /* MsgPackT */ "84A2663101A3663261A161A3663262A162A2663303", - /* RdfXml */ "<rdf:RDF>\n<rdf:Description>\n<jp:f1>1</jp:f1>\n<jp:f2a>a</jp:f2a>\n<jp:f2b>b</jp:f2b>\n<jp:f3>3</jp:f3>\n</rdf:Description>\n</rdf:RDF>\n", - /* RdfXmlT */ "<rdf:RDF>\n<rdf:Description>\n<jp:f1>1</jp:f1>\n<jp:f2a>a</jp:f2a>\n<jp:f2b>b</jp:f2b>\n<jp:f3>3</jp:f3>\n</rdf:Description>\n</rdf:RDF>\n", - /* RdfXmlR */ "<rdf:RDF>\n <rdf:Description>\n <jp:f1>1</jp:f1>\n <jp:f2a>a</jp:f2a>\n <jp:f2b>b</jp:f2b>\n <jp:f3>3</jp:f3>\n </rdf:Description>\n</rdf:RDF>\n" - ) - { - @Override - public void verify(BeanWithDynaMethods o) { - assertType(BeanWithDynaMethods.class, o); - Assert.assertTrue(o.setterCalled); - } - } - }, - { /* 2 */ - new ComboInput<BeanWithDynaGetterOnly>( - "BeanWithDynaGetterOnly", - BeanWithDynaGetterOnly.class, - new BeanWithDynaGetterOnly().init(), - /* Json */ "{f1:1,f2a:'a',f2b:'b',f3:3}", - /* JsonT */ "{f1:1,f2a:'a',f2b:'b',f3:3}", - /* JsonR */ "{\n\tf1: 1,\n\tf2a: 'a',\n\tf2b: 'b',\n\tf3: 3\n}", - /* Xml */ "<object><f1>1</f1><f2a>a</f2a><f2b>b</f2b><f3>3</f3></object>", - /* XmlT */ "<object><f1>1</f1><f2a>a</f2a><f2b>b</f2b><f3>3</f3></object>", - /* XmlR */ "<object>\n\t<f1>1</f1>\n\t<f2a>a</f2a>\n\t<f2b>b</f2b>\n\t<f3>3</f3>\n</object>\n", - /* XmlNs */ "<object><f1>1</f1><f2a>a</f2a><f2b>b</f2b><f3>3</f3></object>", - /* Html */ "<table><tr><td>f1</td><td>1</td></tr><tr><td>f2a</td><td>a</td></tr><tr><td>f2b</td><td>b</td></tr><tr><td>f3</td><td>3</td></tr></table>", - /* HtmlT */ "<table><tr><td>f1</td><td>1</td></tr><tr><td>f2a</td><td>a</td></tr><tr><td>f2b</td><td>b</td></tr><tr><td>f3</td><td>3</td></tr></table>", - /* HtmlR */ "<table>\n\t<tr>\n\t\t<td>f1</td>\n\t\t<td>1</td>\n\t</tr>\n\t<tr>\n\t\t<td>f2a</td>\n\t\t<td>a</td>\n\t</tr>\n\t<tr>\n\t\t<td>f2b</td>\n\t\t<td>b</td>\n\t</tr>\n\t<tr>\n\t\t<td>f3</td>\n\t\t<td>3</td>\n\t</tr>\n</table>\n", - /* Uon */ "(f1=1,f2a=a,f2b=b,f3=3)", - /* UonT */ "(f1=1,f2a=a,f2b=b,f3=3)", - /* UonR */ "(\n\tf1=1,\n\tf2a=a,\n\tf2b=b,\n\tf3=3\n)", - /* UrlEnc */ "f1=1&f2a=a&f2b=b&f3=3", - /* UrlEncT */ "f1=1&f2a=a&f2b=b&f3=3", - /* UrlEncR */ "f1=1\n&f2a=a\n&f2b=b\n&f3=3", - /* MsgPack */ "84A2663101A3663261A161A3663262A162A2663303", - /* MsgPackT */ "84A2663101A3663261A161A3663262A162A2663303", - /* RdfXml */ "<rdf:RDF>\n<rdf:Description>\n<jp:f1>1</jp:f1>\n<jp:f2a>a</jp:f2a>\n<jp:f2b>b</jp:f2b>\n<jp:f3>3</jp:f3>\n</rdf:Description>\n</rdf:RDF>\n", - /* RdfXmlT */ "<rdf:RDF>\n<rdf:Description>\n<jp:f1>1</jp:f1>\n<jp:f2a>a</jp:f2a>\n<jp:f2b>b</jp:f2b>\n<jp:f3>3</jp:f3>\n</rdf:Description>\n</rdf:RDF>\n", - /* RdfXmlR */ "<rdf:RDF>\n <rdf:Description>\n <jp:f1>1</jp:f1>\n <jp:f2a>a</jp:f2a>\n <jp:f2b>b</jp:f2b>\n <jp:f3>3</jp:f3>\n </rdf:Description>\n</rdf:RDF>\n" - ) - { - @Override - public void verify(BeanWithDynaGetterOnly o) { - assertType(BeanWithDynaGetterOnly.class, o); - } - } - }, - { /* 3 */ - new ComboInput<BeanWithDynaFieldSwapped>( - "BeanWithDynaFieldSwapped", - BeanWithDynaFieldSwapped.class, - new BeanWithDynaFieldSwapped().init(), - /* Json */ "{f1a:'1901-03-03T18:11:12Z'}", - /* JsonT */ "{f1a:'1901-03-03T18:11:12Z'}", - /* JsonR */ "{\n\tf1a: '1901-03-03T18:11:12Z'\n}", - /* Xml */ "<object><f1a>1901-03-03T18:11:12Z</f1a></object>", - /* XmlT */ "<object><f1a>1901-03-03T18:11:12Z</f1a></object>", - /* XmlR */ "<object>\n\t<f1a>1901-03-03T18:11:12Z</f1a>\n</object>\n", - /* XmlNs */ "<object><f1a>1901-03-03T18:11:12Z</f1a></object>", - /* Html */ "<table><tr><td>f1a</td><td>1901-03-03T18:11:12Z</td></tr></table>", - /* HtmlT */ "<table><tr><td>f1a</td><td>1901-03-03T18:11:12Z</td></tr></table>", - /* HtmlR */ "<table>\n\t<tr>\n\t\t<td>f1a</td>\n\t\t<td>1901-03-03T18:11:12Z</td>\n\t</tr>\n</table>\n", - /* Uon */ "(f1a=1901-03-03T18:11:12Z)", - /* UonT */ "(f1a=1901-03-03T18:11:12Z)", - /* UonR */ "(\n\tf1a=1901-03-03T18:11:12Z\n)", - /* UrlEnc */ "f1a=1901-03-03T18:11:12Z", - /* UrlEncT */ "f1a=1901-03-03T18:11:12Z", - /* UrlEncR */ "f1a=1901-03-03T18:11:12Z", - /* MsgPack */ "81A3663161B4313930312D30332D30335431383A31313A31325A", - /* MsgPackT */ "81A3663161B4313930312D30332D30335431383A31313A31325A", - /* RdfXml */ "<rdf:RDF>\n<rdf:Description>\n<jp:f1a>1901-03-03T18:11:12Z</jp:f1a>\n</rdf:Description>\n</rdf:RDF>\n", - /* RdfXmlT */ "<rdf:RDF>\n<rdf:Description>\n<jp:f1a>1901-03-03T18:11:12Z</jp:f1a>\n</rdf:Description>\n</rdf:RDF>\n", - /* RdfXmlR */ "<rdf:RDF>\n <rdf:Description>\n <jp:f1a>1901-03-03T18:11:12Z</jp:f1a>\n </rdf:Description>\n</rdf:RDF>\n" - ) - { - @Override - public void verify(BeanWithDynaFieldSwapped o) { - assertType(BeanWithDynaFieldSwapped.class, o); - assertType(Calendar.class, o.f1.get("f1a")); - } - } - }, - { /* 4 */ - new ComboInput<BeanWithDynaFieldStringList>( - "BeanWithDynaFieldStringList", - BeanWithDynaFieldStringList.class, - new BeanWithDynaFieldStringList().init(), - /* Json */ "{f1a:['foo','bar']}", - /* JsonT */ "{f1a:['foo','bar']}", - /* JsonR */ "{\n\tf1a: [\n\t\t'foo',\n\t\t'bar'\n\t]\n}", - /* Xml */ "<object><f1a><string>foo</string><string>bar</string></f1a></object>", - /* XmlT */ "<object><f1a><string>foo</string><string>bar</string></f1a></object>", - /* XmlR */ "<object>\n\t<f1a>\n\t\t<string>foo</string>\n\t\t<string>bar</string>\n\t</f1a>\n</object>\n", - /* XmlNs */ "<object><f1a><string>foo</string><string>bar</string></f1a></object>", - /* Html */ "<table><tr><td>f1a</td><td><ul><li>foo</li><li>bar</li></ul></td></tr></table>", - /* HtmlT */ "<table><tr><td>f1a</td><td><ul><li>foo</li><li>bar</li></ul></td></tr></table>", - /* HtmlR */ "<table>\n\t<tr>\n\t\t<td>f1a</td>\n\t\t<td>\n\t\t\t<ul>\n\t\t\t\t<li>foo</li>\n\t\t\t\t<li>bar</li>\n\t\t\t</ul>\n\t\t</td>\n\t</tr>\n</table>\n", - /* Uon */ "(f1a=@(foo,bar))", - /* UonT */ "(f1a=@(foo,bar))", - /* UonR */ "(\n\tf1a=@(\n\t\tfoo,\n\t\tbar\n\t)\n)", - /* UrlEnc */ "f1a=@(foo,bar)", - /* UrlEncT */ "f1a=@(foo,bar)", - /* UrlEncR */ "f1a=@(\n\tfoo,\n\tbar\n)", - /* MsgPack */ "81A366316192A3666F6FA3626172", - /* MsgPackT */ "81A366316192A3666F6FA3626172", - /* RdfXml */ "<rdf:RDF>\n<rdf:Description>\n<jp:f1a>\n<rdf:Seq>\n<rdf:li>foo</rdf:li>\n<rdf:li>bar</rdf:li>\n</rdf:Seq>\n</jp:f1a>\n</rdf:Description>\n</rdf:RDF>\n", - /* RdfXmlT */ "<rdf:RDF>\n<rdf:Description>\n<jp:f1a>\n<rdf:Seq>\n<rdf:li>foo</rdf:li>\n<rdf:li>bar</rdf:li>\n</rdf:Seq>\n</jp:f1a>\n</rdf:Description>\n</rdf:RDF>\n", - /* RdfXmlR */ "<rdf:RDF>\n <rdf:Description>\n <jp:f1a>\n <rdf:Seq>\n <rdf:li>foo</rdf:li>\n <rdf:li>bar</rdf:li>\n </rdf:Seq>\n </jp:f1a>\n </rdf:Description>\n</rdf:RDF>\n" - ) - { - @Override - public void verify(BeanWithDynaFieldStringList o) { - assertType(BeanWithDynaFieldStringList.class, o); - } - } - }, - }); - } - - public DynaBeanComboTest(ComboInput<?> comboInput) { - super(comboInput); - } - - @Override - protected Serializer applySettings(Serializer s) throws Exception { - return s.builder().trimNullProperties(false).build(); - } - - @Override - protected Parser applySettings(Parser p) throws Exception { - return p.builder().build(); - } - - @Bean(sort=true) - public static class BeanWithDynaField { - public int f1; - @BeanProperty(name="*") - public Map<String,Object> f2 = new LinkedHashMap<String,Object>(); - public int f3; - - public BeanWithDynaField init() { - this.f1 = 1; - this.f2 = new ObjectMap().append("f2a", "a").append("f2b", "b"); - this.f3 = 3; - return this; - } - } - - @Bean(sort=true) - public static class BeanWithDynaMethods { - - private int f1, f3; - private Map<String,Object> f2 = new LinkedHashMap<String,Object>(); - private boolean setterCalled = false; - - public int getF1() { - return f1; - } - public void setF1(int f1) { - this.f1 = f1; - } - public int getF3() { - return f3; - } - public void setF3(int f3) { - this.f3 = f3; - } - - @BeanProperty(name="*") - public Map<String, Object> xxx() { - return f2; - } - - @BeanProperty(name="*") - public void yyy(String name, Object o) { - setterCalled = true; - this.f2.put(name, o); - } - - public BeanWithDynaMethods init() { - this.f1 = 1; - this.f2 = new ObjectMap().append("f2a", "a").append("f2b", "b"); - this.f3 = 3; - return this; - } - } - - @Bean(sort=true) - public static class BeanWithDynaGetterOnly { - - private int f1, f3; - private Map<String,Object> f2 = new LinkedHashMap<String,Object>(); - - public int getF1() { - return f1; - } - public void setF1(int f1) { - this.f1 = f1; - } - public int getF3() { - return f3; - } - public void setF3(int f3) { - this.f3 = f3; - } - - @BeanProperty(name="*") - public Map<String, Object> xxx() { - return f2; - } - - public BeanWithDynaGetterOnly init() { - this.f1 = 1; - this.f2 = new ObjectMap().append("f2a", "a").append("f2b", "b"); - this.f3 = 3; - return this; - } - } - - private static Calendar singleDate = new GregorianCalendar(TimeZone.getTimeZone("PST")); - static { - singleDate.setTimeInMillis(0); - singleDate.set(1901, 2, 3, 10, 11, 12); - } - - @Bean(sort=true) - public static class BeanWithDynaFieldSwapped { - @BeanProperty(name="*", swap=CalendarSwap.ISO8601DTZ.class) - public Map<String,Calendar> f1 = new LinkedHashMap<String,Calendar>(); - - public BeanWithDynaFieldSwapped init() { - this.f1.put("f1a", singleDate); - return this; - } - } - - @Bean(sort=true) - public static class BeanWithDynaFieldStringList { - @BeanProperty(name="*") - public Map<String,List<String>> f1 = new LinkedHashMap<String,List<String>>(); - - public BeanWithDynaFieldStringList init() { - this.f1.put("f1a", Arrays.asList(new String[]{"foo","bar"})); - return this; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/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 deleted file mode 100755 index e22d86d..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/IgnoredClassesTest.java +++ /dev/null @@ -1,72 +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 static org.junit.Assume.*; - -import java.io.*; - -import org.apache.juneau.json.*; -import org.junit.*; - -@SuppressWarnings("javadoc") -public class IgnoredClassesTest { - - //==================================================================================================== - // testFilesRenderedAsStrings - //==================================================================================================== - @Test - public void testFilesRenderedAsStrings() throws Exception { - assumeTrue(System.getProperty("os.name").toLowerCase().startsWith("win")); - // Files should be rendered as strings. - File f = new File("C:/temp"); - assertObjectEquals("'C:\\\\temp'", f); - } - - //==================================================================================================== - // testIgnorePackages - //==================================================================================================== - @Test - public void testIgnorePackages() throws Exception { - A a = new 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.build().serialize(a)); - s.notBeanPackages("org.apache.juneau.*"); - assertEquals("'isNotBean'", s.build().serialize(a)); - s.removeNotBeanPackages("org.apache.juneau.*"); - 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.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 { - public String f1 = "isBean"; - @Override /* Object */ - public String toString() { - return "isNotBean"; - } - } - // TODO - Ignored packages. -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/JacocoDummyTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/JacocoDummyTest.java b/juneau-core-test/src/test/java/org/apache/juneau/JacocoDummyTest.java deleted file mode 100755 index 98b1212..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/JacocoDummyTest.java +++ /dev/null @@ -1,47 +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 java.lang.reflect.*; - -import org.apache.juneau.ini.*; -import org.apache.juneau.internal.*; -import org.apache.juneau.jena.*; -import org.apache.juneau.xml.annotation.*; -import org.junit.*; - -@SuppressWarnings("javadoc") -public class JacocoDummyTest { - - //==================================================================================================== - // Dummy code to add test coverage in Jacoco. - //==================================================================================================== - @Test - public void accessPrivateConstructorsOnStaticUtilityClasses() throws Exception { - - Class<?>[] classes = new Class[] { - StringUtils.class, ArrayUtils.class, ClassUtils.class, CollectionUtils.class, ConfigUtils.class - }; - - for (Class<?> c : classes) { - Constructor<?> c1 = c.getDeclaredConstructor(); - c1.setAccessible(true); - c1.newInstance(); - } - - ConfigFileFormat.valueOf(ConfigFileFormat.INI.toString()); - RdfCollectionFormat.valueOf(RdfCollectionFormat.DEFAULT.toString()); - XmlFormat.valueOf(XmlFormat.DEFAULT.toString()); - Visibility.valueOf(Visibility.DEFAULT.toString()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/ab15d45b/juneau-core-test/src/test/java/org/apache/juneau/MaxIndentTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/MaxIndentTest.java b/juneau-core-test/src/test/java/org/apache/juneau/MaxIndentTest.java deleted file mode 100644 index a88cba0..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/MaxIndentTest.java +++ /dev/null @@ -1,313 +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 java.util.*; - -import org.apache.juneau.html.*; -import org.apache.juneau.json.*; -import org.apache.juneau.serializer.*; -import org.apache.juneau.test.pojos.*; -import org.apache.juneau.uon.*; -import org.apache.juneau.urlencoding.*; -import org.apache.juneau.xml.*; -import org.junit.*; -import org.junit.runner.*; -import org.junit.runners.*; - -/** - * Exhaustive serialization tests DynaBean support. - */ -@RunWith(Parameterized.class) -@SuppressWarnings({"javadoc","serial"}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class MaxIndentTest { - - @Parameterized.Parameters - public static Collection<Object[]> getParameters() { - return Arrays.asList(new Object[][] { - { /* 0 */ - new Input( - "List1dOfBeans-0", - new List1dOfBeans().init1(), - 0, - /* Json */ "[{a:1, b:'foo'}]", - /* Xml */ "<array><object><a>1</a><b>foo</b></object></array>\n", - /* Html */ "<table _type='array'><tr><th>a</th><th>b</th></tr><tr><td>1</td><td>foo</td></tr></table>\n", - /* Uon */ "@((a=1,b=foo))", - /* UrlEnc */ "0=(a=1,b=foo)" - ) - }, - { /* 1 */ - new Input( - "List1dOfBeans-1", - new List1dOfBeans().init1(), - 1, - /* Json */ "[\n\t{a:1, b:'foo'}\n]", - /* Xml */ "<array>\n\t<object><a>1</a><b>foo</b></object>\n</array>\n", - /* Html */ "<table _type='array'>\n\t<tr><th>a</th><th>b</th></tr>\n\t<tr><td>1</td><td>foo</td></tr>\n</table>\n", - /* Uon */ "@(\n\t(a=1,b=foo)\n)", - /* UrlEnc */ "0=(\n\ta=1,\n\tb=foo\n)" - ) - }, - { /* 2 */ - new Input( - "List1dOfBeans-2", - new List1dOfBeans().init1(), - 2, - /* Json */ "[\n\t{\n\t\ta: 1,\n\t\tb: 'foo'\n\t}\n]", - /* Xml */ "<array>\n\t<object>\n\t\t<a>1</a>\n\t\t<b>foo</b>\n\t</object>\n</array>\n", - /* Html */ "<table _type='array'>\n\t<tr>\n\t\t<th>a</th>\n\t\t<th>b</th>\n\t</tr>\n\t<tr>\n\t\t<td>1</td>\n\t\t<td>foo</td>\n\t</tr>\n</table>\n", - /* Uon */ "@(\n\t(\n\t\ta=1,\n\t\tb=foo\n\t)\n)", - /* UrlEnc */ "0=(\n\ta=1,\n\tb=foo\n)" - ) - }, - { /* 3 */ - new Input( - "List2dOfBeans-0", - new List2dOfBeans().init2(), - 0, - /* Json */ "[[{a:1, b:'foo'}]]", - /* Xml */ "<array><array><object><a>1</a><b>foo</b></object></array></array>\n", - /* Html */ "<ul><li><table _type='array'><tr><th>a</th><th>b</th></tr><tr><td>1</td><td>foo</td></tr></table></li></ul>\n", - /* Uon */ "@(@((a=1,b=foo)))", - /* UrlEnc */ "0=@((a=1,b=foo))" - ) - }, - { /* 4 */ - new Input( - "List2dOfBeans-1", - new List2dOfBeans().init2(), - 1, - /* Json */ "[\n\t[{a:1, b:'foo'}]\n]", - /* Xml */ "<array>\n\t<array><object><a>1</a><b>foo</b></object></array>\n</array>\n", - /* Html */ "<ul>\n\t<li><table _type='array'><tr><th>a</th><th>b</th></tr><tr><td>1</td><td>foo</td></tr></table></li>\n</ul>\n", - /* Uon */ "@(\n\t@((a=1,b=foo))\n)", - /* UrlEnc */ "0=@(\n\t(a=1,b=foo)\n)" - ) - }, - { /* 5 */ - new Input( - "List2dOfBeans-2", - new List2dOfBeans().init2(), - 2, - /* Json */ "[\n\t[\n\t\t{a:1, b:'foo'}\n\t]\n]", - /* Xml */ "<array>\n\t<array>\n\t\t<object><a>1</a><b>foo</b></object>\n\t</array>\n</array>\n", - /* Html */ "<ul>\n\t<li>\n\t\t<table _type='array'><tr><th>a</th><th>b</th></tr><tr><td>1</td><td>foo</td></tr></table>\n\t</li>\n</ul>\n", - /* Uon */ "@(\n\t@(\n\t\t(a=1,b=foo)\n\t)\n)", - /* UrlEnc */ "0=@(\n\t(\n\t\ta=1,\n\t\tb=foo\n\t)\n)" - ) - }, - { /* 6 */ - new Input( - "List2dOfBeans-3", - new List2dOfBeans().init2(), - 3, - /* Json */ "[\n\t[\n\t\t{\n\t\t\ta: 1,\n\t\t\tb: 'foo'\n\t\t}\n\t]\n]", - /* Xml */ "<array>\n\t<array>\n\t\t<object>\n\t\t\t<a>1</a>\n\t\t\t<b>foo</b>\n\t\t</object>\n\t</array>\n</array>\n", - /* Html */ "<ul>\n\t<li>\n\t\t<table _type='array'>\n\t\t\t<tr><th>a</th><th>b</th></tr>\n\t\t\t<tr><td>1</td><td>foo</td></tr>\n\t\t</table>\n\t</li>\n</ul>\n", - /* Uon */ "@(\n\t@(\n\t\t(\n\t\t\ta=1,\n\t\t\tb=foo\n\t\t)\n\t)\n)", - /* UrlEnc */ "0=@(\n\t(\n\t\ta=1,\n\t\tb=foo\n\t)\n)" - ) - }, - { /* 7 */ - new Input( - "Map1dOfBeans-0", - new Map1dOfBeans().init1(), - 0, - /* Json */ "{a:{a:1, b:'foo'}}", - /* Xml */ "<object><a><a>1</a><b>foo</b></a></object>\n", - /* Html */ "<table><tr><td>a</td><td><table><tr><td>a</td><td>1</td></tr><tr><td>b</td><td>foo</td></tr></table></td></tr></table>\n", - /* Uon */ "(a=(a=1,b=foo))", - /* UrlEnc */ "a=(a=1,b=foo)" - ) - }, - { /* 8 */ - new Input( - "Map1dOfBeans-1", - new Map1dOfBeans().init1(), - 1, - /* Json */ "{\n\ta: {a:1, b:'foo'}\n}", - /* Xml */ "<object>\n\t<a><a>1</a><b>foo</b></a>\n</object>\n", - /* Html */ "<table>\n\t<tr><td>a</td><td><table><tr><td>a</td><td>1</td></tr><tr><td>b</td><td>foo</td></tr></table></td></tr>\n</table>\n", - /* Uon */ "(\n\ta=(a=1,b=foo)\n)", - /* UrlEnc */ "a=(\n\ta=1,\n\tb=foo\n)" - ) - }, - { /* 9 */ - new Input( - "Map1dOfBeans-2", - new Map1dOfBeans().init1(), - 2, - /* Json */ "{\n\ta: {\n\t\ta: 1,\n\t\tb: 'foo'\n\t}\n}", - /* Xml */ "<object>\n\t<a>\n\t\t<a>1</a>\n\t\t<b>foo</b>\n\t</a>\n</object>\n", - /* Html */ "<table>\n\t<tr>\n\t\t<td>a</td>\n\t\t<td><table><tr><td>a</td><td>1</td></tr><tr><td>b</td><td>foo</td></tr></table></td>\n\t</tr>\n</table>\n", - /* Uon */ "(\n\ta=(\n\t\ta=1,\n\t\tb=foo\n\t)\n)", - /* UrlEnc */ "a=(\n\ta=1,\n\tb=foo\n)" - ) - }, - { /* 10 */ - new Input( - "Map2dOfBeans-0", - new Map2dOfBeans().init2(), - 0, - /* Json */ "{b:{a:{a:1, b:'foo'}}}", - /* Xml */ "<object><b><a><a>1</a><b>foo</b></a></b></object>\n", - /* Html */ "<table><tr><td>b</td><td><table><tr><td>a</td><td><table><tr><td>a</td><td>1</td></tr><tr><td>b</td><td>foo</td></tr></table></td></tr></table></td></tr></table>\n", - /* Uon */ "(b=(a=(a=1,b=foo)))", - /* UrlEnc */ "b=(a=(a=1,b=foo))" - ) - }, - { /* 11 */ - new Input( - "Map2dOfBeans-1", - new Map2dOfBeans().init2(), - 1, - /* Json */ "{\n\tb: {a:{a:1, b:'foo'}}\n}", - /* Xml */ "<object>\n\t<b><a><a>1</a><b>foo</b></a></b>\n</object>\n", - /* Html */ "<table>\n\t<tr><td>b</td><td><table><tr><td>a</td><td><table><tr><td>a</td><td>1</td></tr><tr><td>b</td><td>foo</td></tr></table></td></tr></table></td></tr>\n</table>\n", - /* Uon */ "(\n\tb=(a=(a=1,b=foo))\n)", - /* UrlEnc */ "b=(\n\ta=(a=1,b=foo)\n)" - ) - }, - { /* 12 */ - new Input( - "Map2dOfBeans-2", - new Map2dOfBeans().init2(), - 2, - /* Json */ "{\n\tb: {\n\t\ta: {a:1, b:'foo'}\n\t}\n}", - /* Xml */ "<object>\n\t<b>\n\t\t<a><a>1</a><b>foo</b></a>\n\t</b>\n</object>\n", - /* Html */ "<table>\n\t<tr>\n\t\t<td>b</td>\n\t\t<td><table><tr><td>a</td><td><table><tr><td>a</td><td>1</td></tr><tr><td>b</td><td>foo</td></tr></table></td></tr></table></td>\n\t</tr>\n</table>\n", - /* Uon */ "(\n\tb=(\n\t\ta=(a=1,b=foo)\n\t)\n)", - /* UrlEnc */ "b=(\n\ta=(\n\t\ta=1,\n\t\tb=foo\n\t)\n)" - ) - }, - { /* 13 */ - new Input( - "Map2dOfBeans-3", - new Map2dOfBeans().init2(), - 3, - /* Json */ "{\n\tb: {\n\t\ta: {\n\t\t\ta: 1,\n\t\t\tb: 'foo'\n\t\t}\n\t}\n}", - /* Xml */ "<object>\n\t<b>\n\t\t<a>\n\t\t\t<a>1</a>\n\t\t\t<b>foo</b>\n\t\t</a>\n\t</b>\n</object>\n", - /* Html */ "<table>\n\t<tr>\n\t\t<td>b</td>\n\t\t<td>\n\t\t\t<table><tr><td>a</td><td><table><tr><td>a</td><td>1</td></tr><tr><td>b</td><td>foo</td></tr></table></td></tr></table>\n\t\t</td>\n\t</tr>\n</table>\n", - /* Uon */ "(\n\tb=(\n\t\ta=(\n\t\t\ta=1,\n\t\t\tb=foo\n\t\t)\n\t)\n)", - /* UrlEnc */ "b=(\n\ta=(\n\t\ta=1,\n\t\tb=foo\n\t)\n)" - ) - }, - }); - } - - Input input; - - public MaxIndentTest(Input input) { - this.input = input; - } - - static class Input { - String label; - Object in; - int maxDepth; - String json, xml, html, uon, urlEnc; - - Input(String label, Object in, int maxDepth, String json, String xml, String html, String uon, String urlEnc) { - this.label = label; - this.in = in; - this.maxDepth = maxDepth; - this.json = json; - this.xml = xml; - this.html = html; - this.uon = uon; - this.urlEnc = urlEnc; - } - } - - public static class List1dOfBeans extends LinkedList<ABean> { - public List1dOfBeans init1() { - add(new ABean().init()); - return this; - } - } - - public static class List2dOfBeans extends LinkedList<List1dOfBeans> { - public List2dOfBeans init2() { - add(new List1dOfBeans().init1()); - return this; - } - } - - public static class Map1dOfBeans extends LinkedHashMap<String,ABean> { - public Map1dOfBeans init1() { - put("a", new ABean().init()); - return this; - } - } - - public static class Map2dOfBeans extends LinkedHashMap<String,Map1dOfBeans> { - public Map2dOfBeans init2() { - put("b", new Map1dOfBeans().init1()); - return this; - } - } - - @Test - public void a1_serializeJson() throws Exception { - WriterSerializer s = JsonSerializer.DEFAULT_LAX_READABLE.builder().maxIndent(input.maxDepth).build(); - testSerialize("json", s, input.json); - } - - @Test - public void b11_serializeXml() throws Exception { - WriterSerializer s = XmlSerializer.DEFAULT_SQ_READABLE.builder().maxIndent(input.maxDepth).build(); - testSerialize("xml", s, input.xml); - } - - @Test - public void c11_serializeHtml() throws Exception { - WriterSerializer s = HtmlSerializer.DEFAULT_SQ_READABLE.builder().maxIndent(input.maxDepth).build(); - testSerialize("html", s, input.html); - } - - @Test - public void d11_serializeUon() throws Exception { - WriterSerializer s = UonSerializer.DEFAULT_READABLE.builder().maxIndent(input.maxDepth).build(); - testSerialize("uon", s, input.uon); - } - - @Test - public void e11_serializeUrlEncoding() throws Exception { - WriterSerializer s = UrlEncodingSerializer.DEFAULT_READABLE.builder().maxIndent(input.maxDepth).build(); - testSerialize("urlEncoding", s, input.urlEnc); - } - - private void testSerialize(String testName, Serializer s, String expected) throws Exception { - try { - String r = s.isWriterSerializer() ? ((WriterSerializer)s).serialize(input.in) : ((OutputStreamSerializer)s).serializeToHex(input.in); - - // Specifying "xxx" in the expected results will spit out what we should populate the field with. - if (expected.equals("xxx")) { - System.out.println(input.label + "/" + testName + "=\n" + r.replaceAll("\n", "\\\\n").replaceAll("\t", "\\\\t")); // NOT DEBUG - System.out.println(r); - return; - } - - TestUtils.assertEquals(expected, r, "{0}/{1} parse-normal failed", input.label, testName); - - } catch (AssertionError e) { - throw e; - } catch (Exception e) { - e.printStackTrace(); - throw new AssertionError(input.label + "/" + testName + " failed. exception=" + e.getLocalizedMessage()); - } - } - -} \ No newline at end of file
