Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-05-19 06:05:31 -0400
committerChristopher Frost2011-05-19 06:05:31 -0400
commiteacd0b68f14a6073cc8a06d3e9372ebdd051a10e (patch)
treef7cf17bdea0cb301bcd5afcbe0ba16ba4089c90e /org.eclipse.virgo.kernel.model
parente44fa636541db42c095b9fbbbae18d0e68a8a841 (diff)
downloadorg.eclipse.virgo.kernel-eacd0b68f14a6073cc8a06d3e9372ebdd051a10e.tar.gz
org.eclipse.virgo.kernel-eacd0b68f14a6073cc8a06d3e9372ebdd051a10e.tar.xz
org.eclipse.virgo.kernel-eacd0b68f14a6073cc8a06d3e9372ebdd051a10e.zip
Adding tests for some new code and an extra nonNull annotation to the aspect
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/StandardSpringContextAccessor.java3
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/StandardSpringContextAccessorTests.java99
-rw-r--r--org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/deployer/ModelInstallArtifactLifecycleListenerInitializerTests.java4
3 files changed, 103 insertions, 3 deletions
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
index 26794367..6fe08397 100644
--- 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
@@ -14,6 +14,7 @@
package org.eclipse.virgo.kernel.model.internal;
import org.eclipse.virgo.kernel.serviceability.Assert;
+import org.eclipse.virgo.kernel.serviceability.NonNull;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
@@ -35,7 +36,7 @@ public class StandardSpringContextAccessor implements SpringContextAccessor {
* {@inheritDoc}
*/
@Override
- public boolean isSpringPowered(Bundle bundle){
+ public boolean isSpringPowered(@NonNull Bundle bundle){
BundleContext bundleContext = bundle.getBundleContext();
if (bundleContext != null) {
String symbolicName = bundle.getSymbolicName();
diff --git a/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/StandardSpringContextAccessorTests.java b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/StandardSpringContextAccessorTests.java
new file mode 100644
index 00000000..25eaff65
--- /dev/null
+++ b/org.eclipse.virgo.kernel.model/src/test/java/org/eclipse/virgo/kernel/model/internal/StandardSpringContextAccessorTests.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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 static org.easymock.EasyMock.createNiceMock;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+import org.eclipse.virgo.teststubs.osgi.framework.StubFilter;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
+import org.springframework.context.ApplicationContext;
+
+public class StandardSpringContextAccessorTests {
+
+ private static final String FILTER = "(Bundle-SymbolicName=test-bundle)";
+
+ private final StandardSpringContextAccessor standardSpringContextAccessor = new StandardSpringContextAccessor();
+
+ private StubBundle bundle;
+
+ private StubBundleContext bundleContext;
+
+ @Before
+ public void setUp(){
+ this.bundle = new StubBundle("test-bundle", Version.emptyVersion);
+ this.bundleContext = new StubBundleContext(bundle);
+ this.bundle.setBundleContext(this.bundleContext);
+ this.bundleContext.addFilter(FILTER, new TestFilter());
+ }
+
+ @Test(expected = FatalAssertionException.class)
+ public void testNullBundle(){
+ this.standardSpringContextAccessor.isSpringPowered(null);
+ }
+
+ @Test
+ public void testSpringPowered(){
+ Dictionary<String, String> properties = new Hashtable<String, String>();
+ properties.put("Bundle-SymbolicName", "test-bundle");
+ this.bundleContext.registerService(ApplicationContext.class, createNiceMock(ApplicationContext.class), properties);
+ assertTrue(this.standardSpringContextAccessor.isSpringPowered(this.bundle));
+ }
+
+ @Test
+ public void testNotSpringPowered(){
+ assertFalse(this.standardSpringContextAccessor.isSpringPowered(this.bundle));
+ }
+
+ private class TestFilter implements StubFilter {
+
+ @Override
+ public boolean match(ServiceReference<?> reference) {
+ return true;
+ }
+
+ @Override
+ public boolean match(Dictionary<String, ?> dictionary) {
+ return true;
+ }
+
+ @Override
+ public boolean matchCase(Dictionary<String, ?> dictionary) {
+ return true;
+ }
+
+ @Override
+ public boolean matches(Map<String, ?> map) {
+ return true;
+ }
+
+ @Override
+ public String getFilterString() {
+ return FILTER;
+ }
+
+ }
+
+}
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 34a66c01..34ef4cfa 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
@@ -59,6 +59,8 @@ public class ModelInstallArtifactLifecycleListenerInitializerTests {
this.bundleContext.addFilter(filterString2, new TrueFilter(filterString2));
}
+ private final ModelInstallArtifactLifecycleListenerInitializer initializer = new ModelInstallArtifactLifecycleListenerInitializer(artifactRepository, bundleContext, runtimeArtifactModel, regionDigraph, region, springContextAccessor);
+
@Before
public void setUp(){
reset(this.regionDigraph);
@@ -66,8 +68,6 @@ public class ModelInstallArtifactLifecycleListenerInitializerTests {
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, springContextAccessor);

Back to the top