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 2020/05/10 19:41:47 UTC

[isis] branch master updated: ISIS-2340: fixes test mockups

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 9576d49  ISIS-2340: fixes test mockups
9576d49 is described below

commit 9576d490ca3513f7e40a59d395436968bd3081a3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sun May 10 21:41:32 2020 +0200

    ISIS-2340: fixes test mockups
---
 .../metamodel/interactions/InteractionContext.java |  9 ++--
 .../WrapperFactoryDefault_wrappedObject_Test.java  | 59 +++++++++++++++-------
 2 files changed, 46 insertions(+), 22 deletions(-)

diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/interactions/InteractionContext.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/interactions/InteractionContext.java
index 1255054..1c12751 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/interactions/InteractionContext.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/interactions/InteractionContext.java
@@ -70,7 +70,7 @@ public abstract class InteractionContext {
      * Model that holds the objects involved with the interaction.
      * @since 2.0
      */
-    @Value(staticConstructor = "of2")
+    @Value(staticConstructor = "unchecked")
     public static class Head {
         /**
          * The owning object that this interaction is associated with.
@@ -85,16 +85,15 @@ public abstract class InteractionContext {
         /** in support of legacy code */
         public static Head of(@NonNull ManagedObject owner, @NonNull ManagedObject target) {
             if(ManagedObject.isSpecified(owner) 
-                    && owner.getSpecification().getBeanSort().isMixin()
-                    && owner.getPojo()==null) {
-                throw _Exceptions.unrecoverableFormatted("owner not spec. %s", owner);
+                    && owner.getSpecification().getBeanSort().isMixin()) {
+                throw _Exceptions.unrecoverableFormatted("unexpected: owner is a mixin %s", owner);
             }
             if(ManagedObject.isSpecified(target)                    
                     && target.getSpecification().getBeanSort().isMixin()
                     && target.getPojo()==null) {
                 throw _Exceptions.unrecoverableFormatted("target not spec. %s", target);
             }
-            return of2(owner, target);
+            return unchecked(owner, target);
         }
         
         /** when owner equals target (no mixin) */
diff --git a/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault_wrappedObject_Test.java b/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault_wrappedObject_Test.java
index 0bd3fbf..68e63b0 100644
--- a/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault_wrappedObject_Test.java
+++ b/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault_wrappedObject_Test.java
@@ -19,10 +19,16 @@
 
 package org.apache.isis.core.runtimeservices.wrapper;
 
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
+import java.util.stream.Stream;
 
 import org.jmock.Expectations;
 import org.jmock.auto.Mock;
@@ -31,11 +37,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
+import org.apache.isis.applib.Identifier;
 import org.apache.isis.applib.services.bookmark.BookmarkService;
 import org.apache.isis.applib.services.command.Command;
 import org.apache.isis.applib.services.command.Command.Executor;
@@ -43,6 +45,7 @@ import org.apache.isis.applib.services.command.CommandContext;
 import org.apache.isis.applib.services.command.CommandExecutorService;
 import org.apache.isis.applib.services.factory.FactoryService;
 import org.apache.isis.applib.services.message.MessageService;
+import org.apache.isis.applib.services.metamodel.BeanSort;
 import org.apache.isis.applib.services.wrapper.DisabledException;
 import org.apache.isis.applib.services.wrapper.HiddenException;
 import org.apache.isis.applib.services.wrapper.InvalidException;
@@ -65,6 +68,7 @@ import org.apache.isis.core.metamodel.facets.properties.update.clear.PropertyCle
 import org.apache.isis.core.metamodel.facets.properties.update.init.PropertyInitializationFacetViaSetterMethod;
 import org.apache.isis.core.metamodel.facets.properties.update.modify.PropertySetterFacetViaModifyMethod;
 import org.apache.isis.core.metamodel.facets.properties.validating.method.PropertyValidateFacetViaMethod;
+import org.apache.isis.core.metamodel.interactions.HidingInteractionAdvisor;
 import org.apache.isis.core.metamodel.objectmanager.ObjectManager;
 import org.apache.isis.core.metamodel.services.command.CommandDtoServiceInternal;
 import org.apache.isis.core.metamodel.spec.ManagedObject;
@@ -116,6 +120,7 @@ public class WrapperFactoryDefault_wrappedObject_Test {
     @Mock private ManagedObject mockEmployeeAdapter;
     @Mock private ManagedObject mockAdapterForStringSmith;
     @Mock private ManagedObject mockAdapterForStringJones;
+    @Mock private Identifier mockId;
 
     private final SimpleSession session = new SimpleSession("tester", Collections.<String>emptyList());
 
@@ -168,12 +173,12 @@ public class WrapperFactoryDefault_wrappedObject_Test {
                 allowing(mockObjectManager).adapt(employeeDO);
                 will(returnValue(mockEmployeeAdapter));
 
-//                allowing(mockEmployeeAdapter).getOid();
-//                will(returnValue(Factory.persistentOf(ObjectSpecId.of("EMP"), "1")));
-
                 allowing(mockEmployeeSpec).isManagedBean();
                 will(returnValue(true));
                 
+                allowing(mockEmployeeSpec).getBeanSort();
+                will(returnValue(BeanSort.ENTITY));
+                
                 allowing(mockEmployeeSpec).isIdentifiable();
                 will(returnValue(true));
                 
@@ -201,9 +206,6 @@ public class WrapperFactoryDefault_wrappedObject_Test {
                 allowing(mockAuthenticationSessionTracker).currentAuthenticationSession();
                 will(returnValue(Optional.of(session)));
 
-//                allowing(mockAdapterManager).adapterFor(employeeDO);
-//                will(returnValue(mockEmployeeAdapter));
-
                 allowing(mockEmployeeAdapter).titleString(null);
                 will(returnValue("titleOf[mockEmployeeAdapter]"));
                 
@@ -315,11 +317,18 @@ public class WrapperFactoryDefault_wrappedObject_Test {
             allowing(mockAdapterForStringSmith).getSpecification();
             will(returnValue(mockStringSpec));
 
-            ignoring(mockStringSpec);
-
-//            allowing(mockAdapterForStringSmith).isDestroyed();
-//            will(returnValue(false));
-
+            allowing(mockStringSpec).isEntity();
+            will(returnValue(false));
+            
+            allowing(mockStringSpec).getIdentifier();
+            will(returnValue(mockId));
+            
+            allowing(mockStringSpec).getBeanSort();
+            will(returnValue(BeanSort.VIEW_MODEL));
+            
+            allowing(mockStringSpec).streamFacets(HidingInteractionAdvisor.class);
+            will(returnValue(Stream.empty()));
+            
             allowing(mockObjectManager).adapt("Smith");
             will(returnValue(mockAdapterForStringSmith));
         }});
@@ -356,7 +365,23 @@ public class WrapperFactoryDefault_wrappedObject_Test {
 
                 ignoring(mockCommand);
 
-                ignoring(mockStringSpec);
+                //ignoring(mockStringSpec);
+                
+                allowing(mockStringSpec).isParented();
+                will(returnValue(false));
+                
+                allowing(mockStringSpec).isEntity();
+                will(returnValue(false));
+                
+                allowing(mockStringSpec).getIdentifier();
+                will(returnValue(mockId));
+                
+                allowing(mockStringSpec).getBeanSort();
+                will(returnValue(BeanSort.VIEW_MODEL));
+                
+                allowing(mockStringSpec).streamFacets(HidingInteractionAdvisor.class);
+                will(returnValue(Stream.empty()));
+                
             }
         });