You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/12/17 22:08:37 UTC

[isis] branch master updated: ISIS-2158: resolve 2 TODOs with Auditer and Publisher smoketests

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 63d41e9  ISIS-2158: resolve 2 TODOs with Auditer and Publisher smoketests
63d41e9 is described below

commit 63d41e9d4ec3efdd39da17c22e62dcd178ae0bbd
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Dec 17 23:08:26 2019 +0100

    ISIS-2158: resolve 2 TODOs with Auditer and Publisher smoketests
---
 .../org/apache/isis/testdomain/jdo/Product.java    |  3 +-
 .../testdomain/auditing/AuditerServiceTest.java    | 31 +++++++++++++++--
 .../publishing/PublisherServiceTest.java           | 40 ++++++++++++++++++++--
 3 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/Product.java b/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/Product.java
index 5243d1c..01d378d 100644
--- a/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/Product.java
+++ b/examples/smoketests/src/main/java/org/apache/isis/testdomain/jdo/Product.java
@@ -32,6 +32,7 @@ import javax.jdo.annotations.Persistent;
 
 import org.apache.isis.applib.annotation.Collection;
 import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.Editing;
 import org.apache.isis.applib.annotation.Property;
 
 import lombok.AccessLevel;
@@ -54,7 +55,7 @@ public class Product {
         return toString();
     }
 
-    @Property
+    @Property(editing = Editing.DISABLED) // used for an async rule check test
     @Getter @Setter @Column(allowsNull = "true")
     private String name;
 
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/auditing/AuditerServiceTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/auditing/AuditerServiceTest.java
index 7fa85c2..382782d 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/auditing/AuditerServiceTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/auditing/AuditerServiceTest.java
@@ -37,8 +37,10 @@ import org.springframework.transaction.support.TransactionTemplate;
 import org.apache.isis.applib.services.audit.AuditerService;
 import org.apache.isis.applib.services.bookmark.Bookmark;
 import org.apache.isis.applib.services.repository.RepositoryService;
+import org.apache.isis.applib.services.wrapper.DisabledException;
 import org.apache.isis.applib.services.wrapper.WrapperFactory;
 import org.apache.isis.applib.services.wrapper.WrapperFactory.ExecutionMode;
+import org.apache.isis.config.presets.IsisPresets;
 import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
 import org.apache.isis.testdomain.Incubating;
 import org.apache.isis.testdomain.Smoketest;
@@ -47,6 +49,7 @@ import org.apache.isis.testdomain.jdo.Book;
 import org.apache.isis.testdomain.jdo.JdoTestDomainPersona;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import lombok.val;
 import lombok.extern.log4j.Log4j2;
@@ -61,7 +64,7 @@ import lombok.extern.log4j.Log4j2;
                 "logging.config=log4j2-test.xml",
         })
 @TestPropertySource({
-    //IsisPresets.DebugPersistence
+    IsisPresets.SilenceWicket // just to have any config properties at all
 })
 @Incubating("inconsitent state when run in a test batch")
 //@Transactional //XXX this test is non transactional
@@ -122,7 +125,7 @@ class AuditerServiceTest {
         auditerService.clearHistory();
 
         // when - running within its own background task
-        val future = wrapper.async(book, ExecutionMode.SKIP_RULES) //TODO why do we fail when not skipping rules?
+        val future = wrapper.async(book, ExecutionMode.SKIP_RULES) // don't enforce rules for this test
         .run(Book::setName, "Book #2");
 
         future.get(1000, TimeUnit.SECONDS);
@@ -131,6 +134,30 @@ class AuditerServiceTest {
         assertEquals("targetClassName=Book,propertyName=name,preValue=Sample Book,postValue=Book #2;",
                 auditerService.getHistory());
     }
+    
+    @Test
+    void auditerService_shouldNotBeAwareOfInventoryChanges_whenUsingAsyncExecutionThatFails() 
+            throws InterruptedException, ExecutionException, TimeoutException {
+
+        // given
+        val books = repository.allInstances(Book.class);
+        assertEquals(1, books.size());
+        val book = books.listIterator().next();
+        auditerService.clearHistory();
+
+        // when - running within its own background task
+        assertThrows(DisabledException.class, ()->{
+        
+            val future = wrapper.async(book, ExecutionMode.EXECUTE)
+                    .run(Book::setName, "Book #2");
+
+            future.get(1000, TimeUnit.SECONDS);
+            
+        });
+        
+        // then - after the exception
+        assertEquals("", auditerService.getHistory());
+    }
 
     // -- HELPER
 
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/publishing/PublisherServiceTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/publishing/PublisherServiceTest.java
index 2708f35..61a1560 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/publishing/PublisherServiceTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/publishing/PublisherServiceTest.java
@@ -33,6 +33,7 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.TestMethodOrder;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.stereotype.Service;
+import org.springframework.test.context.TestPropertySource;
 import org.springframework.transaction.PlatformTransactionManager;
 import org.springframework.transaction.support.TransactionTemplate;
 
@@ -40,8 +41,10 @@ import org.apache.isis.applib.services.iactn.Interaction.Execution;
 import org.apache.isis.applib.services.publish.PublishedObjects;
 import org.apache.isis.applib.services.publish.PublisherService;
 import org.apache.isis.applib.services.repository.RepositoryService;
+import org.apache.isis.applib.services.wrapper.DisabledException;
 import org.apache.isis.applib.services.wrapper.WrapperFactory;
 import org.apache.isis.applib.services.wrapper.WrapperFactory.ExecutionMode;
+import org.apache.isis.config.presets.IsisPresets;
 import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
 import org.apache.isis.testdomain.Incubating;
 import org.apache.isis.testdomain.Smoketest;
@@ -50,6 +53,7 @@ import org.apache.isis.testdomain.jdo.Book;
 import org.apache.isis.testdomain.jdo.JdoTestDomainPersona;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import lombok.Getter;
 import lombok.val;
@@ -66,6 +70,9 @@ import lombok.val;
                 // "isis.reflector.introspector.parallelize=false",
                 // "logging.level.org.apache.isis.metamodel.specloader.specimpl.ObjectSpecificationAbstract=TRACE"
         })
+@TestPropertySource({
+    IsisPresets.SilenceWicket // just to have any config properties at all
+})
 @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
 @Incubating("inconsitent state when run in a test batch")
 class PublisherServiceTest {
@@ -117,7 +124,7 @@ class PublisherServiceTest {
     }
 
     @Test @Order(2)
-    void publisherServiceShouldBeAwareOfInventoryChanges_whenUsingAsyncExecution() 
+    void publisherService_shouldBeAwareOfInventoryChanges_whenUsingAsyncExecution() 
             throws InterruptedException, ExecutionException, TimeoutException {
 
         // given
@@ -125,7 +132,7 @@ class PublisherServiceTest {
         publisherService.clearHistory();
 
         // when - running within its own background task
-        val future = wrapper.async(book, ExecutionMode.SKIP_RULES) //TODO why do we fail when not skipping rules?
+        val future = wrapper.async(book, ExecutionMode.SKIP_RULES) // don't enforce rules for this test
                 .run(Book::setName, "Book #2");
 
         future.get(1000, TimeUnit.SECONDS);
@@ -139,6 +146,35 @@ class PublisherServiceTest {
         assertEquals(1, history.get("modified"));
 
     }
+    
+    
+    @Test @Order(3)
+    void publisherService_shouldNotBeAwareOfInventoryChanges_whenUsingAsyncExecutionFails() 
+            throws InterruptedException, ExecutionException, TimeoutException {
+
+        // given
+        val book = repository.allInstances(Book.class).listIterator().next();
+        publisherService.clearHistory();
+
+        // when - running within its own background task
+        assertThrows(DisabledException.class, ()->{
+            
+            val future = wrapper.async(book, ExecutionMode.EXECUTE) 
+                .run(Book::setName, "Book #2");
+            
+            future.get(1000, TimeUnit.SECONDS);
+            
+        });
+
+        // then - after the commit
+        val history = publisherService.getHistory();
+        assertEquals(null, history.get("created"));
+        assertEquals(null, history.get("deleted"));
+        assertEquals(null, history.get("loaded"));
+        assertEquals(null, history.get("updated"));
+        assertEquals(null, history.get("modified"));
+
+    }
 
     // -- HELPER