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 2014/12/19 09:07:26 UTC

[03/11] isis git commit: ISIS-928: minor incidental changes to the todoapp (additional tests)

ISIS-928: minor incidental changes to the todoapp (additional tests)


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

Branch: refs/heads/master
Commit: f4197f196fbe10a8c3b12cc1bacaa8371590d09f
Parents: a1529f7
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Dec 18 08:53:48 2014 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Dec 19 06:22:43 2014 +0000

----------------------------------------------------------------------
 .../dom/src/main/java/dom/todo/ToDoItem.java    | 34 ++++++++++-----
 .../src/test/java/dom/todo/ToDoItemTest.java    | 46 ++++++++++++++++++--
 .../integration/glue/todoitem/ToDoItemGlue.java |  4 +-
 3 files changed, 67 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/f4197f19/example/application/todoapp/dom/src/main/java/dom/todo/ToDoItem.java
----------------------------------------------------------------------
diff --git a/example/application/todoapp/dom/src/main/java/dom/todo/ToDoItem.java b/example/application/todoapp/dom/src/main/java/dom/todo/ToDoItem.java
index 2c79aee..1fff120 100644
--- a/example/application/todoapp/dom/src/main/java/dom/todo/ToDoItem.java
+++ b/example/application/todoapp/dom/src/main/java/dom/todo/ToDoItem.java
@@ -182,6 +182,14 @@ public class ToDoItem implements Categorized, Comparable<ToDoItem> {
         return dueBy;
     }
 
+    /**
+     * Demonstrates how to perform security checks within the domain code.
+     *
+     * <p>
+     *     Generally speaking this approach is not recommended; such checks should
+     *     wherever possible be externalized in the security subsystem.
+     * </p>
+     */
     public boolean hideDueBy() {
         final UserMemento user = container.getUser();
         return user.hasRole("realm1:noDueBy_role");
@@ -903,26 +911,28 @@ public class ToDoItem implements Categorized, Comparable<ToDoItem> {
 
     //region > injected services
     @javax.inject.Inject
-    private DomainObjectContainer container;
+    DomainObjectContainer container;
 
     @javax.inject.Inject
-    private ToDoItems toDoItems;
+    ToDoItems toDoItems;
 
-    Bulk.InteractionContext bulkInteractionContext;
-    public void injectBulkInteractionContext(Bulk.InteractionContext bulkInteractionContext) {
-        this.bulkInteractionContext = bulkInteractionContext;
-    }
+    @javax.inject.Inject
+    Scratchpad scratchpad;
 
+    /**
+     * public only so can be injected from integ tests
+     */
     @javax.inject.Inject
-    private Scratchpad scratchpad;
+    public Bulk.InteractionContext bulkInteractionContext;
 
-    EventBusService eventBusService;
-    public void injectEventBusService(EventBusService eventBusService) {
-        this.eventBusService = eventBusService;
-    }
+    /**
+     * public only so can be injected from integ tests
+     */
+    @javax.inject.Inject
+    public EventBusService eventBusService;
 
     @javax.inject.Inject
-    private WrapperFactory wrapperFactory;
+    WrapperFactory wrapperFactory;
 
     //endregion
 

http://git-wip-us.apache.org/repos/asf/isis/blob/f4197f19/example/application/todoapp/dom/src/test/java/dom/todo/ToDoItemTest.java
----------------------------------------------------------------------
diff --git a/example/application/todoapp/dom/src/test/java/dom/todo/ToDoItemTest.java b/example/application/todoapp/dom/src/test/java/dom/todo/ToDoItemTest.java
index 63512c1..a9c102c 100644
--- a/example/application/todoapp/dom/src/test/java/dom/todo/ToDoItemTest.java
+++ b/example/application/todoapp/dom/src/test/java/dom/todo/ToDoItemTest.java
@@ -16,11 +16,15 @@
  */
 package dom.todo;
 
+import org.jmock.Expectations;
 import org.jmock.auto.Mock;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.apache.isis.applib.DomainObjectContainer;
 import org.apache.isis.applib.annotation.Bulk;
+import org.apache.isis.applib.security.RoleMemento;
+import org.apache.isis.applib.security.UserMemento;
 import org.apache.isis.applib.services.eventbus.EventBusService;
 import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
 import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2.Mode;
@@ -50,9 +54,45 @@ public abstract class ToDoItemTest {
         context.ignoring(eventBusService);
     }
 
-    public static class Actions {
+    public static class Properties extends ToDoItemTest {
 
-        public static class Completed extends ToDoItemTest {
+        @Mock
+        DomainObjectContainer mockContainer;
+
+        public static class DueBy extends Properties {
+
+            @Test
+            public void hiddenForNoDueByRole() {
+                final UserMemento userWithRole = new UserMemento("user", new RoleMemento("realm1:noDueBy_role"));
+                context.checking(new Expectations() {{
+                    allowing(mockContainer).getUser();
+                    will(returnValue(userWithRole));
+                }});
+
+                toDoItem.container = mockContainer;
+
+                assertThat(toDoItem.hideDueBy(), is(true));
+            }
+
+            @Test
+            public void notHiddenWithoutRole() {
+                final UserMemento userWithRole = new UserMemento("user", new RoleMemento("realm1:someOtherRole"));
+                context.checking(new Expectations() {{
+                    allowing(mockContainer).getUser();
+                    will(returnValue(userWithRole));
+                }});
+
+                toDoItem.container = mockContainer;
+
+                assertThat(toDoItem.hideDueBy(), is(false));
+            }
+        }
+
+    }
+
+    public static class Actions extends ToDoItemTest {
+
+        public static class Completed extends Actions {
 
             @Test
             public void happyCase() throws Exception {
@@ -70,7 +110,7 @@ public abstract class ToDoItemTest {
             }
         }
 
-        public static class NotYetCompleted extends ToDoItemTest {
+        public static class NotYetCompleted extends Actions {
 
             @Test
             public void happyCase() throws Exception {

http://git-wip-us.apache.org/repos/asf/isis/blob/f4197f19/example/application/todoapp/integtests/src/test/java/integration/glue/todoitem/ToDoItemGlue.java
----------------------------------------------------------------------
diff --git a/example/application/todoapp/integtests/src/test/java/integration/glue/todoitem/ToDoItemGlue.java b/example/application/todoapp/integtests/src/test/java/integration/glue/todoitem/ToDoItemGlue.java
index 1997ce1..0782e38 100644
--- a/example/application/todoapp/integtests/src/test/java/integration/glue/todoitem/ToDoItemGlue.java
+++ b/example/application/todoapp/integtests/src/test/java/integration/glue/todoitem/ToDoItemGlue.java
@@ -80,8 +80,8 @@ public class ToDoItemGlue extends CukeGlueAbstract {
                     allowing(eventBusService);
                 }
             });
-            toDoItem.injectBulkInteractionContext(bulkInteractionContext);
-            toDoItem.injectEventBusService(eventBusService);
+            toDoItem.bulkInteractionContext = bulkInteractionContext;
+            toDoItem.eventBusService = eventBusService;
         }
         wrap(toDoItem).completed();
     }