You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2012/12/12 15:58:42 UTC

svn commit: r1420723 [8/12] - in /uima/sandbox/trunk/uimaFIT: ./ src/ src/main/ src/main/assembly/ src/main/java/ src/main/java/org/ src/main/java/org/uimafit/ src/main/java/org/uimafit/component/ src/main/java/org/uimafit/component/initialize/ src/mai...

Added: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/initialize/ConfigurationParameterInitializerTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/initialize/ConfigurationParameterInitializerTest.java?rev=1420723&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/initialize/ConfigurationParameterInitializerTest.java (added)
+++ uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/initialize/ConfigurationParameterInitializerTest.java Wed Dec 12 14:58:37 2012
@@ -0,0 +1,485 @@
+/*
+ Copyright 2009-2010	Regents of the University of Colorado.
+ All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+package org.uimafit.component.initialize;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static java.util.Arrays.asList;
+
+import java.awt.Point;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Locale;
+
+import org.apache.uima.UIMAException;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.UimaContext;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.metadata.impl.ConfigurationParameterSettings_impl;
+import org.junit.Test;
+import org.uimafit.ComponentTestBase;
+import org.uimafit.component.JCasAnnotator_ImplBase;
+import org.uimafit.descriptor.ConfigurationParameter;
+import org.uimafit.factory.AnalysisEngineFactory;
+import org.uimafit.factory.testAes.Annotator1;
+import org.uimafit.factory.testAes.ParameterizedAE;
+import org.uimafit.factory.testAes.ParameterizedAE.EnumValue;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Philip Ogren
+ */
+
+public class ConfigurationParameterInitializerTest extends ComponentTestBase {
+
+	@Test
+	public void testInitialize() throws ResourceInitializationException, SecurityException {
+
+		ResourceInitializationException rie = null;
+		try {
+			AnalysisEngineFactory.createPrimitive(ParameterizedAE.class, typeSystemDescription);
+		}
+		catch (ResourceInitializationException e) {
+			rie = e;
+		}
+		assertNotNull(rie);
+		AnalysisEngine engine = AnalysisEngineFactory.createPrimitive(ParameterizedAE.class,
+				typeSystemDescription,
+				ParameterizedAE.PARAM_FLOAT_3, 1.234f,
+				ParameterizedAE.PARAM_FLOAT_6, new Float[] { 1.234f, 0.001f },
+				"file2", "foo/bar",
+				"files9", new File[] { new File("test/data/file"), new File("test/data/file2") } );
+				// Test initializing a multi-valued parameter with a single value
+				// This is supposed to be fixed as part of issue #79
+				// -- REC 2011-05-02
+//				ParameterizedAE.PARAM_STRING_9, "singleelementarray");
+
+		ParameterizedAE component = new ParameterizedAE();
+		component.initialize(engine.getUimaContext());
+		assertEquals("pineapple", component.getString1());
+		assertArrayEquals(new String[] { "coconut", "mango" }, component.getString2());
+		assertEquals(null, component.getString3());
+		assertArrayEquals(new String[] { "apple" }, component.getString4());
+		assertArrayEquals(new String[] { "" }, component.getString5());
+		assertEquals(3, component.getStrings6().size());
+		assertTrue(component.getStrings6().contains("kiwi fruit"));
+		assertTrue(component.getStrings6().contains("grape"));
+		assertTrue(component.getStrings6().contains("pear"));
+		assertNull(component.getStrings7());
+		assertEquals(1, component.getStrings8().size());
+		assertTrue(component.getStrings8().contains("cherry"));
+//		assertTrue(component.getStrings9().contains("singleelementarray"));
+
+		assertFalse(component.isBoolean1());
+
+		NullPointerException npe = null;
+		try {
+			assertFalse(component.isBoolean2());
+		}
+		catch (NullPointerException e) {
+			npe = e;
+		}
+		assertNotNull(npe);
+
+		assertFalse(component.isBoolean2b());
+
+		assertTrue(component.getBoolean3()[0]);
+		assertTrue(component.getBoolean3()[1]);
+		assertFalse(component.getBoolean3()[2]);
+		assertTrue(component.boolean4[0]);
+		assertFalse(component.boolean4[1]);
+		assertTrue(component.boolean4[2]);
+		assertFalse(component.getBoolean5()[0]);
+		assertEquals(4, component.getBooleans6().size());
+		assertTrue(component.getBooleans6().get(0));
+		assertTrue(component.getBooleans6().get(1));
+		assertTrue(component.getBooleans6().get(2));
+		assertFalse(component.getBooleans6().get(3));
+
+		assertEquals(0, component.getInt1());
+		assertEquals(42, component.getInt2());
+		assertEquals(42, component.getInt3()[0]);
+		assertEquals(111, component.getInt3()[1]);
+		assertEquals(Integer.valueOf(2), component.getInt4()[0]);
+		assertEquals(1, component.getInts5().size());
+		assertEquals(2, component.getInts5().get(0).intValue());
+		assertEquals(5, component.getInts6().size());
+		assertEquals(1, component.getInts6().get(0).intValue());
+		assertEquals(2, component.getInts6().get(1).intValue());
+		assertEquals(3, component.getInts6().get(2).intValue());
+		assertEquals(4, component.getInts6().get(3).intValue());
+		assertEquals(5, component.getInts6().get(4).intValue());
+
+		assertEquals(0.0f, component.getFloat1(), 0.001f);
+		assertEquals(3.1415f, component.getFloat2(), 0.001f);
+		assertEquals(1.234f, component.getFloat3(), 0.001f);
+		assertNull(component.getFloat4());
+		assertEquals(0f, component.getFloat5()[0], 0.001f);
+		assertEquals(3.1415f, component.getFloat5()[1], 0.001f);
+		assertEquals(2.7182818f, component.getFloat5()[2], 0.001f);
+		assertEquals(1.234f, component.getFloat6()[0], 0.001f);
+		assertEquals(0.001f, component.getFloat6()[1], 0.001f);
+		assertEquals(1.1111f, component.getFloat7()[0], 0.001f);
+		assertEquals(2.2222f, component.getFloat7()[1], 0.001f);
+		assertEquals(3.3333f, component.getFloat7()[2], 0.001f);
+
+		assertEquals(EnumValue.ENUM_1, component.getEnum1());
+		assertArrayEquals(new EnumValue[] { EnumValue.ENUM_1, EnumValue.ENUM_2 }, component.getEnum2());
+		assertEquals(asList( EnumValue.ENUM_1, EnumValue.ENUM_2 ), component.getEnum3());
+		assertEquals(new File("test/data/file"), component.getFile1());
+		assertEquals(new File("test/data/file"), component.getFile1b());
+		assertEquals(new File("foo/bar"), component.getFile2());
+		assertNull(component.getFiles3());
+		assertArrayEquals(new File[] { new File("test/data/file") }, component.getFiles4());
+		assertArrayEquals(new File[] { new File("test/data/file"), new File("test/data/file2") },
+				component.getFiles5());
+		assertNull(component.getFiles6());
+		assertEquals(1, component.getFiles7().size());
+		assertEquals(new File("test/data/file"), component.getFiles7().get(0));
+		assertEquals(2, component.getFiles8().size());
+		assertEquals(new File("test/data/file"), component.getFiles8().get(0));
+		assertEquals(new File("test/data/file2"), component.getFiles8().get(1));
+		assertEquals(2, component.getFiles9().size());
+		assertEquals(new File("test/data/file"), component.getFiles9().get(0));
+		assertEquals(new File("test/data/file2"), component.getFiles9().get(1));
+
+		engine = AnalysisEngineFactory.createPrimitive(ParameterizedAE.class,
+				typeSystemDescription, ParameterizedAE.PARAM_FLOAT_3, 1.234f,
+				ParameterizedAE.PARAM_FLOAT_6, new Float[] { 1.234f, 0.001f },
+				ParameterizedAE.PARAM_STRING_1, "lime", ParameterizedAE.PARAM_STRING_2,
+				new String[] { "banana", "strawberry" }, ParameterizedAE.PARAM_STRING_3, "cherry",
+				ParameterizedAE.PARAM_STRING_4, new String[] { "raspberry", "blueberry",
+						"blackberry" }, ParameterizedAE.PARAM_STRING_5, new String[] { "a" },
+				ParameterizedAE.PARAM_BOOLEAN_1, true, ParameterizedAE.PARAM_BOOLEAN_2, true,
+				ParameterizedAE.PARAM_BOOLEAN_3, new boolean[] { true, true, false },
+				ParameterizedAE.PARAM_BOOLEAN_4, new Boolean[] { true, false, false },
+				ParameterizedAE.PARAM_BOOLEAN_5, new Boolean[] { true },
+				ParameterizedAE.PARAM_INT_1, 0, ParameterizedAE.PARAM_INT_2, 24,
+				ParameterizedAE.PARAM_INT_3, new int[] { 5 }, "file1", "foo1/bar1", "file1b",
+				"foo1b/bar1b", "file2", "foo2/bar2", "files3", new String[] {
+						"C:\\Documents and Settings\\Philip\\My Documents\\", "/usr/local/bin" },
+				"files4", new String[0], "files5", new String[] { "foos/bars" }, "files6",
+				new String[] { "C:\\Documents and Settings\\Philip\\My Documents\\",
+						"/usr/local/bin" }, "files7", new String[0], "files8",
+				new String[] { "foos/bars" }, "files9", Arrays.asList(new File("test/data/file"), 
+						new File("test/data/file2")));
+		component = new ParameterizedAE();
+		component.initialize(engine.getUimaContext());
+		assertEquals("lime", component.getString1());
+		assertArrayEquals(new String[] { "banana", "strawberry" }, component.getString2());
+		assertEquals("cherry", component.getString3());
+		assertArrayEquals(new String[] { "raspberry", "blueberry", "blackberry" },
+				component.getString4());
+		assertArrayEquals(new String[] { "a" }, component.getString5());
+		assertTrue(component.isBoolean1());
+		assertTrue(component.isBoolean2());
+		assertTrue(component.getBoolean3()[0]);
+		assertTrue(component.getBoolean3()[1]);
+		assertFalse(component.getBoolean3()[2]);
+		assertTrue(component.boolean4[0]);
+		assertFalse(component.boolean4[1]);
+		assertFalse(component.boolean4[2]);
+		assertTrue(component.getBoolean5()[0]);
+		assertEquals(0, component.getInt1());
+		assertEquals(24, component.getInt2());
+		assertEquals(5, component.getInt3()[0]);
+
+		assertEquals(new File("foo1/bar1"), component.getFile1());
+		assertEquals(new File("foo1b/bar1b"), component.getFile1b());
+		assertEquals(new File("foo2/bar2"), component.getFile2());
+		assertArrayEquals(new File[] {
+				new File("C:\\Documents and Settings\\Philip\\My Documents\\"),
+				new File("/usr/local/bin") }, component.getFiles3());
+		assertEquals(0, component.getFiles4().length);
+		assertArrayEquals(new File[] { new File("foos/bars") }, component.getFiles5());
+		assertEquals(2, component.getFiles6().size());
+		assertEquals(new File("C:\\Documents and Settings\\Philip\\My Documents\\"), component
+				.getFiles6().get(0));
+		assertEquals(new File("/usr/local/bin"), component.getFiles6().get(1));
+		assertEquals(0, component.getFiles7().size());
+		assertEquals(1, component.getFiles8().size());
+		assertEquals(new File("foos/bars"), component.getFiles8().get(0));
+		assertEquals(2, component.getFiles9().size());
+		assertEquals(new File("test/data/file"), component.getFiles9().get(0));
+		assertEquals(new File("test/data/file2"), component.getFiles9().get(1));
+
+		engine = AnalysisEngineFactory.createPrimitive(ParameterizedAE.class,
+				typeSystemDescription, ParameterizedAE.PARAM_FLOAT_3, 1.234f,
+				ParameterizedAE.PARAM_FLOAT_6, new Float[] { 1.234f, 0.001f },
+				ParameterizedAE.PARAM_BOOLEAN_1, true, ParameterizedAE.PARAM_BOOLEAN_3,
+				new boolean[3], ParameterizedAE.PARAM_FLOAT_5, new float[] { 1.2f, 3.4f }, "file2",
+				"foo2/bar2");
+		component = new ParameterizedAE();
+		component.initialize(engine.getUimaContext());
+		assertFalse(component.getBoolean3()[0]);
+		assertFalse(component.getBoolean3()[1]);
+		assertFalse(component.getBoolean3()[2]);
+		assertEquals(component.getFloat5()[0], 1.2f, 0.001f);
+		assertEquals(component.getFloat5()[1], 3.4f, 0.001f);
+
+		rie = null;
+		try {
+			engine = AnalysisEngineFactory.createPrimitive(ParameterizedAE.class,
+					typeSystemDescription, ParameterizedAE.PARAM_FLOAT_3, 1.234f,
+					ParameterizedAE.PARAM_FLOAT_6, new Float[] { 1.234f, 0.001f },
+					ParameterizedAE.PARAM_STRING_1, true);
+		}
+		catch (ResourceInitializationException e) {
+			rie = e;
+		}
+		assertNotNull(rie);
+
+	}
+
+	@Test
+	public void testInitialize2() throws ResourceInitializationException {
+		AnalysisEngine engine = AnalysisEngineFactory.createPrimitive(Annotator1.class,
+				typeSystemDescription);
+		assertEquals(1, engine.getAnalysisEngineMetaData().getCapabilities().length);
+	}
+
+	@Test
+	public void testInitialize3() throws FileNotFoundException, IOException, UIMAException {
+		// here we test an optional parameter that is missing from the
+		// configuration to ensure that it is filled in with the default value
+		AnalysisEngine aed = AnalysisEngineFactory
+				.createAnalysisEngineFromPath("src/test/resources/data/descriptor/DefaultValueAE1.xml");
+		DefaultValueAE1 ae = new DefaultValueAE1();
+		ae.initialize(aed.getUimaContext());
+		assertEquals("green", ae.color);
+
+		// here we test a mandatory parameter that is missing from the
+		// configuration and ensure that an exception is thrown because
+		// no default value is given in the configuration parameter annotation.
+		ResourceInitializationException rie = null;
+		try {
+			aed = AnalysisEngineFactory
+					.createAnalysisEngineFromPath("src/test/resources/data/descriptor/DefaultValueAE2.xml");
+		}
+		catch (ResourceInitializationException e) {
+			rie = e;
+		}
+		assertNotNull(rie);
+	}
+
+	/**
+	 * If a parameter value is set to null, that is as good as if it was not set at all. If a
+	 * default value is specified, it should be used.
+	 */
+	@Test
+	public void testParameterSetToNull() throws Exception {
+		String paramColor = DefaultValueAE1.class.getName() + ".color";
+		AnalysisEngine aed = AnalysisEngineFactory.createPrimitive(DefaultValueAE1.class, null,
+				paramColor, null);
+		DefaultValueAE1 ae = new DefaultValueAE1();
+		ae.initialize(aed.getUimaContext());
+		assertEquals("green", ae.color);
+	}
+
+	/**
+	 * If a parameter value is set to null, that is as good as if it was not set at all. If it is
+	 * mandatory, an exception has to be thrown.
+	 */
+	@Test(expected = ResourceInitializationException.class)
+	public void testMandatoryParameterSetToNull() throws Exception {
+		String paramColor = DefaultValueAE2.class.getName() + ".color";
+		AnalysisEngine aed = AnalysisEngineFactory.createPrimitive(DefaultValueAE2.class, null,
+				paramColor, null);
+		DefaultValueAE2 ae = new DefaultValueAE2();
+		ae.initialize(aed.getUimaContext());
+
+	}
+
+	/**
+	 * Test that a parameter not supported by UIMA produces an error.
+	 */
+	@Test(expected = IllegalArgumentException.class)
+	public void testNonUimaCompatibleParameterValue() throws Exception {
+		String paramColor = DefaultValueAE2.class.getName() + ".color";
+		AnalysisEngine aed = AnalysisEngineFactory.createPrimitive(DefaultValueAE2.class, null,
+				paramColor, new Point(1, 2));
+		DefaultValueAE2 ae = new DefaultValueAE2();
+		ae.initialize(aed.getUimaContext());
+	}
+
+	/**
+	 * Check that an Analysis Engine created from a descriptor declaring optional parameters but not
+	 * setting them actually uses the default values declared in the Java annotation
+	 */
+	@Test
+	public void testUnsetOptionalParameter() throws Exception {
+		AnalysisEngineDescription aed = AnalysisEngineFactory.createPrimitiveDescription(
+				DefaultValueAE1.class, (Object[]) null);
+		// Remove the settings from the descriptor, but leave the declarations.
+		// The settings are already filled with default values by createPrimitiveDescription,
+		// but here we want to simulate loading a descriptor without settings from a file.
+		// The file of course would declare the parameters optional and thus the settings
+		// for the optional parameters would be empty. We expect that a default value from the
+		// annotation is used in this case.
+		aed.getMetaData().setConfigurationParameterSettings(
+				new ConfigurationParameterSettings_impl());
+		AnalysisEngine template = UIMAFramework.produceAnalysisEngine(aed);
+		DefaultValueAE1 ae = new DefaultValueAE1();
+		ae.initialize(template.getUimaContext());
+		assertEquals("green", ae.color);
+	}
+
+	public static class DefaultValueAE1 extends JCasAnnotator_ImplBase {
+		@ConfigurationParameter(defaultValue = "green")
+		private String color;
+
+		@Override
+		public void initialize(UimaContext aContext) throws ResourceInitializationException {
+			super.initialize(aContext);
+		}
+
+		@Override
+		public void process(JCas aJCas) throws AnalysisEngineProcessException {
+			/* do nothing */
+		}
+
+	}
+
+	public static class DefaultValueAE2 extends JCasAnnotator_ImplBase {
+		@SuppressWarnings("unused")
+		@ConfigurationParameter(mandatory = true)
+		private String color;
+
+		@Override
+		public void initialize(UimaContext aContext) throws ResourceInitializationException {
+			super.initialize(aContext);
+		}
+
+		@Override
+		public void process(JCas aJCas) throws AnalysisEngineProcessException {
+			/* do nothing */
+		}
+
+	}
+
+	@Test
+	public void testEnumDefaultValue() throws Exception {
+		try {
+			AnalysisEngine aed = AnalysisEngineFactory.createPrimitive(DefaultEnumValueAE.class,
+					(Object[]) null);
+			DefaultEnumValueAE ae = new DefaultEnumValueAE();
+			ae.initialize(aed.getUimaContext());
+			assertEquals(Color.GREEN, ae.color);
+		}
+		catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	public static enum Color {
+		RED, GREEN, BLUE
+	}
+
+	public static class DefaultEnumValueAE extends JCasAnnotator_ImplBase {
+		@ConfigurationParameter(defaultValue = "GREEN")
+		private Color color;
+
+		@Override
+		public void initialize(UimaContext aContext) throws ResourceInitializationException {
+			super.initialize(aContext);
+		}
+
+		@Override
+		public void process(JCas aJCas) throws AnalysisEngineProcessException {
+			/* do nothing */
+		}
+	}
+
+	public static class DefaultLocaleValueAE extends JCasAnnotator_ImplBase {
+		@ConfigurationParameter(name = "L1", defaultValue = "US")
+		public Locale locale1;
+
+		@ConfigurationParameter(name = "L2")
+		public Locale locale2;
+
+		@ConfigurationParameter(name = "L3")
+		public Locale locale3;
+
+		@ConfigurationParameter(name = "L4")
+		public Locale locale4;
+
+		@Override
+		public void process(JCas aJCas) throws AnalysisEngineProcessException {
+			/* do nothing */
+		}
+	}
+
+	@Test
+	public void testLocaleParams() throws Exception {
+		AnalysisEngine aed = AnalysisEngineFactory.createPrimitive(DefaultLocaleValueAE.class,
+				"L2", "en-CA", "L3", "CANADA_FRENCH", "L4", "zh");
+		DefaultLocaleValueAE ae = new DefaultLocaleValueAE();
+		ae.initialize(aed.getUimaContext());
+		assertEquals(Locale.US, ae.locale1);
+		assertEquals(new Locale("en", "CA"), ae.locale2);
+		assertEquals(Locale.CANADA_FRENCH, ae.locale3);
+		assertEquals(new Locale("zh"), ae.locale4);
+
+		aed = AnalysisEngineFactory.createPrimitive(DefaultLocaleValueAE.class, "L1",
+				"es-ES-Traditional_WIN", "L2", "CHINA", "L3", "es", "L4", "en-CA");
+		ae = new DefaultLocaleValueAE();
+		ae.initialize(aed.getUimaContext());
+		assertEquals(new Locale("es", "ES", "Traditional_WIN"), ae.locale1);
+		assertEquals(Locale.CHINA, ae.locale2);
+		assertEquals(new Locale("es"), ae.locale3);
+		assertEquals(new Locale("en", "CA"), ae.locale4);
+
+		aed = AnalysisEngineFactory.createPrimitive(DefaultLocaleValueAE.class, "L1", "", "L2", "",
+				"L3", null);
+		ae = new DefaultLocaleValueAE();
+		ae.initialize(aed.getUimaContext());
+		assertEquals(Locale.getDefault(), ae.locale1);
+		assertEquals(Locale.getDefault(), ae.locale2);
+		assertEquals(null, ae.locale3);
+		assertEquals(null, ae.locale4);
+
+	}
+
+	/**
+	 * This main method creates the descriptor files used in testInitialize3. If I weren't lazy I
+	 * would figure out how to programmatically remove the configuration parameter corresponding to
+	 * 'color'. As it is, however, the parameter must be manually removed (I used the Component
+	 * Descriptor Editor to do this.) This point is moot anyways because I am checking in the
+	 * generated descriptor files and there is no reason to run this main method in the future.
+	 */
+	public static void main(String[] args) throws ResourceInitializationException,
+			FileNotFoundException, SAXException, IOException {
+		AnalysisEngineDescription aed = AnalysisEngineFactory.createPrimitiveDescription(
+				DefaultValueAE1.class, (Object[]) null);
+		aed.toXML(new FileOutputStream("src/test/resources/data/descriptor/DefaultValueAE1.xml"));
+		aed = AnalysisEngineFactory.createPrimitiveDescription(DefaultValueAE2.class,
+				(Object[]) null);
+		aed.toXML(new FileOutputStream("src/test/resources/data/descriptor/DefaultValueAE2.xml"));
+	}
+
+}

Propchange: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/initialize/ConfigurationParameterInitializerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/xwriter/CASDumpWriterTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/xwriter/CASDumpWriterTest.java?rev=1420723&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/xwriter/CASDumpWriterTest.java (added)
+++ uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/xwriter/CASDumpWriterTest.java Wed Dec 12 14:58:37 2012
@@ -0,0 +1,61 @@
+/*
+ Copyright 2010
+ Ubiquitous Knowledge Processing (UKP) Lab
+ Technische Universitaet Darmstadt
+ All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+package org.uimafit.component.xwriter;
+
+import static org.apache.commons.io.FileUtils.readFileToString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.jcas.JCas;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.uimafit.factory.AnalysisEngineFactory;
+import org.uimafit.factory.JCasFactory;
+
+/**
+ * @author Richard Eckart de Castilho
+ */
+public class CASDumpWriterTest {
+
+	@Rule
+	public TemporaryFolder folder = new TemporaryFolder();
+
+	@Test
+	public void testXWriter() throws Exception {
+		File outputFile = new File(folder.getRoot(), "dump-output.txt");
+
+		AnalysisEngine writer = AnalysisEngineFactory.createPrimitive(CASDumpWriter.class,
+				CASDumpWriter.PARAM_OUTPUT_FILE, outputFile.getPath());
+		JCas jcas = writer.newJCas();
+		JCasFactory.loadJCas(jcas, "src/test/resources/data/docs/test.xmi");
+		writer.process(jcas);
+		assertTrue(outputFile.exists());
+
+		String reference = readFileToString(
+				new File("src/test/resources/data/reference/test.xmi.dump"), "UTF-8").trim();
+		String actual = readFileToString(outputFile, "UTF-8").trim();
+		actual = actual.replaceAll("\r\n", "\n");
+
+		assertEquals(reference, actual);
+	}
+}

Propchange: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/xwriter/CASDumpWriterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/xwriter/XWriterTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/xwriter/XWriterTest.java?rev=1420723&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/xwriter/XWriterTest.java (added)
+++ uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/xwriter/XWriterTest.java Wed Dec 12 14:58:37 2012
@@ -0,0 +1,189 @@
+/* 
+   Copyright 2010 Regents of the University of Colorado.  
+ All rights reserved. 
+
+ Licensed under the Apache License, Version 2.0 (the "License"); 
+ you may not use this file except in compliance with the License. 
+ You may obtain a copy of the License at 
+
+ http://www.apache.org/licenses/LICENSE-2.0 
+
+ Unless required by applicable law or agreed to in writing, software 
+ distributed under the License is distributed on an "AS IS" BASIS, 
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ See the License for the specific language governing permissions and 
+ limitations under the License.
+ */
+package org.uimafit.component.xwriter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import org.apache.uima.UIMAException;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.FileUtils;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.uimafit.ComponentTestBase;
+import org.uimafit.factory.AggregateBuilder;
+import org.uimafit.factory.AnalysisEngineFactory;
+import org.uimafit.factory.JCasFactory;
+import org.uimafit.factory.testAes.Annotator1;
+import org.uimafit.factory.testAes.Annotator2;
+import org.uimafit.factory.testAes.Annotator3;
+import org.uimafit.factory.testAes.ViewNames;
+
+/**
+ * @author Philip Ogren
+ */
+public class XWriterTest extends ComponentTestBase {
+
+	@Rule
+	public TemporaryFolder folder = new TemporaryFolder();
+
+	private File outputDirectory;
+
+	@Before
+	public void setup() {
+		outputDirectory = folder.newFolder("test/xmi-output");
+	}
+
+	@Test
+	public void testXWriter() throws Exception {
+		addDataToCas();
+
+		AnalysisEngine xWriter = AnalysisEngineFactory.createPrimitive(XWriter.class,
+				typeSystemDescription, XWriter.PARAM_OUTPUT_DIRECTORY_NAME,
+				outputDirectory.getPath());
+
+		xWriter.process(jCas);
+
+		File xmiFile = new File(outputDirectory, "1.xmi");
+		assertTrue(xmiFile.exists());
+
+		jCas.reset();
+		JCasFactory.loadJCas(jCas, xmiFile.getPath());
+		assertEquals("Anyone up for a game of Foosball?", jCas.getDocumentText());
+		assertEquals("Any(o)n(e) (u)p f(o)r (a) g(a)m(e) (o)f F(oo)sb(a)ll?", jCas.getView("A")
+				.getDocumentText());
+		assertEquals("?AFaaabeeffgllmnnoooooprsuy", jCas.getView("B").getDocumentText());
+		assertEquals("(((((((((())))))))))?AFaaabeeffgllmnnoooooprsuy", jCas.getView("C")
+				.getDocumentText());
+		assertEquals("yusrpooooonnmllgffeebaaaFA?", jCas.getView(ViewNames.REVERSE_VIEW)
+				.getDocumentText());
+
+		jCas.reset();
+		addDataToCas();
+
+		xWriter = AnalysisEngineFactory.createPrimitive(XWriter.class, typeSystemDescription,
+				XWriter.PARAM_OUTPUT_DIRECTORY_NAME, outputDirectory.getPath(),
+				IntegerFileNamer.PARAM_PREFIX, "myprefix-");
+
+		xWriter.process(jCas);
+
+		xmiFile = new File(outputDirectory, "myprefix-1.xmi");
+		assertTrue(xmiFile.exists());
+
+	}
+
+	private void addDataToCas() throws UIMAException {
+		tokenBuilder.buildTokens(jCas, "Anyone up for a game of Foosball?");
+
+		AggregateBuilder builder = new AggregateBuilder();
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(Annotator1.class,
+				typeSystemDescription), ViewNames.PARENTHESES_VIEW, "A");
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(Annotator2.class,
+				typeSystemDescription), ViewNames.SORTED_VIEW, "B",
+				ViewNames.SORTED_PARENTHESES_VIEW, "C", ViewNames.PARENTHESES_VIEW, "A");
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(Annotator3.class,
+				typeSystemDescription), ViewNames.INITIAL_VIEW, "B");
+		AnalysisEngine aggregateEngine = builder.createAggregate();
+
+		aggregateEngine.process(jCas);
+	}
+
+	@Test
+	public void testXmi() throws Exception {
+		AnalysisEngine engine = AnalysisEngineFactory.createPrimitive(XWriter.class,
+				typeSystemDescription, XWriter.PARAM_OUTPUT_DIRECTORY_NAME,
+				this.outputDirectory.getPath());
+		tokenBuilder.buildTokens(jCas, "I like\nspam!", "I like spam !", "PRP VB NN .");
+		engine.process(jCas);
+		engine.collectionProcessComplete();
+
+		File outputFile = new File(this.outputDirectory, "1.xmi");
+
+		SAXBuilder builder = new SAXBuilder();
+		builder.setDTDHandler(null);
+		Element root = null;
+		try {
+			Document doc = builder.build(new StringReader(FileUtils.file2String(outputFile)));
+			root = doc.getRootElement();
+		}
+		catch (JDOMException e) {
+			throw new AnalysisEngineProcessException(e);
+		}
+		catch (IOException e) {
+			throw new AnalysisEngineProcessException(e);
+		}
+
+		List<?> elements = root.getChildren("Sentence", root.getNamespace("type"));
+		Assert.assertEquals(1, elements.size());
+		elements = root.getChildren("Token", root.getNamespace("type"));
+		Assert.assertEquals(4, elements.size());
+
+	}
+
+	@Test
+	public void testXcas() throws Exception {
+		AnalysisEngine engine = AnalysisEngineFactory.createPrimitive(XWriter.class,
+				typeSystemDescription, XWriter.PARAM_OUTPUT_DIRECTORY_NAME,
+				this.outputDirectory.getPath(), XWriter.PARAM_XML_SCHEME_NAME, XWriter.XCAS);
+		tokenBuilder.buildTokens(jCas, "I like\nspam!", "I like spam !", "PRP VB NN .");
+		engine.process(jCas);
+		engine.collectionProcessComplete();
+
+		File outputFile = new File(this.outputDirectory, "1.xcas");
+
+		SAXBuilder builder = new SAXBuilder();
+		builder.setDTDHandler(null);
+		Element root = null;
+		try {
+			Document doc = builder.build(new StringReader(FileUtils.file2String(outputFile)));
+			root = doc.getRootElement();
+		}
+		catch (JDOMException e) {
+			throw new AnalysisEngineProcessException(e);
+		}
+		catch (IOException e) {
+			throw new AnalysisEngineProcessException(e);
+		}
+
+		List<?> elements = root.getChildren("org.uimafit.type.Sentence");
+		Assert.assertEquals(1, elements.size());
+		elements = root.getChildren("org.uimafit.type.Token");
+		Assert.assertEquals(4, elements.size());
+
+	}
+
+	@Test(expected = ResourceInitializationException.class)
+	public void testBadXmlSchemeName() throws ResourceInitializationException {
+		AnalysisEngineFactory.createPrimitive(XWriter.class, typeSystemDescription,
+				XWriter.PARAM_XML_SCHEME_NAME, "xcas");
+	}
+
+}

