Support serializing directly from Readers and InputStreams. Project: http://git-wip-us.apache.org/repos/asf/incubator-juneau/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-juneau/commit/b37d99ba Tree: http://git-wip-us.apache.org/repos/asf/incubator-juneau/tree/b37d99ba Diff: http://git-wip-us.apache.org/repos/asf/incubator-juneau/diff/b37d99ba
Branch: refs/heads/master Commit: b37d99bac5ddc63de368d5dbdd98f25347540ce7 Parents: 23fe563 Author: JamesBognar <[email protected]> Authored: Sun Aug 27 18:22:10 2017 -0400 Committer: JamesBognar <[email protected]> Committed: Sun Aug 27 18:22:10 2017 -0400 ---------------------------------------------------------------------- .../java/org/apache/juneau/jena/RdfParser.java | 23 +- .../apache/juneau/jena/RdfParserBuilder.java | 2 +- .../org/apache/juneau/jena/RdfSerializer.java | 41 +- .../juneau/jena/RdfSerializerBuilder.java | 2 +- .../juneau/jena/RdfSerializerSession.java | 5 +- .../test/java/org/apache/juneau/ComboInput.java | 11 +- .../org/apache/juneau/ComboRoundTripTest.java | 708 + .../org/apache/juneau/ComboSerializeTest.java | 367 + .../test/java/org/apache/juneau/ComboTest.java | 708 - .../org/apache/juneau/DynaBeanComboTest.java | 2 +- .../apache/juneau/dto/html5/Html5ComboTest.java | 2 +- .../dto/html5/Html5TemplateComboTest.java | 2 +- .../apache/juneau/parser/ParserGroupTest.java | 25 +- .../serializer/ReaderObjectComboTest.java | 439 + .../juneau/serializer/SerializerGroupTest.java | 34 +- .../transforms/BeanDictionaryComboTest.java | 2 +- .../ByteArrayBase64SwapComboTest.java | 2 +- .../transforms/CalendarSwapComboTest.java | 2 +- .../juneau/transforms/DateSwapComboTest.java | 2 +- .../juneau/transforms/ReaderObjectSwapTest.java | 494 + .../org/apache/juneau/annotation/Consumes.java | 72 - .../org/apache/juneau/annotation/Produces.java | 85 - .../java/org/apache/juneau/csv/CsvParser.java | 4 +- .../org/apache/juneau/csv/CsvSerializer.java | 4 +- .../apache/juneau/csv/CsvSerializerSession.java | 1 - .../apache/juneau/html/HtmlDocSerializer.java | 29 +- .../java/org/apache/juneau/html/HtmlParser.java | 4 +- .../juneau/html/HtmlSchemaDocSerializer.java | 32 +- .../org/apache/juneau/html/HtmlSerializer.java | 32 +- .../juneau/html/HtmlSerializerSession.java | 11 +- .../juneau/html/HtmlStrippedDocSerializer.java | 29 +- .../java/org/apache/juneau/http/MediaType.java | 32 +- .../org/apache/juneau/internal/IOUtils.java | 99 +- .../java/org/apache/juneau/jso/JsoParser.java | 4 +- .../org/apache/juneau/jso/JsoSerializer.java | 4 +- .../apache/juneau/jso/JsoSerializerSession.java | 3 +- .../java/org/apache/juneau/json/JsonParser.java | 14 +- .../juneau/json/JsonSchemaSerializer.java | 8 +- .../json/JsonSchemaSerializerSession.java | 1 - .../org/apache/juneau/json/JsonSerializer.java | 39 +- .../juneau/json/JsonSerializerSession.java | 5 +- .../apache/juneau/msgpack/MsgPackParser.java | 6 +- .../juneau/msgpack/MsgPackSerializer.java | 4 +- .../msgpack/MsgPackSerializerSession.java | 8 +- .../apache/juneau/parser/InputStreamParser.java | 15 +- .../java/org/apache/juneau/parser/Parser.java | 53 +- .../org/apache/juneau/parser/ParserSession.java | 4 +- .../apache/juneau/parser/ParserSessionArgs.java | 5 - .../org/apache/juneau/parser/ReaderParser.java | 13 +- .../java/org/apache/juneau/parser/package.html | 6 +- .../juneau/plaintext/PlainTextParser.java | 17 +- .../juneau/plaintext/PlainTextSerializer.java | 33 +- .../plaintext/PlainTextSerializerSession.java | 1 - .../serializer/OutputStreamSerializer.java | 33 +- .../OutputStreamSerializerSession.java | 1 - .../apache/juneau/serializer/Serializer.java | 70 +- .../juneau/serializer/SerializerSession.java | 5 +- .../serializer/SerializerSessionArgs.java | 5 - .../juneau/serializer/WriterSerializer.java | 33 +- .../serializer/WriterSerializerSession.java | 1 - .../org/apache/juneau/serializer/package.html | 6 +- .../apache/juneau/soap/SoapXmlSerializer.java | 4 +- .../juneau/soap/SoapXmlSerializerSession.java | 1 - .../java/org/apache/juneau/uon/UonParser.java | 21 +- .../org/apache/juneau/uon/UonParserSession.java | 14 +- .../org/apache/juneau/uon/UonSerializer.java | 32 +- .../apache/juneau/uon/UonSerializerSession.java | 5 +- .../juneau/urlencoding/UrlEncodingParser.java | 4 +- .../urlencoding/UrlEncodingSerializer.java | 36 +- .../UrlEncodingSerializerSession.java | 4 +- .../org/apache/juneau/xml/XmlDocSerializer.java | 2 - .../juneau/xml/XmlDocSerializerSession.java | 1 - .../java/org/apache/juneau/xml/XmlParser.java | 19 +- .../xml/XmlSchemaDocSerializerSession.java | 1 - .../apache/juneau/xml/XmlSchemaSerializer.java | 4 +- .../juneau/xml/XmlSchemaSerializerSession.java | 1 - .../org/apache/juneau/xml/XmlSerializer.java | 35 +- .../apache/juneau/xml/XmlSerializerSession.java | 53 +- juneau-core/src/main/javadoc/overview.html | 22623 +++++++++-------- .../juneau/examples/rest/PhotosResource.java | 7 +- .../juneau/rest/test/AcceptCharsetResource.java | 7 +- .../rest/test/CharsetEncodingsResource.java | 7 +- .../rest/test/DefaultContentTypesResource.java | 27 +- .../apache/juneau/rest/test/GroupsResource.java | 7 +- .../juneau/rest/test/HeadersResource.java | 7 +- .../juneau/rest/test/InheritanceResource.java | 39 +- .../juneau/rest/test/NlsPropertyResource.java | 4 +- .../juneau/rest/test/OnPostCallResource.java | 4 +- .../juneau/rest/test/OnPreCallResource.java | 4 +- .../juneau/rest/test/ParsersResource.java | 13 +- .../juneau/rest/test/PropertiesResource.java | 7 +- .../juneau/rest/test/SerializersResource.java | 13 +- .../java/org/apache/juneau/rest/package.html | 6 +- .../juneau/rest/response/DefaultHandler.java | 3 +- 94 files changed, 14126 insertions(+), 12593 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b37d99ba/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java index d68c70a..a94c123 100644 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParser.java @@ -16,7 +16,6 @@ import static org.apache.juneau.jena.Constants.*; import static org.apache.juneau.jena.RdfCommonContext.*; import org.apache.juneau.*; -import org.apache.juneau.annotation.*; import org.apache.juneau.parser.*; /** @@ -45,11 +44,10 @@ import org.apache.juneau.parser.*; * * See <a class="doclink" href="package-summary.html#TOC">RDF Overview</a> for an overview of RDF support in Juneau. */ -@Consumes(value="text/xml+rdf") public class RdfParser extends ReaderParser { /** Default XML parser, all default settings.*/ - public static final RdfParser DEFAULT_XML = new RdfParser(PropertyStore.create()); + public static final RdfParser DEFAULT_XML = new Xml(PropertyStore.create()); /** Default Turtle parser, all default settings.*/ public static final RdfParser DEFAULT_TURTLE = new Turtle(PropertyStore.create()); @@ -62,7 +60,6 @@ public class RdfParser extends ReaderParser { /** Consumes RDF/XML input */ - @Consumes("text/xml+rdf") public static class Xml extends RdfParser { /** @@ -71,12 +68,11 @@ public class RdfParser extends ReaderParser { * @param propertyStore The property store containing all the settings for this object. */ public Xml(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_RDF_XML)); + super(propertyStore.copy().append(RDF_language, LANG_RDF_XML), "text/xml+rdf"); } } /** Consumes N-Triple input */ - @Consumes(value="text/n-triple") public static class NTriple extends RdfParser { /** @@ -85,12 +81,11 @@ public class RdfParser extends ReaderParser { * @param propertyStore The property store containing all the settings for this object. */ public NTriple(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_NTRIPLE)); + super(propertyStore.copy().append(RDF_language, LANG_NTRIPLE), "text/n-triple"); } } /** Consumes Turtle input */ - @Consumes(value="text/turtle") public static class Turtle extends RdfParser { /** @@ -99,12 +94,11 @@ public class RdfParser extends ReaderParser { * @param propertyStore The property store containing all the settings for this object. */ public Turtle(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_TURTLE)); + super(propertyStore.copy().append(RDF_language, LANG_TURTLE), "text/turtle"); } } /** Consumes N3 input */ - @Consumes(value="text/n3") public static class N3 extends RdfParser { /** @@ -113,7 +107,7 @@ public class RdfParser extends ReaderParser { * @param propertyStore The property store containing all the settings for this object. */ public N3(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_N3)); + super(propertyStore.copy().append(RDF_language, LANG_N3), "text/n3"); } } @@ -124,12 +118,13 @@ public class RdfParser extends ReaderParser { * Constructor. * * @param propertyStore The property store containing all the settings for this object. + * @param consumes The list of media types that this parser consumes (e.g. <js>"application/json"</js>). */ - public RdfParser(PropertyStore propertyStore) { - super(propertyStore); + public RdfParser(PropertyStore propertyStore, String...consumes) { + super(propertyStore, consumes); this.ctx = createContext(RdfParserContext.class); } - + @Override /* CoreObject */ public RdfParserBuilder builder() { return new RdfParserBuilder(propertyStore); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b37d99ba/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java index 61b60ca..095d45a 100644 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfParserBuilder.java @@ -47,7 +47,7 @@ public class RdfParserBuilder extends ParserBuilder { @Override /* CoreObjectBuilder */ public RdfParser build() { - return new RdfParser(propertyStore); + return new RdfParser(propertyStore, "text/xml+rdf"); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b37d99ba/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java index e19d8b2..b574186 100644 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializer.java @@ -16,7 +16,6 @@ import static org.apache.juneau.jena.Constants.*; import static org.apache.juneau.jena.RdfCommonContext.*; import org.apache.juneau.*; -import org.apache.juneau.annotation.*; import org.apache.juneau.serializer.*; /** @@ -42,7 +41,6 @@ import org.apache.juneau.serializer.*; * * See <a class="doclink" href="package-summary.html#TOC">RDF Overview</a> for an overview of RDF support in Juneau. */ -@Produces(value="text/xml+rdf+abbrev", contentType="text/xml+rdf") public class RdfSerializer extends WriterSerializer { /** Default RDF/XML serializer, all default settings.*/ @@ -62,7 +60,6 @@ public class RdfSerializer extends WriterSerializer { /** Produces RDF/XML output */ - @Produces("text/xml+rdf") public static class Xml extends RdfSerializer { /** @@ -71,12 +68,11 @@ public class RdfSerializer extends WriterSerializer { * @param propertyStore The property store containing all the settings for this object. */ public Xml(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_RDF_XML)); + super(propertyStore.copy().append(RDF_language, LANG_RDF_XML), "text/xml+rdf"); } } /** Produces Abbreviated RDF/XML output */ - @Produces(value="text/xml+rdf+abbrev", contentType="text/xml+rdf") public static class XmlAbbrev extends RdfSerializer { /** @@ -85,12 +81,11 @@ public class RdfSerializer extends WriterSerializer { * @param propertyStore The property store containing all the settings for this object. */ public XmlAbbrev(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_RDF_XML_ABBREV)); + super(propertyStore.copy().append(RDF_language, LANG_RDF_XML_ABBREV), "text/xml+rdf", "text/xml+rdf+abbrev"); } } /** Produces N-Triple output */ - @Produces("text/n-triple") public static class NTriple extends RdfSerializer { /** @@ -99,12 +94,11 @@ public class RdfSerializer extends WriterSerializer { * @param propertyStore The property store containing all the settings for this object. */ public NTriple(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_NTRIPLE)); + super(propertyStore.copy().append(RDF_language, LANG_NTRIPLE), "text/n-triple"); } } /** Produces Turtle output */ - @Produces("text/turtle") public static class Turtle extends RdfSerializer { /** @@ -113,12 +107,11 @@ public class RdfSerializer extends WriterSerializer { * @param propertyStore The property store containing all the settings for this object. */ public Turtle(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_TURTLE)); + super(propertyStore.copy().append(RDF_language, LANG_TURTLE), "text/turtle"); } } /** Produces N3 output */ - @Produces("text/n3") public static class N3 extends RdfSerializer { /** @@ -127,7 +120,7 @@ public class RdfSerializer extends WriterSerializer { * @param propertyStore The property store containing all the settings for this object. */ public N3(PropertyStore propertyStore) { - super(propertyStore.copy().append(RDF_language, LANG_N3)); + super(propertyStore.copy().append(RDF_language, LANG_N3), "text/n3"); } } @@ -136,11 +129,27 @@ public class RdfSerializer extends WriterSerializer { /** * Constructor. - * - * @param propertyStore The property store containing all the settings for this object. + * + * @param propertyStore + * The property store containing all the settings for this object. + * @param produces + * The media type that this serializer produces. + * @param accept + * The accept media types that the serializer can handle. + * <p> + * Can contain meta-characters per the <code>media-type</code> specification of + * <a class="doclink" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1">RFC2616/14.1</a> + * <p> + * If empty, then assumes the only media type supported is <code>produces</code>. + * <p> + * For example, if this serializer produces <js>"application/json"</js> but should handle media types of + * <js>"application/json"</js> and <js>"text/json"</js>, then the arguments should be: + * <br><code><jk>super</jk>(propertyStore, <js>"application/json"</js>, <js>"application/json"</js>, <js>"text/json"</js>);</code> + * <br>...or... + * <br><code><jk>super</jk>(propertyStore, <js>"application/json"</js>, <js>"*​/json"</js>);</code> */ - public RdfSerializer(PropertyStore propertyStore) { - super(propertyStore); + public RdfSerializer(PropertyStore propertyStore, String produces, String...accept) { + super(propertyStore, produces, accept); this.ctx = createContext(RdfSerializerContext.class); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b37d99ba/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerBuilder.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerBuilder.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerBuilder.java index 196bdfa..59b15c5 100644 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerBuilder.java +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerBuilder.java @@ -47,7 +47,7 @@ public class RdfSerializerBuilder extends SerializerBuilder { @Override /* CoreObjectBuilder */ public RdfSerializer build() { - return new RdfSerializer(propertyStore); + return new RdfSerializer(propertyStore, "text/xml+rdf"); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b37d99ba/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java ---------------------------------------------------------------------- diff --git a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java index d033c45..0f66237 100644 --- a/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java +++ b/juneau-core-rdf/src/main/java/org/apache/juneau/jena/RdfSerializerSession.java @@ -63,7 +63,6 @@ public final class RdfSerializerSession extends WriterSerializerSession { * These specify session-level information such as locale and URI context. * It also include session-level properties that override the properties defined on the bean and * serializer contexts. - * <br>If <jk>null</jk>, defaults to {@link SerializerSessionArgs#DEFAULT}. */ protected RdfSerializerSession(RdfSerializerContext ctx, SerializerSessionArgs args) { super(ctx, args); @@ -293,6 +292,10 @@ public final class RdfSerializerSession extends WriterSerializerSession { case MULTI_VALUED: serializeToMultiProperties(c, eType, bpm, attrName, parentResource); break; default: n = serializeToContainer(c, eType, m.createSeq()); } + + } else if (sType.isReader() || sType.isInputStream()) { + n = m.createLiteral(encodeTextInvalidChars(IOUtils.read(o))); + } else { n = m.createLiteral(encodeTextInvalidChars(toString(o))); } http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b37d99ba/juneau-core-test/src/test/java/org/apache/juneau/ComboInput.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/ComboInput.java b/juneau-core-test/src/test/java/org/apache/juneau/ComboInput.java index 2bfc196..3ee1389 100644 --- a/juneau-core-test/src/test/java/org/apache/juneau/ComboInput.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/ComboInput.java @@ -21,7 +21,7 @@ import java.lang.reflect.*; public class ComboInput<T> { final String label; - final Object in; + private final T in; final Type type; final String json, jsonT, jsonR, xml, xmlT, xmlR, xmlNs, html, htmlT, htmlR, uon, uonT, uonR, urlEncoding, urlEncodingT, urlEncodingR, msgPack, msgPackT, rdfXml, rdfXmlT, rdfXmlR; @@ -79,6 +79,15 @@ public class ComboInput<T> { } /** + * Returns the input object. + * Override this method if you want it dynamically created each time. + * @throws Exception + */ + public T getInput() throws Exception { + return in; + } + + /** * Override this method if you want to do a post-parse verification on the object. * <p> * Note that a Function would be preferred here, but it's not available in Java 6. http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b37d99ba/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 new file mode 100644 index 0000000..4da5f1e --- /dev/null +++ b/juneau-core-test/src/test/java/org/apache/juneau/ComboRoundTripTest.java @@ -0,0 +1,708 @@ +// *************************************************************************************************************************** +// * 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/b37d99ba/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 new file mode 100644 index 0000000..6768d91 --- /dev/null +++ b/juneau-core-test/src/test/java/org/apache/juneau/ComboSerializeTest.java @@ -0,0 +1,367 @@ +// *************************************************************************************************************************** +// * 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/b37d99ba/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 deleted file mode 100644 index 510fe01..0000000 --- a/juneau-core-test/src/test/java/org/apache/juneau/ComboTest.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 ComboTest { - - /* 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 ComboTest(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.in) : ((OutputStreamSerializer)s).serializeToHex(comboInput.in); - - // 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.in) : ((OutputStreamSerializer)s).serializeToHex(comboInput.in); - 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.in) : ((OutputStreamSerializer)s).serializeToHex(comboInput.in); - 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.in); - 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/b37d99ba/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 index f15b238..9afaaf8 100644 --- a/juneau-core-test/src/test/java/org/apache/juneau/DynaBeanComboTest.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/DynaBeanComboTest.java @@ -29,7 +29,7 @@ import org.junit.runners.*; */ @RunWith(Parameterized.class) @SuppressWarnings({"javadoc"}) -public class DynaBeanComboTest extends ComboTest { +public class DynaBeanComboTest extends ComboRoundTripTest { @Parameterized.Parameters public static Collection<Object[]> getParameters() { http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b37d99ba/juneau-core-test/src/test/java/org/apache/juneau/dto/html5/Html5ComboTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/dto/html5/Html5ComboTest.java b/juneau-core-test/src/test/java/org/apache/juneau/dto/html5/Html5ComboTest.java index 5ef24a7..1e25392 100755 --- a/juneau-core-test/src/test/java/org/apache/juneau/dto/html5/Html5ComboTest.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/dto/html5/Html5ComboTest.java @@ -26,7 +26,7 @@ import org.junit.runners.*; */ @RunWith(Parameterized.class) @SuppressWarnings({"javadoc"}) -public class Html5ComboTest extends ComboTest { +public class Html5ComboTest extends ComboRoundTripTest { private static final B btag = b("bbb"); http://git-wip-us.apache.org/repos/asf/incubator-juneau/blob/b37d99ba/juneau-core-test/src/test/java/org/apache/juneau/dto/html5/Html5TemplateComboTest.java ---------------------------------------------------------------------- diff --git a/juneau-core-test/src/test/java/org/apache/juneau/dto/html5/Html5TemplateComboTest.java b/juneau-core-test/src/test/java/org/apache/juneau/dto/html5/Html5TemplateComboTest.java index 7fad0fb..e3a3267 100644 --- a/juneau-core-test/src/test/java/org/apache/juneau/dto/html5/Html5TemplateComboTest.java +++ b/juneau-core-test/src/test/java/org/apache/juneau/dto/html5/Html5TemplateComboTest.java @@ -28,7 +28,7 @@ import org.junit.runners.*; */ @RunWith(Parameterized.class) @SuppressWarnings({"javadoc"}) -public class Html5TemplateComboTest extends ComboTest { +public class Html5TemplateComboTest extends ComboRoundTripTest { @Parameterized.Parameters public static Collection<Object[]> getParameters() {
