CQ-4081: Initial import
diff --git a/tests/org.eclipse.e4.core.metaconfig.test/.classpath b/tests/org.eclipse.e4.core.metaconfig.test/.classpath
new file mode 100644
index 0000000..8a8f166
--- /dev/null
+++ b/tests/org.eclipse.e4.core.metaconfig.test/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>

+<classpath>

+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>

+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>

+	<classpathentry kind="src" path="src"/>

+	<classpathentry kind="output" path="bin"/>

+</classpath>

diff --git a/tests/org.eclipse.e4.core.metaconfig.test/.project b/tests/org.eclipse.e4.core.metaconfig.test/.project
new file mode 100644
index 0000000..e31fbce
--- /dev/null
+++ b/tests/org.eclipse.e4.core.metaconfig.test/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>

+<projectDescription>

+	<name>org.eclipse.e4.core.metaconfig.test</name>

+	<comment></comment>

+	<projects>

+	</projects>

+	<buildSpec>

+		<buildCommand>

+			<name>org.eclipse.jdt.core.javabuilder</name>

+			<arguments>

+			</arguments>

+		</buildCommand>

+		<buildCommand>

+			<name>org.eclipse.pde.ManifestBuilder</name>

+			<arguments>

+			</arguments>

+		</buildCommand>

+		<buildCommand>

+			<name>org.eclipse.pde.SchemaBuilder</name>

+			<arguments>

+			</arguments>

+		</buildCommand>

+	</buildSpec>

+	<natures>

+		<nature>org.eclipse.pde.PluginNature</nature>

+		<nature>org.eclipse.jdt.core.javanature</nature>

+	</natures>

+</projectDescription>

diff --git a/tests/org.eclipse.e4.core.metaconfig.test/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.e4.core.metaconfig.test/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..cca8957
--- /dev/null
+++ b/tests/org.eclipse.e4.core.metaconfig.test/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+#Mon May 04 09:54:01 CDT 2009

+eclipse.preferences.version=1

+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled

+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5

+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve

+org.eclipse.jdt.core.compiler.compliance=1.5

+org.eclipse.jdt.core.compiler.debug.lineNumber=generate

+org.eclipse.jdt.core.compiler.debug.localVariable=generate

+org.eclipse.jdt.core.compiler.debug.sourceFile=generate

+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error

+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error

+org.eclipse.jdt.core.compiler.source=1.5

diff --git a/tests/org.eclipse.e4.core.metaconfig.test/META-INF/MANIFEST.MF b/tests/org.eclipse.e4.core.metaconfig.test/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..1fec7ec
--- /dev/null
+++ b/tests/org.eclipse.e4.core.metaconfig.test/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Configuration Framework Test Fragment
+Bundle-SymbolicName: org.eclipse.e4.core.metaconfig.test
+Bundle-Version: 4.6.0.qualifier
+Fragment-Host: org.eclipse.e4.core.metaconfig;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.junit,
+ org.eclipse.e4.ui.test.utils
diff --git a/tests/org.eclipse.e4.core.metaconfig.test/build.properties b/tests/org.eclipse.e4.core.metaconfig.test/build.properties
new file mode 100644
index 0000000..41eb6ad
--- /dev/null
+++ b/tests/org.eclipse.e4.core.metaconfig.test/build.properties
@@ -0,0 +1,4 @@
+source.. = src/

+output.. = bin/

+bin.includes = META-INF/,\

+               .