Propchange: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/component/xwriter/XWriterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/data/CreateSampleXCASFile.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/data/CreateSampleXCASFile.java?rev=1420723&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/data/CreateSampleXCASFile.java (added)
+++ uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/data/CreateSampleXCASFile.java Wed Dec 12 14:58:37 2012
@@ -0,0 +1,58 @@
+/* 
+ Copyright 2009-2010	Regents of the University of Colorado.  
+ All rights reserved. 
+
+ Licensed under the Apache License, Version 2.0 (the "License"); 
+ you may not use this file except in compliance with the License. 
+ You may obtain a copy of the License at 
+
+ http://www.apache.org/licenses/LICENSE-2.0 
+
+ Unless required by applicable law or agreed to in writing, software 
+ distributed under the License is distributed on an "AS IS" BASIS, 
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ See the License for the specific language governing permissions and 
+ limitations under the License.
+ */
+package org.uimafit.data;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.uima.UIMAException;
+import org.apache.uima.cas.impl.XCASSerializer;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.util.XMLSerializer;
+import org.uimafit.factory.JCasFactory;
+import org.uimafit.testing.factory.TokenBuilder;
+import org.uimafit.type.Sentence;
+import org.uimafit.type.Token;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Steven Bethard, Philip Ogren
+ */
+
+public class CreateSampleXCASFile {
+
+	public static void main(String[] args) throws UIMAException, SAXException, IOException {
+		TokenBuilder<Token, Sentence> tokenBuilder = new TokenBuilder<Token, Sentence>(Token.class,
+				Sentence.class, "pos", "stem");
+		JCas jCas = JCasFactory.createJCas();
+		// quote from http://www.gutenberg.org/files/20417/20417-h/20417-h.htm
+		String text = "... the more knowledge advances the more it becomes possible to condense it into little books.";
+		tokenBuilder
+				.buildTokens(
+						jCas,
+						text,
+						"... the more knowledge advances the more it becomes possible to condense it into little books . ",
+						". T M K A T M I B P T C I I L B .",
+						"... the more knowledge advance the more it become possible to condense it into little book . ");
+
+		FileOutputStream out = new FileOutputStream("src/test/resources/data/docs/test.xcas");
+		XCASSerializer ser = new XCASSerializer(jCas.getTypeSystem());
+		XMLSerializer xmlSer = new XMLSerializer(out, false);
+		ser.serialize(jCas.getCas(), xmlSer.getContentHandler());
+		out.close();
+	}
+}

