polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [6/8] zest-java git commit: ZEST-107 Moved issue test to core/testsupport/AbstractEntityStoreTest
Date Mon, 27 Jul 2015 15:12:40 GMT
ZEST-107 Moved issue test to core/testsupport/AbstractEntityStoreTest


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

Branch: refs/heads/develop
Commit: 12622af224963294fea405cff9cf96b200fb12e4
Parents: 14cbf30
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Jul 27 16:27:03 2015 +0200
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Jul 27 17:09:02 2015 +0200

----------------------------------------------------------------------
 .../test/entity/AbstractEntityStoreTest.java    |  27 ++++
 .../qi4j/cache/ehcache/JSONEntityStoreTest.java | 134 -------------------
 2 files changed, 27 insertions(+), 134 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zest-java/blob/12622af2/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 4549826..f78f932 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
@@ -53,6 +53,7 @@ import org.qi4j.spi.uuid.UuidIdentityGeneratorService;
 import org.qi4j.test.AbstractQi4jTest;
 
 import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.not;
 import static org.joda.time.DateTimeZone.UTC;
 import static org.junit.Assert.assertThat;
@@ -455,6 +456,32 @@ public abstract class AbstractEntityStoreTest
         }
     }
 
+    @Test
+    public void givenEntityStoredLoadedChangedWhenUnitOfWorkDiscardsThenDontStoreState()
+        throws UnitOfWorkCompletionException
+    {
+        UnitOfWork unitOfWork = module.newUnitOfWork();
+        try
+        {
+            String identity = createEntity( unitOfWork ).identity().get();
+            unitOfWork.complete();
+
+            unitOfWork = module.newUnitOfWork();
+            TestEntity entity = unitOfWork.get( TestEntity.class, identity );
+            assertThat( entity.intValue().get(), is( 42 ) );
+            entity.intValue().set( 23 );
+            unitOfWork.discard();
+
+            unitOfWork = module.newUnitOfWork();
+            entity = unitOfWork.get( TestEntity.class, identity );
+            assertThat( entity.intValue().get(), is( 42 ) );
+        }
+        finally
+        {
+            unitOfWork.discard();
+        }
+    }
+
     public interface TestEntity
         extends EntityComposite
     {

http://git-wip-us.apache.org/repos/asf/zest-java/blob/12622af2/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
deleted file mode 100644
index 14250ce..0000000
--- a/extensions/cache-ehcache/src/test/java/org/qi4j/cache/ehcache/JSONEntityStoreTest.java
+++ /dev/null
@@ -1,134 +0,0 @@
-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 cached_NEW_State()
-            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 );
-
-        String accountId = b.newInstance().identity().get();
-
-        uow1.complete();
-
-        UnitOfWork uow2 = assembler.module().newUnitOfWork();
-        Account account2 = uow2.get(Account.class, accountId);
-        account2.balance().set( BigDecimal.ONE);
-        uow2.complete();
-
-    }
-
-    @Test
-    public void globalStateClone()
-            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 );
-
-        String accountId = b.newInstance().identity().get();
-
-        uow1.complete();
-
-        UnitOfWork uow2 = assembler.module().newUnitOfWork();
-        Account account2 = uow2.get( Account.class, accountId);
-        account2.balance().set( BigDecimal.ONE);
-        uow2.complete();
-
-        UnitOfWork uow3 = assembler.module().newUnitOfWork();
-        Account account3 = uow3.get( Account.class, accountId);
-        account3.balance().set( BigDecimal.TEN);
-        uow3.discard();
-
-        UnitOfWork uow4 = assembler.module().newUnitOfWork();
-        Account account4 = uow4.get( Account.class, accountId);
-
-        assertEquals( BigDecimal.ONE, account4.balance().get());
-
-        uow4.discard();
-    }
-
-        public interface Account
-            extends EntityComposite
-    {
-
-        Property<String> name();
-
-        Property<BigDecimal> balance();
-    }
-
-}


Mime
View raw message