polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nic...@apache.org
Subject [05/14] zest-qi4j git commit: OrgJson Serialization has a bug in the handling of NamedAssociation. Adding test for that.
Date Tue, 09 Jun 2015 23:58:03 GMT
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/develop
Commit: 15e1e72248c7a0b93e3ac5bbb1ba501576e69561
Parents: 29e605a
Author: Niclas Hedhman <niclas@hedhman.org>
Authored: Thu May 21 16:20:44 2015 +0800
Committer: Niclas Hedhman <niclas@hedhman.org>
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<DualFaced> 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<String> name();
+    }
+
+    public interface DualFaced extends Identity
+    {
+        Property<String> name();
+
+        Association<SimpleEntity> simple();
+
+        ManyAssociation<SimpleEntity> simples();
+
+        NamedAssociation<SimpleEntity> 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<SimpleEntity> builder1 = uow.newEntityBuilder( SimpleEntity.class
);
+            EntityBuilder<SimpleName> builder1 = uow.newEntityBuilder( SimpleName.class
);
             builder1.instance().name().set( "Niclas" );
-            SimpleEntity simpleEntity = builder1.newInstance();
+            SimpleName simpleEntity = builder1.newInstance();
             identity1 = simpleEntity.identity().get();
 
             EntityBuilder<DualFaced> 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<SimpleName> builder1 = uow.newEntityBuilder( SimpleName.class
);
+            builder1.instance().name().set( "Niclas" );
+            SimpleName simpleEntity = builder1.newInstance();
+            identity1 = simpleEntity.identity().get();
+
+            EntityBuilder<DualFaced> 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<DualFaced> 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<String> name();
     }
@@ -123,10 +159,10 @@ public class ValueWithAssociationTest extends AbstractQi4jTest
     {
         Property<String> name();
 
-        Association<SimpleEntity> simple();
+        Association<SimpleName> simple();
 
-        ManyAssociation<SimpleEntity> simples();
+        ManyAssociation<SimpleName> simples();
 
-        NamedAssociation<SimpleEntity> namedSimples();
+        NamedAssociation<SimpleName> namedSimples();
     }
 }


Mime
View raw message