Propchange: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/data/CreateSampleXCASFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/data/CreateSampleXMIFile.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/data/CreateSampleXMIFile.java?rev=1420723&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/data/CreateSampleXMIFile.java (added)
+++ uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/data/CreateSampleXMIFile.java Wed Dec 12 14:58:37 2012
@@ -0,0 +1,53 @@
+/* 
+ Copyright 2009-2010	Regents of the University of Colorado.  
+ All rights reserved. 
+
+ Licensed under the Apache License, Version 2.0 (the "License"); 
+ you may not use this file except in compliance with the License. 
+ You may obtain a copy of the License at 
+
+ http://www.apache.org/licenses/LICENSE-2.0 
+
+ Unless required by applicable law or agreed to in writing, software 
+ distributed under the License is distributed on an "AS IS" BASIS, 
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ See the License for the specific language governing permissions and 
+ limitations under the License.
+ */
+package org.uimafit.data;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.uima.UIMAException;
+import org.apache.uima.cas.impl.XmiCasSerializer;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.util.XMLSerializer;
+import org.uimafit.factory.JCasFactory;
+import org.uimafit.testing.factory.TokenBuilder;
+import org.uimafit.type.Sentence;
+import org.uimafit.type.Token;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Steven Bethard, Philip Ogren
+ */
+
+public class CreateSampleXMIFile {
+
+	public static void main(String[] args) throws UIMAException, SAXException, IOException {
+		TokenBuilder<Token, Sentence> tokenBuilder = new TokenBuilder<Token, Sentence>(Token.class,
+				Sentence.class, "pos", "stem");
+		JCas jCas = JCasFactory.createJCas();
+		String text = "Me and all my friends are non-conformists.";
+		tokenBuilder.buildTokens(jCas, text, "Me and all my friends are non - conformists .",
+				"M A A M F A N - C .", "me and all my friend are non - conformist .");
+
+		FileOutputStream out = new FileOutputStream("src/test/resources/data/docs/test.xmi");
+		XmiCasSerializer ser = new XmiCasSerializer(jCas.getTypeSystem());
+		XMLSerializer xmlSer = new XMLSerializer(out, false);
+		ser.serialize(jCas.getCas(), xmlSer.getContentHandler());
+		out.close();
+
+	}
+}

