Return-Path: X-Original-To: apmail-zest-commits-archive@minotaur.apache.org Delivered-To: apmail-zest-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 675AA17D85 for ; Fri, 17 Apr 2015 16:05:22 +0000 (UTC) Received: (qmail 31905 invoked by uid 500); 17 Apr 2015 16:05:22 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 31852 invoked by uid 500); 17 Apr 2015 16:05:22 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 31504 invoked by uid 99); 17 Apr 2015 16:05:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Apr 2015 16:05:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F09CBE0280; Fri, 17 Apr 2015 16:05:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: niclas@apache.org To: commits@zest.apache.org Date: Fri, 17 Apr 2015 16:05:37 -0000 Message-Id: <6ce6e499dbd54f99ab26826b86eb35d7@git.apache.org> In-Reply-To: <7ba7b5c06d714c99b0db0e728d48e7c3@git.apache.org> References: <7ba7b5c06d714c99b0db0e728d48e7c3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [17/50] [abbrv] zest-qi4j git commit: core-testsupport: better AbstractEntityStoreTest 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 Authored: Wed Feb 13 11:52:54 2013 +0100 Committer: Paul Merlin 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 valueBuilder4 = module.newValueBuilder( Tjabba.class ); @@ -94,13 +131,14 @@ public abstract class AbstractEntityStoreTest ValueBuilder 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 mapValue = new HashMap(); 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 mapValue = new HashMap(); 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 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 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 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 intValue(); @@ -379,14 +463,32 @@ public abstract class AbstractEntityStoreTest Property booleanValue(); @Optional + Property bigIntegerValue(); + + @Optional + Property bigDecimalValue(); + + @Optional Property dateValue(); @Optional + Property dateTimeValue(); + + @Optional + Property localDateTimeValue(); + + @Optional + Property localDateValue(); + + @Optional Property name(); @Optional Property unsetName(); + @UseDefaults + Property emptyName(); + @Optional Property valueProperty(); @@ -402,17 +504,18 @@ public abstract class AbstractEntityStoreTest public interface TjabbaValue extends Tjabba, ValueComposite { - } public interface Tjabba { + Property bling(); } public interface TestValue extends ValueComposite { + @UseDefaults Property stringProperty(); @@ -432,12 +535,13 @@ public abstract class AbstractEntityStoreTest Property tjabbaProperty(); - Property> serializableProperty(); + Property> mapStringStringProperty(); } public interface TestValue2 extends ValueComposite { + Property stringValue(); Property anotherValue(); @@ -445,6 +549,8 @@ public abstract class AbstractEntityStoreTest public enum TestEnum { + VALUE1, VALUE2, VALUE3 } + } \ No newline at end of file