You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2023/09/29 08:52:07 UTC

[causeway] branch CAUSEWAY-3546 updated: CAUSEWAY-3546: fixes impl and tests

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

danhaywood pushed a commit to branch CAUSEWAY-3546
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/CAUSEWAY-3546 by this push:
     new f0b4c97117 CAUSEWAY-3546: fixes impl and tests
f0b4c97117 is described below

commit f0b4c97117d3435b537f303f9fa9c9d0683a1c51
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Sep 29 09:52:01 2023 +0100

    CAUSEWAY-3546: fixes impl and tests
---
 .../CommandPublishingFacetForActionAnnotation.java |  4 +-
 ...ommandPublishingFacetForPropertyAnnotation.java | 10 ++-
 ...xecutionPublishingFacetForActionAnnotation.java | 48 ++++++------
 ...cutionPublishingFacetForPropertyAnnotation.java |  7 +-
 ...tationFacetFactoryTest_executionPublishing.java | 86 +++++++++++++++++++++-
 5 files changed, 117 insertions(+), 38 deletions(-)

diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/command/CommandPublishingFacetForActionAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/command/CommandPublishingFacetForActionAnnotation.java
index e4f6f711e6..8f4dd4a4d1 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/command/CommandPublishingFacetForActionAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/command/CommandPublishingFacetForActionAnnotation.java
@@ -88,14 +88,14 @@ public abstract class CommandPublishingFacetForActionAnnotation extends CommandP
                                 case ALL:
                                     return new CommandPublishingFacetForActionAnnotationAsConfigured.All(holder, servicesInjector);
                                 default:
-                                    throw new IllegalStateException(String.format("configured commandPublishing policy '%s' not recognised", publishingPolicy));
+                                    throw new IllegalStateException(String.format("configured action.commandPublishing policy '%s' not recognised", publishingPolicy));
                             }
                         case DISABLED:
                             return new CommandPublishingFacetForActionAnnotation.Disabled(processor, holder, servicesInjector);
                         case ENABLED:
                             return new CommandPublishingFacetForActionAnnotation.Enabled(processor, holder, servicesInjector);
                         default:
-                            throw new IllegalStateException(String.format("commandPublishing '%s' not recognised", publishing));
+                            throw new IllegalStateException(String.format("@Action#commandPublishing '%s' not recognised", publishing));
                     }
                 });
     }
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/command/CommandPublishingFacetForPropertyAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/command/CommandPublishingFacetForPropertyAnnotation.java
index 7415b05ce3..6a5a8196c3 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/command/CommandPublishingFacetForPropertyAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/command/CommandPublishingFacetForPropertyAnnotation.java
@@ -87,28 +87,30 @@ public abstract class CommandPublishingFacetForPropertyAnnotation extends Comman
                             case ALL:
                                 return new CommandPublishingFacetForPropertyAnnotationAsConfigured.All(holder, servicesInjector);
                             default:
-                                throw new IllegalStateException(String.format("configured publishingPolicy '%s' not recognised", publishingPolicy));
+                                throw new IllegalStateException(String.format("configured property.commandpublishing policy '%s' not recognised", publishingPolicy));
                         }
                     case DISABLED:
                         return new CommandPublishingFacetForPropertyAnnotation.Disabled(processor, holder, servicesInjector);
                     case ENABLED:
                         return new CommandPublishingFacetForPropertyAnnotation.Enabled(processor, holder, servicesInjector);
                     default:
-                        throw new IllegalStateException(String.format("commandPublishing '%s' not recognised", publishing));
+                        throw new IllegalStateException(String.format("@Property#commandPublishing '%s' not recognised", publishing));
                 }
             })
             .orElseGet(() -> {
                 // there is no publishing facet from either @Action or @Property, so use the appropriate configuration to install a default
                 if (representsProperty(holder)) {
+                    // we are dealing with a property
                     switch (publishingPolicy) {
                         case NONE:
                             return new CommandPublishingFacetForPropertyFromConfiguration.None(holder, servicesInjector);
                         case ALL:
                             return new CommandPublishingFacetForPropertyFromConfiguration.All(holder, servicesInjector);
                         default:
-                            throw new IllegalStateException(String.format("configured property publishingPolicy '%s' not recognised", publishingPolicy));
+                            throw new IllegalStateException(String.format("configured property.commandPublishing policy '%s' not recognised", publishingPolicy));
                     }
                 } else {
+                    // we are dealing with an action
                     val actionPublishingPolicy = ActionConfigOptions.actionCommandPublishingPolicy(configuration);
                     switch (actionPublishingPolicy) {
                         case NONE:
@@ -121,7 +123,7 @@ public abstract class CommandPublishingFacetForPropertyAnnotation extends Comman
                         case ALL:
                             return new CommandPublishingFacetForActionFromConfiguration.All(holder, servicesInjector);
                         default:
-                            throw new IllegalStateException(String.format("configured action publishingPolicy '%s' not recognised", actionPublishingPolicy));
+                            throw new IllegalStateException(String.format("configured action.commandPublishing policy '%s' not recognised", actionPublishingPolicy));
                     }
                 }
             });
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/execution/ExecutionPublishingFacetForActionAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/execution/ExecutionPublishingFacetForActionAnnotation.java
index da9b9ba8f0..a4fa9d5553 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/execution/ExecutionPublishingFacetForActionAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/execution/ExecutionPublishingFacetForActionAnnotation.java
@@ -63,31 +63,31 @@ public abstract class ExecutionPublishingFacetForActionAnnotation extends Execut
         return
         actionsIfAny
                 .filter(action -> action.executionPublishing() != Publishing.NOT_SPECIFIED)