Propchange: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/data/CreateSampleXMIFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/descriptor/TypeCapabilityTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/descriptor/TypeCapabilityTest.java?rev=1420723&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/descriptor/TypeCapabilityTest.java (added)
+++ uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/descriptor/TypeCapabilityTest.java Wed Dec 12 14:58:37 2012
@@ -0,0 +1,57 @@
+/* 
+ Copyright 2010 Regents of the University of Colorado.  
+ All rights reserved. 
+
+ Licensed under the Apache License, Version 2.0 (the "License"); 
+ you may not use this file except in compliance with the License. 
+ You may obtain a copy of the License at 
+
+ http://www.apache.org/licenses/LICENSE-2.0 
+
+ Unless required by applicable law or agreed to in writing, software 
+ distributed under the License is distributed on an "AS IS" BASIS, 
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ See the License for the specific language governing permissions and 
+ limitations under the License.
+ */
+
+package org.uimafit.descriptor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.TypeOrFeature;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.metadata.Capability;
+import org.junit.Test;
+import org.uimafit.ComponentTestBase;
+import org.uimafit.factory.AnalysisEngineFactory;
+import org.uimafit.factory.testAes.Annotator4;
+
+/**
+ * @author Philip Ogren
+ */
+
+public class TypeCapabilityTest extends ComponentTestBase {
+
+	@Test
+	public void testTC() throws ResourceInitializationException {
+		AnalysisEngineDescription aed = AnalysisEngineFactory.createPrimitiveDescription(
+				Annotator4.class, typeSystemDescription);
+		Capability[] capabilities = aed.getAnalysisEngineMetaData().getCapabilities();
+		assertEquals(1, capabilities.length);
+		Capability capability = capabilities[0];
+		TypeOrFeature[] inputs = capability.getInputs();
+		assertEquals(1, inputs.length);
+		assertEquals("org.uimafit.type.Token", inputs[0].getName());
+		assertTrue(inputs[0].isType());
+
+		TypeOrFeature[] outputs = capability.getOutputs();
+		assertEquals(1, outputs.length);
+		assertEquals("org.uimafit.type.Token:pos", outputs[0].getName());
+		assertFalse(outputs[0].isType());
+
+	}
+}

