You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2013/05/14 16:18:05 UTC
svn commit: r1482341 - in
/sling/trunk/contrib/extensions/healthcheck/hc-core/src:
main/java/org/apache/sling/hc/api/Rule.java
test/java/org/apache/sling/hc/api/
test/java/org/apache/sling/hc/api/RuleTagsTest.java
Author: bdelacretaz
Date: Tue May 14 14:18:05 2013
New Revision: 1482341
URL: http://svn.apache.org/r1482341
Log:
SLING-2822 Rule tags added
Added:
sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/
sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleTagsTest.java (with props)
Modified:
sling/trunk/contrib/extensions/healthcheck/hc-core/src/main/java/org/apache/sling/hc/api/Rule.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=1482341&r1=1482340&r2=1482341&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 Tue May 14 14:18:05 2013
@@ -17,6 +17,10 @@
*/
package org.apache.sling.hc.api;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
import org.apache.sling.hc.impl.RuleLoggerImpl;
import org.apache.sling.hc.util.DefaultEvaluator;
import org.slf4j.Logger;
@@ -31,6 +35,7 @@ public class Rule {
private final Evaluator evaluator;
private final String expression;
private final Logger logger = LoggerFactory.getLogger(getClass());
+ private Set<String> tags = Collections.<String>emptySet();
public Rule(SystemAttribute attr, String expression) {
this(attr, expression, new DefaultEvaluator());
@@ -42,6 +47,25 @@ public class Rule {
this.evaluator = e;
}
+ /** Replace the tags of this rule by supplied ones.
+ * Tags are lowercased before being set */
+ public void setTags(String ...newTags) {
+ tags = new HashSet<String>();
+ for(String tag : newTags) {
+ tags.add(tag.toLowerCase());
+ }
+ }
+
+ /** Return this rule's tags */
+ public Set<String> getTags() {
+ return tags;
+ }
+
+ /** True if this rule has given tags */
+ public boolean hasTag(String tag) {
+ return getTags().contains(tag);
+ }
+
/** Evaluate the rule and return the results */
public EvaluationResult evaluate() {
final RuleLoggerImpl ruleLogger = new RuleLoggerImpl(logger);
Added: sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleTagsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleTagsTest.java?rev=1482341&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleTagsTest.java (added)
+++ sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleTagsTest.java Tue May 14 14:18:05 2013
@@ -0,0 +1,78 @@
+/*
+ * 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.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+
+public class RuleTagsTest {
+ private Rule r;
+
+ @Before
+ public void setup() {
+ r = new Rule(null, null);
+ }
+
+ @Test
+ public void testNoTags() {
+ assertTrue(r.getTags().isEmpty());
+ }
+
+ @Test
+ public void testEmptyTagsList() {
+ r.setTags();
+ assertTrue(r.getTags().isEmpty());
+ }
+
+ @Test
+ public void testSingleTag() {
+ r.setTags("foo");
+ assertEquals(1, r.getTags().size());
+ assertTrue(r.hasTag("foo"));
+ assertFalse(r.hasTag("absent"));
+ }
+
+ @Test
+ public void testSeveralTags() {
+ r.setTags("foo", "bar", "BAR");
+ assertEquals(2, r.getTags().size());
+ assertTrue(r.hasTag("foo"));
+ assertTrue(r.hasTag("bar"));
+ assertFalse(r.hasTag("BAR"));
+ }
+
+ @Test
+ public void testReplaceTags() {
+ r.setTags("foo", "bar", "BAR");
+ assertEquals(2, r.getTags().size());
+ assertTrue(r.hasTag("foo"));
+ assertTrue(r.hasTag("bar"));
+ assertFalse(r.hasTag("BAR"));
+
+ r.setTags("one", "two", "three four");
+ assertEquals(3, r.getTags().size());
+ assertTrue(r.hasTag("one"));
+ assertTrue(r.hasTag("two"));
+ assertTrue(r.hasTag("three four"));
+ assertFalse(r.hasTag("foo"));
+ assertFalse(r.hasTag("bar"));
+ }
+}
Propchange: sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleTagsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/healthcheck/hc-core/src/test/java/org/apache/sling/hc/api/RuleTagsTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL