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 2015/04/23 15:36:27 UTC

[17/20] isis git commit: ISIS-1129: updating documentation on usage of SudoService.

ISIS-1129: updating documentation on usage of SudoService.


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

Branch: refs/heads/master
Commit: 0f7022b4ccc70f104e70ccf730f61382c3107a32
Parents: 9ae8002
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Thu Apr 23 12:57:38 2015 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Thu Apr 23 12:57:38 2015 +0100

----------------------------------------------------------------------
 adocs/documentation/README.md                   | 16 ++++++
 .../asciidoc/user-guide/user-guide-testing.adoc | 52 ++++++++++++++++++++
 2 files changed, 68 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/0f7022b4/adocs/documentation/README.md
----------------------------------------------------------------------
diff --git a/adocs/documentation/README.md b/adocs/documentation/README.md
index 1233a23..00b381d 100644
--- a/adocs/documentation/README.md
+++ b/adocs/documentation/README.md
@@ -39,6 +39,22 @@ Put the following information in your ~/.m2/settings.xml file
     </server>
 
 
+Build and Review
+----------------
+
+To build the documentation locally, simply use:
+
+    mvn site
+
+The site will be generated at `target/site/index.html`.
+
+To review, recommend running a Python server:
+
+    cd target/site
+    python -m SimpleHTTPServer
+    
+Then open the browser on [localhost:8000](http://localhost:8000/).
+
 Publish procedure
 -----------------
 

http://git-wip-us.apache.org/repos/asf/isis/blob/0f7022b4/adocs/documentation/src/main/asciidoc/user-guide/user-guide-testing.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/user-guide/user-guide-testing.adoc b/adocs/documentation/src/main/asciidoc/user-guide/user-guide-testing.adoc
index e4d69b5..d7be033 100644
--- a/adocs/documentation/src/main/asciidoc/user-guide/user-guide-testing.adoc
+++ b/adocs/documentation/src/main/asciidoc/user-guide/user-guide-testing.adoc
@@ -15,6 +15,58 @@ IMPORTANT: TODO
 
 ## SudoService (1.9.0-SNAPSHOT)
 
+Sometimes in our fixture scripts we want to perform a business action runnin as a particular user.  This might be for the usual reason - so that our fixtures accurately reflect the reality of the system with all business constraints enforced using the `WrapperFactory` - or more straightforwardly it might be simply that the action depends on the identity of the user invoking the action.
+
+An example of the latter case is in the link:[todoapp]'s `ToDoItem` class:
+
+[source,java]
+.Production code that depends on current user
+----
+public ToDoItem newToDo(
+        @Parameter(regexPattern = "\\w[@&:\\-\\,\\.\\+ \\w]*") @ParameterLayout(named="Description")
+        final String description,
+        @ParameterLayout(named="Category")
+        final Category category,
+        @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named="Subcategory")
+        final Subcategory subcategory,
+        @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named="Due by")
+        final LocalDate dueBy,
+        @Parameter(optionality = Optionality.OPTIONAL) @ParameterLayout(named="Cost")
+        final BigDecimal cost) {
+    return newToDo(description, category, subcategory, currentUserName(), dueBy, cost);
+}
+private String currentUserName() {
+    return container.getUser().getName(); // <1>
+}
+----
+<1> is the current user.
+
+The fixture for this can use the `SudoService` to run a block of code as a specified user:
+
+[source,java]
+.Fixture Script
+----
+final String description = ...
+final Category category = ...
+final Subcategory subcategory = ...
+final LocalDate dueBy = ...
+final BigDecimal cost = ...
+final Location location = ...
+
+toDoItem = sudoService.sudo(username,
+        new Callable<ToDoItem>() {
+            @Override
+            public ToDoItem call() {
+                final ToDoItem toDoItem = wrap(toDoItems).newToDo(
+                        description, category, subcategory, dueBy, cost);
+                wrap(toDoItem).setLocation(location);
+                return toDoItem;
+            }
+        });
+----
+
+Behind the scenes the `SudoService` simply talks to the `DomainObjectContainer` to override the user returned by the `getUser()` API.  It is possible to override both users and roles.
+
 ## IsisConfigurationForJdoIntegTests
 
 ## Isis CmdLine Arguments (for prototyping)