Author: bdelacretaz Date: Wed Dec 3 05:26:00 2008 New Revision: 722881 URL: http://svn.apache.org/viewvc?rev=722881&view=rev Log: SLING-734 - jcrinstall integration tests, first simple InstallClonedBundlesTest works
Added: incubator/sling/trunk/extensions/jcrinstall/pom.xml (with props) incubator/sling/trunk/extensions/jcrinstall/testbundles/ (with props) incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/ (with props) incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/pom.xml (with props) incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/testing/ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/testing/testbundles/ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/testing/testbundles/observer/ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/testing/testbundles/observer/ObserverService.java (with props) incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/InstallClonedBundlesTest.java (with props) incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java (with props) incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/util/ incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/util/BundleCloner.java (with props) Modified: incubator/sling/trunk/extensions/jcrinstall/service/pom.xml incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java incubator/sling/trunk/extensions/jcrinstall/testing/pom.xml incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/HttpPingTest.java Added: incubator/sling/trunk/extensions/jcrinstall/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/pom.xml?rev=722881&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/pom.xml (added) +++ incubator/sling/trunk/extensions/jcrinstall/pom.xml Wed Dec 3 05:26:00 2008 @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<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>4-incubator-SNAPSHOT</version> + <relativePath>../../parent/</relativePath> + </parent> + + <artifactId>org.apache.sling.jcr.jcrinstall.parent</artifactId> + <version>2.0.3-incubator-SNAPSHOT</version> + <packaging>pom</packaging> + <name>Sling - JCR OSGi Installer Parent</name> + <description>Parent pom for the the jcrinstall submodules</description> + + <scm> + <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/extensions/jcrinstall</connection> + <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/extensions/jcrinstall</developerConnection> + <url>http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall</url> + </scm> + + <modules> + <module>service</module> + <module>testbundles/observer</module> + </modules> + + <profiles> + <profile> + <!-- + Allow the integration tests to be excluded, as they might be slow + --> + <id>integrationTests</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <modules> + <module>testing</module> + </modules> + </profile> + </profiles> + +</project> \ No newline at end of file Propchange: incubator/sling/trunk/extensions/jcrinstall/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/sling/trunk/extensions/jcrinstall/service/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/pom.xml?rev=722881&r1=722880&r2=722881&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/service/pom.xml (original) +++ incubator/sling/trunk/extensions/jcrinstall/service/pom.xml Wed Dec 3 05:26:00 2008 @@ -21,17 +21,17 @@ <modelVersion>4.0.0</modelVersion> <parent> - <groupId>org.apache.sling</groupId> - <artifactId>sling</artifactId> - <version>4-incubator-SNAPSHOT</version> - <relativePath>../../../parent/</relativePath> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.jcr.jcrinstall.parent</artifactId> + <version>2.0.3-incubator-SNAPSHOT</version> + <relativePath>../</relativePath> </parent> <artifactId>org.apache.sling.jcr.jcrinstall</artifactId> <version>2.0.3-incubator-SNAPSHOT</version> <packaging>bundle</packaging> - <name>Sling - JCR OSGi Installer</name> + <name>Sling - JCR OSGi Installer Service</name> <description> Loads OSGi bundles, deployment packages and configs from configurable locations in the JCR repository. Modified: incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=722881&r1=722880&r2=722881&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java Wed Dec 3 05:26:00 2008 @@ -21,9 +21,11 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.SortedSet; @@ -45,6 +47,7 @@ import org.apache.sling.jcr.jcrinstall.jcr.NodeConverter; import org.apache.sling.jcr.jcrinstall.osgi.OsgiController; import org.apache.sling.jcr.jcrinstall.osgi.ResourceOverrideRules; +import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkEvent; import org.osgi.framework.FrameworkListener; import org.osgi.framework.ServiceReference; @@ -554,12 +557,32 @@ doGet(request, response); } + /** Report on the jcrinstall enabled/disabled status, number of bundles in each state, etc. */ @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { - final String status = repository != null ? "enabled" : "disabled"; + final Properties props = new Properties(); + + if(componentContext != null) { + // report on how many bundles we have in the different states + final Map<Integer, Integer> states = new HashMap<Integer, Integer>(); + for(Bundle b : componentContext.getBundleContext().getBundles()) { + final Integer s = new Integer(b.getState()); + Integer i = states.get(s); + i = i == null ? new Integer(1) : new Integer(i.intValue() + 1); + states.put(s, i); + } + + for(Map.Entry<Integer, Integer> e : states.entrySet()) { + props.put("bundles.in.state." + e.getKey().toString(), e.getValue().toString()); + } + } + + props.put("osgi.start.level", String.valueOf(startLevel.getStartLevel())); + props.put("jcrinstall.enabled", new Boolean(repository != null).toString()); + response.setContentType("text/plain"); - response.getWriter().write(getClass().getSimpleName() + " is " + status); + props.store(response.getOutputStream(), "jcrinstall status"); } -} \ No newline at end of file + } \ No newline at end of file Propchange: incubator/sling/trunk/extensions/jcrinstall/testbundles/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Wed Dec 3 05:26:00 2008 @@ -0,0 +1,12 @@ +target +bin +derby.log +*.iml +*.ipr +*.iws +.settings +.project +.classpath +.externalToolBuilders +maven-eclipse.xml + Propchange: incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Wed Dec 3 05:26:00 2008 @@ -0,0 +1,13 @@ +target +bin +derby.log +*.iml +*.ipr +*.iws +.settings +.project +.classpath +.externalToolBuilders +maven-eclipse.xml + + Added: incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/pom.xml?rev=722881&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/pom.xml (added) +++ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/pom.xml Wed Dec 3 05:26:00 2008 @@ -0,0 +1,96 @@ +<?xml version="1.0" encoding="UTF-8"?> + <!-- + 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. + --> +<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>org.apache.sling.jcr.jcrinstall.parent</artifactId> + <version>2.0.3-incubator-SNAPSHOT</version> + <relativePath>../../</relativePath> + </parent> + + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.jcr.jcrinstall.testbundles.observer</artifactId> + <packaging>bundle</packaging> + <version>2.0.3-incubator-SNAPSHOT</version> + <name>Sling - JCR OSGi Installer - Observer test bundle</name> + <description> Bundle used in jcrinstall automated tests. </description> + + <scm> + <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/extensions/jcrinstall/testbundles/observer</connection> + <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/extensions/jcrinstall/testbundles/observer</developerConnection> + <url>http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testbundles/observer</url> + </scm> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Private-Package>org.apache.sling.jcrinstall.testing.testbundles.*</Private-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + + <reporting> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + </plugin> + </plugins> + </reporting> + + <dependencies> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.commons.log</artifactId> + <version>2.0.3-incubator-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.jcr.api</artifactId> + <version>2.0.3-incubator-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.api</artifactId> + <version>2.0.3-incubator-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + </dependencies> +</project> \ No newline at end of file Propchange: incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/testing/testbundles/observer/ObserverService.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/testing/testbundles/observer/ObserverService.java?rev=722881&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/testing/testbundles/observer/ObserverService.java (added) +++ incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/testing/testbundles/observer/ObserverService.java Wed Dec 3 05:26:00 2008 @@ -0,0 +1,83 @@ +/* + * 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.jcrinstall.testing.testbundles.observer; + +import javax.jcr.Session; +import javax.jcr.observation.Event; +import javax.jcr.observation.EventIterator; +import javax.jcr.observation.EventListener; + +import org.apache.sling.jcr.api.SlingRepository; +import org.osgi.framework.FrameworkEvent; +import org.osgi.framework.FrameworkListener; +import org.osgi.service.component.ComponentContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** Dummy service for jcrinstall integration testing - listens to + * repository and framework events and logs them. + * + * @scr.component + * label="jcrinstall test ObserverService" + * description="Listens to repository and framework events and logs them" + * immediate="true" + * @scr.service + * @scr.property + * name="service.description" + * value="Sling jcrinstall Test ObserverService" + * @scr.property + * name="service.vendor" + * value="The Apache Software Foundation" +*/ +public class ObserverService implements EventListener, FrameworkListener { + /** @scr.reference */ + private SlingRepository repository; + + private Session session; + private final Logger log = LoggerFactory.getLogger(getClass()); + + protected void activate(ComponentContext context) throws Exception { + context.getBundleContext().addFrameworkListener(this); + session = repository.loginAdministrative(repository.getDefaultWorkspace()); + final int eventTypes = Event.NODE_ADDED | Event.NODE_REMOVED + | Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED; + final boolean isDeep = true; + final boolean noLocal = true; + final String path = "/content"; + session.getWorkspace().getObservationManager().addEventListener( + this, eventTypes, path, + isDeep, null, null, noLocal); + } + + protected void deactivate(ComponentContext context) throws Exception { + context.getBundleContext().removeFrameworkListener(this); + if(session != null) { + session.getWorkspace().getObservationManager().removeEventListener(this); + session.logout(); + session = null; + } + } + + public void onEvent(EventIterator it) { + log.debug("onEvent()"); + } + + public void frameworkEvent(FrameworkEvent e) { + log.debug("FrameworkEvent of type {}", e.getType()); + } +} Propchange: incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/testing/testbundles/observer/ObserverService.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/extensions/jcrinstall/testbundles/observer/src/main/java/org/apache/sling/jcrinstall/testing/testbundles/observer/ObserverService.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: incubator/sling/trunk/extensions/jcrinstall/testing/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testing/pom.xml?rev=722881&r1=722880&r2=722881&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/testing/pom.xml (original) +++ incubator/sling/trunk/extensions/jcrinstall/testing/pom.xml Wed Dec 3 05:26:00 2008 @@ -20,12 +20,12 @@ <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>4-incubator-SNAPSHOT</version> - <relativePath>../../../parent/</relativePath> - </parent> + <parent> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.jcr.jcrinstall.parent</artifactId> + <version>2.0.3-incubator-SNAPSHOT</version> + <relativePath>../</relativePath> + </parent> <artifactId>org.apache.sling.jcr.jcrinstall.testing</artifactId> <packaging>war</packaging> @@ -79,6 +79,12 @@ started. Useful to manually test the integration testing webapp. --> <integration.test.wait>false</integration.test.wait> + + <!-- Where to copy our test bundles --> + <sling.testbundles.path>${project.build.directory}/testbundles</sling.testbundles.path> + + <!-- Can be used to run tests with more or less bundles --> + <sling.test.scale.factor>10</sling.test.scale.factor> </properties> <build> @@ -171,6 +177,30 @@ </includeScope> </configuration> </execution> + <execution> + <!-- + Copy test bundles, test cases will create multiple instances of them + --> + <id>copy-testbundles</id> + <goals> + <goal>copy-dependencies</goal> + </goals> + <configuration> + <outputDirectory> + ${sling.testbundles.path} + </outputDirectory> + <excludeTransitive>true</excludeTransitive> + <includeGroupIds> + org.apache.sling + </includeGroupIds> + <includeArtifactIds> + org.apache.sling.jcr.jcrinstall.testbundles.observer + </includeArtifactIds> + <includeScope> + provided + </includeScope> + </configuration> + </execution> </executions> </plugin> @@ -289,6 +319,14 @@ http://${test.host}:${http.port}/${webdav.workspace.path} </value> </property> + <property> + <name>sling.testbundles.path</name> + <value>${sling.testbundles.path}</value> + </property> + <property> + <name>sling.test.scale.factor</name> + <value>${sling.test.scale.factor}</value> + </property> </systemProperties> </configuration> </plugin> @@ -657,7 +695,19 @@ <artifactId>jcl-over-slf4j</artifactId> <scope>test</scope> </dependency> - + <dependency> + <groupId>biz.aQute</groupId> + <artifactId>bnd</artifactId> + <version>0.0.169</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.jcr.jcrinstall.testbundles.observer</artifactId> + <version>2.0.3-incubator-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <!-- The servlet container will have to provide these API classes --> <dependency> <groupId>javax.servlet</groupId> Modified: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/HttpPingTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/HttpPingTest.java?rev=722881&r1=722880&r2=722881&view=diff ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/HttpPingTest.java (original) +++ incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/HttpPingTest.java Wed Dec 3 05:26:00 2008 @@ -17,12 +17,11 @@ package org.apache.sling.jcr.jcrinstall.integrationtest; import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.sling.commons.testing.integration.HttpTestBase; /** Ping the Sling server to verify that our integration test * setup is ok. */ -public class HttpPingTest extends HttpTestBase { +public class HttpPingTest extends JcrinstallTestBase { public void testWebServerRoot() throws Exception { Added: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/InstallClonedBundlesTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/InstallClonedBundlesTest.java?rev=722881&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/InstallClonedBundlesTest.java (added) +++ incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/InstallClonedBundlesTest.java Wed Dec 3 05:26:00 2008 @@ -0,0 +1,44 @@ +/* + * 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.jcr.jcrinstall.integrationtest; + +import java.util.LinkedList; +import java.util.List; + +/** Try installing some cloned bundles */ +public class InstallClonedBundlesTest extends JcrinstallTestBase { + + public void testInstallAndRemoveBundles() throws Exception { + final int activeBeforeTest = getActiveBundlesCount(); + final List<String> installed = new LinkedList<String>(); + + final int nBundles = 10 * scaleFactor; + for(int i=0 ; i < nBundles; i++) { + installed.add(installClonedBundle(null, null)); + } + + assertActiveBundleCount("after adding bundles", + activeBeforeTest + nBundles, DEFAULT_BUNDLES_TIMEOUT); + + for(String path : installed) { + removeClonedBundle(path); + } + + assertActiveBundleCount("after removing added bundles", + activeBeforeTest, DEFAULT_BUNDLES_TIMEOUT); + } +} Propchange: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/InstallClonedBundlesTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/InstallClonedBundlesTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java?rev=722881&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java (added) +++ incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java Wed Dec 3 05:26:00 2008 @@ -0,0 +1,169 @@ +/* + * 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.jcr.jcrinstall.integrationtest; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import org.apache.sling.commons.testing.integration.HttpTestBase; +import org.apache.sling.jcr.jcrinstall.integrationtest.util.BundleCloner; +import org.osgi.framework.Bundle; + +/** Base class for jcrinstall test cases */ +public class JcrinstallTestBase extends HttpTestBase { + + public static final int DEFAULT_BUNDLES_TIMEOUT = 10; + public static final String JCRINSTALL_STATUS_PATH = "/system/sling/jcrinstall"; + public static final String DEFAULT_INSTALL_PATH = "/libs/jcrinstall/testing/install"; + public static final String DEFAULT_BUNDLE_NAME_PATTERN = "observer"; + private static long bundleCounter = System.currentTimeMillis(); + private static Set<String> installedClones; + public static final String SCALE_FACTOR_PROP = "sling.test.scale.factor"; + protected final int scaleFactor = Integer.getInteger(SCALE_FACTOR_PROP); + + private class ShutdownThread extends Thread { + @Override + public void run() { + try { + System.out.println("Deleting " + installedClones.size() + " cloned bundles..."); + for(String path : installedClones) { + testClient.delete(WEBDAV_BASE_URL + path); + } + } catch(Exception e) { + System.out.println("Exception in ShutdownThread:" + e); + } + } + + }; + + @Override + protected void setUp() throws Exception { + super.setUp(); + + if(scaleFactor < 1) { + throw new IllegalArgumentException("scaleFactor < 1, " + SCALE_FACTOR_PROP + " system property missing?"); + } + } + + /** Fail test if active bundles count is not expectedCount, after + * at most timeoutSeconds */ + protected void assertActiveBundleCount(String message, int expectedCount, int timeoutSeconds) throws IOException { + final long timeout = System.currentTimeMillis() + timeoutSeconds * 1000L; + int count = 0; + while(System.currentTimeMillis() < timeout) { + count = getActiveBundlesCount(); + if(count == expectedCount) { + return; + } + } + fail(message + ": expected " + expectedCount + " active bundles, found " + count); + } + + protected int getActiveBundlesCount() throws IOException { + final String key = "bundles.in.state." + Bundle.ACTIVE; + final Properties props = getJcrInstallProperties(); + int result = 0; + if(props.containsKey(key)) { + result = Integer.valueOf(props.getProperty(key)); + } + return result; + } + + /** Return the Properties found at /system/sling/jcrinstall */ + protected Properties getJcrInstallProperties() throws IOException { + final String content = getContent(HTTP_BASE_URL + JCRINSTALL_STATUS_PATH, CONTENT_TYPE_PLAIN); + final Properties result = new Properties(); + result.load(new ByteArrayInputStream(content.getBytes("UTF-8"))); + return result; + } + + /** Remove a cloned bundle that had been installed before */ + protected void removeClonedBundle(String path) throws IOException { + testClient.delete(WEBDAV_BASE_URL + path); + installedClones.remove(path); + } + + /** Generate a clone of one of our test bundles, with unique bundle name and + * symbolic name, and install it via WebDAV. + * @param bundleNamePattern The first test bundle that contains this pattern + * is used as a source. If null, uses DEFAULT_BUNDLE_NAME_PATTERN + * @param installPath if null, use DEFAULT_INSTALL_PATH + * @return the path of the installed bundle + */ + protected String installClonedBundle(String bundleNamePattern, String installPath) throws Exception { + if(bundleNamePattern == null) { + bundleNamePattern = DEFAULT_BUNDLE_NAME_PATTERN; + } + if(installPath == null) { + installPath = DEFAULT_INSTALL_PATH; + } + + // find test bundle to clone + final File testBundlesDir = new File(System.getProperty("sling.testbundles.path")); + if(!testBundlesDir.isDirectory()) { + throw new IOException(testBundlesDir.getAbsolutePath() + " is not a directory"); + } + File bundleSrc = null; + for(String bundle : testBundlesDir.list()) { + if(bundle.contains(bundleNamePattern)) { + bundleSrc = new File(testBundlesDir, bundle); + break; + } + } + + // clone bundle + final File outputDir = new File(testBundlesDir, "cloned-bundles"); + outputDir.mkdirs(); + final String bundleId = bundleNamePattern + "_clone_" + bundleCounter++; + final File clone = new File(outputDir, bundleId + ".jar"); + new BundleCloner().cloneBundle(bundleSrc, clone, bundleId, bundleId); + + // install clone by copying to repository - jcrinstall should then pick it up + FileInputStream fis = new FileInputStream(clone); + final String path = installPath + "/" + clone.getName(); + final String url = WEBDAV_BASE_URL + path; + try { + testClient.mkdirs(WEBDAV_BASE_URL, installPath); + testClient.upload(url, fis); + setupBundlesCleanup(); + installedClones.add(path); + } finally { + if(fis != null) { + fis.close(); + } + } + + return path; + } + + /** If not done yet, register a shutdown hook to delete cloned bundles that + * we installed. + */ + private void setupBundlesCleanup() { + synchronized (JcrinstallTestBase.class) { + if(installedClones == null) { + installedClones = new HashSet<String>(); + Runtime.getRuntime().addShutdownHook(new ShutdownThread()); + } + } + } +} \ No newline at end of file Propchange: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/JcrinstallTestBase.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/util/BundleCloner.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/util/BundleCloner.java?rev=722881&view=auto ============================================================================== --- incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/util/BundleCloner.java (added) +++ incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/util/BundleCloner.java Wed Dec 3 05:26:00 2008 @@ -0,0 +1,55 @@ +/* + * 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.jcr.jcrinstall.integrationtest.util; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.util.Properties; + +import aQute.bnd.main.bnd; + +/** Generate a clone of an OSGi bundle, with its + * own Bundle-Name and Bundle-SymbolicName. + */ +public class BundleCloner { + private final bnd bnd = new bnd(); + + /** Create a clone of supplied bundle */ + public void cloneBundle(File bundle, File output, String name, String symbolicName) throws Exception { + int options = 0; + + Properties props = new Properties(); + props.put("Bundle-Name", name); + props.put("Bundle-SymbolicName", symbolicName); + File properties = File.createTempFile(getClass().getSimpleName(), "properties"); + final OutputStream out = new FileOutputStream(properties); + + File classpath[] = null; + try { + props.store(out, getClass().getSimpleName()); + bnd.doWrap(properties, bundle, output, classpath, options, null); + } finally { + if(out != null) { + out.close(); + } + if(properties != null) { + properties.delete(); + } + } + } +} Propchange: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/util/BundleCloner.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/extensions/jcrinstall/testing/src/test/java/org/apache/sling/jcr/jcrinstall/integrationtest/util/BundleCloner.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL