]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Improve JCR
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 5 Oct 2011 15:11:59 +0000 (15:11 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 5 Oct 2011 15:11:59 +0000 (15:11 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@4802 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/test/TestStatus.java
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.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java
runtime/org.argeo.slc.support.jcr/src/main/resources/org/argeo/slc/jcr/slc.cnd

index d353c32e7c83107af17ce7d611188adb4f22e413..d4e91e46318c5d59c837d58516b142c1d095e1b6 100644 (file)
@@ -17,7 +17,9 @@
 package org.argeo.slc.test;\r
 \r
 /**\r
- * Simple statuses.\r
+ * Simple statuses. Ordering of the flags can be relied upon in aggregation: if\r
+ * one element is failed, the aggregation is failed. Is one element is in ERROR,\r
+ * the aggregation is in ERROR.\r
  * <p>\r
  * <ul>\r
  * <li>{@link #PASSED}: the test succeeded</li>\r
index 74a31678df4dcce1d5f490491d990571431303fa..ea2495e3ec19889708ae2bceacf9a75a3fc6a3d9 100644 (file)
@@ -30,6 +30,8 @@ public class JcrTestResult implements TestResult, SlcNames {
        /** cached for performance purposes */
        private String nodeIdentifier = null;
 
+       private Map<String, String> attributes = new HashMap<String, String>();
+
        public void init() {
                try {
                        if (uuid == null) {
@@ -38,6 +40,15 @@ public class JcrTestResult implements TestResult, SlcNames {
                                String path = SlcJcrUtils.createResultPath(uuid);
                                Node resultNode = JcrUtils.mkdirs(session, path, resultType);
                                resultNode.setProperty(SLC_UUID, uuid);
+                               for (String attr : attributes.keySet()) {
+                                       String property = attr;
+                                       // compatibility with legacy applications
+                                       if ("testCase".equals(attr))
+                                               property = SLC_TEST_CASE;
+                                       else if ("testCaseType".equals(attr))
+                                               property = SLC_TEST_CASE_TYPE;
+                                       resultNode.setProperty(property, attributes.get(attr));
+                               }
                                session.save();
                        }
                } catch (Exception e) {
@@ -158,4 +169,12 @@ public class JcrTestResult implements TestResult, SlcNames {
                this.resultType = resultType;
        }
 
+       public void setAttributes(Map<String, String> attributes) {
+               if (uuid != null)
+                       throw new SlcException(
+                                       "Attributes cannot be set on an already initialized test result."
+                                                       + " Update the related JCR node directly instead.");
+               this.attributes = attributes;
+       }
+
 }
index c3cdda7573e421dd7b2408c6775628d8b5fa40c4..793670e7c1b1b235db6c5fc703cd09072250fa8b 100644 (file)
@@ -4,6 +4,7 @@ import java.util.Calendar;
 import java.util.GregorianCalendar;
 
 import javax.jcr.Node;
+import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 
 import org.argeo.jcr.JcrUtils;
@@ -11,12 +12,13 @@ import org.argeo.slc.SlcException;
 import org.argeo.slc.core.execution.PrimitiveAccessor;
 import org.argeo.slc.core.execution.PrimitiveUtils;
 import org.argeo.slc.deploy.ModuleDescriptor;
+import org.argeo.slc.test.TestStatus;
 
 /**
  * Utilities around the SLC JCR model. Note that it relies on fixed base paths
  * (convention over configuration) for optimization purposes.
  */
-public class SlcJcrUtils {
+public class SlcJcrUtils implements SlcNames {
        public final static Integer AGENT_FACTORY_DEPTH = 3;
 
        /** Extracts the path of a flow relative to its execution module */
@@ -114,6 +116,65 @@ public class SlcJcrUtils {
                }
        }
 
+       /** Aggregates the {@link TestStatus} of this sub-tree. */
+       public static Integer aggregateTestStatus(Node node) {
+               try {
+                       Integer status = TestStatus.PASSED;
+                       if (node.isNodeType(SlcTypes.SLC_CHECK))
+                               if (node.getProperty(SLC_SUCCESS).getBoolean())
+                                       status = TestStatus.PASSED;
+                               else if (node.hasProperty(SLC_ERROR_MESSAGE))
+                                       status = TestStatus.ERROR;
+                               else
+                                       status = TestStatus.FAILED;
+
+                       NodeIterator it = node.getNodes();
+                       while (it.hasNext()) {
+                               Integer childStatus = aggregateTestStatus(it.nextNode());
+                               if (childStatus > status)
+                                       status = childStatus;
+                       }
+                       return status;
+               } catch (Exception e) {
+                       throw new SlcException("Could not aggregate test status from "
+                                       + node, e);
+               }
+       }
+
+       /**
+        * Aggregates the {@link TestStatus} of this sub-tree.
+        * 
+        * @return the same {@link StringBuffer}, for convenience (typically calling
+        *         toString() on it)
+        */
+       public static StringBuffer aggregateTestMessages(Node node,
+                       StringBuffer messages) {
+               try {
+                       if (node.isNodeType(SlcTypes.SLC_CHECK)) {
+                               if (node.hasProperty(SLC_MESSAGE)) {
+                                       if (messages.length() > 0)
+                                               messages.append('\n');
+                                       messages.append(node.getProperty(SLC_MESSAGE).getString());
+                               }
+                               if (node.hasProperty(SLC_ERROR_MESSAGE)) {
+                                       if (messages.length() > 0)
+                                               messages.append('\n');
+                                       messages.append(node.getProperty(SLC_ERROR_MESSAGE)
+                                                       .getString());
+                               }
+                       }
+                       NodeIterator it = node.getNodes();
+                       while (it.hasNext()) {
+                               Node child = it.nextNode();
+                               aggregateTestMessages(child, messages);
+                       }
+                       return messages;
+               } catch (Exception e) {
+                       throw new SlcException("Could not aggregate test messages from "
+                                       + node, e);
+               }
+       }
+
        /** Prevents instantiation */
        private SlcJcrUtils() {
 
index 97bd58451666fdd5b78bf9a3a455abaa7f2e331b..daf1ede4e957a7607d5ea7052d59ed9e7f90485f 100644 (file)
@@ -31,10 +31,22 @@ public interface SlcNames {
        public final static String SLC_MESSAGE = "slc:message";
        public final static String SLC_TAG = "slc:tag";
        public final static String SLC_ERROR_MESSAGE = "slc:errorMessage";
+       public final static String SLC_TEST_CASE = "slc:testCase";
+       public final static String SLC_TEST_CASE_TYPE = "slc:testCaseType";
+
        // diff result
        public final static String SLC_SUMMARY = "slc:summary";
-       public final static String SLC_TOLERANCES = "slc:tolerances";
        public final static String SLC_ISSUES = "slc:issues";
+       public final static String SLC_TOLERANCE = "slc:tolerance";
+       public final static String SLC_RELATIVE_TOLERANCE = "slc:relativeTolerance";
+       public final static String SLC_KEY_COLUMN = "slc:keyColumn";
+       public final static String SLC_MISMATCH = "slc:mismatch";
+       public final static String SLC_LEFT_OVER = "slc:leftOver";
+       public final static String SLC_MISSING = "slc:missing";
+       public final static String SLC_LEFT_OVER_MAX = "slc:leftOverMax";
+       public final static String SLC_MISSING_MAX = "slc:missingMax";
+       public final static String SLC_DETAILED = "slc:detailed";
+       public final static String SLC_ZERO_MISMATCH = "slc:zeroMismatch";
 
        /*
         * REPO
index e51744f80b7ef1a6c91c6415794fdf0b5ebf84c0..36ced22db752977d466c98f4485272363d78fa3d 100644 (file)
@@ -102,6 +102,7 @@ mixin
 - slc:message (STRING)
 // ERROR if set, the check could not be performed because of an unexpected exception
 - slc:errorMessage (STRING)
+// to ease transition with legacy approach
 + * (slc:property) *
 
 [slc:property] > nt:unstructured