Propchange: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/descriptor/TypeCapabilityTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AggregateBuilderTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AggregateBuilderTest.java?rev=1420723&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AggregateBuilderTest.java (added)
+++ uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AggregateBuilderTest.java Wed Dec 12 14:58:37 2012
@@ -0,0 +1,208 @@
+/* 
+  Copyright 2010 Regents of the University of Colorado.  
+ All rights reserved. 
+
+ Licensed under the Apache License, Version 2.0 (the "License"); 
+ you may not use this file except in compliance with the License. 
+ You may obtain a copy of the License at 
+
+ http://www.apache.org/licenses/LICENSE-2.0 
+
+ Unless required by applicable law or agreed to in writing, software 
+ distributed under the License is distributed on an "AS IS" BASIS, 
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ See the License for the specific language governing permissions and 
+ limitations under the License.
+ */
+
+package org.uimafit.factory;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.uima.UIMAException;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.flow.FlowControllerDescription;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.junit.Test;
+import org.uimafit.ComponentTestBase;
+import org.uimafit.component.NoOpAnnotator;
+import org.uimafit.factory.testAes.Annotator1;
+import org.uimafit.factory.testAes.Annotator2;
+import org.uimafit.factory.testAes.Annotator3;
+import org.uimafit.factory.testAes.FlowAE1;
+import org.uimafit.factory.testAes.FlowAE2;
+import org.uimafit.factory.testAes.FlowAE3;
+import org.uimafit.factory.testAes.ReversableTestFlowController;
+import org.uimafit.factory.testAes.ViewNames;
+import org.uimafit.pipeline.SimplePipeline;
+import org.uimafit.util.TypeSystemUtil;
+
+/**
+ * @author Philip Ogren
+ */
+public class AggregateBuilderTest extends ComponentTestBase {
+
+	@Test
+	public void testAggregateBuilder() throws UIMAException, IOException {
+		tokenBuilder.buildTokens(jCas, "Anyone up for a game of Foosball?");
+
+		AggregateBuilder builder = new AggregateBuilder();
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(Annotator1.class,
+				typeSystemDescription), ViewNames.PARENTHESES_VIEW, "A");
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(Annotator2.class,
+				typeSystemDescription), ViewNames.SORTED_VIEW, "B",
+				ViewNames.SORTED_PARENTHESES_VIEW, "C", ViewNames.PARENTHESES_VIEW, "A");
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(Annotator3.class,
+				typeSystemDescription), ViewNames.INITIAL_VIEW, "B");
+		AnalysisEngine aggregateEngine = builder.createAggregate();
+
+		aggregateEngine.process(jCas);
+
+		assertEquals("Anyone up for a game of Foosball?", jCas.getDocumentText());
+		assertEquals("Any(o)n(e) (u)p f(o)r (a) g(a)m(e) (o)f F(oo)sb(a)ll?", jCas.getView("A")
+				.getDocumentText());
+		assertEquals("?AFaaabeeffgllmnnoooooprsuy", jCas.getView("B").getDocumentText());
+		assertEquals("(((((((((())))))))))?AFaaabeeffgllmnnoooooprsuy", jCas.getView("C")
+				.getDocumentText());
+		assertEquals("yusrpooooonnmllgffeebaaaFA?", jCas.getView(ViewNames.REVERSE_VIEW)
+				.getDocumentText());
+
+		JCasFactory.loadJCas(jCas, "src/test/resources/data/docs/test.xmi");
+		AnalysisEngine ae1 = AnalysisEngineFactory.createPrimitive(NoOpAnnotator.class,
+				typeSystemDescription);
+
+		SimplePipeline.runPipeline(jCas, ae1, aggregateEngine);
+
+		AnalysisEngineDescription aggregateDescription = builder.createAggregateDescription();
+		builder = new AggregateBuilder();
+		builder.add(aggregateDescription);
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(Annotator1.class,
+				typeSystemDescription), ViewNames.PARENTHESES_VIEW, "PARENS");
+		aggregateEngine = builder.createAggregate();
+
+		jCas.reset();
+
+		tokenBuilder.buildTokens(jCas, "Anyone up for a game of Foosball?");
+
+		aggregateEngine.process(jCas);
+
+		assertEquals("Anyone up for a game of Foosball?", jCas.getDocumentText());
+		assertEquals("Any(o)n(e) (u)p f(o)r (a) g(a)m(e) (o)f F(oo)sb(a)ll?", jCas.getView("A")
+				.getDocumentText());
+		assertEquals("?AFaaabeeffgllmnnoooooprsuy", jCas.getView("B").getDocumentText());
+		assertEquals("(((((((((())))))))))?AFaaabeeffgllmnnoooooprsuy", jCas.getView("C")
+				.getDocumentText());
+		assertEquals("yusrpooooonnmllgffeebaaaFA?", jCas.getView(ViewNames.REVERSE_VIEW)
+				.getDocumentText());
+		assertEquals("Any(o)n(e) (u)p f(o)r (a) g(a)m(e) (o)f F(oo)sb(a)ll?", jCas
+				.getView("PARENS").getDocumentText());
+
+	}
+
+	@Test
+	public void testAggregateBuilder2() throws UIMAException {
+		tokenBuilder.buildTokens(jCas, "'Verb' is a noun!?");
+
+		AggregateBuilder builder = new AggregateBuilder();
+		String componentName1 = builder.add(AnalysisEngineFactory.createPrimitiveDescription(
+				Annotator1.class, typeSystemDescription));
+		String componentName2 = builder.add(AnalysisEngineFactory.createPrimitiveDescription(
+				Annotator1.class, typeSystemDescription));
+		String componentName3 = builder.add(AnalysisEngineFactory.createPrimitiveDescription(
+				Annotator1.class, typeSystemDescription));
+
+		assertEquals("org.uimafit.factory.testAes.Annotator1", componentName1);
+		assertEquals("org.uimafit.factory.testAes.Annotator1.2", componentName2);
+		assertEquals("org.uimafit.factory.testAes.Annotator1.3", componentName3);
+
+		builder.addSofaMapping(componentName1, ViewNames.PARENTHESES_VIEW, "A");
+		builder.addSofaMapping(componentName2, ViewNames.PARENTHESES_VIEW, "B");
+		builder.addSofaMapping(componentName3, ViewNames.PARENTHESES_VIEW, "C");
+		AnalysisEngineDescription aggregateEngineDescription = builder.createAggregateDescription();
+
+		AnalysisEngine aggregateEngine = AnalysisEngineFactory
+				.createAggregate(aggregateEngineDescription);
+
+		aggregateEngine.process(jCas);
+
+		assertEquals("'Verb' is a noun!?", jCas.getDocumentText());
+		assertEquals("'V(e)rb' (i)s (a) n(ou)n!?", jCas.getView("A").getDocumentText());
+		assertEquals("'V(e)rb' (i)s (a) n(ou)n!?", jCas.getView("B").getDocumentText());
+		assertEquals("'V(e)rb' (i)s (a) n(ou)n!?", jCas.getView("C").getDocumentText());
+
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void testOddNumberOfViewNames() throws ResourceInitializationException {
+		AggregateBuilder builder = new AggregateBuilder();
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(Annotator1.class,
+				typeSystemDescription), ViewNames.PARENTHESES_VIEW);
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void testDuplicateComponentNames() throws ResourceInitializationException {
+		AggregateBuilder builder = new AggregateBuilder();
+		builder.add("name", AnalysisEngineFactory.createPrimitiveDescription(Annotator1.class,
+				typeSystemDescription));
+		builder.add("name", AnalysisEngineFactory.createPrimitiveDescription(Annotator1.class,
+				typeSystemDescription));
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void testBadSofaMapping() {
+		AggregateBuilder builder = new AggregateBuilder();
+		builder.addSofaMapping("name", ViewNames.PARENTHESES_VIEW, "A");
+	}
+
+	@Test
+	public void testAggregateBuilderWithFlowController() throws UIMAException {
+		tokenBuilder.buildTokens(jCas, "An honest man can never surrender an honest doubt.");
+
+		AggregateBuilder builder = new AggregateBuilder();
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(FlowAE1.class,
+				typeSystemDescription));
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(FlowAE2.class,
+				typeSystemDescription));
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(FlowAE3.class,
+				typeSystemDescription));
+
+		FlowControllerDescription fcd = FlowControllerFactory
+				.createFlowControllerDescription(ReversableTestFlowController.class);
+		builder.setFlowControllerDescription(fcd);
+		AnalysisEngine aggregateEngine = builder.createAggregate();
+		aggregateEngine.process(jCas);
+
+		String text = "An honest man can never surrender an honest doubt.";
+		text = text.replaceAll("[aeiou]+", "($0)"); // this is what FlowAE1 does
+		text = FlowAE2.sort(text);
+		text = FlowAE3.reverse(text);
+
+		assertEquals(text, TypeSystemUtil.getAnalyzedText(jCas));
+		assertEquals("vuutttsssrrrrooonnnnnnnnmhheeeeeeddcbaaaA.)))))))))))))(((((((((((((",
+				TypeSystemUtil.getAnalyzedText(jCas));
+
+		fcd = FlowControllerFactory.createFlowControllerDescription(
+				ReversableTestFlowController.class,
+				ReversableTestFlowController.PARAM_REVERSE_ORDER, true);
+		builder.setFlowControllerDescription(fcd);
+		aggregateEngine = builder.createAggregate();
+
+		jCas.reset();
+		tokenBuilder.buildTokens(jCas, "An honest man can never surrender an honest doubt.");
+		aggregateEngine.process(jCas);
+
+		text = "An honest man can never surrender an honest doubt.";
+		text = FlowAE3.reverse(text);
+		text = FlowAE2.sort(text);
+		text = text.replaceAll("[aeiou]+", "($0)"); // this is what FlowAE1 does
+
+		assertEquals(text, TypeSystemUtil.getAnalyzedText(jCas));
+		assertEquals(".A(aaa)bcdd(eeeeee)hhmnnnnnnnn(ooo)rrrrsssttt(uu)v",
+				TypeSystemUtil.getAnalyzedText(jCas));
+
+	}
+
+}

