This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.hc.it-1.0.4
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-hc-it.git

commit 1ae820b12d10a8834d3b0e26c1e2a8dd88284458
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Mon Apr 15 09:52:11 2013 +0000

    SLING-2822 - Muppet - extensible system health checking tool
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/contrib/extensions/muppet/it@1467919
 13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 115 +++++++++++++++++++
 .../apache/sling/muppet/it/core/AllRulesTest.java  |  65 +++++++++++
 .../sling/muppet/it/core/MuppetOsgiFacadeTest.java | 123 +++++++++++++++++++++
 .../apache/sling/muppet/it/core/OsgiRulesTest.java |  61 ++++++++++
 .../java/org/apache/sling/muppet/it/core/U.java    |  73 ++++++++++++
 5 files changed, 437 insertions(+)

diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..f1c8114
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project 
+    xmlns="http://maven.apache.org/POM/4.0.0"; 
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+    
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>15</version>
+        <relativePath>15</relativePath>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.muppet.it</artifactId>
+    <packaging>jar</packaging>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Muppet Integration Tests</name>
+    <inceptionYear>2013</inceptionYear>
+
+    <properties>
+        <exam.version>3.0.3</exam.version>
+        <url.version>1.5.2</url.version>
+        
<org.ops4j.pax.logging.DefaultServiceLog.level>INFO</org.ops4j.pax.logging.DefaultServiceLog.level>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <systemProperties>
+                        
<org.ops4j.pax.logging.DefaultServiceLog.level>${org.ops4j.pax.logging.DefaultServiceLog.level}</org.ops4j.pax.logging.DefaultServiceLog.level>
+                        
<muppet.core.version>${project.version}</muppet.core.version>
+                    </systemProperties>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.muppet.core</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.muppet.rules</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.6.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <version>1.6.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-native</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-junit4</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-link-mvn</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-aether</artifactId>
+            <version>${url.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>4.2.1</version>
+            <scope>test</scope>
+        </dependency>
+     </dependencies>
+</project>
diff --git a/src/test/java/org/apache/sling/muppet/it/core/AllRulesTest.java 
b/src/test/java/org/apache/sling/muppet/it/core/AllRulesTest.java
new file mode 100644
index 0000000..7ca61a1
--- /dev/null
+++ b/src/test/java/org/apache/sling/muppet/it/core/AllRulesTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.muppet.it.core;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.apache.sling.muppet.api.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+/** Test our various types of {@link Rule} together */ 
+@RunWith(PaxExam.class)
+public class AllRulesTest {
+    
+    @Inject
+    private MuppetFacade facade;
+    
+    @Configuration
+    public Option[] config() {
+        return U.config(true);
+    }
+    
+    @Test
+    public void testMixOfRules() throws IOException {
+        // There should be at least one rule builder, but not a lot
+        final String [] rules = { 
+            "osgi:bundle.state:org.apache.sling.muppet.core:active",
+            "osgi:bundle.state:some.nonexistenbundle:BUNDLE_NOT_FOUND",
+            "jmxbeans:java.lang#type=ClassLoading:LoadedClassCount:> 100",
+            "muppet:RuleBuilderCount:between 2 and 10"
+        };
+        final List<EvaluationResult> r = U.evaluateRules(facade, rules);
+        
+        assertEquals(4, r.size());
+        int i=0;
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: 
bundle.state:org.apache.sling.muppet.core active");
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: 
bundle.state:some.nonexistenbundle BUNDLE_NOT_FOUND");
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: 
java.lang:type=ClassLoading:LoadedClassCount > 100");
+    }
+}
diff --git 
a/src/test/java/org/apache/sling/muppet/it/core/MuppetOsgiFacadeTest.java 
b/src/test/java/org/apache/sling/muppet/it/core/MuppetOsgiFacadeTest.java
new file mode 100644
index 0000000..3beac31
--- /dev/null
+++ b/src/test/java/org/apache/sling/muppet/it/core/MuppetOsgiFacadeTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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.muppet.it.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.RuleBuilder;
+import org.apache.sling.muppet.api.SystemAttribute;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+@RunWith(PaxExam.class)
+public class MuppetOsgiFacadeTest {
+    
+    @Inject
+    private MuppetFacade facade;
+    
+    @Inject
+    private BundleContext bundleContext;
+    
+    @Configuration
+    public Option[] config() {
+        return U.config(false);
+    }
+    
+    @Test
+    public void testFacadePresent() {
+        assertNotNull("Expecting MuppetFacade service to be provided", facade);
+    }
+    
+    @Test
+    public void testDefaultRules() throws IOException {
+        // There should be at least one rule builder, but not a lot
+        final String [] rules = { 
+            "muppet:RuleBuilderCount:> 0",
+            "muppet:RuleBuilderCount:> 42"
+        };
+        final List<EvaluationResult> r = U.evaluateRules(facade, rules);
+        
+        assertEquals(2, r.size());
+        int i=0;
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: 
RuleBuilderCount > 0");
+        U.assertResult(r.get(i++), EvaluationResult.Status.ERROR, "Rule: 
RuleBuilderCount > 42");
+    }
+    
+    @Test
+    public void testAddingCustomRule() throws IOException {
+        final String [] rules = { 
+            "muppet:RuleBuilderCount:> 0",
+            "muppet:RuleBuilderCount:> 42",
+            "test:constant:5",
+            "test:constant:12",
+        };
+        
+        final SystemAttribute five = new SystemAttribute() {
+            @Override
+            public String toString() {
+                return "five";
+            }
+            @Override
+            public Object getValue() {
+                return 5;
+            }
+        };
+        
+        // To add new rule types, just register RuleBuilder services
+        final RuleBuilder rb = new RuleBuilder() {
+            @Override
+            public Rule buildRule(String namespace, String ruleName, String 
qualifier, String expression) {
+                if("test".equals(namespace) && "constant".equals(ruleName)) {
+                    return new Rule(five, expression);
+                }
+                return null;
+            }
+        };
+        
+        final ServiceRegistration<?> reg = 
bundleContext.registerService(RuleBuilder.class.getName(), rb, null);
+
+        try {
+            final List<EvaluationResult> r = U.evaluateRules(facade, rules);
+            assertEquals(4, r.size());
+            int i=0;
+            U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: 
RuleBuilderCount > 0");
+            U.assertResult(r.get(i++), EvaluationResult.Status.ERROR, "Rule: 
RuleBuilderCount > 42");
+            U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: five 
5");
+            U.assertResult(r.get(i++), EvaluationResult.Status.ERROR, "Rule: 
five 12");
+        } finally {
+            reg.unregister();
+        }
+        
+        final List<EvaluationResult> r = U.evaluateRules(facade, rules);
+        assertEquals("Expecting custom RuleBuilder to be gone", 2, r.size());
+    }
+}
diff --git a/src/test/java/org/apache/sling/muppet/it/core/OsgiRulesTest.java 
b/src/test/java/org/apache/sling/muppet/it/core/OsgiRulesTest.java
new file mode 100644
index 0000000..295b085
--- /dev/null
+++ b/src/test/java/org/apache/sling/muppet/it/core/OsgiRulesTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.muppet.it.core;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class OsgiRulesTest {
+    
+    @Inject
+    private MuppetFacade facade;
+    
+    @Configuration
+    public Option[] config() {
+        return U.config(true);
+    }
+    
+    
+    @Test
+    public void testBundleStateRules() throws IOException {
+        // There should be at least one rule builder, but not a lot
+        final String [] rules = { 
+            "osgi:bundle.state:org.apache.sling.muppet.core:active",
+            "osgi:bundle.state:some.nonexistenbundle:BUNDLE_NOT_FOUND",
+        };
+        final List<EvaluationResult> r = U.evaluateRules(facade, rules);
+        
+        assertEquals(2, r.size());
+        int i=0;
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: 
bundle.state:org.apache.sling.muppet.core active");
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: 
bundle.state:some.nonexistenbundle BUNDLE_NOT_FOUND");
+    }
+}
diff --git a/src/test/java/org/apache/sling/muppet/it/core/U.java 
b/src/test/java/org/apache/sling/muppet/it/core/U.java
new file mode 100644
index 0000000..0491c6d
--- /dev/null
+++ b/src/test/java/org/apache/sling/muppet/it/core/U.java
@@ -0,0 +1,73 @@
+/*
+ * 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.muppet.it.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.apache.sling.muppet.api.RulesEngine;
+import org.ops4j.pax.exam.Option;
+
+/** Test utilities */
+public class U {
+    
+    static Option[] config(boolean includeRules) {
+        final String coreVersion = System.getProperty("muppet.core.version");
+
+        if(includeRules) {
+            return options(
+                    junitBundles(),
+                    provision(
+                            mavenBundle("org.apache.sling", 
"org.apache.sling.muppet.core", coreVersion),
+                            mavenBundle("org.apache.sling", 
"org.apache.sling.muppet.rules", coreVersion)
+                    )
+            );
+        } else {
+            return options(
+                    junitBundles(),
+                    provision(
+                            mavenBundle("org.apache.sling", 
"org.apache.sling.muppet.core", coreVersion)
+                    )
+            );
+        }
+    }
+    
+    static List<EvaluationResult> evaluateRules(MuppetFacade facade, String [] 
rules) throws IOException {
+        final RulesEngine e = facade.getNewRulesEngine();
+        final StringBuilder b = new StringBuilder();
+        for(String line : rules) {
+            b.append(line).append("\n");
+        }
+        e.addRules(facade.parseSimpleTextRules(new 
StringReader(b.toString())));
+        return e.evaluateRules();
+    }
+    
+    static void assertResult(EvaluationResult rr, EvaluationResult.Status 
status, String ruleString) {
+        assertEquals("Expecting " + rr.getRule() + " result to match", status, 
rr.getStatus());
+        assertEquals("Expecting " + rr.getRule() + " string to match", 
ruleString, rr.getRule().toString());
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to