Search in sources :

Example 11 with CollectionType

use of org.qi4j.api.type.CollectionType in project qi4j-sdk by Qi4j.

the class AbstractJsonDateFormatTest method givenISO6801DateFormatWhenConvertingFromSerializedStateExpectValidDate.

@Test
public void givenISO6801DateFormatWhenConvertingFromSerializedStateExpectValidDate() throws Exception {
    CollectionType collectionType = new CollectionType(List.class, dateType);
    List<Date> value = valueDeserializer.deserialize(collectionType, "[\"2009-08-12T14:54:27.895+0800\"]");
    assertEquals(new DateTime("2009-08-12T06:54:27.895Z", DateTimeZone.UTC).toDate(), value.get(0));
}
Also used : CollectionType(org.qi4j.api.type.CollectionType) Date(java.util.Date) DateTime(org.joda.time.DateTime) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 12 with CollectionType

use of org.qi4j.api.type.CollectionType in project qi4j-sdk by Qi4j.

the class AbstractJsonDateFormatTest method givenMicrosoftDateFormatWhenConvertingFromSerializedStateExpectValidDate.

@Test
public void givenMicrosoftDateFormatWhenConvertingFromSerializedStateExpectValidDate() throws Exception {
    long tstamp = System.currentTimeMillis();
    CollectionType collectionType = new CollectionType(List.class, dateType);
    List<Date> value = valueDeserializer.deserialize(collectionType, "[\"/Date(" + tstamp + ")/\"]");
    assertEquals(new Date(tstamp), value.get(0));
}
Also used : CollectionType(org.qi4j.api.type.CollectionType) Date(java.util.Date) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 13 with CollectionType

use of org.qi4j.api.type.CollectionType in project qi4j-sdk by Qi4j.

the class AbstractCollectionSerializationTest method givenIterableTypeWithByteAndNullElementWhenSerializingAndDeserializingExpectEquals.

@Test
public void givenIterableTypeWithByteAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception {
    String output = valueSerialization.serialize(Iterables.iterable(byteCollection().toArray()));
    CollectionType collectionType = new CollectionType(List.class, new ValueType(Byte.class));
    List<Byte> list = valueSerialization.deserialize(collectionType, output);
    assertEquals(byteCollection(), list);
}
Also used : ValueType(org.qi4j.api.type.ValueType) CollectionType(org.qi4j.api.type.CollectionType) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 14 with CollectionType

use of org.qi4j.api.type.CollectionType in project qi4j-sdk by Qi4j.

the class AbstractCollectionSerializationTest method givenCollectionTypeWithDoubleAndNullElementWhenSerializingExpectCorrectJsonOutput.

@Test
public void givenCollectionTypeWithDoubleAndNullElementWhenSerializingExpectCorrectJsonOutput() throws Exception {
    String output = valueSerialization.serialize(doubleCollection());
    CollectionType collectionType = new CollectionType(List.class, new ValueType(Double.class));
    List<Double> list = valueSerialization.deserialize(collectionType, output);
    assertEquals(doubleCollection(), list);
}
Also used : ValueType(org.qi4j.api.type.ValueType) CollectionType(org.qi4j.api.type.CollectionType) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Example 15 with CollectionType

use of org.qi4j.api.type.CollectionType in project qi4j-sdk by Qi4j.

the class AbstractCollectionSerializationTest method givenCollectionTypeWithBigIntegerAndNullElementWhenSerializingAndDeserializingExpectEquals.

@Test
public void givenCollectionTypeWithBigIntegerAndNullElementWhenSerializingAndDeserializingExpectEquals() throws Exception {
    String output = valueSerialization.serialize(bigIntegerCollection());
    CollectionType collectionType = new CollectionType(List.class, new ValueType(BigInteger.class));
    List<BigInteger> list = valueSerialization.deserialize(collectionType, output);
    assertEquals(bigIntegerCollection(), list);
}
Also used : ValueType(org.qi4j.api.type.ValueType) CollectionType(org.qi4j.api.type.CollectionType) BigInteger(java.math.BigInteger) AbstractQi4jTest(org.qi4j.test.AbstractQi4jTest) Test(org.junit.Test)

Aggregations

CollectionType (org.qi4j.api.type.CollectionType)22 Test (org.junit.Test)16 ValueType (org.qi4j.api.type.ValueType)16 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)16 MapType (org.qi4j.api.type.MapType)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Map (java.util.Map)6 ValueCompositeType (org.qi4j.api.type.ValueCompositeType)6 LinkedHashMap (java.util.LinkedHashMap)5 Date (java.util.Date)3 HashMap (java.util.HashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 EntityReference (org.qi4j.api.entity.EntityReference)3 PropertyDescriptor (org.qi4j.api.property.PropertyDescriptor)3 EnumType (org.qi4j.api.type.EnumType)3 ValueComposite (org.qi4j.api.value.ValueComposite)3 BigInteger (java.math.BigInteger)2 Collection (java.util.Collection)2