Propchange: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AggregateBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AggregateWithReaderTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AggregateWithReaderTest.java?rev=1420723&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AggregateWithReaderTest.java (added)
+++ uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AggregateWithReaderTest.java Wed Dec 12 14:58:37 2012
@@ -0,0 +1,195 @@
+/* 
+  Copyright 2010 Regents of the University of Colorado.  
+ All rights reserved. 
+
+ Licensed under the Apache License, Version 2.0 (the "License"); 
+ you may not use this file except in compliance with the License. 
+ You may obtain a copy of the License at 
+
+ http://www.apache.org/licenses/LICENSE-2.0 
+
+ Unless required by applicable law or agreed to in writing, software 
+ distributed under the License is distributed on an "AS IS" BASIS, 
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ See the License for the specific language governing permissions and 
+ limitations under the License.
+ */
+package org.uimafit.factory;
+
+import java.io.IOException;
+
+import org.apache.uima.ResourceSpecifierFactory;
+import org.apache.uima.UIMAException;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_component.CasAnnotator_ImplBase;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.analysis_engine.CasIterator;
+import org.apache.uima.analysis_engine.metadata.FixedFlow;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.collection.CollectionException;
+import org.apache.uima.collection.CollectionReaderDescription;
+import org.apache.uima.collection.CollectionReader_ImplBase;
+import org.apache.uima.util.Progress;
+import org.junit.Test;
+
+/**
+ * @author Richard Eckart de Castilho
+ */
+public class AggregateWithReaderTest {
+	
+	/**
+	 * Demo of running a collection reader as part of an aggregate engine. This allows to run
+	 * a pipeline an access the output CASes directly - no need to write the data to files.
+	 */
+	@Test
+	public void demoAggregateWithReader() throws UIMAException {
+		ResourceSpecifierFactory factory = UIMAFramework.getResourceSpecifierFactory();
+
+		CollectionReaderDescription reader = factory.createCollectionReaderDescription();
+		reader.getMetaData().setName("reader");
+		reader.setImplementationName(SimpleReader.class.getName());
+
+		AnalysisEngineDescription analyzer = factory.createAnalysisEngineDescription();
+		analyzer.getMetaData().setName("analyzer");
+		analyzer.setPrimitive(true);
+		analyzer.setImplementationName(SimpleAnalyzer.class.getName());
+
+		FixedFlow flow = factory.createFixedFlow();
+		flow.setFixedFlow(new String[] { "reader", "analyzer" });
+
+		AnalysisEngineDescription aggregate = factory.createAnalysisEngineDescription();
+		aggregate.getMetaData().setName("aggregate");
+		aggregate.getAnalysisEngineMetaData().setFlowConstraints(flow);
+		aggregate.getAnalysisEngineMetaData().getOperationalProperties().setOutputsNewCASes(true);
+		aggregate.getAnalysisEngineMetaData().getOperationalProperties()
+				.setMultipleDeploymentAllowed(false);
+		aggregate.setPrimitive(false);
+		aggregate.getDelegateAnalysisEngineSpecifiersWithImports().put("reader", reader);
+		aggregate.getDelegateAnalysisEngineSpecifiersWithImports().put("analyzer", analyzer);
+
+		AnalysisEngine pipeline = UIMAFramework.produceAnalysisEngine(aggregate);
+		CasIterator iterator = pipeline.processAndOutputNewCASes(pipeline.newCAS());
+		while (iterator.hasNext()) {
+			CAS cas = iterator.next();
+			System.out.printf("[%s] is [%s]%n", cas.getDocumentText(), cas.getDocumentLanguage());
+		}
+	}
+
+	/**
+	 * Demo of disguising a reader as a CAS multiplier. This works because internally, UIMA wraps
+	 * the reader in a CollectionReaderAdapter. This nice thing about this is, that in principle
+	 * it would be possible to define sofa mappings. However, UIMA-2419 prevents this.
+	 */
+	@Test
+	public void demoAggregateWithDisguisedReader() throws UIMAException {
+		ResourceSpecifierFactory factory = UIMAFramework.getResourceSpecifierFactory();
+		
+		AnalysisEngineDescription reader = factory.createAnalysisEngineDescription();
+		reader.getMetaData().setName("reader");
+		reader.setPrimitive(true);
+		reader.setImplementationName(SimpleReader.class.getName());
+		reader.getAnalysisEngineMetaData().getOperationalProperties().setOutputsNewCASes(true);
+	
+		AnalysisEngineDescription analyzer = factory.createAnalysisEngineDescription();
+		analyzer.getMetaData().setName("analyzer");
+		analyzer.setPrimitive(true);
+		analyzer.setImplementationName(SimpleAnalyzer.class.getName());
+	
+		FixedFlow flow = factory.createFixedFlow();
+		flow.setFixedFlow(new String[] { "reader", "analyzer" });
+	
+		AnalysisEngineDescription aggregate = factory.createAnalysisEngineDescription();
+		aggregate.getMetaData().setName("aggregate");
+		aggregate.setPrimitive(false);
+		aggregate.getAnalysisEngineMetaData().setFlowConstraints(flow);
+		aggregate.getAnalysisEngineMetaData().getOperationalProperties().setOutputsNewCASes(true);
+		aggregate.getAnalysisEngineMetaData().getOperationalProperties()
+				.setMultipleDeploymentAllowed(false);
+		aggregate.getDelegateAnalysisEngineSpecifiersWithImports().put("reader", reader);
+		aggregate.getDelegateAnalysisEngineSpecifiersWithImports().put("analyzer", analyzer);
+	
+		AnalysisEngine pipeline = UIMAFramework.produceAnalysisEngine(aggregate);
+		CasIterator iterator = pipeline.processAndOutputNewCASes(pipeline.newCAS());
+		while (iterator.hasNext()) {
+			CAS cas = iterator.next();
+			System.out.printf("[%s] is [%s]%n", cas.getDocumentText(), cas.getDocumentLanguage());
+		}
+	}
+
+//	@Test
+//	public void testAggregateBuilderWithReaderAndSofaMapping() throws UIMAException {
+//		CollectionReaderDescription reader = CollectionReaderFactory.createDescription(TestReader.class);
+//		
+//		AnalysisEngineDescription readerAed = UIMAFramework.getResourceSpecifierFactory().createAnalysisEngineDescription();
+//		readerAed.setAnnotatorImplementationName(reader.getImplementationName());
+//		readerAed.setExternalResourceDependencies(reader.getExternalResourceDependencies());
+//		readerAed.setFrameworkImplementation(reader.getFrameworkImplementation());
+//		readerAed.setImplementationName(reader.getImplementationName());
+//		readerAed.setMetaData(reader.getMetaData());
+////		readerAed.getAnalysisEngineMetaData().getOperationalProperties().setModifiesCas(true);
+////		readerAed.getAnalysisEngineMetaData().getOperationalProperties().setOutputsNewCASes(true);
+//		readerAed.setPrimitive(true);
+//		readerAed.setResourceManagerConfiguration(reader.getResourceManagerConfiguration());
+//		readerAed.setSourceUrl(reader.getSourceUrl());
+//		
+//		AggregateBuilder builder = new AggregateBuilder();
+//		builder.add(readerAed, 
+//				ViewNames.INITIAL_VIEW, "A");
+//		builder.add(AnalysisEngineFactory.createPrimitiveDescription(Annotator3.class), 
+//				ViewNames.INITIAL_VIEW, "A",
+//				ViewNames.REVERSE_VIEW, "B");
+//		
+//		builder.setFlowControllerDescription(createFlowControllerDescription(FixedFlowController.class,
+//				FixedFlowController.PARAM_ACTION_AFTER_CAS_MULTIPLIER, "drop"));
+//		
+//		AnalysisEngineDescription aggregateEngineDesc = builder.createAggregateDescription();
+//		aggregateEngineDesc.getAnalysisEngineMetaData().getOperationalProperties().setOutputsNewCASes(true);
+//
+//		AnalysisEngine aggregateEngine = createAggregate(aggregateEngineDesc);
+//		
+//		jCas.reset();
+//		JCasIterator ji = aggregateEngine.processAndOutputNewCASes(jCas);
+//		while (ji.hasNext()) {
+//			JCas jc = ji.next();
+//			FSIterator<SofaFS> i = jc.getSofaIterator();
+//			while (i.hasNext()) {
+//				SofaFS s = i.next();
+//				System.out.printf("%s - %s%n", s.getSofaID(), jc.getView(s.getSofaID()).getDocumentText());
+//			}
+//
+//			assertEquals("Anyone up for a game of Foosball?", jc.getView("A").getDocumentText());
+//			assertEquals("?llabsooF fo emag a rof pu enoynA", jc.getView("B").getDocumentText());
+//		}
+//	}
+	
+	public static class SimpleReader extends CollectionReader_ImplBase {
+		private boolean done = false;
+
+		public void getNext(CAS aCAS) throws IOException, CollectionException {
+			aCAS.setDocumentText("Anyone up for a game of Foosball?");
+			done = true;
+		}
+
+		public boolean hasNext() throws IOException, CollectionException {
+			return !done;
+		}
+
+		public Progress[] getProgress() {
+			return new Progress[0];
+		}
+
+		public void close() throws IOException {
+			// Nothing to do
+		}
+	}
+
+	public static class SimpleAnalyzer extends CasAnnotator_ImplBase {
+
+		@Override
+		public void process(CAS aCas) throws AnalysisEngineProcessException {
+			aCas.setDocumentLanguage("en");
+		}
+	}
+}

