You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2009/05/04 14:24:42 UTC
svn commit: r771287 - in
/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src:
main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/
test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/
Author: bdelacretaz
Date: Mon May 4 12:24:42 2009
New Revision: 771287
URL: http://svn.apache.org/viewvc?rev=771287&view=rev
Log:
SLING-904 - OsgiControllerTask added, refactoring operations for a future worker thread
Added:
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java (with props)
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorList.java (with props)
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorListTest.java
- copied, changed from r771233, incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerGetProcessorTest.java
Removed:
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerGetProcessorTest.java
Modified:
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java
incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/Utilities.java
Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java?rev=771287&r1=771286&r2=771287&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java (original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java Mon May 4 12:24:42 2009
@@ -18,8 +18,6 @@
*/
package org.apache.sling.jcr.jcrinstall.osgi.impl;
-import static org.apache.sling.jcr.jcrinstall.osgi.InstallResultCode.IGNORED;
-
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
@@ -56,12 +54,16 @@
public class OsgiControllerImpl implements OsgiController, SynchronousBundleListener {
private Storage storage;
- private List<OsgiResourceProcessor> processors;
+ private OsgiResourceProcessorList processors;
private final Logger log = LoggerFactory.getLogger(this.getClass());
private ResourceOverrideRules roRules;
+ private final List<OsgiControllerTask> tasks = new LinkedList<OsgiControllerTask>();
public static final String STORAGE_FILENAME = "controller.storage";
+ /** Storage key: digest of an InstallableData */
+ public static final String KEY_DIGEST = "data.digest";
+
/** @scr.reference */
private ConfigurationAdmin configAdmin;
@@ -71,20 +73,11 @@
/** @scr.reference */
protected StartLevel startLevel;
- /** Storage key: digest of an InstallableData */
- public static final String KEY_DIGEST = "data.digest";
-
/** Default value for getLastModified() */
public static final long LAST_MODIFIED_NOT_FOUND = -1;
protected void activate(ComponentContext context) throws IOException {
-
- // Note that, in executeScheduledOperations(),
- // processors are called in the order of this list
- processors = new LinkedList<OsgiResourceProcessor>();
- processors.add(new BundleResourceProcessor(context.getBundleContext(), packageAdmin, startLevel));
- processors.add(new ConfigResourceProcessor(configAdmin));
-
+ processors = new OsgiResourceProcessorList(context.getBundleContext(), packageAdmin, startLevel, configAdmin);
storage = new Storage(context.getBundleContext().getDataFile(STORAGE_FILENAME));
}
@@ -108,72 +101,15 @@
}
public void scheduleInstallOrUpdate(String uri, InstallableData data) throws IOException, JcrInstallException {
-
- // If a corresponding higher priority resource is already installed, ignore this one
- if(roRules != null) {
- for(String r : roRules.getHigherPriorityResources(uri)) {
- if(storage.contains(r)) {
- log.info("Resource {} ignored, overridden by {} which has higher priority",
- uri, r);
- return;
- }
- }
- }
-
- // If a corresponding lower priority resource is installed, uninstall it first
- if(roRules != null) {
- for(String r : roRules.getLowerPriorityResources(uri)) {
- if(storage.contains(r)) {
- log.info("Resource {} overrides {}, uninstalling the latter",
- uri, r);
- scheduleUninstall(uri);
- }
- }
- }
-
- // let suitable OsgiResourceProcessor process install
- final OsgiResourceProcessor p = getProcessor(uri, data);
- if (p != null) {
- try {
- final Map<String, Object> map = storage.getMap(uri);
- if(p.installOrUpdate(uri, map, data) != IGNORED) {
- map.put(KEY_DIGEST, data.getDigest());
- }
- storage.saveToFile();
- } catch(IOException ioe) {
- throw ioe;
- } catch(Exception e) {
- throw new JcrInstallException("Exception in installOrUpdate (" + uri + ")", e);
- }
- }
- return;
+ synchronized (tasks) {
+ tasks.add(new OsgiControllerTask(storage, processors, roRules, uri, data));
+ }
}
public void scheduleUninstall(String uri) throws JcrInstallException {
- // If a corresponding higher priority resource is installed, ignore this request
- if(roRules != null) {
- for(String r : roRules.getHigherPriorityResources(uri)) {
- if(storage.contains(r)) {
- log.info("Resource {} won't be uninstalled, overridden by {} which has higher priority",
- uri, r);
- return;
- }
- }
- }
-
- try {
- // let each processor try to uninstall, one of them
- // should know how that handle uri
- for(OsgiResourceProcessor p : this.processors) {
- p.uninstall(uri, storage.getMap(uri));
- }
-
- storage.remove(uri);
- storage.saveToFile();
-
- } catch(Exception e) {
- throw new JcrInstallException("Exception in uninstall (" + uri + ")", e);
- }
+ synchronized (tasks) {
+ tasks.add(new OsgiControllerTask(storage, processors, roRules, uri, null));
+ }
}
public Set<String> getInstalledUris() {
@@ -197,28 +133,6 @@
return "jcrinstall://" + uri;
}
- /** Return the first processor that accepts given uri, null if not found */
- OsgiResourceProcessor getProcessor(String uri, InstallableData data) {
- OsgiResourceProcessor result = null;
-
- if(processors == null) {
- throw new IllegalStateException("Processors are not set");
- }
-
- for(OsgiResourceProcessor p : processors) {
- if(p.canProcess(uri, data)) {
- result = p;
- break;
- }
- }
-
- if(result == null) {
- log.debug("No processor found for resource {}", uri);
- }
-
- return result;
- }
-
/** Schedule our next scan sooner if anything happens to bundles */
public void bundleChanged(BundleEvent e) {
//loopDelay = 0;
@@ -230,7 +144,14 @@
log.info("Not activated yet, cannot executeScheduledOperations");
return;
}
-
+
+ // Execute all our tasks, and then let processors execute
+ // their own queued operations
+ synchronized (tasks) {
+ while(tasks.size() > 0) {
+ tasks.remove(0).execute();
+ }
+ }
for(OsgiResourceProcessor p : processors) {
p.processResourceQueue();
}
Added: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java?rev=771287&view=auto
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java (added)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java Mon May 4 12:24:42 2009
@@ -0,0 +1,140 @@
+/*
+ * 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.osgi.impl;
+
+import static org.apache.sling.jcr.jcrinstall.osgi.InstallResultCode.IGNORED;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
+import org.apache.sling.jcr.jcrinstall.osgi.JcrInstallException;
+import org.apache.sling.jcr.jcrinstall.osgi.OsgiResourceProcessor;
+import org.apache.sling.jcr.jcrinstall.osgi.ResourceOverrideRules;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** An install/upgrade/uninistall task, meant to be executed
+ * by the OsgiController worker thread.
+ */
+class OsgiControllerTask {
+
+ private final String uri;
+ private final InstallableData data;
+ private final Storage storage;
+ private final OsgiResourceProcessorList processors;
+ private final ResourceOverrideRules roRules;
+
+ private static final Logger log = LoggerFactory.getLogger(OsgiControllerTask.class);
+
+ /** Create a task that will install, update or uninstall a resource.
+ * @param data if not null, operation is install or update, else uninstall
+ */
+ OsgiControllerTask(
+ Storage storage,
+ OsgiResourceProcessorList processors,
+ ResourceOverrideRules roRules,
+ String uri,
+ InstallableData data)
+ {
+ this.storage = storage;
+ this.processors = processors;
+ this.roRules = roRules;
+ this.uri = uri;
+ this.data = data;
+ }
+
+ void execute() throws JcrInstallException, IOException {
+ if(data != null) {
+ executeInstallOrUpdate();
+ } else {
+ executeUninstall();
+ }
+ }
+
+ private void executeUninstall() throws JcrInstallException {
+ // If a corresponding higher priority resource is installed, ignore this request
+ if(roRules != null) {
+ for(String r : roRules.getHigherPriorityResources(uri)) {
+ if(storage.contains(r)) {
+ log.info("Resource {} won't be uninstalled, overridden by {} which has higher priority",
+ uri, r);
+ return;
+ }
+ }
+ }
+
+ try {
+ // let each processor try to uninstall, one of them
+ // should know how that handle uri
+ for(OsgiResourceProcessor p : this.processors) {
+ p.uninstall(uri, storage.getMap(uri));
+ }
+
+ storage.remove(uri);
+ storage.saveToFile();
+
+ } catch(Exception e) {
+ throw new JcrInstallException("Exception in uninstall (" + uri + ")", e);
+ }
+ }
+
+ private void executeInstallOrUpdate() throws JcrInstallException , IOException {
+ // If a corresponding higher priority resource is already installed, ignore this one
+ if(roRules != null) {
+ for(String r : roRules.getHigherPriorityResources(uri)) {
+ if(storage.contains(r)) {
+ log.info("Resource {} ignored, overridden by {} which has higher priority",
+ uri, r);
+ return;
+ }
+ }
+ }
+
+ // If a corresponding lower priority resource is installed, uninstall it first
+ if(roRules != null) {
+ for(String r : roRules.getLowerPriorityResources(uri)) {
+ if(storage.contains(r)) {
+ log.info("Resource {} overrides {}, uninstalling the latter",
+ uri, r);
+ executeUninstall();
+ }
+ }
+ }
+
+ // let suitable OsgiResourceProcessor process install
+ final OsgiResourceProcessor p = processors.getProcessor(uri, data);
+ if (p != null) {
+ try {
+ final Map<String, Object> map = storage.getMap(uri);
+ if(p.installOrUpdate(uri, map, data) != IGNORED) {
+ map.put(OsgiControllerImpl.KEY_DIGEST, data.getDigest());
+ }
+ storage.saveToFile();
+ } catch(IOException ioe) {
+ throw ioe;
+ } catch(Exception e) {
+ throw new JcrInstallException("Exception in installOrUpdate (" + uri + ")", e);
+ }
+ }
+ return;
+
+ }
+}
Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorList.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorList.java?rev=771287&view=auto
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorList.java (added)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorList.java Mon May 4 12:24:42 2009
@@ -0,0 +1,60 @@
+/*
+ * 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.osgi.impl;
+
+import java.util.LinkedList;
+
+import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
+import org.apache.sling.jcr.jcrinstall.osgi.OsgiResourceProcessor;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.startlevel.StartLevel;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** List of OsgiResourceProcessor, initialized with our
+ * set of processors.
+ */
+@SuppressWarnings("serial")
+class OsgiResourceProcessorList extends LinkedList<OsgiResourceProcessor> {
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ OsgiResourceProcessorList(BundleContext ctx, PackageAdmin pa, StartLevel sa, ConfigurationAdmin ca) {
+ add(new BundleResourceProcessor(ctx, pa, sa));
+ add(new ConfigResourceProcessor(ca));
+ }
+
+ OsgiResourceProcessor getProcessor(String uri, InstallableData data) {
+ OsgiResourceProcessor result = null;
+
+ for(OsgiResourceProcessor p : this) {
+ if(p.canProcess(uri, data)) {
+ result = p;
+ break;
+ }
+ }
+
+ if(result == null) {
+ log.debug("No processor found for resource {}", uri);
+ }
+
+ return result;
+ }
+}
\ No newline at end of file
Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorList.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorList.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java?rev=771287&r1=771286&r2=771287&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java (original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/BundleResourceProcessorTest.java Mon May 4 12:24:42 2009
@@ -18,9 +18,6 @@
*/
package org.apache.sling.jcr.jcrinstall.osgi.impl;
-import static org.apache.sling.jcr.jcrinstall.osgi.InstallResultCode.IGNORED;
-import static org.apache.sling.jcr.jcrinstall.osgi.InstallResultCode.INSTALLED;
-import static org.apache.sling.jcr.jcrinstall.osgi.InstallResultCode.UPDATED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -35,6 +32,7 @@
import org.jmock.Sequence;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.service.packageadmin.PackageAdmin;
@@ -71,6 +69,7 @@
final TestStorage s = new TestStorage(Utilities.getTestFile());
Utilities.setStorage(c, s);
final Bundle b = mockery.mock(Bundle.class);
+ final Bundle [] bundles = { b };
final long bundleId = 1234;
final String uri = "/test/bundle.jar";
final MockInstallableData data = new MockInstallableData(uri);
@@ -81,8 +80,16 @@
mockery.checking(new Expectations() {{
allowing(pa).refreshPackages(null);
allowing(pa).resolveBundles(null);
+ allowing(b).start();
+ allowing(b).getSymbolicName();
+ will(returnValue(bundleId + "-name"));
allowing(b).getBundleId();
will(returnValue(bundleId));
+ allowing(b).getState();
+ allowing(bc).getBundle(bundleId);
+ will(returnValue(b));
+ allowing(bc).getBundles();
+ will(returnValue(bundles));
allowing(b).getLocation();
will(returnValue(uri));
allowing(bc).addFrameworkListener(with(any(FrameworkListener.class)));
@@ -107,30 +114,56 @@
// Do the calls and check some stuff on the way
final BundleResourceProcessor p = new BundleResourceProcessor(bc, pa, new MockStartLevel());
- Utilities.setProcessors(c, p);
+ final OsgiResourceProcessorList proc = new OsgiResourceProcessorList(bc, null, null, null);
+ proc.clear();
+ proc.add(p);
+ Utilities.setField(c, "processors", proc);
assertFalse("Before install, uri must not be in list", c.getInstalledUris().contains(uri));
-
- assertEquals("First install returns INSTALLED", INSTALLED, c.scheduleInstallOrUpdate(uri, data));
+
+ // Need to send framework events to p
+ // TODO: this test is getting too complicated... ;-)
+ class FEThread extends Thread {
+ boolean active = true;
+ public FEThread() {
+ setDaemon(true);
+ start();
+ }
+ public void run() {
+ while(active) {
+ try {
+ Thread.sleep(1000L);
+ } catch(InterruptedException iex) {
+ active = false;
+ }
+ p.frameworkEvent(new FrameworkEvent(FrameworkEvent.PACKAGES_REFRESHED, b, null));
+ }
+ }
+ };
+ FEThread t = new FEThread();
+
+ // do the actual testing
+ c.scheduleInstallOrUpdate(uri, data);
+ c.executeScheduledOperations();
assertTrue("After install, uri must be in list", c.getInstalledUris().contains(uri));
assertEquals("Digest must have been stored", data.getDigest(), c.getDigest(uri));
assertEquals("Storage data has been saved during install", 1, s.saveCounter);
data.setDigest("digest is now different");
- assertEquals("Second install returns UPDATED", UPDATED, c.scheduleInstallOrUpdate(uri, data));
+ c.scheduleInstallOrUpdate(uri, data);
+ c.executeScheduledOperations();
assertTrue("After update, uri must be in list", c.getInstalledUris().contains(uri));
assertEquals("Digest must have been updated", data.getDigest(), c.getDigest(uri));
assertEquals("Storage data has been saved during update", 2, s.saveCounter);
c.scheduleUninstall(uri);
+ c.executeScheduledOperations();
assertFalse("After uninstall, uri must not be in list", c.getInstalledUris().contains(uri));
assertEquals("Digest must be gone", null, c.getDigest(uri));
assertFalse("After getLastModified, uri must not be in list", c.getInstalledUris().contains(uri));
assertEquals("Storage data has been saved during uninstall", 3, s.saveCounter);
- final String nonJarUri = "no_jar_extension";
- assertEquals(nonJarUri + " must be ignored", c.scheduleInstallOrUpdate("", data), IGNORED);
-
// And verify expectations
mockery.assertIsSatisfied();
+ t.active = false;
}
}
Copied: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorListTest.java (from r771233, incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerGetProcessorTest.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorListTest.java?p2=incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorListTest.java&p1=incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerGetProcessorTest.java&r1=771233&r2=771287&rev=771287&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerGetProcessorTest.java (original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiResourceProcessorListTest.java Mon May 4 12:24:42 2009
@@ -26,32 +26,43 @@
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
import org.junit.runner.RunWith;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkListener;
@RunWith(JMock.class)
-public class OsgiControllerGetProcessorTest {
+public class OsgiResourceProcessorListTest {
private final Mockery mockery = new Mockery();
@org.junit.Test public void testNoProcessors() throws Exception {
- final OsgiControllerImpl c = new OsgiControllerImpl();
- Utilities.setProcessors(c);
- assertNull("Controller must return null processor for null uri", c.getProcessor(null, null));
- assertNull("Controller must return null processor for TEST uri", c.getProcessor("TEST", null));
+ final BundleContext bc = mockery.mock(BundleContext.class);
+ mockery.checking(new Expectations() {{
+ allowing(bc).addFrameworkListener(with(any(FrameworkListener.class)));
+ }});
+ final OsgiResourceProcessorList c = new OsgiResourceProcessorList(bc, null, null, null);
+ c.clear();
+ assertNull("OsgiResourceProcessorList must return null processor for null uri", c.getProcessor(null, null));
+ assertNull("OsgiResourceProcessorList must return null processor for TEST uri", c.getProcessor("TEST", null));
}
@org.junit.Test public void testTwoProcessors() throws Exception {
- final OsgiControllerImpl c = new OsgiControllerImpl();
+ final BundleContext bc = mockery.mock(BundleContext.class);
final OsgiResourceProcessor p1 = mockery.mock(OsgiResourceProcessor.class);
final OsgiResourceProcessor p2 = mockery.mock(OsgiResourceProcessor.class);
- Utilities.setProcessors(c, p1, p2);
mockery.checking(new Expectations() {{
+ allowing(bc).addFrameworkListener(with(any(FrameworkListener.class)));
allowing(p1).canProcess("foo", null) ; will(returnValue(true));
allowing(p1).canProcess("bar", null) ; will(returnValue(false));
allowing(p2).canProcess("foo", null) ; will(returnValue(false));
allowing(p2).canProcess("bar", null) ; will(returnValue(true));
}});
+ final OsgiResourceProcessorList c = new OsgiResourceProcessorList(bc, null, null, null);
+ c.clear();
+ c.add(p1);
+ c.add(p2);
+
assertEquals("foo extension must return processor p1", p1, c.getProcessor("foo", null));
assertEquals("bar extension must return processor p2", p2, c.getProcessor("bar", null));
}
Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/Utilities.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/Utilities.java?rev=771287&r1=771286&r2=771287&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/Utilities.java (original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/Utilities.java Mon May 4 12:24:42 2009
@@ -34,14 +34,6 @@
return result;
}
- static void setProcessors(OsgiControllerImpl c, OsgiResourceProcessor ... processors) throws Exception {
- final List<OsgiResourceProcessor> list = new LinkedList<OsgiResourceProcessor>();
- for(OsgiResourceProcessor p : processors) {
- list.add(p);
- }
- setField(c, "processors", list);
- }
-
static void setStorage(OsgiControllerImpl c, Storage s) throws Exception {
final Field f = c.getClass().getDeclaredField("storage");
f.setAccessible(true);