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 2021/07/30 20:17:35 UTC

[isis] branch master updated: ISIS-2794: add tests for CreatedLifecycleEvent

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 b5272ff  ISIS-2794: add tests for CreatedLifecycleEvent
b5272ff is described below

commit b5272ff03352c4987b2985c854051e9db71c1d89
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Jul 30 22:17:20 2021 +0200

    ISIS-2794: add tests for CreatedLifecycleEvent
---
 .../publishing/LifecycleEventPublishingTestAbstract.java       | 10 ++++++++--
 .../isis/testdomain/publishing/PublishingTestFactoryJdo.java   |  7 ++++++-
 .../isis/testdomain/publishing/PublishingTestFactoryJpa.java   |  9 ++++++---
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/publishing/LifecycleEventPublishingTestAbstract.java b/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/publishing/LifecycleEventPublishingTestAbstract.java
index 0f08964..fa67dcc 100644
--- a/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/publishing/LifecycleEventPublishingTestAbstract.java
+++ b/regressiontests/incubating/src/test/java/org/apache/isis/testdomain/publishing/LifecycleEventPublishingTestAbstract.java
@@ -77,6 +77,7 @@ extends PublishingTestAbstract {
 
         case FAILURE_CASE:
 
+            assertHasCreatedLifecycleEvents(Can.empty());
             assertHasLoadedLifecycleEvents(Can.empty());
             assertHasPersistingLifecycleEvents(Can.empty());
             assertHasPersistedLifecycleEvents(Can.empty());
@@ -125,6 +126,7 @@ extends PublishingTestAbstract {
             switch(changeScenario) {
             case ENTITY_CREATION:
 
+                //assertHasCreatedLifecycleEvents(bookSample1); //FIXME creation events not triggered
                 assertHasLoadedLifecycleEvents(Can.empty());
                 assertHasPersistingLifecycleEvents(bookSample1);
                 assertHasPersistedLifecycleEvents(bookSample1);
@@ -134,6 +136,8 @@ extends PublishingTestAbstract {
                 return;
 
             case ENTITY_LOADING:
+
+                assertHasCreatedLifecycleEvents(Can.empty());
                 assertHasLoadedLifecycleEvents(bookSample1);
                 assertHasPersistingLifecycleEvents(Can.empty());
                 assertHasPersistedLifecycleEvents(Can.empty());
@@ -145,6 +149,7 @@ extends PublishingTestAbstract {
 
             case PROPERTY_UPDATE: // update the book's name -> "Book #2"
 
+                assertHasCreatedLifecycleEvents(Can.empty());
                 assertHasLoadedLifecycleEvents(Can.empty());
                 assertHasPersistingLifecycleEvents(Can.empty());
                 assertHasPersistedLifecycleEvents(Can.empty());
@@ -155,6 +160,7 @@ extends PublishingTestAbstract {
 
             case ACTION_INVOCATION: // double the book's price action -> 198.0
 
+                assertHasCreatedLifecycleEvents(Can.empty());
                 assertHasLoadedLifecycleEvents(Can.empty());
                 assertHasPersistingLifecycleEvents(Can.empty());
                 assertHasPersistedLifecycleEvents(Can.empty());
@@ -165,6 +171,7 @@ extends PublishingTestAbstract {
 
             case ENTITY_REMOVAL:
 
+                assertHasCreatedLifecycleEvents(Can.empty());
                 assertHasLoadedLifecycleEvents(Can.empty());
                 assertHasPersistingLifecycleEvents(Can.empty());
                 assertHasPersistedLifecycleEvents(Can.empty());
@@ -186,7 +193,7 @@ extends PublishingTestAbstract {
 
     // -- HELPER
 
-    //TODO also verify these
+    // these events are emitted by the FactoryService only!
     private void assertHasCreatedLifecycleEvents(final Can<BookDto> expectedBooks) {
         assertHasLifecycleEvents(
                 JdoBook.CreatedLifecycleEvent.class,
@@ -194,7 +201,6 @@ extends PublishingTestAbstract {
                 expectedBooks);
     }
 
-    //TODO also verify these
     private void assertHasLoadedLifecycleEvents(final Can<BookDto> expectedBooks) {
         assertHasLifecycleEvents(
                 JdoBook.LoadedLifecycleEvent.class,
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJdo.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJdo.java
index dcb540c..f49afde 100644
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJdo.java
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJdo.java
@@ -36,6 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.fail;
 
 import org.apache.isis.applib.annotation.Where;
+import org.apache.isis.applib.services.factory.FactoryService;
 import org.apache.isis.applib.services.iactnlayer.InteractionService;
 import org.apache.isis.applib.services.repository.RepositoryService;
 import org.apache.isis.applib.services.wrapper.DisabledException;
@@ -79,6 +80,7 @@ extends PublishingTestFactoryAbstract {
     private final ObjectManager objectManager;
     private final FixtureScripts fixtureScripts;
     private final CommitListener commitListener;
+    private final FactoryService factoryService;
 
     @Getter(onMethod_ = {@Override}, value = AccessLevel.PROTECTED)
     private final InteractionService interactionService;
@@ -406,7 +408,10 @@ extends PublishingTestFactoryAbstract {
 
         val products = new HashSet<JdoProduct>();
 
-        products.add(BookDto.sample().toJdoBook());
+        // should trigger an ObjectCreatedEvent
+        val detachedNewBook = factoryService.detachedEntity(BookDto.sample().toJdoBook());
+
+        products.add(detachedNewBook);
 
         val inventory = JdoInventory.of("Sample Inventory", products);
         pm.makePersistent(inventory);
diff --git a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJpa.java b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJpa.java
index b233d79..5bcd078 100644
--- a/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJpa.java
+++ b/regressiontests/stable/src/main/java/org/apache/isis/testdomain/publishing/PublishingTestFactoryJpa.java
@@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.fail;
 
 import org.apache.isis.applib.annotation.Where;
+import org.apache.isis.applib.services.factory.FactoryService;
 import org.apache.isis.applib.services.iactnlayer.InteractionService;
 import org.apache.isis.applib.services.repository.RepositoryService;
 import org.apache.isis.applib.services.wrapper.DisabledException;
@@ -78,6 +79,7 @@ extends PublishingTestFactoryAbstract {
     private final FixtureScripts fixtureScripts;
     private final CommitListener commitListener;
     private final JpaSupportService jpaSupport;
+    private final FactoryService factoryService;
 
     @Getter(onMethod_ = {@Override}, value = AccessLevel.PROTECTED)
     private final InteractionService interactionService;
@@ -368,8 +370,6 @@ extends PublishingTestFactoryAbstract {
         // when
         withBookDo(book->{
 
-
-
             // when - running synchronous
             val asyncControl = returningVoid().withCheckRules(); // enforce rules
 
@@ -398,7 +398,10 @@ extends PublishingTestFactoryAbstract {
 
         val products = new HashSet<JpaProduct>();
 
-        products.add(BookDto.sample().toJpaBook());
+        // should trigger an ObjectCreatedEvent
+        val detachedNewBook = factoryService.detachedEntity(BookDto.sample().toJpaBook());
+
+        products.add(detachedNewBook);
 
         val inventory = JpaInventory.of("Sample Inventory", products);
         em.persist(inventory);