diff --git a/tests/org.eclipse.e4.core.metaconfig.test/src/org/eclipse/e4/core/metaconfig/ConfigurationTest.java b/tests/org.eclipse.e4.core.metaconfig.test/src/org/eclipse/e4/core/metaconfig/ConfigurationTest.java
new file mode 100644
index 0000000..3ee780a
--- /dev/null
+++ b/tests/org.eclipse.e4.core.metaconfig.test/src/org/eclipse/e4/core/metaconfig/ConfigurationTest.java
@@ -0,0 +1,213 @@
+/******************************************************************************
+ * Copyright (c) David Orme and others
+ * 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:
+ *    David Orme - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.e4.core.metaconfig;

+

+import java.io.FileNotFoundException;

+import java.io.InputStream;

+import java.util.Properties;

+

+import org.eclipse.e4.core.metaconfig.Configuration;
+import org.eclipse.e4.core.metaconfig.ConfigurationException;
+import org.eclipse.e4.ui.test.utils.StringInputStream;
+

+import junit.framework.TestCase;

+

+public class ConfigurationTest extends TestCase {

+

+	Configuration testee = null;

+

+	public void testReturnedPropertiesAreCloned() throws Exception {

+		testee = new Configuration() {

+			@Override

+			Properties populateProperties(String configFileSource) {

+				Properties stunt = new Properties();

+				stunt.setProperty("cow", "moo");

+				stunt.setProperty("pig", "oink");

+				return stunt;

+			}

+

+			@Override

+			String getPropertiesFileLocation() throws ConfigurationException {

+				return "this is ignored too";

+			}

+		};

+

+		Properties properties1 = testee.getProperties();

+		Properties properties2 = testee.getProperties();

+

+		assertTrue(properties1.equals(properties2));

+		assertFalse(properties1 == properties2);

+	}

+

+	public void testPopulatePropertiesWithNullPath_shouldThrowConfigurationException() throws Exception {

+		testee = new Configuration();

+

+		try {

+			testee.populateProperties(null);

+			fail();

+

+		} catch (ConfigurationException e) {

+			// want to be here

+		}

+	}

+

+	public void testGetPropertiesFileLocation_missingConfigFile_shouldThrowConfigurationException() throws Exception {

+		testee = new Configuration() {

+			@Override

+			InputStream openMetaPropertiesFile() throws FileNotFoundException {

+				throw new FileNotFoundException("File not found");

+			}

+

+			@Override

+			public String installLocation() {

+				return INSTALL_LOCATION;

+			}

+		};

+

+		try {

+			testee.getPropertiesFileLocation();

+			fail();

+		} catch (ConfigurationException e) {

+			assertTrue(e.getCause() instanceof FileNotFoundException);

+		}

+	}

+

+	public void testGetPropertiesFileLocation_ValidConfigFile_success() throws Exception {

+		final String LOCATION = "configuration.location";

+		testee = new Configuration() {

+			@Override

+			InputStream openMetaPropertiesFile() throws FileNotFoundException {

+				String propertiesFile = Configuration.CONFIGURATION_KEY + "=" + LOCATION;

+				return new StringInputStream(propertiesFile);

+			}

+		};

+

+		String result = testee.getPropertiesFileLocation();

+		assertEquals("Found result", LOCATION, result);

+	}

+

+	// --------------------------------------------------------------------------

+

+	public void testSubstitute_nullInputThrowsIllegalArgumentException() throws Exception {

+		testee = new Configuration();

+

+		try {

+			testee.substitute(null, null, null);

+			fail();

+		} catch (IllegalArgumentException e) {

+			// success

+		}

+		try {

+			testee.substitute("", "", null);

+			fail();

+		} catch (IllegalArgumentException e) {

+			// success

+		}

+		try {

+			testee.substitute("", null, "");

+			fail();

+		} catch (IllegalArgumentException e) {

+			// success

+		}

+		try {

+			testee.substitute(null, "", "");

+			fail();

+		} catch (IllegalArgumentException e) {

+			// success

+		}

+		try {

+			testee.substitute(null, null, "");

+			fail();

+		} catch (IllegalArgumentException e) {

+			// success

+		}

+		try {

+			testee.substitute("", null, null);

+			fail();

+		} catch (IllegalArgumentException e) {

+			// success

+		}

+		try {

+			testee.substitute(null, "", null);

+			fail();

+		} catch (IllegalArgumentException e) {

+			// success

+		}

+	}

+

+	public void testSubstitute_substitutionNotFound() throws Exception {

+		testee = new Configuration();

+

+		String source = "Source";

+		String result = testee.substitute(source, "fubar", "blah");

+

+		assertSame("Nothing substituted", source, result);

+	}

+

+	public void testSubstitute_success() throws Exception {

+		testee = new Configuration();

+

+		String source = "Source";

+		String result = testee.substitute(source, "ourc", "af");

+

+		assertEquals("Substituted", "Safe", result);

+	}

+

+	// --------------------------------------------------------------------------

+

+	public void testSubstituteVariables_nullInput() throws Exception {

+		testee = new Configuration();

+

+		try {

+			testee.substituteVariables(null);

+			fail();

+		} catch (IllegalArgumentException e) {

+			// success

+		}

+	}

+

+	final String INSTALL_LOCATION = "/install/location";

+	final String USER_LOCATION = "/user/location";

+	final String WORKSPACE_LOCATION = "/workspace/location";

+

+	Configuration substitutionTestee = new Configuration() {

+		@Override

+		public String installLocation() {

+			return INSTALL_LOCATION;

+		}

+

+		@Override

+		public String userLocation() {

+			return USER_LOCATION;

+		}

+

+		@Override

+		public String workspaceLocation() {

+			return WORKSPACE_LOCATION;

+		}

+	};

+

+	public void testSubstituteVariables_InstallDir() throws Exception {

+		String result = substitutionTestee.substituteVariables("some ${install_location} string");

+		assertTrue("Found ${install_location}", result.indexOf(INSTALL_LOCATION) > 0);

+	}

+

+	public void testSubstituteVariables_UserDir() throws Exception {

+		String result = substitutionTestee.substituteVariables("some ${user_location} string");

+		assertTrue("Found ${user_location}", result.indexOf(USER_LOCATION) > 0);

+	}

+

+	public void testSubstituteVariables_WorkspaceDir() throws Exception {

+		String result = substitutionTestee.substituteVariables("some ${workspace_location} string");

+		assertTrue("Found ${workspace_location}", result.indexOf(WORKSPACE_LOCATION) > 0);

+	}

+

+}