Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2010-05-11 12:15:08 +0000
committerGlyn Normington2010-05-11 12:15:08 +0000
commit5dfdbe75bdf1ba2476fe2e60e62e3454a3565de7 (patch)
tree5522099ce269769cdd39fe31fbe2d20afd416a1c /org.eclipse.virgo.kernel.deployer/src/test
parentb99bf75af622c030c6c9b479c1639925bd1ea872 (diff)
downloadorg.eclipse.virgo.kernel-5dfdbe75bdf1ba2476fe2e60e62e3454a3565de7.tar.gz
org.eclipse.virgo.kernel-5dfdbe75bdf1ba2476fe2e60e62e3454a3565de7.tar.xz
org.eclipse.virgo.kernel-5dfdbe75bdf1ba2476fe2e60e62e3454a3565de7.zip
initial checkin from dm Server kernel commit dffbc217a919cefba04886160ba820f2c6cf5f57 omitting build-kernel/bin/service
Diffstat (limited to 'org.eclipse.virgo.kernel.deployer/src/test')
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/ArtifactIdentityTests.java38
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/DeploymentOptionsTests.java65
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/StubInstallArtifactLifecycleListener.java262
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/BundleDeploymentPropertiesTransformerTests.java92
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/DeployerBlockingSignalTests.java142
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/DescopingBundleManifestTests.java275
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/ImportExpandingTransformerTests.java178
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/ManifestUpgraderTests.java166
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/SignalJunctionTests.java164
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/recovery/DeployerRecoveryLogTests.java85
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/uri/RepositoryDeployUriNormalizerTests.java231
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/hot/HotDeployerFileSystemListenerTests.java105
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/hot/HotDeployerTests.java123
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/management/RecoveryMonitorTests.java69
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractInstallArtifactTests.java127
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ArtifactStateMonitorTests.java150
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/AtomicInstallArtifactLifecycleListenerTests.java380
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PlanMemberCollectorTests.java105
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ScopeServiceRepositoryTests.java84
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/SpringConfigServiceModelScannerTests.java63
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactIdentityDeterminerTests.java109
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardInstallArtifactTreeInclosureTests.java243
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubArtifactBridge.java93
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubEventLogger.java32
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubInstallArtifactRefreshHandler.java55
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/TreeRestrictingInstallArtifactLifecycleListenerTests.java79
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/bundle/StandardBundleInstallArtifactTests.java143
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/environment/internal/StandardInstallEnvironmentTests.java43
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/AbstractPipelineStageTests.java102
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/internal/CompensatingPipelineTests.java358
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/internal/StandardPipelineTests.java269
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/TransformationStageTests.java102
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/internal/SyntheticContextBundleCreatingTransformerTests.java198
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/internal/UserInstalledTaggingTransformerTests.java49
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/META-INF/MANIFEST.MF0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/META-INF/web/index.jsp12
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/somefile.txt1
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/somefolder/.gitignore0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/malformed-application-context.jarbin0 -> 713 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/nobsn.jarbin0 -> 545 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/rawfile1
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple.jarbin0 -> 576 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple/test/rawfile1
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/test.properties1
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.B.after.jarbin0 -> 1589 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.B.before.jarbin0 -> 1331 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.C.jarbin0 -> 1641 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/app/1.0/META-INF/MANIFEST.MF5
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/hibernate/3.2.5/META-INF/MANIFEST.MF5
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/hibernate/3.2.6/META-INF/MANIFEST.MF5
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/spring/2.5.3/META-INF/MANIFEST.MF6
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/config/BundleUpdateTests/repository.properties7
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/dat/one/bundle/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/dat/two/bundle/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/debug.options4
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar1.jarbin0 -> 456 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar2.jarbin0 -> 456 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar2a.jarbin0 -> 456 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/dummy/other/ignore.txt0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/dummy/other/jar2.jarbin0 -> 715 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/exploded/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/export-same-package/root-a/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/export-same-package/root-b/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/faulty/imp/META-INF/MANIFEST.MF5
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/a1.txt0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/z/a1z.txt0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/z/file.wont.be.found0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/b/1/b1.txt0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/b/1/file.wont.be.found0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/c/1/c1.txt0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/c/c.txt0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/invalid/bundle/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/jars/dummy.jarbin0 -> 774 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/jars/mockbundle.jarbin0 -> 419 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/exploded/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/exploded/bundle.jarbin0 -> 673 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/spring-instrumented.libd4
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/spring.libd5
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/manifests/invalid-import-package.MF11
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/one.jarbin0 -> 374 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/two.jarbin0 -> 374 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/multi-root/root-a/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/multi-root/root-b/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/org/eclipse/virgo/kernel/install/artifact/internal/sbiat-bundle/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/duplicate-repository-in-chain.properties7
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/missing-chain.properties2
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/missing-repositories.properties1
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/repository.properties12
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/a.jarbin0 -> 391 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/b.jar0
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/c.jarbin0 -> 391 bytes
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/a/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/b/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/c/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/scoping/complexService.xml18
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/scoping/simpleService.xml12
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/test/dummy.txt1
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/resources/unit.test.subsystem/subsystem.xml4
100 files changed, 4949 insertions, 0 deletions
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/ArtifactIdentityTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/ArtifactIdentityTests.java
new file mode 100644
index 00000000..a796a411
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/ArtifactIdentityTests.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.virgo.kernel.deployer.ArtifactIdentity;
+import org.junit.Test;
+
+
+/**
+ * ArtifactIdentityTests
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Test thread-safe
+ *
+ */
+public class ArtifactIdentityTests {
+
+ @Test
+ public void testArtifactIdentityConstruction() {
+ ArtifactIdentity ai = new ArtifactIdentity("type","name","version");
+ assertEquals("type", ai.getType());
+ assertEquals("name", ai.getName());
+ assertEquals("version", ai.getVersion());
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/DeploymentOptionsTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/DeploymentOptionsTests.java
new file mode 100644
index 00000000..f93d26a0
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/DeploymentOptionsTests.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.core;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer.DeploymentOptions;
+import org.junit.Test;
+
+
+/**
+ * <code>DeploymentOptionsTests</code> is a simple test of the {@link DeploymentOptions} class.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * thread-safe
+ *
+ */
+public class DeploymentOptionsTests {
+
+ @Test
+ public void constructionDefault() throws Exception {
+ DeploymentOptions deploymentOptions = new DeploymentOptions();
+
+ assertOptions(deploymentOptions, "default", true, false, true);
+ }
+
+ private static void assertOptions(DeploymentOptions deploymentOptions, String name, boolean recoverable, boolean owned, boolean synchronous) {
+ assertEquals(name + " recoverable option", recoverable, deploymentOptions.getRecoverable());
+ assertEquals(name + " deployerOwned option", owned, deploymentOptions.getDeployerOwned());
+ assertEquals(name + " synchronous option", synchronous, deploymentOptions.getSynchronous());
+ }
+
+ @Test
+ public void constructionUnowned() throws Exception {
+ DeploymentOptions deploymentOptions = new DeploymentOptions(true, false, true);
+
+ assertOptions(deploymentOptions, "unowned", true, false, true);
+ }
+
+ @Test
+ public void constructionOwned() throws Exception {
+ DeploymentOptions deploymentOptions = new DeploymentOptions(true, true, true);
+
+ assertOptions(deploymentOptions, "owned", true, true, true);
+ }
+
+ @Test
+ public void constructionNonRecoverable() throws Exception {
+ DeploymentOptions deploymentOptions = new DeploymentOptions(false, false, true);
+
+ assertOptions(deploymentOptions, "non-recoverable", false, false, true);
+ }
+
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/StubInstallArtifactLifecycleListener.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/StubInstallArtifactLifecycleListener.java
new file mode 100644
index 00000000..dd403d20
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/StubInstallArtifactLifecycleListener.java
@@ -0,0 +1,262 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.core;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListener;
+
+
+public final class StubInstallArtifactLifecycleListener implements InstallArtifactLifecycleListener {
+
+ private final AtomicInteger installingCount = new AtomicInteger();
+
+ private final AtomicInteger installFailedCount = new AtomicInteger();
+
+ private final AtomicInteger installedCount = new AtomicInteger();
+
+ private final AtomicInteger resolvingCount = new AtomicInteger();
+
+ private final AtomicInteger resolveFailedCount = new AtomicInteger();
+
+ private final AtomicInteger resolvedCount = new AtomicInteger();
+
+ private final AtomicInteger startingCount = new AtomicInteger();
+
+ private final AtomicInteger startFailedCount = new AtomicInteger();
+
+ private final AtomicInteger startedCount = new AtomicInteger();
+
+ private final AtomicInteger stoppingCount = new AtomicInteger();
+
+ private final AtomicInteger stopFailedCount = new AtomicInteger();
+
+ private final AtomicInteger stoppedCount = new AtomicInteger();
+
+ private final AtomicInteger unresolvedCount = new AtomicInteger();
+
+ private final AtomicInteger uninstallingCount = new AtomicInteger();
+
+ private final AtomicInteger uninstallFailedCount = new AtomicInteger();
+
+ private final AtomicInteger uninstalledCount = new AtomicInteger();
+
+ public void assertLifecycleCounts(int starting, int started, int stopping, int stopped) {
+ assertStartingCount(starting);
+ assertStartedCount(started);
+ assertStoppingCount(stopping);
+ assertStoppedCount(stopped);
+ }
+
+ public void assertLifecycleCounts(int installing, int installFailed, int installed, int resolving, int resolveFailed, int resolved, int starting,
+ int startFailed, int started, int stopping, int stopFailed, int stopped, int uninstalling, int uninstallFailed, int uninstalled) {
+ assertInstallingCount(installing);
+ assertInstallFailedCount(installFailed);
+ assertInstalledCount(installed);
+
+ assertResolvingCount(resolving);
+ assertResolvedFailedCount(resolveFailed);
+ assertResolvedCount(resolved);
+
+ assertStartingCount(starting);
+ assertStartFailedCount(startFailed);
+ assertStartedCount(started);
+
+ assertStoppingCount(stopping);
+ assertStopFailedCount(stopFailed);
+ assertStoppedCount(stopped);
+
+ assertUninstallingCount(uninstalling);
+ assertUninstallFailedCount(uninstallFailed);
+ assertUninstalledCount(uninstalled);
+ }
+
+ public void assertInstallingCount(int installing) {
+ assertEquals("Incorrect installing count", installing, this.installingCount.get());
+ }
+
+ public void assertInstallFailedCount(int installFailed) {
+ assertEquals("Incorrect install failed count", installFailed, this.installFailedCount.get());
+ }
+
+ public void assertInstalledCount(int installed) {
+ assertEquals("Incorrect installed count", installed, this.installedCount.get());
+ }
+
+ public void assertResolvingCount(int resolving) {
+ assertEquals("Incorrect resolving count", resolving, this.resolvingCount.get());
+ }
+
+ public void assertResolvedFailedCount(int resolveFailed) {
+ assertEquals("Incorrect resolve failed count", resolveFailed, this.resolveFailedCount.get());
+ }
+
+ public void assertResolvedCount(int resolved) {
+ assertEquals("Incorrect resolved count", resolved, this.resolvedCount.get());
+ }
+
+ public void assertStartingCount(int starting) {
+ assertEquals("Incorrect starting count", starting, this.startingCount.get());
+ }
+
+ public void assertStartFailedCount(int startFailed) {
+ assertEquals("Incorrect start failed count", startFailed, this.startFailedCount.get());
+ }
+
+ public void assertStartedCount(int started) {
+ assertEquals("Incorrect started count", started, this.startedCount.get());
+ }
+
+ public void assertStoppingCount(int stopping) {
+ assertEquals("Incorrect stopping count", stopping, this.stoppingCount.get());
+ }
+
+ public void assertStopFailedCount(int stopFailed) {
+ assertEquals("Incorrect stop failed count", stopFailed, this.stopFailedCount.get());
+ }
+
+ public void assertStoppedCount(int stopped) {
+ assertEquals("Incorrect stopped count", stopped, this.stoppedCount.get());
+ }
+
+ public void assertUnresolvedCount(int unresolved) {
+ assertEquals("Incorrect unresolved count", unresolved, this.unresolvedCount.get());
+ }
+
+ public void assertUninstallingCount(int uninstalling) {
+ assertEquals("Incorrect uninstalling count", uninstalling, this.uninstallingCount.get());
+ }
+
+ public void assertUninstallFailedCount(int uninstallFailed) {
+ assertEquals("Incorrect uninstall failed count", uninstallFailed, this.uninstallFailedCount.get());
+ }
+
+ public void assertUninstalledCount(int uninstalled) {
+ assertEquals("Incorrect uninstalled count", uninstalled, this.uninstalledCount.get());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onInstalling(InstallArtifact installArtifact) {
+ this.installingCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onInstallFailed(InstallArtifact installArtifact) {
+ this.installFailedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onInstalled(InstallArtifact installArtifact) {
+ this.installedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onResolving(InstallArtifact installArtifact) {
+ this.resolvingCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onResolveFailed(InstallArtifact installArtifact) {
+ this.resolveFailedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onResolved(InstallArtifact installArtifact) {
+ this.resolvedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onStarting(InstallArtifact installArtifact) {
+ this.startingCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onStartFailed(InstallArtifact installArtifact, Throwable cause) {
+ this.startFailedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onStarted(InstallArtifact installArtifact) {
+ this.startedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onStopping(InstallArtifact installArtifact) {
+ this.stoppingCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onStopFailed(InstallArtifact installArtifact, Throwable cause) {
+ this.stopFailedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onStopped(InstallArtifact installArtifact) {
+ this.stoppedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onUnresolved(InstallArtifact installArtifact) {
+ this.unresolvedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onUninstalling(InstallArtifact installArtifact) {
+ this.uninstallingCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onUninstallFailed(InstallArtifact installArtifact, Throwable cause) {
+ this.uninstallFailedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onUninstalled(InstallArtifact installArtifact) {
+ this.uninstalledCount.incrementAndGet();
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/BundleDeploymentPropertiesTransformerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/BundleDeploymentPropertiesTransformerTests.java
new file mode 100644
index 00000000..37452171
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/BundleDeploymentPropertiesTransformerTests.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.core.internal;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+import static org.easymock.EasyMock.*;
+
+
+import org.eclipse.virgo.kernel.deployer.core.internal.BundleDeploymentPropertiesTransformer;
+import org.eclipse.virgo.kernel.install.artifact.BundleInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.util.common.ThreadSafeArrayListTree;
+import org.eclipse.virgo.util.common.Tree;
+import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
+import org.eclipse.virgo.util.osgi.manifest.BundleManifestFactory;
+
+
+public class BundleDeploymentPropertiesTransformerTests {
+
+ @Test
+ public void testTransformWithWebContextPath() throws Exception {
+ BundleManifest manifest = BundleManifestFactory.createBundleManifest();
+
+ Map<String, String> props = new HashMap<String, String>();
+ props.put("header:Web-ContextPath", "/foo");
+
+ BundleInstallArtifact artifact = createMock(BundleInstallArtifact.class);
+ expect(artifact.getDeploymentProperties()).andReturn(props);
+ expect(artifact.getBundleManifest()).andReturn(manifest);
+
+ replay(artifact);
+ Tree<InstallArtifact> tree = new ThreadSafeArrayListTree<InstallArtifact>(artifact);
+
+ BundleDeploymentPropertiesTransformer transformer = new BundleDeploymentPropertiesTransformer();
+ transformer.transform(tree, null);
+ verify(artifact);
+
+ assertEquals("/foo", manifest.getHeader("Web-ContextPath"));
+ }
+
+ @Test
+ public void testTransformWithNullProperties() throws Exception {
+ BundleManifest manifest = BundleManifestFactory.createBundleManifest();
+
+ BundleInstallArtifact artifact = createMock(BundleInstallArtifact.class);
+ expect(artifact.getDeploymentProperties()).andReturn(null);
+
+ replay(artifact);
+ Tree<InstallArtifact> tree = new ThreadSafeArrayListTree<InstallArtifact>(artifact);
+
+ BundleDeploymentPropertiesTransformer transformer = new BundleDeploymentPropertiesTransformer();
+ transformer.transform(tree, null);
+ verify(artifact);
+
+ assertNull(manifest.getHeader("Web-ContextPath"));
+ }
+
+ @Test
+ public void testTransformWithNonHeaderProperties() throws Exception {
+ BundleManifest manifest = BundleManifestFactory.createBundleManifest();
+
+ Map<String, String> props = new HashMap<String, String>();
+ props.put("Web-ContextPath", "/foo");
+
+ BundleInstallArtifact artifact = createMock(BundleInstallArtifact.class);
+ expect(artifact.getBundleManifest()).andReturn(manifest);
+ expect(artifact.getDeploymentProperties()).andReturn(props);
+
+ replay(artifact);
+ Tree<InstallArtifact> tree = new ThreadSafeArrayListTree<InstallArtifact>(artifact);
+
+ BundleDeploymentPropertiesTransformer transformer = new BundleDeploymentPropertiesTransformer();
+ transformer.transform(tree, null);
+ verify(artifact);
+
+ assertNull(manifest.getHeader("Web-ContextPath"));
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/DeployerBlockingSignalTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/DeployerBlockingSignalTests.java
new file mode 100644
index 00000000..4b66a10b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/DeployerBlockingSignalTests.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.core.internal;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.deployer.core.internal.BlockingSignal;
+import org.junit.Test;
+
+
+/**
+ */
+public class DeployerBlockingSignalTests {
+
+ private static final long TEST_PERIOD = 2; //Seconds
+
+ /**
+ * Test method for {@link org.eclipse.virgo.kernel.deployer.core.internal.BlockingSignal#awaitCompletion(long)}.
+ * @throws DeploymentException
+ */
+ @Test
+ public void testAwaitCompletionBlock() throws DeploymentException {
+ BlockingSignal blockingSignal = new BlockingSignal(true);
+ long start = System.currentTimeMillis();
+ boolean awaitCompletion = blockingSignal.awaitCompletion(TEST_PERIOD);
+ long finish = System.currentTimeMillis();
+ assertFalse(awaitCompletion);
+ assertTrue(finish - start > TEST_PERIOD * 1000);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.kernel.deployer.core.internal.BlockingSignal#awaitCompletion(long)}.
+ * @throws DeploymentException
+ */
+ @Test
+ public void testAwaitCompletionBlockSucceed() throws DeploymentException {
+ BlockingSignal blockingSignal = new BlockingSignal(true);
+ long start = System.currentTimeMillis();
+ this.launchThread(blockingSignal, TEST_PERIOD/2);
+ boolean awaitCompletion = blockingSignal.awaitCompletion(TEST_PERIOD);
+ long finish = System.currentTimeMillis();
+ assertTrue(awaitCompletion);
+ assertTrue(finish - start < TEST_PERIOD * 1000);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.kernel.deployer.core.internal.BlockingSignal#awaitCompletion(long)}.
+ * @throws DeploymentException
+ */
+ @Test
+ public void testAwaitCompletionNoBlock() throws DeploymentException {
+ BlockingSignal blockingSignal = new BlockingSignal(false);
+ long start = System.currentTimeMillis();
+ boolean awaitCompletion = blockingSignal.awaitCompletion(TEST_PERIOD);
+ long finish = System.currentTimeMillis();
+ assertFalse(awaitCompletion);
+ assertTrue(finish - start < TEST_PERIOD * 1000);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.kernel.deployer.core.internal.BlockingSignal#checkComplete()}.
+ * @throws DeploymentException
+ */
+ @Test
+ public void testCheckCompleteBlockFast() throws DeploymentException {
+ BlockingSignal blockingSignal = new BlockingSignal(true);
+ long start = System.currentTimeMillis();
+ this.launchThread(blockingSignal, TEST_PERIOD/2);
+ boolean checkCompletion = blockingSignal.checkComplete();
+ long finish = System.currentTimeMillis();
+ assertTrue(checkCompletion);
+ assertTrue(finish - start < TEST_PERIOD * 1000);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.kernel.deployer.core.internal.BlockingSignal#checkComplete()}.
+ * @throws DeploymentException
+ */
+ @Test
+ public void testCheckCompleteBlockSlow() throws DeploymentException {
+ BlockingSignal blockingSignal = new BlockingSignal(true);
+ long start = System.currentTimeMillis();
+ this.launchThread(blockingSignal, TEST_PERIOD + 1);
+ boolean checkCompletion = blockingSignal.checkComplete();
+ long finish = System.currentTimeMillis();
+ assertTrue(checkCompletion);
+ assertTrue(finish - start > TEST_PERIOD * 1000);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.virgo.kernel.deployer.core.internal.BlockingSignal#checkComplete()}.
+ * @throws DeploymentException
+ */
+ @Test
+ public void testCheckCompleteNoBlock() throws DeploymentException {
+ BlockingSignal blockingSignal = new BlockingSignal(false);
+ long start = System.currentTimeMillis();
+ boolean checkCompletion = blockingSignal.checkComplete();
+ long finish = System.currentTimeMillis();
+ assertFalse(checkCompletion);
+ assertTrue(finish - start < TEST_PERIOD * 1000);
+ }
+
+
+ private void launchThread(BlockingSignal blockingSignal, long seconds) {
+ SignalSucceeder signalSucceeder = new SignalSucceeder(blockingSignal, seconds * 1000);
+ new Thread(signalSucceeder).start();
+ }
+
+ private static class SignalSucceeder implements Runnable{
+
+ private final long timeOut;
+ private final BlockingSignal blockingSignal;
+
+ public SignalSucceeder(BlockingSignal blockingSignal, long timeOut) {
+ this.blockingSignal = blockingSignal;
+ this.timeOut = timeOut;
+ }
+
+ public void run() {
+ try {
+ Thread.sleep(this.timeOut);
+ } catch (InterruptedException e) {
+ System.out.println("Sleep interupted");
+ }
+ this.blockingSignal.signalSuccessfulCompletion();
+ }
+
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/DescopingBundleManifestTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/DescopingBundleManifestTests.java
new file mode 100644
index 00000000..47911037
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/DescopingBundleManifestTests.java
@@ -0,0 +1,275 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.core.internal;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+import static org.easymock.EasyMock.*;
+
+import org.eclipse.virgo.kernel.deployer.core.internal.DescopingBundleManifest;
+import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
+
+public class DescopingBundleManifestTests {
+
+ private BundleManifest descopingBundleManifest;
+
+ private BundleManifest mockBundleManifest;
+
+ @Before
+ public void setup() {
+ this.mockBundleManifest = createMock(BundleManifest.class);
+ this.descopingBundleManifest = new DescopingBundleManifest(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testBundleActivationPolicy() {
+ expect(this.mockBundleManifest.getBundleActivationPolicy()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getBundleActivationPolicy();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testBundleClasspath() {
+ expect(this.mockBundleManifest.getBundleClasspath()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getBundleClasspath();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testBundleDescription() {
+ expect(this.mockBundleManifest.getBundleDescription()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getBundleDescription();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testBundleManifestVersion() {
+ expect(this.mockBundleManifest.getBundleManifestVersion()).andReturn(0);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getBundleManifestVersion();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testBundleName() {
+ expect(this.mockBundleManifest.getBundleName()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getBundleName();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testBundleSymbolicName() {
+ expect(this.mockBundleManifest.getBundleSymbolicName()).andReturn(null);
+ expect(this.mockBundleManifest.getModuleScope()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getBundleSymbolicName();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testBundleUpdateLocation() {
+ expect(this.mockBundleManifest.getBundleUpdateLocation()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getBundleUpdateLocation();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testBundleVersion() {
+ expect(this.mockBundleManifest.getBundleVersion()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getBundleVersion();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testDynamicImportPackage() {
+ expect(this.mockBundleManifest.getDynamicImportPackage()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getDynamicImportPackage();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testExportPackage() {
+ expect(this.mockBundleManifest.getExportPackage()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getExportPackage();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testFragmentHost() {
+ expect(this.mockBundleManifest.getFragmentHost()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getFragmentHost();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testHeader() {
+ expect(this.mockBundleManifest.getHeader(isA(String.class))).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getHeader("");
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testImportBundle() {
+ expect(this.mockBundleManifest.getImportBundle()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getImportBundle();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testImportLibrary() {
+ expect(this.mockBundleManifest.getImportLibrary()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getImportLibrary();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testImportPackage() {
+ expect(this.mockBundleManifest.getImportPackage()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getImportPackage();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testModuleScope() {
+ expect(this.mockBundleManifest.getModuleScope()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getModuleScope();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testModuleType() {
+ expect(this.mockBundleManifest.getModuleType()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getModuleType();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testRequireBundle() {
+ expect(this.mockBundleManifest.getRequireBundle()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.getRequireBundle();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testSetBundleDescription() {
+ this.mockBundleManifest.setBundleDescription(isA(String.class));
+ expectLastCall();
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.setBundleDescription("");
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testSetBundleManifestVersion() {
+ this.mockBundleManifest.setBundleManifestVersion(eq(0));
+ expectLastCall();
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.setBundleManifestVersion(0);
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testSetBundleName() {
+ this.mockBundleManifest.setBundleName(isA(String.class));
+ expectLastCall();
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.setBundleName("");
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testSetBundleUpdateLocation() throws MalformedURLException {
+ this.mockBundleManifest.setBundleUpdateLocation(isA(URL.class));
+ expectLastCall();
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.setBundleUpdateLocation(new URL("http://blah"));
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testSetBundleVersion() {
+ this.mockBundleManifest.setBundleVersion(isA(Version.class));
+ expectLastCall();
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.setBundleVersion(Version.emptyVersion);
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testSetHeader() {
+ this.mockBundleManifest.setHeader(isA(String.class), isA(String.class));
+ expectLastCall();
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.setHeader("", "");
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testSetModuleScope() {
+ this.mockBundleManifest.setModuleScope(isA(String.class));
+ expectLastCall();
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.setModuleScope("");
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testSetModuleType() {
+ this.mockBundleManifest.setModuleType(isA(String.class));
+ expectLastCall();
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.setModuleType("");
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testToDictionary() {
+ expect(this.mockBundleManifest.toDictionary()).andReturn(null);
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.toDictionary();
+ verify(this.mockBundleManifest);
+ }
+
+ @Test
+ public void testWrite() throws IOException {
+ this.mockBundleManifest.write(isA(Writer.class));
+ expectLastCall();
+ replay(this.mockBundleManifest);
+ this.descopingBundleManifest.write(new StringWriter());
+ verify(this.mockBundleManifest);
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/ImportExpandingTransformerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/ImportExpandingTransformerTests.java
new file mode 100644
index 00000000..7b0244c1
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/ImportExpandingTransformerTests.java
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.core.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+import org.eclipse.virgo.kernel.osgi.framework.ImportMergeException;
+import org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyDependenciesException;
+import org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyLibraryDependenciesException;
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.deployer.core.internal.ImportExpandingTransformer;
+import org.eclipse.virgo.kernel.install.artifact.BundleInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.environment.InstallEnvironment;
+import org.eclipse.virgo.kernel.install.environment.InstallLog;
+import org.eclipse.virgo.util.common.ThreadSafeArrayListTree;
+import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
+import org.eclipse.virgo.util.osgi.manifest.BundleManifestFactory;
+
+/**
+ */
+// TODO Improve the tests to check that the right number of bundles is passed to expandImports
+// TODO Improve the tests to check that bundles in scoped plans are processed as a group
+public class ImportExpandingTransformerTests {
+
+ private BundleInstallArtifact bundleIinstallArtifact;
+
+ private InstallEnvironment installEnvironment;
+
+ private BundleManifest bundleManifest;
+
+ private org.eclipse.virgo.kernel.osgi.framework.ImportExpander importExpander;
+
+ private InstallLog installLog;
+
+ @Before
+ public void setUp() throws Exception {
+ this.bundleIinstallArtifact = createMock(BundleInstallArtifact.class);
+ this.installEnvironment = createMock(InstallEnvironment.class);
+ this.importExpander = createMock(org.eclipse.virgo.kernel.osgi.framework.ImportExpander.class);
+ this.installLog = createMock(InstallLog.class);
+ this.bundleManifest = BundleManifestFactory.createBundleManifest();
+ }
+
+ @After
+ public void tearDown() {
+ resetMocks();
+ }
+
+ private void replayMocks() {
+ replay(this.bundleIinstallArtifact, this.installEnvironment, this.importExpander, this.installLog);
+ }
+
+ private void verifyMocks() {
+ verify(this.bundleIinstallArtifact, this.installEnvironment, this.importExpander, this.installLog);
+ }
+
+ private void resetMocks() {
+ reset(this.bundleIinstallArtifact, this.installEnvironment, this.importExpander, this.installLog);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testNormalCase() throws DeploymentException, IOException, ImportMergeException, UnableToSatisfyDependenciesException {
+
+ this.bundleManifest.getImportLibrary().addImportedLibrary("lib");
+
+ expect(this.bundleIinstallArtifact.getBundleManifest()).andReturn(this.bundleManifest);
+ expect(this.importExpander.expandImports(isA(List.class))).andReturn(null);
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog);
+ this.installLog.log(isA(Object.class), isA(String.class), isA(String.class));
+ expectLastCall();
+
+ replayMocks();
+
+ ImportExpandingTransformer importExpander = new ImportExpandingTransformer(this.importExpander);
+ importExpander.transform(new ThreadSafeArrayListTree<InstallArtifact>(bundleIinstallArtifact), installEnvironment);
+
+ verifyMocks();
+ }
+
+ @Test
+ public void testBundleManifestIOException() throws Exception {
+
+ this.bundleManifest.getImportLibrary().addImportedLibrary("lib");
+
+ expect(this.bundleIinstallArtifact.getBundleManifest()).andThrow(new IOException());
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog);
+ this.installLog.log(isA(Object.class), isA(String.class), isA(String.class));
+ expectLastCall();
+
+ replayMocks();
+
+ ImportExpandingTransformer importExpander = new ImportExpandingTransformer(this.importExpander);
+ try {
+ importExpander.transform(new ThreadSafeArrayListTree<InstallArtifact>(bundleIinstallArtifact), installEnvironment);
+ } catch (DeploymentException e) {
+ assertTrue(e.getCause() instanceof IOException);
+ }
+
+ verifyMocks();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testImportMergeException() throws Exception {
+
+ this.bundleManifest.getImportLibrary().addImportedLibrary("lib");
+
+ expect(this.bundleIinstallArtifact.getBundleManifest()).andReturn(this.bundleManifest);
+ expect(this.importExpander.expandImports(isA(List.class))).andThrow(new ImportMergeException("pkg", "src1", "src2"));
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog);
+ this.installLog.log(isA(Object.class), isA(String.class), isA(String.class), isA(String.class), isA(String.class));
+ expectLastCall();
+
+ replayMocks();
+
+ ImportExpandingTransformer importExpander = new ImportExpandingTransformer(this.importExpander);
+ try {
+ importExpander.transform(new ThreadSafeArrayListTree<InstallArtifact>(bundleIinstallArtifact), installEnvironment);
+ } catch (DeploymentException e) {
+ assertTrue(e.getCause() instanceof ImportMergeException);
+ }
+
+ verifyMocks();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testUnableToSatisfyDependenciesException() throws Exception {
+
+ this.bundleManifest.getImportLibrary().addImportedLibrary("lib");
+
+ expect(this.bundleIinstallArtifact.getBundleManifest()).andReturn(this.bundleManifest);
+ expect(this.importExpander.expandImports(isA(List.class))).andThrow(
+ new UnableToSatisfyLibraryDependenciesException("sym", new Version("0"), "fail"));
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog);
+ this.installLog.log(isA(Object.class), isA(String.class), isA(String.class), isA(String.class));
+ expectLastCall();
+
+ replayMocks();
+
+ ImportExpandingTransformer importExpander = new ImportExpandingTransformer(this.importExpander);
+ try {
+ importExpander.transform(new ThreadSafeArrayListTree<InstallArtifact>(bundleIinstallArtifact), installEnvironment);
+ } catch (DeploymentException e) {
+ assertTrue(e.getCause() instanceof UnableToSatisfyLibraryDependenciesException);
+ }
+
+ verifyMocks();
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/ManifestUpgraderTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/ManifestUpgraderTests.java
new file mode 100644
index 00000000..0f7821e5
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/ManifestUpgraderTests.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.core.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
+import java.net.URL;
+
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.deployer.core.internal.ManifestUpgrader;
+import org.eclipse.virgo.kernel.install.artifact.BundleInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.environment.InstallEnvironment;
+import org.eclipse.virgo.kernel.install.environment.InstallLog;
+import org.eclipse.virgo.repository.Repository;
+import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
+import org.eclipse.virgo.util.osgi.manifest.internal.StandardBundleManifest;
+
+public class ManifestUpgraderTests {
+
+ private static final String BUNDLE_SYMBOLIC_NAME = "testBundleName";
+
+ private static final Version BUNDLE_VERSION = Version.emptyVersion;
+
+ private final ManifestUpgrader upgrader = new ManifestUpgrader();
+
+ private final BundleInstallArtifact installArtifact = createMock(BundleInstallArtifact.class);
+
+ private final InstallEnvironment installEnvironment = new StubInstallEnvironment();
+
+ @Test
+ public void notBundleInstallArtifact() throws DeploymentException {
+ this.upgrader.operate(null, null);
+
+ InstallArtifact mock = createMock(InstallArtifact.class);
+ replay(mock);
+ this.upgrader.operate(mock, this.installEnvironment);
+ verify(mock);
+ }
+
+ @Test(expected = DeploymentException.class)
+ public void noAppManifest() throws DeploymentException, IOException {
+ expect(this.installArtifact.getBundleManifest()).andThrow(new IOException());
+ expect(this.installArtifact.getName()).andReturn(BUNDLE_SYMBOLIC_NAME);
+ expect(this.installArtifact.getVersion()).andReturn(BUNDLE_VERSION);
+ replay(this.installArtifact);
+ this.upgrader.operate(this.installArtifact, this.installEnvironment);
+ }
+
+ @Test
+ public void noUpgradeManifest() throws IOException, DeploymentException {
+ BundleManifest bundleManifest = new StandardBundleManifest(null);
+ bundleManifest.setBundleManifestVersion(2);
+ bundleManifest.getBundleSymbolicName().setSymbolicName(BUNDLE_SYMBOLIC_NAME);
+ expect(this.installArtifact.getBundleManifest()).andReturn(bundleManifest);
+ replay(this.installArtifact);
+ this.upgrader.operate(this.installArtifact, this.installEnvironment);
+ verify(this.installArtifact);
+ }
+
+ @Test
+ public void upgradeManifest() throws IOException, DeploymentException {
+ BundleManifest bundleManifest = new StandardBundleManifest(null);
+ bundleManifest.getBundleSymbolicName().setSymbolicName(BUNDLE_SYMBOLIC_NAME);
+ expect(this.installArtifact.getBundleManifest()).andReturn(bundleManifest);
+ replay(this.installArtifact);
+ this.upgrader.operate(this.installArtifact, this.installEnvironment);
+ verify(this.installArtifact);
+ assertEquals(2, bundleManifest.getBundleManifestVersion());
+ assertEquals(BUNDLE_SYMBOLIC_NAME, bundleManifest.getBundleSymbolicName().getSymbolicName());
+ }
+
+ @Test
+ public void upgradeManifestNoSymbolicName() throws IOException, DeploymentException {
+ BundleManifest bundleManifest = new StandardBundleManifest(null);
+ expect(this.installArtifact.getBundleManifest()).andReturn(bundleManifest);
+ expect(this.installArtifact.getName()).andReturn(BUNDLE_SYMBOLIC_NAME);
+ replay(this.installArtifact);
+ this.upgrader.operate(this.installArtifact, this.installEnvironment);
+ verify(this.installArtifact);
+ assertEquals(2, bundleManifest.getBundleManifestVersion());
+ assertEquals(BUNDLE_SYMBOLIC_NAME, bundleManifest.getBundleSymbolicName().getSymbolicName());
+ }
+
+ @Test(expected = DeploymentException.class)
+ public void invalidManifest() throws IOException, DeploymentException {
+ BundleManifest bundleManifest = new StandardBundleManifest(null);
+ bundleManifest.setBundleManifestVersion(2);
+ expect(this.installArtifact.getBundleManifest()).andReturn(bundleManifest);
+ expect(this.installArtifact.getName()).andReturn(BUNDLE_SYMBOLIC_NAME);
+ expect(this.installArtifact.getVersion()).andReturn(BUNDLE_VERSION);
+ replay(this.installArtifact);
+ this.upgrader.operate(this.installArtifact, this.installEnvironment);
+ }
+
+ @Test
+ public void validManifest() throws IOException, DeploymentException {
+ BundleManifest bundleManifest = new StandardBundleManifest(null);
+ bundleManifest.setBundleManifestVersion(2);
+ bundleManifest.getBundleSymbolicName().setSymbolicName(BUNDLE_SYMBOLIC_NAME);
+ expect(this.installArtifact.getBundleManifest()).andReturn(bundleManifest);
+ replay(this.installArtifact);
+ this.upgrader.operate(this.installArtifact, this.installEnvironment);
+ verify(this.installArtifact);
+ }
+
+ @Test
+ public void bundleUpdateLocation() throws IOException, DeploymentException {
+ BundleManifest bundleManifest = new StandardBundleManifest(null);
+ bundleManifest.setBundleUpdateLocation(new URL("file:///"));
+ expect(this.installArtifact.getBundleManifest()).andReturn(bundleManifest);
+ expect(this.installArtifact.getName()).andReturn(BUNDLE_SYMBOLIC_NAME).anyTimes();
+ expect(this.installArtifact.getVersion()).andReturn(BUNDLE_VERSION).anyTimes();
+ replay(this.installArtifact);
+ this.upgrader.operate(this.installArtifact, this.installEnvironment);
+ verify(this.installArtifact);
+ assertNull(bundleManifest.getBundleUpdateLocation());
+ }
+
+ @Test
+ public void noBundleUpdateLocation() throws IOException, DeploymentException {
+ BundleManifest bundleManifest = new StandardBundleManifest(null);
+ bundleManifest.setBundleManifestVersion(2);
+ bundleManifest.getBundleSymbolicName().setSymbolicName(BUNDLE_SYMBOLIC_NAME);
+ expect(this.installArtifact.getBundleManifest()).andReturn(bundleManifest);
+ replay(this.installArtifact);
+ this.upgrader.operate(this.installArtifact, this.installEnvironment);
+ verify(this.installArtifact);
+ }
+
+ private static class StubInstallEnvironment implements InstallEnvironment {
+
+ public InstallLog getInstallLog() {
+ return createMock(InstallLog.class);
+ }
+
+ public QuasiFramework getQuasiFramework() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Repository getRepository() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/SignalJunctionTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/SignalJunctionTests.java
new file mode 100644
index 00000000..d8b3fd8e
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/SignalJunctionTests.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.core.internal;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.virgo.kernel.core.Signal;
+import org.eclipse.virgo.kernel.deployer.core.internal.SignalJunction;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ */
+public class SignalJunctionTests {
+
+ private Signal signal;
+
+ private boolean signalCompleted;
+
+ private boolean signalFailed;
+
+ @Before
+ public void setUp() {
+ this.signalCompleted = false;
+ this.signalFailed = false;
+ this.signal = new Signal() {
+
+ public void signalFailure(Throwable cause) {
+ signalFailed = true;
+ }
+
+ public void signalSuccessfulCompletion() {
+ signalCompleted = true;
+ }
+
+ };
+ }
+
+ @Test
+ public void testEmptyJunction() {
+ new SignalJunction(this.signal, 0);
+ assertTrue(this.signalCompleted);
+ assertFalse(this.signalFailed);
+ }
+
+ @Test
+ public void testUnaryJunction() {
+ SignalJunction sj = new SignalJunction(this.signal, 1);
+ sj.getSignals().get(0).signalSuccessfulCompletion();
+ assertTrue(this.signalCompleted);
+ assertFalse(this.signalFailed);
+ }
+
+ @Test
+ public void testBinaryJunction() {
+ SignalJunction sj = new SignalJunction(this.signal, 2);
+ sj.getSignals().get(0).signalSuccessfulCompletion();
+ sj.getSignals().get(1).signalSuccessfulCompletion();
+ assertTrue(this.signalCompleted);
+ assertFalse(this.signalFailed);
+ }
+
+ @Test
+ public void testNestedBinaryJunctionOrder1() {
+ SignalJunction top = new SignalJunction(this.signal, 2);
+ Signal top1 = top.getSignals().get(0);
+ Signal top2 = top.getSignals().get(1);
+ SignalJunction bottom = new SignalJunction(top2, 2);
+ Signal bottom1 = bottom.getSignals().get(0);
+ Signal bottom2 = bottom.getSignals().get(1);
+ top1.signalSuccessfulCompletion();
+ bottom1.signalSuccessfulCompletion();
+ bottom2.signalSuccessfulCompletion();
+ assertTrue(this.signalCompleted);
+ assertFalse(this.signalFailed);
+ }
+
+ @Test
+ public void testNestedBinaryJunctionOrder2() {
+ SignalJunction top = new SignalJunction(this.signal, 2);
+ Signal top1 = top.getSignals().get(0);
+ Signal top2 = top.getSignals().get(1);
+ SignalJunction bottom = new SignalJunction(top2, 2);
+ Signal bottom1 = bottom.getSignals().get(0);
+ Signal bottom2 = bottom.getSignals().get(1);
+ bottom1.signalSuccessfulCompletion();
+ top1.signalSuccessfulCompletion();
+ bottom2.signalSuccessfulCompletion();
+ assertTrue(this.signalCompleted);
+ assertFalse(this.signalFailed);
+ }
+
+ @Test
+ public void testNestedBinaryJunctionOrder3() {
+ SignalJunction top = new SignalJunction(this.signal, 2);
+ Signal top1 = top.getSignals().get(0);
+ Signal top2 = top.getSignals().get(1);
+ SignalJunction bottom = new SignalJunction(top2, 2);
+ Signal bottom1 = bottom.getSignals().get(0);
+ Signal bottom2 = bottom.getSignals().get(1);
+ bottom1.signalSuccessfulCompletion();
+ bottom2.signalSuccessfulCompletion();
+ top1.signalSuccessfulCompletion();
+ assertTrue(this.signalCompleted);
+ assertFalse(this.signalFailed);
+ }
+
+ @Test
+ public void testNestedBinaryJunctionOrder4() {
+ SignalJunction top = new SignalJunction(this.signal, 2);
+ Signal top1 = top.getSignals().get(0);
+ Signal top2 = top.getSignals().get(1);
+ SignalJunction bottom = new SignalJunction(top2, 2);
+ Signal bottom1 = bottom.getSignals().get(0);
+ Signal bottom2 = bottom.getSignals().get(1);
+ top1.signalSuccessfulCompletion();
+ bottom2.signalSuccessfulCompletion();
+ bottom1.signalSuccessfulCompletion();
+ assertTrue(this.signalCompleted);
+ assertFalse(this.signalFailed);
+ }
+
+ @Test
+ public void testNestedBinaryJunctionOrder5() {
+ SignalJunction top = new SignalJunction(this.signal, 2);
+ Signal top1 = top.getSignals().get(0);
+ Signal top2 = top.getSignals().get(1);
+ SignalJunction bottom = new SignalJunction(top2, 2);
+ Signal bottom1 = bottom.getSignals().get(0);
+ Signal bottom2 = bottom.getSignals().get(1);
+ bottom2.signalSuccessfulCompletion();
+ top1.signalSuccessfulCompletion();
+ bottom1.signalSuccessfulCompletion();
+ assertTrue(this.signalCompleted);
+ assertFalse(this.signalFailed);
+ }
+
+ @Test
+ public void testNestedBinaryJunctionOrder6() {
+ SignalJunction top = new SignalJunction(this.signal, 2);
+ Signal top1 = top.getSignals().get(0);
+ Signal top2 = top.getSignals().get(1);
+ SignalJunction bottom = new SignalJunction(top2, 2);
+ Signal bottom1 = bottom.getSignals().get(0);
+ Signal bottom2 = bottom.getSignals().get(1);
+ bottom2.signalSuccessfulCompletion();
+ bottom1.signalSuccessfulCompletion();
+ top1.signalSuccessfulCompletion();
+ assertTrue(this.signalCompleted);
+ assertFalse(this.signalFailed);
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/recovery/DeployerRecoveryLogTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/recovery/DeployerRecoveryLogTests.java
new file mode 100644
index 00000000..a8e4ddf4
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/recovery/DeployerRecoveryLogTests.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.core.internal.recovery;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer;
+import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer.DeploymentOptions;
+import org.eclipse.virgo.kernel.deployer.core.internal.recovery.DeployerRecoveryLog;
+import org.eclipse.virgo.util.io.PathReference;
+
+public class DeployerRecoveryLogTests {
+
+ private PathReference deployArea = new PathReference("target/deployArea");
+
+ @Before
+ public void cleanup() {
+ deployArea.delete(true);
+ deployArea.createDirectory();
+ }
+
+ @Test
+ public void emptyLog() {
+ DeployerRecoveryLog log = new DeployerRecoveryLog(deployArea);
+ assertEquals(0, log.getRecoveryState().size());
+ }
+
+ @Test
+ public void recovery() {
+ DeployerRecoveryLog log = new DeployerRecoveryLog(deployArea);
+ URI app1 = new File("app/one").toURI();
+ log.add(app1, new ApplicationDeployer.DeploymentOptions(true, true, true));
+ URI app2 = new File("app/two").toURI();
+ log.add(app2, new ApplicationDeployer.DeploymentOptions(true, false, true));
+
+ log = new DeployerRecoveryLog(deployArea);
+
+ Map<URI, DeploymentOptions> recoveryState = log.getRecoveryState();
+ assertEquals(2, recoveryState.size());
+
+ DeploymentOptions app1Options = recoveryState.remove(app1);
+ assertNotNull(app1Options);
+ assertTrue(app1Options.getDeployerOwned());
+ assertTrue(app1Options.getRecoverable());
+
+ DeploymentOptions app2Options = recoveryState.remove(app2);
+ assertNotNull(app2Options);
+ assertFalse(app2Options.getDeployerOwned());
+ assertTrue(app2Options.getRecoverable());
+
+ assertEquals(0, recoveryState.size());
+ }
+
+ @Test
+ public void rewrite() {
+ DeployerRecoveryLog log = new DeployerRecoveryLog(deployArea);
+ URI app1 = new File("app/one").toURI();
+ for (int i = 0; i < 100; i++) {
+ log.add(app1, new ApplicationDeployer.DeploymentOptions(true, true, true));
+ if (i < 99) {
+ log.remove(app1);
+ }
+ }
+ assertEquals(1, log.getRecoveryState().size());
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/uri/RepositoryDeployUriNormalizerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/uri/RepositoryDeployUriNormalizerTests.java
new file mode 100644
index 00000000..eb9de1bb
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/core/internal/uri/RepositoryDeployUriNormalizerTests.java
@@ -0,0 +1,231 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.core.internal.uri;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+import org.eclipse.virgo.kernel.deployer.core.DeployerLogEvents;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.deployer.core.internal.uri.RepositoryDeployUriNormaliser;
+import org.eclipse.virgo.medic.eventlog.Level;
+import org.eclipse.virgo.medic.test.eventlog.LoggedEvent;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.repository.Attribute;
+import org.eclipse.virgo.repository.Repository;
+import org.eclipse.virgo.repository.RepositoryAwareArtifactDescriptor;
+import org.eclipse.virgo.util.osgi.VersionRange;
+
+public class RepositoryDeployUriNormalizerTests {
+
+ private static final String REPO_NAME = "a repo";
+
+ private static final String BUNDLE_VERSION = "6";
+
+ private static final VersionRange BUNDLE_VERSION_RANGE = VersionRange.createExactRange(new Version(BUNDLE_VERSION));
+
+ private static final String BUNDLE_SYMBOLIC_NAME = "foo";
+
+ private static final String BUNDLE_TYPE = "bundle";
+
+ private static final String REPO_URI = "repository:" + BUNDLE_TYPE + "/" + BUNDLE_SYMBOLIC_NAME + "/" + BUNDLE_VERSION;
+
+ private static final URI NORMALISED = URI.create("normalised://normal");
+
+ private final Repository repository = createMock(Repository.class);
+
+ private final MockEventLogger eventLogger = new MockEventLogger();
+
+ private final RepositoryDeployUriNormaliser normaliser = new RepositoryDeployUriNormaliser(repository, eventLogger);
+
+ private final RepositoryAwareArtifactDescriptor artifactDescriptor = new StubArtifactDescriptor();
+
+ @Test
+ public void normaliseUriWithVersion() throws DeploymentException {
+ URI uri = URI.create("repository:bundle/foo/1.0.0");
+
+ expect(repository.get(BUNDLE_TYPE, BUNDLE_SYMBOLIC_NAME, new VersionRange("[1.0.0,1.0.0]"))).andReturn(artifactDescriptor);
+
+ replay(this.repository);
+
+ URI normalised = this.normaliser.normalise(uri);
+
+ verify(this.repository);
+
+ assertEquals(NORMALISED, normalised);
+
+ assertEquals(0, this.eventLogger.getLoggedEvents().size());
+ }
+
+ @Test
+ public void normaliseUriWithoutVersion() throws DeploymentException {
+ URI uri = URI.create("repository:bundle/foo");
+
+ expect(repository.get(BUNDLE_TYPE, BUNDLE_SYMBOLIC_NAME, VersionRange.NATURAL_NUMBER_RANGE)).andReturn(artifactDescriptor);
+
+ replay(this.repository);
+
+ URI normalised = this.normaliser.normalise(uri);
+
+ verify(this.repository);
+
+ assertEquals(NORMALISED, normalised);
+
+ assertEquals(0, this.eventLogger.getLoggedEvents().size());
+ }
+
+ @Test(expected = DeploymentException.class)
+ public void normaliseMalformedUri() throws DeploymentException {
+ URI uri = URI.create("repository:bundle");
+
+ replay(this.repository);
+ URI normalised = null;
+ try {
+ normalised = this.normaliser.normalise(uri);
+ } finally {
+ verify(this.repository);
+
+ assertNull(normalised);
+
+ assertEquals(1, this.eventLogger.getLoggedEvents().size());
+ assertEquals(uri, this.eventLogger.getLoggedEvents().get(0).getInserts()[0]);
+ assertEquals(DeployerLogEvents.REPOSITORY_DEPLOYMENT_URI_MALFORMED.getEventCode(), this.eventLogger.getLoggedEvents().get(0).getCode());
+ assertEquals(Level.ERROR, this.eventLogger.getLoggedEvents().get(0).getLevel());
+ }
+ }
+
+ @Test(expected = DeploymentException.class)
+ public void normaliseUriWithInvalidVersion() throws DeploymentException {
+ URI uri = URI.create("repository:bundle/foo/6-7");
+
+ replay(this.repository);
+ URI normalised = null;
+ try {
+ normalised = this.normaliser.normalise(uri);
+ } finally {
+ verify(this.repository);
+
+ assertNull(normalised);
+
+ assertEquals(1, this.eventLogger.getLoggedEvents().size());
+ assertEquals("6-7", this.eventLogger.getLoggedEvents().get(0).getInserts()[0]);
+ assertEquals(uri, this.eventLogger.getLoggedEvents().get(0).getInserts()[1]);
+ assertEquals(DeployerLogEvents.REPOSITORY_DEPLOYMENT_INVALID_VERSION.getEventCode(), this.eventLogger.getLoggedEvents().get(0).getCode());
+ assertEquals(Level.ERROR, this.eventLogger.getLoggedEvents().get(0).getLevel());
+ }
+ }
+
+ @Test(expected = DeploymentException.class)
+ public void normaliseUriOfNonExistentArtifact() throws DeploymentException {
+ URI uri = URI.create(REPO_URI);
+
+ expect(repository.getName()).andReturn(REPO_NAME);
+ expect(repository.get(BUNDLE_TYPE, BUNDLE_SYMBOLIC_NAME, BUNDLE_VERSION_RANGE)).andReturn(null);
+
+ replay(this.repository);
+
+ try {
+ this.normaliser.normalise(uri);
+ } finally {
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertEquals(1, loggedEvents.size());
+ LoggedEvent loggedEvent = loggedEvents.get(0);
+ assertEquals(Level.ERROR, loggedEvent.getLevel());
+ assertEquals(DeployerLogEvents.ARTIFACT_NOT_FOUND.getEventCode(), loggedEvent.getCode());
+
+ Object[] inserts = loggedEvent.getInserts();
+ assertEquals(4, inserts.length);
+
+ Object type = inserts[0];
+ assertEquals(BUNDLE_TYPE, type);
+
+ Object name = inserts[1];
+ assertEquals(BUNDLE_SYMBOLIC_NAME, name);
+
+ Object versionRange = inserts[2];
+ assertEquals(BUNDLE_VERSION_RANGE, versionRange);
+
+ Object repoName = inserts[3];
+ assertEquals(REPO_NAME, repoName);
+ }
+ }
+
+ private static final class StubArtifactDescriptor implements RepositoryAwareArtifactDescriptor {
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<Attribute> getAttribute(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<Attribute> getAttributes() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getFilename() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getRepositoryName() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getType() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public URI getUri() {
+ return NORMALISED;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Version getVersion() {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/hot/HotDeployerFileSystemListenerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/hot/HotDeployerFileSystemListenerTests.java
new file mode 100644
index 00000000..d2617d58
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/hot/HotDeployerFileSystemListenerTests.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.hot;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.io.File;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
+import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer.DeploymentOptions;
+import org.eclipse.virgo.kernel.deployer.hot.HotDeploymentFileSystemListener;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.util.io.FileSystemEvent;
+
+public class HotDeployerFileSystemListenerTests {
+
+ private HotDeploymentFileSystemListener listener;
+
+ private ApplicationDeployer deployer;
+
+ private DeploymentIdentity deploymentIdentity;
+
+ @Before
+ public void initialise() {
+ deployer = createMock(ApplicationDeployer.class);
+ listener = new HotDeploymentFileSystemListener(deployer, new MockEventLogger());
+ deploymentIdentity = createMock(DeploymentIdentity.class);
+ }
+
+ @Test
+ public void appCreated() throws Exception {
+ File app = new File("path/to/app");
+ expect(deployer.deploy(eq(app.toURI()), isA(DeploymentOptions.class))).andReturn(deploymentIdentity);
+ replay(deployer);
+ listener.onChange("path/to/app", FileSystemEvent.CREATED);
+ verify(deployer);
+ }
+
+ @Test
+ public void newAppDuringStartup() throws Exception {
+ File app = new File("path/to/app");
+ expect(deployer.isDeployed(app.toURI())).andReturn(false);
+ expect(deployer.deploy(eq(app.toURI()), isA(DeploymentOptions.class))).andReturn(deploymentIdentity);
+ replay(deployer);
+ listener.onChange("path/to/app", FileSystemEvent.INITIAL);
+ verify(deployer);
+ }
+
+ @Test
+ public void existingAppDuringStartup() throws Exception {
+ File app = new File("path/to/app");
+ expect(deployer.isDeployed(app.toURI())).andReturn(true);
+ replay(deployer);
+ listener.onChange("path/to/app", FileSystemEvent.INITIAL);
+ verify(deployer);
+ }
+
+ @Test
+ public void appModified() throws Exception {
+ File app = new File("path/to/app");
+ expect(deployer.deploy(eq(app.toURI()), isA(DeploymentOptions.class))).andReturn(deploymentIdentity);
+ replay(deployer);
+ listener.onChange("path/to/app", FileSystemEvent.MODIFIED);
+ verify(deployer);
+ }
+
+ @Test
+ public void appDeleted() throws Exception {
+ File app = new File("path/to/app");
+ expect(deployer.getDeploymentIdentity(app.toURI())).andReturn(this.deploymentIdentity);
+ deployer.undeploy(this.deploymentIdentity);
+
+ replay(deployer);
+ listener.onChange("path/to/app", FileSystemEvent.DELETED);
+ verify(deployer);
+ }
+
+ @Test
+ public void nonexistentAppDeleted() throws Exception {
+ File app = new File("path/to/app");
+ expect(deployer.getDeploymentIdentity(app.toURI())).andReturn(null);
+ replay(deployer);
+ listener.onChange("path/to/app", FileSystemEvent.DELETED);
+ verify(deployer);
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/hot/HotDeployerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/hot/HotDeployerTests.java
new file mode 100644
index 00000000..e637ef8f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/hot/HotDeployerTests.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.hot;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.service.event.Event;
+
+import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer;
+import org.eclipse.virgo.kernel.deployer.core.DeployerConfiguration;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
+import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer.DeploymentOptions;
+import org.eclipse.virgo.kernel.deployer.hot.HotDeployer;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.util.io.PathReference;
+
+/**
+ */
+public class HotDeployerTests {
+
+ private static final PathReference PICKUP_DIR = new PathReference("target/pickup");
+
+ private ApplicationDeployer deployer;
+
+ @Before
+ public void setUp() {
+ PICKUP_DIR.createDirectory();
+ }
+
+ @After
+ public void cleanUp() {
+ PICKUP_DIR.delete(true);
+ }
+
+ @Test
+ public void deploy() throws Exception {
+ PathReference sourceFile = new PathReference("src/test/resources/test/dummy.txt");
+ assertTrue(sourceFile.exists());
+
+ this.deployer = createMock(ApplicationDeployer.class);
+ DeploymentIdentity deploymentIdentity = new DeploymentIdentity() {
+
+ private static final long serialVersionUID = 1L;
+
+ public String getType() {
+ return null;
+ }
+
+ public String getSymbolicName() {
+ return null;
+ }
+
+ public String getVersion() {
+ return null;
+ }
+
+ };
+ this.deployer.deploy(isA(URI.class), isA(DeploymentOptions.class));
+ expectLastCall().andReturn(deploymentIdentity);
+ replay(this.deployer);
+
+ DeployerConfiguration deployerConfiguration = createMock(DeployerConfiguration.class);
+ expect(deployerConfiguration.getDeploymentPickupDirectory()).andReturn(new PathReference("target/pickup"));
+
+ replay(deployerConfiguration);
+
+ HotDeployer deployer = new HotDeployer(deployerConfiguration, this.deployer, new MockEventLogger());
+ deployer.handleEvent(new Event("org/eclipse/virgo/kernel/deployer/recovery/COMPLETED", null));
+
+ try {
+ // Deployer.start() is asynchronous: sleep long
+ // enough for it to have started up
+ Thread.sleep(2000);
+ } catch (InterruptedException ie) {
+
+ }
+
+ PathReference copy = sourceFile.copy(PICKUP_DIR);
+ pauseOnCreate(copy, 4000, 4000);
+ deployer.stop();
+
+ verify(this.deployer);
+ }
+
+ private void pauseOnCreate(PathReference pr, long pause, long timeout) {
+ long start = System.currentTimeMillis();
+
+ while (!pr.exists() && System.currentTimeMillis() - start < timeout) {
+ sleep(100);
+ }
+ if (pr.exists()) {
+ sleep(pause);
+ }
+ }
+
+ private void sleep(long millis) {
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException e) {
+
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/management/RecoveryMonitorTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/management/RecoveryMonitorTests.java
new file mode 100644
index 00000000..b5e6a33e
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/management/RecoveryMonitorTests.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.deployer.management;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.management.ManagementFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.eclipse.virgo.kernel.deployer.management.StandardRecoveryMonitor;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.service.event.Event;
+
+/**
+ */
+public class RecoveryMonitorTests {
+
+ private ObjectName objectName;
+
+ private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+
+ @Before public void before() throws Exception {
+ this.objectName = ObjectName.getInstance("deployer:name=Recovery,env=Test");
+ }
+
+ public void after() throws Exception {
+ if (this.server.isRegistered(this.objectName)) {
+ this.server.unregisterMBean(this.objectName);
+ }
+ }
+
+ @Test public void testRecoveryNotification() throws Exception {
+ StandardRecoveryMonitor mbean = new StandardRecoveryMonitor();
+ this.server.registerMBean(mbean, this.objectName);
+ assertFalse(queryRecoveryComplete());
+ final AtomicInteger counter = new AtomicInteger(0);
+ this.server.addNotificationListener(this.objectName, new NotificationListener() {
+
+ public void handleNotification(Notification notification, Object handback) {
+ counter.incrementAndGet();
+ }
+
+ }, null, null);
+ mbean.handleEvent(new Event("org/eclipse/virgo/kernel/deployer/recovery/COMPLETED", null));
+ assertTrue(queryRecoveryComplete());
+ assertEquals(1, counter.get());
+ }
+
+ private boolean queryRecoveryComplete() throws Exception {
+ return (Boolean) this.server.getAttribute(this.objectName, "RecoveryComplete");
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractInstallArtifactTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractInstallArtifactTests.java
new file mode 100644
index 00000000..21f1f169
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/AbstractInstallArtifactTests.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+
+import org.eclipse.virgo.kernel.artifact.fs.ArtifactFS;
+import org.eclipse.virgo.kernel.core.Signal;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.ArtifactIdentity;
+import org.eclipse.virgo.kernel.install.artifact.internal.AbstractInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.internal.ArtifactStorage;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+
+/**
+ */
+public class AbstractInstallArtifactTests {
+
+ private static final String PROPERTY_NAME = "name";
+
+ private static final String PROPERTY_VALUE = "value";
+
+ private static final String PROPERTY_VALUE_2 = "value2";
+
+ private TestInstallArtifact installArtifact;
+
+ @Before
+ public void setUp() throws Exception {
+ installArtifact = new TestInstallArtifact();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testGetProperty() {
+ assertNull(this.installArtifact.getProperty(PROPERTY_NAME));
+
+ this.installArtifact.setProperty(PROPERTY_NAME, PROPERTY_VALUE);
+ assertEquals(PROPERTY_VALUE, this.installArtifact.getProperty(PROPERTY_NAME));
+ }
+
+ @Test
+ public void testGetPropertyNames() {
+ assertEquals(0, this.installArtifact.getPropertyNames().size());
+
+ this.installArtifact.setProperty(PROPERTY_NAME, PROPERTY_VALUE);
+ Set<String> expectedNames = new HashSet<String>();
+ expectedNames.add(PROPERTY_NAME);
+ assertEquals(expectedNames, this.installArtifact.getPropertyNames());
+ }
+
+ @Test
+ public void testSetProperty() {
+ assertNull(this.installArtifact.setProperty(PROPERTY_NAME, PROPERTY_VALUE));
+ assertEquals(PROPERTY_VALUE, this.installArtifact.setProperty(PROPERTY_NAME, PROPERTY_VALUE_2));
+ }
+
+ public static final class TestInstallArtifact extends AbstractInstallArtifact {
+
+ public TestInstallArtifact() {
+ super(new ArtifactIdentity("type", "name", Version.emptyVersion, null), new StubArtifactStorage(), null, null, new MockEventLogger());
+ }
+
+ @Override
+ protected void doStop() throws DeploymentException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected void doUninstall() throws DeploymentException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected void doStart(Signal signal) throws DeploymentException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean doRefresh() throws DeploymentException {
+ return false;
+ }
+ }
+
+ private static class StubArtifactStorage implements ArtifactStorage {
+
+ public void delete() {
+ }
+
+ public ArtifactFS getArtifactFS() {
+ return null;
+ }
+
+ public void synchronize() {
+ }
+
+ public void synchronize(URI sourceUri) {
+ }
+
+ public void rollBack() {
+ }
+
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ArtifactStateMonitorTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ArtifactStateMonitorTests.java
new file mode 100644
index 00000000..189221d5
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ArtifactStateMonitorTests.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.deployer.core.StubInstallArtifactLifecycleListener;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListener;
+import org.eclipse.virgo.kernel.install.artifact.internal.ArtifactStateMonitor;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+
+/**
+ */
+public class ArtifactStateMonitorTests {
+
+ BundleContext bundleContext;
+
+ ArtifactStateMonitor asm;
+
+ StubInstallArtifactLifecycleListener listener;
+
+ @Before
+ public void setUp() {
+ this.bundleContext = new StubBundleContext();
+ this.asm = new ArtifactStateMonitor(this.bundleContext);
+ this.listener = new StubInstallArtifactLifecycleListener();
+ this.bundleContext.registerService(InstallArtifactLifecycleListener.class.getName(), this.listener, null);
+ }
+
+ @Test
+ public void testInstalling() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onInstalling(null);
+ this.listener.assertLifecycleCounts(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testInstallFailed() throws DeploymentException {
+ // Set INSTALLING before failing install so state actually changes to INITIAL.
+ this.asm.onInstalling(null);
+ this.listener.assertLifecycleCounts(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onInstallFailed(null);
+ this.listener.assertLifecycleCounts(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testInstalled() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onInstalled(null);
+ this.listener.assertLifecycleCounts(0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testResolving() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onResolving(null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testResolveFailed() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onResolveFailed(null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testResolved() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onResolved(null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testStarting() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onStarting(null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testStartFailed() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onStartFailed(null, null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testStarted() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onStarted(null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testStopping() {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onStopping(null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testStopFailed() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onStopFailed(null, null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0);
+ }
+
+ @Test
+ public void testStopped() {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onStopped(null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0);
+ }
+
+ @Test
+ public void testUninstalling() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onUninstalling(null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0);
+ }
+
+ @Test
+ public void testUninstallFailed() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onUninstallFailed(null, null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0);
+ }
+
+ @Test
+ public void testUninstalled() throws DeploymentException {
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ this.asm.onUninstalled(null);
+ this.listener.assertLifecycleCounts(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/AtomicInstallArtifactLifecycleListenerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/AtomicInstallArtifactLifecycleListenerTests.java
new file mode 100644
index 00000000..cf4a2f6c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/AtomicInstallArtifactLifecycleListenerTests.java
@@ -0,0 +1,380 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+
+import org.eclipse.virgo.kernel.artifact.ArtifactSpecification;
+import org.eclipse.virgo.kernel.artifact.fs.ArtifactFS;
+import org.eclipse.virgo.kernel.core.Signal;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.PlanInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.internal.AtomicInstallArtifactLifecycleListener;
+import org.eclipse.virgo.util.common.ThreadSafeArrayListTree;
+import org.eclipse.virgo.util.common.Tree;
+
+public class AtomicInstallArtifactLifecycleListenerTests {
+
+ private static enum Methods {
+ ASYNC_START, //
+ START, //
+ STOP, //
+ UNINSTALL
+ }
+
+ private final AtomicInstallArtifactLifecycleListener listener = new AtomicInstallArtifactLifecycleListener();
+
+ private final StubInstallArtifact oneAtomicNoTree = new StubInstallArtifact(true);
+
+ private final StubInstallArtifact oneNonAtomicNoTree = new StubInstallArtifact(false);
+
+ private final StubInstallArtifact oneAtomic = makeChain(new StubInstallArtifact(true));
+
+ private final StubInstallArtifact oneNonAtomic = makeChain(new StubInstallArtifact(false));
+
+ private final StubInstallArtifact twoNonAtomic = makeChain(new StubInstallArtifact(false), new StubInstallArtifact(false));
+
+ private final StubInstallArtifact oneNonAtomicOneAtomic = makeChain(new StubInstallArtifact(true), new StubInstallArtifact(false));
+
+ private final StubInstallArtifact twoNonAtomicOneAtomic = makeChain(new StubInstallArtifact(true), new StubInstallArtifact(false),
+ new StubInstallArtifact(false));
+
+ private final StubInstallArtifact oneNonAtomicOneAtomicOneNonAtomic = makeChain(new StubInstallArtifact(false), new StubInstallArtifact(true),
+ new StubInstallArtifact(false));
+
+ @Test
+ public void onStarting() throws DeploymentException {
+ listener.onStarting(oneAtomicNoTree);
+ assertMethodCalls(oneAtomicNoTree);
+
+ listener.onStarting(oneNonAtomicNoTree);
+ assertMethodCalls(oneNonAtomicNoTree);
+
+ listener.onStarting(oneAtomic);
+ assertMethodCalls(oneAtomic);
+
+ listener.onStarting(oneNonAtomic);
+ assertMethodCalls(oneNonAtomic);
+
+ listener.onStarting(twoNonAtomic);
+ assertMethodCalls(twoNonAtomic);
+ assertMethodCalls(getParent(twoNonAtomic));
+
+ listener.onStarting(oneNonAtomicOneAtomic);
+ assertMethodCalls(oneNonAtomicOneAtomic);
+ assertMethodCalls(getParent(oneNonAtomicOneAtomic), Methods.START);
+
+ listener.onStarting(twoNonAtomicOneAtomic);
+ assertMethodCalls(twoNonAtomicOneAtomic);
+ assertMethodCalls(getParent(twoNonAtomicOneAtomic));
+ assertMethodCalls(getParent(getParent(twoNonAtomicOneAtomic)));
+
+ listener.onStarting(oneNonAtomicOneAtomicOneNonAtomic);
+ assertMethodCalls(oneNonAtomicOneAtomicOneNonAtomic);
+ assertMethodCalls(getParent(oneNonAtomicOneAtomicOneNonAtomic), Methods.START);
+ assertMethodCalls(getParent(getParent(oneNonAtomicOneAtomicOneNonAtomic)));
+ }
+
+ @Test
+ public void onStartFailed() throws DeploymentException {
+ listener.onStartFailed(oneAtomicNoTree, null);
+ assertMethodCalls(oneAtomicNoTree);
+
+ listener.onStartFailed(oneNonAtomicNoTree, null);
+ assertMethodCalls(oneNonAtomicNoTree);
+
+ listener.onStartFailed(oneAtomic, null);
+ assertMethodCalls(oneAtomic);
+
+ listener.onStartFailed(oneNonAtomic, null);
+ assertMethodCalls(oneNonAtomic);
+
+ listener.onStartFailed(twoNonAtomic, null);
+ assertMethodCalls(twoNonAtomic);
+ assertMethodCalls(getParent(twoNonAtomic));
+
+ listener.onStartFailed(oneNonAtomicOneAtomic, null);
+ assertMethodCalls(oneNonAtomicOneAtomic);
+ assertMethodCalls(getParent(oneNonAtomicOneAtomic), Methods.STOP);
+
+ listener.onStartFailed(twoNonAtomicOneAtomic, null);
+ assertMethodCalls(twoNonAtomicOneAtomic);
+ assertMethodCalls(getParent(twoNonAtomicOneAtomic));
+ assertMethodCalls(getParent(getParent(twoNonAtomicOneAtomic)));
+
+ listener.onStartFailed(oneNonAtomicOneAtomicOneNonAtomic, null);
+ assertMethodCalls(oneNonAtomicOneAtomicOneNonAtomic);
+ assertMethodCalls(getParent(oneNonAtomicOneAtomicOneNonAtomic), Methods.STOP);
+ assertMethodCalls(getParent(getParent(oneNonAtomicOneAtomicOneNonAtomic)));
+ }
+
+ @Test
+ public void onStopped() {
+ listener.onStopped(oneAtomicNoTree);
+ assertMethodCalls(oneAtomicNoTree);
+
+ listener.onStopped(oneNonAtomicNoTree);
+ assertMethodCalls(oneNonAtomicNoTree);
+
+ listener.onStopped(oneAtomic);
+ assertMethodCalls(oneAtomic);
+
+ listener.onStopped(oneNonAtomic);
+ assertMethodCalls(oneNonAtomic);
+
+ listener.onStopped(twoNonAtomic);
+ assertMethodCalls(twoNonAtomic);
+ assertMethodCalls(getParent(twoNonAtomic));
+
+ listener.onStopped(oneNonAtomicOneAtomic);
+ assertMethodCalls(oneNonAtomicOneAtomic);
+ assertMethodCalls(getParent(oneNonAtomicOneAtomic), Methods.STOP);
+
+ listener.onStopped(twoNonAtomicOneAtomic);
+ assertMethodCalls(twoNonAtomicOneAtomic);
+ assertMethodCalls(getParent(twoNonAtomicOneAtomic));
+ assertMethodCalls(getParent(getParent(twoNonAtomicOneAtomic)));
+
+ listener.onStopped(oneNonAtomicOneAtomicOneNonAtomic);
+ assertMethodCalls(oneNonAtomicOneAtomicOneNonAtomic);
+ assertMethodCalls(getParent(oneNonAtomicOneAtomicOneNonAtomic), Methods.STOP);
+ assertMethodCalls(getParent(getParent(oneNonAtomicOneAtomicOneNonAtomic)));
+ }
+
+ @Test
+ public void onUninstalled() throws DeploymentException {
+ listener.onUninstalled(oneAtomicNoTree);
+ assertMethodCalls(oneAtomicNoTree);
+
+ listener.onUninstalled(oneNonAtomicNoTree);
+ assertMethodCalls(oneNonAtomicNoTree);
+
+ listener.onUninstalled(oneAtomic);
+ assertMethodCalls(oneAtomic);
+
+ listener.onUninstalled(oneNonAtomic);
+ assertMethodCalls(oneNonAtomic);
+
+ listener.onUninstalled(twoNonAtomic);
+ assertMethodCalls(twoNonAtomic);
+ assertMethodCalls(getParent(twoNonAtomic));
+
+ listener.onUninstalled(oneNonAtomicOneAtomic);
+ assertMethodCalls(oneNonAtomicOneAtomic);
+ assertMethodCalls(getParent(oneNonAtomicOneAtomic), Methods.UNINSTALL);
+
+ listener.onUninstalled(twoNonAtomicOneAtomic);
+ assertMethodCalls(twoNonAtomicOneAtomic);
+ assertMethodCalls(getParent(twoNonAtomicOneAtomic));
+ assertMethodCalls(getParent(getParent(twoNonAtomicOneAtomic)));
+
+ listener.onUninstalled(oneNonAtomicOneAtomicOneNonAtomic);
+ assertMethodCalls(oneNonAtomicOneAtomicOneNonAtomic);
+ assertMethodCalls(getParent(oneNonAtomicOneAtomicOneNonAtomic), Methods.UNINSTALL);
+ assertMethodCalls(getParent(getParent(oneNonAtomicOneAtomicOneNonAtomic)));
+ }
+
+ private StubInstallArtifact getParent(StubInstallArtifact artifact) {
+ Tree<InstallArtifact> tree = artifact.getTree();
+ if (tree != null) {
+ Tree<InstallArtifact> parent = tree.getParent();
+ if (parent != null) {
+ return (StubInstallArtifact) parent.getValue();
+ }
+ }
+ return null;
+ }
+
+ private void assertMethodCalls(StubInstallArtifact artifact, Methods... methods) {
+ List<Methods> calledMethods = Arrays.asList(methods);
+ if (calledMethods.contains(Methods.START)) {
+ assertTrue(artifact.getStartCalled());
+ } else {
+ assertFalse(artifact.getStartCalled());
+ }
+
+ if (calledMethods.contains(Methods.STOP)) {
+ assertTrue(artifact.getStopCalled());
+ } else {
+ assertFalse(artifact.getStopCalled());
+ }
+
+ if (calledMethods.contains(Methods.UNINSTALL)) {
+ assertTrue(artifact.getUninstallCalled());
+ } else {
+ assertFalse(artifact.getUninstallCalled());
+ }
+ }
+
+ /**
+ * Create a chain (linear tree) behind a list of values:
+ *
+ * <pre>
+ * makeChain([a,b,c])
+ * </pre>
+ *
+ * produces
+ *
+ * <pre>
+ * (a)->(b)->(c)
+ * </pre>
+ *
+ * and returns <code><em>c</em></code>, the value of the last node (with tree attached).
+ *
+ * @param installArtifactArray array of values to be in nodes of chain tree
+ * @return value (with tree attached) at last leaf of chain tree
+ */
+ private final static StubInstallArtifact makeChain(StubInstallArtifact... installArtifactArray) {
+ Tree<InstallArtifact> tree = null;
+ for (StubInstallArtifact installArtifact : installArtifactArray) {
+ Tree<InstallArtifact> leaf = new ThreadSafeArrayListTree<InstallArtifact>(installArtifact);
+ if (tree == null) {
+ tree = leaf;
+ } else {
+ tree = tree.addChild(leaf);
+ }
+ installArtifact.setTree(tree);
+ }
+
+ if(tree == null){
+ return null;
+ }
+ return (StubInstallArtifact) tree.getValue();
+ }
+
+ private static class StubInstallArtifact implements PlanInstallArtifact {
+
+ private final boolean atomic;
+
+ private volatile Tree<InstallArtifact> tree;
+
+ private volatile boolean startCalled = false;
+
+ private volatile boolean stopCalled = false;
+
+ private volatile boolean uninstallCalled = false;
+
+ public StubInstallArtifact(boolean atomic) {
+ this.atomic = atomic;
+ }
+
+ public boolean getStartCalled() {
+ return startCalled;
+ }
+
+ public boolean getStopCalled() {
+ return stopCalled;
+ }
+
+ public boolean getUninstallCalled() {
+ return uninstallCalled;
+ }
+
+ public Tree<InstallArtifact> getTree() {
+ return this.tree;
+ }
+
+ public void setTree(Tree<InstallArtifact> tree) {
+ this.tree = tree;
+ }
+
+ public void stop() throws DeploymentException {
+ this.stopCalled = true;
+ }
+
+ public void start() throws DeploymentException {
+ start(null);
+ }
+
+ public void start(Signal signal) throws DeploymentException {
+ this.startCalled = true;
+ }
+
+ public void uninstall() throws DeploymentException {
+ this.uninstallCalled = true;
+ }
+
+ public boolean isAtomic() {
+ return this.atomic;
+ }
+
+ public ArtifactFS getArtifactFS() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getName() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getRepositoryName() {
+ throw new UnsupportedOperationException();
+ }
+
+ public State getState() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getType() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Version getVersion() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean refresh() {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<ArtifactSpecification> getArtifactSpecifications() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isScoped() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean refresh(String symbolicName) throws DeploymentException {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean refreshScope() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getProperty(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Set<String> getPropertyNames() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String setProperty(String name, String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getScopeName() {
+ return null;
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PlanMemberCollectorTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PlanMemberCollectorTests.java
new file mode 100644
index 00000000..065eded7
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/PlanMemberCollectorTests.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Test;
+
+import org.eclipse.virgo.kernel.install.artifact.BundleInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.PlanInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.internal.PlanMemberCollector;
+import org.eclipse.virgo.util.common.ThreadSafeArrayListTree;
+import org.eclipse.virgo.util.common.Tree;
+
+
+/**
+ */
+public class PlanMemberCollectorTests {
+
+ private final PlanMemberCollector collector = new PlanMemberCollector();
+
+ @Test
+ public void rootPlanIsNotIncludedInTheCollection() {
+ PlanInstallArtifact plan = createNiceMock(PlanInstallArtifact.class);
+ Tree<InstallArtifact> tree = new ThreadSafeArrayListTree<InstallArtifact>(plan);
+ expect(plan.getTree()).andReturn(tree);
+
+ replay(plan);
+
+ List<InstallArtifact> members = this.collector.collectPlanMembers(plan);
+ assertNotNull(members);
+ assertEquals(0, members.size());
+ }
+
+ @Test
+ public void singleLevelPlan() {
+ PlanInstallArtifact plan = createNiceMock(PlanInstallArtifact.class);
+ Tree<InstallArtifact> tree = new ThreadSafeArrayListTree<InstallArtifact>(plan);
+
+ BundleInstallArtifact bundle1 = createNiceMock(BundleInstallArtifact.class);
+ tree.addChild(new ThreadSafeArrayListTree<InstallArtifact>(bundle1));
+
+ BundleInstallArtifact bundle2 = createNiceMock(BundleInstallArtifact.class);
+ tree.addChild(new ThreadSafeArrayListTree<InstallArtifact>(bundle2));
+
+ expect(plan.getTree()).andReturn(tree);
+
+ replay(plan);
+
+ List<InstallArtifact> members = this.collector.collectPlanMembers(plan);
+ assertNotNull(members);
+ assertEquals(2, members.size());
+ assertTrue(members.contains(bundle1));
+ assertTrue(members.contains(bundle2));
+ }
+
+ @Test
+ public void nestedPlan() {
+ PlanInstallArtifact plan = createNiceMock(PlanInstallArtifact.class);
+ Tree<InstallArtifact> tree = new ThreadSafeArrayListTree<InstallArtifact>(plan);
+ expect(plan.getTree()).andReturn(tree);
+
+ BundleInstallArtifact bundle1 = createNiceMock(BundleInstallArtifact.class);
+ tree.addChild(new ThreadSafeArrayListTree<InstallArtifact>(bundle1));
+
+ BundleInstallArtifact bundle2 = createNiceMock(BundleInstallArtifact.class);
+ tree.addChild(new ThreadSafeArrayListTree<InstallArtifact>(bundle2));
+
+ PlanInstallArtifact nestedPlan = createNiceMock(PlanInstallArtifact.class);
+ Tree<InstallArtifact> nestedTree = new ThreadSafeArrayListTree<InstallArtifact>(nestedPlan);
+ expect(nestedPlan.getTree()).andReturn(nestedTree);
+
+ BundleInstallArtifact bundle3 = createNiceMock(BundleInstallArtifact.class);
+ nestedTree.addChild(new ThreadSafeArrayListTree<InstallArtifact>(bundle3));
+
+ tree.addChild(nestedTree);
+
+ replay(plan, nestedPlan);
+
+ List<InstallArtifact> members = this.collector.collectPlanMembers(plan);
+ assertNotNull(members);
+ assertEquals(4, members.size());
+ assertTrue(members.contains(bundle1));
+ assertTrue(members.contains(bundle2));
+ assertTrue(members.contains(nestedPlan));
+ assertTrue(members.contains(bundle3));
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ScopeServiceRepositoryTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ScopeServiceRepositoryTests.java
new file mode 100644
index 00000000..b10f5e2b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/ScopeServiceRepositoryTests.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import org.eclipse.virgo.kernel.install.artifact.ScopeServiceRepository;
+import org.eclipse.virgo.kernel.install.artifact.internal.StandardScopeServiceRepository;
+import org.junit.Test;
+
+
+/**
+ */
+public class ScopeServiceRepositoryTests {
+
+ private static final String TEST_SCOPE = "test";
+
+ @Test
+ public void testServiceWithSingleTypeNoFilter() throws Exception {
+ ScopeServiceRepository repository = new StandardScopeServiceRepository();
+ repository.recordService(TEST_SCOPE, new String[]{String.class.getName()}, null);
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, String.class.getName(), null));
+ assertFalse(repository.scopeHasMatchingService(TEST_SCOPE, Integer.class.getName(), null));
+ }
+
+ @Test
+ public void testServiceWithSingleTypeFiltered() throws Exception {
+ ScopeServiceRepository repository = new StandardScopeServiceRepository();
+ Properties p = new Properties();
+ p.setProperty("foo", "bar");
+ repository.recordService(TEST_SCOPE, new String[]{String.class.getName()}, p);
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, String.class.getName(), "(foo=bar)"));
+ assertFalse(repository.scopeHasMatchingService(TEST_SCOPE, Integer.class.getName(), "(foo=bar)"));
+ }
+
+ @Test
+ public void testServiceWithMultiTypeNoFilter() throws Exception {
+ ScopeServiceRepository repository = new StandardScopeServiceRepository();
+ repository.recordService(TEST_SCOPE, new String[]{String.class.getName(), Serializable.class.getName()}, null);
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, String.class.getName(), null));
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, Serializable.class.getName(), null));
+ assertFalse(repository.scopeHasMatchingService(TEST_SCOPE, Integer.class.getName(), null));
+ }
+
+ @Test
+ public void testServiceWithMultiTypeFilter() throws Exception {
+ ScopeServiceRepository repository = new StandardScopeServiceRepository();
+ Properties p = new Properties();
+ p.setProperty("foo", "bar");
+ repository.recordService(TEST_SCOPE, new String[]{String.class.getName(), Serializable.class.getName()}, p);
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, String.class.getName(), "(foo=bar)"));
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, Serializable.class.getName(), "(foo=bar)"));
+ assertFalse(repository.scopeHasMatchingService(TEST_SCOPE, Integer.class.getName(), "(foo=bar)"));
+ }
+
+ @Test
+ public void testClearScope() throws Exception {
+ ScopeServiceRepository repository = new StandardScopeServiceRepository();
+ repository.recordService(TEST_SCOPE, new String[]{String.class.getName()}, null);
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, String.class.getName(), null));
+ repository.clearScope(TEST_SCOPE);
+ assertFalse(repository.scopeHasMatchingService(TEST_SCOPE, String.class.getName(), null));
+ }
+
+ @Test
+ public void testNullNameWithObjectClassFilter() throws Exception {
+ ScopeServiceRepository repository = new StandardScopeServiceRepository();
+ repository.recordService(TEST_SCOPE, new String[]{String.class.getName()}, null);
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, null, "(objectClass=java.lang.String)"));
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/SpringConfigServiceModelScannerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/SpringConfigServiceModelScannerTests.java
new file mode 100644
index 00000000..8bdce80f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/SpringConfigServiceModelScannerTests.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.Serializable;
+
+import org.junit.Test;
+import org.osgi.framework.Version;
+import org.springframework.core.io.ClassPathResource;
+
+
+import org.eclipse.virgo.kernel.install.artifact.ScopeServiceRepository;
+import org.eclipse.virgo.kernel.install.artifact.internal.SpringConfigServiceModelScanner;
+import org.eclipse.virgo.kernel.install.artifact.internal.StandardScopeServiceRepository;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+
+/**
+ */
+public class SpringConfigServiceModelScannerTests {
+
+ private static final String TEST_SCOPE = "test";
+
+ @Test
+ public void testServicesRegistered() throws Exception {
+
+ ScopeServiceRepository repository = new StandardScopeServiceRepository();
+ String location = "scoping/simpleService.xml";
+ run(repository, location);
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, Serializable.class.getName(), null));
+ assertFalse(repository.scopeHasMatchingService(TEST_SCOPE, Integer.class.getName(), null));
+ }
+
+ @Test
+ public void testComplexService() throws Exception {
+
+ ScopeServiceRepository repository = new StandardScopeServiceRepository();
+ String location = "scoping/complexService.xml";
+ run(repository, location);
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, Serializable.class.getName(), null));
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, Serializable.class.getName(), "(foo=bar)"));
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, Appendable.class.getName(), null));
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, Appendable.class.getName(), "(foo=bar)"));
+ assertTrue(repository.scopeHasMatchingService(TEST_SCOPE, Appendable.class.getName(), "(org.springframework.osgi.bean.name=service)"));
+ }
+
+ private final void run(ScopeServiceRepository repository, String configLocation) throws Exception {
+ ClassPathResource resource = new ClassPathResource(configLocation);
+ SpringConfigServiceModelScanner scanner = new SpringConfigServiceModelScanner(TEST_SCOPE, repository, new MockEventLogger());
+ scanner.scanConfigFile("bundle", Version.emptyVersion, configLocation, resource.getInputStream());
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactIdentityDeterminerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactIdentityDeterminerTests.java
new file mode 100644
index 00000000..e1681e27
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardArtifactIdentityDeterminerTests.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+import org.eclipse.virgo.kernel.install.artifact.ArtifactIdentity;
+import org.eclipse.virgo.kernel.install.artifact.ArtifactIdentityDeterminer;
+import org.eclipse.virgo.kernel.install.artifact.internal.StandardArtifactIdentityDeterminer;
+import org.eclipse.virgo.repository.ArtifactBridge;
+import org.eclipse.virgo.repository.ArtifactDescriptor;
+import org.eclipse.virgo.repository.ArtifactGenerationException;
+
+/**
+ */
+public class StandardArtifactIdentityDeterminerTests {
+
+ private ArtifactIdentityDeterminer artifactIdentityDeterminer;
+
+ @Before
+ public void setUp() {
+ this.artifactIdentityDeterminer = new StandardArtifactIdentityDeterminer(Collections.<ArtifactBridge>emptySet());
+ }
+
+ @Test
+ public void testJarFileType() {
+ ArtifactIdentity identity = this.artifactIdentityDeterminer.determineIdentity(new File("test.jar"), null);
+ assertEquals(ArtifactIdentityDeterminer.BUNDLE_TYPE, identity.getType());
+ assertEquals("test", identity.getName());
+ assertEquals(Version.emptyVersion, identity.getVersion());
+ }
+
+ @Test
+ public void testPlanFileType() {
+ ArtifactIdentity identity = this.artifactIdentityDeterminer.determineIdentity(new File("test.plan"), null);
+ assertEquals(ArtifactIdentityDeterminer.PLAN_TYPE, identity.getType());
+ assertEquals("test", identity.getName());
+ assertEquals(Version.emptyVersion, identity.getVersion());
+ }
+
+ @Test
+ public void testPropertiesFileType() {
+ ArtifactIdentity identity = this.artifactIdentityDeterminer.determineIdentity(new File("test.properties"), null);
+ assertEquals(ArtifactIdentityDeterminer.CONFIGURATION_TYPE, identity.getType());
+ assertEquals("test", identity.getName());
+ assertEquals(Version.emptyVersion, identity.getVersion());
+ }
+
+ @Test
+ public void testParFileType() {
+ ArtifactIdentity identity = this.artifactIdentityDeterminer.determineIdentity(new File("test.par"), null);
+ assertEquals(ArtifactIdentityDeterminer.PAR_TYPE, identity.getType());
+ assertEquals("test", identity.getName());
+ assertEquals(Version.emptyVersion, identity.getVersion());
+ }
+
+ @Test
+ public void testWarFileType() {
+ assertNull(this.artifactIdentityDeterminer.determineIdentity(new File("test.war"), null));
+ }
+
+ @Test
+ public void testNoFileType() {
+ assertNull(this.artifactIdentityDeterminer.determineIdentity(new File("test"), null));
+ }
+
+ @Test
+ public void identityFromBridge() throws ArtifactGenerationException {
+ ArtifactDescriptor artifactDescriptor = createMock(ArtifactDescriptor.class);
+ expect(artifactDescriptor.getType()).andReturn("foo");
+ expect(artifactDescriptor.getName()).andReturn("bar");
+ expect(artifactDescriptor.getVersion()).andReturn(new Version(1,2,3));
+
+ ArtifactBridge bridge = createMock(ArtifactBridge.class);
+ expect(bridge.generateArtifactDescriptor(new File("test"))).andReturn(artifactDescriptor);
+
+ replay(artifactDescriptor, bridge);
+
+ ArtifactIdentity artifactIdentity = new StandardArtifactIdentityDeterminer(new HashSet<ArtifactBridge>(Arrays.asList(bridge))).determineIdentity(new File("test"), null);
+ assertEquals("foo", artifactIdentity.getType());
+ assertEquals("bar", artifactIdentity.getName());
+ assertEquals(new Version(1,2,3), artifactIdentity.getVersion());
+
+ verify(artifactDescriptor, bridge);
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardInstallArtifactTreeInclosureTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardInstallArtifactTreeInclosureTests.java
new file mode 100644
index 00000000..42eb1459
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StandardInstallArtifactTreeInclosureTests.java
@@ -0,0 +1,243 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+import org.eclipse.virgo.kernel.osgi.framework.OsgiFramework;
+import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
+
+import org.eclipse.virgo.kernel.artifact.ArtifactSpecification;
+import org.eclipse.virgo.kernel.artifact.fs.StandardArtifactFSFactory;
+import org.eclipse.virgo.kernel.core.BundleStarter;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.deployer.core.ApplicationDeployer.DeploymentOptions;
+import org.eclipse.virgo.kernel.install.artifact.BundleInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifactTreeFactory;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifactTreeInclosure;
+import org.eclipse.virgo.kernel.install.artifact.internal.ArtifactStorageFactory;
+import org.eclipse.virgo.kernel.install.artifact.internal.StandardArtifactIdentityDeterminer;
+import org.eclipse.virgo.kernel.install.artifact.internal.StandardArtifactStorageFactory;
+import org.eclipse.virgo.kernel.install.artifact.internal.StandardInstallArtifactRefreshHandler;
+import org.eclipse.virgo.kernel.install.artifact.internal.StandardInstallArtifactTreeInclosure;
+import org.eclipse.virgo.kernel.install.artifact.internal.bundle.BundleInstallArtifactTreeFactory;
+import org.eclipse.virgo.kernel.install.environment.InstallEnvironmentFactory;
+import org.eclipse.virgo.kernel.install.pipeline.Pipeline;
+import org.eclipse.virgo.kernel.shim.serviceability.TracingService;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+import org.eclipse.virgo.repository.ArtifactBridge;
+import org.eclipse.virgo.repository.Repository;
+import org.eclipse.virgo.repository.RepositoryAwareArtifactDescriptor;
+import org.eclipse.virgo.util.common.Tree;
+import org.eclipse.virgo.util.io.PathReference;
+import org.eclipse.virgo.util.osgi.VersionRange;
+
+/**
+ */
+public class StandardInstallArtifactTreeInclosureTests {
+
+ private static final String TEST_BUNDLE_REPOSITORY_NAME = "testBundleRepositoryName";
+
+ private final InstallEnvironmentFactory installEnvironmentFactory = createMock(InstallEnvironmentFactory.class);
+
+ private final Pipeline refreshPipeline = createMock(Pipeline.class);
+
+ private InstallArtifactTreeInclosure installArtifactFactory;
+
+ private URI bundleURI;
+
+ private OsgiFramework osgiFramework;
+
+ private BundleStarter bundleStarter;
+
+ private TracingService tracingService;
+
+ private PackageAdminUtil packageAdminUtil;
+
+ private Repository repository;
+
+ private RepositoryAwareArtifactDescriptor artifactDescriptor;
+
+ private final ArtifactStorageFactory artifactStorageFactory = new StandardArtifactStorageFactory(
+ new PathReference("target/work/deployer.staging"), new StandardArtifactFSFactory(), new MockEventLogger());
+
+ private Set<ArtifactBridge> testArtifactBridges = new HashSet<ArtifactBridge>();
+
+ @Before
+ public void setUp() {
+ this.bundleURI = new File("src/test/resources/artifacts/simple.jar").toURI();
+ this.osgiFramework = createMock(OsgiFramework.class);
+ this.bundleStarter = createMock(BundleStarter.class);
+ this.tracingService = createMock(TracingService.class);
+ this.packageAdminUtil = createMock(PackageAdminUtil.class);
+ this.repository = createMock(Repository.class);
+ this.artifactDescriptor = createMock(RepositoryAwareArtifactDescriptor.class);
+ this.testArtifactBridges.add(new StubArtifactBridge("bundle", ".jar"));
+ }
+
+ private void replayMocks() {
+ replay(this.osgiFramework, this.bundleStarter, this.tracingService, this.packageAdminUtil, this.repository, this.artifactDescriptor);
+ }
+
+ private void verifyMocks() {
+ verify(this.osgiFramework, this.bundleStarter, this.tracingService, this.packageAdminUtil, this.repository, this.artifactDescriptor);
+ }
+
+ private void resetMocks() {
+ reset(this.osgiFramework, this.bundleStarter, this.tracingService, this.packageAdminUtil, this.repository, this.artifactDescriptor);
+ }
+
+ @Test
+ public void testBundle() throws DeploymentException, IOException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundleContext userRegionBundleContext = new StubBundleContext();
+ expect(this.osgiFramework.getBundleContext()).andReturn(bundleContext).anyTimes();
+ expect(this.repository.get(isA(String.class), isA(String.class), isA(VersionRange.class))).andReturn(this.artifactDescriptor);
+ expect(this.artifactDescriptor.getUri()).andReturn(this.bundleURI);
+ expect(this.artifactDescriptor.getVersion()).andReturn(new Version(1,2,3));
+ expect(this.artifactDescriptor.getRepositoryName()).andReturn(TEST_BUNDLE_REPOSITORY_NAME);
+
+ replayMocks();
+
+ StandardArtifactIdentityDeterminer artifactIdentityDeterminer = new StandardArtifactIdentityDeterminer(testArtifactBridges);
+
+ StandardInstallArtifactRefreshHandler refreshHelper = new StandardInstallArtifactRefreshHandler(installEnvironmentFactory, refreshPipeline);
+
+ bundleContext.registerService(InstallArtifactTreeFactory.class.getName(), new BundleInstallArtifactTreeFactory(this.osgiFramework,
+ bundleContext, refreshHelper, this.bundleStarter, this.tracingService, this.packageAdminUtil, userRegionBundleContext, new MockEventLogger(), null), null);
+
+ this.installArtifactFactory = new StandardInstallArtifactTreeInclosure(this.artifactStorageFactory, bundleContext, this.repository,
+ new MockEventLogger(), artifactIdentityDeterminer);
+
+ ArtifactSpecification specification = new ArtifactSpecification("bundle", "a", new VersionRange("2.0.0"));
+ InstallArtifact installArtifact = this.installArtifactFactory.createInstallTree(specification).getValue();
+ assertNotNull(installArtifact);
+ assertEquals(TEST_BUNDLE_REPOSITORY_NAME, installArtifact.getRepositoryName());
+ assertTrue(installArtifact instanceof BundleInstallArtifact);
+ BundleInstallArtifact bundleInstallArtifact = (BundleInstallArtifact) installArtifact;
+ assertEquals("a", bundleInstallArtifact.getBundleManifest().getBundleSymbolicName().getSymbolicName());
+
+ verifyMocks();
+ resetMocks();
+ }
+
+ @Test
+ public void testBundleImplicitTypeAndVersion() throws DeploymentException, IOException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundleContext userRegionBundleContext = new StubBundleContext();
+ expect(this.osgiFramework.getBundleContext()).andReturn(bundleContext).anyTimes();
+
+ replayMocks();
+
+ StandardArtifactIdentityDeterminer artifactIdentityDeterminer = new StandardArtifactIdentityDeterminer(testArtifactBridges);
+
+ StandardInstallArtifactRefreshHandler refreshHelper = new StandardInstallArtifactRefreshHandler(installEnvironmentFactory, refreshPipeline);
+
+ bundleContext.registerService(InstallArtifactTreeFactory.class.getName(), new BundleInstallArtifactTreeFactory(this.osgiFramework,
+ bundleContext, refreshHelper, this.bundleStarter, this.tracingService, this.packageAdminUtil, userRegionBundleContext, new MockEventLogger(), null), null);
+
+ this.installArtifactFactory = new StandardInstallArtifactTreeInclosure(this.artifactStorageFactory, bundleContext, this.repository,
+ new MockEventLogger(), artifactIdentityDeterminer);
+
+ Tree<InstallArtifact> installArtifactTree = this.installArtifactFactory.createInstallTree(new File(this.bundleURI));
+ checkBundleImplicitTypeAndVersion(installArtifactTree.getValue());
+
+ verifyMocks();
+ resetMocks();
+ }
+
+ @Test
+ public void testNoBSNBundleImplicitTypeAndVersion() throws DeploymentException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundleContext userRegionBundleContext = new StubBundleContext();
+ expect(this.osgiFramework.getBundleContext()).andReturn(bundleContext).anyTimes();
+
+ replayMocks();
+
+ StandardArtifactIdentityDeterminer artifactIdentityDeterminer = new StandardArtifactIdentityDeterminer(testArtifactBridges);
+
+ StandardInstallArtifactRefreshHandler refreshHelper = new StandardInstallArtifactRefreshHandler(installEnvironmentFactory, refreshPipeline);
+
+ bundleContext.registerService(InstallArtifactTreeFactory.class.getName(), new BundleInstallArtifactTreeFactory(this.osgiFramework,
+ bundleContext, refreshHelper, this.bundleStarter, this.tracingService, this.packageAdminUtil, userRegionBundleContext, new MockEventLogger(), null), null);
+
+ this.installArtifactFactory = new StandardInstallArtifactTreeInclosure(this.artifactStorageFactory, bundleContext, this.repository,
+ new MockEventLogger(), artifactIdentityDeterminer);
+
+ Tree<InstallArtifact> installArtifactTree = this.installArtifactFactory.createInstallTree(new File("src/test/resources/artifacts/nobsn.jar"));
+ InstallArtifact installArtifact = installArtifactTree.getValue();
+ assertNotNull(installArtifact);
+ assertTrue(installArtifact instanceof BundleInstallArtifact);
+ assertEquals("nobsn", installArtifact.getName());
+ assertEquals(new Version("0"), installArtifact.getVersion());
+
+ verifyMocks();
+ resetMocks();
+ }
+
+ @Test
+ public void testRecoverBundleImplicitTypeAndVersion() throws DeploymentException, IOException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundleContext userRegionBundleContext = new StubBundleContext();
+ expect(this.osgiFramework.getBundleContext()).andReturn(bundleContext).anyTimes();
+
+ replayMocks();
+
+ StandardInstallArtifactRefreshHandler refreshHelper = new StandardInstallArtifactRefreshHandler(installEnvironmentFactory, refreshPipeline);
+
+ StandardArtifactIdentityDeterminer artifactIdentityDeterminer = new StandardArtifactIdentityDeterminer(testArtifactBridges);
+
+ bundleContext.registerService(InstallArtifactTreeFactory.class.getName(), new BundleInstallArtifactTreeFactory(this.osgiFramework,
+ bundleContext, refreshHelper, this.bundleStarter, this.tracingService, this.packageAdminUtil, userRegionBundleContext, new MockEventLogger(), null), null);
+
+ this.installArtifactFactory = new StandardInstallArtifactTreeInclosure(this.artifactStorageFactory, bundleContext, this.repository,
+ new MockEventLogger(), artifactIdentityDeterminer);
+
+ Tree<InstallArtifact> installArtifactTree = this.installArtifactFactory.createInstallTree(new File(this.bundleURI));
+ checkBundleImplicitTypeAndVersion(installArtifactTree.getValue());
+
+ DeploymentOptions deploymentOptions = new DeploymentOptions(/* recoverable */true, /* deployerOwned */false, true);
+ Tree<InstallArtifact> recoveredInstallTree = this.installArtifactFactory.recoverInstallTree(new File(this.bundleURI), deploymentOptions);
+ checkBundleImplicitTypeAndVersion(recoveredInstallTree.getValue());
+
+ verifyMocks();
+ resetMocks();
+ }
+
+ private void checkBundleImplicitTypeAndVersion(InstallArtifact installArtifact) throws IOException {
+ assertNotNull(installArtifact);
+ assertTrue(installArtifact instanceof BundleInstallArtifact);
+ BundleInstallArtifact bundleInstallArtifact = (BundleInstallArtifact) installArtifact;
+ assertEquals("simple", bundleInstallArtifact.getBundleManifest().getBundleSymbolicName().getSymbolicName());
+ assertEquals(new Version("0"), bundleInstallArtifact.getBundleManifest().getBundleVersion());
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubArtifactBridge.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubArtifactBridge.java
new file mode 100644
index 00000000..c3994058
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubArtifactBridge.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Set;
+
+import org.osgi.framework.Version;
+
+import org.eclipse.virgo.repository.ArtifactBridge;
+import org.eclipse.virgo.repository.ArtifactDescriptor;
+import org.eclipse.virgo.repository.ArtifactGenerationException;
+import org.eclipse.virgo.repository.Attribute;
+
+
+/**
+ * <p>
+ * TODO Document StubArtifactBridge
+ * </p>
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * TODO Document concurrent semantics of StubArtifactBridge
+ *
+ */
+public class StubArtifactBridge implements ArtifactBridge {
+
+ private final String planType;
+
+ private final String[] matchs;
+
+ public StubArtifactBridge(String planType, String... matchs) {
+ this.planType = planType;
+ this.matchs = matchs;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ArtifactDescriptor generateArtifactDescriptor(File artifactFile) throws ArtifactGenerationException {
+ boolean matched = false;
+ for(String ending : this.matchs){
+ if(artifactFile.getName().endsWith(ending)){
+ matched = true;
+ }
+ }
+
+ if(matched){
+ return new ArtifactDescriptor() {
+
+ public Version getVersion() {
+ return null;
+ }
+
+ public URI getUri() {
+ return null;
+ }
+
+ public String getType() {
+ return planType;
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ public String getFilename() {
+ return null;
+ }
+
+ public Set<Attribute> getAttributes() {
+ return null;
+ }
+
+ public Set<Attribute> getAttribute(String name) {
+ return null;
+ }
+ };
+ }
+ return null;
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubEventLogger.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubEventLogger.java
new file mode 100644
index 00000000..bf278a1d
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubEventLogger.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import org.eclipse.virgo.medic.eventlog.EventLogger;
+import org.eclipse.virgo.medic.eventlog.Level;
+import org.eclipse.virgo.medic.eventlog.LogEvent;
+
+public class StubEventLogger implements EventLogger {
+
+ public void log(LogEvent logEvent, Object... inserts) {
+ }
+
+ public void log(String code, Level level, Object... inserts) {
+ }
+
+ public void log(LogEvent logEvent, Throwable throwable, Object... inserts) {
+ }
+
+ public void log(String code, Level level, Throwable throwable, Object... inserts) {
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubInstallArtifactRefreshHandler.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubInstallArtifactRefreshHandler.java
new file mode 100644
index 00000000..04f28687
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/StubInstallArtifactRefreshHandler.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.internal.InstallArtifactRefreshHandler;
+
+
+/**
+ */
+public class StubInstallArtifactRefreshHandler implements InstallArtifactRefreshHandler {
+
+ private final List<InstallArtifact> refreshedArtifacts = new ArrayList<InstallArtifact>();
+
+ private Map<InstallArtifact, Boolean> refreshOutcomes = new HashMap<InstallArtifact, Boolean>();
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean refresh(InstallArtifact installArtifact) {
+ Boolean refreshed = this.refreshOutcomes.get(installArtifact);
+
+ if (refreshed == null) {
+ throw new IllegalStateException("No refresh outcome set for install artifact '" + installArtifact + "'");
+ }
+
+ this.refreshedArtifacts.add(installArtifact);
+
+ return refreshed;
+ }
+
+ public void setRefreshOutcome(InstallArtifact artifact, boolean refreshSuccessful) {
+ this.refreshOutcomes.put(artifact, refreshSuccessful);
+ }
+
+ public void assertRefreshed(InstallArtifact installArtifact) {
+ assertTrue(this.refreshedArtifacts.contains(installArtifact));
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/TreeRestrictingInstallArtifactLifecycleListenerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/TreeRestrictingInstallArtifactLifecycleListenerTests.java
new file mode 100644
index 00000000..cf414f8c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/TreeRestrictingInstallArtifactLifecycleListenerTests.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListener;
+import org.eclipse.virgo.kernel.install.artifact.internal.TreeRestrictingInstallArtifactLifecycleListener;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+
+/**
+ */
+public class TreeRestrictingInstallArtifactLifecycleListenerTests {
+
+ private StubEventLogger stubEventLogger;
+
+ private InstallArtifactLifecycleListener treeRestrictingListener;
+
+ private InstallArtifact installArtifact1;
+
+ private InstallArtifact installArtifact2;
+
+ @Before
+ public void setUp() throws Exception {
+ this.stubEventLogger = new StubEventLogger();
+ this.treeRestrictingListener = new TreeRestrictingInstallArtifactLifecycleListener(this.stubEventLogger);
+
+ this.installArtifact1 = createMock(InstallArtifact.class);
+ expect(this.installArtifact1.getType()).andReturn("type1").anyTimes();
+ expect(this.installArtifact1.getName()).andReturn("name1").anyTimes();
+ expect(this.installArtifact1.getVersion()).andReturn(Version.emptyVersion).anyTimes();
+ expect(this.installArtifact1.getScopeName()).andReturn(null).anyTimes();
+
+ this.installArtifact2 = createMock(InstallArtifact.class);
+ expect(this.installArtifact2.getType()).andReturn("type2").anyTimes();
+ expect(this.installArtifact2.getName()).andReturn("name2").anyTimes();
+ expect(this.installArtifact2.getVersion()).andReturn(Version.emptyVersion).anyTimes();
+ expect(this.installArtifact2.getScopeName()).andReturn(null).anyTimes();
+
+ replay(this.installArtifact1, this.installArtifact2);
+ }
+
+ @Test
+ public void testOnInstalling() throws DeploymentException {
+ this.treeRestrictingListener.onInstalling(this.installArtifact1);
+ this.treeRestrictingListener.onInstalling(this.installArtifact2);
+ }
+
+ @Test
+ public void testOnInstallFailed() throws DeploymentException {
+ this.treeRestrictingListener.onInstalling(this.installArtifact1);
+ this.treeRestrictingListener.onInstallFailed(this.installArtifact1);
+ this.treeRestrictingListener.onInstalling(this.installArtifact1);
+ }
+
+ @Test
+ public void testOnUninstalled() throws DeploymentException {
+ this.treeRestrictingListener.onInstalling(this.installArtifact1);
+ this.treeRestrictingListener.onUninstalled(this.installArtifact1);
+ this.treeRestrictingListener.onInstalling(this.installArtifact1);
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/bundle/StandardBundleInstallArtifactTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/bundle/StandardBundleInstallArtifactTests.java
new file mode 100644
index 00000000..79bb9af2
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/artifact/internal/bundle/StandardBundleInstallArtifactTests.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.artifact.internal.bundle;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URI;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+import org.eclipse.virgo.kernel.osgi.quasi.QuasiBundle;
+
+import org.eclipse.virgo.kernel.artifact.fs.ArtifactFS;
+import org.eclipse.virgo.kernel.artifact.fs.internal.DirectoryArtifactFS;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.ArtifactIdentity;
+import org.eclipse.virgo.kernel.install.artifact.ArtifactIdentityDeterminer;
+import org.eclipse.virgo.kernel.install.artifact.BundleInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.internal.ArtifactStateMonitor;
+import org.eclipse.virgo.kernel.install.artifact.internal.ArtifactStorage;
+import org.eclipse.virgo.kernel.install.artifact.internal.StubInstallArtifactRefreshHandler;
+import org.eclipse.virgo.kernel.install.artifact.internal.bundle.BundleDriver;
+import org.eclipse.virgo.kernel.install.artifact.internal.bundle.StandardBundleInstallArtifact;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+import org.eclipse.virgo.util.common.ThreadSafeArrayListTree;
+import org.eclipse.virgo.util.common.Tree;
+import org.eclipse.virgo.util.io.IOUtils;
+import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
+import org.eclipse.virgo.util.osgi.manifest.BundleManifestFactory;
+
+/**
+ */
+public class StandardBundleInstallArtifactTests {
+
+ private final BundleDriver bundleDriver = createMock(BundleDriver.class);
+
+ private final ArtifactIdentityDeterminer identityDeterminer = createMock(ArtifactIdentityDeterminer.class);
+
+ private final StubInstallArtifactRefreshHandler refreshHandler = new StubInstallArtifactRefreshHandler();
+
+ private final File bundleFile = new File("src/test/resources/org/eclipse/virgo/kernel/install/artifact/internal/sbiat-bundle");
+
+ private final BundleContext bundleContext = new StubBundleContext();
+
+ private final ArtifactStateMonitor artifactStateMonitor = new ArtifactStateMonitor(this.bundleContext);
+
+ private BundleInstallArtifact createInstallArtifact(ArtifactStorage artifactStorage, ArtifactStateMonitor artifactStateMonitor)
+ throws IOException {
+ FileReader reader = null;
+ try {
+ reader = new FileReader(new File(bundleFile, "META-INF/MANIFEST.MF"));
+ BundleManifest bundleManifest = BundleManifestFactory.createBundleManifest(reader);
+ return new StandardBundleInstallArtifact(new ArtifactIdentity(ArtifactIdentityDeterminer.BUNDLE_TYPE,
+ bundleManifest.getBundleSymbolicName().getSymbolicName(), bundleManifest.getBundleVersion(), null), bundleManifest, artifactStorage,
+ bundleDriver, artifactStateMonitor, this.refreshHandler, null, new MockEventLogger(), identityDeterminer);
+ } finally {
+ IOUtils.closeQuietly(reader);
+ }
+ }
+
+ protected ArtifactStorage createArtifactStorage() {
+ return new ArtifactStorage() {
+
+ private final ArtifactFS artifactFS = new DirectoryArtifactFS(bundleFile);
+
+ public void synchronize(URI sourceUri) {
+ }
+
+ public void synchronize() {
+ }
+
+ public ArtifactFS getArtifactFS() {
+ return this.artifactFS;
+ }
+
+ public void delete() {
+ }
+
+ public void rollBack() {
+ }
+ };
+ }
+
+ @Test
+ public void updateAndRefreshWhenNotPartOfAPlan() throws IOException, DeploymentException {
+
+ StandardBundleInstallArtifact artifact = (StandardBundleInstallArtifact) createInstallArtifact(createArtifactStorage(), artifactStateMonitor);
+
+ ArtifactIdentity identity = new ArtifactIdentity(artifact.getType(), artifact.getName(), artifact.getVersion(), artifact.getScopeName());
+ expect(this.identityDeterminer.determineIdentity(isA(File.class), (String)isNull())).andReturn(identity);
+ replay(this.identityDeterminer);
+
+ QuasiBundle quasiBundle = createMock(QuasiBundle.class);
+ StubBundle bundle = new StubBundle();
+ bundle.setState(Bundle.INSTALLED);
+ expect(quasiBundle.getBundle()).andReturn(bundle);
+ replay(quasiBundle);
+
+ artifact.setQuasiBundle(quasiBundle);
+
+ Tree<InstallArtifact> tree = new ThreadSafeArrayListTree<InstallArtifact>(artifact);
+ artifact.setTree(tree);
+
+ expect(this.bundleDriver.update(isA(BundleManifest.class))).andReturn(true);
+ this.bundleDriver.refreshBundle();
+ replay(this.bundleDriver);
+
+ this.refreshHandler.setRefreshOutcome(artifact, true);
+ assertTrue(artifact.refresh());
+ this.refreshHandler.assertRefreshed(artifact);
+ }
+
+ @Test
+ public void testDeploymentProperties() throws Exception {
+ BundleInstallArtifact installArtifact = createInstallArtifact(createArtifactStorage(), artifactStateMonitor);
+
+ installArtifact.getDeploymentProperties().put("foo", "bar");
+ assertEquals("bar", installArtifact.getDeploymentProperties().get("foo"));
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/environment/internal/StandardInstallEnvironmentTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/environment/internal/StandardInstallEnvironmentTests.java
new file mode 100644
index 00000000..235b3c8c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/environment/internal/StandardInstallEnvironmentTests.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.environment.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import org.eclipse.virgo.kernel.osgi.quasi.QuasiFramework;
+
+import org.eclipse.virgo.kernel.install.environment.InstallEnvironment;
+import org.eclipse.virgo.kernel.install.environment.InstallLog;
+import org.eclipse.virgo.kernel.install.environment.internal.StandardInstallEnvironment;
+import org.eclipse.virgo.repository.Repository;
+
+/**
+ */
+public class StandardInstallEnvironmentTests {
+
+ private Repository repository = createMock(Repository.class);
+
+ private InstallLog installLog = createMock(InstallLog.class);
+
+ private QuasiFramework quasiFramework = createMock(QuasiFramework.class);
+
+ @Test
+ public void testStandardInstallEnvironment() {
+ InstallEnvironment ie = new StandardInstallEnvironment(this.repository, this.installLog, this.quasiFramework);
+ assertEquals(this.repository, ie.getRepository());
+ assertEquals(this.installLog, ie.getInstallLog());
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/AbstractPipelineStageTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/AbstractPipelineStageTests.java
new file mode 100644
index 00000000..89adb7d8
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/AbstractPipelineStageTests.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.pipeline;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyBundleDependenciesException;
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.environment.InstallEnvironment;
+import org.eclipse.virgo.kernel.install.environment.InstallLog;
+import org.eclipse.virgo.kernel.install.pipeline.stage.AbstractPipelineStage;
+import org.eclipse.virgo.kernel.install.pipeline.stage.PipelineStage;
+import org.eclipse.virgo.util.common.ThreadSafeArrayListTree;
+import org.eclipse.virgo.util.common.Tree;
+
+/**
+ */
+public class AbstractPipelineStageTests {
+
+ private boolean processed;
+
+ private Tree<InstallArtifact> installTree;
+
+ private InstallEnvironment installEnvironment;
+
+ private InstallLog installLog;
+
+ private final class TestPipelineStage extends AbstractPipelineStage {
+
+ @Override
+ protected void doProcessTree(Tree<InstallArtifact> installTree, InstallEnvironment installEnvironment) {
+ AbstractPipelineStageTests.this.processed = true;
+ }
+
+ public String toString() {
+ return "stage";
+ }
+
+ }
+
+ @Before
+ public void setUp() {
+ this.processed = false;
+ this.installTree = new ThreadSafeArrayListTree<InstallArtifact>(null);
+ this.installEnvironment = createMock(InstallEnvironment.class);
+ this.installLog = createMock(InstallLog.class);
+ }
+
+ private void replayMocks() {
+ replay(this.installEnvironment, this.installLog);
+ }
+
+ private void verifyMocks() {
+ verify(this.installEnvironment, this.installLog);
+ }
+
+ private void resetMocks() {
+ reset(this.installEnvironment, this.installLog);
+ }
+
+ @Test
+ public void testAbstractPipelineStage() throws DeploymentException, UnableToSatisfyBundleDependenciesException {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog);
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().times(2);
+
+ replayMocks();
+
+ PipelineStage ps = new TestPipelineStage();
+ assertEquals(false, this.processed);
+ ps.process(installTree, installEnvironment);
+ assertEquals(true, this.processed);
+
+ verifyMocks();
+ resetMocks();
+ }
+
+
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/internal/CompensatingPipelineTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/internal/CompensatingPipelineTests.java
new file mode 100644
index 00000000..7f303651
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/internal/CompensatingPipelineTests.java
@@ -0,0 +1,358 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.pipeline.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyBundleDependenciesException;
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.environment.InstallEnvironment;
+import org.eclipse.virgo.kernel.install.environment.InstallLog;
+import org.eclipse.virgo.kernel.install.pipeline.Pipeline;
+import org.eclipse.virgo.kernel.install.pipeline.internal.CompensatingPipeline;
+import org.eclipse.virgo.kernel.install.pipeline.stage.AbstractPipelineStage;
+import org.eclipse.virgo.kernel.install.pipeline.stage.PipelineStage;
+import org.eclipse.virgo.medic.eventlog.LogEvent;
+import org.eclipse.virgo.util.common.ThreadSafeArrayListTree;
+import org.eclipse.virgo.util.common.Tree;
+
+/**
+ */
+public class CompensatingPipelineTests {
+
+ private Tree<InstallArtifact> installTree;
+
+ private InstallEnvironment installEnvironment;
+
+ private InstallLog installLog;
+
+ private List<PipelineStage> stageTrace;
+
+ private class GoodPipelineStage extends AbstractPipelineStage {
+
+ @Override
+ protected void doProcessTree(Tree<InstallArtifact> installTree, InstallEnvironment installEnvironment) {
+ CompensatingPipelineTests.this.stageTrace.add(this);
+ }
+
+ public String toString() {
+ return "stage";
+ }
+
+ }
+
+ private class DeploymentExceptionPipelineStage extends AbstractPipelineStage {
+
+ @Override
+ protected void doProcessTree(Tree<InstallArtifact> installTree, InstallEnvironment installEnvironment) throws DeploymentException {
+ CompensatingPipelineTests.this.stageTrace.add(this);
+ throw new DeploymentException("failed");
+ }
+
+ public String toString() {
+ return "DeploymentExceptionPipelineStage";
+ }
+
+ }
+
+ private class UnableToSatisfyBundleDependenciesExceptionPipelineStage extends AbstractPipelineStage {
+
+ @Override
+ protected void doProcessTree(Tree<InstallArtifact> installTree, InstallEnvironment installEnvironment)
+ throws UnableToSatisfyBundleDependenciesException {
+ CompensatingPipelineTests.this.stageTrace.add(this);
+ throw new UnableToSatisfyBundleDependenciesException("failed", null, null);
+ }
+
+ public String toString() {
+ return "UnableToSatisfyBundleDependenciesException";
+ }
+
+ }
+
+ private class RuntimeExceptionPipelineStage extends AbstractPipelineStage {
+
+ @Override
+ protected void doProcessTree(Tree<InstallArtifact> installTree, InstallEnvironment installEnvironment) {
+ CompensatingPipelineTests.this.stageTrace.add(this);
+ throw new RuntimeException("failed");
+ }
+
+ public String toString() {
+ return "RuntimeException";
+ }
+
+ }
+
+ private class CompensationStage extends AbstractPipelineStage {
+
+ @Override
+ protected void doProcessTree(Tree<InstallArtifact> installTree, InstallEnvironment installEnvironment) {
+ CompensatingPipelineTests.this.stageTrace.add(this);
+ }
+
+ public String toString() {
+ return "compensation";
+ }
+
+ }
+
+ @Before
+ public void setUp() {
+ this.installTree = new ThreadSafeArrayListTree<InstallArtifact>(null);
+ this.installEnvironment = createMock(InstallEnvironment.class);
+ this.installLog = createMock(InstallLog.class);
+ this.stageTrace = new ArrayList<PipelineStage>();
+ }
+
+ private void replayMocks() {
+ replay(this.installEnvironment, this.installLog);
+ }
+
+ private void verifyMocks() {
+ verify(this.installEnvironment, this.installLog);
+ }
+
+ private void resetMocks() {
+ reset(this.installEnvironment, this.installLog);
+ }
+
+ @Test
+ public void testEmptyPipeline() throws DeploymentException, UnableToSatisfyBundleDependenciesException {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog);
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().times(2);
+
+ replayMocks();
+
+ List<PipelineStage> expectedStageTrace = new ArrayList<PipelineStage>();
+
+ Pipeline p = new CompensatingPipeline(new CompensationStage());
+ p.process(installTree, installEnvironment);
+
+ assertEquals(expectedStageTrace, this.stageTrace);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+ @Test
+ public void testSimplePipeline() throws DeploymentException, UnableToSatisfyBundleDependenciesException {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog).anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().times(6);
+
+ replayMocks();
+
+ List<PipelineStage> expectedStageTrace = new ArrayList<PipelineStage>();
+
+ Pipeline p = new CompensatingPipeline(new CompensationStage());
+
+ PipelineStage ps1 = new GoodPipelineStage();
+ p.appendStage(ps1);
+ expectedStageTrace.add(ps1);
+
+ PipelineStage ps2 = new GoodPipelineStage();
+ p.appendStage(ps2);
+ expectedStageTrace.add(ps2);
+
+ p.process(installTree, installEnvironment);
+
+ assertEquals(expectedStageTrace, this.stageTrace);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+ @Test
+ public void testEarlyDeploymentException() throws Exception {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog).anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class), isA(String.class));
+ expectLastCall().anyTimes();
+ this.installLog.logFailure(isA(LogEvent.class), isA(Throwable.class));
+ expectLastCall().anyTimes();
+
+ replayMocks();
+
+ List<PipelineStage> expectedStageTrace = new ArrayList<PipelineStage>();
+
+ CompensationStage compensation = new CompensationStage();
+ Pipeline p = new CompensatingPipeline(compensation);
+
+ PipelineStage ps1 = new DeploymentExceptionPipelineStage();
+ p.appendStage(ps1);
+ expectedStageTrace.add(ps1);
+
+ PipelineStage ps2 = new GoodPipelineStage();
+ p.appendStage(ps2);
+
+ expectedStageTrace.add(compensation);
+
+ try {
+ p.process(installTree, installEnvironment);
+ assertTrue(false);
+ } catch (DeploymentException e) {
+ }
+
+ assertEquals(expectedStageTrace, this.stageTrace);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+ @Test
+ public void testLateDeploymentException() throws Exception {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog).anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class), isA(String.class));
+ expectLastCall().anyTimes();
+ this.installLog.logFailure(isA(LogEvent.class), isA(Throwable.class));
+ expectLastCall().anyTimes();
+
+
+ replayMocks();
+
+ List<PipelineStage> expectedStageTrace = new ArrayList<PipelineStage>();
+
+ CompensationStage compensation = new CompensationStage();
+ Pipeline p = new CompensatingPipeline(compensation);
+
+ PipelineStage ps1 = new GoodPipelineStage();
+ p.appendStage(ps1);
+ expectedStageTrace.add(ps1);
+
+ PipelineStage ps2 = new DeploymentExceptionPipelineStage();
+ p.appendStage(ps2);
+ expectedStageTrace.add(ps2);
+
+ expectedStageTrace.add(compensation);
+
+ try {
+ p.process(installTree, installEnvironment);
+ assertTrue(false);
+ } catch (DeploymentException e) {
+ }
+
+ assertEquals(expectedStageTrace, this.stageTrace);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+ @Test
+ public void testUnableToSatisfyBundleDependenciesException() throws Exception {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog).anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class), isA(String.class));
+ expectLastCall().anyTimes();
+ this.installLog.logFailure(isA(LogEvent.class), isA(Throwable.class));
+ expectLastCall().anyTimes();
+
+ replayMocks();
+
+ List<PipelineStage> expectedStageTrace = new ArrayList<PipelineStage>();
+
+ CompensationStage compensation = new CompensationStage();
+ Pipeline p = new CompensatingPipeline(compensation);
+
+ PipelineStage ps1 = new UnableToSatisfyBundleDependenciesExceptionPipelineStage();
+ p.appendStage(ps1);
+ expectedStageTrace.add(ps1);
+
+ PipelineStage ps2 = new GoodPipelineStage();
+ p.appendStage(ps2);
+
+ expectedStageTrace.add(compensation);
+
+ try {
+ p.process(installTree, installEnvironment);
+ assertTrue(false);
+ } catch (UnableToSatisfyBundleDependenciesException e) {
+ }
+
+ assertEquals(expectedStageTrace, this.stageTrace);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+ @Test
+ public void testRuntimeException() throws Exception {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog).anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class), isA(String.class));
+ expectLastCall().anyTimes();
+ this.installLog.logFailure(isA(LogEvent.class), isA(Throwable.class));
+ expectLastCall().anyTimes();
+
+ replayMocks();
+
+ List<PipelineStage> expectedStageTrace = new ArrayList<PipelineStage>();
+
+ CompensationStage compensation = new CompensationStage();
+ Pipeline p = new CompensatingPipeline(compensation);
+
+ PipelineStage ps1 = new RuntimeExceptionPipelineStage();
+ p.appendStage(ps1);
+ expectedStageTrace.add(ps1);
+
+ PipelineStage ps2 = new GoodPipelineStage();
+ p.appendStage(ps2);
+
+ expectedStageTrace.add(compensation);
+
+ try {
+ p.process(installTree, installEnvironment);
+ assertTrue(false);
+ } catch (RuntimeException e) {
+ }
+
+ assertEquals(expectedStageTrace, this.stageTrace);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/internal/StandardPipelineTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/internal/StandardPipelineTests.java
new file mode 100644
index 00000000..7855bfea
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/internal/StandardPipelineTests.java
@@ -0,0 +1,269 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.pipeline.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reset;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyBundleDependenciesException;
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.environment.InstallEnvironment;
+import org.eclipse.virgo.kernel.install.environment.InstallLog;
+import org.eclipse.virgo.kernel.install.pipeline.Pipeline;
+import org.eclipse.virgo.kernel.install.pipeline.internal.StandardPipeline;
+import org.eclipse.virgo.kernel.install.pipeline.stage.AbstractPipelineStage;
+import org.eclipse.virgo.kernel.install.pipeline.stage.PipelineStage;
+import org.eclipse.virgo.util.common.ThreadSafeArrayListTree;
+import org.eclipse.virgo.util.common.Tree;
+
+/**
+ */
+public class StandardPipelineTests {
+
+ private Tree<InstallArtifact> installTree;
+
+ private InstallEnvironment installEnvironment;
+
+ private InstallLog installLog;
+
+ private List<PipelineStage> stageTrace;
+
+ private class TestPipelineStage extends AbstractPipelineStage {
+
+ @Override
+ protected void doProcessTree(Tree<InstallArtifact> installTree, InstallEnvironment installEnvironment) {
+ StandardPipelineTests.this.stageTrace.add(this);
+ }
+
+ public String toString() {
+ return "stage";
+ }
+
+ }
+
+ private class SelfModifyingPipelineStage extends TestPipelineStage {
+
+ private final Pipeline pipeline;
+
+ private final PipelineStage extraStage;
+
+ public SelfModifyingPipelineStage(Pipeline pipeline, PipelineStage extraStage) {
+ this.pipeline = pipeline;
+ this.extraStage = extraStage;
+ }
+
+ @Override
+ protected void doProcessTree(Tree<InstallArtifact> installTree, InstallEnvironment installEnvironment) {
+ super.doProcessTree(installTree, installEnvironment);
+ this.pipeline.appendStage(this.extraStage);
+ }
+
+ }
+
+ @Before
+ public void setUp() {
+ this.installTree = new ThreadSafeArrayListTree<InstallArtifact>(null);;
+ this.installEnvironment = createMock(InstallEnvironment.class);
+ this.installLog = createMock(InstallLog.class);
+ this.stageTrace = new ArrayList<PipelineStage>();
+ }
+
+ private void replayMocks() {
+ replay(this.installEnvironment, this.installLog);
+ }
+
+ private void verifyMocks() {
+ verify(this.installEnvironment, this.installLog);
+ }
+
+ private void resetMocks() {
+ reset(this.installEnvironment, this.installLog);
+ }
+
+ @Test
+ public void testEmptyPipeline() throws DeploymentException, UnableToSatisfyBundleDependenciesException {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog);
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().times(2);
+
+ replayMocks();
+
+ Pipeline p = new StandardPipeline();
+ p.process(installTree, installEnvironment);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+ @Test
+ public void testSimplePipeline() throws DeploymentException, UnableToSatisfyBundleDependenciesException {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog).anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().times(6);
+
+ replayMocks();
+
+ List<PipelineStage> expectedStageTrace = new ArrayList<PipelineStage>();
+
+ Pipeline p = new StandardPipeline();
+
+ PipelineStage ps1 = new TestPipelineStage();
+ p.appendStage(ps1);
+ expectedStageTrace.add(ps1);
+
+ PipelineStage ps2 = new TestPipelineStage();
+ p.appendStage(ps2);
+ expectedStageTrace.add(ps2);
+
+ p.process(installTree, installEnvironment);
+
+ assertEquals(expectedStageTrace, this.stageTrace);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+ @Test
+ public void testPipelineWithDuplicatedStage() throws DeploymentException, UnableToSatisfyBundleDependenciesException {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog).anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().times(8);
+
+ replayMocks();
+
+ List<PipelineStage> expectedStageTrace = new ArrayList<PipelineStage>();
+
+ Pipeline p = new StandardPipeline();
+
+ PipelineStage ps1 = new TestPipelineStage();
+ p.appendStage(ps1);
+ expectedStageTrace.add(ps1);
+
+ PipelineStage ps2 = new TestPipelineStage();
+ p.appendStage(ps2);
+ expectedStageTrace.add(ps2);
+
+ p.appendStage(ps1);
+ expectedStageTrace.add(ps1);
+
+ p.process(installTree, installEnvironment);
+
+ assertEquals(expectedStageTrace, this.stageTrace);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+ @Test
+ public void testNestedPipeline() throws DeploymentException, UnableToSatisfyBundleDependenciesException {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog).anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().times(14);
+
+ replayMocks();
+
+ List<PipelineStage> expectedStageTrace = new ArrayList<PipelineStage>();
+
+ Pipeline child1 = new StandardPipeline();
+
+ PipelineStage ps1 = new TestPipelineStage();
+ child1.appendStage(ps1);
+ expectedStageTrace.add(ps1);
+
+ PipelineStage ps2 = new TestPipelineStage();
+ child1.appendStage(ps2);
+ expectedStageTrace.add(ps2);
+
+ Pipeline child2 = new StandardPipeline();
+
+ PipelineStage ps3 = new TestPipelineStage();
+ child2.appendStage(ps3);
+ expectedStageTrace.add(ps3);
+
+ PipelineStage ps4 = new TestPipelineStage();
+ child2.appendStage(ps4);
+ expectedStageTrace.add(ps4);
+
+ Pipeline parent = new StandardPipeline();
+ parent.appendStage(child1);
+ parent.appendStage(child2);
+
+ parent.process(installTree, installEnvironment);
+
+ assertEquals(expectedStageTrace, this.stageTrace);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+ @Test
+ public void testSelfModifyingPipeline() throws DeploymentException, UnableToSatisfyBundleDependenciesException {
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog).anyTimes();
+ this.installLog.log(isA(PipelineStage.class), isA(String.class), isA(String.class));
+ expectLastCall().times(12);
+
+ replayMocks();
+
+ List<PipelineStage> expectedStageTrace = new ArrayList<PipelineStage>();
+
+ Pipeline p = new StandardPipeline();
+
+ PipelineStage ps1 = new TestPipelineStage();
+ p.appendStage(ps1);
+ expectedStageTrace.add(ps1);
+
+ PipelineStage ps4 = new TestPipelineStage();
+ PipelineStage ps2 = new SelfModifyingPipelineStage(p, ps4);
+ p.appendStage(ps2);
+ expectedStageTrace.add(ps2);
+
+ PipelineStage ps5 = new TestPipelineStage();
+ PipelineStage ps3 = new SelfModifyingPipelineStage(p, ps5);
+ p.appendStage(ps3);
+ expectedStageTrace.add(ps3);
+
+ expectedStageTrace.add(ps4);
+ expectedStageTrace.add(ps5);
+
+ p.process(installTree, installEnvironment);
+
+ assertEquals(expectedStageTrace, this.stageTrace);
+
+ verifyMocks();
+ resetMocks();
+
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/TransformationStageTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/TransformationStageTests.java
new file mode 100644
index 00000000..1168287c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/TransformationStageTests.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.pipeline.stage.transform;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceRegistration;
+
+import org.eclipse.virgo.kernel.osgi.framework.UnableToSatisfyBundleDependenciesException;
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.environment.InstallEnvironment;
+import org.eclipse.virgo.kernel.install.environment.InstallLog;
+import org.eclipse.virgo.kernel.install.pipeline.stage.PipelineStage;
+import org.eclipse.virgo.kernel.install.pipeline.stage.transform.Transformer;
+import org.eclipse.virgo.kernel.install.pipeline.stage.transform.internal.TransformationStage;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+import org.eclipse.virgo.util.common.Tree;
+
+/**
+ * TODO Document TransformationStageTests
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * TODO Document concurrent semantics of TransformationStageTests
+ *
+ */
+public class TransformationStageTests {
+
+ private Tree<InstallArtifact> installTree;
+
+ private InstallEnvironment installEnvironment;
+
+ private Transformer transformer1;
+
+ private Transformer transformer2;
+
+ private InstallLog installLog;
+
+ private PipelineStage transformationStage;
+
+ private StubBundleContext bundleContext = new StubBundleContext();
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() {
+ this.installTree = createMock(Tree.class);
+ this.transformer1 = createMock(Transformer.class);
+ this.transformer2 = createMock(Transformer.class);
+ this.transformationStage = new TransformationStage(bundleContext);
+ this.installEnvironment = createMock(InstallEnvironment.class);
+ this.installLog = createMock(InstallLog.class);
+
+ expect(this.installEnvironment.getInstallLog()).andReturn(this.installLog).anyTimes();
+ this.installLog.log(isA(Object.class), isA(String.class), isA(String.class));
+ expectLastCall().anyTimes();
+ }
+
+ @Test
+ public void transformation() throws DeploymentException, UnableToSatisfyBundleDependenciesException {
+ this.transformer1.transform(this.installTree, this.installEnvironment);
+ this.transformer2.transform(this.installTree, this.installEnvironment);
+ this.transformer2.transform(this.installTree, this.installEnvironment);
+
+ replay(this.transformer1, this.transformer2, this.installEnvironment, this.installLog);
+
+ this.transformationStage.process(this.installTree, this.installEnvironment);
+
+ ServiceRegistration registration1 = this.bundleContext.registerService(Transformer.class.getName(), this.transformer1, null);
+ ServiceRegistration registration2= this.bundleContext.registerService(Transformer.class.getName(), this.transformer2, null);
+
+ this.transformationStage.process(this.installTree, this.installEnvironment);
+
+ registration1.unregister();
+
+ this.transformationStage.process(this.installTree, this.installEnvironment);
+
+ registration2.unregister();
+
+ this.transformationStage.process(this.installTree, this.installEnvironment);
+
+ verify(this.transformer1, this.transformer2, this.installEnvironment, this.installLog);
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/internal/SyntheticContextBundleCreatingTransformerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/internal/SyntheticContextBundleCreatingTransformerTests.java
new file mode 100644
index 00000000..afd0ceab
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/internal/SyntheticContextBundleCreatingTransformerTests.java
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.pipeline.stage.transform.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.isNull;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.jar.JarFile;
+
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+
+import org.eclipse.virgo.kernel.artifact.fs.StandardArtifactFSFactory;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.ArtifactIdentity;
+import org.eclipse.virgo.kernel.install.artifact.BundleInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifactTreeFactory;
+import org.eclipse.virgo.kernel.install.artifact.PlanInstallArtifact;
+import org.eclipse.virgo.kernel.install.artifact.internal.ArtifactStorage;
+import org.eclipse.virgo.kernel.install.artifact.internal.ArtifactStorageFactory;
+import org.eclipse.virgo.kernel.install.artifact.internal.StandardArtifactStorageFactory;
+import org.eclipse.virgo.kernel.install.artifact.internal.scoping.ScopeNameFactory;
+import org.eclipse.virgo.kernel.install.environment.InstallEnvironment;
+import org.eclipse.virgo.kernel.install.pipeline.stage.transform.Transformer;
+import org.eclipse.virgo.kernel.install.pipeline.stage.transform.internal.SyntheticContextBundleCreatingTransformer;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.util.common.ThreadSafeArrayListTree;
+import org.eclipse.virgo.util.common.Tree;
+import org.eclipse.virgo.util.io.PathReference;
+import org.eclipse.virgo.util.osgi.manifest.BundleManifest;
+import org.eclipse.virgo.util.osgi.manifest.BundleManifestFactory;
+import org.eclipse.virgo.util.osgi.manifest.ImportedBundle;
+
+/**
+ */
+public final class SyntheticContextBundleCreatingTransformerTests {
+
+ private final InstallArtifactTreeFactory installArtifactTreeFactory = createMock(InstallArtifactTreeFactory.class);
+
+ private final InstallEnvironment installEnvironment = createMock(InstallEnvironment.class);
+
+ private final ArtifactStorageFactory artifactStorageFactory = new StandardArtifactStorageFactory(new PathReference("target/work"),
+ new StandardArtifactFSFactory(), new MockEventLogger());
+
+ private final Transformer transformer = new SyntheticContextBundleCreatingTransformer(this.installArtifactTreeFactory,
+ this.artifactStorageFactory);
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void basicSyntheticContextCreation() throws DeploymentException, FileNotFoundException, IOException {
+ Tree<InstallArtifact> planInstallTree = createMockPlan(true, new Version(1, 0, 0), "plan-name", "bundle1", "bundle2", "bundle3");
+ InstallArtifact syntheticContextInstallArtifact = createMock(InstallArtifact.class);
+
+ File syntheticBundleDir = new File("target/work/staging/plan-name-1/bundle/plan-name-1-synthetic.context/1.0.0/plan-name-1-synthetic.context.jar").getAbsoluteFile();
+ expect(
+ this.installArtifactTreeFactory.constructInstallArtifactTree(eq(new ArtifactIdentity("bundle", "plan-name-1-synthetic.context",
+ new Version(1, 0, 0), ScopeNameFactory.createScopeName("plan-name", new Version(1, 0, 0)))), isA(ArtifactStorage.class),
+ (Map<String, String>) isNull(), (String) isNull())).andReturn(
+ new ThreadSafeArrayListTree<InstallArtifact>(syntheticContextInstallArtifact));
+
+ replay(this.installEnvironment, this.installArtifactTreeFactory);
+
+ this.transformer.transform(planInstallTree, this.installEnvironment);
+
+ verify(this.installEnvironment, this.installArtifactTreeFactory);
+
+ File manifest = new File(syntheticBundleDir, JarFile.MANIFEST_NAME);
+ assertTrue(manifest.exists());
+
+ assertBundlesImported(manifest, "bundle1", "bundle2", "bundle3");
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void nestedPlanSyntheticContextCreation() throws DeploymentException, FileNotFoundException, IOException {
+ Tree<InstallArtifact> rootPlanInstallTree = createMockPlan(true, new Version(1, 0, 0), "plan-name", "bundle1");
+ rootPlanInstallTree.addChild(createMockPlan(true, new Version(1, 0, 0), "nested-plan", "bundle2", "bundle3"));
+
+ InstallArtifact syntheticContextInstallArtifact = createMock(InstallArtifact.class);
+
+ File syntheticBundleDir = new File("target/work/staging/plan-name-1/bundle/plan-name-1-synthetic.context/1.0.0/plan-name-1-synthetic.context.jar").getAbsoluteFile();
+ expect(
+ this.installArtifactTreeFactory.constructInstallArtifactTree(eq(new ArtifactIdentity("bundle", "plan-name-1-synthetic.context",
+ new Version(1, 0, 0), ScopeNameFactory.createScopeName("plan-name", new Version(1, 0, 0)))), isA(ArtifactStorage.class),
+ (Map<String, String>) isNull(), (String) isNull())).andReturn(
+ new ThreadSafeArrayListTree<InstallArtifact>(syntheticContextInstallArtifact));
+
+ replay(this.installEnvironment, this.installArtifactTreeFactory);
+
+ this.transformer.transform(rootPlanInstallTree, this.installEnvironment);
+
+ verify(this.installEnvironment, this.installArtifactTreeFactory);
+
+ File manifest = new File(syntheticBundleDir, JarFile.MANIFEST_NAME);
+ assertTrue(manifest.exists());
+
+ assertBundlesImported(manifest, "bundle1", "bundle2", "bundle3");
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void syntheticContextOnlyCreatedForScopedPlans() throws DeploymentException, FileNotFoundException, IOException {
+ Tree<InstallArtifact> rootPlanInstallTree = createMockPlan(false, new Version(1, 0, 0), "plan-name", "bundle1");
+ // This test need not use TreeUtils.addChild
+ rootPlanInstallTree.addChild(createMockPlan(true, new Version(1, 0, 0), "nested-plan", "bundle2", "bundle3"));
+
+ InstallArtifact syntheticContextInstallArtifact = createMock(InstallArtifact.class);
+
+ File syntheticBundleDir = new File(
+ "target/work/staging/nested-plan-1/bundle/nested-plan-1-synthetic.context/1.0.0/nested-plan-1-synthetic.context.jar").getAbsoluteFile();
+ expect(
+ this.installArtifactTreeFactory.constructInstallArtifactTree(eq(new ArtifactIdentity("bundle", "nested-plan-1-synthetic.context",
+ new Version(1, 0, 0), ScopeNameFactory.createScopeName("nested-plan", new Version(1, 0, 0)))), isA(ArtifactStorage.class),
+ (Map<String, String>) isNull(), (String) isNull())).andReturn(
+ new ThreadSafeArrayListTree<InstallArtifact>(syntheticContextInstallArtifact));
+
+ replay(this.installEnvironment, this.installArtifactTreeFactory);
+
+ this.transformer.transform(rootPlanInstallTree, this.installEnvironment);
+
+ verify(this.installEnvironment, this.installArtifactTreeFactory);
+
+ File manifest = new File(syntheticBundleDir, JarFile.MANIFEST_NAME);
+ assertTrue(manifest.exists());
+
+ assertBundlesImported(manifest, "bundle2", "bundle3");
+ }
+
+ private void assertBundlesImported(File manifestFile, String... symbolicNames) throws FileNotFoundException, IOException {
+ BundleManifest bundleManifest = BundleManifestFactory.createBundleManifest(new FileReader(manifestFile));
+ List<ImportedBundle> importedBundles = bundleManifest.getImportBundle().getImportedBundles();
+ assertEquals(symbolicNames.length, importedBundles.size());
+
+ for (String symbolicName : symbolicNames) {
+ assertBundleImported(importedBundles, symbolicName);
+ }
+ }
+
+ private void assertBundleImported(List<ImportedBundle> importedBundles, String symbolicName) {
+ for (ImportedBundle importedBundle : importedBundles) {
+ if (symbolicName.equals(importedBundle.getBundleSymbolicName())) {
+ return;
+ }
+ }
+ fail("No import for symbolic name '" + symbolicName + "' was found among imported bundles " + importedBundles);
+ }
+
+ private InstallArtifact createMockBundleInstallArtifact(String symbolicName) {
+ InstallArtifact bundle = createMock(BundleInstallArtifact.class);
+ expect(bundle.getName()).andReturn(symbolicName).anyTimes();
+ replay(bundle);
+ return bundle;
+ }
+
+ private Tree<InstallArtifact> createMockPlan(boolean scoped, Version version, String name, String... bundleSymbolicNames) {
+ PlanInstallArtifact plan = createMock(PlanInstallArtifact.class);
+
+ expect(plan.isScoped()).andReturn(scoped).anyTimes();
+ expect(plan.getVersion()).andReturn(version).anyTimes();
+ expect(plan.getName()).andReturn(name).anyTimes();
+
+ replay(plan);
+
+ Tree<InstallArtifact> installTree = new ThreadSafeArrayListTree<InstallArtifact>(plan);
+
+ for (String bundleSymbolicName : bundleSymbolicNames) {
+ InstallArtifact bundle = createMockBundleInstallArtifact(bundleSymbolicName);
+ // This test need not use TreeUtils.addChild
+ installTree.addChild(new ThreadSafeArrayListTree<InstallArtifact>(bundle));
+ }
+ return installTree;
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/internal/UserInstalledTaggingTransformerTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/internal/UserInstalledTaggingTransformerTests.java
new file mode 100644
index 00000000..bd5425ba
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/install/pipeline/stage/transform/internal/UserInstalledTaggingTransformerTests.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.install.pipeline.stage.transform.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import org.junit.Test;
+
+
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.kernel.install.environment.InstallEnvironment;
+import org.eclipse.virgo.kernel.install.pipeline.stage.transform.internal.UserInstalledTaggingTransformer;
+import org.eclipse.virgo.util.common.Tree;
+
+public class UserInstalledTaggingTransformerTests {
+
+ private final UserInstalledTaggingTransformer transformer = new UserInstalledTaggingTransformer();
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void test() throws DeploymentException {
+ InstallEnvironment installEnvironment = createMock(InstallEnvironment.class);
+ Tree<InstallArtifact> installTree = createMock(Tree.class);
+ InstallArtifact installArtifact = createMock(InstallArtifact.class);
+
+ expect(installTree.getValue()).andReturn(installArtifact);
+ expect(installArtifact.setProperty(eq("user.installed"), eq("true"))).andReturn(null);
+
+ replay(installEnvironment, installTree, installArtifact);
+
+ this.transformer.transform(installTree, installEnvironment);
+
+ verify(installEnvironment, installTree, installArtifact);
+ }
+}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/META-INF/MANIFEST.MF
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/META-INF/web/index.jsp b/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/META-INF/web/index.jsp
new file mode 100644
index 00000000..8102008f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/META-INF/web/index.jsp
@@ -0,0 +1,12 @@
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Hello Web!</title>
+</head>
+<body>
+<p>Hello Web!</p>
+</body>
+</html> \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/somefile.txt b/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/somefile.txt
new file mode 100644
index 00000000..c57eff55
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/somefile.txt
@@ -0,0 +1 @@
+Hello World! \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/somefolder/.gitignore b/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/somefolder/.gitignore
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artefacts/exploded/somefolder/.gitignore
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/malformed-application-context.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/malformed-application-context.jar
new file mode 100644
index 00000000..ea524f8c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/malformed-application-context.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/nobsn.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/nobsn.jar
new file mode 100644
index 00000000..032a7df2
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/nobsn.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/rawfile b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/rawfile
new file mode 100644
index 00000000..93a4a0b2
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/rawfile
@@ -0,0 +1 @@
+rawfile \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple.jar
new file mode 100644
index 00000000..7efafc13
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..f976ff04
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Manifest-Version: 1.0
+Created-By: 1.6.0_07 (Apple Inc.)
+Bundle-SymbolicName: test
+
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple/test/rawfile b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple/test/rawfile
new file mode 100644
index 00000000..93a4a0b2
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/simple/test/rawfile
@@ -0,0 +1 @@
+rawfile \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/test.properties b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/test.properties
new file mode 100644
index 00000000..efc73add
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/artifacts/test.properties
@@ -0,0 +1 @@
+a=b
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.B.after.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.B.after.jar
new file mode 100644
index 00000000..1059cb73
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.B.after.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.B.before.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.B.before.jar
new file mode 100644
index 00000000..e2e02495
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.B.before.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.C.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.C.jar
new file mode 100644
index 00000000..e30aebad
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/but/but.C.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/app/1.0/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/app/1.0/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..a1bb7684
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/app/1.0/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: com.springsource.app
+Bundle-Version: 1.0
+Import-Package: org.hibernate;version="[3.2.5,3.2.5]",org.springframework.orm.hibernate;version="2.5.3"
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/hibernate/3.2.5/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/hibernate/3.2.5/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..4a044c81
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/hibernate/3.2.5/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.hibernate.clone
+Bundle-Version: 3.2.5
+Export-Package: org.hibernate;version="3.2.5"
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/hibernate/3.2.6/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/hibernate/3.2.6/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..2b5b9d41
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/hibernate/3.2.6/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.hibernate.clone
+Bundle-Version: 3.2.6
+Export-Package: org.hibernate;version="3.2.6"
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/spring/2.5.3/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/spring/2.5.3/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..e4aa5be8
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/cloning/spring/2.5.3/META-INF/MANIFEST.MF
@@ -0,0 +1,6 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.springframework.clone
+Bundle-Version: 2.5.3
+Export-Package: org.springframework.orm.hibernate;version="2.5.3";uses:="org.hibernate"
+Import-Package: org.hibernate
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/config/BundleUpdateTests/repository.properties b/org.eclipse.virgo.kernel.deployer/src/test/resources/config/BundleUpdateTests/repository.properties
new file mode 100644
index 00000000..945bc8b1
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/config/BundleUpdateTests/repository.properties
@@ -0,0 +1,7 @@
+bundles.type=external
+bundles.searchPattern=../{bundle}/target/classes
+
+ivy-cache-bundles.type=external
+ivy-cache-bundles.searchPattern=../${ivy.cache::ivy-cache}/repository/{org}/{name}/{version}/{bundle}.jar
+
+chain=bundles,ivy-cache-bundles
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/dat/one/bundle/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/dat/one/bundle/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..e550bfa5
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/dat/one/bundle/META-INF/MANIFEST.MF
@@ -0,0 +1 @@
+Manifest-Version: 1
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/dat/two/bundle/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/dat/two/bundle/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..e550bfa5
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/dat/two/bundle/META-INF/MANIFEST.MF
@@ -0,0 +1 @@
+Manifest-Version: 1
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/debug.options b/org.eclipse.virgo.kernel.deployer/src/test/resources/debug.options
new file mode 100644
index 00000000..847eb366
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/debug.options
@@ -0,0 +1,4 @@
+org.eclipse.osgi/resolver/debug=true
+org.eclipse.osgi/resolver/wiring=true
+org.eclipse.osgi/resolver/imports=true
+org.eclipse.osgi/eclipseadaptor/debug/platformadmin/resolver=true \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar1.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar1.jar
new file mode 100644
index 00000000..15f1858b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar1.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar2.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar2.jar
new file mode 100644
index 00000000..945bb179
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar2.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar2a.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar2a.jar
new file mode 100644
index 00000000..945bb179
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/different-hash-test/jar2a.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/dummy/other/ignore.txt b/org.eclipse.virgo.kernel.deployer/src/test/resources/dummy/other/ignore.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/dummy/other/ignore.txt
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/dummy/other/jar2.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/dummy/other/jar2.jar
new file mode 100644
index 00000000..ecd3eac9
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/dummy/other/jar2.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/exploded/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/exploded/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..9a0adaaa
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/exploded/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: org.eclipse.virgo.server.exploded
+Bundle-Version: 1.2.3
+
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/export-same-package/root-a/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/export-same-package/root-a/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..78a09911
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/export-same-package/root-a/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Bundle-SymbolicName: bundleA
+Bundle-Version: 1.0
+Bundle-ManifestVersion: 2
+Export-Package: com.foo
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/export-same-package/root-b/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/export-same-package/root-b/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..e489459e
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/export-same-package/root-b/META-INF/MANIFEST.MF
@@ -0,0 +1,4 @@
+Bundle-SymbolicName: bundleB
+Bundle-Version: 1.0
+Bundle-ManifestVersion: 2
+Export-Package: com.foo
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/faulty/imp/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/faulty/imp/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..f15776db
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/faulty/imp/META-INF/MANIFEST.MF
@@ -0,0 +1,5 @@
+Manifest-Version: 1
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: faulty.imp
+Bundle-Version: 1.2.3
+Import-Package: foo.bar
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/a1.txt b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/a1.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/a1.txt
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/z/a1z.txt b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/z/a1z.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/z/a1z.txt
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/z/file.wont.be.found b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/z/file.wont.be.found
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/a/1/z/file.wont.be.found
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/b/1/b1.txt b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/b/1/b1.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/b/1/b1.txt
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/b/1/file.wont.be.found b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/b/1/file.wont.be.found
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/b/1/file.wont.be.found
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/c/1/c1.txt b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/c/1/c1.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/c/1/c1.txt
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/c/c.txt b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/c/c.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/file-system-searcher/c/c.txt
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/invalid/bundle/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/invalid/bundle/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..4f019d76
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/invalid/bundle/META-INF/MANIFEST.MF
@@ -0,0 +1,2 @@
+Bundle-SymbolicName: org.eclipse.virgo.server.invalid
+Import-Package: org.springframework.core
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/jars/dummy.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/jars/dummy.jar
new file mode 100644
index 00000000..7ab5fb31
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/jars/dummy.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/jars/mockbundle.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/jars/mockbundle.jar
new file mode 100644
index 00000000..37fe0034
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/jars/mockbundle.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/exploded/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/exploded/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..d1a0ac69
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/exploded/META-INF/MANIFEST.MF
@@ -0,0 +1,2 @@
+Library-SymbolicName: org.exploded
+Library-Version: 1.2.3
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/exploded/bundle.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/exploded/bundle.jar
new file mode 100644
index 00000000..f11d1abb
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/exploded/bundle.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/spring-instrumented.libd b/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/spring-instrumented.libd
new file mode 100644
index 00000000..1d468650
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/spring-instrumented.libd
@@ -0,0 +1,4 @@
+Library-SymbolicName: org.springframework.instrumented
+Library-Version: 2.5.1
+Import-Bundle: org.springframework.core.instrumented;version=2.5.2,
+ org.springframework.beans.instrumented;version=2.5.2 \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/spring.libd b/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/spring.libd
new file mode 100644
index 00000000..4288bbef
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/libraries/spring.libd
@@ -0,0 +1,5 @@
+Library-SymbolicName: org.springframework
+Library-Name: Spring framework
+Library-Description: description
+Library-Version: 2.5.1
+Import-Bundle: org.springframework.bundle.spring.core;version=2.5.1,org.springframework.bundle.spring.beans;version=2.5.1 \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/manifests/invalid-import-package.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/manifests/invalid-import-package.MF
new file mode 100644
index 00000000..40d36d57
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/manifests/invalid-import-package.MF
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Hotel Booking Service Implementation
+Bundle-SymbolicName: org.springframework.booking.internal
+Import-Package: org.springframework.booking.domain,
+ org.springframework.booking.service,
+Export-Package: org.springframework.booking.internal
+Import-Library: javax_persistence;version="1.0.0",
+ org.springframework_spring;version="2.5.3",
+ org_hibernate;version="3.2.6.ga"
+
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..20f5886d
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Application-SymbolicName: org.eclipse.virgo.kernel.deployer.app.MultiBundleApplicationTestApp
+Application-Version: 1.0.0
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/one.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/one.jar
new file mode 100644
index 00000000..9445d6b8
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/one.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/two.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/two.jar
new file mode 100644
index 00000000..c009ee09
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-bundle-application-tests/two.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-root/root-a/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-root/root-a/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..44b62505
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-root/root-a/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: multi.root
+Bundle-Version: 1.0
+Test: A
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-root/root-b/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-root/root-b/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..b9c297c5
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/multi-root/root-b/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: multi.root
+Bundle-Version: 1.0
+Test: B
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/org/eclipse/virgo/kernel/install/artifact/internal/sbiat-bundle/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/org/eclipse/virgo/kernel/install/artifact/internal/sbiat-bundle/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..baf82172
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/org/eclipse/virgo/kernel/install/artifact/internal/sbiat-bundle/META-INF/MANIFEST.MF
@@ -0,0 +1 @@
+Bundle-SymbolicName: sbiat-bundle
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/duplicate-repository-in-chain.properties b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/duplicate-repository-in-chain.properties
new file mode 100644
index 00000000..6f11ef61
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/duplicate-repository-in-chain.properties
@@ -0,0 +1,7 @@
+bundles-ext.type=external
+bundles-ext.searchPattern=repository/bundles/ext/*.jar
+
+bundles-usr.type=external
+bundles-usr.searchPattern=repository/bundles/usr/*.jar
+
+chain=bundles-ext,bundles-usr,bundles-ext,bundles-usr
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/missing-chain.properties b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/missing-chain.properties
new file mode 100644
index 00000000..f0cb96a1
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/missing-chain.properties
@@ -0,0 +1,2 @@
+bundles-ext.type=external
+bundles-ext.searchPattern=repository/bundles/ext/*.jar
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/missing-repositories.properties b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/missing-repositories.properties
new file mode 100644
index 00000000..15803a71
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/missing-repositories.properties
@@ -0,0 +1 @@
+chain=bundles-ext,bundles-usr,libraries-ext,libraries-usr,managed-repo,watched-repo,remote-repo
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/repository.properties b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/repository.properties
new file mode 100644
index 00000000..92dbf4b5
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-configuration/repository.properties
@@ -0,0 +1,12 @@
+bundles-ext.type=external
+bundles-ext.searchPattern=repository/bundles/ext/*.jar
+
+watched-repo.type=watched
+watched-repo.watchDirectory=repository/watched
+watched-repo.watchInterval=5
+
+remote-repo.type=remote
+remote-repo.uri=http://localhost:8080/org.eclipse.virgo.repository/foo
+remote-repo.indexRefreshInterval=5
+
+chain=bundles-ext,watched-repo,remote-repo
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/a.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/a.jar
new file mode 100644
index 00000000..f647f271
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/a.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/b.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/b.jar
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/b.jar
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/c.jar b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/c.jar
new file mode 100644
index 00000000..a20a1aa0
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/corrupt-jar-test/c.jar
Binary files differ
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/a/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/a/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..421e9b5d
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/a/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: a
+Export-Package: com.foo.a
+Bundle-ManifestVersion: 2
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/b/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/b/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..d6227b60
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/b/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: b
+Export-Package: com.foo.b;@$%,,
+Bundle-ManifestVersion: 2
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/c/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/c/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..f93fa1fb
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/repository-populator-tests/malformed-manifest-test/c/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Bundle-SymbolicName: c
+Export-Package: com.foo.c
+Bundle-ManifestVersion: 2
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/scoping/complexService.xml b/org.eclipse.virgo.kernel.deployer/src/test/resources/scoping/complexService.xml
new file mode 100644
index 00000000..9afe0b45
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/scoping/complexService.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+ <osgi:service ref="service">
+ <osgi:interfaces>
+ <value>java.io.Serializable</value>
+ <value>java.lang.Appendable</value>
+ </osgi:interfaces>
+ <osgi:service-properties>
+ <entry key="foo" value="bar"/>
+ <entry key="boo" value="baz"/>
+ </osgi:service-properties>
+ </osgi:service>
+ <bean id="service" class="java.lang.StringBuffer" />
+</beans>
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/scoping/simpleService.xml b/org.eclipse.virgo.kernel.deployer/src/test/resources/scoping/simpleService.xml
new file mode 100644
index 00000000..74aa011a
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/scoping/simpleService.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:osgi="http://www.springframework.org/schema/osgi"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <osgi:service ref="service" interface="java.io.Serializable" />
+
+ <bean id="service" class="java.lang.String"/>
+
+</beans>
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/test/dummy.txt b/org.eclipse.virgo.kernel.deployer/src/test/resources/test/dummy.txt
new file mode 100644
index 00000000..9f26b637
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/test/dummy.txt
@@ -0,0 +1 @@
+Foo \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/resources/unit.test.subsystem/subsystem.xml b/org.eclipse.virgo.kernel.deployer/src/test/resources/unit.test.subsystem/subsystem.xml
new file mode 100644
index 00000000..55ccdf42
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/resources/unit.test.subsystem/subsystem.xml
@@ -0,0 +1,4 @@
+<subsystem name="unit.test.subsystem" description="Unit test subsystem descriptor">
+ <bundle symbolic-name="bundle1"/>
+ <bundle symbolic-name="bundle2"/>
+</subsystem>

Back to the top