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/06/30 13:32:43 UTC

[isis] branch master updated: ISIS-1720: adds some wrapper interaction tests with abstract mixins

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 238d415  ISIS-1720: adds some wrapper interaction tests with abstract mixins
238d415 is described below

commit 238d4152b107a67d9a79cecd13554e8326ffb7d4
Author: andi-huber <ah...@apache.org>
AuthorDate: Wed Jun 30 15:32:30 2021 +0200

    ISIS-1720: adds some wrapper interaction tests with abstract mixins
---
 .../interact/WrapperInteractionTest.java           | 148 +++++++++++++++++++++
 1 file changed, 148 insertions(+)

diff --git a/regressiontests/stable-interact/src/test/java/org/apache/isis/testdomain/interact/WrapperInteractionTest.java b/regressiontests/stable-interact/src/test/java/org/apache/isis/testdomain/interact/WrapperInteractionTest.java
new file mode 100644
index 0000000..9abdce8
--- /dev/null
+++ b/regressiontests/stable-interact/src/test/java/org/apache/isis/testdomain/interact/WrapperInteractionTest.java
@@ -0,0 +1,148 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.testdomain.interact;
+
+import javax.inject.Inject;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+
+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.core.config.presets.IsisPresets;
+import org.apache.isis.core.metamodel.facets.all.named.MemberNamedFacet;
+import org.apache.isis.core.metamodel.spec.feature.MixedIn;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
+import org.apache.isis.testdomain.conf.Configuration_headless;
+import org.apache.isis.testdomain.model.interaction.Configuration_usingInteractionDomain;
+import org.apache.isis.testdomain.model.interaction.InteractionDemo;
+import org.apache.isis.testdomain.model.interaction.InteractionDemo_biArgEnabled;
+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,
+                WrapperInteractionTest.Customer.class,
+                WrapperInteractionTest.ConcreteMixin.class,
+                WrapperInteractionTest.ConcreteMixin2.class,
+        }
+)
+@TestPropertySource({
+    IsisPresets.SilenceMetaModel,
+    IsisPresets.SilenceProgrammingModel
+})
+class WrapperInteractionTest
+extends InteractionTestAbstract {
+
+    @Data @DomainObject(nature = Nature.VIEW_MODEL)
+    static class Customer {
+        String name;
+        @Action public String who() { return name; }
+    }
+
+    // an abstract mixin class
+    static abstract class MixinAbstract<T extends Object> {
+        public T act(String startTime, String endTime) {
+            return null;
+        }
+    }
+
+    @Action
+    @RequiredArgsConstructor
+    public static class ConcreteMixin
+    extends MixinAbstract<String> {
+        @SuppressWarnings("unused")
+        private final Customer mixee;
+        @Override
+        public String act(String startTime, String endTime) {
+            return "acted";
+        }
+    }
+
+    @Action
+    @RequiredArgsConstructor
+    public static class ConcreteMixin2
+    extends MixinAbstract<String> {
+        @SuppressWarnings("unused")
+        private final Customer mixee;
+
+        @Override
+        public String act(String startTime, String endTime) {
+            return "acted2";
+        }
+    }
+
+    @Inject SpecificationLoader specificationLoader;
+
+    @Test
+    void mixinMemberNamedFacet_whenSharingSameAbstractMixin() {
+        val objectSpec = specificationLoader.specForType(Customer.class).get();
+
+        assertEquals(
+                2L,
+                objectSpec.streamRuntimeActions(MixedIn.INCLUDED)
+                .filter(ObjectAction::isMixedIn)
+                .peek(act->{
+                    //System.out.println("act: " + act);
+                    val memberNamedFacet = act.getFacet(MemberNamedFacet.class);
+                    assertNotNull(memberNamedFacet);
+                    assertTrue(memberNamedFacet.getSpecialization().isLeft());
+                })
+                .count());
+    }
+
+    @Test
+    void mixinActionValidation() {
+        InvalidException cause = assertThrows(InvalidException.class, ()-> {
+            wrapMixin(ConcreteMixin.class, new Customer()).act(null, "17:00");
+        });
+        assertEquals("'Start Time' is mandatory", cause.getMessage());
+
+        InvalidException cause2 = assertThrows(InvalidException.class, ()-> {
+            wrapMixin(ConcreteMixin2.class, new Customer()).act(null, "17:00");
+        });
+        assertEquals("'Start Time' is mandatory", cause2.getMessage());
+    }
+
+    @Test
+    void regularPropertyAccess() {
+        assertEquals("initial", wrapper.wrap(new InteractionDemo()).getString2());
+    }
+
+    @Test
+    void mixinActionAccess() {
+        assertEquals(3, wrapper.wrapMixin(InteractionDemo_biArgEnabled.class, new InteractionDemo()).act(1, 2));
+    }
+
+
+}