Author: bdelacretaz
Date: Mon Apr 15 13:20:06 2013
New Revision: 1468044
URL: http://svn.apache.org/r1468044
Log:
SLING-2822 - add junit rules to execute server-side JUnit tests
Added:
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestRuleBuilder.java
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestSelector.java
sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/impl/
sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/impl/rules/
sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestSelectorTest.java
sling/trunk/contrib/extensions/muppet/sling-demo/ (with props)
sling/trunk/contrib/extensions/muppet/sling-demo/pom.xml
sling/trunk/contrib/extensions/muppet/sling-demo/src/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/RepositoryPresentTest.java
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/ResourcesExistTest.java
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo.json
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/RepositoryPresentTest.json
(with props)
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest-checkAppsExist.json
(with props)
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest.json
(with props)
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-foo.json
(with props)
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-login.json
(with props)
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/groovy-bundle.json
(with props)
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/junit-sling-all.json
(with props)
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/non-existent-bundle.json
(with props)
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/sling-api-bundle.json
(with props)
Modified:
sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/JsonResultRendererImpl.java
sling/trunk/contrib/extensions/muppet/pom.xml
Modified: sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml?rev=1468044&r1=1468043&r2=1468044&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml (original)
+++ sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml Mon Apr 15
13:20:06 2013
@@ -37,6 +37,10 @@
<extensions>true</extensions>
<configuration>
<instructions>
+ <Import-Package>
+ org.junit.*;resolution:=optional,
+ *
+ </Import-Package>
<Export-Package>
org.apache.sling.muppet.sling.api
</Export-Package>
@@ -89,6 +93,12 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.junit.core</artifactId>
+ <version>1.0.6</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
@@ -123,7 +133,7 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
- <scope>test</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
Modified:
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/JsonResultRendererImpl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/JsonResultRendererImpl.java?rev=1468044&r1=1468043&r2=1468044&view=diff
==============================================================================
---
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/JsonResultRendererImpl.java
(original)
+++
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/JsonResultRendererImpl.java
Mon Apr 15 13:20:06 2013
@@ -35,7 +35,8 @@ public class JsonResultRendererImpl impl
@Override
public void render(List<EvaluationResult> results, Writer output) throws
IOException {
- // TODO not JSON yet...trouble with animalsniffer and JSON dependency
+ // TODO: trouble with animalsniffer and JSON dependency
+ output.write("TODO: this should be JSON - not implemented yet\n");
for(EvaluationResult r : results) {
output.write(r.getStatus().toString());
output.write(" ");
Added:
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestRuleBuilder.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestRuleBuilder.java?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestRuleBuilder.java
(added)
+++
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestRuleBuilder.java
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,187 @@
+/*
+ * 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.sling.impl.rules;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.junit.Renderer;
+import org.apache.sling.junit.TestSelector;
+import org.apache.sling.junit.TestsManager;
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.RuleBuilder;
+import org.apache.sling.muppet.api.SystemAttribute;
+import org.junit.runner.Description;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+
+/** Creates {@link Rule} to execute JUnit tests using the
+ * org.apache.sling.junit.core services.
+ */
+@Component
+@Service(value=RuleBuilder.class)
+public class JUnitTestRuleBuilder implements RuleBuilder {
+
+ public static final String NAMESPACE = "sling";
+ public static final String RULE_NAME = "junit";
+
+ public static final String ALL_PASSED = "ALL_TESTS_PASSED";
+
+ @Reference
+ private TestsManager testsManager;
+
+ private static class CustomRunListener extends RunListener {
+
+ final List<Failure> failures = new ArrayList<Failure>();
+ int nTests;
+
+ @Override
+ public void testFailure(Failure failure) throws Exception {
+ super.testFailure(failure);
+ failures.add(failure);
+ }
+
+ @Override
+ public void testFinished(Description description) throws Exception {
+ super.testFinished(description);
+ nTests++;
+ }
+ }
+
+ private static class CustomRenderer implements Renderer {
+
+ private final String extension;
+ final List<String> infoLines = new ArrayList<String>();
+ private final RunListener listener;
+
+ CustomRenderer(RunListener listener, String extension) {
+ this.extension = extension;
+ this.listener = listener;
+ }
+
+ @Override
+ public boolean appliesTo(TestSelector ts) {
+ return true;
+ }
+
+ @Override
+ public void cleanup() {
+ }
+
+ @Override
+ public String getExtension() {
+ return extension;
+ }
+
+ @Override
+ public RunListener getRunListener() {
+ return listener;
+ }
+
+ @Override
+ public void info(String role, String info) {
+ infoLines.add(info);
+ }
+
+ @Override
+ public void link(String arg0, String arg1, String arg2) {
+ }
+
+ @Override
+ public void list(String arg0, Collection<String> arg1) {
+ }
+
+ @Override
+ public void setup(HttpServletResponse arg0, String arg1) throws
IOException, UnsupportedEncodingException {
+ }
+
+ @Override
+ public void title(int arg0, String arg1) {
+ }
+ }
+
+ private class JUnitTestSystemAttribute implements SystemAttribute {
+
+ private final TestSelector selector;
+ private final String extension;
+
+ JUnitTestSystemAttribute(TestSelector selector, String extension) {
+ this.selector = selector;
+ this.extension = extension;
+ }
+
+ @Override
+ public String toString() {
+ return selector.toString();
+ }
+
+ @Override
+ public Object getValue() {
+ String errorMsg = null;
+ final CustomRunListener listener = new CustomRunListener();
+ final Renderer r = new CustomRenderer(listener, extension);
+ final Collection<String> testNames =
testsManager.getTestNames(selector);
+ if(testNames.isEmpty()) {
+ errorMsg = "No tests found for selector " + selector;
+ } else {
+ try {
+ testsManager.executeTests(testNames, r, selector);
+ if(!listener.failures.isEmpty()) {
+ // TODO need better formatting of this;
+ errorMsg = "Some tests failed: " + listener.failures;
+ } else if(listener.nTests == 0) {
+ errorMsg = "No tests executed with selector " +
selector;
+ }
+ } catch(Exception e) {
+ errorMsg = "Exception while executing tests: " +
e.toString();
+ }
+ }
+
+ return errorMsg != null ? errorMsg : ALL_PASSED;
+ }
+ }
+
+ @Override
+ public Rule buildRule(String namespace, String ruleName, String qualifier,
String expression) {
+ if(!NAMESPACE.equals(namespace) || !RULE_NAME.equals(ruleName) ||
qualifier == null) {
+ return null;
+ }
+
+ // Qualifier is the package or class names of JUnit tests to
+ // execute. A method can be specified after a hash sign, so
+ // for example com.example.tests.MyTestClass#theMethod
+ final String [] parts = qualifier.split("#");
+ if(parts.length > 0) {
+ final String testPackageOrClass = parts[0].trim();
+ final String testMethod = parts.length > 1 ? parts[1].trim() :
null;
+ final String extension = "json";
+ final TestSelector selector = new
JUnitTestSelector(testPackageOrClass, testMethod, extension);
+ return new Rule(new JUnitTestSystemAttribute(selector, extension),
expression);
+ }
+
+ return null;
+ }
+}
\ No newline at end of file
Added:
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestSelector.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestSelector.java?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestSelector.java
(added)
+++
sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestSelector.java
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,57 @@
+/*
+ * 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 ASF 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.sling.impl.rules;
+
+import org.apache.sling.junit.TestSelector;
+
+class JUnitTestSelector implements TestSelector {
+
+ private final String testPackageOrClass;
+ private final String testMethod;
+ private final String extension;
+
+ JUnitTestSelector(String testPackageOrClass, String testMethod, String
extension) {
+ this.testPackageOrClass = testPackageOrClass;
+ this.testMethod = testMethod;
+ this.extension = extension;
+ }
+
+ @Override
+ public boolean acceptTestName(String name) {
+ return name.startsWith(testPackageOrClass);
+ }
+
+ @Override
+ public String getExtension() {
+ return extension;
+ }
+
+ @Override
+ public String getSelectedTestMethodName() {
+ return testMethod;
+ }
+
+ @Override
+ public String getTestSelectorString() {
+ return testPackageOrClass + (testMethod == null ? "" : "#" +
testMethod);
+ }
+
+ @Override
+ public String toString() {
+ return getTestSelectorString();
+ }
+}
Added:
sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestSelectorTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestSelectorTest.java?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestSelectorTest.java
(added)
+++
sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/impl/rules/JUnitTestSelectorTest.java
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,47 @@
+/*
+ * 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 ASF 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.sling.impl.rules;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class JUnitTestSelectorTest {
+
+ @Test
+ public void testSelectorString() {
+ assertEquals("com.example.foo", new
JUnitTestSelector("com.example.foo", null, null).getTestSelectorString());
+ assertEquals("com.example.testing#someMethod", new
JUnitTestSelector("com.example.testing", "someMethod",
null).getTestSelectorString());
+ }
+
+ @Test
+ public void testNoMethod() {
+ final JUnitTestSelector s = new JUnitTestSelector("com.example.foo",
null, null);
+ assertTrue("Expecting package to be selected",
s.acceptTestName("com.example.foo"));
+ assertTrue("Expecting subpackage to be selected",
s.acceptTestName("com.example.foo.bar"));
+ assertTrue("Expecting class to be selected",
s.acceptTestName("com.example.foo.some.ThisClass"));
+ assertFalse("Expecting other package.accept to return false",
s.acceptTestName("com.other.foo"));
+ }
+
+ @Test
+ public void testWithMethod() {
+ final JUnitTestSelector s = new JUnitTestSelector("com.example.foo",
"someMethod", null);
+ assertTrue("Expecting package to be selected",
s.acceptTestName("com.example.foo"));
+ assertEquals("someMethod", s.getSelectedTestMethodName());
+ }
+}
Modified: sling/trunk/contrib/extensions/muppet/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/pom.xml?rev=1468044&r1=1468043&r2=1468044&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/muppet/pom.xml (original)
+++ sling/trunk/contrib/extensions/muppet/pom.xml Mon Apr 15 13:20:06 2013
@@ -29,6 +29,7 @@
<module>muppet-core</module>
<module>muppet-rules</module>
<module>muppet-sling</module>
+ <module>sling-demo</module>
<module>it</module>
</modules>
</project>
Propchange: sling/trunk/contrib/extensions/muppet/sling-demo/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Apr 15 13:20:06 2013
@@ -0,0 +1,13 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+
+
+
Added: sling/trunk/contrib/extensions/muppet/sling-demo/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/pom.xml?rev=1468044&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/sling-demo/pom.xml (added)
+++ sling/trunk/contrib/extensions/muppet/sling-demo/pom.xml Mon Apr 15
13:20:06 2013
@@ -0,0 +1,90 @@
+<?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.slingdemo</artifactId>
+ <packaging>bundle</packaging>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <name>Muppet Sling demo content</name>
+ <inceptionYear>2013</inceptionYear>
+
+ <description>
+ Sling demo content and tests for Muppet
+ </description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+
<Sling-Initial-Content>SLING-CONTENT</Sling-Initial-Content>
+ <Import-Package>
+ org.junit.*;resolution:=optional,
+ *
+ </Import-Package>
+ <Private-Package>
+ org.apache.sling.muppet.sling.demo.*
+ </Private-Package>
+ <Sling-Test-Regexp>.*Test</Sling-Test-Regexp>
+ </instructions>
+ </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.api</artifactId>
+ <version>2.0.6</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.jcr.api</artifactId>
+ <version>2.0.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.junit.core</artifactId>
+ <version>1.0.6</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/RepositoryPresentTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/RepositoryPresentTest.java?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/RepositoryPresentTest.java
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/RepositoryPresentTest.java
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,58 @@
+package org.apache.sling.muppet.demo.tests;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import javax.jcr.Session;
+
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
+import org.apache.sling.junit.annotations.TestReference;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/*
+ * 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 ASF 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.
+ */
+
+/** Trivial test used to demonstrate the Muppet junit rules - verify
+ * that the SlingRepository is functional.
+ */
+@RunWith(SlingAnnotationsTestRunner.class)
+public class RepositoryPresentTest {
+ @TestReference
+ private SlingRepository repository;
+
+ @Test
+ public void checkRepositoryPresent() {
+ assertNotNull(repository);
+ }
+
+ @Test
+ public void checkAdminLogin() {
+ Session s = null;
+ try {
+ s = repository.loginAdministrative(null);
+ assertNotNull(s);
+ } catch(Exception e) {
+ fail("SlingRepository login failed: " + e);
+ } finally {
+ if(s != null) {
+ s.logout();
+ }
+ }
+ }
+}
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/ResourcesExistTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/ResourcesExistTest.java?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/ResourcesExistTest.java
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/java/org/apache/sling/muppet/demo/tests/ResourcesExistTest.java
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,61 @@
+package org.apache.sling.muppet.demo.tests;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import javax.jcr.Session;
+
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
+import org.apache.sling.junit.annotations.TestReference;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/*
+ * 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 ASF 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.
+ */
+
+/** Trivial test used to demonstrate the Muppet junit rules - verify
+ * the existence of some resources. One of the tests is designed to fail.
+ */
+@RunWith(SlingAnnotationsTestRunner.class)
+public class ResourcesExistTest {
+ @TestReference
+ private SlingRepository repository;
+
+ private void assertResource(String path) throws Exception {
+ Session s = null;
+ try {
+ s = repository.loginAdministrative(null);
+ assertNotNull(s);
+ assertTrue("Expecting path " + path + " to exist",
s.itemExists(path));
+ } finally {
+ if(s != null) {
+ s.logout();
+ }
+ }
+ }
+
+ @Test
+ public void checkAppsExist() throws Exception {
+ assertResource("/apps");
+ }
+
+ @Test
+ public void checkNonExistentPath() throws Exception {
+ assertResource("/NON_EXISTENT/" + System.currentTimeMillis());
+ }
+}
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo.json
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo.json?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo.json
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo.json
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType" : "nt:unstructured",
+ "sling:resourceType" : "sling/muppet.rules"
+}
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/RepositoryPresentTest.json
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/RepositoryPresentTest.json?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/RepositoryPresentTest.json
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/RepositoryPresentTest.json
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,7 @@
+{
+ "expression": "ALL_TESTS_PASSED",
+ "ruleName": "junit",
+ "namespace": "sling",
+ "jcr:primaryType": "nt:unstructured",
+ "qualifier": "org.apache.sling.muppet.demo.tests.RepositoryPresentTest"
+}
\ No newline at end of file
Propchange:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/RepositoryPresentTest.json
------------------------------------------------------------------------------
svn:executable = *
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest-checkAppsExist.json
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest-checkAppsExist.json?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest-checkAppsExist.json
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest-checkAppsExist.json
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,7 @@
+{
+ "expression": "ALL_TESTS_PASSED",
+ "ruleName": "junit",
+ "namespace": "sling",
+ "jcr:primaryType": "nt:unstructured",
+ "qualifier":
"org.apache.sling.muppet.demo.tests.ResourcesExistTest#checkAppsExist"
+}
\ No newline at end of file
Propchange:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest-checkAppsExist.json
------------------------------------------------------------------------------
svn:executable = *
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest.json
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest.json?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest.json
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest.json
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,7 @@
+{
+ "expression": "ALL_TESTS_PASSED",
+ "ruleName": "junit",
+ "namespace": "sling",
+ "jcr:primaryType": "nt:unstructured",
+ "qualifier": "org.apache.sling.muppet.demo.tests.ResourcesExistTest"
+}
\ No newline at end of file
Propchange:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/ResourcesExistTest.json
------------------------------------------------------------------------------
svn:executable = *
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-foo.json
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-foo.json?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-foo.json
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-foo.json
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,7 @@
+{
+ "expression": "LOGIN_FAILED",
+ "ruleName": "login",
+ "namespace": "sling",
+ "jcr:primaryType": "nt:unstructured",
+ "qualifier": "admin#foo"
+}
\ No newline at end of file
Propchange:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-foo.json
------------------------------------------------------------------------------
svn:executable = *
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-login.json
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-login.json?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-login.json
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-login.json
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,7 @@
+{
+ "expression": "LOGIN_OK",
+ "ruleName": "login",
+ "namespace": "sling",
+ "jcr:primaryType": "nt:unstructured",
+ "qualifier": "admin#admin"
+}
\ No newline at end of file
Propchange:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/admin-login.json
------------------------------------------------------------------------------
svn:executable = *
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/groovy-bundle.json
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/groovy-bundle.json?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/groovy-bundle.json
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/groovy-bundle.json
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,7 @@
+{
+ "expression": "active",
+ "ruleName": "bundle.state",
+ "namespace": "osgi",
+ "jcr:primaryType": "nt:unstructured",
+ "qualifier": "groovy-all"
+}
\ No newline at end of file
Propchange:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/groovy-bundle.json
------------------------------------------------------------------------------
svn:executable = *
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/junit-sling-all.json
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/junit-sling-all.json?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/junit-sling-all.json
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/junit-sling-all.json
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,7 @@
+{
+ "expression": "ALL_TESTS_PASSED",
+ "ruleName": "junit",
+ "namespace": "sling",
+ "jcr:primaryType": "nt:unstructured",
+ "qualifier": "org.apache.sling.muppet.demo.tests"
+}
\ No newline at end of file
Propchange:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/junit-sling-all.json
------------------------------------------------------------------------------
svn:executable = *
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/non-existent-bundle.json
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/non-existent-bundle.json?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/non-existent-bundle.json
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/non-existent-bundle.json
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,7 @@
+{
+ "expression": "BUNDLE_NOT_FOUND",
+ "ruleName": "bundle.state",
+ "namespace": "osgi",
+ "jcr:primaryType": "nt:unstructured",
+ "qualifier": "non.existent.bundle"
+}
\ No newline at end of file
Propchange:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/non-existent-bundle.json
------------------------------------------------------------------------------
svn:executable = *
Added:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/sling-api-bundle.json
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/sling-api-bundle.json?rev=1468044&view=auto
==============================================================================
---
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/sling-api-bundle.json
(added)
+++
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/sling-api-bundle.json
Mon Apr 15 13:20:06 2013
@@ -0,0 +1,7 @@
+{
+ "expression": "active",
+ "ruleName": "bundle.state",
+ "namespace": "osgi",
+ "jcr:primaryType": "nt:unstructured",
+ "qualifier": "org.apache.sling.api"
+}
\ No newline at end of file
Propchange:
sling/trunk/contrib/extensions/muppet/sling-demo/src/main/resources/SLING-CONTENT/apps/muppet/demo/sling-api-bundle.json
------------------------------------------------------------------------------
svn:executable = *