Add HandCraftedJsonTest POLYGENE-231
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/14fe39ce Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/14fe39ce Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/14fe39ce Branch: refs/heads/develop Commit: 14fe39ce9c3946cf4351797a205d316e4629235a Parents: bd39297 Author: Paul Merlin <[email protected]> Authored: Sun Mar 26 17:20:39 2017 +0200 Committer: Paul Merlin <[email protected]> Committed: Sun Apr 2 19:16:24 2017 +0200 ---------------------------------------------------------------------- .../javaxjson/HandCraftedJsonTest.java | 74 ++++++++++++++++++++ 1 file changed, 74 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/14fe39ce/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/HandCraftedJsonTest.java ---------------------------------------------------------------------- diff --git a/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/HandCraftedJsonTest.java b/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/HandCraftedJsonTest.java new file mode 100644 index 0000000..2181b6b --- /dev/null +++ b/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/HandCraftedJsonTest.java @@ -0,0 +1,74 @@ +/* + * 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.polygene.serialization.javaxjson; + +import org.apache.polygene.api.injection.scope.Service; +import org.apache.polygene.api.property.Property; +import org.apache.polygene.api.serialization.Deserializer; +import org.apache.polygene.bootstrap.ModuleAssembly; +import org.apache.polygene.serialization.javaxjson.assembly.JavaxJsonSerializationAssembler; +import org.apache.polygene.test.AbstractPolygeneTest; +import org.apache.polygene.test.util.NotYetImplemented; +import org.junit.Test; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + +public class HandCraftedJsonTest extends AbstractPolygeneTest +{ + @Override + public void assemble( ModuleAssembly module ) + { + new JavaxJsonSerializationAssembler().assemble( module ); + module.values( SomeValue.class ); + } + + public interface SomeValue + { + Property<String> foo(); + } + + @Service + private Deserializer deserializer; + + @Test + public void canReadSingleLineJson() + { + String json = " { \"foo\" : \"bar\" } "; + assertThat( deserializer.deserialize( module, SomeValue.class, json ).foo().get(), + equalTo( "bar" ) ); + } + + @Test + public void canReadFormattedMultiLineJson() + { + String json = " \n { \n\t\"foo\" : \"bar\" \n }\n "; + assertThat( deserializer.deserialize( module, SomeValue.class, json ).foo().get(), + equalTo( "bar" ) ); + } + + @Test + @NotYetImplemented( reason = "need to manage javax.json providers and properties first, could work with Johnzon" ) + // See org.apache.johnzon.supports-comments + public void canReadCommentedJson() + { + String json = "// One comment\n { \n\t\"foo\" : \"bar\" \n/* Two comments */ }\n "; + assertThat( deserializer.deserialize( module, SomeValue.class, json ).foo().get(), + equalTo( "bar" ) ); + } +}
