QI-318 Leaner unit tests Added methods for simple use cases in ValueDeserializer.
API should be done now. Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/a2069655 Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/a2069655 Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/a2069655 Branch: refs/heads/master Commit: a206965544cd48c9f948275d8e2f59fb524f274c Parents: 13edb4e Author: Paul Merlin <[email protected]> Authored: Sat Feb 9 15:10:47 2013 +0100 Committer: Paul Merlin <[email protected]> Committed: Sat Feb 9 17:34:27 2013 +0100 ---------------------------------------------------------------------- .../org/qi4j/api/value/ValueDeserializer.java | 39 ++++++ .../api/value/ValueSerializationException.java | 15 +++ .../spi/value/ValueDeserializerAdapter.java | 50 ++++++++ .../orgjson/OrgJsonValueSerialization.java | 20 +++ .../OrgJsonTemporalValueSerializationTest.java | 38 ------ .../AbstractCollectionSerializationTest.java | 7 +- .../AbstractPlainValueSerializationTest.java | 33 +++-- .../AbstractTemporalValueSerializationTest.java | 123 ------------------- ...AbstractValueCompositeSerializationTest.java | 4 +- .../main/java/org/qi4j/test/value/package.html | 5 + .../valueserialization-jackson/dev-status.xml | 17 +++ .../JacksonTemporalValueSerializationTest.java | 39 ------ .../valueserialization-stax/dev-status.xml | 17 +++ .../StaxTemporalValueSerializationTest.java | 38 ------ 14 files changed, 184 insertions(+), 261 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/core/api/src/main/java/org/qi4j/api/value/ValueDeserializer.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/value/ValueDeserializer.java b/core/api/src/main/java/org/qi4j/api/value/ValueDeserializer.java index 0b6022f..b75886a 100644 --- a/core/api/src/main/java/org/qi4j/api/value/ValueDeserializer.java +++ b/core/api/src/main/java/org/qi4j/api/value/ValueDeserializer.java @@ -71,6 +71,19 @@ public interface ValueDeserializer /** * Factory method for a typed deserialize function. * + * <p>The returned Function may throw {@link ValueSerializationException}.</p> + * + * @param type the value type + * @param <T> the parametrized function return type + * @return a deserialization function + */ + <T> Function<String, T> deserialize( Class<T> type ); + + /** + * Factory method for a typed deserialize function. + * + * <p>The returned Function may throw {@link ValueSerializationException}.</p> + * * @param valueType the value type * @param <T> the parametrized function return type * @return a deserialization function @@ -80,6 +93,8 @@ public interface ValueDeserializer /** * Factory method for an untyped deserialize function. * + * <p>The returned Function may throw {@link ValueSerializationException}.</p> + * * @param <T> the parametrized function return type * @return a deserialization function */ @@ -89,6 +104,18 @@ public interface ValueDeserializer * Deserialize a value from a state. * * @param <T> the parametrized returned type + * @param type the value type + * @param input the state + * @return the value + * @throws ValueSerializationException if the deserialization failed + */ + <T> T deserialize( Class<?> type, String input ) + throws ValueSerializationException; + + /** + * Deserialize a value from a state. + * + * @param <T> the parametrized returned type * @param valueType the value type * @param input the state * @return the value @@ -101,6 +128,18 @@ public interface ValueDeserializer * Deserialize a value from a state. * * @param <T> the parametrized returned type + * @param type the value type + * @param input the state stream + * @return the value + * @throws ValueSerializationException if the deserialization failed + */ + <T> T deserialize( Class<?> type, InputStream input ) + throws ValueSerializationException; + + /** + * Deserialize a value from a state. + * + * @param <T> the parametrized returned type * @param valueType the value type * @param input the state stream * @return the value http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/core/api/src/main/java/org/qi4j/api/value/ValueSerializationException.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/value/ValueSerializationException.java b/core/api/src/main/java/org/qi4j/api/value/ValueSerializationException.java index b267d86..e1f3d44 100644 --- a/core/api/src/main/java/org/qi4j/api/value/ValueSerializationException.java +++ b/core/api/src/main/java/org/qi4j/api/value/ValueSerializationException.java @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2012, Paul Merlin. All Rights Reserved. + * + * Licensed 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.qi4j.api.value; /** http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java b/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java index a482294..c8afe2b 100644 --- a/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java +++ b/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java @@ -303,6 +303,22 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> } @Override + public <T> Function<String, T> deserialize( Class<T> type ) + { + if( CollectionType.isCollection( type ) ) + { + ValueType objectValueType = new ValueType( Object.class ); + return deserialize( new CollectionType( type, objectValueType ) ); + } + if( MapType.isMap( type ) ) + { + ValueType objectValueType = new ValueType( Object.class ); + return deserialize( new MapType( type, objectValueType, objectValueType ) ); + } + return deserialize( new ValueType( type ) ); + } + + @Override public final <T> Function<String, T> deserialize( final ValueType valueType ) { return new Function<String, T>() @@ -329,6 +345,23 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> } @Override + public final <T> T deserialize( Class<?> type, String input ) + throws ValueSerializationException + { + if( CollectionType.isCollection( type ) ) + { + ValueType objectValueType = new ValueType( Object.class ); + return deserialize( new CollectionType( type, objectValueType ), input ); + } + if( MapType.isMap( type ) ) + { + ValueType objectValueType = new ValueType( Object.class ); + return deserialize( new MapType( type, objectValueType, objectValueType ), input ); + } + return deserialize( new ValueType( type ), input ); + } + + @Override public final <T> T deserialize( ValueType valueType, String input ) throws ValueSerializationException { @@ -347,6 +380,23 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> } @Override + public final <T> T deserialize( Class<?> type, InputStream input ) + throws ValueSerializationException + { + if( CollectionType.isCollection( type ) ) + { + ValueType objectValueType = new ValueType( Object.class ); + return deserialize( new CollectionType( type, objectValueType ), input ); + } + if( MapType.isMap( type ) ) + { + ValueType objectValueType = new ValueType( Object.class ); + return deserialize( new MapType( type, objectValueType, objectValueType ), input ); + } + return deserialize( new ValueType( type ), input ); + } + + @Override public final <T> T deserialize( ValueType valueType, InputStream input ) throws ValueSerializationException { http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/core/spi/src/main/java/org/qi4j/valueserialization/orgjson/OrgJsonValueSerialization.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/qi4j/valueserialization/orgjson/OrgJsonValueSerialization.java b/core/spi/src/main/java/org/qi4j/valueserialization/orgjson/OrgJsonValueSerialization.java index 7dedd0d..242ac52 100644 --- a/core/spi/src/main/java/org/qi4j/valueserialization/orgjson/OrgJsonValueSerialization.java +++ b/core/spi/src/main/java/org/qi4j/valueserialization/orgjson/OrgJsonValueSerialization.java @@ -97,6 +97,12 @@ public class OrgJsonValueSerialization } @Override + public <T> Function<String, T> deserialize( Class<T> type ) + { + return deserializer.deserialize( type ); + } + + @Override public <T> Function<String, T> deserialize( ValueType valueType ) { return deserializer.deserialize( valueType ); @@ -109,6 +115,13 @@ public class OrgJsonValueSerialization } @Override + public <T> T deserialize( Class<?> type, String input ) + throws ValueSerializationException + { + return deserializer.deserialize( type, input ); + } + + @Override public <T> T deserialize( ValueType type, String input ) throws ValueSerializationException { @@ -116,6 +129,13 @@ public class OrgJsonValueSerialization } @Override + public <T> T deserialize( Class<?> type, InputStream input ) + throws ValueSerializationException + { + return deserializer.deserialize( new ValueType( type ), input ); + } + + @Override public <T> T deserialize( ValueType type, InputStream input ) throws ValueSerializationException { http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/core/spi/src/test/java/org/qi4j/valueserialization/orgjson/OrgJsonTemporalValueSerializationTest.java ---------------------------------------------------------------------- diff --git a/core/spi/src/test/java/org/qi4j/valueserialization/orgjson/OrgJsonTemporalValueSerializationTest.java b/core/spi/src/test/java/org/qi4j/valueserialization/orgjson/OrgJsonTemporalValueSerializationTest.java deleted file mode 100644 index a2804db..0000000 --- a/core/spi/src/test/java/org/qi4j/valueserialization/orgjson/OrgJsonTemporalValueSerializationTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2012, Paul Merlin. All Rights Reserved. - * - * Licensed 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.qi4j.valueserialization.orgjson; - -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.test.value.AbstractTemporalValueSerializationTest; - -public class OrgJsonTemporalValueSerializationTest - extends AbstractTemporalValueSerializationTest -{ - - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.services( OrgJsonValueSerializationService.class ); - } - - @Override - protected String asSingleValueArray( String value ) - { - return "[\"" + value + "\"]"; - } -} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/core/testsupport/src/main/java/org/qi4j/test/value/AbstractCollectionSerializationTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractCollectionSerializationTest.java b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractCollectionSerializationTest.java index 65bef75..59f44cd 100644 --- a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractCollectionSerializationTest.java +++ b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractCollectionSerializationTest.java @@ -82,8 +82,7 @@ public class AbstractCollectionSerializationTest String output = sb.toString(); List<Byte> list = new ArrayList<Byte>(); - ValueType valueType = new ValueType( Byte.class ); - text( output ).transferTo( map( valueSerialization.<Byte>deserialize( valueType ), collection( list ) ) ); + text( output ).transferTo( map( valueSerialization.deserialize( Byte.class ), collection( list ) ) ); assertEquals( byteCollection(), list ); } @@ -96,7 +95,7 @@ public class AbstractCollectionSerializationTest 23, 42, -23, -42 }; String output = valueSerialization.serialize( primitiveArray ); - int[] deserialized = valueSerialization.deserialize( new ValueType( int[].class ), output ); + int[] deserialized = valueSerialization.deserialize( int[].class, output ); assertArrayEquals( primitiveArray, deserialized ); } @@ -109,7 +108,7 @@ public class AbstractCollectionSerializationTest 9, null, -12, -12, 127, -128, 73 }; String output = valueSerialization.serialize( array ); - Byte[] deserialized = valueSerialization.deserialize( new ValueType( Byte[].class ), output ); + Byte[] deserialized = valueSerialization.deserialize( Byte[].class, output ); assertArrayEquals( array, deserialized ); } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/core/testsupport/src/main/java/org/qi4j/test/value/AbstractPlainValueSerializationTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractPlainValueSerializationTest.java b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractPlainValueSerializationTest.java index 6458a96..abb6a65 100644 --- a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractPlainValueSerializationTest.java +++ b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractPlainValueSerializationTest.java @@ -26,7 +26,6 @@ import org.junit.Before; import org.junit.Test; import org.qi4j.api.entity.EntityReference; import org.qi4j.api.injection.scope.Service; -import org.qi4j.api.type.ValueType; import org.qi4j.api.value.ValueSerialization; import org.qi4j.bootstrap.AssemblyException; import org.qi4j.bootstrap.ModuleAssembly; @@ -64,7 +63,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( "" ); assertThat( "Serialized", serialized, equalTo( "" ) ); - String deserialized = valueSerialization.deserialize( new ValueType( String.class ), serialized ); + String deserialized = valueSerialization.deserialize( String.class, serialized ); assertThat( "Deserialized", deserialized, equalTo( "" ) ); } @@ -74,7 +73,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( "test" ); assertThat( serialized, equalTo( "test" ) ); - String deserialized = valueSerialization.deserialize( new ValueType( String.class ), serialized ); + String deserialized = valueSerialization.deserialize( String.class, serialized ); assertThat( deserialized, equalTo( "test" ) ); } @@ -84,7 +83,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( Boolean.TRUE ); assertThat( serialized, equalTo( "true" ) ); - Boolean deserialized = valueSerialization.deserialize( new ValueType( Boolean.class ), serialized ); + Boolean deserialized = valueSerialization.deserialize( Boolean.class, serialized ); assertThat( deserialized, equalTo( Boolean.TRUE ) ); } @@ -93,7 +92,7 @@ public class AbstractPlainValueSerializationTest { String serialized = valueSerialization.serialize( 42 ); assertThat( serialized, equalTo( "42" ) ); - Integer deserialized = valueSerialization.deserialize( new ValueType( Integer.class ), serialized ); + Integer deserialized = valueSerialization.deserialize( Integer.class, serialized ); assertThat( deserialized, equalTo( 42 ) ); } @@ -103,7 +102,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( 42L ); assertThat( serialized, equalTo( "42" ) ); - Long deserialized = valueSerialization.deserialize( new ValueType( Long.class ), serialized ); + Long deserialized = valueSerialization.deserialize( Long.class, serialized ); assertThat( deserialized, equalTo( 42L ) ); } @@ -113,7 +112,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( (short) 42 ); assertThat( serialized, equalTo( "42" ) ); - Short deserialized = valueSerialization.deserialize( new ValueType( Short.class ), serialized ); + Short deserialized = valueSerialization.deserialize( Short.class, serialized ); assertThat( deserialized, equalTo( (short) 42 ) ); } @@ -122,7 +121,7 @@ public class AbstractPlainValueSerializationTest { String serialized = valueSerialization.serialize( (byte) 42 ); assertThat( serialized, equalTo( "42" ) ); - Byte deserialized = valueSerialization.deserialize( new ValueType( Byte.class ), serialized ); + Byte deserialized = valueSerialization.deserialize( Byte.class, serialized ); assertThat( deserialized, equalTo( (byte) 42 ) ); } @@ -132,7 +131,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( 42F ); assertThat( serialized, equalTo( "42.0" ) ); - Float deserialized = valueSerialization.deserialize( new ValueType( Float.class ), serialized ); + Float deserialized = valueSerialization.deserialize( Float.class, serialized ); assertThat( deserialized, equalTo( 42F ) ); } @@ -142,7 +141,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( 42D ); assertThat( serialized, equalTo( "42.0" ) ); - Double deserialized = valueSerialization.deserialize( new ValueType( Double.class ), serialized ); + Double deserialized = valueSerialization.deserialize( Double.class, serialized ); assertThat( deserialized, equalTo( 42D ) ); } @@ -152,7 +151,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( new BigInteger( "42" ) ); assertThat( serialized, equalTo( "42" ) ); - BigInteger deserialized = valueSerialization.deserialize( new ValueType( BigInteger.class ), serialized ); + BigInteger deserialized = valueSerialization.deserialize( BigInteger.class, serialized ); assertThat( deserialized, equalTo( new BigInteger( "42" ) ) ); } @@ -162,7 +161,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( new BigDecimal( "42" ) ); assertThat( serialized, equalTo( "42" ) ); - BigDecimal deserialized = valueSerialization.deserialize( new ValueType( BigDecimal.class ), serialized ); + BigDecimal deserialized = valueSerialization.deserialize( BigDecimal.class, serialized ); assertThat( deserialized, equalTo( new BigDecimal( "42" ) ) ); } @@ -172,7 +171,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( new DateTime( "2020-03-04T13:24:35", UTC ).toDate() ); assertThat( serialized, equalTo( "2020-03-04T13:24:35.000Z" ) ); - Date deserialized = valueSerialization.deserialize( new ValueType( Date.class ), serialized ); + Date deserialized = valueSerialization.deserialize( Date.class, serialized ); assertThat( deserialized, equalTo( new DateTime( "2020-03-04T13:24:35", UTC ).toDate() ) ); } @@ -181,7 +180,7 @@ public class AbstractPlainValueSerializationTest { String serialized = valueSerialization.serialize( new DateTime( "2020-03-04T13:24:35", UTC ) ); assertThat( serialized, equalTo( "2020-03-04T13:24:35.000Z" ) ); - DateTime deserialized = valueSerialization.deserialize( new ValueType( DateTime.class ), serialized ); + DateTime deserialized = valueSerialization.deserialize( DateTime.class, serialized ); assertThat( deserialized, equalTo( new DateTime( "2020-03-04T13:24:35", UTC ) ) ); } @@ -191,7 +190,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( new LocalDateTime( "2020-03-04T13:23:00", UTC ) ); assertThat( serialized, equalTo( "2020-03-04T13:23:00.000" ) ); - LocalDateTime deserialized = valueSerialization.deserialize( new ValueType( LocalDateTime.class ), serialized ); + LocalDateTime deserialized = valueSerialization.deserialize( LocalDateTime.class, serialized ); assertThat( deserialized, equalTo( new LocalDateTime( "2020-03-04T13:23:00", UTC ) ) ); } @@ -201,7 +200,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( new LocalDate( "2020-03-04" ) ); assertThat( serialized, equalTo( "2020-03-04" ) ); - LocalDate deserialized = valueSerialization.deserialize( new ValueType( LocalDate.class ), serialized ); + LocalDate deserialized = valueSerialization.deserialize( LocalDate.class, serialized ); assertThat( deserialized, equalTo( new LocalDate( "2020-03-04" ) ) ); } @@ -211,7 +210,7 @@ public class AbstractPlainValueSerializationTest String serialized = valueSerialization.serialize( EntityReference.parseEntityReference( "ABCD-1234" ) ); assertThat( serialized, equalTo( "ABCD-1234" ) ); - EntityReference deserialized = valueSerialization.deserialize( new ValueType( EntityReference.class ), serialized ); + EntityReference deserialized = valueSerialization.deserialize( EntityReference.class, serialized ); assertThat( deserialized, equalTo( EntityReference.parseEntityReference( "ABCD-1234" ) ) ); } } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/core/testsupport/src/main/java/org/qi4j/test/value/AbstractTemporalValueSerializationTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractTemporalValueSerializationTest.java b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractTemporalValueSerializationTest.java deleted file mode 100644 index e841dc3..0000000 --- a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractTemporalValueSerializationTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2011, Niclas Hehdman. All Rights Reserved. - * Copyright (c) 2012, Paul Merlin. All Rights Reserved. - * - * Licensed 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.qi4j.test.value; - -import java.util.Collections; -import java.util.List; -import java.util.Set; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.LocalDateTime; -import org.junit.Before; -import org.junit.Test; -import org.qi4j.api.injection.scope.Service; -import org.qi4j.api.type.CollectionType; -import org.qi4j.api.type.ValueType; -import org.qi4j.api.value.ValueSerialization; -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.test.AbstractQi4jTest; - -import static org.joda.time.DateTimeZone.UTC; -import static org.junit.Assert.*; - -/** - * Assert that a ValueSerialization support JodaTime times correctly. - */ -@SuppressWarnings( "ProtectedField" ) -public abstract class AbstractTemporalValueSerializationTest - extends AbstractQi4jTest -{ - - private final ValueType jodaDateTimeType = new ValueType( DateTime.class ); - private final ValueType jodaLocalDateTimeType = new ValueType( LocalDateTime.class ); - private final ValueType jodaLocalDateType = new ValueType( LocalDate.class ); - - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - // NOOP - } - - @Before - public void before() - { - module.injectTo( this ); - } - @Service - protected ValueSerialization valueSerialization; - - @Test - public void givenDateTimeTypeWhenConvertingToJsonExpectValidString() - throws Exception - { - Set<DateTime> value = Collections.singleton( new DateTime( "2020-03-04T13:24:35", UTC ) ); - String stateString = valueSerialization.serialize( value ); - assertEquals( asSingleValueArray( "2020-03-04T13:24:35.000Z" ), stateString ); - } - - @Test - public void givenDateTimeTypeWhenConvertingFromJsonExpectValidLocalDate() - throws Exception - { - CollectionType collectionType = new CollectionType( List.class, jodaDateTimeType ); - String serializedState = asSingleValueArray( "2020-03-04T12:23:33Z" ); - List<DateTime> value = valueSerialization.deserialize( collectionType, serializedState ); - assertEquals( new DateTime( "2020-03-04T12:23:33Z", UTC ), value.get( 0 ) ); - } - - @Test - public void givenLocalDateTimeTypeWhenConvertingToJsonExpectValidString() - throws Exception - { - Set<LocalDateTime> value = Collections.singleton( new LocalDateTime( "2020-03-04T13:23:00", UTC ) ); - String stateString = valueSerialization.serialize( value ); - assertEquals( asSingleValueArray( "2020-03-04T13:23:00.000" ), stateString ); - } - - @Test - public void givenLocalDateTimeTypeWhenConvertingFromJsonExpectValidLocalDate() - throws Exception - { - CollectionType collectionType = new CollectionType( List.class, jodaLocalDateTimeType ); - String serializedState = asSingleValueArray( "2020-03-04T12:23:09" ); - List<LocalDateTime> value = valueSerialization.deserialize( collectionType, serializedState ); - assertEquals( new LocalDateTime( "2020-03-04T12:23:09", UTC ), value.get( 0 ) ); - } - - @Test - public void givenLocalDateTypeWhenConvertingToJsonExpectValidString() - throws Exception - { - Set<LocalDate> value = Collections.singleton( new LocalDate( "2020-03-04" ) ); - String stateString = valueSerialization.serialize( value ); - assertEquals( asSingleValueArray( "2020-03-04" ), stateString ); - } - - @Test - public void givenLocalDateTypeWhenConvertingFromJsonExpectValidLocalDate() - throws Exception - { - CollectionType collectionType = new CollectionType( List.class, jodaLocalDateType ); - String serializedState = asSingleValueArray( "2020-03-04" ); - List<LocalDate> value = valueSerialization.deserialize( collectionType, serializedState ); - assertEquals( new LocalDate( "2020-03-04" ), value.get( 0 ) ); - } - - protected abstract String asSingleValueArray( String value ); -} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/core/testsupport/src/main/java/org/qi4j/test/value/AbstractValueCompositeSerializationTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractValueCompositeSerializationTest.java b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractValueCompositeSerializationTest.java index d470958..ba5cf15 100644 --- a/core/testsupport/src/main/java/org/qi4j/test/value/AbstractValueCompositeSerializationTest.java +++ b/core/testsupport/src/main/java/org/qi4j/test/value/AbstractValueCompositeSerializationTest.java @@ -97,14 +97,14 @@ public abstract class AbstractValueCompositeSerializationTest { SomeValue some = buildSomeValue(); - // Serialize + // Serialize using injected service ByteArrayOutputStream output = new ByteArrayOutputStream(); valueSerialization.serialize( some, output, true ); String stateString = output.toString( "UTF-8" ); log.info( "Complex ValueComposite state:\n\n{}\n", stateString ); - // Deserialize + // Deserialize using Module API SomeValue some2 = module.newValueFromSerializedState( SomeValue.class, stateString ); assertThat( "Same value toString", some.toString(), equalTo( some2.toString() ) ); http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/core/testsupport/src/main/java/org/qi4j/test/value/package.html ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/qi4j/test/value/package.html b/core/testsupport/src/main/java/org/qi4j/test/value/package.html new file mode 100644 index 0000000..b8575dc --- /dev/null +++ b/core/testsupport/src/main/java/org/qi4j/test/value/package.html @@ -0,0 +1,5 @@ +<html> + <body> + <h2>ValueSerialization SPI Test Support.</h2> + </body> +</html> http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/extensions/valueserialization-jackson/dev-status.xml ---------------------------------------------------------------------- diff --git a/extensions/valueserialization-jackson/dev-status.xml b/extensions/valueserialization-jackson/dev-status.xml new file mode 100644 index 0000000..7a7c572 --- /dev/null +++ b/extensions/valueserialization-jackson/dev-status.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<module xmlns="http://www.qi4j.org/schemas/2008/dev-status/1" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.qi4j.org/schemas/2008/dev-status/1 + http://www.qi4j.org/schemas/2008/dev-status/1/dev-status.xsd"> + <status> + <codebase>beta</codebase> + <!--none,early,beta,stable,mature--> + <documentation>none</documentation> + <!-- none, brief, good, complete --> + <unittests>complete</unittests> + <!-- none, some, good, complete --> + </status> + <licenses> + <license>ALv2</license> + </licenses> +</module> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/extensions/valueserialization-jackson/src/test/java/org/qi4j/valueserialization/jackson/JacksonTemporalValueSerializationTest.java ---------------------------------------------------------------------- diff --git a/extensions/valueserialization-jackson/src/test/java/org/qi4j/valueserialization/jackson/JacksonTemporalValueSerializationTest.java b/extensions/valueserialization-jackson/src/test/java/org/qi4j/valueserialization/jackson/JacksonTemporalValueSerializationTest.java deleted file mode 100644 index 6d95b45..0000000 --- a/extensions/valueserialization-jackson/src/test/java/org/qi4j/valueserialization/jackson/JacksonTemporalValueSerializationTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2012, Paul Merlin. All Rights Reserved. - * - * Licensed 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.qi4j.valueserialization.jackson; - -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.test.value.AbstractTemporalValueSerializationTest; - -public class JacksonTemporalValueSerializationTest - extends AbstractTemporalValueSerializationTest -{ - - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - super.assemble( module ); - module.services( JacksonValueSerializationService.class ); - } - - @Override - protected String asSingleValueArray( String value ) - { - return "[\"" + value + "\"]"; - } -} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/extensions/valueserialization-stax/dev-status.xml ---------------------------------------------------------------------- diff --git a/extensions/valueserialization-stax/dev-status.xml b/extensions/valueserialization-stax/dev-status.xml new file mode 100644 index 0000000..7a7c572 --- /dev/null +++ b/extensions/valueserialization-stax/dev-status.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<module xmlns="http://www.qi4j.org/schemas/2008/dev-status/1" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.qi4j.org/schemas/2008/dev-status/1 + http://www.qi4j.org/schemas/2008/dev-status/1/dev-status.xsd"> + <status> + <codebase>beta</codebase> + <!--none,early,beta,stable,mature--> + <documentation>none</documentation> + <!-- none, brief, good, complete --> + <unittests>complete</unittests> + <!-- none, some, good, complete --> + </status> + <licenses> + <license>ALv2</license> + </licenses> +</module> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/a2069655/extensions/valueserialization-stax/src/test/java/org/qi4j/valueserialization/stax/StaxTemporalValueSerializationTest.java ---------------------------------------------------------------------- diff --git a/extensions/valueserialization-stax/src/test/java/org/qi4j/valueserialization/stax/StaxTemporalValueSerializationTest.java b/extensions/valueserialization-stax/src/test/java/org/qi4j/valueserialization/stax/StaxTemporalValueSerializationTest.java deleted file mode 100644 index 019d9f9..0000000 --- a/extensions/valueserialization-stax/src/test/java/org/qi4j/valueserialization/stax/StaxTemporalValueSerializationTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2012, Paul Merlin. All Rights Reserved. - * - * Licensed 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.qi4j.valueserialization.stax; - -import org.qi4j.bootstrap.AssemblyException; -import org.qi4j.bootstrap.ModuleAssembly; -import org.qi4j.test.value.AbstractTemporalValueSerializationTest; - -public class StaxTemporalValueSerializationTest - extends AbstractTemporalValueSerializationTest -{ - - @Override - public void assemble( ModuleAssembly module ) - throws AssemblyException - { - module.services( StaxValueSerializationService.class ); - } - - @Override - protected String asSingleValueArray( String value ) - { - return "<?xml version=\"1.1\" encoding=\"utf-8\"?><array><value>" + value + "</value></array>"; - } -}
