polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [41/50] zest-java git commit: entity store with enabled cache test case
Date Tue, 28 Jul 2015 12:55:38 GMT
entity store with enabled cache test case


Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/5378de50
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/5378de50
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/5378de50

Branch: refs/heads/master
Commit: 5378de507b811bd59cdca069e11f6651a970ae1f
Parents: 2982826
Author: tbml <tibor.mlynarik@adleritech.com>
Authored: Thu Jul 23 18:05:40 2015 +0200
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Jul 27 17:09:01 2015 +0200

----------------------------------------------------------------------
 .../helpers/JSONMapEntityStoreMixin.java        |   3 +-
 .../qi4j/cache/ehcache/JSONEntityStoreTest.java | 112 +++++++++++++++++++
 2 files changed, 114 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/5378de50/core/spi/src/main/java/org/qi4j/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/qi4j/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
b/core/spi/src/main/java/org/qi4j/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
index 47bf17f..cac8ec9 100644
--- a/core/spi/src/main/java/org/qi4j/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
+++ b/core/spi/src/main/java/org/qi4j/spi/entitystore/helpers/JSONMapEntityStoreMixin.java
@@ -479,7 +479,8 @@ public class JSONMapEntityStoreMixin
             {
                 String type = data.getString( JSONKeys.TYPE );
                 EntityDescriptor entityDescriptor = module.entityDescriptor( type );
-                return new JSONEntityState( currentTime, valueSerialization, identity, entityDescriptor,
data );
+//                return new JSONEntityState( currentTime, valueSerialization, identity,
entityDescriptor, data );
+                return new JSONEntityState( valueSerialization, data.getString( JSONKeys.VERSION
), data.getLong( JSONKeys.MODIFIED ), identity, EntityStatus.LOADED, entityDescriptor, data
);
             }
             catch( JSONException e )
             {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/5378de50/extensions/cache-ehcache/src/test/java/org/qi4j/cache/ehcache/JSONEntityStoreTest.java
----------------------------------------------------------------------
diff --git a/extensions/cache-ehcache/src/test/java/org/qi4j/cache/ehcache/JSONEntityStoreTest.java
b/extensions/cache-ehcache/src/test/java/org/qi4j/cache/ehcache/JSONEntityStoreTest.java
new file mode 100644
index 0000000..13670c2
--- /dev/null
+++ b/extensions/cache-ehcache/src/test/java/org/qi4j/cache/ehcache/JSONEntityStoreTest.java
@@ -0,0 +1,112 @@
+package org.qi4j.cache.ehcache;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.qi4j.api.common.Visibility;
+import org.qi4j.api.entity.EntityBuilder;
+import org.qi4j.api.entity.EntityComposite;
+import org.qi4j.api.property.Property;
+import org.qi4j.api.unitofwork.UnitOfWork;
+import org.qi4j.api.value.ValueSerialization;
+import org.qi4j.bootstrap.AssemblyException;
+import org.qi4j.bootstrap.ModuleAssembly;
+import org.qi4j.bootstrap.SingletonAssembler;
+import org.qi4j.entitystore.memory.MemoryEntityStoreService;
+import org.qi4j.spi.uuid.UuidIdentityGeneratorService;
+import org.qi4j.test.EntityTestAssembler;
+import org.qi4j.valueserialization.orgjson.OrgJsonValueSerializationService;
+
+import java.math.BigDecimal;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+public class JSONEntityStoreTest
+{
+
+    private static SingletonAssembler assembler;
+
+    @BeforeClass
+    public static void setup()
+            throws Exception
+    {
+        assembler = new SingletonAssembler()
+        {
+            public void assemble( ModuleAssembly module )
+                    throws AssemblyException
+            {
+                module.entities(
+                        Account.class
+                );
+
+                ModuleAssembly cacheCfgModule = module.layer().application().layer("configLayer").module(
"configModule" );
+
+                cacheCfgModule.services( MemoryEntityStoreService.class )
+                        .instantiateOnStartup()
+                        .visibleIn(Visibility.module);
+
+                cacheCfgModule.services( UuidIdentityGeneratorService.class ).visibleIn(
Visibility.module );
+                cacheCfgModule.services( OrgJsonValueSerializationService.class ).taggedWith(
ValueSerialization.Formats.JSON );
+                cacheCfgModule.entities( EhCacheConfiguration.class).visibleIn(Visibility.application);
+
+                module.layer().uses( cacheCfgModule.layer() );
+
+                module.services( EhCachePoolService.class)
+                        .visibleIn(Visibility.module)
+                        .identifiedBy("ehcache");
+
+
+                new EntityTestAssembler()
+                        .visibleIn( Visibility.module)
+                        .assemble( module);
+
+            }
+        };
+
+    }
+
+    @Test
+    public void cacheJSONGlobalStateTest()
+            throws Exception
+    {
+
+        UnitOfWork uow1 = assembler.module().newUnitOfWork();
+        EntityBuilder<Account> b = uow1.newEntityBuilder(Account.class);
+
+        b.instance().name().set("account1");
+        b.instance().balance().set( BigDecimal.ZERO );
+
+        Account account1 = b.newInstance();
+
+        uow1.complete();
+
+        UnitOfWork uow2 = assembler.module().newUnitOfWork();
+        Account account2 = uow2.get(account1);
+        account2.balance().set( BigDecimal.ONE);
+        uow2.complete();
+
+        UnitOfWork uow3 = assembler.module().newUnitOfWork();
+        Account account3 = uow3.get(account1);
+        account3.balance().set( BigDecimal.TEN);
+        uow3.discard();
+
+        UnitOfWork uow4 = assembler.module().newUnitOfWork();
+        Account account4 = uow4.get(account1);
+
+        assertEquals( BigDecimal.ONE, account4.balance().get());
+
+        uow4.discard();
+    }
+
+        public interface Account
+            extends EntityComposite
+    {
+
+        Property<String> name();
+
+        Property<BigDecimal> balance();
+    }
+
+}


Mime
View raw message