You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/06/30 14:54:27 UTC

[isis] branch ISIS-1720 created (now 2dca301)

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

danhaywood pushed a change to branch ISIS-1720
in repository https://gitbox.apache.org/repos/asf/isis.git.


      at 2dca301  ISIS-1720: adds failing example

This branch includes the following new commits:

     new 2dca301  ISIS-1720: adds failing example

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[isis] 01/01: ISIS-1720: adds failing example

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-1720
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 2dca30164d652ed0a84518921815aaff9cf8f731
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Jun 30 15:52:08 2021 +0100

    ISIS-1720: adds failing example
---
 .../interact/WrapperInteractionTest2.java          | 95 +++++++++++++---------
 1 file changed, 56 insertions(+), 39 deletions(-)

diff --git a/regressiontests/stable-interact/src/test/java/org/apache/isis/testdomain/interact/WrapperInteractionTest2.java b/regressiontests/stable-interact/src/test/java/org/apache/isis/testdomain/interact/WrapperInteractionTest2.java
index c444f10..72c8c2e 100644
--- a/regressiontests/stable-interact/src/test/java/org/apache/isis/testdomain/interact/WrapperInteractionTest2.java
+++ b/regressiontests/stable-interact/src/test/java/org/apache/isis/testdomain/interact/WrapperInteractionTest2.java
@@ -18,16 +18,26 @@
  */
 package org.apache.isis.testdomain.interact;
 
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
 import javax.inject.Inject;
 
+import org.assertj.core.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.TestPropertySource;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import org.apache.isis.applib.annotation.Action;
 import org.apache.isis.applib.annotation.DomainObject;
 import org.apache.isis.applib.annotation.Nature;
-import org.apache.isis.applib.services.wrapper.InvalidException;
+import org.apache.isis.applib.annotation.Optionality;
+import org.apache.isis.applib.annotation.Property;
 import org.apache.isis.core.config.presets.IsisPresets;
 import org.apache.isis.core.metamodel.facets.all.named.MemberNamedFacet;
 import org.apache.isis.core.metamodel.spec.feature.MixedIn;
@@ -37,21 +47,17 @@ import org.apache.isis.testdomain.conf.Configuration_headless;
 import org.apache.isis.testdomain.model.interaction.Configuration_usingInteractionDomain;
 import org.apache.isis.testdomain.util.interaction.InteractionTestAbstract;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
 import lombok.Data;
+import lombok.RequiredArgsConstructor;
 import lombok.val;
 
 @SpringBootTest(
         classes = {
                 Configuration_headless.class,
                 Configuration_usingInteractionDomain.class,
-                WrapperInteractionTest2.Customer.class,
-                WrapperInteractionTest2.Customer.ConcreteMixin.class,
-                WrapperInteractionTest2.Customer.ConcreteMixin2.class,
+                WrapperInteractionTest2.Task.class,
+                WrapperInteractionTest2.Task.Succeeded.class,
+                WrapperInteractionTest2.Task.Failed.class,
         }
 )
 @TestPropertySource({
@@ -62,44 +68,57 @@ class WrapperInteractionTest2
 extends InteractionTestAbstract {
 
     @Data @DomainObject(nature = Nature.VIEW_MODEL)
-    public static class Customer {
-        String name;
-        @Action public String who() { return name; }
+    public static class Task {
 
-        @Action
-        public class ConcreteMixin
-        extends MixinAbstract<String> {
+        @RequiredArgsConstructor
+        enum Outcome {
+            SUPER(true),
+            GREAT(true),
+            OK(true),
+            BAD(false),
+            TERRIBLE(false),
+            JUST_GIVE_UP(false),;
+
+            final boolean representsSuccess;
 
-            @Override
-            public String act(String startTime, String endTime) {
-                return "acted";
+            public static List<Outcome> successes() {
+                return Arrays.stream(Outcome.values()).filter(x -> x.representsSuccess).collect(Collectors.toList());
+            }
+            public static List<Outcome> failures() {
+                return Arrays.stream(Outcome.values()).filter(x -> ! x.representsSuccess).collect(Collectors.toList());
             }
         }
 
-        @Action
-        public class ConcreteMixin2
-        extends MixinAbstract<String> {
+        @Property(optionality = Optionality.OPTIONAL)
+        Outcome outcome;
 
-            @Override
-            public String act(String startTime, String endTime) {
-                return "acted2";
-            }
+        @Action
+        public class Succeeded
+        extends MixinAbstract {
+            public List<Task.Outcome> choices0Act() { return Task.Outcome.successes(); }
         }
 
-    }
+        @Action
+        public class Failed
+        extends MixinAbstract {
+            public List<Task.Outcome> choices0Act() { return Task.Outcome.failures(); }
+        }
 
-    // an abstract mixin class
-    static abstract class MixinAbstract<T extends Object> {
-        public T act(String startTime, String endTime) {
-            return null;
+        // an abstract mixin class
+        abstract class MixinAbstract {
+            public Task act(Task.Outcome outcome) {
+                Task.this.outcome = outcome;
+                return Task.this;
+            }
         }
     }
 
+
     @Inject SpecificationLoader specificationLoader;
 
     @Test
     void mixinMemberNamedFacet_whenSharingSameAbstractMixin() {
-        val objectSpec = specificationLoader.specForType(Customer.class).get();
+        val objectSpec = specificationLoader.specForType(Task.class).get();
 
         assertEquals(
                 2L,
@@ -117,15 +136,13 @@ extends InteractionTestAbstract {
     @Test
     void mixinActionValidation() {
 
-        InvalidException cause = assertThrows(InvalidException.class, ()-> {
-            wrapMixin(Customer.ConcreteMixin.class, new Customer()).act(null, "17:00");
-        });
-        assertEquals("'Start Time' is mandatory", cause.getMessage());
+        final Task task = new Task();
+
+        wrapMixin(Task.Succeeded.class, task).act(Task.Outcome.SUPER);
+        Assertions.assertThat(task).extracting(Task::getOutcome).isEqualTo(Task.Outcome.SUPER);
 
-        InvalidException cause2 = assertThrows(InvalidException.class, ()-> {
-            wrapMixin(Customer.ConcreteMixin2.class, new Customer()).act(null, "17:00");
-        });
-        assertEquals("'Start Time' is mandatory", cause2.getMessage());
+        wrapMixin(Task.Failed.class, task).act(Task.Outcome.JUST_GIVE_UP);
+        Assertions.assertThat(task).extracting(Task::getOutcome).isEqualTo(Task.Outcome.JUST_GIVE_UP);
     }
 
 }