Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.virgo.kernel.core/src/test')
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/StubConfiguration.java58
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/StubConfigurationAdmin.java51
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ConfigurationPublisherTests.java140
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/KernelConfigurationPropertiesSourceTests.java48
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/KernelConfigurationTests.java61
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/UserConfigurationPropertiesSourceTests.java45
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/commandline/CommandLinePropertiesSourceTests.java126
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ovf/OvfEnvironmentPropertiesReaderTests.java37
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ovf/OvfPropertiesSourceTests.java84
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/BundleStartTrackerTests.java292
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/CoreBundleActivatorTests.java79
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/ShutdownManagerTests.java103
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/StartupTrackerTests.java192
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/blueprint/ApplicationContextDependencyMonitorTests.java268
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/blueprint/TickerTests.java44
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/AssertTests.java175
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/dump/FFDCExceptionStateTests.java80
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/enforcement/NonNullAssertionEnforcerTests.java74
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/java/test/AssertingService.java48
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_badprops/noprops.properties2
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_noprops/noise.config11
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_noprops/noise2.config11
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_props1/dup.properties3
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_props2/dup.properties6
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/resources/UserConfigurationPropertiesSourceTests/one.properties1
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/resources/UserConfigurationPropertiesSourceTests/two.properties1
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/resources/ovf/environment.xml26
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/resources/ovf/invalid.xml25
-rw-r--r--org.eclipse.virgo.kernel.core/src/test/resources/ovf/valid.xml28
29 files changed, 2119 insertions, 0 deletions
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/StubConfiguration.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/StubConfiguration.java
new file mode 100644
index 00000000..2d09a67f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/StubConfiguration.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.service.cm.Configuration;
+
+public class StubConfiguration implements Configuration {
+
+ private Hashtable properties = new Hashtable();
+
+ public void delete() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getBundleLocation() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getFactoryPid() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getPid() {
+ throw new UnsupportedOperationException();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Dictionary getProperties() {
+ Hashtable propertiesCopy = new Hashtable();
+ propertiesCopy.putAll(this.properties);
+ return propertiesCopy;
+ }
+
+ public void setBundleLocation(String arg0) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void update() throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void update(Dictionary dictionary) throws IOException {
+ this.properties = (Hashtable)dictionary;
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/StubConfigurationAdmin.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/StubConfigurationAdmin.java
new file mode 100644
index 00000000..ece41256
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/StubConfigurationAdmin.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+
+public class StubConfigurationAdmin implements ConfigurationAdmin {
+
+ private final Map<String, Configuration> configurations = new HashMap<String, Configuration>();
+
+ public Configuration createFactoryConfiguration(String arg0) throws IOException {
+ return createFactoryConfiguration(arg0, null);
+ }
+
+ public Configuration createFactoryConfiguration(String arg0, String arg1) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ public Configuration getConfiguration(String arg0) throws IOException {
+ return getConfiguration(arg0, null);
+ }
+
+ public Configuration getConfiguration(String pid, String location) throws IOException {
+ Configuration configuration = this.configurations.get(pid);
+ if (configuration == null) {
+ configuration = new StubConfiguration();
+ configurations.put(pid, configuration);
+ }
+ return configuration;
+ }
+
+ public Configuration[] listConfigurations(String arg0) throws IOException, InvalidSyntaxException {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ConfigurationPublisherTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ConfigurationPublisherTests.java
new file mode 100644
index 00000000..5904d1a8
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ConfigurationPublisherTests.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * 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.config.internal;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+
+import org.eclipse.virgo.kernel.StubConfigurationAdmin;
+import org.eclipse.virgo.kernel.config.internal.ConfigurationPublisher;
+import org.eclipse.virgo.kernel.config.internal.PropertiesSource;
+import org.junit.Test;
+import org.osgi.service.cm.Configuration;
+
+
+/**
+ */
+public class ConfigurationPublisherTests {
+
+ @Test
+ public void testSingleSource() throws IOException {
+ StubPropertiesSource source = new StubPropertiesSource();
+
+ String pid = "single";
+
+ Properties p = new Properties();
+ p.setProperty("foo", "bar");
+
+ source.configurationProperties.put(pid, p);
+
+ StubConfigurationAdmin configAdmin = new StubConfigurationAdmin();
+
+ ConfigurationPublisher publisher = new ConfigurationPublisher(configAdmin, source);
+ publisher.publishConfigurations();
+
+ Configuration configuration = configAdmin.getConfiguration(pid);
+ assertConfigurationEquals(configuration, p);
+
+ }
+
+ @Test
+ public void testTwoSources() throws Exception {
+ StubPropertiesSource one = new StubPropertiesSource();
+ StubPropertiesSource two = new StubPropertiesSource();
+
+ // setup one
+ String pidOne = "one";
+
+ Properties propertiesOne = new Properties();
+ propertiesOne.setProperty("foo", "bar");
+
+ one.configurationProperties.put(pidOne, propertiesOne);
+
+ // setup two
+ String pidTwo = "two";
+
+ Properties propertiesTwo = new Properties();
+ propertiesTwo.setProperty("bar", "baz");
+
+ two.configurationProperties.put(pidTwo, propertiesTwo);
+
+ StubConfigurationAdmin configAdmin = new StubConfigurationAdmin();
+
+ ConfigurationPublisher publisher = new ConfigurationPublisher(configAdmin, one, two);
+ publisher.publishConfigurations();
+
+ Configuration configuration = configAdmin.getConfiguration(pidOne);
+ assertConfigurationEquals(configuration, propertiesOne);
+
+ configuration = configAdmin.getConfiguration(pidTwo);
+ assertConfigurationEquals(configuration, propertiesTwo);
+
+ }
+
+ @Test
+ public void testMultiSourceMerge() throws Exception {
+ StubPropertiesSource one = new StubPropertiesSource();
+ StubPropertiesSource two = new StubPropertiesSource();
+
+ // setup one
+ String pidOne = "one";
+
+ Properties propertiesOne = new Properties();
+ propertiesOne.setProperty("foo", "bar");
+ propertiesOne.setProperty("bar", "baz");
+
+ one.configurationProperties.put(pidOne, propertiesOne);
+
+ // setup two
+ String pidTwo = pidOne;
+
+ Properties propertiesTwo = new Properties();
+ propertiesTwo.setProperty("bar", "boo");
+ propertiesTwo.setProperty("boo", "bof");
+
+ two.configurationProperties.put(pidTwo, propertiesTwo);
+
+ StubConfigurationAdmin configAdmin = new StubConfigurationAdmin();
+
+ ConfigurationPublisher publisher = new ConfigurationPublisher(configAdmin, one, two);
+ publisher.publishConfigurations();
+
+ Configuration configuration = configAdmin.getConfiguration(pidOne);
+
+ assertEquals("bar", configuration.getProperties().get("foo"));
+ assertEquals("boo", configuration.getProperties().get("bar"));
+ assertEquals("bof", configuration.getProperties().get("boo"));
+ }
+
+ private void assertConfigurationEquals(Configuration configuration, Properties properties) {
+ for (String s : properties.stringPropertyNames()) {
+ assertEquals(properties.getProperty(s), configuration.getProperties().get(s));
+ }
+ }
+
+ private static class StubPropertiesSource implements PropertiesSource {
+
+ private final Map<String, Properties> configurationProperties = new TreeMap<String, Properties>();
+
+ /**
+ * {@inheritDoc}
+ */
+ public Map<String, Properties> getConfigurationProperties() {
+ return this.configurationProperties;
+ }
+
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/KernelConfigurationPropertiesSourceTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/KernelConfigurationPropertiesSourceTests.java
new file mode 100644
index 00000000..5b361493
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/KernelConfigurationPropertiesSourceTests.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.config.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.Test;
+
+import org.eclipse.virgo.kernel.config.internal.KernelConfiguration;
+import org.eclipse.virgo.kernel.config.internal.KernelConfigurationPropertiesSource;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+
+
+
+/**
+ */
+public class KernelConfigurationPropertiesSourceTests {
+
+ @Test
+ public void testGetProperties() {
+ StubBundleContext context = new StubBundleContext();
+ context.addProperty(KernelConfiguration.PROPERTY_KERNEL_HOME, "target/home");
+
+ KernelConfiguration configuration = new KernelConfiguration(context);
+
+ KernelConfigurationPropertiesSource source = new KernelConfigurationPropertiesSource(configuration);
+
+ Map<String, Properties> configurationProperties = source.getConfigurationProperties();
+ Properties properties = configurationProperties.get(KernelConfigurationPropertiesSource.KERNEL_CONFIGURATION_PID);
+ assertNotNull(properties);
+ assertEquals(configuration.getDomain(), properties.getProperty(KernelConfigurationPropertiesSource.PROPERTY_DOMAIN));
+ assertEquals(configuration.getHomeDirectory().getAbsolutePath(), properties.getProperty(KernelConfigurationPropertiesSource.PROPERTY_HOME_DIRECTORY));
+ assertEquals(configuration.getWorkDirectory().getAbsolutePath(), properties.getProperty(KernelConfigurationPropertiesSource.PROPERTY_WORK_DIRECTORY));
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/KernelConfigurationTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/KernelConfigurationTests.java
new file mode 100644
index 00000000..cbc667cf
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/KernelConfigurationTests.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * 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.config.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+
+import org.junit.Test;
+
+import org.eclipse.virgo.kernel.config.internal.KernelConfiguration;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+
+
+/**
+ */
+public class KernelConfigurationTests {
+
+ @Test
+ public void testCreateMinimalKernelConfiguration() {
+ StubBundleContext context = new StubBundleContext();
+ context.addProperty(KernelConfiguration.PROPERTY_KERNEL_HOME, "target");
+
+ KernelConfiguration configuration = new KernelConfiguration(context);
+ assertEquals(new File("target"), configuration.getHomeDirectory());
+ assertNotNull(configuration.getWorkDirectory());
+ assertNotNull(configuration.getConfigDirectories());
+ assertEquals(1, configuration.getConfigDirectories().length);
+ assertNotNull(configuration.getDomain());
+ }
+
+ @Test
+ public void testCustomConfiguration() {
+ StubBundleContext context = new StubBundleContext();
+ context.addProperty(KernelConfiguration.PROPERTY_KERNEL_HOME, "target");
+ context.addProperty(KernelConfiguration.PROPERTY_KERNEL_DOMAIN, "my.domain");
+ context.addProperty(KernelConfiguration.PROPERTY_KERNEL_CONFIG, "foo,bar");
+
+ KernelConfiguration configuration = new KernelConfiguration(context);
+ assertEquals(new File("target"), configuration.getHomeDirectory());
+ assertNotNull(configuration.getWorkDirectory());
+ assertNotNull(configuration.getConfigDirectories());
+ assertEquals(2, configuration.getConfigDirectories().length);
+ assertEquals("my.domain", configuration.getDomain());
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void testMissingKernelHomeProperty() {
+ new KernelConfiguration(new StubBundleContext());
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/UserConfigurationPropertiesSourceTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/UserConfigurationPropertiesSourceTests.java
new file mode 100644
index 00000000..cde779fd
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/UserConfigurationPropertiesSourceTests.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.config.internal;
+
+import java.io.File;
+import java.util.Map;
+import java.util.Properties;
+
+import org.eclipse.virgo.kernel.config.internal.UserConfigurationPropertiesSource;
+import org.junit.Test;
+
+
+import static org.junit.Assert.*;
+
+
+/**
+ */
+public class UserConfigurationPropertiesSourceTests {
+
+ @Test
+ public void testReadUserConfiguration() {
+ File[] dirs = new File[]{
+ new File("src/test/resources/" + getClass().getSimpleName())
+ };
+
+ UserConfigurationPropertiesSource source = new UserConfigurationPropertiesSource(dirs);
+ Map<String, Properties> properties = source.getConfigurationProperties();
+
+ Properties one = properties.get("one");
+ Properties two = properties.get("two");
+ assertNotNull(one);
+ assertNotNull(two);
+ assertEquals("bar", one.getProperty("foo"));
+ assertEquals("baz", two.getProperty("bar"));
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/commandline/CommandLinePropertiesSourceTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/commandline/CommandLinePropertiesSourceTests.java
new file mode 100644
index 00000000..c59e73f0
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/commandline/CommandLinePropertiesSourceTests.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * 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.config.internal.commandline;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.Test;
+
+
+import org.eclipse.virgo.kernel.config.internal.PropertiesSource;
+import org.eclipse.virgo.kernel.config.internal.commandline.CommandLinePropertiesSource;
+import org.eclipse.virgo.medic.test.eventlog.LoggedEvent;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+
+public class CommandLinePropertiesSourceTests {
+
+ private StubBundleContext bundleContext = new StubBundleContext();
+
+ private MockEventLogger eventLogger = new MockEventLogger();
+
+ @Test
+ public void defaults() {
+ PropertiesSource propertiesSource = new CommandLinePropertiesSource(this.bundleContext, this.eventLogger);
+ Map<String, Properties> configurationProperties = propertiesSource.getConfigurationProperties();
+
+ Properties properties = configurationProperties.get("org.eclipse.virgo.kernel.userregion");
+ assertNotNull(properties);
+
+ assertEquals("", properties.get("commandLineArtifacts"));
+
+ assertEquals(0, this.eventLogger.getLoggedEvents().size());
+ }
+
+ @Test
+ public void singlePlanWithVersion() {
+ this.bundleContext.addProperty("org.eclipse.virgo.osgi.launcher.unrecognizedArguments", "-plan,foo,1");
+ PropertiesSource propertiesSource = new CommandLinePropertiesSource(this.bundleContext, this.eventLogger);
+ Map<String, Properties> configurationProperties = propertiesSource.getConfigurationProperties();
+
+ Properties properties = configurationProperties.get("org.eclipse.virgo.kernel.userregion");
+ assertNotNull(properties);
+
+ assertEquals("repository:plan/foo/1", properties.get("commandLineArtifacts"));
+
+ assertEquals(0, this.eventLogger.getLoggedEvents().size());
+ }
+
+ @Test
+ public void singlePlanWithoutVersion() {
+ this.bundleContext.addProperty("org.eclipse.virgo.osgi.launcher.unrecognizedArguments", "-plan,foo");
+ PropertiesSource propertiesSource = new CommandLinePropertiesSource(this.bundleContext, this.eventLogger);
+ Map<String, Properties> configurationProperties = propertiesSource.getConfigurationProperties();
+
+ Properties properties = configurationProperties.get("org.eclipse.virgo.kernel.userregion");
+ assertNotNull(properties);
+
+ assertEquals("repository:plan/foo", properties.get("commandLineArtifacts"));
+
+ assertEquals(0, this.eventLogger.getLoggedEvents().size());
+ }
+
+ @Test
+ public void multiplePlans() {
+ this.bundleContext.addProperty("org.eclipse.virgo.osgi.launcher.unrecognizedArguments", "-plan,foo,-plan,bar,1.2.3");
+ PropertiesSource propertiesSource = new CommandLinePropertiesSource(this.bundleContext, this.eventLogger);
+ Map<String, Properties> configurationProperties = propertiesSource.getConfigurationProperties();
+
+ Properties properties = configurationProperties.get("org.eclipse.virgo.kernel.userregion");
+ assertNotNull(properties);
+
+ assertEquals("repository:plan/foo,repository:plan/bar/1.2.3", properties.get("commandLineArtifacts"));
+
+ assertEquals(0, this.eventLogger.getLoggedEvents().size());
+ }
+
+ @Test
+ public void planWithMissingArguments() {
+ this.bundleContext.addProperty("org.eclipse.virgo.osgi.launcher.unrecognizedArguments", "-plan");
+ PropertiesSource propertiesSource = new CommandLinePropertiesSource(this.bundleContext, this.eventLogger);
+ Map<String, Properties> configurationProperties = propertiesSource.getConfigurationProperties();
+
+ Properties properties = configurationProperties.get("org.eclipse.virgo.kernel.userregion");
+ assertNotNull(properties);
+
+ assertEquals("", properties.get("commandLineArtifacts"));
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertEquals(1, loggedEvents.size());
+
+ assertArrayEquals(new Object[] {0, ""}, loggedEvents.get(0).getInserts());
+ }
+
+ @Test
+ public void planWithSurplusArguments() {
+ this.bundleContext.addProperty("org.eclipse.virgo.osgi.launcher.unrecognizedArguments", "-plan,foo,bar,1.2.3");
+ PropertiesSource propertiesSource = new CommandLinePropertiesSource(this.bundleContext, this.eventLogger);
+ Map<String, Properties> configurationProperties = propertiesSource.getConfigurationProperties();
+
+ Properties properties = configurationProperties.get("org.eclipse.virgo.kernel.userregion");
+ assertNotNull(properties);
+
+ assertEquals("", properties.get("commandLineArtifacts"));
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertEquals(1, loggedEvents.size());
+
+ assertArrayEquals(new Object[] {3, "foo, bar, 1.2.3"}, loggedEvents.get(0).getInserts());
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ovf/OvfEnvironmentPropertiesReaderTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ovf/OvfEnvironmentPropertiesReaderTests.java
new file mode 100644
index 00000000..8604b3b0
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ovf/OvfEnvironmentPropertiesReaderTests.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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.config.internal.ovf;
+
+import java.io.FileReader;
+import java.util.Properties;
+
+import org.eclipse.virgo.kernel.config.internal.ovf.OvfEnvironmentPropertiesReader;
+import org.junit.Test;
+
+
+import static org.junit.Assert.*;
+
+
+/**
+ */
+public class OvfEnvironmentPropertiesReaderTests {
+
+ @Test
+ public void testReadProperties() throws Exception {
+
+ OvfEnvironmentPropertiesReader reader = new OvfEnvironmentPropertiesReader();
+ Properties props = reader.readProperties(new FileReader("src/test/resources/ovf/environment.xml"));
+ assertEquals("bar", props.getProperty("com.myapp.foo"));
+ assertEquals("baz", props.getProperty("com.myapp.bar"));
+
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ovf/OvfPropertiesSourceTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ovf/OvfPropertiesSourceTests.java
new file mode 100644
index 00000000..f6e3243c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/config/internal/ovf/OvfPropertiesSourceTests.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.config.internal.ovf;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.Test;
+
+
+import org.eclipse.virgo.kernel.config.internal.ovf.OvfPropertiesSource;
+import org.eclipse.virgo.kernel.diagnostics.KernelLogEvents;
+import org.eclipse.virgo.medic.test.eventlog.LoggedEvent;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+
+
+/**
+ */
+public class OvfPropertiesSourceTests {
+
+ @Test
+ public void testReadValidFile() {
+ MockEventLogger logger = new MockEventLogger();
+
+ StubBundleContext context = new StubBundleContext();
+ context.addProperty(OvfPropertiesSource.FRAMEWORK_PROPERTY_OVF, "src/test/resources/ovf/valid.xml");
+
+ OvfPropertiesSource source = new OvfPropertiesSource(context, logger);
+ Map<String, Properties> properties = source.getConfigurationProperties();
+ assertNotNull(properties);
+
+ Properties one = properties.get("one");
+ assertNotNull(one);
+ assertEquals("bar", one.getProperty("foo"));
+ assertEquals("baz", one.getProperty("bar"));
+
+ Properties two = properties.get("two");
+ assertNotNull(two);
+ assertEquals("quux", two.getProperty("baz"));
+
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void testReadFileWithInvalidProperty() {
+ MockEventLogger logger = new MockEventLogger();
+
+ StubBundleContext context = new StubBundleContext();
+ context.addProperty(OvfPropertiesSource.FRAMEWORK_PROPERTY_OVF, "src/test/resources/ovf/invalid.xml");
+
+ OvfPropertiesSource source = new OvfPropertiesSource(context, logger);
+ source.getConfigurationProperties();
+ }
+
+ @Test
+ public void testReadNonExistentFile() {
+ MockEventLogger logger = new MockEventLogger();
+
+ StubBundleContext context = new StubBundleContext();
+ context.addProperty(OvfPropertiesSource.FRAMEWORK_PROPERTY_OVF, "src/test/resources/ovf/nonexistent.xml");
+
+ OvfPropertiesSource source = new OvfPropertiesSource(context, logger);
+ Map<String, Properties> properties = source.getConfigurationProperties();
+
+ List<LoggedEvent> loggedEvents = logger.getLoggedEvents();
+ assertEquals(1, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(0);
+ assertEquals(KernelLogEvents.OVF_CONFIGURATION_FILE_DOES_NOT_EXIST.getEventCode(), loggedEvent.getCode());
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/BundleStartTrackerTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/BundleStartTrackerTests.java
new file mode 100644
index 00000000..0398a61d
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/BundleStartTrackerTests.java
@@ -0,0 +1,292 @@
+/*******************************************************************************
+ * 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.core.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.service.event.Event;
+import org.springframework.core.task.SyncTaskExecutor;
+
+import org.eclipse.virgo.kernel.core.Signal;
+import org.eclipse.virgo.kernel.core.internal.BundleStartTracker;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+
+
+/**
+ */
+public class BundleStartTrackerTests {
+
+ @Test
+ public void startOfBundleThatIsNotPoweredBySpringDm() throws BundleException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundle bundle = new StubBundle();
+ bundle.setBundleContext(bundleContext);
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(bundleContext);
+
+ UnitTestSignal signal = new UnitTestSignal();
+
+ bundleStartTracker.trackStart(bundle, signal);
+ bundle.start();
+
+ assertEquals(1, signal.successCount);
+ assertEquals(0, signal.failures.size());
+
+ assertEquals(Bundle.ACTIVE, bundle.getState());
+ }
+
+ @Test
+ public void startOfBundleThatIsPoweredBySpringDm() throws BundleException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundle bundle = new StubBundle();
+ bundle.addHeader("Spring-Context", "foo");
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(bundleContext);
+
+ UnitTestSignal signal = new UnitTestSignal();
+
+ bundleStartTracker.trackStart(bundle, signal);
+
+ assertEquals(0, signal.successCount);
+ assertEquals(0, signal.failures.size());
+
+ bundle.start();
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("bundle", bundle);
+
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/CREATED", properties));
+
+ assertEquals(1, signal.successCount);
+ assertEquals(0, signal.failures.size());
+ }
+
+ @Test
+ public void applicationContextCreationFailureOfBundleThatIsPoweredBySpringDm() throws BundleException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundle bundle = new StubBundle();
+ bundle.addHeader("Spring-Context", "foo");
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(bundleContext);
+
+ UnitTestSignal signal = new UnitTestSignal();
+
+ bundleStartTracker.trackStart(bundle, signal);
+
+ assertEquals(0, signal.successCount);
+ assertEquals(0, signal.failures.size());
+
+ bundle.start();
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("bundle", bundle);
+ Exception failure = new Exception();
+ properties.put("exception", failure);
+
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/FAILURE", properties));
+
+ assertEquals(0, signal.successCount);
+ assertEquals(1, signal.failures.size());
+
+ assertTrue(signal.failures.contains(failure));
+ }
+
+ @Test
+ public void trackingOfSpringDmPoweredBundleThatAlreadyCreatedItsContainer() throws BundleException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundle bundle = new StubBundle();
+ bundle.addHeader("Spring-Context", "foo");
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(bundleContext);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("bundle", bundle);
+
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/CREATED", properties));
+
+ UnitTestSignal signal = new UnitTestSignal();
+
+ bundleStartTracker.trackStart(bundle, signal);
+
+ assertEquals(1, signal.successCount);
+ assertEquals(0, signal.failures.size());
+ }
+
+ @Test
+ public void trackingOfSpringDmPoweredBundleThatHasAlreadyFailedToCreateItsApplicationContext() throws BundleException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundle bundle = new StubBundle();
+ bundle.addHeader("Spring-Context", "foo");
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(bundleContext);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("bundle", bundle);
+ Exception failure = new Exception();
+ properties.put("exception", failure);
+
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/FAILURE", properties));
+
+ UnitTestSignal signal = new UnitTestSignal();
+
+ bundleStartTracker.trackStart(bundle, signal);
+
+ assertEquals(0, signal.successCount);
+ assertEquals(1, signal.failures.size());
+ assertTrue(signal.failures.contains(failure));
+ }
+
+ @Test
+ public void signalIsOnlyDrivenOnceEvenWithMultipleEventsForStartOfBundleThatIsPoweredBySpringDm() throws BundleException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundle bundle = new StubBundle();
+ bundle.addHeader("Spring-Context", "foo");
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(bundleContext);
+
+ UnitTestSignal signal = new UnitTestSignal();
+
+ bundleStartTracker.trackStart(bundle, signal);
+
+ assertEquals(0, signal.successCount);
+ assertEquals(0, signal.failures.size());
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("bundle", bundle);
+
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/CREATED", properties));
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/CREATED", properties));
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/CREATED", properties));
+
+ assertEquals(1, signal.successCount);
+ assertEquals(0, signal.failures.size());
+ }
+
+ @Test
+ public void signalIsOnlyDrivenOnceEvenWithMultipleEventsForApplicationContextCreationFailureOfBundleThatIsPoweredBySpringDm() throws BundleException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundle bundle = new StubBundle();
+ bundle.addHeader("Spring-Context", "foo");
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(bundleContext);
+
+ UnitTestSignal signal = new UnitTestSignal();
+
+ bundleStartTracker.trackStart(bundle, signal);
+
+ assertEquals(0, signal.successCount);
+ assertEquals(0, signal.failures.size());
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("bundle", bundle);
+ Exception failure = new Exception();
+ properties.put("exception", failure);
+
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/FAILURE", properties));
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/FAILURE", properties));
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/FAILURE", properties));
+
+ assertEquals(0, signal.successCount);
+ assertEquals(1, signal.failures.size());
+
+ assertTrue(signal.failures.contains(failure));
+ }
+
+ @Test
+ public void createdStateIsCleanedUpWhenBundleIsStopped() throws BundleException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundle bundle = new StubBundle();
+ bundle.setBundleContext(bundleContext);
+ bundle.addHeader("Spring-Context", "foo");
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(bundleContext);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("bundle", bundle);
+
+ bundle.start();
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/CREATED", properties));
+ bundle.stop();
+
+ UnitTestSignal signal = new UnitTestSignal();
+
+ bundleStartTracker.trackStart(bundle, signal);
+
+ assertEquals(0, signal.successCount);
+ assertEquals(0, signal.failures.size());
+ }
+
+ @Test
+ public void failureStateIsCleanedUpWhenBundleIsStopped() throws BundleException {
+ StubBundleContext bundleContext = new StubBundleContext();
+ StubBundle bundle = new StubBundle();
+ bundle.setBundleContext(bundleContext);
+ bundle.addHeader("Spring-Context", "foo");
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(bundleContext);
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("bundle", bundle);
+ properties.put("exception", new Exception());
+
+ bundle.start();
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/FAILURE", properties));
+ bundle.stop();
+
+ UnitTestSignal signal = new UnitTestSignal();
+
+ bundleStartTracker.trackStart(bundle, signal);
+
+ assertEquals(0, signal.successCount);
+ assertEquals(0, signal.failures.size());
+ }
+
+ private static final class UnitTestSignal implements Signal {
+
+ private final List<Throwable> failures = new ArrayList<Throwable>();
+
+ private int successCount = 0;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void signalFailure(Throwable cause) {
+ this.failures.add(cause);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void signalSuccessfulCompletion() {
+ successCount++;
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/CoreBundleActivatorTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/CoreBundleActivatorTests.java
new file mode 100644
index 00000000..23e73c22
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/CoreBundleActivatorTests.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.core.internal;
+
+import static org.easymock.EasyMock.createNiceMock;
+
+import java.io.File;
+
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.event.EventAdmin;
+
+
+import org.eclipse.virgo.kernel.StubConfigurationAdmin;
+import org.eclipse.virgo.kernel.core.Shutdown;
+import org.eclipse.virgo.kernel.core.internal.CoreBundleActivator;
+import org.eclipse.virgo.kernel.core.internal.StartupTracker;
+import org.eclipse.virgo.medic.dump.DumpGenerator;
+import org.eclipse.virgo.medic.eventlog.EventLogger;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+import org.eclipse.virgo.teststubs.osgi.service.event.StubEventAdmin;
+
+/**
+ * Test the logic of {@link CoreBundleActivator}
+ *
+ */
+public class CoreBundleActivatorTests {
+
+ @Test(expected = IllegalStateException.class)
+ public void noConfigService() throws Exception {
+ StubBundleContext bundleContext = new StubBundleContext();
+ bundleContext.addFilter(StartupTracker.APPLICATION_CONTEXT_FILTER, FrameworkUtil.createFilter(StartupTracker.APPLICATION_CONTEXT_FILTER));
+ CoreBundleActivator activator = new TestCoreBundleActivator();
+ activator.start(bundleContext);
+ }
+
+ @Test
+ public void startAndStop() throws Exception {
+ StubBundleContext bundleContext = new StubBundleContext();
+ DumpGenerator dumpGenerator = createNiceMock(DumpGenerator.class);
+ bundleContext.addFilter(StartupTracker.APPLICATION_CONTEXT_FILTER, FrameworkUtil.createFilter(StartupTracker.APPLICATION_CONTEXT_FILTER));
+ bundleContext.registerService(ConfigurationAdmin.class.getName(), new StubConfigurationAdmin(), null);
+ bundleContext.registerService(EventLogger.class.getName(), new MockEventLogger(), null);
+ bundleContext.registerService(EventAdmin.class.getName(), new StubEventAdmin(), null);
+ bundleContext.registerService(DumpGenerator.class.getName(), dumpGenerator, null);
+ bundleContext.addProperty("org.eclipse.virgo.kernel.domain", "test");
+ bundleContext.addProperty("org.eclipse.virgo.kernel.home", new File(".").getAbsolutePath());
+
+ CoreBundleActivator activator = new TestCoreBundleActivator();
+ activator.start(bundleContext);
+ activator.stop(bundleContext);
+ }
+
+ private static final class TestCoreBundleActivator extends CoreBundleActivator {
+ @Override
+ protected Shutdown createShutdown(BundleContext context, EventLogger eventLogger) {
+ return new Shutdown() {
+ public void immediateShutdown() {
+ }
+
+ public void shutdown() {
+ }
+ };
+ }
+
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/ShutdownManagerTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/ShutdownManagerTests.java
new file mode 100644
index 00000000..e07fee7c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/ShutdownManagerTests.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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.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.assertTrue;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.launch.Framework;
+
+import org.eclipse.virgo.kernel.core.internal.ShutdownManager;
+import org.eclipse.virgo.medic.eventlog.EventLogger;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+
+public class ShutdownManagerTests {
+
+ private final Framework framework = createMock(Framework.class);
+
+ private final MockEventLogger eventLogger = new MockEventLogger();
+
+ private final StubBundle bundle = new StubBundle();
+
+ private final StubBundleContext bundleContext = new StubBundleContext(bundle);
+
+ @Test
+ public void shutdown() throws BundleException, InterruptedException {
+
+ expect(this.framework.getBundleContext()).andReturn(this.bundleContext).anyTimes();
+ this.framework.stop();
+ expect(this.framework.waitForStop(30000)).andReturn(new FrameworkEvent(FrameworkEvent.STOPPED, this.bundle, null));
+
+ replay(this.framework);
+
+ ShutdownManager shutdownManager = new ShutdownManager(this.eventLogger, this.framework);
+ shutdownManager.shutdown();
+
+ verify(this.framework);
+ }
+
+ @Test
+ public void failedShutdownDrivesImmediateShutdown() throws Exception {
+ expect(this.framework.getBundleContext()).andReturn(this.bundleContext).anyTimes();
+ this.framework.stop();
+ expect(this.framework.waitForStop(30000)).andReturn(new FrameworkEvent(FrameworkEvent.WAIT_TIMEDOUT, this.bundle, null));
+
+ replay(this.framework);
+
+ UnitTestShutdownManager shutdownManager = new UnitTestShutdownManager(this.eventLogger, this.framework);
+ shutdownManager.shutdown();
+
+ verify(this.framework);
+
+ this.eventLogger.isLogged("KE0011I");
+ }
+
+ @Test
+ public void shutdownMessageLogged() {
+ expect(this.framework.getBundleContext()).andReturn(this.bundleContext).anyTimes();
+
+ replay(this.framework);
+ ShutdownManager shutdownManager = new ShutdownManager(this.eventLogger, this.framework);
+ verify(this.framework);
+
+ List<BundleListener> bundleListeners = this.bundleContext.getBundleListeners();
+
+ assertEquals(1, bundleListeners.size());
+ bundleListeners.get(0).bundleChanged(new BundleEvent(BundleEvent.STOPPING, this.bundle));
+
+ assertTrue(this.eventLogger.isLogged("KE0010I"));
+ }
+
+ private static final class UnitTestShutdownManager extends ShutdownManager {
+
+ public UnitTestShutdownManager(EventLogger eventLogger, Framework framework) {
+ super(eventLogger, framework);
+ }
+
+ @Override
+ public void exitVM() {
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/StartupTrackerTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/StartupTrackerTests.java
new file mode 100644
index 00000000..efb3f608
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/StartupTrackerTests.java
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * 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.core.internal;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.management.ManagementFactory;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.osgi.framework.Version;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.springframework.core.task.SyncTaskExecutor;
+
+
+import org.eclipse.virgo.kernel.config.internal.KernelConfiguration;
+import org.eclipse.virgo.kernel.core.Shutdown;
+import org.eclipse.virgo.kernel.core.internal.BundleStartTracker;
+import org.eclipse.virgo.kernel.core.internal.StartupTracker;
+import org.eclipse.virgo.medic.dump.DumpGenerator;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundleContext;
+import org.eclipse.virgo.teststubs.osgi.service.event.StubEventAdmin;
+import org.eclipse.virgo.teststubs.osgi.support.ObjectClassFilter;
+
+public class StartupTrackerTests {
+
+ private final StubBundleContext bundleContext = new StubBundleContext();
+
+ private final StubEventAdmin eventAdmin = new StubEventAdmin();
+
+ private final StubBundle bundle = new StubBundle("org.eclipse.virgo.kernel.startuptest", new Version(1,0,0));
+
+ private final Shutdown shutdown = createMock(Shutdown.class);
+
+ private final DumpGenerator dumpGenerator = createMock(DumpGenerator.class);
+
+ @Before
+ public void setup() {
+ this.bundleContext.addInstalledBundle(bundle);
+
+ this.bundleContext.addProperty("org.eclipse.virgo.kernel.home", "target");
+ this.bundleContext.addProperty("org.eclipse.virgo.kernel.domain", "the-domain");
+ this.bundleContext.addFilter(new ObjectClassFilter("org.springframework.context.ApplicationContext"));
+ this.bundleContext.registerService(EventAdmin.class.getName(), this.eventAdmin, null);
+
+ this.bundle.setBundleContext(bundleContext);
+ }
+
+ @Test
+ public void successfulStartup() throws Exception {
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(this.bundleContext);
+
+ StartupTracker tracker = new StartupTracker(this.bundleContext, new KernelConfiguration(this.bundleContext), 30, bundleStartTracker, this.shutdown, this.dumpGenerator);
+ tracker.start();
+
+ assertTrue(this.eventAdmin.awaitPostingOfEvent(new Event("org/eclipse/virgo/kernel/STARTING", null), 10000));
+
+ this.bundle.start();
+
+ assertTrue(this.eventAdmin.awaitPostingOfEvent(new Event("org/eclipse/virgo/kernel/STARTED", null), 10000));
+
+ tracker.stop();
+ }
+
+ @Test
+ @Ignore("[DMS-2424] timeout is now hard-coded at one hour and so cannot be tested conveniently")
+ public void startupTimeout() {
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(this.bundleContext);
+
+ this.bundle.addHeader("Spring-Context", "foo");
+
+ this.shutdown.immediateShutdown();
+ this.dumpGenerator.generateDump("startupTimedOut");
+
+ replay(this.shutdown, this.dumpGenerator);
+
+ StartupTracker tracker = new StartupTracker(this.bundleContext, new KernelConfiguration(this.bundleContext), 1, bundleStartTracker, this.shutdown, this.dumpGenerator);
+ tracker.start();
+
+ assertTrue(this.eventAdmin.awaitPostingOfEvent(new Event("org/eclipse/virgo/kernel/STARTING", null), 10000));
+ assertTrue(this.eventAdmin.awaitPostingOfEvent(new Event("org/eclipse/virgo/kernel/START_TIMED_OUT", null), 10000));
+
+ waitForABit(500);
+
+ tracker.stop();
+
+ verify(this.shutdown);
+ verify(this.dumpGenerator);
+ }
+
+ /**
+ * This method is used to allow actions taken after the events are posted to complete
+ * before making test verification checks. This is an artifact of the testing environment, and the waits
+ * should be no more than about 500 ms.
+ * @param milliSeconds time to wait
+ */
+ private void waitForABit(long milliSeconds) {
+ try {
+ Thread.sleep(milliSeconds);
+ } catch (InterruptedException _) {
+ }
+ }
+
+ @Test
+ public void startupFailed() throws InterruptedException {
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(this.bundleContext);
+
+ this.bundle.addHeader("Spring-Context", "foo");
+
+ this.shutdown.immediateShutdown();
+
+ Exception failure = new Exception();
+ this.dumpGenerator.generateDump("startupFailed", failure);
+
+ replay(this.shutdown, this.dumpGenerator);
+
+ StartupTracker tracker = new StartupTracker(this.bundleContext, new KernelConfiguration(this.bundleContext), 1, bundleStartTracker, this.shutdown, this.dumpGenerator);
+ tracker.start();
+
+ assertTrue(this.eventAdmin.awaitPostingOfEvent(new Event("org/eclipse/virgo/kernel/STARTING", null), 10000));
+
+ Dictionary<String, Object> properties = new Hashtable<String, Object>();
+ properties.put("bundle", bundle);
+ properties.put("exception", failure);
+
+ bundleStartTracker.handleEvent(new Event("org/osgi/service/blueprint/container/FAILURE", properties));
+
+ assertTrue(this.eventAdmin.awaitPostingOfEvent(new Event("org/eclipse/virgo/kernel/START_FAILED", null), 10000));
+
+ waitForABit(500);
+
+ tracker.stop();
+
+ verify(this.shutdown, this.dumpGenerator);
+ }
+
+
+ @Test
+ public void statusMBeanRegistration() throws Exception {
+ assertMBeanNotRegistered();
+
+ BundleStartTracker bundleStartTracker = new BundleStartTracker(new SyncTaskExecutor());
+ bundleStartTracker.initialize(this.bundleContext);
+
+ StartupTracker tracker = new StartupTracker(this.bundleContext, new KernelConfiguration(this.bundleContext), 1, bundleStartTracker, this.shutdown, this.dumpGenerator);
+ tracker.start();
+
+ assertMBeanRegistered();
+
+ tracker.stop();
+
+ assertMBeanNotRegistered();
+ }
+
+ private void assertMBeanRegistered() throws Exception {
+ assertTrue(isMBeanRegistered());
+ }
+
+ private void assertMBeanNotRegistered() throws Exception {
+ assertFalse(isMBeanRegistered());
+ }
+
+ private boolean isMBeanRegistered() throws Exception {
+ MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
+ return mBeanServer.isRegistered(new ObjectName("the-domain", "type", "KernelStatus"));
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/blueprint/ApplicationContextDependencyMonitorTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/blueprint/ApplicationContextDependencyMonitorTests.java
new file mode 100644
index 00000000..168dc5a6
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/blueprint/ApplicationContextDependencyMonitorTests.java
@@ -0,0 +1,268 @@
+/*******************************************************************************
+ * 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.core.internal.blueprint;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.junit.Test;
+import org.osgi.framework.Version;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventConstants;
+
+import org.eclipse.virgo.kernel.core.internal.blueprint.ApplicationContextDependencyMonitor;
+import org.eclipse.virgo.medic.test.eventlog.LoggedEvent;
+import org.eclipse.virgo.medic.test.eventlog.MockEventLogger;
+import org.eclipse.virgo.teststubs.osgi.framework.StubBundle;
+
+/**
+ */
+public class ApplicationContextDependencyMonitorTests {
+
+ private final MockEventLogger eventLogger = new MockEventLogger();
+
+ private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
+
+ private final ApplicationContextDependencyMonitor dependencyMonitor = new ApplicationContextDependencyMonitor(executor, eventLogger);
+
+ private final StubBundle bundle = new StubBundle("the.bundle", new Version(1, 2, 3));
+
+ @Test
+ public void loggingOfWaitingEventForMandatoryService() throws InterruptedException {
+ Event event = new Event("org/osgi/service/blueprint/container/WAITING", createProperties("filter", "theBean", true));
+ this.dependencyMonitor.handleEvent(event);
+
+ Thread.sleep(6000);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertEquals(1, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(0);
+
+ assertEquals("KE0100W", loggedEvent.getCode());
+ Object[] inserts = loggedEvent.getInserts();
+ assertEquals(4, inserts.length);
+
+ assertEquals("theBean", inserts[0]);
+ assertEquals(this.bundle.getSymbolicName(), inserts[1]);
+ assertEquals(this.bundle.getVersion(), inserts[2]);
+ assertEquals("filter", inserts[3]);
+ }
+
+ @Test
+ public void loggingOfWaitingEventForOptionalService() throws InterruptedException {
+ Event event = new Event("org/osgi/service/blueprint/container/WAITING", createProperties("filter", "theBean", false));
+ this.dependencyMonitor.handleEvent(event);
+
+ Thread.sleep(6000);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertEquals(1, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(0);
+
+ assertEquals("KE0100W", loggedEvent.getCode());
+ Object[] inserts = loggedEvent.getInserts();
+ assertEquals(4, inserts.length);
+
+ assertEquals("theBean", inserts[0]);
+ assertEquals(this.bundle.getSymbolicName(), inserts[1]);
+ assertEquals(this.bundle.getVersion(), inserts[2]);
+ assertEquals("filter", inserts[3]);
+ }
+
+ @Test
+ public void loggingOfDependencySatisfied() throws InterruptedException {
+ Event event = new Event("org/osgi/service/blueprint/container/WAITING", createProperties("filter", "theBean", true));
+ this.dependencyMonitor.handleEvent(event);
+
+ Thread.sleep(6000);
+
+ event = new Event("org/osgi/service/blueprint/container/GRACE_PERIOD", createProperties());
+ this.dependencyMonitor.handleEvent(event);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertEquals(2, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(1);
+
+ assertEquals("KE0101I", loggedEvent.getCode());
+ Object[] inserts = loggedEvent.getInserts();
+ assertEquals(4, inserts.length);
+
+ assertEquals("theBean", inserts[0]);
+ assertEquals(this.bundle.getSymbolicName(), inserts[1]);
+ assertEquals(this.bundle.getVersion(), inserts[2]);
+ assertEquals("filter", inserts[3]);
+ }
+
+ @Test
+ public void loggingOfMandatoryDependencyTimedOut() throws InterruptedException {
+ Event event = new Event("org/osgi/service/blueprint/container/WAITING", createProperties("filter", "theBean", true));
+ this.dependencyMonitor.handleEvent(event);
+
+ Thread.sleep(6000);
+
+ event = new Event("org/osgi/service/blueprint/container/FAILURE", createProperties("filter", "theBean", true));
+ this.dependencyMonitor.handleEvent(event);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertEquals(2, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(1);
+
+ assertEquals("KE0102E", loggedEvent.getCode());
+ Object[] inserts = loggedEvent.getInserts();
+ assertEquals(4, inserts.length);
+
+ assertEquals("theBean", inserts[0]);
+ assertEquals(this.bundle.getSymbolicName(), inserts[1]);
+ assertEquals(this.bundle.getVersion(), inserts[2]);
+ assertEquals("filter", inserts[3]);
+ }
+
+ @Test
+ public void loggingOfOptionalDependencyTimedOut() throws InterruptedException {
+ Event event = new Event("org/osgi/service/blueprint/container/WAITING", createProperties("filter", "theBean", false));
+ this.dependencyMonitor.handleEvent(event);
+
+ Thread.sleep(6000);
+
+ event = new Event("org/osgi/service/blueprint/container/FAILURE", createProperties("filter", "theBean", false));
+ this.dependencyMonitor.handleEvent(event);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertEquals(2, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(1);
+
+ assertEquals("KE0102E", loggedEvent.getCode());
+ Object[] inserts = loggedEvent.getInserts();
+ assertEquals(4, inserts.length);
+
+ assertEquals("theBean", inserts[0]);
+ assertEquals(this.bundle.getSymbolicName(), inserts[1]);
+ assertEquals(this.bundle.getVersion(), inserts[2]);
+ assertEquals("filter", inserts[3]);
+ }
+
+ @Test
+ public void containerCreationFailureRemovesTickers() throws InterruptedException {
+ Event event = new Event("org/osgi/service/blueprint/container/WAITING", createProperties("filter", "theBean", true));
+ this.dependencyMonitor.handleEvent(event);
+
+ event = new Event("org/osgi/service/blueprint/container/FAILURE", createProperties());
+ this.dependencyMonitor.handleEvent(event);
+
+ Thread.sleep(3000);
+
+ assertFalse(this.eventLogger.getCalled());
+ }
+
+ @Test
+ public void containerCreationDrivesOutstandingTickers() throws InterruptedException {
+ Event event = new Event("org/osgi/service/blueprint/container/WAITING", createProperties("filter", "theBean", true));
+ this.dependencyMonitor.handleEvent(event);
+
+ Thread.sleep(6000);
+
+ event = new Event("org/osgi/service/blueprint/container/CREATED", createProperties());
+ this.dependencyMonitor.handleEvent(event);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertEquals(2, loggedEvents.size());
+
+ LoggedEvent loggedEvent = loggedEvents.get(1);
+
+ assertEquals("KE0101I", loggedEvent.getCode());
+ Object[] inserts = loggedEvent.getInserts();
+ assertEquals(4, inserts.length);
+
+ assertEquals("theBean", inserts[0]);
+ assertEquals(this.bundle.getSymbolicName(), inserts[1]);
+ assertEquals(this.bundle.getVersion(), inserts[2]);
+ assertEquals("filter", inserts[3]);
+ }
+
+ @Test
+ public void dependencyThatIsSatisfiedQuicklyLogsNothing() throws InterruptedException {
+ Event event = new Event("org/osgi/service/blueprint/container/WAITING", createProperties("filter", "theBean", true));
+ this.dependencyMonitor.handleEvent(event);
+
+ event = new Event("org/osgi/service/blueprint/container/GRACE_PERIOD", createProperties());
+ this.dependencyMonitor.handleEvent(event);
+
+ Thread.sleep(3000);
+
+ List<LoggedEvent> loggedEvents = this.eventLogger.getLoggedEvents();
+ assertEquals(0, loggedEvents.size());
+ }
+
+ @Test
+ public void slowServicesAreGivenLongerToBecomeAvailable() throws InterruptedException {
+ Event event = new Event("org/osgi/service/blueprint/container/WAITING", createProperties("(org.eclipse.virgo.server.slowservice=true)",
+ "theBean", true));
+ this.dependencyMonitor.handleEvent(event);
+
+ Thread.sleep(3000);
+
+ assertFalse(this.eventLogger.getCalled());
+ }
+
+ @Test
+ public void containerCreatedNotWaiting() {
+ Event event = new Event("org/osgi/service/blueprint/container/CREATED", createProperties());
+ this.dependencyMonitor.handleEvent(event);
+ }
+
+ @Test
+ public void changeInUnsatisfiedDependenciesNotWaiting() {
+ Event event = new Event("org/osgi/service/blueprint/container/GRACE_PERIOD", createProperties());
+ this.dependencyMonitor.handleEvent(event);
+ }
+
+ @Test
+ public void serviceDependenciesTimedOutNotWaiting() {
+ Event event = new Event("org/osgi/service/blueprint/container/FAILURE", createProperties("filter", "theBean", false));
+ this.dependencyMonitor.handleEvent(event);
+ }
+
+ @Test
+ public void containerCreationFailedNotWaiting() {
+ Event event = new Event("org/osgi/service/blueprint/container/FAILURE", createProperties());
+ this.dependencyMonitor.handleEvent(event);
+ }
+
+ @SuppressWarnings("unchecked")
+ private Dictionary createProperties(String filter, String beanName, boolean mandatory) {
+ Dictionary properties = createProperties();
+
+ properties.put("dependencies", new String[] { filter });
+ properties.put("bean.name", new String[] { beanName });
+ properties.put("mandatory", new boolean[] { mandatory });
+
+ return properties;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Dictionary createProperties() {
+ Dictionary properties = new Hashtable();
+ properties.put(EventConstants.BUNDLE, this.bundle);
+ return properties;
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/blueprint/TickerTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/blueprint/TickerTests.java
new file mode 100644
index 00000000..3ea4606b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/core/internal/blueprint/TickerTests.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.core.internal.blueprint;
+
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+
+import org.eclipse.virgo.kernel.core.internal.blueprint.StandardTicker;
+import org.eclipse.virgo.kernel.core.internal.blueprint.Ticker;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+/**
+ */
+public class TickerTests {
+
+ private volatile int ticks;
+
+ @Test public void testTicker() throws InterruptedException {
+ this.ticks = 0;
+ Ticker ticker = StandardTicker.createExponentialTicker(20, 100, 60 * 1000, new Callable<Void>() {
+
+ public Void call() throws Exception {
+ TickerTests.this.ticks++;
+ return null;
+ }}, new ScheduledThreadPoolExecutor(1));
+
+ Thread.sleep(2000);
+ ticker.cancel();
+
+ Assert.assertEquals(6, ticks);
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/AssertTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/AssertTests.java
new file mode 100644
index 00000000..431d75cd
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/AssertTests.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * 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.serviceability;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.virgo.kernel.serviceability.Assert;
+import org.eclipse.virgo.kernel.serviceability.Assert.FatalAssertionException;
+import org.junit.Test;
+
+
+/**
+ */
+public class AssertTests {
+
+ @Test
+ public void testHasLength() {
+ try {
+ Assert.hasLength(null, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ try {
+ Assert.hasLength("", "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ Assert.hasLength("x", "blah");
+ }
+
+ @Test
+ public void testIsAssignable() {
+ try {
+ Assert.isAssignable(String.class, Object.class, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ try {
+ Assert.isAssignable(null, Object.class, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ try {
+ Assert.isAssignable(Object.class, null, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ Assert.isAssignable(Object.class, Object.class, "blah");
+ Assert.isAssignable(Object.class, String.class, "blah");
+ }
+
+ @Test
+ public void testIsInstanceOf() {
+ try {
+ Assert.isInstanceOf(Integer.class, "", "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ try {
+ Assert.isInstanceOf(null, "", "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ try {
+ Assert.isInstanceOf(Integer.class, null, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ Assert.isInstanceOf(String.class, "", "blah");
+ }
+
+ @Test
+ public void testIsNull() {
+ try {
+ Assert.isNull("", "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ Assert.isNull(null, "blah");
+ }
+
+ @Test
+ public void testIsTrue() {
+ try {
+ Assert.isTrue(false, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ Assert.isTrue(true, "blah");
+ }
+
+ @Test
+ public void testIsFalse() {
+ try {
+ Assert.isFalse(true, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ Assert.isFalse(false, "blah");
+ }
+
+ @Test
+ public void testNotEmptyCollection() {
+ try {
+ Assert.notEmpty(new HashSet<String>(), "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ try {
+ Assert.notEmpty((Collection<String>)null, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ Set<String> a = new HashSet<String>();
+ a.add("x");
+ Assert.notEmpty(a, "blah");
+ }
+
+ @Test
+ public void testNotEmptyMap() {
+ try {
+ Assert.notEmpty(new HashMap<String, String>(), "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ try {
+ Assert.notEmpty((Map<String, String>)null, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ Map<String, String> a = new HashMap<String, String>();
+ a.put("k", "v");
+ Assert.notEmpty(a, "blah");
+ }
+
+ @Test
+ public void testNotEmptyArray() {
+ try {
+ Object[] a = {};
+ Assert.notEmpty(a, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ try {
+ Assert.notEmpty((Object[])null, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ Object[] a = {"x"};
+ Assert.notEmpty(a, "blah");
+ }
+
+ @Test
+ public void testNotNull() {
+ try {
+ Assert.notNull(null, "blah");
+ org.junit.Assert.assertTrue(false);
+ } catch (FatalAssertionException e) {
+ }
+ Assert.notNull("x", "blah");
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/dump/FFDCExceptionStateTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/dump/FFDCExceptionStateTests.java
new file mode 100644
index 00000000..d67bbeff
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/dump/FFDCExceptionStateTests.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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.serviceability.dump;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.eclipse.virgo.kernel.serviceability.dump.FFDCExceptionState;
+import org.junit.Test;
+
+
+public class FFDCExceptionStateTests {
+
+ @Test
+ public void seen() {
+ Throwable throwable = new Throwable();
+ assertFalse(FFDCExceptionState.seen(throwable));
+ FFDCExceptionState.record(throwable);
+ assertTrue(FFDCExceptionState.seen(throwable));
+ }
+
+ @Test
+ public void multithreadedSeen() {
+ final Throwable throwable = new Throwable();
+ FFDCExceptionState.record(throwable);
+ assertTrue(FFDCExceptionState.seen(throwable));
+ SeenChecker checker = new SeenChecker(throwable);
+ checker.start();
+ assertFalse(checker.seen());
+ }
+
+ @Test
+ public void seenAsNestedCause() {
+ Throwable nested = new Throwable();
+ FFDCExceptionState.record(nested);
+ Throwable root = new Throwable(nested);
+ assertTrue(FFDCExceptionState.seen(root));
+ }
+
+ private class SeenChecker extends Thread {
+
+ private final Throwable throwable;
+ private volatile boolean seen;
+ private final CountDownLatch latch;
+
+ public SeenChecker(Throwable throwable) {
+ this.throwable = throwable;
+ this.latch = new CountDownLatch(1);
+ }
+
+ public boolean seen() {
+ boolean awaiting = true;
+ while (awaiting) {
+ try {
+ this.latch.await();
+ awaiting = false;
+ } catch (InterruptedException ie) {
+
+ }
+ }
+ return this.seen;
+ }
+
+ public void run() {
+ seen = FFDCExceptionState.seen(throwable);
+ latch.countDown();
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/enforcement/NonNullAssertionEnforcerTests.java b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/enforcement/NonNullAssertionEnforcerTests.java
new file mode 100644
index 00000000..413359b4
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/org/eclipse/virgo/kernel/serviceability/enforcement/NonNullAssertionEnforcerTests.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.serviceability.enforcement;
+
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import test.AssertingService;
+
+import org.eclipse.virgo.kernel.serviceability.Assert;
+import org.eclipse.virgo.kernel.serviceability.dump.DumpCoordinator;
+import org.eclipse.virgo.medic.dump.DumpGenerator;
+
+public class NonNullAssertionEnforcerTests {
+
+ @Before
+ public void injectDumpGenerator() {
+ DumpCoordinator.aspectOf().setDumpGenerator(new StubDumpGenerator());
+ }
+
+ @Test(expected = Assert.FatalAssertionException.class)
+ public void firstMethodArg() {
+ AssertingService service = new AssertingService();
+ service.test(null);
+ }
+
+ @Test(expected = Assert.FatalAssertionException.class)
+ public void secondMethodArg() {
+ AssertingService service = new AssertingService();
+ service.test("foo", null);
+ }
+
+ @Test(expected = Assert.FatalAssertionException.class)
+ public void thirdMethodArg() {
+ AssertingService service = new AssertingService();
+ service.test("foo", 1, null);
+ }
+
+ @Test(expected = Assert.FatalAssertionException.class)
+ public void firstConstructorArg() {
+ new AssertingService(null);
+ }
+
+ @Test(expected = Assert.FatalAssertionException.class)
+ public void secondConstructorArg() {
+ new AssertingService("foo", null);
+ }
+
+ @Test(expected = Assert.FatalAssertionException.class)
+ public void thirdConstructorArg() {
+ new AssertingService("foo", 1, null);
+ }
+
+ private static class StubDumpGenerator implements DumpGenerator {
+
+ public void generateDump(String cause, Throwable... throwables) {
+ }
+
+ public void generateDump(String cause, Map<String, Object> context, Throwable... throwables) {
+ }
+
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/java/test/AssertingService.java b/org.eclipse.virgo.kernel.core/src/test/java/test/AssertingService.java
new file mode 100644
index 00000000..006c96b2
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/java/test/AssertingService.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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 test;
+
+import org.eclipse.virgo.kernel.serviceability.NonNull;
+
+
+/**
+ */
+@SuppressWarnings("unused")
+public class AssertingService {
+
+ public AssertingService() {
+
+ }
+
+ public AssertingService( @NonNull String a) {
+
+ }
+
+ public AssertingService(String a, @NonNull Integer b) {
+
+ }
+
+ public AssertingService(String a, Integer b, @NonNull Double c) {
+
+ }
+
+ public void test(@NonNull String a) {
+ }
+
+ public void test(@NonNull String a, @NonNull Integer b) {
+
+ }
+
+ public void test(String a, Integer b, @NonNull Double d) {
+
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_badprops/noprops.properties b/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_badprops/noprops.properties
new file mode 100644
index 00000000..b419c60e
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_badprops/noprops.properties
@@ -0,0 +1,2 @@
+
+!@£$%^&*()_
diff --git a/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_noprops/noise.config b/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_noprops/noise.config
new file mode 100644
index 00000000..f13418ca
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_noprops/noise.config
@@ -0,0 +1,11 @@
+{
+ "types": {
+ "int" : 123,
+ "string": "foo",
+ "boolean": true,
+ "path1": "foo/bar",
+ "path2": "/foo/bar",
+ "path3": "../../foo/bar",
+ "path4": "/foo/../bar"
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_noprops/noise2.config b/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_noprops/noise2.config
new file mode 100644
index 00000000..f13418ca
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_noprops/noise2.config
@@ -0,0 +1,11 @@
+{
+ "types": {
+ "int" : 123,
+ "string": "foo",
+ "boolean": true,
+ "path1": "foo/bar",
+ "path2": "/foo/bar",
+ "path3": "../../foo/bar",
+ "path4": "/foo/../bar"
+ }
+}
diff --git a/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_props1/dup.properties b/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_props1/dup.properties
new file mode 100644
index 00000000..30aee8b2
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_props1/dup.properties
@@ -0,0 +1,3 @@
+# Properties file for Config Admin service configuration properties.
+test=This is a test string
+dup_prop=Duplicate property one
diff --git a/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_props2/dup.properties b/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_props2/dup.properties
new file mode 100644
index 00000000..f700caf3
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/resources/ConfigBundleTests/config_tests_props2/dup.properties
@@ -0,0 +1,6 @@
+# Properties file for Config Admin service configuration properties.
+test=This is a test string as well
+dup_prop=Duplicate property two
+hidden=Hidden property
+boolean=false
+integer=1024
diff --git a/org.eclipse.virgo.kernel.core/src/test/resources/UserConfigurationPropertiesSourceTests/one.properties b/org.eclipse.virgo.kernel.core/src/test/resources/UserConfigurationPropertiesSourceTests/one.properties
new file mode 100644
index 00000000..74d0a43f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/resources/UserConfigurationPropertiesSourceTests/one.properties
@@ -0,0 +1 @@
+foo=bar
diff --git a/org.eclipse.virgo.kernel.core/src/test/resources/UserConfigurationPropertiesSourceTests/two.properties b/org.eclipse.virgo.kernel.core/src/test/resources/UserConfigurationPropertiesSourceTests/two.properties
new file mode 100644
index 00000000..eacf225c
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/resources/UserConfigurationPropertiesSourceTests/two.properties
@@ -0,0 +1 @@
+bar=baz
diff --git a/org.eclipse.virgo.kernel.core/src/test/resources/ovf/environment.xml b/org.eclipse.virgo.kernel.core/src/test/resources/ovf/environment.xml
new file mode 100644
index 00000000..9c16f830
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/resources/ovf/environment.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Environment xmlns="http://schemas.dmtf.org/ovf/environment/1"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1"
+ xsi:schemaLocation="http://schemas.dmtf.org/ovf/environment/1 http://schemas.dmtf.org/ovf/environment/1/dsp8027.xsd"
+ ovfenv:id="DB1">
+
+ <!-- This example reference a local schema file, to validate against online schema use:
+ xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8027_1.0.0.xsd"
+ -->
+
+ <!-- Information about hypervisor platform -->
+ <PlatformSection>
+ <Kind>ESX Server</Kind>
+ <Version>3.0.1</Version>
+ <Vendor>VMware, Inc.</Vendor>
+ <Locale>en_US</Locale>
+ </PlatformSection>
+
+ <!--- Properties defined for this virtual machine -->
+ <PropertySection>
+ <Property ovfenv:key="com.myapp.foo" ovfenv:value="bar"/>
+ <Property ovfenv:key="com.myapp.bar" ovfenv:value="baz"/>
+ </PropertySection>
+
+</Environment>
diff --git a/org.eclipse.virgo.kernel.core/src/test/resources/ovf/invalid.xml b/org.eclipse.virgo.kernel.core/src/test/resources/ovf/invalid.xml
new file mode 100644
index 00000000..ee406ee4
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/resources/ovf/invalid.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Environment xmlns="http://schemas.dmtf.org/ovf/environment/1"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1"
+ xsi:schemaLocation="http://schemas.dmtf.org/ovf/environment/1 http://schemas.dmtf.org/ovf/environment/1/dsp8027.xsd"
+ ovfenv:id="DB1">
+
+ <!-- This example reference a local schema file, to validate against online schema use:
+ xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8027_1.0.0.xsd"
+ -->
+
+ <!-- Information about hypervisor platform -->
+ <PlatformSection>
+ <Kind>ESX Server</Kind>
+ <Version>3.0.1</Version>
+ <Vendor>VMware, Inc.</Vendor>
+ <Locale>en_US</Locale>
+ </PlatformSection>
+
+ <!--- Properties defined for this virtual machine -->
+ <PropertySection>
+ <Property ovfenv:key="cm:invalid" ovfenv:value="bar"/>
+ </PropertySection>
+
+</Environment>
diff --git a/org.eclipse.virgo.kernel.core/src/test/resources/ovf/valid.xml b/org.eclipse.virgo.kernel.core/src/test/resources/ovf/valid.xml
new file mode 100644
index 00000000..aff0fc60
--- /dev/null
+++ b/org.eclipse.virgo.kernel.core/src/test/resources/ovf/valid.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Environment xmlns="http://schemas.dmtf.org/ovf/environment/1"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1"
+ xsi:schemaLocation="http://schemas.dmtf.org/ovf/environment/1 http://schemas.dmtf.org/ovf/environment/1/dsp8027.xsd"
+ ovfenv:id="DB1">
+
+ <!-- This example reference a local schema file, to validate against online schema use:
+ xsi:schemaLocation="http://schemas.dmtf.org/ovf/envelope/1 http://schemas.dmtf.org/ovf/envelope/1/dsp8027_1.0.0.xsd"
+ -->
+
+ <!-- Information about hypervisor platform -->
+ <PlatformSection>
+ <Kind>ESX Server</Kind>
+ <Version>3.0.1</Version>
+ <Vendor>VMware, Inc.</Vendor>
+ <Locale>en_US</Locale>
+ </PlatformSection>
+
+ <!--- Properties defined for this virtual machine -->
+ <PropertySection>
+ <Property ovfenv:key="cm:one:foo" ovfenv:value="bar"/>
+ <Property ovfenv:key="cm:one:bar" ovfenv:value="baz"/>
+ <Property ovfenv:key="cm:two:baz" ovfenv:value="quux"/>
+ <Property ovfenv:key="some.random.property" ovfenv:value="value"/>
+ </PropertySection>
+
+</Environment>

Back to the top