Change Diff API
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 6 Sep 2012 13:37:17 +0000 (13:37 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 6 Sep 2012 13:37:17 +0000 (13:37 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@5565 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/JcrTestResult.java
runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/diff/Diff.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/diff/DiffResult.java [new file with mode: 0644]

index 66b658b750e06dd786c90f3681ab1461b1ab6551..3006266f3ceb6a93c0e42715f5216070663a5213 100644 (file)
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
+import javax.jcr.Credentials;
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
@@ -47,18 +48,21 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled {
        private String uuid;
        private Repository repository;
        private Session session;
+       /**
+        * For testing purposes, best practice is to not set them explicitely but
+        * via other mechanisms such as JAAS or SPring Security.
+        */
+       private Credentials credentials = null;
        private String resultType = SlcTypes.SLC_TEST_RESULT;
 
        /** cached for performance purposes */
        private String nodeIdentifier = null;
 
-       private Boolean logoutWhenDestroyed = true;
-
        private Map<String, String> attributes = new HashMap<String, String>();
 
        public void init() {
                try {
-                       session = repository.login();
+                       session = repository.login(credentials);
                        if (uuid == null) {
                                // create new result
                                uuid = UUID.randomUUID().toString();
@@ -83,8 +87,7 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled {
        }
 
        public void destroy() {
-               if (logoutWhenDestroyed)
-                       JcrUtils.logoutQuietly(session);
+               JcrUtils.logoutQuietly(session);
        }
 
        public Node getNode() {
@@ -141,6 +144,7 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled {
                }
        }
 
+       /** JCR session is NOT logged out */
        public void close() {
                Node node = getNode();
                try {
@@ -153,8 +157,6 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled {
                        JcrUtils.discardUnderlyingSessionQuietly(node);
                        throw new SlcException("Cannot get close date from " + node, e);
                }
-               if (logoutWhenDestroyed)
-                       JcrUtils.logoutQuietly(session);
        }
 
        public Date getCloseDate() {
@@ -208,6 +210,10 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled {
                this.attributes = attributes;
        }
 
+       public void setCredentials(Credentials credentials) {
+               this.credentials = credentials;
+       }
+
        // public void setLogoutWhenDestroyed(Boolean logoutWhenDestroyed) {
        // this.logoutWhenDestroyed = logoutWhenDestroyed;
        // }
index 52931218bcbe1c15142c9ec4744b16c6b55c9304..af7385000ffdb76e715ad0b4c28a84d6319b4764 100644 (file)
@@ -89,9 +89,12 @@ public class SlcJcrUtils implements SlcNames {
        public static String createResultPath(Session session, String uuid)
                        throws RepositoryException {
                Calendar now = new GregorianCalendar();
-               return UserJcrUtils.getUserHome(session).getPath() + '/'
-                               + SlcNames.SLC_RESULTS + '/' + JcrUtils.dateAsPath(now, true)
-                               + uuid;
+               Node userHome = UserJcrUtils.getUserHome(session);
+               if (userHome == null)
+                       throw new SlcException("No user home available for "
+                                       + session.getUserID());
+               return userHome.getPath() + '/' + SlcNames.SLC_RESULTS + '/'
+                               + JcrUtils.dateAsPath(now, true) + uuid;
        }
 
        /**
index 7e610cdf85793a0670616137978562f2a7380b97..f369ad8a8508fb743651343dabae6f50dfe44c0e 100644 (file)
@@ -18,7 +18,8 @@ package org.argeo.slc.diff;
 import org.springframework.core.io.Resource;\r
 \r
 /** A comparator providing structured information about the differences found. */\r
-public interface Diff<T> {\r
+public interface Diff {\r
        /** Performs the comparison. */\r
-       public T compare(Resource expected, Resource reached);\r
+       public void compare(Resource expected, Resource reached,\r
+                       DiffResult diffResult);\r
 }\r
diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/diff/DiffResult.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/diff/DiffResult.java
new file mode 100644 (file)
index 0000000..8c0f9e2
--- /dev/null
@@ -0,0 +1,10 @@
+package org.argeo.slc.diff;
+
+/**
+ * The result of a diff, to be subclassed in order to provide richer information
+ */
+public interface DiffResult {
+       /** Adds a diff issue */
+       public void addDiffIssue(DiffIssue diffIssue);
+
+}