Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-05-18 12:56:31 -0400
committerChristopher Frost2011-05-18 12:56:31 -0400
commit83848c5cbcaadc649158c4be03b04b4b138a9e06 (patch)
tree994856f66957e135012eb1f90c7123eb5dc4eed0 /org.eclipse.virgo.kernel.model
parent8edc8df99724531e5a0168a7f29b8cbe4bc84a4d (diff)
downloadorg.eclipse.virgo.kernel-83848c5cbcaadc649158c4be03b04b4b138a9e06.tar.gz
org.eclipse.virgo.kernel-83848c5cbcaadc649158c4be03b04b4b138a9e06.tar.xz
org.eclipse.virgo.kernel-83848c5cbcaadc649158c4be03b04b4b138a9e06.zip
Moving logic to decorate mBeans with Spring powered property from apps to Kernel
Diffstat (limited to 'org.eclipse.virgo.kernel.model')
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/SpringContextAccessor.java34
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/StandardSpringContextAccessor.java54
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java8
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java10
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/NativeBundleArtifact.java8
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java12
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListener.java16
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializer.java19
-rw-r--r--org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml4
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubSpringContextAccessor.java30
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java18
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java18
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/NativeBundleArtifactTests.java (renamed from org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifactTests.java)23
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java39
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerTests.java33
15 files changed, 276 insertions, 50 deletions
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/SpringContextAccessor.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/SpringContextAccessor.java
new file mode 100644
index 00000000..006ec274
--- /dev/null
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/SpringContextAccessor.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.model.internal;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * SpringContextAccessor
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * TODO Document concurrent semantics of SpringContextAccessor
+ */
+public interface SpringContextAccessor {
+
+ /**
+ * Inspects the service registry to find out if the {@link Bundle} registers
+ * a service for a Spring ApplicationContext, must be able to handle multiple
+ * instances of the Spring framework running in the OSGi framework.
+ *
+ * @param bundle to inspect
+ * @return true if Spring found
+ */
+ public boolean isSpringPowered(Bundle bundle);
+
+} \ No newline at end of file
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/StandardSpringContextAccessor.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/StandardSpringContextAccessor.java
new file mode 100644
index 00000000..380a2f9d
--- /dev/null
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/StandardSpringContextAccessor.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * This file is part of the Eclipse Virgo project.
+ *
+ * Copyright (c) 2011 copyright_holder
+ * 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:
+ * cgfrost - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.model.internal;
+
+import org.eclipse.virgo.kernel.serviceability.Assert;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * StandardSpringContextAccessor avoids issues of multiple Spring frameworks
+ * being present by not using any spring types.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * Thread-safe
+ */
+public class StandardSpringContextAccessor implements SpringContextAccessor {
+
+ private static final String APPLICATION_CONTEXT_CLASS_NAME = "org.springframework.context.ApplicationContext";
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isSpringPowered(Bundle bundle){
+ BundleContext bundleContext = bundle.getBundleContext();
+ if (bundleContext != null) {
+ String symbolicName = bundle.getSymbolicName();
+ try {
+ ServiceReference<?>[] refs = bundleContext.getAllServiceReferences(APPLICATION_CONTEXT_CLASS_NAME, "(Bundle-SymbolicName=" + symbolicName + ")");
+ if (refs.length > 0) {
+ return true;
+ }
+ } catch (InvalidSyntaxException e) {
+ Assert.isFalse(true, "Unexpected exception %s", e.getMessage());
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java
index 8e3d1b8e..881e9046 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListener.java
@@ -16,6 +16,7 @@ import org.eclipse.equinox.region.RegionDigraph;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.ArtifactState;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
+import org.eclipse.virgo.kernel.model.internal.SpringContextAccessor;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.Bundle;
@@ -49,11 +50,14 @@ final class ModelBundleListener implements SynchronousBundleListener {
private final RegionDigraph regionDigraph;
- public ModelBundleListener(@NonNull BundleContext bundleContext, @NonNull RuntimeArtifactRepository artifactRepository, @NonNull PackageAdminUtil packageAdminUtil, @NonNull RegionDigraph regionDigraph) {
+ private final SpringContextAccessor springContextAccessor;
+
+ public ModelBundleListener(@NonNull BundleContext bundleContext, @NonNull RuntimeArtifactRepository artifactRepository, @NonNull PackageAdminUtil packageAdminUtil, @NonNull RegionDigraph regionDigraph, @NonNull SpringContextAccessor springContextAccessor) {
this.bundleContext = bundleContext;
this.artifactRepository = artifactRepository;
this.packageAdminUtil = packageAdminUtil;
this.regionDigraph = regionDigraph;
+ this.springContextAccessor = springContextAccessor;
}
/**
@@ -71,7 +75,7 @@ final class ModelBundleListener implements SynchronousBundleListener {
Bundle bundle = event.getBundle();
Region region = this.regionDigraph.getRegion(bundle);
logger.info("Processing installed event for bundle '{}:{}' in region '{}'", new Object[] {bundle.getSymbolicName(), bundle.getVersion().toString(), region.getName()});
- this.artifactRepository.add(new NativeBundleArtifact(bundleContext, packageAdminUtil, bundle, region));
+ this.artifactRepository.add(new NativeBundleArtifact(this.bundleContext, this.packageAdminUtil, bundle, region, this.springContextAccessor));
}
private void processUninstalled(BundleEvent event) {
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java
index 012525a5..7965c526 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializer.java
@@ -16,6 +16,7 @@ import javax.annotation.PreDestroy;
import org.eclipse.equinox.region.RegionDigraph;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
+import org.eclipse.virgo.kernel.model.internal.SpringContextAccessor;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.Bundle;
@@ -49,12 +50,15 @@ public final class ModelBundleListenerInitializer {
private final RegionDigraph regionDigraph;
- public ModelBundleListenerInitializer(@NonNull RuntimeArtifactRepository artifactRepository, @NonNull PackageAdminUtil packageAdminUtil, @NonNull BundleContext kernelBundleContext, @NonNull RegionDigraph regionDigraph) {
+ private final SpringContextAccessor springContextAccessor;
+
+ public ModelBundleListenerInitializer(@NonNull RuntimeArtifactRepository artifactRepository, @NonNull PackageAdminUtil packageAdminUtil, @NonNull BundleContext kernelBundleContext, @NonNull RegionDigraph regionDigraph, @NonNull SpringContextAccessor springContextAccessor) {
this.artifactRepository = artifactRepository;
this.packageAdminUtil = packageAdminUtil;
this.kernelBundleContext = kernelBundleContext;
- this.bundleListener = new ModelBundleListener(kernelBundleContext, artifactRepository, packageAdminUtil, regionDigraph);
+ this.bundleListener = new ModelBundleListener(kernelBundleContext, artifactRepository, packageAdminUtil, regionDigraph, springContextAccessor);
this.regionDigraph = regionDigraph;
+ this.springContextAccessor = springContextAccessor;
}
/**
@@ -69,7 +73,7 @@ public final class ModelBundleListenerInitializer {
// Find bundles that the listener has almost certainly missed.
for (Bundle bundle : systemBundleContext.getBundles()) {
try {
- this.artifactRepository.add(new NativeBundleArtifact(this.kernelBundleContext, this.packageAdminUtil, bundle, this.regionDigraph.getRegion(bundle)));
+ this.artifactRepository.add(new NativeBundleArtifact(this.kernelBundleContext, this.packageAdminUtil, bundle, this.regionDigraph.getRegion(bundle), this.springContextAccessor));
} catch (Exception e) {
this.logger.error(String.format("Exception adding bundle '%s:%s' to the repository", bundle.getSymbolicName(),
bundle.getVersion().toString()), e);
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/NativeBundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/NativeBundleArtifact.java
index 30f64f3f..7f18e1fa 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/NativeBundleArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/bundle/NativeBundleArtifact.java
@@ -19,6 +19,7 @@ import org.eclipse.equinox.region.Region;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.ArtifactState;
import org.eclipse.virgo.kernel.model.internal.AbstractArtifact;
+import org.eclipse.virgo.kernel.model.internal.SpringContextAccessor;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.Bundle;
@@ -46,11 +47,14 @@ final class NativeBundleArtifact extends AbstractArtifact {
private final PackageAdminUtil packageAdminUtil;
private final Bundle bundle;
+
+ private final SpringContextAccessor springContextAccessor;
- public NativeBundleArtifact(@NonNull BundleContext bundleContext, @NonNull PackageAdminUtil packageAdminUtil, @NonNull Bundle bundle, @NonNull Region region) {
+ public NativeBundleArtifact(@NonNull BundleContext bundleContext, @NonNull PackageAdminUtil packageAdminUtil, @NonNull Bundle bundle, @NonNull Region region, @NonNull SpringContextAccessor springContextAccessor) {
super(bundleContext, TYPE, bundle.getSymbolicName(), bundle.getVersion(), region);
this.packageAdminUtil = packageAdminUtil;
this.bundle = bundle;
+ this.springContextAccessor = springContextAccessor;
}
/**
@@ -66,7 +70,7 @@ final class NativeBundleArtifact extends AbstractArtifact {
public Map<String, String> getProperties() {
Map<String, String> properties = new HashMap<String, String>();
properties.put("BundleId", String.valueOf(this.bundle.getBundleId()));
- properties.put("Location", this.bundle.getLocation());
+ properties.put("Spring", String.valueOf(this.springContextAccessor.isSpringPowered(bundle)));
return Collections.unmodifiableMap(properties);
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java
index 9cd55072..9baea5f1 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/DeployerBundleArtifact.java
@@ -19,16 +19,21 @@ import java.util.Map;
import org.eclipse.equinox.region.Region;
import org.eclipse.virgo.kernel.install.artifact.BundleInstallArtifact;
import org.eclipse.virgo.kernel.model.BundleArtifact;
+import org.eclipse.virgo.kernel.model.internal.SpringContextAccessor;
import org.eclipse.virgo.kernel.serviceability.NonNull;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
final class DeployerBundleArtifact extends DeployerArtifact implements BundleArtifact {
private final BundleInstallArtifact installArtifact;
+
+ private SpringContextAccessor springContextAccessor;
- public DeployerBundleArtifact(@NonNull BundleContext bundleContext, @NonNull BundleInstallArtifact installArtifact, @NonNull Region region) {
+ public DeployerBundleArtifact(@NonNull BundleContext bundleContext, @NonNull BundleInstallArtifact installArtifact, @NonNull Region region, @NonNull SpringContextAccessor springContextAccessor) {
super(bundleContext, installArtifact, region);
this.installArtifact = installArtifact;
+ this.springContextAccessor = springContextAccessor;
}
/**
@@ -52,8 +57,9 @@ final class DeployerBundleArtifact extends DeployerArtifact implements BundleArt
Map<String, String> parentProperties = super.getProperties();
Map<String, String> properties = new HashMap<String, String>();
properties.putAll(parentProperties);
- properties.put("BundleId", String.valueOf(this.installArtifact.getBundle().getBundleId()));
- properties.put("Location", this.installArtifact.getBundle().getLocation());
+ Bundle bundle = this.installArtifact.getBundle();
+ properties.put("BundleId", String.valueOf(bundle.getBundleId()));
+ properties.put("Spring", String.valueOf(this.springContextAccessor.isSpringPowered(bundle)));
return Collections.unmodifiableMap(properties);
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListener.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListener.java
index 10185966..930298c6 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListener.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListener.java
@@ -22,6 +22,7 @@ import org.eclipse.virgo.kernel.install.artifact.PlanInstallArtifact;
import org.eclipse.virgo.kernel.model.Artifact;
import org.eclipse.virgo.kernel.model.BundleArtifact;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
+import org.eclipse.virgo.kernel.model.internal.SpringContextAccessor;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
@@ -57,11 +58,14 @@ class ModelInstallArtifactLifecycleListener extends InstallArtifactLifecycleList
private final RegionDigraph regionDigraph;
private final Region globalRegion;
+
+ private final SpringContextAccessor springContextAccessor;
- public ModelInstallArtifactLifecycleListener(@NonNull BundleContext bundleContext, @NonNull RuntimeArtifactRepository artifactRepository, @NonNull RegionDigraph regionDigraph, @NonNull Region globalRegion) {
+ public ModelInstallArtifactLifecycleListener(@NonNull BundleContext bundleContext, @NonNull RuntimeArtifactRepository artifactRepository, @NonNull RegionDigraph regionDigraph, @NonNull Region globalRegion, @NonNull SpringContextAccessor springContextAccessor) {
this.bundleContext = bundleContext;
this.artifactRepository = artifactRepository;
this.regionDigraph = regionDigraph;
+ this.springContextAccessor = springContextAccessor;
this.globalRegion = globalRegion;
}
@@ -85,10 +89,10 @@ class ModelInstallArtifactLifecycleListener extends InstallArtifactLifecycleList
}
private void addOrReplaceBundle(BundleInstallArtifact bundleInstallArtifact) {
- Artifact existingBundleArtifact = this.artifactRepository.getArtifact(bundleInstallArtifact.getType(), bundleInstallArtifact.getName(), bundleInstallArtifact.getVersion(), this.regionDigraph.getRegion(USER_REGION_NAME));
+ Artifact existingBundleArtifact = this.artifactRepository.getArtifact(bundleInstallArtifact.getType(), bundleInstallArtifact.getName(), bundleInstallArtifact.getVersion(), getRegion(USER_REGION_NAME));
if (!(existingBundleArtifact instanceof DeployerBundleArtifact)) {
remove(bundleInstallArtifact);
- this.artifactRepository.add(new DeployerBundleArtifact(this.bundleContext, bundleInstallArtifact, this.regionDigraph.getRegion(USER_REGION_NAME)));
+ this.artifactRepository.add(new DeployerBundleArtifact(this.bundleContext, bundleInstallArtifact, getRegion(USER_REGION_NAME), this.springContextAccessor));
}
}
@@ -121,10 +125,14 @@ class ModelInstallArtifactLifecycleListener extends InstallArtifactLifecycleList
private void remove(InstallArtifact installArtifact) {
if(installArtifact instanceof BundleInstallArtifact){
- this.artifactRepository.remove(installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion(), this.regionDigraph.getRegion(USER_REGION_NAME));
+ this.artifactRepository.remove(installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion(), getRegion(USER_REGION_NAME));
} else {
this.artifactRepository.remove(installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion(), this.globalRegion);
}
}
+
+ private Region getRegion(String name){
+ return this.regionDigraph.getRegion(name);
+ }
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializer.java b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializer.java
index 644394c2..f9e22896 100644
--- a/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializer.java
+++ b/org.eclipse.virgo.kernel.model/src/main/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializer.java
@@ -22,6 +22,7 @@ import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
import org.eclipse.virgo.kernel.install.artifact.InstallArtifactLifecycleListener;
import org.eclipse.virgo.kernel.install.artifact.PlanInstallArtifact;
import org.eclipse.virgo.kernel.model.RuntimeArtifactRepository;
+import org.eclipse.virgo.kernel.model.internal.SpringContextAccessor;
import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.eclipse.virgo.util.osgi.ServiceRegistrationTracker;
import org.osgi.framework.BundleContext;
@@ -40,7 +41,7 @@ import org.slf4j.LoggerFactory;
* @see ModelInstallArtifactLifecycleListener
*/
public final class ModelInstallArtifactLifecycleListenerInitializer {
-
+
private static final String USER_REGION_NAME = "org.eclipse.virgo.region.user";
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -56,13 +57,16 @@ public final class ModelInstallArtifactLifecycleListenerInitializer {
private final RegionDigraph regionDigraph;
private final Region globalRegion;
+
+ private final SpringContextAccessor springContextAccessor;
- public ModelInstallArtifactLifecycleListenerInitializer(@NonNull RuntimeArtifactRepository artifactRepository, @NonNull BundleContext bundleContext, @NonNull RuntimeArtifactModel runtimeArtifactModel, @NonNull RegionDigraph regionDigraph, @NonNull Region globalRegion) {
+ public ModelInstallArtifactLifecycleListenerInitializer(@NonNull RuntimeArtifactRepository artifactRepository, @NonNull BundleContext bundleContext, @NonNull RuntimeArtifactModel runtimeArtifactModel, @NonNull RegionDigraph regionDigraph, @NonNull Region globalRegion, @NonNull SpringContextAccessor springContextAccessor) {
this.artifactRepository = artifactRepository;
this.bundleContext = bundleContext;
this.runtimeArtifactModel = runtimeArtifactModel;
this.regionDigraph = regionDigraph;
this.globalRegion = globalRegion;
+ this.springContextAccessor = springContextAccessor;
}
/**
@@ -71,7 +75,7 @@ public final class ModelInstallArtifactLifecycleListenerInitializer {
*/
@PostConstruct
public void initialize() {
- ModelInstallArtifactLifecycleListener listener = new ModelInstallArtifactLifecycleListener(this.bundleContext, this.artifactRepository, this.regionDigraph, this.globalRegion);
+ ModelInstallArtifactLifecycleListener listener = new ModelInstallArtifactLifecycleListener(this.bundleContext, this.artifactRepository, this.regionDigraph, this.globalRegion, this.springContextAccessor);
this.registrationTracker.track(this.bundleContext.registerService(InstallArtifactLifecycleListener.class.getCanonicalName(), listener, null));
for (DeploymentIdentity deploymentIdentity : this.runtimeArtifactModel.getDeploymentIdentities()) {
InstallArtifact installArtifact = this.runtimeArtifactModel.get(deploymentIdentity);
@@ -79,9 +83,9 @@ public final class ModelInstallArtifactLifecycleListenerInitializer {
if (installArtifact instanceof PlanInstallArtifact) {
this.artifactRepository.add(new DeployerCompositeArtifact(this.bundleContext, (PlanInstallArtifact) installArtifact, this.globalRegion));
} else if (installArtifact instanceof BundleInstallArtifact) {
- this.artifactRepository.remove(installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion(), this.regionDigraph.getRegion(USER_REGION_NAME));
+ this.artifactRepository.remove(installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion(), getRegion(USER_REGION_NAME));
BundleInstallArtifact bundleInstallArtifact = (BundleInstallArtifact) installArtifact;
- this.artifactRepository.add(new DeployerBundleArtifact(this.bundleContext, bundleInstallArtifact, this.regionDigraph.getRegion(USER_REGION_NAME)));
+ this.artifactRepository.add(new DeployerBundleArtifact(this.bundleContext, bundleInstallArtifact, getRegion(USER_REGION_NAME), this.springContextAccessor));
} else {
this.artifactRepository.remove(installArtifact.getType(), installArtifact.getName(), installArtifact.getVersion(), null);
this.artifactRepository.add(new DeployerArtifact(this.bundleContext, installArtifact, this.globalRegion));
@@ -99,4 +103,9 @@ public final class ModelInstallArtifactLifecycleListenerInitializer {
public void destroy() {
this.registrationTracker.unregisterAll();
}
+
+ private Region getRegion(String name){
+ return this.regionDigraph.getRegion(name);
+ }
+
}
diff --git a/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml b/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml
index fedb4a8f..2831ce8f 100644
--- a/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml
+++ b/org.eclipse.virgo.kernel.model/src/main/resources/META-INF/spring/module-context.xml
@@ -10,6 +10,7 @@
<constructor-arg ref="packageAdminUtil"/>
<constructor-arg ref="bundleContext"/>
<constructor-arg ref="regionDigraph"/>
+ <constructor-arg ref="springContextAccessor" />
</bean>
<bean class="org.eclipse.virgo.kernel.model.internal.configurationadmin.ModelConfigurationListenerInitializer">
@@ -25,6 +26,7 @@
<constructor-arg ref="runtimeArtifactModel"/>
<constructor-arg ref="regionDigraph"/>
<constructor-arg ref="globalRegion"/>
+ <constructor-arg ref="springContextAccessor" />
</bean>
<bean id="bundleDependencyDeterminer" class="org.eclipse.virgo.kernel.model.internal.bundle.BundleDependencyDeterminer">
@@ -47,6 +49,8 @@
destroy-method="destroy">
<constructor-arg ref="runtimeArtifactModelObjectNameCreator"/>
</bean>
+
+ <bean id="springContextAccessor" class="org.eclipse.virgo.kernel.model.internal.StandardSpringContextAccessor" />
<bean id="runtimeArtifactModelObjectNameCreator" class="org.eclipse.virgo.kernel.model.management.internal.DefaultRuntimeArtifactModelObjectNameCreator">
<constructor-arg value="#{kernelConfig.getProperty('domain')}"/>
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubSpringContextAccessor.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubSpringContextAccessor.java
new file mode 100644
index 00000000..a3b07ba3
--- /dev/null
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/StubSpringContextAccessor.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * 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.model;
+
+import org.eclipse.virgo.kernel.model.internal.SpringContextAccessor;
+import org.osgi.framework.Bundle;
+
+/**
+ * Stub impl
+ */
+public class StubSpringContextAccessor implements SpringContextAccessor {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isSpringPowered(Bundle bundle) {
+ return false;
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java
index 04f65cfa..368352a9 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerInitializerTests.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import org.eclipse.equinox.region.RegionDigraph;
import org.eclipse.virgo.kernel.model.StubArtifactRepository;
import org.eclipse.virgo.kernel.model.StubRegion;
+import org.eclipse.virgo.kernel.model.StubSpringContextAccessor;
import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
@@ -40,6 +41,8 @@ public class ModelBundleListenerInitializerTests {
private final PackageAdminUtil packageAdminUtil = createMock(PackageAdminUtil.class);
+ private final StubSpringContextAccessor springContextAccessor = new StubSpringContextAccessor();
+
private final StubBundleContext bundleContext;
private final StubBundleContext systemBundleContext;
@@ -58,26 +61,31 @@ public class ModelBundleListenerInitializerTests {
expect(regionDigraph.getRegion(bundle)).andReturn(region).anyTimes();
}
- private final ModelBundleListenerInitializer initializer = new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, bundleContext, regionDigraph);
+ private final ModelBundleListenerInitializer initializer = new ModelBundleListenerInitializer(this.artifactRepository, this.packageAdminUtil, this.bundleContext, this.regionDigraph, this.springContextAccessor);
@Test(expected = FatalAssertionException.class)
public void nullArtifactRepository() {
- new ModelBundleListenerInitializer(null, packageAdminUtil, bundleContext, regionDigraph);
+ new ModelBundleListenerInitializer(null, packageAdminUtil, bundleContext, regionDigraph, this.springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullPackageAdminUtil() {
- new ModelBundleListenerInitializer(artifactRepository, null, bundleContext, regionDigraph);
+ new ModelBundleListenerInitializer(artifactRepository, null, bundleContext, regionDigraph, this.springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullKernelBundleContext() {
- new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, null, regionDigraph);
+ new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, null, regionDigraph, this.springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullRegionDigraph() {
- new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, bundleContext, null);
+ new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, bundleContext, null, this.springContextAccessor);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullSpringContextAccessor() {
+ new ModelBundleListenerInitializer(artifactRepository, packageAdminUtil, bundleContext, regionDigraph, null);
}
@Test
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java
index 9b3a1761..c82edcef 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/ModelBundleListenerTests.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import org.eclipse.equinox.region.RegionDigraph;
import org.eclipse.virgo.kernel.model.StubArtifactRepository;
import org.eclipse.virgo.kernel.model.StubRegion;
+import org.eclipse.virgo.kernel.model.StubSpringContextAccessor;
import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
@@ -35,6 +36,8 @@ public class ModelBundleListenerTests {
private final StubArtifactRepository artifactRepository = new StubArtifactRepository();
private final PackageAdminUtil packageAdminUtil = createMock(PackageAdminUtil.class);
+
+ private final StubSpringContextAccessor springContextAccessor = new StubSpringContextAccessor();
private final StubBundleContext bundleContext;
@@ -49,26 +52,31 @@ public class ModelBundleListenerTests {
expect(regionDigraph.getRegion(isA(Bundle.class))).andReturn(region).anyTimes();
}
- private final ModelBundleListener listener = new ModelBundleListener(bundleContext, artifactRepository, packageAdminUtil, regionDigraph);
+ private final ModelBundleListener listener = new ModelBundleListener(this.bundleContext, this.artifactRepository, this.packageAdminUtil, this.regionDigraph, this.springContextAccessor);
@Test(expected = FatalAssertionException.class)
public void nullBundleContext() {
- new ModelBundleListener(null, artifactRepository, packageAdminUtil, regionDigraph);
+ new ModelBundleListener(null, artifactRepository, packageAdminUtil, regionDigraph, this.springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullArtifactRepository() {
- new ModelBundleListener(bundleContext, null, packageAdminUtil, regionDigraph);
+ new ModelBundleListener(bundleContext, null, packageAdminUtil, regionDigraph, this.springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullPackageAdminUtil() {
- new ModelBundleListener(bundleContext, artifactRepository, null, regionDigraph);
+ new ModelBundleListener(bundleContext, artifactRepository, null, regionDigraph, this.springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullRegionDigraph() {
- new ModelBundleListener(bundleContext, artifactRepository, packageAdminUtil, null);
+ new ModelBundleListener(bundleContext, artifactRepository, packageAdminUtil, null, this.springContextAccessor);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullSpringContextAccessor() {
+ new ModelBundleListener(bundleContext, artifactRepository, packageAdminUtil, regionDigraph, null);
}
@Test
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifactTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/NativeBundleArtifactTests.java
index 189570c4..27b0e489 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/BundleArtifactTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/bundle/NativeBundleArtifactTests.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import org.eclipse.equinox.region.Region;
import org.eclipse.virgo.kernel.model.ArtifactState;
+import org.eclipse.virgo.kernel.model.StubSpringContextAccessor;
import org.eclipse.virgo.kernel.model.internal.AbstractArtifact;
import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
import org.eclipse.virgo.kernel.osgi.framework.PackageAdminUtil;
@@ -31,7 +32,7 @@ import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
-public class BundleArtifactTests {
+public class NativeBundleArtifactTests {
private final PackageAdminUtil packageAdminUtil = createMock(PackageAdminUtil.class);
@@ -39,6 +40,8 @@ public class BundleArtifactTests {
private final StubBundleContext bundleContext;
+ private final StubSpringContextAccessor springContextAccessor = new StubSpringContextAccessor();
+
private final Region region = createMock(Region.class);
{
@@ -48,21 +51,31 @@ public class BundleArtifactTests {
expect(this.region.getName()).andReturn("test.region").anyTimes();
}
- private final AbstractArtifact artifact = new NativeBundleArtifact(bundleContext, packageAdminUtil, bundle, this.region);
+ private final AbstractArtifact artifact = new NativeBundleArtifact(this.bundleContext, this.packageAdminUtil, this.bundle, this.region, this.springContextAccessor);
@Test(expected = FatalAssertionException.class)
public void nullBundleContext() {
- new NativeBundleArtifact(null, packageAdminUtil, bundle, this.region);
+ new NativeBundleArtifact(null, packageAdminUtil, bundle, this.region, this.springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullPackageAdminUtil() {
- new NativeBundleArtifact(bundleContext, null, bundle, this.region);
+ new NativeBundleArtifact(bundleContext, null, bundle, this.region, this.springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullBundle() {
- new NativeBundleArtifact(bundleContext, packageAdminUtil, null, this.region);
+ new NativeBundleArtifact(bundleContext, packageAdminUtil, null, this.region, this.springContextAccessor);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullRegion() {
+ new NativeBundleArtifact(bundleContext, packageAdminUtil, bundle, null, this.springContextAccessor);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullSpringContextAccessor() {
+ new NativeBundleArtifact(bundleContext, packageAdminUtil, bundle, this.region, null);
}
@Test
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java
index 6d11a830..34a66c01 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java
@@ -15,6 +15,7 @@ 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;
@@ -25,12 +26,14 @@ import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
import org.eclipse.virgo.kernel.deployer.model.RuntimeArtifactModel;
import org.eclipse.virgo.kernel.model.StubArtifactRepository;
import org.eclipse.virgo.kernel.model.StubRegion;
+import org.eclipse.virgo.kernel.model.StubSpringContextAccessor;
import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
import org.eclipse.virgo.kernel.stubs.StubInstallArtifact;
import org.eclipse.virgo.kernel.stubs.StubPlanInstallArtifact;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
import org.eclipse.virgo.teststubs.osgi.support.TrueFilter;
+import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.Version;
@@ -43,6 +46,10 @@ public class ModelInstallArtifactLifecycleListenerInitializerTests {
private final RegionDigraph regionDigraph = createMock(RegionDigraph.class);
+ private final StubSpringContextAccessor springContextAccessor = new StubSpringContextAccessor();
+
+ private final StubRegion region = new StubRegion("test-region");
+
private final StubBundleContext bundleContext;
{
this.bundleContext = new StubBundleContext();
@@ -51,35 +58,49 @@ public class ModelInstallArtifactLifecycleListenerInitializerTests {
String filterString2 = String.format("(&(objectClass=%s)(artifactType=plan))", DependencyDeterminer.class.getCanonicalName());
this.bundleContext.addFilter(filterString2, new TrueFilter(filterString2));
}
-
- private final StubRegion region = new StubRegion("test-region");
- private final ModelInstallArtifactLifecycleListenerInitializer initializer = new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, bundleContext, runtimeArtifactModel, regionDigraph, region);
+ @Before
+ public void setUp(){
+ reset(this.regionDigraph);
+ expect(this.regionDigraph.getRegion("global")).andReturn(region).anyTimes();
+ replay(this.regionDigraph);
+ }
+
+ private final ModelInstallArtifactLifecycleListenerInitializer initializer = new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, bundleContext, runtimeArtifactModel, regionDigraph, region, springContextAccessor);
@Test(expected = FatalAssertionException.class)
public void nullArtifactRepository() {
- new ModelInstallArtifactLifecycleListenerInitializer(null, bundleContext, runtimeArtifactModel, regionDigraph, region);
+ new ModelInstallArtifactLifecycleListenerInitializer(null, bundleContext, runtimeArtifactModel, regionDigraph, region, springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullBundleContext() {
- new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, null, runtimeArtifactModel, regionDigraph, region);
+ new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, null, runtimeArtifactModel, regionDigraph, region, springContextAccessor);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullRuntimeArtifactModel() {
+ new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, bundleContext, null, regionDigraph, region, springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullRegionDigraph() {
- new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, bundleContext, runtimeArtifactModel, null, region);
+ new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, bundleContext, runtimeArtifactModel, null, region, springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullRegion() {
- new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, bundleContext, runtimeArtifactModel, regionDigraph, null);
+ new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, bundleContext, runtimeArtifactModel, regionDigraph, null, springContextAccessor);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullSpringContextAccessor() {
+ new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, bundleContext, runtimeArtifactModel, regionDigraph, region, null);
}
@Test
public void initialize() throws IOException, InvalidSyntaxException {
- expect(this.runtimeArtifactModel.getDeploymentIdentities()).andReturn(
- new DeploymentIdentity[] { new StubDeploymentIdentity("plan"), new StubDeploymentIdentity("bundle") });
+ expect(this.runtimeArtifactModel.getDeploymentIdentities()).andReturn(new DeploymentIdentity[] { new StubDeploymentIdentity("plan"), new StubDeploymentIdentity("bundle") });
expect(this.runtimeArtifactModel.get(isA(DeploymentIdentity.class))).andReturn(new StubInstallArtifact("bundle"));
expect(this.runtimeArtifactModel.get(isA(DeploymentIdentity.class))).andReturn(new StubPlanInstallArtifact());
replay(this.runtimeArtifactModel);
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerTests.java
index 8f016b8d..c2952051 100644
--- a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerTests.java
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerTests.java
@@ -12,6 +12,9 @@
package org.eclipse.virgo.kernel.model.internal.deployer;
import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.reset;
import static org.junit.Assert.assertEquals;
import org.eclipse.equinox.region.RegionDigraph;
@@ -19,12 +22,14 @@ import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
import org.eclipse.virgo.kernel.model.StubArtifactRepository;
import org.eclipse.virgo.kernel.model.StubRegion;
+import org.eclipse.virgo.kernel.model.StubSpringContextAccessor;
import org.eclipse.virgo.kernel.model.internal.DependencyDeterminer;
import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
import org.eclipse.virgo.kernel.stubs.StubInstallArtifact;
import org.eclipse.virgo.kernel.stubs.StubPlanInstallArtifact;
import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
import org.eclipse.virgo.teststubs.osgi.support.TrueFilter;
+import org.junit.Before;
import org.junit.Test;
public class ModelInstallArtifactLifecycleListenerTests {
@@ -33,6 +38,10 @@ public class ModelInstallArtifactLifecycleListenerTests {
private final RegionDigraph regionDigraph = createMock(RegionDigraph.class);
+ private final StubSpringContextAccessor springContextAccessor = new StubSpringContextAccessor();
+
+ private final StubRegion region = new StubRegion("test-region");
+
private final StubBundleContext bundleContext;
{
this.bundleContext = new StubBundleContext();
@@ -41,29 +50,39 @@ public class ModelInstallArtifactLifecycleListenerTests {
String filterString2 = String.format("(&(objectClass=%s)(artifactType=plan))", DependencyDeterminer.class.getCanonicalName());
this.bundleContext.addFilter(filterString2, new TrueFilter(filterString2));
}
-
- private final StubRegion region = new StubRegion("test-region");
- private final ModelInstallArtifactLifecycleListener listener = new ModelInstallArtifactLifecycleListener(bundleContext, artifactRepository, regionDigraph, region);
+ private final ModelInstallArtifactLifecycleListener listener = new ModelInstallArtifactLifecycleListener(bundleContext, artifactRepository, regionDigraph, region, springContextAccessor);
+ @Before
+ public void setUp(){
+ reset(this.regionDigraph);
+ expect(this.regionDigraph.getRegion("global")).andReturn(region).anyTimes();
+ replay(this.regionDigraph);
+ }
+
@Test(expected = FatalAssertionException.class)
public void nullBundleContext() {
- new ModelInstallArtifactLifecycleListener(null, artifactRepository, regionDigraph, region);
+ new ModelInstallArtifactLifecycleListener(null, artifactRepository, regionDigraph, region, springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullArtifactRepository() {
- new ModelInstallArtifactLifecycleListener(bundleContext, null, regionDigraph, region);
+ new ModelInstallArtifactLifecycleListener(bundleContext, null, regionDigraph, region, springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullRegionDigraph() {
- new ModelInstallArtifactLifecycleListener(bundleContext, artifactRepository, null, region);
+ new ModelInstallArtifactLifecycleListener(bundleContext, artifactRepository, null, region, springContextAccessor);
}
@Test(expected = FatalAssertionException.class)
public void nullRegion() {
- new ModelInstallArtifactLifecycleListener(bundleContext, artifactRepository, regionDigraph, null);
+ new ModelInstallArtifactLifecycleListener(bundleContext, artifactRepository, regionDigraph, null, springContextAccessor);
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void nullSpringContextAccessor() {
+ new ModelInstallArtifactLifecycleListener(bundleContext, artifactRepository, regionDigraph, region, null);
}
@Test

Back to the top