You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by pa...@apache.org on 2017/03/13 10:35:28 UTC
[36/50] [abbrv] polygene-java git commit: Unify handling of primitive
value types and their boxed counterparts
Unify handling of primitive value types and their boxed counterparts
More coverage for plain values (de)serialization on json/xml/msgpack
POLYGENE-191
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/86d01692
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/86d01692
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/86d01692
Branch: refs/heads/serialization-3.0
Commit: 86d01692489040167e8c870b35fae562c0cb7c90
Parents: c9dd722
Author: Paul Merlin <pa...@apache.org>
Authored: Sun Feb 26 23:43:29 2017 +0100
Committer: Paul Merlin <pa...@apache.org>
Committed: Mon Mar 13 11:24:03 2017 +0100
----------------------------------------------------------------------
.../org/apache/polygene/api/type/ValueType.java | 56 +++++-
.../AbstractPlainValueSerializationTest.java | 176 ++++++++++++++-----
extensions/entitystore-sql/build.gradle | 3 +
.../entitystore/sql/SQLMapEntityStoreMixin.java | 4 +-
.../apache/polygene/index/rdf/ContainsTest.java | 2 +-
.../JavaxJsonPlainValueSerializationTest.java | 5 +
.../javaxxml/JavaxXmlDeserializer.java | 6 +-
.../JavaxXmlPlainValueSerializationTest.java | 58 ++++++
.../javaxxml/JavaxXmlPlainValueTest.java | 35 ----
.../MessagePackPlainValueSerializationTest.java | 11 +-
10 files changed, 267 insertions(+), 89 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/86d01692/core/api/src/main/java/org/apache/polygene/api/type/ValueType.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/type/ValueType.java b/core/api/src/main/java/org/apache/polygene/api/type/ValueType.java
index d457d81..6c45db2 100644
--- a/core/api/src/main/java/org/apache/polygene/api/type/ValueType.java
+++ b/core/api/src/main/java/org/apache/polygene/api/type/ValueType.java
@@ -29,6 +29,7 @@ import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.Period;
import java.time.ZonedDateTime;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@@ -48,8 +49,8 @@ public class ValueType implements HasTypes
public static final ValueType CHARACTER = ValueType.of( Character.class, char.class );
public static final ValueType BOOLEAN = ValueType.of( Boolean.class, boolean.class );
public static final ValueType INTEGER = ValueType.of( Integer.class, int.class );
- public static final ValueType LONG = ValueType.of( Long.class, long.class );
public static final ValueType SHORT = ValueType.of( Short.class, short.class );
+ public static final ValueType LONG = ValueType.of( Long.class, long.class );
public static final ValueType BYTE = ValueType.of( Byte.class, byte.class );
public static final ValueType FLOAT = ValueType.of( Float.class, float.class );
public static final ValueType DOUBLE = ValueType.of( Double.class, double.class );
@@ -80,7 +81,56 @@ public class ValueType implements HasTypes
protected ValueType( List<Class<?>> types )
{
- this.types = types;
+ this.types = applyPrimitiveAndBoxedTypes( types );
+ }
+
+ private List<Class<?>> applyPrimitiveAndBoxedTypes( List<Class<?>> types )
+ {
+ int charPrimitiveIndex = types.indexOf( char.class );
+ int charBoxedIndex = types.indexOf( Character.class );
+ int boolPrimitiveIndex = types.indexOf( boolean.class );
+ int boolBoxedIndex = types.indexOf( Boolean.class );
+ int intPrimitiveIndex = types.indexOf( int.class );
+ int intBoxedIndex = types.indexOf( Integer.class );
+ int shortPrimitiveIndex = types.indexOf( short.class );
+ int shortBoxedIndex = types.indexOf( Short.class );
+ int longPrimitiveIndex = types.indexOf( long.class );
+ int longBoxedIndex = types.indexOf( Long.class );
+ int bytePrimitiveIndex = types.indexOf( byte.class );
+ int byteBoxedIndex = types.indexOf( Byte.class );
+ int floatPrimitiveIndex = types.indexOf( float.class );
+ int floatBoxedIndex = types.indexOf( Float.class );
+ int doublePrimitiveIndex = types.indexOf( double.class );
+ int doubleBoxedIndex = types.indexOf( Double.class );
+ if( charPrimitiveIndex == -1 && charBoxedIndex == -1
+ && boolPrimitiveIndex == -1 && boolBoxedIndex == -1
+ && intPrimitiveIndex == -1 && intBoxedIndex == -1
+ && shortPrimitiveIndex == -1 && shortBoxedIndex == -1
+ && longPrimitiveIndex == -1 && longBoxedIndex == -1
+ && bytePrimitiveIndex == -1 && byteBoxedIndex == -1
+ && floatPrimitiveIndex == -1 && floatBoxedIndex == -1
+ && doublePrimitiveIndex == -1 && doubleBoxedIndex == -1 )
+ {
+ return types;
+ }
+ List<Class<?>> allTypes = new ArrayList<>( types );
+ if( charPrimitiveIndex >= 0 && charBoxedIndex == -1 ) { allTypes.add( Character.class ); }
+ if( charPrimitiveIndex == -1 && charBoxedIndex >= 0 ) { allTypes.add( char.class ); }
+ if( boolPrimitiveIndex >= 0 && boolBoxedIndex == -1 ) { allTypes.add( Boolean.class ); }
+ if( boolPrimitiveIndex == -1 && boolBoxedIndex >= 0 ) { allTypes.add( boolean.class ); }
+ if( intPrimitiveIndex >= 0 && intBoxedIndex == -1 ) { allTypes.add( Integer.class ); }
+ if( intPrimitiveIndex == -1 && intBoxedIndex >= 0 ) { allTypes.add( int.class ); }
+ if( shortPrimitiveIndex >= 0 && shortBoxedIndex == -1 ) { allTypes.add( Short.class ); }
+ if( shortPrimitiveIndex == -1 && shortBoxedIndex >= 0 ) { allTypes.add( short.class ); }
+ if( longPrimitiveIndex >= 0 && longBoxedIndex == -1 ) { allTypes.add( Long.class ); }
+ if( longPrimitiveIndex == -1 && longBoxedIndex >= 0 ) { allTypes.add( long.class ); }
+ if( bytePrimitiveIndex >= 0 && byteBoxedIndex == -1 ) { allTypes.add( Byte.class ); }
+ if( bytePrimitiveIndex == -1 && byteBoxedIndex >= 0 ) { allTypes.add( byte.class ); }
+ if( floatPrimitiveIndex >= 0 && floatBoxedIndex == -1 ) { allTypes.add( Float.class ); }
+ if( floatPrimitiveIndex == -1 && floatBoxedIndex >= 0 ) { allTypes.add( float.class ); }
+ if( doublePrimitiveIndex >= 0 && doubleBoxedIndex == -1 ) { allTypes.add( Double.class ); }
+ if( doublePrimitiveIndex == -1 && doubleBoxedIndex >= 0 ) { allTypes.add( double.class ); }
+ return allTypes;
}
public Class<?> primaryType()
@@ -115,7 +165,7 @@ public class ValueType implements HasTypes
String name = types.stream().map( Class::getName ).collect( joining( "," ) );
if( name.contains( "," ) )
{
- name = "{" + name + "}";
+ name = '{' + name + '}';
}
return name;
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/86d01692/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractPlainValueSerializationTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractPlainValueSerializationTest.java b/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractPlainValueSerializationTest.java
index 7e72ff1..8f3ad6a 100644
--- a/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractPlainValueSerializationTest.java
+++ b/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractPlainValueSerializationTest.java
@@ -21,9 +21,14 @@ package org.apache.polygene.test.serialization;
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.time.Duration;
+import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
+import java.time.LocalTime;
import java.time.OffsetDateTime;
+import java.time.Period;
+import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import org.apache.polygene.api.entity.EntityReference;
@@ -44,8 +49,7 @@ import static org.junit.Assert.assertThat;
/**
* Assert that ValueSerialization behaviour on plain values is correct.
*/
-public abstract class AbstractPlainValueSerializationTest
- extends AbstractPolygeneTest
+public abstract class AbstractPlainValueSerializationTest extends AbstractPolygeneTest
{
@Service
protected Serialization stateSerialization;
@@ -55,61 +59,83 @@ public abstract class AbstractPlainValueSerializationTest
{
}
- @Test
- public void givenEmptyStateStringWhenDeserializingExpectSuccesses()
- {
- assertThat( stateSerialization.deserialize( module, ValueType.of( Integer.class ), "" ), is( 0 ) );
- assertThat( stateSerialization.deserialize( module, ValueType.of( String.class ), "" ), equalTo( "" ) );
- }
+ protected abstract String getSingleStringRawState( String state ) throws Exception;
@Test
public void givenNullValueWhenSerializingAndDeserializingExpectNull()
{
String output = stateSerialization.serialize( null );
System.out.println( output );
+
assertThat( stateSerialization.deserialize( module, ValueType.of( Integer.class ), output ), nullValue() );
assertThat( stateSerialization.deserialize( module, ValueType.of( String.class ), output ), nullValue() );
assertThat( stateSerialization.deserialize( module, ValueType.of( SomeEnum.class ), output ), nullValue() );
}
@Test
- public void givenEnumValueWhenSerializingAndDeserializingExpectEquals()
+ public void givenEnumValueWhenSerializingAndDeserializingExpectEquals() throws Exception
{
String output = stateSerialization.serialize( SomeEnum.B�R );
System.out.println( output );
+ assertThat( getSingleStringRawState( output ), equalTo( "B�R" ) );
+
SomeEnum value = stateSerialization.deserialize( module, EnumType.of( SomeEnum.class ), output );
assertThat( value, is( SomeEnum.B�R ) );
}
@Test
- public void givenCharacterValueWhenSerializingAndDeserializingExpectEquals()
+ public void givenPrimitiveValueWhenSerializingAndDeserializingUsingPrimitiveAndBoxedTypesExpectEquals()
+ {
+ assertPrimitiveBoxedDeserializationEquals( char.class, Character.class, '\u20ac' );
+ assertPrimitiveBoxedDeserializationEquals( boolean.class, Boolean.class, true );
+ assertPrimitiveBoxedDeserializationEquals( short.class, Short.class, (short) 23 );
+ assertPrimitiveBoxedDeserializationEquals( int.class, Integer.class, 23 );
+ assertPrimitiveBoxedDeserializationEquals( byte.class, Byte.class, (byte) 23 );
+ assertPrimitiveBoxedDeserializationEquals( long.class, Long.class, 23L );
+ assertPrimitiveBoxedDeserializationEquals( float.class, Float.class, 23F );
+ assertPrimitiveBoxedDeserializationEquals( double.class, Double.class, 23D );
+ }
+
+ private <P, B> void assertPrimitiveBoxedDeserializationEquals( Class<P> primitiveType, Class<B> boxedType, P value )
+ {
+ String serialized = stateSerialization.serialize( value );
+ System.out.println( serialized );
+
+ B boxed = stateSerialization.deserialize( module, boxedType, serialized );
+ P primitive = stateSerialization.deserialize( module, primitiveType, serialized );
+ assertThat( "Primitive/Boxed", boxed, equalTo( primitive ) );
+ }
+
+ @Test
+ public void givenCharacterValueWhenSerializingAndDeserializingExpectEquals() throws Exception
{
String serialized = stateSerialization.serialize( '\u222b' );
- System.out.println(serialized);
- assertThat( "Serialized", serialized, equalTo( "\u222b" ) );
+ System.out.println( serialized );
Character deserialized = stateSerialization.deserialize( module, Character.class, serialized );
assertThat( "Deserialized", deserialized, equalTo( '\u222b' ) );
deserialized = stateSerialization.deserialize( module, char.class, serialized );
- assertThat( "Deserialized", deserialized, equalTo( '\u222b' ) );
+ assertThat( "Deserialized", deserialized, is( '\u222b' ) );
}
@Test
- public void givenEmptyStringValueWhenSerializingAndDeserializingExpectEquals()
+ public void givenEmptyStringValueWhenSerializingAndDeserializingExpectEquals() throws Exception
{
String serialized = stateSerialization.serialize( "" );
- assertThat( "Serialized", serialized, equalTo( "" ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "" ) );
String deserialized = stateSerialization.deserialize( module, String.class, serialized );
assertThat( "Deserialized", deserialized, equalTo( "" ) );
}
@Test
- public void givenStringValueWhenSerializingAndDeserializingExpectEquals()
+ public void givenStringValueWhenSerializingAndDeserializingExpectEquals() throws Exception
{
String serialized = stateSerialization.serialize( "�\u222b" );
- assertThat( serialized, equalTo( "�\u222b" ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "�\u222b" ) );
String deserialized = stateSerialization.deserialize( module, String.class, serialized );
assertThat( deserialized, equalTo( "�\u222b" ) );
@@ -119,7 +145,7 @@ public abstract class AbstractPlainValueSerializationTest
public void givenBooleanValueWhenSerializingAndDeserializingExpectEquals()
{
String serialized = stateSerialization.serialize( true );
- assertThat( serialized, equalTo( "true" ) );
+ System.out.println( serialized );
Boolean deserialized = stateSerialization.deserialize( module, Boolean.class, serialized );
assertThat( deserialized, equalTo( Boolean.TRUE ) );
@@ -129,7 +155,8 @@ public abstract class AbstractPlainValueSerializationTest
public void givenIntegerValueWhenSerializingAndDeserializingExpectEquals()
{
String serialized = stateSerialization.serialize( 42 );
- assertThat( serialized, equalTo( "42" ) );
+ System.out.println( serialized );
+
Integer deserialized = stateSerialization.deserialize( module, Integer.class, serialized );
assertThat( deserialized, equalTo( 42 ) );
}
@@ -138,7 +165,7 @@ public abstract class AbstractPlainValueSerializationTest
public void givenLongValueWhenSerializingAndDeserializingExpectEquals()
{
String serialized = stateSerialization.serialize( 42L );
- assertThat( serialized, equalTo( "42" ) );
+ System.out.println( serialized );
Long deserialized = stateSerialization.deserialize( module, Long.class, serialized );
assertThat( deserialized, equalTo( 42L ) );
@@ -148,7 +175,7 @@ public abstract class AbstractPlainValueSerializationTest
public void givenShortValueWhenSerializingAndDeserializingExpectEquals()
{
String serialized = stateSerialization.serialize( (short) 42 );
- assertThat( serialized, equalTo( "42" ) );
+ System.out.println( serialized );
Short deserialized = stateSerialization.deserialize( module, Short.class, serialized );
assertThat( deserialized, equalTo( (short) 42 ) );
@@ -158,7 +185,8 @@ public abstract class AbstractPlainValueSerializationTest
public void givenByteValueWhenSerializingAndDeserializingExpectEquals()
{
String serialized = stateSerialization.serialize( (byte) 42 );
- assertThat( serialized, equalTo( "42" ) );
+ System.out.println( serialized );
+
Byte deserialized = stateSerialization.deserialize( module, Byte.class, serialized );
assertThat( deserialized, equalTo( (byte) 42 ) );
}
@@ -167,7 +195,7 @@ public abstract class AbstractPlainValueSerializationTest
public void givenFloatValueWhenSerializingAndDeserializingExpectEquals()
{
String serialized = stateSerialization.serialize( 42F );
- assertThat( serialized, equalTo( "42.0" ) );
+ System.out.println( serialized );
Float deserialized = stateSerialization.deserialize( module, Float.class, serialized );
assertThat( deserialized, equalTo( 42F ) );
@@ -177,7 +205,7 @@ public abstract class AbstractPlainValueSerializationTest
public void givenDoubleValueWhenSerializingAndDeserializingExpectEquals()
{
String serialized = stateSerialization.serialize( 42D );
- assertThat( serialized, equalTo( "42.0" ) );
+ System.out.println( serialized );
Double deserialized = stateSerialization.deserialize( module, Double.class, serialized );
assertThat( deserialized, equalTo( 42D ) );
@@ -190,7 +218,7 @@ public abstract class AbstractPlainValueSerializationTest
assertThat( bigInteger, not( equalTo( BigInteger.valueOf( bigInteger.longValue() ) ) ) );
String serialized = stateSerialization.serialize( bigInteger );
- assertThat( serialized, equalTo( "42424242424242424242424242" ) );
+ System.out.println( serialized );
BigInteger deserialized = stateSerialization.deserialize( module, BigInteger.class, serialized );
assertThat( deserialized, equalTo( bigInteger ) );
@@ -203,49 +231,111 @@ public abstract class AbstractPlainValueSerializationTest
assertThat( bigDecimal.doubleValue(), equalTo( Double.POSITIVE_INFINITY ) );
String serialized = stateSerialization.serialize( bigDecimal );
- assertThat( serialized, equalTo( "4.22376931348623157E+310" ) );
+ System.out.println( serialized );
BigDecimal deserialized = stateSerialization.deserialize( module, BigDecimal.class, serialized );
assertThat( deserialized, equalTo( bigDecimal ) );
}
@Test
- public void givenDateTimeValueWhenSerializingAndDeserializingExpectEquals()
- {
- String serialized = stateSerialization.serialize(
- OffsetDateTime.of( 2020, 3, 4, 13, 24, 35, 123000000, ZoneOffset.ofHours( 1 ) ) );
- assertThat( serialized, equalTo( "2020-03-04T13:24:35.123+01:00" ) );
- ZonedDateTime deserialized = stateSerialization.deserialize( module, ZonedDateTime.class, serialized );
- assertThat( deserialized,
- equalTo( ZonedDateTime.of( 2020, 3, 4, 13, 24, 35, 123000000, ZoneOffset.ofHours( 1 ) ) ) );
- }
-
- @Test
- public void givenLocalDateTimeValueWhenSerializingAndDeserializingExpectEquals()
+ public void givenLocalDateTimeValueWhenSerializingAndDeserializingExpectEquals() throws Exception
{
// Serialized without TimeZone
String serialized = stateSerialization.serialize( LocalDateTime.of( 2020, 3, 4, 13, 23, 12 ) );
- assertThat( serialized, equalTo( "2020-03-04T13:23:12" ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "2020-03-04T13:23:12" ) );
LocalDateTime deserialized = stateSerialization.deserialize( module, LocalDateTime.class, serialized );
assertThat( deserialized, equalTo( LocalDateTime.of( 2020, 3, 4, 13, 23, 12 ) ) );
}
@Test
- public void givenLocalDateValueWhenSerializingAndDeserializingExpectEquals()
+ public void givenLocalDateValueWhenSerializingAndDeserializingExpectEquals() throws Exception
{
String serialized = stateSerialization.serialize( LocalDate.of( 2020, 3, 4 ) );
- assertThat( serialized, equalTo( "2020-03-04" ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "2020-03-04" ) );
LocalDate deserialized = stateSerialization.deserialize( module, LocalDate.class, serialized );
assertThat( deserialized, equalTo( LocalDate.of( 2020, 3, 4 ) ) );
}
@Test
- public void givenEntityReferenceValueWhenSerializingAndDeserializingExpectEquals()
+ public void givenLocalTimeValueWhenSerializingAndDeserializingExpectEquals() throws Exception
+ {
+ String serialized = stateSerialization.serialize( LocalTime.of( 14, 54, 27 ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "14:54:27" ) );
+
+ LocalTime deserialized = stateSerialization.deserialize( module, LocalTime.class, serialized );
+ assertThat( deserialized, equalTo( LocalTime.of( 14, 54, 27 ) ) );
+ }
+
+ @Test
+ public void givenOffsetDateTimeValueWhenSerializingAndDeserializingExpectEquals() throws Exception
+ {
+ String serialized = stateSerialization.serialize( OffsetDateTime.of( 2009, 8, 12, 14, 54, 27, 895000000,
+ ZoneOffset.ofHours( 8 ) ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "2009-08-12T14:54:27.895+08:00" ) );
+
+ OffsetDateTime deserialized = stateSerialization.deserialize( module, OffsetDateTime.class, serialized );
+ assertThat( deserialized, equalTo( OffsetDateTime.of( 2009, 8, 12, 14, 54, 27, 895000000,
+ ZoneOffset.ofHours( 8 ) ) ) );
+ }
+
+ @Test
+ public void givenZonedDateTimeValueWhenSerializingAndDeserializingExpectEquals() throws Exception
+ {
+ String serialized = stateSerialization.serialize( ZonedDateTime.of( 2009, 8, 12, 14, 54, 27, 895000000,
+ ZoneId.of( "CET" ) ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "2009-08-12T14:54:27.895+02:00[CET]" ) );
+
+ ZonedDateTime deserialized = stateSerialization.deserialize( module, ZonedDateTime.class, serialized );
+ assertThat( deserialized, equalTo( ZonedDateTime.of( 2009, 8, 12, 14, 54, 27, 895000000,
+ ZoneId.of( "CET" ) ) ) );
+ }
+
+ @Test
+ public void givenInstantValueWhenSerializingAndDeserializingExpectEquals() throws Exception
+ {
+ String serialized = stateSerialization.serialize( Instant.parse( "2016-06-11T08:47:12.620Z" ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "2016-06-11T08:47:12.620Z" ) );
+
+ Instant deserialized = stateSerialization.deserialize( module, Instant.class, serialized );
+ assertThat( deserialized, equalTo( Instant.parse( "2016-06-11T08:47:12.620Z" ) ) );
+ }
+
+ @Test
+ public void givenDurationValueWhenSerializingAndDeserializingExpectEquals() throws Exception
+ {
+ String serialized = stateSerialization.serialize( Duration.ofMillis( 3500 ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "PT3.5S" ) );
+
+ Duration deserialized = stateSerialization.deserialize( module, Duration.class, serialized );
+ assertThat( deserialized, equalTo( Duration.ofMillis( 3500 ) ) );
+ }
+
+ @Test
+ public void givenPeriodValueWhenSerializingAndDeserializingExpectEquals() throws Exception
+ {
+ String serialized = stateSerialization.serialize( Period.of( 3, 5, 13 ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "P3Y5M13D" ) );
+
+ Period deserialized = stateSerialization.deserialize( module, Period.class, serialized );
+ assertThat( deserialized, equalTo( Period.of( 3, 5, 13 ) ) );
+ }
+
+ @Test
+ public void givenEntityReferenceValueWhenSerializingAndDeserializingExpectEquals() throws Exception
{
String serialized = stateSerialization.serialize( EntityReference.parseEntityReference( "ABCD-1234" ) );
- assertThat( serialized, equalTo( "ABCD-1234" ) );
+ System.out.println( serialized );
+ assertThat( getSingleStringRawState( serialized ), equalTo( "ABCD-1234" ) );
EntityReference deserialized = stateSerialization.deserialize( module, EntityReference.class, serialized );
assertThat( deserialized, equalTo( EntityReference.parseEntityReference( "ABCD-1234" ) ) );
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/86d01692/extensions/entitystore-sql/build.gradle
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/build.gradle b/extensions/entitystore-sql/build.gradle
index 8ab34f8..15553dc 100644
--- a/extensions/entitystore-sql/build.gradle
+++ b/extensions/entitystore-sql/build.gradle
@@ -29,7 +29,10 @@ dependencies {
api polygene.library( 'sql' )
api libraries.jooq
+ implementation libraries.slf4j_api
implementation polygene.library( 'sql-liquibase' )
+
+ // TODO Remove java SQL generator dependency
implementation libraries.javaSqlGenerator
implementation( libraries.javaSqlGeneratorImpl ) {
exclude group: 'junit'
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/86d01692/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMixin.java b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMixin.java
index 95c9c5e..7e08daf 100644
--- a/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMixin.java
+++ b/extensions/entitystore-sql/src/main/java/org/apache/polygene/entitystore/sql/SQLMapEntityStoreMixin.java
@@ -54,7 +54,9 @@ import org.jooq.impl.DSL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-// TODO Implement optimistic locking! Maybe as a SPI helper
+// TODO Implement optimistic locking! Maybe as a SPI helper (in-progress)
+// TODO Add schema version data into the DB, check it
+// TODO Remove old SQL ES Code
public class SQLMapEntityStoreMixin
implements ServiceActivation, MapEntityStore
{
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/86d01692/extensions/indexing-rdf/src/test/java/org/apache/polygene/index/rdf/ContainsTest.java
----------------------------------------------------------------------
diff --git a/extensions/indexing-rdf/src/test/java/org/apache/polygene/index/rdf/ContainsTest.java b/extensions/indexing-rdf/src/test/java/org/apache/polygene/index/rdf/ContainsTest.java
index 0cde1a7..cf33cca 100644
--- a/extensions/indexing-rdf/src/test/java/org/apache/polygene/index/rdf/ContainsTest.java
+++ b/extensions/indexing-rdf/src/test/java/org/apache/polygene/index/rdf/ContainsTest.java
@@ -99,7 +99,7 @@ public class ContainsTest extends AbstractPolygeneTest
}
@Test( expected = NullPointerException.class )
- public void simplecontainsNullTest() throws Exception
+ public void simpleContainsNullTest() throws Exception
{
this.performContainsStringTest(
setOf( TEST_STRING_1, TEST_STRING_2, TEST_STRING_3 ),
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/86d01692/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/JavaxJsonPlainValueSerializationTest.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/JavaxJsonPlainValueSerializationTest.java b/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/JavaxJsonPlainValueSerializationTest.java
index 00391e7..8be807f 100644
--- a/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/JavaxJsonPlainValueSerializationTest.java
+++ b/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/JavaxJsonPlainValueSerializationTest.java
@@ -23,4 +23,9 @@ import org.apache.polygene.test.serialization.AbstractPlainValueSerializationTes
public class JavaxJsonPlainValueSerializationTest extends AbstractPlainValueSerializationTest
{
+ @Override
+ protected String getSingleStringRawState( String state )
+ {
+ return state;
+ }
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/86d01692/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
index 992e000..6488457 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
@@ -62,6 +62,7 @@ import static java.util.Collections.unmodifiableMap;
import static java.util.Collections.unmodifiableSet;
import static org.apache.polygene.api.util.Collectors.toMapWithNullValues;
+// TODO Support deserialization from formatted XML, whitespaces are a problem ATM
public class JavaxXmlDeserializer extends AbstractTextDeserializer implements XmlDeserializer
{
private static final String NULL_ELEMENT_NAME = "null";
@@ -79,10 +80,7 @@ public class JavaxXmlDeserializer extends AbstractTextDeserializer implements Xm
if( stateElement.isPresent() )
{
Optional<Node> stateNode = JavaxXml.firstStateChildNode( stateElement.get() );
- if( stateNode.isPresent() )
- {
- return doDeserialize( module, valueType, stateNode.get() );
- }
+ return doDeserialize( module, valueType, stateNode.orElse( null ) );
}
return null;
}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/86d01692/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueSerializationTest.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueSerializationTest.java b/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueSerializationTest.java
new file mode 100644
index 0000000..11979a2
--- /dev/null
+++ b/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueSerializationTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.javaxxml;
+
+import java.io.StringReader;
+import java.util.Optional;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.test.serialization.AbstractPlainValueSerializationTest;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+public class JavaxXmlPlainValueSerializationTest extends AbstractPlainValueSerializationTest
+{
+ @Override
+ public void assemble( ModuleAssembly module )
+ {
+ new JavaxXmlSerializationAssembler().assemble( module );
+ super.assemble( module );
+ }
+
+ @Override
+ protected String getSingleStringRawState( String state ) throws Exception
+ {
+ JavaxXmlSettings settings = serviceFinder.findService( JavaxXmlSerialization.class )
+ .metaInfo( JavaxXmlSettings.class );
+ settings = JavaxXmlSettings.orDefault( settings );
+ DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document doc = docBuilder.parse( new InputSource( new StringReader( state ) ) );
+ Optional<Element> stateElement = JavaxXml.firstChildElementNamed( doc, settings.getRootTagName() );
+ if( stateElement.isPresent() )
+ {
+ Optional<Node> stateNode = JavaxXml.firstStateChildNode( stateElement.get() );
+ return stateNode.map( Node::getNodeValue ).orElse( "" );
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/86d01692/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueTest.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueTest.java b/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueTest.java
deleted file mode 100644
index 51d8e8a..0000000
--- a/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueTest.java
+++ /dev/null
@@ -1,35 +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.polygene.serialization.javaxxml;
-
-import org.apache.polygene.bootstrap.ModuleAssembly;
-import org.apache.polygene.test.serialization.AbstractPlainValueSerializationTest;
-import org.junit.Ignore;
-
-@Ignore( "Super test assume JSON" )
-public class JavaxXmlPlainValueTest extends AbstractPlainValueSerializationTest
-{
- @Override
- public void assemble( ModuleAssembly module )
- {
- new JavaxXmlSerializationAssembler().assemble( module );
- super.assemble( module );
- }
-}
http://git-wip-us.apache.org/repos/asf/polygene-java/blob/86d01692/extensions/serialization-msgpack/src/test/java/org/apache/polygene/serialization/msgpack/MessagePackPlainValueSerializationTest.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-msgpack/src/test/java/org/apache/polygene/serialization/msgpack/MessagePackPlainValueSerializationTest.java b/extensions/serialization-msgpack/src/test/java/org/apache/polygene/serialization/msgpack/MessagePackPlainValueSerializationTest.java
index 3940b64..48ad8f8 100644
--- a/extensions/serialization-msgpack/src/test/java/org/apache/polygene/serialization/msgpack/MessagePackPlainValueSerializationTest.java
+++ b/extensions/serialization-msgpack/src/test/java/org/apache/polygene/serialization/msgpack/MessagePackPlainValueSerializationTest.java
@@ -19,11 +19,11 @@
*/
package org.apache.polygene.serialization.msgpack;
+import java.util.Base64;
import org.apache.polygene.bootstrap.ModuleAssembly;
import org.apache.polygene.test.serialization.AbstractPlainValueSerializationTest;
-import org.junit.Ignore;
+import org.msgpack.core.MessagePack;
-@Ignore( "Super test assume text" )
public class MessagePackPlainValueSerializationTest extends AbstractPlainValueSerializationTest
{
@Override
@@ -32,4 +32,11 @@ public class MessagePackPlainValueSerializationTest extends AbstractPlainValueSe
new MessagePackSerializationAssembler().assemble( module );
super.assemble( module );
}
+
+ @Override
+ protected String getSingleStringRawState( String state ) throws Exception
+ {
+ return MessagePack.newDefaultUnpacker( Base64.getDecoder().decode( state ) )
+ .unpackValue().asStringValue().asString();
+ }
}