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 2013/07/14 14:46:55 UTC

git commit: ISIS-463: reworking the provision of WrapperFactory...

Updated Branches:
  refs/heads/master 880644265 -> 9a9f55e6e


ISIS-463: reworking the provision of WrapperFactory...

... in specs/integ tests.  Was broken, basically.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/9a9f55e6
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/9a9f55e6
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/9a9f55e6

Branch: refs/heads/master
Commit: 9a9f55e6e660d868055ae982cfbbf4facb367a93
Parents: 8806442
Author: Dan Haywood <da...@apache.org>
Authored: Sun Jul 14 13:37:14 2013 +0100
Committer: Dan Haywood <da...@apache.org>
Committed: Sun Jul 14 13:37:14 2013 +0100

----------------------------------------------------------------------
 .../ScenarioExecutionForIntegration.java        |   5 +-
 .../scenarios/DomainServiceProviderMockery.java | 107 +++++++++++++++++++
 .../scenarios/ScenarioExecution.java            |  15 ++-
 .../scenarios/ScenarioExecutionForUnit.java     |  97 ++---------------
 4 files changed, 123 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/9a9f55e6/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ScenarioExecutionForIntegration.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ScenarioExecutionForIntegration.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ScenarioExecutionForIntegration.java
index f25f903..6e822ac 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ScenarioExecutionForIntegration.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/scenarios/ScenarioExecutionForIntegration.java
@@ -39,15 +39,14 @@ public class ScenarioExecutionForIntegration extends ScenarioExecution  {
     private IsisSystemForTest isft;
 
     public ScenarioExecutionForIntegration() {
-        super(IsisSystemForTest.get(), new WrapperFactoryDefault());
+        super(IsisSystemForTest.get());
         this.isft = (IsisSystemForTest) dsp;
     }
 
     // //////////////////////////////////////
 
-    private WrapperFactory wrapperFactory = new WrapperFactoryDefault();
     public WrapperFactory wrapperFactory() {
-        return wrapperFactory;
+        return service(WrapperFactory.class);
     }
 
     // //////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/isis/blob/9a9f55e6/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/DomainServiceProviderMockery.java
----------------------------------------------------------------------
diff --git a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/DomainServiceProviderMockery.java b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/DomainServiceProviderMockery.java
new file mode 100644
index 0000000..5b639c9
--- /dev/null
+++ b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/DomainServiceProviderMockery.java
@@ -0,0 +1,107 @@
+/**
+ *  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.core.specsupport.scenarios;
+
+import java.util.Map;
+
+import com.google.common.collect.Maps;
+
+import org.hamcrest.Description;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.api.Action;
+import org.jmock.api.Invocation;
+import org.jmock.lib.legacy.ClassImposteriser;
+
+import org.apache.isis.applib.DomainObjectContainer;
+
+class DomainServiceProviderMockery implements DomainServiceProvider {
+
+    private DomainObjectContainer mockContainer = null;
+    private final Map<Class<?>, Object> mocks = Maps.newHashMap();
+    
+    private Mockery context;
+
+    private ScenarioExecution scenarioExecution;
+
+    DomainServiceProviderMockery() {
+        init();
+    }
+
+    private void init() {
+        context = new Mockery() {{
+            setImposteriser(ClassImposteriser.INSTANCE);
+        }};
+        mocks.clear();
+    }
+
+    @Override
+    public DomainObjectContainer getContainer() {
+        if(mockContainer == null) {
+            mockContainer = getService(DomainObjectContainer.class);
+            context.checking(new Expectations() {
+                {
+                    allowing(mockContainer).newTransientInstance(with(Expectations.<Class<?>>anything()));
+                    will(new Action() {
+                        
+                        @SuppressWarnings("rawtypes")
+                        public Object invoke(Invocation invocation) throws Throwable {
+                            Class cls = (Class) invocation.getParameter(0);
+                            return scenarioExecution.injectServices(cls.newInstance());
+                        }
+                        
+                        public void describeTo(Description description) {
+                            description.appendText("newTransientInstance");
+                        }
+                    });
+                    
+                    allowing(mockContainer).persistIfNotAlready(with(anything()));
+                }
+            });
+        }
+        return mockContainer;
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T> T getService(Class<T> serviceClass) {
+        Object mock = mocks.get(serviceClass);
+        if(mock == null) {
+            mock = context.mock(serviceClass);
+        }
+        mocks.put(serviceClass, mock);
+        return (T) mock;
+    }
+    
+    public Mockery mockery() {
+        return context;
+    }
+
+    DomainServiceProviderMockery init(ScenarioExecution scenarioExecution) {
+        this.scenarioExecution = scenarioExecution;
+        return this;
+    }
+
+    /**
+     * not API 
+     */
+    void assertIsSatisfied() {
+        mockery().assertIsSatisfied();
+        // discard all existing mocks and mockery, to start again.
+        init();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/9a9f55e6/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
----------------------------------------------------------------------
diff --git a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
index f39fef2..61cd893 100644
--- a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
+++ b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecution.java
@@ -72,11 +72,9 @@ public abstract class ScenarioExecution {
     // //////////////////////////////////////
 
     protected final DomainServiceProvider dsp;
-    private WrapperFactory wrapperFactory;
     
-    protected ScenarioExecution(final DomainServiceProvider dsp, final WrapperFactory wrapperFactory) {
+    protected ScenarioExecution(final DomainServiceProvider dsp) {
         this.dsp = dsp;
-        this.wrapperFactory = wrapperFactory;
         current.set(this);
     }
 
@@ -86,11 +84,7 @@ public abstract class ScenarioExecution {
      * 
      * @throws IllegalStateException if not available
      */
-    @SuppressWarnings("unchecked")
     public <T> T service(Class<T> cls) {
-        if(WrapperFactory.class.isAssignableFrom(cls)) {
-            return (T) wrapperFactory();
-        }
         final T service = dsp.getService(cls);
         if(service == null) {
             throw new IllegalStateException(
@@ -117,8 +111,13 @@ public abstract class ScenarioExecution {
     }
 
     
+    /**
+     * Returns the  {@link WrapperFactory} if one {@link #service(Class) is available}, 
+     * otherwise returns a {@link WrapperFactory#NOOP no-op} implementation.
+     */
     public WrapperFactory wrapperFactory() {
-        return wrapperFactory;
+        final WrapperFactory wrapperFactory = dsp.getService(WrapperFactory.class);
+        return wrapperFactory != null? wrapperFactory: WrapperFactory.NOOP;
     }
 
 

http://git-wip-us.apache.org/repos/asf/isis/blob/9a9f55e6/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecutionForUnit.java
----------------------------------------------------------------------
diff --git a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecutionForUnit.java b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecutionForUnit.java
index 6d35214..d29b3ce 100644
--- a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecutionForUnit.java
+++ b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/ScenarioExecutionForUnit.java
@@ -16,21 +16,11 @@
  */
 package org.apache.isis.core.specsupport.scenarios;
 
-import java.util.Map;
-
-import com.google.common.collect.Maps;
-
-import org.hamcrest.Description;
-import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.jmock.Sequence;
 import org.jmock.States;
-import org.jmock.api.Action;
-import org.jmock.api.Invocation;
 import org.jmock.internal.ExpectationBuilder;
-import org.jmock.lib.legacy.ClassImposteriser;
 
-import org.apache.isis.applib.DomainObjectContainer;
 import org.apache.isis.applib.services.wrapper.WrapperFactory;
 import org.apache.isis.core.wrapper.WrapperFactoryDefault;
 
@@ -45,96 +35,23 @@ import org.apache.isis.core.wrapper.WrapperFactoryDefault;
  */
 public class ScenarioExecutionForUnit extends ScenarioExecution {
 
-    private static class DomainServiceProviderMockery implements DomainServiceProvider {
-
-        private DomainObjectContainer mockContainer = null;
-        private final Map<Class<?>, Object> mocks = Maps.newHashMap();
-        
-        private Mockery context;
-
-        private ScenarioExecution scenarioExecution;
-
-        DomainServiceProviderMockery() {
-            init();
-        }
-
-        private void init() {
-            context = new Mockery() {{
-                setImposteriser(ClassImposteriser.INSTANCE);
-            }};
-            mocks.clear();
-        }
-
-        @Override
-        public DomainObjectContainer getContainer() {
-            if(mockContainer == null) {
-                mockContainer = getService(DomainObjectContainer.class);
-                context.checking(new Expectations() {
-                    {
-                        allowing(mockContainer).newTransientInstance(with(Expectations.<Class<?>>anything()));
-                        will(new Action() {
-                            
-                            @SuppressWarnings("rawtypes")
-                            public Object invoke(Invocation invocation) throws Throwable {
-                                Class cls = (Class) invocation.getParameter(0);
-                                return scenarioExecution.injectServices(cls.newInstance());
-                            }
-                            
-                            public void describeTo(Description description) {
-                                description.appendText("newTransientInstance");
-                            }
-                        });
-                        
-                        allowing(mockContainer).persistIfNotAlready(with(anything()));
-                    }
-                });
-            }
-            return mockContainer;
-        }
-
-        @SuppressWarnings("unchecked")
-        @Override
-        public <T> T getService(Class<T> serviceClass) {
-            Object mock = mocks.get(serviceClass);
-            if(mock == null) {
-                mock = context.mock(serviceClass);
-            }
-            mocks.put(serviceClass, mock);
-            return (T) mock;
-        }
-        
-        public Mockery mockery() {
-            return context;
-        }
-
-        private DomainServiceProviderMockery init(ScenarioExecution scenarioExecution) {
-            this.scenarioExecution = scenarioExecution;
-            return this;
-        }
-
-        /**
-         * not API 
-         */
-        void assertIsSatisfied() {
-            mockery().assertIsSatisfied();
-            // discard all existing mocks and mockery, to start again.
-            init();
-        }
-    }
-
-    private final ScenarioExecutionForUnit.DomainServiceProviderMockery dspm;
+    private final DomainServiceProviderMockery dspm;
     
     public ScenarioExecutionForUnit() {
         this(new DomainServiceProviderMockery());
     }
-    private ScenarioExecutionForUnit(ScenarioExecutionForUnit.DomainServiceProviderMockery dspm) {
-        super(dspm, WrapperFactory.NOOP);
+    private ScenarioExecutionForUnit(DomainServiceProviderMockery dspm) {
+        super(dspm);
         this.dspm = dspm.init(this);
     }
 
 
     // //////////////////////////////////////
 
+    /**
+     * Sets up an expectation against the underlying JMock {@link Mockery} 
+     * (as wrapped by {@link DomainServiceProviderMockery}).
+     */
     public void checking(ExpectationBuilder expectations) {
         dspm.mockery().checking(expectations);
     }