-        .map(Action::executionPublishing)
-        .<ExecutionPublishingFacet>map(publishing -> {
-            switch (publishing) {
-                case AS_CONFIGURED:
-                    switch (publishingPolicy) {
-                        case NONE:
-                            return new ExecutionPublishingFacetForActionAnnotationAsConfigured.None(holder);
-                        case IGNORE_QUERY_ONLY:
-                        case IGNORE_SAFE:
-                            return hasSafeSemantics(holder)
-                                    ? new ExecutionPublishingFacetForActionAnnotationAsConfigured.IgnoreSafe(holder)
-                                    : new ExecutionPublishingFacetForActionAnnotationAsConfigured.IgnoreSafeYetNot(holder);
-                        case ALL:
-                            return new ExecutionPublishingFacetForActionAnnotationAsConfigured.All(holder);
+                .map(Action::executionPublishing)
+                .<ExecutionPublishingFacet>map(publishing -> {
+                    switch (publishing) {
+                        case AS_CONFIGURED:
+                            switch (publishingPolicy) {
+                                case NONE:
+                                    return new ExecutionPublishingFacetForActionAnnotationAsConfigured.None(holder);
+                                case IGNORE_QUERY_ONLY:
+                                case IGNORE_SAFE:
+                                    return hasSafeSemantics(holder)
+                                            ? new ExecutionPublishingFacetForActionAnnotationAsConfigured.IgnoreSafe(holder)
+                                            : new ExecutionPublishingFacetForActionAnnotationAsConfigured.IgnoreSafeYetNot(holder);
+                                case ALL:
+                                    return new ExecutionPublishingFacetForActionAnnotationAsConfigured.All(holder);
+                                default:
+                                    throw new IllegalStateException(String.format("configured action.executionPublishing policy '%s' not recognised", publishingPolicy));
+                                }
+                        case DISABLED:
+                            return new ExecutionPublishingFacetForActionAnnotation.Disabled(holder);
+                        case ENABLED:
+                            return new ExecutionPublishingFacetForActionAnnotation.Enabled(holder);
                         default:
-                            throw new IllegalStateException(String.format("configured executionPublishing policy '%s' not recognised", publishingPolicy));
-                        }
-                case DISABLED:
-                    return new ExecutionPublishingFacetForActionAnnotation.Disabled(holder);
-                case ENABLED:
-                    return new ExecutionPublishingFacetForActionAnnotation.Enabled(holder);
-                default:
-                    throw new IllegalStateException(String.format("executionPublishing '%s' not recognised", publishing));
-            }
-        });
+                            throw new IllegalStateException(String.format("@Action#executionPublishing '%s' not recognised", publishing));
+                    }
+                });
     }
 
     static boolean hasSafeSemantics(final FacetHolder holder) {
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/execution/ExecutionPublishingFacetForPropertyAnnotation.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/execution/ExecutionPublishingFacetForPropertyAnnotation.java
index ad6bc81f20..a1ac856636 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/execution/ExecutionPublishingFacetForPropertyAnnotation.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/facets/members/publish/execution/ExecutionPublishingFacetForPropertyAnnotation.java
@@ -29,8 +29,6 @@ import org.apache.causeway.core.metamodel.facetapi.FacetHolder;
 import org.apache.causeway.core.metamodel.facetapi.FeatureType;
 import org.apache.causeway.core.metamodel.facets.TypedHolder;
 import org.apache.causeway.core.metamodel.facets.actions.contributing.ContributingFacet;
-import org.apache.causeway.core.metamodel.facets.members.publish.command.CommandPublishingFacetForActionAnnotation;
-import org.apache.causeway.core.metamodel.facets.members.publish.command.CommandPublishingFacetForActionFromConfiguration;
 import org.apache.causeway.core.metamodel.facets.object.mixin.MixinFacet;
 
 import lombok.val;
@@ -87,7 +85,7 @@ extends ExecutionPublishingFacetAbstract {
                     case ENABLED:
                         return new ExecutionPublishingFacetForPropertyAnnotation.Enabled(holder);
                     default:
-                        throw new IllegalStateException(String.format("executionPublishing '%s' not recognised", publishing));
+                        throw new IllegalStateException(String.format("@Property#executionPublishing '%s' not recognised", publishing));
                 }
             })
             .orElseGet(() -> {
@@ -119,8 +117,7 @@ extends ExecutionPublishingFacetAbstract {
                             throw new IllegalStateException(String.format("configured action.executionPublishing policy '%s' not recognised", actionPublishingPolicy));
                     }
                 }
-            }
-        );
+            });
     }
 
     private static boolean representsProperty(FacetHolder holder) {
diff --git a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/actions/action/ActionAnnotationFacetFactoryTest_executionPublishing.java b/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/actions/action/ActionAnnotationFacetFactoryTest_executionPublishing.java
index 21d8efdb33..f5e98c5ece 100644
--- a/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/actions/action/ActionAnnotationFacetFactoryTest_executionPublishing.java
+++ b/core/metamodel/src/test/java/org/apache/causeway/core/metamodel/facets/actions/action/ActionAnnotationFacetFactoryTest_executionPublishing.java
@@ -172,7 +172,7 @@ extends ActionAnnotationFacetFactoryTest {
     }
 
     @Test
-    void given_asConfigured_and_configurationSetToIgnoreQueryOnly_andNoSemantics_thenException() {
+    void given_asConfigured_and_configurationSetToIgnoreQueryOnly_andNoSemantics_thenPublishing() {
 
         class Customer {
             @Action(executionPublishing = org.apache.causeway.applib.annotation.Publishing.AS_CONFIGURED)
@@ -182,8 +182,88 @@ extends ActionAnnotationFacetFactoryTest {
         allowingPublishingConfigurationToReturn(ActionConfigOptions.PublishingPolicy.IGNORE_QUERY_ONLY);
         actionScenario(Customer.class, "someAction", (processMethodContext, facetHolder, facetedMethod)->{
             // when
-            assertThrows(IllegalStateException.class, ()->
-                processExecutionPublishing(facetFactory, processMethodContext));
+            processExecutionPublishing(facetFactory, processMethodContext);
+
+            // then
+            final Facet facet = facetedMethod.getFacet(ExecutionPublishingFacet.class);
+            assertNotNull(facet);
+            assertTrue(ExecutionPublishingFacet.isPublishingEnabled(facetedMethod));
+            assertNoMethodsRemoved();
+        });
+    }
+
+    @Test
+    void given_asConfigured_and_configurationSetToIgnoreQueryOnly_andSafeSemantics_thenNoPublishing() {
+
+        class Customer {
+            @Action(executionPublishing = org.apache.causeway.applib.annotation.Publishing.AS_CONFIGURED)
+            public void someAction() { }
+        }
+
+        allowingPublishingConfigurationToReturn(ActionConfigOptions.PublishingPolicy.IGNORE_QUERY_ONLY);
+        actionScenario(Customer.class, "someAction", (processMethodContext, facetHolder, facetedMethod)->{
+
+            // given
+            facetedMethod.addFacet(new ActionSemanticsFacetAbstract(SemanticsOf.SAFE, facetedMethod) {});
+
+            // when
+            processExecutionPublishing(facetFactory, processMethodContext);
+
+            // then
+            final Facet facet = facetedMethod.getFacet(ExecutionPublishingFacet.class);
+            assertNotNull(facet);
+            assertFalse(ExecutionPublishingFacet.isPublishingEnabled(facetedMethod));
+            assertNoMethodsRemoved();
+        });
+    }
+
+    @Test
+    void given_asConfigured_and_configurationSetToIgnoreQueryOnly_andIdempotentSemantics_thenNoPublishing() {
+
+        class Customer {
+            @Action(executionPublishing = org.apache.causeway.applib.annotation.Publishing.AS_CONFIGURED)
+            public void someAction() { }
+        }
+
+        allowingPublishingConfigurationToReturn(ActionConfigOptions.PublishingPolicy.IGNORE_QUERY_ONLY);
+        actionScenario(Customer.class, "someAction", (processMethodContext, facetHolder, facetedMethod)->{
+
+            // given
+            facetedMethod.addFacet(new ActionSemanticsFacetAbstract(SemanticsOf.IDEMPOTENT, facetedMethod) {});
+
+            // when
+            processExecutionPublishing(facetFactory, processMethodContext);
+
+            // then
+            final Facet facet = facetedMethod.getFacet(ExecutionPublishingFacet.class);
+            assertNotNull(facet);
+            assertTrue(ExecutionPublishingFacet.isPublishingEnabled(facetedMethod));
+            assertNoMethodsRemoved();
+        });
+    }
+
+    @Test
+    void given_asConfigured_and_configurationSetToIgnoreQueryOnly_andNonIdempotentSemantics_thenNoPublishing() {
+
+        class Customer {
+            @Action(executionPublishing = org.apache.causeway.applib.annotation.Publishing.AS_CONFIGURED)
+            public void someAction() { }
+        }
+
+        allowingPublishingConfigurationToReturn(ActionConfigOptions.PublishingPolicy.IGNORE_QUERY_ONLY);
+        actionScenario(Customer.class, "someAction", (processMethodContext, facetHolder, facetedMethod)->{
+
+            // given
+            facetedMethod.addFacet(new ActionSemanticsFacetAbstract(SemanticsOf.IDEMPOTENT, facetedMethod) {});
+
+            // when
+            processExecutionPublishing(facetFactory, processMethodContext);
+
+            // then
+            final Facet facet = facetedMethod.getFacet(ExecutionPublishingFacet.class);
+            assertNotNull(facet);
+            assertTrue(ExecutionPublishingFacet.isPublishingEnabled(facetedMethod));
+            assertNoMethodsRemoved();
         });
     }