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 F3D7317547 for ; Thu, 21 May 2015 10:25:17 +0000 (UTC) Received: (qmail 22645 invoked by uid 500); 21 May 2015 10:25:17 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 22595 invoked by uid 500); 21 May 2015 10:25:17 -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 22434 invoked by uid 99); 21 May 2015 10:25:00 -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; Thu, 21 May 2015 10:25:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C8814E51A6; Thu, 21 May 2015 10:25:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: niclas@apache.org To: commits@zest.apache.org Date: Thu, 21 May 2015 10:25:04 -0000 Message-Id: <4e47c1735c1d4d0f8ee54876ba050299@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [5/6] zest-qi4j git commit: OrgJson Serialization has a bug in the handling of NamedAssociation. Adding test for that. OrgJson Serialization has a bug in the handling of NamedAssociation. Adding test for that. Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/15e1e722 Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/15e1e722 Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/15e1e722 Branch: refs/heads/ZEST-22_toEntity-toValue Commit: 15e1e72248c7a0b93e3ac5bbb1ba501576e69561 Parents: 29e605a Author: Niclas Hedhman Authored: Thu May 21 16:20:44 2015 +0800 Committer: Niclas Hedhman Committed: Thu May 21 16:20:44 2015 +0800 ---------------------------------------------------------------------- .../value/ValueSerializationRegressionTest.java | 58 ++++++++++++++++++++ .../runtime/value/ValueWithAssociationTest.java | 52 +++++++++++++++--- 2 files changed, 102 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/15e1e722/core/runtime/src/test/java/org/qi4j/runtime/value/ValueSerializationRegressionTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/qi4j/runtime/value/ValueSerializationRegressionTest.java b/core/runtime/src/test/java/org/qi4j/runtime/value/ValueSerializationRegressionTest.java new file mode 100644 index 0000000..5761ff9 --- /dev/null +++ b/core/runtime/src/test/java/org/qi4j/runtime/value/ValueSerializationRegressionTest.java @@ -0,0 +1,58 @@ +package org.qi4j.runtime.value; + +import org.junit.Test; +import org.qi4j.api.association.Association; +import org.qi4j.api.association.ManyAssociation; +import org.qi4j.api.association.NamedAssociation; +import org.qi4j.api.entity.Identity; +import org.qi4j.api.property.Property; +import org.qi4j.api.unitofwork.UnitOfWorkCompletionException; +import org.qi4j.api.value.ValueBuilder; +import org.qi4j.api.value.ValueSerialization; +import org.qi4j.bootstrap.AssemblyException; +import org.qi4j.bootstrap.ModuleAssembly; +import org.qi4j.entitystore.memory.MemoryEntityStoreService; +import org.qi4j.spi.uuid.UuidIdentityGeneratorService; +import org.qi4j.test.AbstractQi4jTest; +import org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService; + +public class ValueSerializationRegressionTest extends AbstractQi4jTest +{ + @Override + public void assemble( ModuleAssembly module ) + throws AssemblyException + { + module.entities( SimpleEntity.class ); + module.entities( DualFaced.class ); + module.values( DualFaced.class ); + module.services( MemoryEntityStoreService.class ); + module.services( UuidIdentityGeneratorService.class ); + module.services( OrgJsonValueSerializationService.class ).taggedWith( ValueSerialization.Formats.JSON ); + } + + @Test + public void givenNewValueWhenConvertingToEntityExpectNewEntityInStore() + throws UnitOfWorkCompletionException + { + ValueBuilder builder = module.newValueBuilder( DualFaced.class ); + builder.prototype().identity().set( "1234" ); + builder.prototype().name().set( "Hedhman" ); + DualFaced value = builder.newInstance(); + } + + public interface SimpleEntity extends Identity + { + Property name(); + } + + public interface DualFaced extends Identity + { + Property name(); + + Association simple(); + + ManyAssociation simples(); + + NamedAssociation namedSimples(); + } +} http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/15e1e722/core/runtime/src/test/java/org/qi4j/runtime/value/ValueWithAssociationTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/qi4j/runtime/value/ValueWithAssociationTest.java b/core/runtime/src/test/java/org/qi4j/runtime/value/ValueWithAssociationTest.java index 2f0fd2c..a7f88b3 100644 --- a/core/runtime/src/test/java/org/qi4j/runtime/value/ValueWithAssociationTest.java +++ b/core/runtime/src/test/java/org/qi4j/runtime/value/ValueWithAssociationTest.java @@ -31,7 +31,7 @@ public class ValueWithAssociationTest extends AbstractQi4jTest public void assemble( ModuleAssembly module ) throws AssemblyException { - module.entities( SimpleEntity.class ); + module.entities( SimpleName.class ); module.entities( DualFaced.class ); module.values( DualFaced.class ); module.services( MemoryEntityStoreService.class ); @@ -39,7 +39,7 @@ public class ValueWithAssociationTest extends AbstractQi4jTest module.services( OrgJsonValueSerializationService.class ).taggedWith( ValueSerialization.Formats.JSON ); } - @Test @Ignore + @Test public void givenEntityInStoreWhenFetchEntityReferenceExpectSuccess() throws UnitOfWorkCompletionException { @@ -48,9 +48,9 @@ public class ValueWithAssociationTest extends AbstractQi4jTest DualFaced value; try (UnitOfWork uow = module.newUnitOfWork()) { - EntityBuilder builder1 = uow.newEntityBuilder( SimpleEntity.class ); + EntityBuilder builder1 = uow.newEntityBuilder( SimpleName.class ); builder1.instance().name().set( "Niclas" ); - SimpleEntity simpleEntity = builder1.newInstance(); + SimpleName simpleEntity = builder1.newInstance(); identity1 = simpleEntity.identity().get(); EntityBuilder builder2 = uow.newEntityBuilder( DualFaced.class ); @@ -114,7 +114,43 @@ public class ValueWithAssociationTest extends AbstractQi4jTest } } - public interface SimpleEntity extends Identity + @Test + public void givenEntityInStoreWhenConvertingValueExpectEntityToBeUpdated() + throws UnitOfWorkCompletionException + { + String identity1; + String identity2; + DualFaced value; + try (UnitOfWork uow = module.newUnitOfWork()) + { + EntityBuilder builder1 = uow.newEntityBuilder( SimpleName.class ); + builder1.instance().name().set( "Niclas" ); + SimpleName simpleEntity = builder1.newInstance(); + identity1 = simpleEntity.identity().get(); + + EntityBuilder builder2 = uow.newEntityBuilder( DualFaced.class ); + DualFaced proto = builder2.instance(); + proto.name().set( "Hedhman" ); + proto.simple().set( simpleEntity ); + proto.simples().add( simpleEntity ); + proto.namedSimples().put( "niclas", simpleEntity ); + DualFaced entity = builder2.newInstance(); + value = spi.toValue( DualFaced.class, entity ); + uow.complete(); + } + + SimpleName simple = value.simple().get(); + +// ValueBuilder builder = module.newValueBuilder( DualFaced.class ); +// DualFaced prototype = builder.prototype(); +// prototype.name().set( "Paul" ); +// DualFaced value = builder.newInstance(); +// try (UnitOfWork uow = module.newUnitOfWork()) +// { +// } + } + + public interface SimpleName extends Identity { Property name(); } @@ -123,10 +159,10 @@ public class ValueWithAssociationTest extends AbstractQi4jTest { Property name(); - Association simple(); + Association simple(); - ManyAssociation simples(); + ManyAssociation simples(); - NamedAssociation namedSimples(); + NamedAssociation namedSimples(); } }