Author: cziegeler
Date: Tue Aug 10 18:35:39 2010
New Revision: 984156
URL: http://svn.apache.org/viewvc?rev=984156&view=rev
Log:
Fix test cases
Modified:
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/RootFolderListener.java
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/FolderDetectionTest.java
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResource.java
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResourceFactory.java
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockOsgiInstaller.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
Modified:
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/RootFolderListener.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/RootFolderListener.java?rev=984156&r1=984155&r2=984156&view=diff
==============================================================================
---
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/RootFolderListener.java
(original)
+++
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/RootFolderListener.java
Tue Aug 10 18:35:39 2010
@@ -30,8 +30,8 @@ import javax.jcr.observation.EventListen
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/** Listen for JCR events under one of our roots, to find out
- * when new WatchedFolders must be created, or when some might
+/** Listen for JCR events under one of our roots, to find out
+ * when new WatchedFolders must be created, or when some might
* have been deleted.
*/
class RootFolderListener implements EventListener {
@@ -40,45 +40,45 @@ class RootFolderListener implements Even
private final FolderNameFilter folderNameFilter;
private final RescanTimer timer;
private final String watchedPath;
-
+
RootFolderListener(Session session, FolderNameFilter fnf, String path,
RescanTimer timer) throws RepositoryException {
folderNameFilter = fnf;
this.timer = timer;
this.watchedPath = path;
-
+
int eventTypes = Event.NODE_ADDED | Event.NODE_REMOVED;
boolean isDeep = true;
boolean noLocal = true;
session.getWorkspace().getObservationManager().addEventListener(this,
eventTypes, watchedPath,
isDeep, null, null, noLocal);
-
+
log.info("Watching {} to detect potential changes in subfolders",
watchedPath);
}
-
+
@Override
public String toString() {
return getClass().getSimpleName() + " (" + watchedPath + ")";
}
-
+
void cleanup(Session session) throws RepositoryException {
session.getWorkspace().getObservationManager().removeEventListener(this);
}
-
+
/** Return our saved paths and clear the list
- * @return null if no paths have been saved
+ * @return null if no paths have been saved
*/
Set<String> getAndClearPaths() {
if(paths.isEmpty()) {
return null;
}
-
+
synchronized(paths) {
- Set<String> result = paths;
+ Set<String> result = paths;
paths = new HashSet<String>();
return result;
}
}
-
+
/** Store the paths of new WatchedFolders to create */
public void onEvent(EventIterator it) {
try {
Modified:
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/FolderDetectionTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/FolderDetectionTest.java?rev=984156&r1=984155&r2=984156&view=diff
==============================================================================
---
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/FolderDetectionTest.java
(original)
+++
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/FolderDetectionTest.java
Tue Aug 10 18:35:39 2010
@@ -18,71 +18,72 @@
*/
package org.apache.sling.jcr.jcrinstall.impl;
+import org.slf4j.LoggerFactory;
+
/** Test that changes in folders to watch are correctly detected,
- * including when root folders are created or deleted
+ * including when root folders are created or deleted
*/
public class FolderDetectionTest extends JcrInstallTestBase {
-
+
protected boolean needsTestContent() {
return false;
}
-
+
public void testCreateAndDeleteLibs() throws Exception {
final String res = "/libs/foo/install/somefile.jar";
assertRegistered("Before test", res, false);
-
+
assertFalse("/libs must not exist when test starts",
session.itemExists("/libs"));
contentHelper.createFolder("/libs");
contentHelper.createFolder("/libs/foo");
contentHelper.createFolder("/libs/foo/install");
MiscUtil.waitAfterContentChanges(eventHelper, installer);
-
+
contentHelper.createOrUpdateFile(res);
MiscUtil.waitAfterContentChanges(eventHelper, installer);
-
assertRegistered("After creating libs and test file", res, true);
-
+
contentHelper.delete("/libs");
MiscUtil.waitAfterContentChanges(eventHelper, installer);
assertRegistered("After deleting libs", res, false);
}
-
+
public void testMoveLibsToFoo() throws Exception {
final String res = "/libs/foo/install/somefile.jar";
assertRegistered("Before test", res, false);
-
+
assertFalse("/libs must not exist when test starts",
session.itemExists("/libs"));
contentHelper.createFolder("/libs");
contentHelper.createFolder("/libs/foo");
contentHelper.createFolder("/libs/foo/install");
MiscUtil.waitAfterContentChanges(eventHelper, installer);
-
+
contentHelper.createOrUpdateFile(res);
MiscUtil.waitAfterContentChanges(eventHelper, installer);
-
+
assertRegistered("After creating libs and test file", res, true);
-
+
session.move("/libs", "/foo");
MiscUtil.waitAfterContentChanges(eventHelper, installer);
assertRegistered("After moving /libs to /foo", res, false);
}
-
+
public void testMoveLibsToApps() throws Exception {
final String res = "/libs/foo/install/somefile.jar";
final String appsRes = "/apps/foo/install/somefile.jar";
assertRegistered("Before test", res, false);
-
+
assertFalse("/libs must not exist when test starts",
session.itemExists("/libs"));
contentHelper.createFolder("/libs");
contentHelper.createFolder("/libs/foo");
contentHelper.createFolder("/libs/foo/install");
MiscUtil.waitAfterContentChanges(eventHelper, installer);
-
+
contentHelper.createOrUpdateFile(res);
MiscUtil.waitAfterContentChanges(eventHelper, installer);
-
+
assertRegistered("After creating libs and test file", res, true);
-
+
session.move("/libs", "/apps");
MiscUtil.waitAfterContentChanges(eventHelper, installer);
MiscUtil.waitAfterContentChanges(eventHelper, installer);
Modified:
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResource.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResource.java?rev=984156&r1=984155&r2=984156&view=diff
==============================================================================
---
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResource.java
(original)
+++
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResource.java
Tue Aug 10 18:35:39 2010
@@ -56,6 +56,27 @@ public class MockInstallableResource imp
this.d = null;
}
+ public MockInstallableResource(String uri, InputStream is,
Dictionary<String, Object> d, String digest, String type, Integer priority) {
+ this.uri = uri;
+ this.is = is;
+ if ( type != null ) {
+ this.type = type;
+ } else {
+ this.type = (is != null ? InstallableResource.TYPE_BUNDLE :
InstallableResource.TYPE_CONFIG);
+ }
+ if ( this.type.equals(InstallableResource.TYPE_CONFIG) && digest ==
null ) {
+ this.digest = computeDigest(d);
+ } else {
+ this.digest = digest;
+ }
+ if ( priority != null ) {
+ this.priority = priority;
+ } else {
+ this.priority = InstallableResourceFactory.DEFAULT_PRIORITY;
+ }
+ this.d = d;
+ }
+
public MockInstallableResource(String uri, InputStream is, String digest,
String type, Integer priority) {
this.uri = uri;
this.is = is;
Modified:
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResourceFactory.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResourceFactory.java?rev=984156&r1=984155&r2=984156&view=diff
==============================================================================
---
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResourceFactory.java
(original)
+++
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockInstallableResourceFactory.java
Tue Aug 10 18:35:39 2010
@@ -27,20 +27,12 @@ import org.apache.sling.osgi.installer.I
class MockInstallableResourceFactory implements InstallableResourceFactory {
- public InstallableResource create(String url, Dictionary<String, Object> d,
- String digest, String type, Integer priority) {
- return new MockInstallableResource(url, d, digest, type, priority);
- }
-
- public InstallableResource create(String url, InputStream is,
- String digest, String type, Integer priority) {
- return new MockInstallableResource(url, is, digest, type, priority);
- }
-
+ /**
+ * @see
org.apache.sling.osgi.installer.InstallableResourceFactory#create(java.lang.String,
java.io.InputStream, java.util.Dictionary, java.lang.String, java.lang.String,
java.lang.Integer)
+ */
public InstallableResource create(String url, InputStream is,
Dictionary<String, Object> d, String digest, String type,
Integer priority) {
- // TODO Auto-generated method stub
- return null;
+ return new MockInstallableResource(url, is, d, digest, type, priority);
}
}
Modified:
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockOsgiInstaller.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockOsgiInstaller.java?rev=984156&r1=984155&r2=984156&view=diff
==============================================================================
---
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockOsgiInstaller.java
(original)
+++
sling/trunk/installer/jcr/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/impl/MockOsgiInstaller.java
Tue Aug 10 18:35:39 2010
@@ -29,6 +29,7 @@ import java.util.Set;
import org.apache.sling.osgi.installer.InstallableResource;
import org.apache.sling.osgi.installer.OsgiInstaller;
import org.apache.sling.osgi.installer.OsgiInstallerStatistics;
+import org.slf4j.LoggerFactory;
class MockOsgiInstaller implements OsgiInstaller, OsgiInstallerStatistics {
@@ -53,7 +54,7 @@ class MockOsgiInstaller implements OsgiI
*/
public void addResource(final String scheme, InstallableResource d) {
urls.add(scheme + ':' + d.getId());
- recordCall("add", d);
+ recordCall("add", scheme, d);
}
public long[] getCounters() {
@@ -70,7 +71,7 @@ class MockOsgiInstaller implements OsgiI
Collections.sort(sorted, new InstallableResourceComparator());
for(InstallableResource r : data) {
urls.add(urlScheme + ':' + r.getId());
- recordCall("register", r);
+ recordCall("register", urlScheme, r);
}
}
@@ -84,8 +85,8 @@ class MockOsgiInstaller implements OsgiI
}
}
- private synchronized void recordCall(String prefix, InstallableResource r)
{
- recordedCalls.add(prefix + ":" + r.getId() + ":" + r.getPriority());
+ private synchronized void recordCall(String prefix, String scheme,
InstallableResource r) {
+ recordedCalls.add(prefix + ":" + scheme + ":" + r.getId() + ":" +
r.getPriority());
}
synchronized void clearRecordedCalls() {
@@ -97,6 +98,7 @@ class MockOsgiInstaller implements OsgiI
}
boolean isRegistered(String urlScheme, String path) {
- return urls.contains(urlScheme + ":" + path);
+ final String url = urlScheme + ':' + path;
+ return urls.contains(url);
}
}
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java?rev=984156&r1=984155&r2=984156&view=diff
==============================================================================
---
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
(original)
+++
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
Tue Aug 10 18:35:39 2010
@@ -30,21 +30,23 @@ import java.util.Dictionary;
*/
public interface InstallableResource {
- /** The type for a bundle - in this case {...@link #getInputStream} must
+ /**
+ * The type for a bundle - in this case {...@link #getInputStream} must
* return an input stream to the bundle. {...@link #getDictionary()} might
* return additional information.
*/
String TYPE_BUNDLE = "bundle";
- /** The type for a configuration - in this case {...@link #getDictionary()}
+ /**
+ * The type for a configuration - in this case {...@link #getDictionary()}
* must return a dictionary with the configuration.
*/
String TYPE_CONFIG = "config";
/**
- * Return this data's URL. It is opaque for the {...@link OsgiInstaller}
- * but the scheme must be the one used in the
- * {...@link OsgiInstaller#registerResources} call.
+ * Return this data's id. It is opaque for the {...@link OsgiInstaller}
+ * but should uniquely identify the resource within the namespace of
+ * the used installation mechanism.
*/
String getId();
@@ -73,14 +75,15 @@ public interface InstallableResource {
*/
Dictionary<String, Object> getDictionary();
- /** Return this resource's digest. Not necessarily an actual md5 or
other digest of the
- * data, can be any string that changes if the data changes.
+ /**
+ * Return this resource's digest. Not necessarily an actual md5 or
other digest of the
+ * data, can be any string that changes if the data changes.
*/
String getDigest();
- /** Return the priority of this resource. Priorities are used to decide
which
- * resource to install when several are registered for the same OSGi
entity
- * (bundle, config, etc.)
+ /**Return the priority of this resource. Priorities are used to decide
which
+ * resource to install when several are registered for the same OSGi
entity
+ * (bundle, config, etc.)
*/
int getPriority();
}
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java?rev=984156&r1=984155&r2=984156&view=diff
==============================================================================
---
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
(original)
+++
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
Tue Aug 10 18:35:39 2010
@@ -20,41 +20,47 @@ package org.apache.sling.osgi.installer;
import java.util.Collection;
-/** OSGi Service that installs/updates/removes InstallableData
- * in the OSGi framework.
+/**
+ * OSGi Service that installs/updates/removes installable data
+ * {...@link InstallableResource} in the OSGi framework.
*
- * The client can register a number of such resources, and the
- * installer decides based on the resource weights, bundle version
- * numbers, etc. which ones are actually installed.
+ * The client can register a number of such resources, and the
+ * installer decides based on the resource weights, bundle version
+ * numbers, etc. which ones are actually installed.
*
- * An InstallableResource can be a bundle, a configuration, and later
- * we might support deployment packages as well.
+ * An InstallableResource can be a bundle, a configuration, and later
+ * we might support deployment packages as well.
*/
public interface OsgiInstaller {
- /** Provide the installer with the complete list of installable
- * resources for a given client.
+ /**
+ * Provide the installer with the complete list of installable
+ * resources for a given client.
*
- * Client must call this at startup and/or when the installer
- * service becomes available. The installer stores the list of
- * previously registered/added resources, compares with the new
- * list and removes resources that have disappeared.
+ * Client must call this at startup and/or when the installer
+ * service becomes available. The installer stores the list of
+ * previously registered/added resources, compares with the new
+ * list and removes resources that have disappeared.
*
- * Invalid resources are ignored.
+ * Invalid resources are ignored.
*
- * @param data the list of available resources
- * @param urlScheme identifies the client. All URLs of the
supplied data
- * must use this scheme
+ * @param urlScheme identifies the client.
+ * @param data the list of available resources
*/
void registerResources(String urlScheme,
Collection<InstallableResource> data);
- /** Inform the installer that a resource is available for installation.
- * also called if the resource has been modified since it was
registered.
- * Invalid resources are ignored.
+ /**
+ * Inform the installer that a resource is available for installation.
+ * also called if the resource has been modified since it was
registered.
+ * Invalid resources are ignored.
+ * @param urlScheme identifies the client.
*/
void addResource(String urlScheme, InstallableResource r);
- /** Inform the installer that a resource is no longer available
- * @param r an empty InstallableResource, isEmpty() must return
true */
+ /**
+ * Inform the installer that a resource is no longer available
+ * @param urlScheme identifies the client.
+ * @param id The identifier for the resource
+ */
void removeResource(String urlScheme, String id);
}
\ No newline at end of file