incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1489798 - in /sling/trunk/contrib/extensions/healthcheck: hc-core/src/main/java/org/apache/sling/hc/api/ hc-core/src/test/java/org/apache/sling/hc/api/ hc-sling/src/main/java/org/apache/sling/hc/sling/impl/ hc-sling/src/test/java/org/apach...
Date Wed, 05 Jun 2013 10:30:14 GMT
Author: bdelacretaz
Date: Wed Jun  5 10:30:13 2013
New Revision: 1489798

URL: http://svn.apache.org/r1489798
Log:
Rule info added, Sling parser adds resource path, displayed in json rendering

Added:
    sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleInfoTest.java
  (with props)
Modified:
    sling/trunk/contrib/extensions/healthcheck/hc-core/src/main/java/org/apache/sling/hc/api/Rule.java
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesResourceParserImpl.java
    sling/trunk/contrib/extensions/healthcheck/hc-sling/src/test/java/org/apache/sling/hc/sling/RulesResourceParserTest.java

Modified: sling/trunk/contrib/extensions/healthcheck/hc-core/src/main/java/org/apache/sling/hc/api/Rule.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-core/src/main/java/org/apache/sling/hc/api/Rule.java?rev=1489798&r1=1489797&r2=1489798&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-core/src/main/java/org/apache/sling/hc/api/Rule.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-core/src/main/java/org/apache/sling/hc/api/Rule.java
Wed Jun  5 10:30:13 2013
@@ -18,7 +18,9 @@
 package org.apache.sling.hc.api;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.sling.hc.impl.RuleLoggerImpl;
@@ -36,6 +38,7 @@ public class Rule {
     private final String expression;
     private final Logger logger = LoggerFactory.getLogger(getClass());
     private Set<String> tags = Collections.<String>emptySet();
+    private final Map<String, Object> ruleInfo = new HashMap<String, Object>();
     
     public Rule(SystemAttribute attr, String expression) {
         this(attr, expression, new DefaultEvaluator());
@@ -74,6 +77,12 @@ public class Rule {
         return new EvaluationResult(this, ruleLogger);
     }
     
+    /** Optional additional free-form information about this Rule.
+     *  The return Map is mutable so that clients can add info to it. */
+    public Map<String, Object> getInfo() {
+        return ruleInfo;
+    }
+    
     @Override
     public String toString() {
         return getClass().getSimpleName() + ": " 

Added: sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleInfoTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleInfoTest.java?rev=1489798&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleInfoTest.java
(added)
+++ sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleInfoTest.java
Wed Jun  5 10:30:13 2013
@@ -0,0 +1,41 @@
+/*
+ * 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 SF 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.sling.hc.api;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+
+public class RuleInfoTest {
+    @Test
+    public void testInitialInfo() {
+        final Rule r = new Rule(null, null);
+        assertNotNull(r.getInfo());
+        assertTrue(r.getInfo().isEmpty());
+    }
+    
+    @Test
+    public void testSetInfo() {
+        final Rule r = new Rule(null, null);
+        final String key = "myself";
+        r.getInfo().put(key, r);
+        assertNotNull(r.getInfo().get(key));
+        assertEquals(r, r.getInfo().get(key));
+    }
+}

Propchange: sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleInfoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleInfoTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java?rev=1489798&r1=1489797&r2=1489798&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/JsonResultRendererImpl.java
Wed Jun  5 10:30:13 2013
@@ -20,6 +20,7 @@ package org.apache.sling.hc.sling.impl;
 import java.io.IOException;
 import java.io.Writer;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
@@ -47,11 +48,24 @@ public class JsonResultRendererImpl impl
                 w.object();
                 {
                     w.key("rule").value(r.getRule().toString());
+                    
+                    final Map<String, Object> info = r.getRule().getInfo();
+                    if(!info.isEmpty()) {
+                        w.key("info").array();
+                        for(Map.Entry<String, Object> e : info.entrySet()) {
+                            w.object();
+                            w.key(e.getKey()).value(e.getValue());
+                            w.endObject();
+                        }
+                        w.endArray();
+                    }
+                    
                     w.key("tags").array();
                     for(String tag : r.getRule().getTags()) {
                         w.value(tag);
                     }
                     w.endArray();
+                    
                     if(r.anythingToReport()) {
                         w.key("log").array();
                         {

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesResourceParserImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesResourceParserImpl.java?rev=1489798&r1=1489797&r2=1489798&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesResourceParserImpl.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/main/java/org/apache/sling/hc/sling/impl/RulesResourceParserImpl.java
Wed Jun  5 10:30:13 2013
@@ -48,6 +48,8 @@ public class RulesResourceParserImpl imp
     @Reference
     private SlingRequestProcessor requestProcessor;
     
+    public static final String RESOURCE_PATH_INFO = "sling.resource.path";
+    
     @SuppressWarnings("serial")
     public static class UnauthorizedException extends SlingException {
         UnauthorizedException() {
@@ -112,6 +114,11 @@ public class RulesResourceParserImpl imp
                     }
                 }
                 
+                // resource path info
+                if(rule != null) {
+                    rule.getInfo().put(RESOURCE_PATH_INFO, r.getPath());
+                }
+                
                 if(rule != null) {
                     return rule;
                 }

Modified: sling/trunk/contrib/extensions/healthcheck/hc-sling/src/test/java/org/apache/sling/hc/sling/RulesResourceParserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-sling/src/test/java/org/apache/sling/hc/sling/RulesResourceParserTest.java?rev=1489798&r1=1489797&r2=1489798&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-sling/src/test/java/org/apache/sling/hc/sling/RulesResourceParserTest.java
(original)
+++ sling/trunk/contrib/extensions/healthcheck/hc-sling/src/test/java/org/apache/sling/hc/sling/RulesResourceParserTest.java
Wed Jun  5 10:30:13 2013
@@ -18,6 +18,7 @@
 package org.apache.sling.hc.sling;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
@@ -96,7 +97,7 @@ public class RulesResourceParserTest {
     
     @Test
     public void testResourceWithTags() {
-        final MockResource r = new MockResource(resolver, "/", "test", "constant", "5", ">
3");
+        final MockResource r = new MockResource(resolver, "/foo", "test", "constant", "5",
"> 3");
         r.setTags(new String [] { "foo", "bar" });
         final List<Rule> rules = parser.parseResource(r); 
         assertEquals(1, rules.size());
@@ -105,6 +106,8 @@ public class RulesResourceParserTest {
         assertEquals(2, rule.getTags().size());
         assertTrue(rule.hasTag("foo"));
         assertTrue(rule.hasTag("bar"));
+        assertNotNull(rule.getInfo());
+        assertEquals("/foo", rule.getInfo().get("sling.resource.path"));
     }
     
     @Test



Mime
View raw message