Propchange: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AggregateWithReaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AnalysisEngineFactoryExternalResourceTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AnalysisEngineFactoryExternalResourceTest.java?rev=1420723&view=auto
==============================================================================
--- uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AnalysisEngineFactoryExternalResourceTest.java (added)
+++ uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AnalysisEngineFactoryExternalResourceTest.java Wed Dec 12 14:58:37 2012
@@ -0,0 +1,406 @@
+/*
+ Copyright 2011
+ Ubiquitous Knowledge Processing (UKP) Lab
+ Technische Universitaet Darmstadt
+ All rights reserved.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+package org.uimafit.factory;
+
+import static org.junit.Assert.assertNotNull;
+import static org.uimafit.factory.AnalysisEngineFactory.createAggregate;
+import static org.uimafit.factory.AnalysisEngineFactory.createAggregateDescription;
+import static org.uimafit.factory.AnalysisEngineFactory.createPrimitive;
+import static org.uimafit.factory.AnalysisEngineFactory.createPrimitiveDescription;
+import static org.uimafit.factory.ExternalResourceFactory.bindExternalResource;
+import static org.uimafit.factory.ExternalResourceFactory.createExternalResourceDescription;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.CustomResourceSpecifier;
+import org.apache.uima.resource.ExternalResourceDescription;
+import org.apache.uima.resource.ResourceCreationSpecifier;
+import org.apache.uima.resource.metadata.ExternalResourceBinding;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.uimafit.component.CasAnnotator_ImplBase;
+import org.uimafit.component.ExternalResourceAware;
+import org.uimafit.descriptor.ConfigurationParameter;
+import org.uimafit.descriptor.ExternalResource;
+import org.uimafit.factory.testRes.TestExternalResource;
+import org.uimafit.factory.testRes.TestSharedResourceObject;
+import org.xml.sax.SAXException;
+
+/**
+ * @author Richard Eckart de Castilho
+ * @author Shuo Yang
+ */
+public class AnalysisEngineFactoryExternalResourceTest {
+	/**
+	 * Test simple injection.
+	 */
+	@Test
+	public void resource_testInjection() throws Exception {
+		AnalysisEngineDescription aeDesc = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithResource.class,
+				TestAnalysisEngineWithResource.PARAM_RESOURCE,
+				createExternalResourceDescription(TestExternalResource.class,
+						TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE)));
+		
+		AnalysisEngine ae = createPrimitive(aeDesc);
+		ae.process(ae.newCAS());
+	}
+
+	/**
+	 * Test shared simple injection.
+	 */
+	@Test
+	public void resource_testSharedInjection() throws Exception {
+		ExternalResourceDescription resDesc = createExternalResourceDescription(
+				TestExternalResource.class,
+				TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE);
+		
+		AnalysisEngineDescription aeDesc1 = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithResource.class,
+				TestAnalysisEngineWithResource.PARAM_RESOURCE, resDesc));
+
+		AnalysisEngineDescription aeDesc2 = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithResource.class,
+				TestAnalysisEngineWithResource.PARAM_RESOURCE, resDesc));
+
+		dumpResourceConfiguration(aeDesc1);
+		dumpResourceConfiguration(aeDesc2);
+		
+		AnalysisEngine ae1 = createPrimitive(aeDesc1);
+		AnalysisEngine ae2 = createPrimitive(aeDesc2);
+		ae1.process(ae1.newCAS());
+		ae2.process(ae2.newCAS());
+		
+		AnalysisEngine ae3 = createAggregate(createAggregateDescription(aeDesc1, aeDesc2));
+		ae3.process(ae3.newCAS());
+	}
+
+	/**
+	 * Test simple nesting.
+	 */
+	@Test
+	public void resource_testSimpleNesting() throws Exception {
+		AnalysisEngineDescription aeDesc = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithResource.class,
+				TestAnalysisEngineWithResource.PARAM_RESOURCE,
+				createExternalResourceDescription(TestExternalResource2.class,
+						TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE,
+						TestExternalResource2.PARAM_RESOURCE, createExternalResourceDescription(
+								TestExternalResource.class,
+								TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE))));
+
+		AnalysisEngine ae = createPrimitive(aeDesc);
+		ae.process(ae.newCAS());
+	}
+
+	/**
+	 * Test simple nesting.
+	 */
+	@Test
+	public void resource_testSharedSimpleNesting() throws Exception {
+		ExternalResourceDescription resDesc = createExternalResourceDescription(
+				TestExternalResource2.class,
+				TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE,
+				TestExternalResource2.PARAM_RESOURCE, createExternalResourceDescription(
+						TestExternalResource.class,
+						TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE));	
+		
+		AnalysisEngineDescription aeDesc1 = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithResource.class,
+				TestAnalysisEngineWithResource.PARAM_RESOURCE, resDesc));
+
+		dumpResourceConfiguration(aeDesc1);
+		
+		AnalysisEngineDescription aeDesc2 = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithResource.class,
+				TestAnalysisEngineWithResource.PARAM_RESOURCE, resDesc));
+
+		dumpResourceConfiguration(aeDesc1);
+		dumpResourceConfiguration(aeDesc2);
+		
+		AnalysisEngine ae1 = createPrimitive(aeDesc1);
+		AnalysisEngine ae2 = createPrimitive(aeDesc2);
+		ae1.process(ae1.newCAS());
+		ae2.process(ae2.newCAS());
+		
+		AnalysisEngine ae3 = createAggregate(createAggregateDescription(aeDesc1, aeDesc2));
+		ae3.process(ae3.newCAS());
+	}
+
+	/**
+	 * Test deeper nesting level.
+	 */
+	@Test
+	public void resource_testDeeperNesting() throws Exception {
+		ExternalResourceDescription resDesc2 = createExternalResourceDescription(
+				TestExternalResource.class,
+				TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE);
+
+		ExternalResourceDescription resDesc = createExternalResourceDescription(
+				TestExternalResource2.class,
+				TestExternalResource2.PARAM_RESOURCE, resDesc2,
+				TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE);
+
+		AnalysisEngineDescription aeDesc = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithResource.class,
+				TestAnalysisEngineWithResource.PARAM_RESOURCE,
+				createExternalResourceDescription(TestExternalResource2.class,
+						TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE,
+						TestExternalResource2.PARAM_RESOURCE, resDesc)));
+
+		dumpResourceConfiguration(aeDesc);
+
+		AnalysisEngine ae = createPrimitive(aeDesc);
+		ae.process(ae.newCAS());
+	}
+
+	/**
+	 * Test self-injection
+	 */
+	@Test
+	public void resource_testSelfInjection() throws Exception {
+		ExternalResourceDescription resDesc = createExternalResourceDescription(
+				TestExternalResource2.class,
+				TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE);
+		bindExternalResource(resDesc, TestExternalResource2.PARAM_RESOURCE, resDesc);
+
+		AnalysisEngineDescription aeDesc = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithResource.class,
+				TestAnalysisEngineWithResource.PARAM_RESOURCE, resDesc));
+		
+		dumpResourceConfiguration(aeDesc);
+		
+		AnalysisEngine ae = createPrimitive(aeDesc);
+		ae.process(ae.newCAS());
+	}
+
+	/**
+	 * Test self-injection
+	 */
+	@Test
+	public void resource_testDoubleSelfInjection() throws Exception {
+		ExternalResourceDescription resDesc = createExternalResourceDescription(
+				TestExternalResource2.class,
+				TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE);
+		bindExternalResource(resDesc, TestExternalResource2.PARAM_RESOURCE, resDesc);
+
+		AnalysisEngineDescription aeDesc1 = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithResource.class,
+				TestAnalysisEngineWithResource.PARAM_RESOURCE, resDesc));
+
+		AnalysisEngineDescription aeDesc2 = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithResource.class,
+				TestAnalysisEngineWithResource.PARAM_RESOURCE, resDesc));
+
+		dumpResourceConfiguration(aeDesc1);
+		dumpResourceConfiguration(aeDesc2);
+		
+		AnalysisEngine ae1 = createPrimitive(aeDesc1);
+		AnalysisEngine ae2 = createPrimitive(aeDesc2);
+		ae1.process(ae1.newCAS());
+		ae2.process(ae2.newCAS());
+		
+		AnalysisEngine ae3 = createAggregate(createAggregateDescription(aeDesc1, aeDesc2));
+		ae3.process(ae3.newCAS());
+	}
+	
+	/**
+	 * Test simple injection.
+	 */
+	@Test
+	public void sharedObject_testInjection() throws Exception {
+		AnalysisEngineDescription aeDesc = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithSharedResourceObject.class,
+				TestAnalysisEngineWithSharedResourceObject.PARAM_RESOURCE,
+				createExternalResourceDescription(TestSharedResourceObject.class, "http://dumm.my",
+						TestSharedResourceObject.PARAM_VALUE, TestSharedResourceObject.EXPECTED_VALUE)));
+		
+		AnalysisEngine ae = createPrimitive(aeDesc);
+		ae.process(ae.newCAS());
+	}
+
+	/**
+	 * Test shared simple injection.
+	 */
+	@Test
+	public void sharedObject_testSharedInjection() throws Exception {
+		ExternalResourceDescription resDesc = createExternalResourceDescription(
+				TestSharedResourceObject.class, "http://dumm.my",
+				TestSharedResourceObject.PARAM_VALUE, TestSharedResourceObject.EXPECTED_VALUE);
+		
+		AnalysisEngineDescription aeDesc1 = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithSharedResourceObject.class,
+				TestAnalysisEngineWithSharedResourceObject.PARAM_RESOURCE, resDesc));
+
+		AnalysisEngineDescription aeDesc2 = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithSharedResourceObject.class,
+				TestAnalysisEngineWithSharedResourceObject.PARAM_RESOURCE, resDesc));
+
+		dumpResourceConfiguration(aeDesc1);
+		dumpResourceConfiguration(aeDesc2);
+		
+		AnalysisEngine ae1 = createPrimitive(aeDesc1);
+		AnalysisEngine ae2 = createPrimitive(aeDesc2);
+		ae1.process(ae1.newCAS());
+		ae2.process(ae2.newCAS());
+		
+		AnalysisEngine ae3 = createAggregate(createAggregateDescription(aeDesc1, aeDesc2));
+		ae3.process(ae3.newCAS());
+	}
+
+	/**
+	 * Test self-injection
+	 */
+	@Test
+	public void sharedObject_testSelfInjection() throws Exception {
+		ExternalResourceDescription resDesc = createExternalResourceDescription(
+				TestSharedResourceObject2.class, "http://dumm.my",
+				TestSharedResourceObject.PARAM_VALUE, TestSharedResourceObject.EXPECTED_VALUE);
+		bindExternalResource(resDesc, TestSharedResourceObject2.PARAM_RESOURCE, resDesc);
+
+		AnalysisEngineDescription aeDesc = saveLoad(createPrimitiveDescription(
+				TestAnalysisEngineWithSharedResourceObject.class,
+				TestAnalysisEngineWithSharedResourceObject.PARAM_RESOURCE, resDesc));
+		
+		dumpResourceConfiguration(aeDesc);
+		
+		AnalysisEngine ae = createPrimitive(aeDesc);
+		ae.process(ae.newCAS());
+	}
+
+	public static class TestExternalResource2 extends TestExternalResource {
+		public final static String PARAM_RESOURCE = "resource2";
+		@ExternalResource(key = PARAM_RESOURCE)
+		private TestExternalResource resource;
+
+		@Override
+		public void afterResourcesInitialized() {
+			System.out.println(getClass().getSimpleName()+".afterResourcesInitialized()");
+			// Ensure the External Resource is bound
+			assertNotNull(resource);
+			if (this != resource) {
+				resource.assertConfiguredOk();
+			}
+			assertConfiguredOk();
+		}
+	}
+
+	public static class TestSharedResourceObject2 extends TestSharedResourceObject implements
+			ExternalResourceAware {
+		public final static String PARAM_RESOURCE = "resource2";
+		@ExternalResource(key = PARAM_RESOURCE)
+		private TestSharedResourceObject resource;
+
+		@ConfigurationParameter(name=ExternalResourceFactory.PARAM_RESOURCE_NAME)
+		private String resourceName;
+
+		public void afterResourcesInitialized() {
+			System.out.println(getClass().getSimpleName()+".afterResourcesInitialized()");
+			// Ensure the External Resource is bound
+			assertNotNull(resource);
+			if (this != resource) {
+				resource.assertConfiguredOk();
+			}
+			assertConfiguredOk();
+		}
+
+		public String getResourceName() {
+			return resourceName;
+		}
+	}
+
+	public static class TestAnalysisEngineWithResource extends CasAnnotator_ImplBase {
+
+		public final static String PARAM_RESOURCE = "resource";
+		@ExternalResource(key = PARAM_RESOURCE)
+		private TestExternalResource resource;
+		
+		@Override
+		public void process(CAS aCAS) throws AnalysisEngineProcessException {
+			System.out.println(getClass().getSimpleName()+".process()");
+			assertNotNull(resource);
+			resource.assertConfiguredOk();
+		}
+	}
+
+	public static class TestAnalysisEngineWithSharedResourceObject extends CasAnnotator_ImplBase {
+
+		public final static String PARAM_RESOURCE = "resource";
+		@ExternalResource(key = PARAM_RESOURCE)
+		private TestSharedResourceObject resource;
+		
+		@Override
+		public void process(CAS aCAS) throws AnalysisEngineProcessException {
+			System.out.println(getClass().getSimpleName()+".process()");
+			assertNotNull(resource);
+			resource.assertConfiguredOk();
+		}
+	}
+
+	AnalysisEngineDescription saveLoad(AnalysisEngineDescription aDesc)
+			throws InvalidXMLException, SAXException, IOException {
+		ByteArrayOutputStream bos = new ByteArrayOutputStream();
+		aDesc.toXML(bos);
+		return UIMAFramework.getXMLParser().parseAnalysisEngineDescription(
+				new XMLInputSource(new ByteArrayInputStream(bos.toByteArray()), null));
+	}
+	
+	private void dumpResourceConfiguration(ResourceCreationSpecifier aSpec)
+	{
+		System.out.println("-- begin resource configuration");
+		for (ExternalResourceBinding b : aSpec.getResourceManagerConfiguration()
+				.getExternalResourceBindings()) {
+			System.out.printf("Binding : %s -> %s %n", b.getKey(), b.getResourceName());
+		}
+
+		for (ExternalResourceDescription r : aSpec.getResourceManagerConfiguration()
+				.getExternalResources()) {
+			if (r.getImplementationName() != null) {
+				System.out.printf("Resource: %s -> %s %n", r.getName(), r.getImplementationName());
+			}
+			else {
+				System.out
+						.printf("Resource: %s -> %s %n", r.getName(), ((CustomResourceSpecifier) r
+								.getResourceSpecifier()).getResourceClassName());
+			}
+		}
+		System.out.println("-- end resource configuration");
+	}
+
+	@Rule
+	public TestName name = new TestName();
+
+	@Before
+	public void printSeparator()
+	{
+		System.out.println("\n=== " + name.getMethodName() + " =====================");
+	}
+}

Propchange: uima/sandbox/trunk/uimaFIT/src/test/java/org/uimafit/factory/AnalysisEngineFactoryExternalResourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native