polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [17/50] [abbrv] zest-qi4j git commit: core-testsupport: better AbstractEntityStoreTest
Date Fri, 17 Apr 2015 16:05:37 GMT
core-testsupport: better AbstractEntityStoreTest


Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/7e0c8ae2
Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/7e0c8ae2
Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/7e0c8ae2

Branch: refs/heads/master
Commit: 7e0c8ae21ae3ef0f605311c28dc436e55ef188a1
Parents: 761d7f1
Author: Paul Merlin <paul@nosphere.org>
Authored: Wed Feb 13 11:52:54 2013 +0100
Committer: Paul Merlin <paul@nosphere.org>
Committed: Wed Feb 13 11:52:54 2013 +0100

----------------------------------------------------------------------
 .../test/entity/AbstractEntityStoreTest.java    | 196 ++++++++++++++-----
 1 file changed, 151 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/7e0c8ae2/core/testsupport/src/main/java/org/qi4j/test/entity/AbstractEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/qi4j/test/entity/AbstractEntityStoreTest.java
b/core/testsupport/src/main/java/org/qi4j/test/entity/AbstractEntityStoreTest.java
index 4826072..d8be70c 100644
--- a/core/testsupport/src/main/java/org/qi4j/test/entity/AbstractEntityStoreTest.java
+++ b/core/testsupport/src/main/java/org/qi4j/test/entity/AbstractEntityStoreTest.java
@@ -1,9 +1,33 @@
+/*
+ * Copyright (c) 2008, Edward Yakop. All Rights Reserved.
+ * Copyright (c) 2008, Michael Hunger. All Rights Reserved.
+ * Copyright (c) 2008, Niclas Hedhman. All Rights Reserved.
+ * Copyright (c) 2008, Rickard Öberg. All Rights Reserved.
+ * Copyright (c) 2013, 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.entity;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import org.joda.time.DateTime;
+import org.joda.time.LocalDate;
+import org.joda.time.LocalDateTime;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -29,6 +53,7 @@ import org.qi4j.test.AbstractQi4jTest;
 
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.not;
+import static org.joda.time.DateTimeZone.UTC;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.fail;
 
@@ -38,6 +63,7 @@ import static org.junit.Assert.fail;
 public abstract class AbstractEntityStoreTest
     extends AbstractQi4jTest
 {
+
     @Service
     private EntityStore store;
 
@@ -74,6 +100,17 @@ public abstract class AbstractEntityStoreTest
         TestEntity instance = builder.newInstance();
 
         instance.name().set( "Test" );
+        instance.intValue().set( 42 );
+        instance.longValue().set( 42L );
+        instance.doubleValue().set( 42D );
+        instance.floatValue().set( 42F );
+        instance.booleanValue().set( Boolean.TRUE );
+        instance.bigIntegerValue().set( new BigInteger( "42" ) );
+        instance.bigDecimalValue().set( new BigDecimal( "42" ) );
+        instance.dateValue().set( new DateTime( "2020-03-04T13:24:35", UTC ).toDate() );
+        instance.dateTimeValue().set( new DateTime( "2020-03-04T13:24:35", UTC ) );
+        instance.localDateTimeValue().set( new LocalDateTime( "2020-03-04T13:23:00", UTC
) );
+        instance.localDateValue().set( new LocalDate( "2020-03-04" ) );
         instance.association().set( instance );
 
         ValueBuilder<Tjabba> valueBuilder4 = module.newValueBuilder( Tjabba.class );
@@ -94,13 +131,14 @@ public abstract class AbstractEntityStoreTest
 
         ValueBuilder<TestValue> valueBuilder1 = module.newValueBuilder( TestValue.class
);
         TestValue prototype = valueBuilder1.prototype();
+        prototype.enumProperty().set( TestEnum.VALUE3 );
         prototype.listProperty().get().add( "Foo" );
 
         prototype.valueProperty().set( valueBuilder2.newInstance() );
         prototype.tjabbaProperty().set( valueBuilder3.newInstance() );
         Map<String, String> mapValue = new HashMap<String, String>();
         mapValue.put( "foo", "bar" );
-        prototype.serializableProperty().set( mapValue );
+        prototype.mapStringStringProperty().set( mapValue );
         instance.valueProperty().set( valueBuilder1.newInstance() );
 
         instance.manyAssociation().add( 0, instance );
@@ -123,39 +161,96 @@ public abstract class AbstractEntityStoreTest
             instance = unitOfWork.get( instance );
 
             // Check state
-            assertThat( "property 'name' has correct value", instance.name().get(), equalTo(
"Test" ) );
-            assertThat( "property 'unsetName' has correct value", instance.unsetName().get(),
equalTo( null ) );
-
-            assertThat( "property has correct value", instance.valueProperty()
-                .get()
-                .valueProperty()
-                .get()
-                .stringValue().get(), equalTo( "Bar" ) );
-            assertThat( "property has correct value", instance.valueProperty()
-                .get()
-                .listProperty()
-                .get().get( 0 ), equalTo( "Foo" ) );
-            assertThat( "property has correct value", instance.valueProperty()
-                .get()
-                .valueProperty()
-                .get()
-                .anotherValue()
-                .get()
-                .bling().get(), equalTo( "BlinkLjus" ) );
-            assertThat( "property has correct value", instance.valueProperty()
-                .get()
-                .tjabbaProperty()
-                .get()
-                .bling().get(), equalTo( "Brakfis" ) );
+            assertThat( "property 'intValue' has correct value",
+                        instance.intValue().get(),
+                        equalTo( 42 ) );
+
+            assertThat( "property 'longValue' has correct value",
+                        instance.longValue().get(),
+                        equalTo( 42L ) );
+
+            assertThat( "property 'doubleValue' has correct value",
+                        instance.doubleValue().get(),
+                        equalTo( 42D ) );
+
+            assertThat( "property 'floatValue' has correct value",
+                        instance.floatValue().get(),
+                        equalTo( 42F ) );
+
+            assertThat( "property 'booleanValue' has correct value",
+                        instance.booleanValue().get(),
+                        equalTo( Boolean.TRUE ) );
+
+            assertThat( "property 'bigInteger' has correct value",
+                        instance.bigIntegerValue().get(),
+                        equalTo( new BigInteger( "42" ) ) );
+
+            assertThat( "property 'bigDecimal' has correct value",
+                        instance.bigDecimalValue().get(),
+                        equalTo( new BigDecimal( "42" ) ) );
+
+            assertThat( "property 'dateValue' has correct value",
+                        instance.dateValue().get(),
+                        equalTo( new DateTime( "2020-03-04T13:24:35", UTC ).toDate() ) );
+
+            assertThat( "property 'dateTimeValue' has correct value",
+                        instance.dateTimeValue().get(),
+                        equalTo( new DateTime( "2020-03-04T13:24:35", UTC ) ) );
+
+            assertThat( "property 'localDateTimeValue' has correct value",
+                        instance.localDateTimeValue().get(),
+                        equalTo( new LocalDateTime( "2020-03-04T13:23:00", UTC ) ) );
+
+            assertThat( "property 'localDateValue' has correct value",
+                        instance.localDateValue().get(),
+                        equalTo( new LocalDate( "2020-03-04" ) ) );
+
+            assertThat( "property 'name' has correct value",
+                        instance.name().get(),
+                        equalTo( "Test" ) );
+
+            assertThat( "property 'unsetName' has correct value",
+                        instance.unsetName().get(),
+                        equalTo( null ) );
+
+            assertThat( "property 'emptyName' has correct value",
+                        instance.emptyName().get(),
+                        equalTo( "" ) );
+
+            assertThat( "property 'valueProperty.stringValue' has correct value",
+                        instance.valueProperty().get().valueProperty().get().stringValue().get(),
+                        equalTo( "Bar" ) );
+
+            assertThat( "property 'valueProperty.listProperty' has correct value",
+                        instance.valueProperty().get().listProperty().get().get( 0 ),
+                        equalTo( "Foo" ) );
+
+            assertThat( "property 'valueProperty.enumProperty' has correct value",
+                        instance.valueProperty().get().enumProperty().get(),
+                        equalTo( TestEnum.VALUE3 ) );
+
+            assertThat( "property 'valueProperty.anotherValue.bling' has correct value",
+                        instance.valueProperty().get().valueProperty().get().anotherValue().get().bling().get(),
+                        equalTo( "BlinkLjus" ) );
+
+            assertThat( "property 'valueProperty.tjabbaProperty.bling' has correct value",
+                        instance.valueProperty().get().tjabbaProperty().get().bling().get(),
+                        equalTo( "Brakfis" ) );
+
             Map<String, String> mapValue = new HashMap<String, String>();
             mapValue.put( "foo", "bar" );
-            assertThat( "property has correct value", instance.valueProperty()
-                .get()
-                .serializableProperty().get(), equalTo( mapValue ) );
+            assertThat( "property 'valueProperty.mapStringStringProperty' has correct value",
+                        instance.valueProperty().get().mapStringStringProperty().get(),
+                        equalTo( mapValue ) );
+
+            assertThat( "association has correct value",
+                        instance.association().get(),
+                        equalTo( instance ) );
+
+            assertThat( "manyAssociation has correct value",
+                        instance.manyAssociation().iterator().next(),
+                        equalTo( instance ) );
 
-            assertThat( "association has correct value", instance.association().get(), equalTo(
instance ) );
-            assertThat( "manyAssociation has correct value", instance.manyAssociation()
-                .iterator().next(), equalTo( instance ) );
             unitOfWork.discard();
         }
         finally
@@ -202,7 +297,6 @@ public abstract class AbstractEntityStoreTest
     {
         TestEntity testEntity;
         String version;
-
         {
             UnitOfWork unitOfWork = module.newUnitOfWork();
             EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class
);
@@ -210,7 +304,6 @@ public abstract class AbstractEntityStoreTest
             testEntity = builder.newInstance();
             unitOfWork.complete();
         }
-
         {
             UnitOfWork unitOfWork = module.newUnitOfWork();
             testEntity = unitOfWork.get( testEntity );
@@ -218,7 +311,6 @@ public abstract class AbstractEntityStoreTest
 
             unitOfWork.complete();
         }
-
         {
             UnitOfWork unitOfWork = module.newUnitOfWork();
             testEntity = unitOfWork.get( testEntity );
@@ -235,7 +327,6 @@ public abstract class AbstractEntityStoreTest
     {
         TestEntity testEntity;
         String version;
-
         {
             UnitOfWork unitOfWork = module.newUnitOfWork();
             EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class
);
@@ -243,7 +334,6 @@ public abstract class AbstractEntityStoreTest
             testEntity = builder.newInstance();
             unitOfWork.complete();
         }
-
         {
             UnitOfWork unitOfWork = module.newUnitOfWork();
             testEntity = unitOfWork.get( testEntity );
@@ -252,7 +342,6 @@ public abstract class AbstractEntityStoreTest
 
             unitOfWork.complete();
         }
-
         {
             UnitOfWork unitOfWork = module.newUnitOfWork();
             testEntity = unitOfWork.get( testEntity );
@@ -269,7 +358,6 @@ public abstract class AbstractEntityStoreTest
     {
         TestEntity testEntity;
         String version;
-
         {
             UnitOfWork unitOfWork = module.newUnitOfWork();
             EntityBuilder<TestEntity> builder = unitOfWork.newEntityBuilder( TestEntity.class
);
@@ -277,7 +365,6 @@ public abstract class AbstractEntityStoreTest
             testEntity = builder.newInstance();
             unitOfWork.complete();
         }
-
         {
             UnitOfWork unitOfWork = module.newUnitOfWork();
             testEntity = unitOfWork.get( testEntity );
@@ -286,7 +373,6 @@ public abstract class AbstractEntityStoreTest
 
             unitOfWork.complete();
         }
-
         {
             UnitOfWork unitOfWork = module.newUnitOfWork();
             testEntity = unitOfWork.get( testEntity );
@@ -326,7 +412,6 @@ public abstract class AbstractEntityStoreTest
             testEntity1.name().set( "A" );
             testEntity1.unsetName().set( "A" );
         }
-
         {
             // Start working with same Entity in another UoW, and complete it
             UnitOfWork unitOfWork = module.newUnitOfWork();
@@ -335,7 +420,6 @@ public abstract class AbstractEntityStoreTest
             testEntity2.name().set( "B" );
             unitOfWork.complete();
         }
-
         {
             // Try to complete first UnitOfWork
             try
@@ -348,7 +432,6 @@ public abstract class AbstractEntityStoreTest
                 unitOfWork1.discard();
             }
         }
-
         {
             // Check values
             unitOfWork1 = module.newUnitOfWork();
@@ -363,6 +446,7 @@ public abstract class AbstractEntityStoreTest
     public interface TestEntity
         extends EntityComposite
     {
+
         @UseDefaults
         Property<Integer> intValue();
 
@@ -379,14 +463,32 @@ public abstract class AbstractEntityStoreTest
         Property<Boolean> booleanValue();
 
         @Optional
+        Property<BigInteger> bigIntegerValue();
+
+        @Optional
+        Property<BigDecimal> bigDecimalValue();
+
+        @Optional
         Property<Date> dateValue();
 
         @Optional
+        Property<DateTime> dateTimeValue();
+
+        @Optional
+        Property<LocalDateTime> localDateTimeValue();
+
+        @Optional
+        Property<LocalDate> localDateValue();
+
+        @Optional
         Property<String> name();
 
         @Optional
         Property<String> unsetName();
 
+        @UseDefaults
+        Property<String> emptyName();
+
         @Optional
         Property<TestValue> valueProperty();
 
@@ -402,17 +504,18 @@ public abstract class AbstractEntityStoreTest
     public interface TjabbaValue
         extends Tjabba, ValueComposite
     {
-
     }
 
     public interface Tjabba
     {
+
         Property<String> bling();
     }
 
     public interface TestValue
         extends ValueComposite
     {
+
         @UseDefaults
         Property<String> stringProperty();
 
@@ -432,12 +535,13 @@ public abstract class AbstractEntityStoreTest
 
         Property<Tjabba> tjabbaProperty();
 
-        Property<Map<String, String>> serializableProperty();
+        Property<Map<String, String>> mapStringStringProperty();
     }
 
     public interface TestValue2
         extends ValueComposite
     {
+
         Property<String> stringValue();
 
         Property<Tjabba> anotherValue();
@@ -445,6 +549,8 @@ public abstract class AbstractEntityStoreTest
 
     public enum TestEnum
     {
+
         VALUE1, VALUE2, VALUE3
     }
+
 }
\ No newline at end of file


Mime
View raw message