Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.virgo.kernel.osgi/src/test')
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/.gitignore0
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/common/VersionTests.java66
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/PackageImportWildcardExpanderTests.java76
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/RegionManagerTests.java86
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/.gitignore0
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTBUNDLE.MF3
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTLIBRARY.MF1
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTPACKAGE.MF1
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTSYSTEMPACKAGES.MF4
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTSYSTEMPACKAGESJAVA6.MF1
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/REQUIREBUNDLE.MF2
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/SATISFIABLEANDUNSATISFIABLE.MF2
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTBUNDLE.MF1
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTLIBRARY.MF1
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTPACKAGE.MF1
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEREQUIREBUNDLE.MF1
-rw-r--r--org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/org.springframework_spring_2.5.3.libd5
17 files changed, 251 insertions, 0 deletions
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/.gitignore b/org.eclipse.virgo.kernel.osgi/src/test/java/.gitignore
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/.gitignore
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/common/VersionTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/common/VersionTests.java
new file mode 100644
index 00000000..d496ff89
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/common/VersionTests.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.osgi.common;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.virgo.kernel.osgi.common.Version;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class VersionTests {
+
+ @Test public void normal() {
+ Version v1 = new Version("1");
+ Version v10 = new Version("1.0");
+ Assert.assertEquals(v1, v10);
+ Version v101 = new Version("1.0.1");
+ Assert.assertEquals(0, v1.compareTo(v10));
+ Assert.assertEquals(-1, v1.compareTo(v101));
+ Assert.assertEquals(1, v101.compareTo(v10));
+ }
+
+ @Test public void edgeCases() {
+
+ Assert.assertEquals(0, (new Version("0")).compareTo(new Version("")));
+ Assert.assertEquals(0, (new Version("0")).compareTo(new Version((String) null)));
+
+ try {
+ @SuppressWarnings("unused") Version v2 = new Version(".");
+ Assert.assertTrue(false);
+ } catch (NumberFormatException e) {
+ }
+ try {
+ @SuppressWarnings("unused") Version v3 = new Version("0-0");
+ Assert.assertTrue(false);
+ } catch (NumberFormatException e) {
+ }
+
+ try {
+ @SuppressWarnings("unused") Version v4 = new Version("1.-3.5");
+ Assert.assertTrue(false);
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ @Test public void listConstructor() {
+ Version v102 = new Version("1.0.2");
+ List<Integer> comps = new ArrayList<Integer>();
+ comps.add(1);
+ comps.add(0);
+ comps.add(2);
+ Version v102a = new Version(comps);
+ Assert.assertEquals(0, v102.compareTo(v102a));
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/PackageImportWildcardExpanderTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/PackageImportWildcardExpanderTests.java
new file mode 100644
index 00000000..9e3105b3
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/PackageImportWildcardExpanderTests.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * 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.osgi.region;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+import org.eclipse.virgo.kernel.osgi.region.PackageImportWildcardExpander;
+import org.eclipse.virgo.medic.eventlog.EventLogger;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+
+/**
+ */
+public class PackageImportWildcardExpanderTests {
+
+ private StubBundleContext stubBundleContext;
+
+ private EventLogger mockEventLogger;
+
+ private PackageAdmin mockPackageAdmin;
+
+ private ExportedPackage[] exportedPackages;
+
+ @Before
+ public void setUp() throws Exception {
+ this.stubBundleContext = new StubBundleContext();
+
+ this.mockEventLogger = createMock(EventLogger.class);
+ replay(this.mockEventLogger);
+ this.stubBundleContext.registerService(EventLogger.class.getName(), this.mockEventLogger, null);
+
+ this.mockPackageAdmin = createMock(PackageAdmin.class);
+ this.exportedPackages = new ExportedPackage[] { createdMockExportedPackage("q"), createdMockExportedPackage("r.a"),
+ createdMockExportedPackage("r.b.c") };
+ expect(this.mockPackageAdmin.getExportedPackages((Bundle) null)).andReturn(this.exportedPackages);
+ replay(this.mockPackageAdmin);
+ this.stubBundleContext.registerService(PackageAdmin.class.getName(), this.mockPackageAdmin, null);
+ }
+
+ private ExportedPackage createdMockExportedPackage(String packageName) {
+ ExportedPackage pkg = createMock(ExportedPackage.class);
+ expect(pkg.getName()).andReturn(packageName);
+ replay(pkg);
+ return pkg;
+ }
+
+ @Test
+ public void testNoWildcards() {
+ String expansion = PackageImportWildcardExpander.expandPackageImportsWildcards("p,r", this.stubBundleContext);
+ assertEquals("Incorrect expansion", "p,r", expansion);
+ }
+
+ @Test
+ public void testWildcards() {
+ String expansion = PackageImportWildcardExpander.expandPackageImportsWildcards("r.*", this.stubBundleContext);
+ assertEquals("Incorrect expansion", "r.a,r.b.c", expansion);
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/RegionManagerTests.java b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/RegionManagerTests.java
new file mode 100644
index 00000000..c6ec9bde
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/java/org/eclipse/virgo/kernel/osgi/region/RegionManagerTests.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * 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.osgi.region;
+
+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.verify;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.launch.Framework;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.framework.CompositeBundle;
+import org.osgi.service.framework.CompositeBundleFactory;
+import org.osgi.service.framework.SurrogateBundle;
+
+import org.eclipse.virgo.kernel.osgi.region.RegionManager;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+import org.eclipse.virgo.teststubs.osgi.framework.StubServiceRegistration;
+
+/**
+ */
+@SuppressWarnings("deprecation")
+public class RegionManagerTests {
+
+ @Test
+ public void testStartAndStop() throws Exception {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundleContext surrogateBundleContext = new StubBundleContext();
+
+ Framework user = createMock(Framework.class);
+ SurrogateBundle surrogate = createMock(SurrogateBundle.class);
+ ServiceFactory serviceFactory = createMock(ServiceFactory.class);
+
+ CompositeBundleFactory factory = createMock(CompositeBundleFactory.class);
+ CompositeBundle bundle = createMock(CompositeBundle.class);
+
+ expect(factory.installCompositeBundle(isA(Map.class), isA(String.class), isA(Map.class))).andReturn(bundle);
+ expect(bundle.getCompositeFramework()).andReturn(user);
+ bundle.start();
+ expect(bundle.getSurrogateBundle()).andReturn(surrogate);
+
+ expect(surrogate.getBundleContext()).andReturn(surrogateBundleContext);
+
+ EventAdmin eventAdmin = createMock(EventAdmin.class);
+ eventAdmin.sendEvent(isA(Event.class));
+
+ Dictionary<String, String> properties = new Hashtable<String, String>();
+ Configuration config = createMock(Configuration.class);
+ expect(config.getProperties()).andReturn(properties);
+
+ ConfigurationAdmin configAdmin = createMock(ConfigurationAdmin.class);
+ expect(configAdmin.getConfiguration(isA(String.class))).andReturn(config);
+
+ replay(factory, bundle, surrogate, eventAdmin, configAdmin, config);
+ RegionManager manager = new RegionManager(bundleContext, factory, eventAdmin, serviceFactory, configAdmin);
+ manager.start();
+
+ List<StubServiceRegistration> serviceRegistrations = bundleContext.getServiceRegistrations();
+ assertEquals("Regions not registered", 2, serviceRegistrations.size());
+
+ manager.stop();
+ verify(factory, bundle, surrogate, eventAdmin, configAdmin, config);
+
+ }
+}
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/.gitignore b/org.eclipse.virgo.kernel.osgi/src/test/resources/.gitignore
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/.gitignore
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTBUNDLE.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTBUNDLE.MF
new file mode 100644
index 00000000..0d4f08c4
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTBUNDLE.MF
@@ -0,0 +1,3 @@
+Import-Bundle: org.springframework.core;version="2.5.3",
+ org.springframework.beans;version="2.5.3",
+ org.springframework.context;version="2.5.3"
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTLIBRARY.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTLIBRARY.MF
new file mode 100644
index 00000000..b7541d03
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTLIBRARY.MF
@@ -0,0 +1 @@
+Import-Library: org.springframework_spring;version="2.5.3"
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTPACKAGE.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTPACKAGE.MF
new file mode 100644
index 00000000..0479f8c8
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTPACKAGE.MF
@@ -0,0 +1 @@
+Import-Package: org.springframework.beans;version=2.5.4,org.springframework.context;version=2.5.4,org.springframework.beans.factory;version=2.5.4
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTSYSTEMPACKAGES.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTSYSTEMPACKAGES.MF
new file mode 100644
index 00000000..3c12faf0
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTSYSTEMPACKAGES.MF
@@ -0,0 +1,4 @@
+Import-Package: javax.sql,
+ javax.transaction,
+ org.apache.commons.logging;version="[1.1.1,1.1.1]";resolution:=optional,
+ org.osgi.framework
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTSYSTEMPACKAGESJAVA6.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTSYSTEMPACKAGESJAVA6.MF
new file mode 100644
index 00000000..c25826a5
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/IMPORTSYSTEMPACKAGESJAVA6.MF
@@ -0,0 +1 @@
+Import-Package: javax.xml.soap
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/REQUIREBUNDLE.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/REQUIREBUNDLE.MF
new file mode 100644
index 00000000..b8048c05
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/REQUIREBUNDLE.MF
@@ -0,0 +1,2 @@
+Require-Bundle: org.springframework.core;version="[2.5.4, 2.6.0)"
+Import-Package: org.springframework.core;version="2.5.4"
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/SATISFIABLEANDUNSATISFIABLE.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/SATISFIABLEANDUNSATISFIABLE.MF
new file mode 100644
index 00000000..d804f6dc
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/SATISFIABLEANDUNSATISFIABLE.MF
@@ -0,0 +1,2 @@
+Import-Library: org.springframework_spring;version="[2.5.3,2.5.3]"
+Require-Bundle: com.foo
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTBUNDLE.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTBUNDLE.MF
new file mode 100644
index 00000000..4f6ab98e
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTBUNDLE.MF
@@ -0,0 +1 @@
+Import-Bundle: com.foo, com.bar
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTLIBRARY.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTLIBRARY.MF
new file mode 100644
index 00000000..645a4a84
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTLIBRARY.MF
@@ -0,0 +1 @@
+Import-Library: com.foo.bar
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTPACKAGE.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTPACKAGE.MF
new file mode 100644
index 00000000..4bd54a5c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEIMPORTPACKAGE.MF
@@ -0,0 +1 @@
+Import-Package: com.foo.bar
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEREQUIREBUNDLE.MF b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEREQUIREBUNDLE.MF
new file mode 100644
index 00000000..07dc36e5
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/UNSATISFIABLEREQUIREBUNDLE.MF
@@ -0,0 +1 @@
+Require-Bundle: com.foo.bar
diff --git a/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/org.springframework_spring_2.5.3.libd b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/org.springframework_spring_2.5.3.libd
new file mode 100644
index 00000000..dd7f6776
--- /dev/null
+++ b/org.eclipse.virgo.kernel.osgi/src/test/resources/com/springsource/kernel/osgi/provisioning/tools/org.springframework_spring_2.5.3.libd
@@ -0,0 +1,5 @@
+Library-SymbolicName: org.springframework_spring
+Library-Version: 2.5.3
+Import-Bundle: org.springframework.core;version="2.5.3",
+ org.springframework.beans;version="2.5.3",
+ org.springframework.context;version="2.5.3" \ No newline at end of file

Back to the top