You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2013/01/11 00:12:37 UTC
svn commit: r1431721 [17/19] - in /uima/sandbox/uimafit/trunk:
uimafit-examples/src/main/java/org/apache/uima/fit/examples/experiment/pos/
uimafit-examples/src/main/java/org/apache/uima/fit/examples/getstarted/
uimafit-examples/src/main/java/org/apache...
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/ExternalResourceFactoryTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/ExternalResourceFactoryTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/ExternalResourceFactoryTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/ExternalResourceFactoryTest.java Thu Jan 10 23:12:33 2013
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.uima.fit.factory;
import static org.apache.uima.fit.factory.AnalysisEngineFactory.createAggregate;
@@ -72,332 +71,342 @@ import org.springframework.mock.jndi.Sim
/**
* Test case for {@link ExternalResource} annotations.
- *
+ *
*/
public class ExternalResourceFactoryTest extends ComponentTestBase {
- private static final String EX_URI = "http://dum.my";
- private static final String EX_FILE_1 = "src/test/resources/data/html/1.html";
- private static final String EX_FILE_3 = "src/test/resources/data/html/3.html";
-
- @BeforeClass
- public static void initJNDI() throws Exception
- {
- // Set up JNDI context to test the JndiResourceLocator
- final SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
- Properties deDict = new Properties();
- deDict.setProperty("Hans", "proper noun");
- builder.bind("dictionaries/german", deDict);
- builder.activate();
- }
-
- @Test
- public void testScanBind() throws Exception {
- // Create analysis enginge description
- AnalysisEngineDescription desc = createPrimitiveDescription(DummyAE.class);
-
- // Bind external resources
- bindResources(desc);
-
- // Test with the default resource manager implementation
- AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc);
- assertNotNull(ae);
- }
-
- @Test
- public void testDirectInjection() throws Exception {
- // Create analysis enginge description
- AnalysisEngineDescription desc = createPrimitiveDescription(DummyAE2.class);
-
- // Bind external resources for DummyAE
- bindResources(desc);
-
- // Bind external resources for DummyAE2 - necessary because autowiring is disabled
- bindExternalResource(desc, DummyAE2.RES_INJECTED_POJO1, "pojoName1");
- bindExternalResource(desc, DummyAE2.RES_INJECTED_POJO2, "pojoName2");
-
- // Create a custom resource manager that allows to inject any Java object as an external
- // dependency
- final Map<String, Object> externalContext = new HashMap<String, Object>();
- externalContext.put("pojoName1", "Just an injected POJO");
- externalContext.put("pojoName2", new AtomicInteger(5));
-
- SimpleNamedResourceManager resMgr = new SimpleNamedResourceManager();
- resMgr.setExternalContext(externalContext);
- assertFalse(resMgr.isAutoWireEnabled());
-
- AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, resMgr, null);
- assertNotNull(ae);
-
- ae.process(ae.newJCas());
- }
-
- @Test
- public void testDirectInjectionAutowire() throws Exception {
- // Create analysis enginge description
- AnalysisEngineDescription desc = createPrimitiveDescription(DummyAE2.class);
-
- // Bind external resources for DummyAE
- bindResources(desc);
-
- // Create a custom resource manager that allows to inject any Java object as an external
- // dependency
- final Map<String, Object> externalContext = new HashMap<String, Object>();
- externalContext.put(DummyAE2.RES_INJECTED_POJO1, "Just an injected POJO");
- externalContext.put(DummyAE2.RES_INJECTED_POJO2, new AtomicInteger(5));
-
- SimpleNamedResourceManager resMgr = new SimpleNamedResourceManager();
- resMgr.setExternalContext(externalContext);
- resMgr.setAutoWireEnabled(true);
- assertTrue(resMgr.isAutoWireEnabled());
-
- AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, resMgr, null);
- assertNotNull(ae);
-
- ae.process(ae.newJCas());
- }
-
- @Test
- public void testMultiBinding() throws Exception {
- ExternalResourceDescription extDesc = createExternalResourceDescription(
- DummyResource.class);
-
- // Binding external resource to each Annotator individually
- AnalysisEngineDescription aed1 = createPrimitiveDescription(MultiBindAE.class,
- MultiBindAE.RES_KEY, extDesc);
- AnalysisEngineDescription aed2 = createPrimitiveDescription(MultiBindAE.class,
- MultiBindAE.RES_KEY, extDesc);
-
- // Check the external resource was injected
- AnalysisEngineDescription aaed = createAggregateDescription(aed1, aed2);
- AnalysisEngine ae = createAggregate(aaed);
- ae.process(ae.newJCas());
-
- MultiBindAE.reset();
-
- // Check the external resource was injected
- SimplePipeline.runPipeline(CasCreationUtils.createCas(aaed.getAnalysisEngineMetaData()), aaed);
- }
-
- private static void bindResources(AnalysisEngineDescription desc) throws Exception {
- bindResource(desc, DummyResource.class);
- bindResource(desc, DummyAE.RES_KEY_1, ConfigurableResource.class,
- ConfigurableResource.PARAM_VALUE, "1");
- bindResource(desc, DummyAE.RES_KEY_2, ConfigurableResource.class,
- ConfigurableResource.PARAM_VALUE, "2");
- bindResource(desc, DummyAE.RES_KEY_3, ParametrizedResource.class,
- ParametrizedResource.PARAM_EXTENSION, ".lala");
- bindResource(desc, DummySharedResourceObject.class, EX_URI,
- DummySharedResourceObject.PARAM_VALUE,"3");
- // An undefined URL may be used if the specified file/remote URL does not exist or if
- // the network is down.
- bindResource(desc, DummyAE.RES_SOME_URL, new File(EX_FILE_1).toURI().toURL());
- bindResource(desc, DummyAE.RES_SOME_OTHER_URL, new File(EX_FILE_3).toURI().toURL());
- bindResource(desc, DummyAE.RES_SOME_FILE, new File(EX_FILE_1));
- bindResource(desc, DummyAE.RES_JNDI_OBJECT, JndiResourceLocator.class,
- JndiResourceLocator.PARAM_NAME, "dictionaries/german");
- createDependencyAndBind(desc, "legacyResource", DummySharedResourceObject.class, EX_URI,
- DummySharedResourceObject.PARAM_VALUE,"3");
- }
-
- public static class DummyAE extends JCasAnnotator_ImplBase {
- @ExternalResource
- DummyResource r;
-
- static final String RES_KEY_1 = "Key1";
- @ExternalResource(key = RES_KEY_1)
- ConfigurableResource configRes1;
-
- static final String RES_KEY_2 = "Key2";
- @ExternalResource(key = RES_KEY_2)
- ConfigurableResource configRes2;
-
- static final String RES_KEY_3 = "Key3";
-
- @ExternalResource
- DummySharedResourceObject sharedObject;
-
- static final String RES_SOME_URL = "SomeUrl";
- @ExternalResource(key = RES_SOME_URL)
- DataResource someUrl;
-
- static final String RES_SOME_OTHER_URL = "SomeOtherUrl";
- @ExternalResource(key = RES_SOME_OTHER_URL)
- DataResource someOtherUrl;
-
- static final String RES_SOME_FILE = "SomeFile";
- @ExternalResource(key = RES_SOME_FILE)
- DataResource someFile;
-
- static final String RES_JNDI_OBJECT = "JndiObject";
- @ExternalResource(key = RES_JNDI_OBJECT)
- Properties jndiPropertes;
-
- @Override
- public void process(JCas aJCas) throws AnalysisEngineProcessException {
- assertNotNull(r);
-
- assertNotNull(configRes1);
- assertEquals("1", configRes1.getValue());
-
- assertNotNull(configRes2);
- assertEquals("2", configRes2.getValue());
-
- try {
- DataResource configuredResource = (DataResource) getContext().getResourceObject(RES_KEY_3,
- new String[] { ConfigurableDataResource.PARAM_URI, "http://dum.my/conf" });
- assertNotNull(configuredResource);
- assertEquals("http://dum.my/conf.lala", configuredResource.getUri().toString());
- }
- catch (ResourceAccessException e) {
- throw new AnalysisEngineProcessException(e);
- }
-
- assertNotNull(sharedObject);
- assertEquals("3", sharedObject.getValue());
-
- assertNotNull(sharedObject);
- assertEquals(EX_URI, sharedObject.getUrl().toString());
-
- assertNotNull(jndiPropertes);
- assertEquals("proper noun", jndiPropertes.get("Hans"));
-
- assertNotNull(someUrl);
- assertEquals(new File(EX_FILE_1).toURI().toString(), someUrl.getUri().toString());
-
- assertNotNull(someOtherUrl);
- assertEquals(new File(EX_FILE_3).toURI().toString(), someOtherUrl.getUri().toString());
-
- assertTrue(someFile.getUrl().toString().startsWith("file:"));
- assertTrue("URL [" + someFile.getUrl() + "] should end in [" + EX_FILE_1 + "]",
- someFile.getUrl().toString().endsWith(EX_FILE_1));
-
- try {
- assertNotNull(getContext().getResourceObject("legacyResource"));
- }
- catch (ResourceAccessException e) {
- throw new AnalysisEngineProcessException(e);
- }
- }
- }
-
- public static final class DummyAE2 extends DummyAE {
- static final String RES_INJECTED_POJO1 = "InjectedPojo1";
- @ExternalResource(key = RES_INJECTED_POJO1)
- String injectedString;
-
- static final String RES_INJECTED_POJO2 = "InjectedPojo2";
- @ExternalResource(key = RES_INJECTED_POJO2)
- Number injectedAtomicInt;
-
- @Override
- public void process(JCas aJCas) throws AnalysisEngineProcessException {
- super.process(aJCas);
- assertEquals("Just an injected POJO", injectedString);
- assertEquals(5, injectedAtomicInt.intValue());
- }
- }
-
- /**
- * Example annotator that uses the share model object. In the process() we only test if the
- * model was properly initialized by uimaFIT
- */
- public static class MultiBindAE extends org.apache.uima.fit.component.JCasAnnotator_ImplBase {
- static int prevHashCode = -1;
-
- static final String RES_KEY = "Res";
- @ExternalResource(key = RES_KEY)
- DummyResource res;
-
- @Override
- public void process(JCas aJCas) throws AnalysisEngineProcessException {
- if (prevHashCode == -1) {
- prevHashCode = res.hashCode();
- }
- else {
- assertEquals(prevHashCode, res.hashCode());
- }
-
- System.out.println(getClass().getSimpleName() + ": " + res);
- }
-
- public static void reset()
- {
- prevHashCode = -1;
- }
- }
-
- public static final class DummyResource extends Resource_ImplBase {
- // Nothing
- }
-
- public static final class ConfigurableResource extends Resource_ImplBase {
- public static final String PARAM_VALUE = "Value";
- @ConfigurationParameter(name = PARAM_VALUE, mandatory = true)
- private String value;
-
- public String getValue() {
- return value;
- }
- }
-
- public static final class ConfigurableDataResource extends Resource_ImplBase implements DataResource {
- public static final String PARAM_URI = "Uri";
- @ConfigurationParameter(name = PARAM_URI, mandatory = true)
- private String uri;
-
- public static final String PARAM_EXTENSION = "Extension";
- @ConfigurationParameter(name = PARAM_EXTENSION, mandatory = true)
- private String extension;
-
- public InputStream getInputStream() throws IOException {
- return null;
- }
-
- public URI getUri() {
- return URI.create(uri+extension);
- }
-
- public URL getUrl() {
- return null;
- }
- }
-
- public static final class ParametrizedResource extends Resource_ImplBase implements
- ParameterizedDataResource {
- public static final String PARAM_EXTENSION = "Extension";
- @ConfigurationParameter(name = PARAM_EXTENSION, mandatory = true)
- private String extension;
-
- public DataResource getDataResource(String[] aParams)
- throws ResourceInitializationException {
- List<String> params = new ArrayList<String>(Arrays.asList(aParams));
- params.add(ConfigurableDataResource.PARAM_EXTENSION);
- params.add(extension);
- ExternalResourceDescription desc = ExternalResourceFactory.createExternalResourceDescription(
- null, ConfigurableDataResource.class, params.toArray(new String[params.size()]));
- return (DataResource) UIMAFramework.produceResource(desc.getResourceSpecifier(), null);
- }
- }
-
- public static final class DummySharedResourceObject implements SharedResourceObject {
- public static final String PARAM_VALUE = "Value";
- @ConfigurationParameter(name = PARAM_VALUE, mandatory = true)
- private String value;
-
- private URI uri;
-
- public void load(DataResource aData) throws ResourceInitializationException {
- ConfigurationParameterInitializer.initialize(this, aData);
- assertEquals(EX_URI, aData.getUri().toString());
- uri = aData.getUri();
- }
-
- public URI getUrl() {
- return uri;
- }
-
- public String getValue() {
- return value;
- }
- }
+ private static final String EX_URI = "http://dum.my";
+
+ private static final String EX_FILE_1 = "src/test/resources/data/html/1.html";
+
+ private static final String EX_FILE_3 = "src/test/resources/data/html/3.html";
+
+ @BeforeClass
+ public static void initJNDI() throws Exception {
+ // Set up JNDI context to test the JndiResourceLocator
+ final SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
+ Properties deDict = new Properties();
+ deDict.setProperty("Hans", "proper noun");
+ builder.bind("dictionaries/german", deDict);
+ builder.activate();
+ }
+
+ @Test
+ public void testScanBind() throws Exception {
+ // Create analysis enginge description
+ AnalysisEngineDescription desc = createPrimitiveDescription(DummyAE.class);
+
+ // Bind external resources
+ bindResources(desc);
+
+ // Test with the default resource manager implementation
+ AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc);
+ assertNotNull(ae);
+ }
+
+ @Test
+ public void testDirectInjection() throws Exception {
+ // Create analysis enginge description
+ AnalysisEngineDescription desc = createPrimitiveDescription(DummyAE2.class);
+
+ // Bind external resources for DummyAE
+ bindResources(desc);
+
+ // Bind external resources for DummyAE2 - necessary because autowiring is disabled
+ bindExternalResource(desc, DummyAE2.RES_INJECTED_POJO1, "pojoName1");
+ bindExternalResource(desc, DummyAE2.RES_INJECTED_POJO2, "pojoName2");
+
+ // Create a custom resource manager that allows to inject any Java object as an external
+ // dependency
+ final Map<String, Object> externalContext = new HashMap<String, Object>();
+ externalContext.put("pojoName1", "Just an injected POJO");
+ externalContext.put("pojoName2", new AtomicInteger(5));
+
+ SimpleNamedResourceManager resMgr = new SimpleNamedResourceManager();
+ resMgr.setExternalContext(externalContext);
+ assertFalse(resMgr.isAutoWireEnabled());
+
+ AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, resMgr, null);
+ assertNotNull(ae);
+
+ ae.process(ae.newJCas());
+ }
+
+ @Test
+ public void testDirectInjectionAutowire() throws Exception {
+ // Create analysis enginge description
+ AnalysisEngineDescription desc = createPrimitiveDescription(DummyAE2.class);
+
+ // Bind external resources for DummyAE
+ bindResources(desc);
+
+ // Create a custom resource manager that allows to inject any Java object as an external
+ // dependency
+ final Map<String, Object> externalContext = new HashMap<String, Object>();
+ externalContext.put(DummyAE2.RES_INJECTED_POJO1, "Just an injected POJO");
+ externalContext.put(DummyAE2.RES_INJECTED_POJO2, new AtomicInteger(5));
+
+ SimpleNamedResourceManager resMgr = new SimpleNamedResourceManager();
+ resMgr.setExternalContext(externalContext);
+ resMgr.setAutoWireEnabled(true);
+ assertTrue(resMgr.isAutoWireEnabled());
+
+ AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, resMgr, null);
+ assertNotNull(ae);
+
+ ae.process(ae.newJCas());
+ }
+
+ @Test
+ public void testMultiBinding() throws Exception {
+ ExternalResourceDescription extDesc = createExternalResourceDescription(DummyResource.class);
+
+ // Binding external resource to each Annotator individually
+ AnalysisEngineDescription aed1 = createPrimitiveDescription(MultiBindAE.class,
+ MultiBindAE.RES_KEY, extDesc);
+ AnalysisEngineDescription aed2 = createPrimitiveDescription(MultiBindAE.class,
+ MultiBindAE.RES_KEY, extDesc);
+
+ // Check the external resource was injected
+ AnalysisEngineDescription aaed = createAggregateDescription(aed1, aed2);
+ AnalysisEngine ae = createAggregate(aaed);
+ ae.process(ae.newJCas());
+
+ MultiBindAE.reset();
+
+ // Check the external resource was injected
+ SimplePipeline.runPipeline(CasCreationUtils.createCas(aaed.getAnalysisEngineMetaData()), aaed);
+ }
+
+ private static void bindResources(AnalysisEngineDescription desc) throws Exception {
+ bindResource(desc, DummyResource.class);
+ bindResource(desc, DummyAE.RES_KEY_1, ConfigurableResource.class,
+ ConfigurableResource.PARAM_VALUE, "1");
+ bindResource(desc, DummyAE.RES_KEY_2, ConfigurableResource.class,
+ ConfigurableResource.PARAM_VALUE, "2");
+ bindResource(desc, DummyAE.RES_KEY_3, ParametrizedResource.class,
+ ParametrizedResource.PARAM_EXTENSION, ".lala");
+ bindResource(desc, DummySharedResourceObject.class, EX_URI,
+ DummySharedResourceObject.PARAM_VALUE, "3");
+ // An undefined URL may be used if the specified file/remote URL does not exist or if
+ // the network is down.
+ bindResource(desc, DummyAE.RES_SOME_URL, new File(EX_FILE_1).toURI().toURL());
+ bindResource(desc, DummyAE.RES_SOME_OTHER_URL, new File(EX_FILE_3).toURI().toURL());
+ bindResource(desc, DummyAE.RES_SOME_FILE, new File(EX_FILE_1));
+ bindResource(desc, DummyAE.RES_JNDI_OBJECT, JndiResourceLocator.class,
+ JndiResourceLocator.PARAM_NAME, "dictionaries/german");
+ createDependencyAndBind(desc, "legacyResource", DummySharedResourceObject.class, EX_URI,
+ DummySharedResourceObject.PARAM_VALUE, "3");
+ }
+
+ public static class DummyAE extends JCasAnnotator_ImplBase {
+ @ExternalResource
+ DummyResource r;
+
+ static final String RES_KEY_1 = "Key1";
+
+ @ExternalResource(key = RES_KEY_1)
+ ConfigurableResource configRes1;
+
+ static final String RES_KEY_2 = "Key2";
+
+ @ExternalResource(key = RES_KEY_2)
+ ConfigurableResource configRes2;
+
+ static final String RES_KEY_3 = "Key3";
+
+ @ExternalResource
+ DummySharedResourceObject sharedObject;
+
+ static final String RES_SOME_URL = "SomeUrl";
+
+ @ExternalResource(key = RES_SOME_URL)
+ DataResource someUrl;
+
+ static final String RES_SOME_OTHER_URL = "SomeOtherUrl";
+
+ @ExternalResource(key = RES_SOME_OTHER_URL)
+ DataResource someOtherUrl;
+
+ static final String RES_SOME_FILE = "SomeFile";
+
+ @ExternalResource(key = RES_SOME_FILE)
+ DataResource someFile;
+
+ static final String RES_JNDI_OBJECT = "JndiObject";
+
+ @ExternalResource(key = RES_JNDI_OBJECT)
+ Properties jndiPropertes;
+
+ @Override
+ public void process(JCas aJCas) throws AnalysisEngineProcessException {
+ assertNotNull(r);
+
+ assertNotNull(configRes1);
+ assertEquals("1", configRes1.getValue());
+
+ assertNotNull(configRes2);
+ assertEquals("2", configRes2.getValue());
+
+ try {
+ DataResource configuredResource = (DataResource) getContext().getResourceObject(RES_KEY_3,
+ new String[] { ConfigurableDataResource.PARAM_URI, "http://dum.my/conf" });
+ assertNotNull(configuredResource);
+ assertEquals("http://dum.my/conf.lala", configuredResource.getUri().toString());
+ } catch (ResourceAccessException e) {
+ throw new AnalysisEngineProcessException(e);
+ }
+
+ assertNotNull(sharedObject);
+ assertEquals("3", sharedObject.getValue());
+
+ assertNotNull(sharedObject);
+ assertEquals(EX_URI, sharedObject.getUrl().toString());
+
+ assertNotNull(jndiPropertes);
+ assertEquals("proper noun", jndiPropertes.get("Hans"));
+
+ assertNotNull(someUrl);
+ assertEquals(new File(EX_FILE_1).toURI().toString(), someUrl.getUri().toString());
+
+ assertNotNull(someOtherUrl);
+ assertEquals(new File(EX_FILE_3).toURI().toString(), someOtherUrl.getUri().toString());
+
+ assertTrue(someFile.getUrl().toString().startsWith("file:"));
+ assertTrue("URL [" + someFile.getUrl() + "] should end in [" + EX_FILE_1 + "]", someFile
+ .getUrl().toString().endsWith(EX_FILE_1));
+
+ try {
+ assertNotNull(getContext().getResourceObject("legacyResource"));
+ } catch (ResourceAccessException e) {
+ throw new AnalysisEngineProcessException(e);
+ }
+ }
+ }
+
+ public static final class DummyAE2 extends DummyAE {
+ static final String RES_INJECTED_POJO1 = "InjectedPojo1";
+
+ @ExternalResource(key = RES_INJECTED_POJO1)
+ String injectedString;
+
+ static final String RES_INJECTED_POJO2 = "InjectedPojo2";
+
+ @ExternalResource(key = RES_INJECTED_POJO2)
+ Number injectedAtomicInt;
+
+ @Override
+ public void process(JCas aJCas) throws AnalysisEngineProcessException {
+ super.process(aJCas);
+ assertEquals("Just an injected POJO", injectedString);
+ assertEquals(5, injectedAtomicInt.intValue());
+ }
+ }
+
+ /**
+ * Example annotator that uses the share model object. In the process() we only test if the model
+ * was properly initialized by uimaFIT
+ */
+ public static class MultiBindAE extends org.apache.uima.fit.component.JCasAnnotator_ImplBase {
+ static int prevHashCode = -1;
+
+ static final String RES_KEY = "Res";
+
+ @ExternalResource(key = RES_KEY)
+ DummyResource res;
+
+ @Override
+ public void process(JCas aJCas) throws AnalysisEngineProcessException {
+ if (prevHashCode == -1) {
+ prevHashCode = res.hashCode();
+ } else {
+ assertEquals(prevHashCode, res.hashCode());
+ }
+
+ System.out.println(getClass().getSimpleName() + ": " + res);
+ }
+
+ public static void reset() {
+ prevHashCode = -1;
+ }
+ }
+
+ public static final class DummyResource extends Resource_ImplBase {
+ // Nothing
+ }
+
+ public static final class ConfigurableResource extends Resource_ImplBase {
+ public static final String PARAM_VALUE = "Value";
+
+ @ConfigurationParameter(name = PARAM_VALUE, mandatory = true)
+ private String value;
+
+ public String getValue() {
+ return value;
+ }
+ }
+
+ public static final class ConfigurableDataResource extends Resource_ImplBase implements
+ DataResource {
+ public static final String PARAM_URI = "Uri";
+
+ @ConfigurationParameter(name = PARAM_URI, mandatory = true)
+ private String uri;
+
+ public static final String PARAM_EXTENSION = "Extension";
+
+ @ConfigurationParameter(name = PARAM_EXTENSION, mandatory = true)
+ private String extension;
+
+ public InputStream getInputStream() throws IOException {
+ return null;
+ }
+
+ public URI getUri() {
+ return URI.create(uri + extension);
+ }
+
+ public URL getUrl() {
+ return null;
+ }
+ }
+
+ public static final class ParametrizedResource extends Resource_ImplBase implements
+ ParameterizedDataResource {
+ public static final String PARAM_EXTENSION = "Extension";
+
+ @ConfigurationParameter(name = PARAM_EXTENSION, mandatory = true)
+ private String extension;
+
+ public DataResource getDataResource(String[] aParams) throws ResourceInitializationException {
+ List<String> params = new ArrayList<String>(Arrays.asList(aParams));
+ params.add(ConfigurableDataResource.PARAM_EXTENSION);
+ params.add(extension);
+ ExternalResourceDescription desc = ExternalResourceFactory.createExternalResourceDescription(
+ null, ConfigurableDataResource.class, params.toArray(new String[params.size()]));
+ return (DataResource) UIMAFramework.produceResource(desc.getResourceSpecifier(), null);
+ }
+ }
+
+ public static final class DummySharedResourceObject implements SharedResourceObject {
+ public static final String PARAM_VALUE = "Value";
+
+ @ConfigurationParameter(name = PARAM_VALUE, mandatory = true)
+ private String value;
+
+ private URI uri;
+
+ public void load(DataResource aData) throws ResourceInitializationException {
+ ConfigurationParameterInitializer.initialize(this, aData);
+ assertEquals(EX_URI, aData.getUri().toString());
+ uri = aData.getUri();
+ }
+
+ public URI getUrl() {
+ return uri;
+ }
+
+ public String getValue() {
+ return value;
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/FlowControllerFactoryExternalResourceTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/FlowControllerFactoryExternalResourceTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/FlowControllerFactoryExternalResourceTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/FlowControllerFactoryExternalResourceTest.java Thu Jan 10 23:12:33 2013
@@ -36,7 +36,6 @@
* under the License.
*/
-
package org.apache.uima.fit.factory;
import static org.apache.uima.fit.factory.ExternalResourceFactory.createExternalResourceDescription;
@@ -59,35 +58,36 @@ import org.junit.Test;
/**
*/
public class FlowControllerFactoryExternalResourceTest {
- @Test
- public void testAutoExternalResourceBinding() throws Exception {
- AggregateBuilder builder = new AggregateBuilder();
- builder.add(AnalysisEngineFactory.createPrimitiveDescription(NoOpAnnotator.class));
- builder.setFlowControllerDescription(createFlowControllerDescription(
- TestFlowController.class,
- TestFlowController.PARAM_RESOURCE,
- createExternalResourceDescription(TestExternalResource.class,
- TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE)));
- AnalysisEngine aggregateEngine = builder.createAggregate();
- aggregateEngine.process(aggregateEngine.newCAS());
- }
-
- public static class TestFlowController extends CasFlowController_ImplBase {
- public final static String PARAM_RESOURCE = "resource";
- @ExternalResource(key = PARAM_RESOURCE)
- private TestExternalResource resource;
-
- @Override
- public Flow computeFlow(CAS aCAS) throws AnalysisEngineProcessException {
- assertNotNull(resource);
- resource.assertConfiguredOk();
- return new TestFlowObject();
- }
- }
-
- public static class TestFlowObject extends CasFlow_ImplBase {
- public Step next() throws AnalysisEngineProcessException {
- return new FinalStep();
- }
- }
+ @Test
+ public void testAutoExternalResourceBinding() throws Exception {
+ AggregateBuilder builder = new AggregateBuilder();
+ builder.add(AnalysisEngineFactory.createPrimitiveDescription(NoOpAnnotator.class));
+ builder.setFlowControllerDescription(createFlowControllerDescription(
+ TestFlowController.class,
+ TestFlowController.PARAM_RESOURCE,
+ createExternalResourceDescription(TestExternalResource.class,
+ TestExternalResource.PARAM_VALUE, TestExternalResource.EXPECTED_VALUE)));
+ AnalysisEngine aggregateEngine = builder.createAggregate();
+ aggregateEngine.process(aggregateEngine.newCAS());
+ }
+
+ public static class TestFlowController extends CasFlowController_ImplBase {
+ public final static String PARAM_RESOURCE = "resource";
+
+ @ExternalResource(key = PARAM_RESOURCE)
+ private TestExternalResource resource;
+
+ @Override
+ public Flow computeFlow(CAS aCAS) throws AnalysisEngineProcessException {
+ assertNotNull(resource);
+ resource.assertConfiguredOk();
+ return new TestFlowObject();
+ }
+ }
+
+ public static class TestFlowObject extends CasFlow_ImplBase {
+ public Step next() throws AnalysisEngineProcessException {
+ return new FinalStep();
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/FsIndexFactoryTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/FsIndexFactoryTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/FsIndexFactoryTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/FsIndexFactoryTest.java Thu Jan 10 23:12:33 2013
@@ -43,95 +43,89 @@ import org.junit.Test;
/**
*/
public class FsIndexFactoryTest extends ComponentTestBase {
- @Test
- public void testCreateIndexCollection() throws Exception {
- org.apache.uima.resource.metadata.FsIndexCollection fsIndexCollection =
- createFsIndexCollection(IndexTestComponent.class);
-
- assertEquals(2, fsIndexCollection.getFsIndexes().length);
-
- FsIndexDescription index1 = fsIndexCollection.getFsIndexes()[0];
- assertEquals("index1", index1.getLabel());
- assertEquals(Token.class.getName(), index1.getTypeName());
- assertEquals(FsIndexDescription.KIND_SORTED, index1.getKind());
-
- FsIndexKeyDescription key11 = index1.getKeys()[0];
- assertEquals("begin", key11.getFeatureName());
- assertEquals(FsIndexKeyDescription.REVERSE_STANDARD_COMPARE, key11.getComparator());
-
- FsIndexKeyDescription key12 = index1.getKeys()[1];
- assertEquals("end", key12.getFeatureName());
- assertEquals(FsIndexKeyDescription.STANDARD_COMPARE, key12.getComparator());
-
- FsIndexDescription index2 = fsIndexCollection.getFsIndexes()[1];
- assertEquals("index2", index2.getLabel());
- assertEquals(Sentence.class.getName(), index2.getTypeName());
- assertEquals(FsIndexDescription.KIND_SET, index2.getKind());
-
- FsIndexKeyDescription key21 = index2.getKeys()[0];
- assertEquals("begin", key21.getFeatureName());
- assertEquals(FsIndexKeyDescription.STANDARD_COMPARE, key21.getComparator());
-
- fsIndexCollection.toXML(new FileOutputStream("target/dummy.xml"));
- }
-
- @Test
- public void testIndexesWork() throws Exception {
- // Index should be added the descriptor and thus end up in the CAS generated from the
- // analysis engine.
- AnalysisEngine desc = createPrimitive(IndexTestComponent.class);
- JCas jcas = desc.newJCas();
-
- Token token1 = new Token(jcas, 1, 2);
- token1.addToIndexes();
-
- // index1 is a sorted index, so when adding a token twice, both remain in the index
- Token token2 = new Token(jcas, 3, 4);
- token2.addToIndexes();
- token2.addToIndexes();
-
- Sentence sentence1 = new Sentence(jcas, 1, 2);
- sentence1.addToIndexes();
-
- // index2 is a set index, so even when adding a sentence twice, only one remains in the index
- Sentence sentence2 = new Sentence(jcas, 3, 4);
- sentence2.addToIndexes();
- sentence2.addToIndexes();
-
- FSIndex<FeatureStructure> index1 = jcas.getFSIndexRepository().getIndex("index1");
- FSIndex<FeatureStructure> index2 = jcas.getFSIndexRepository().getIndex("index2");
-
- assertEquals(3, index1.size());
- assertEquals(2, index2.size());
-
-// AnalysisEngine dumpWriter = createPrimitive(CASDumpWriter.class);
-// dumpWriter.process(jcas.getCas());
- }
-
- @FsIndexCollection(fsIndexes = {
- @FsIndex(label="index1", type=Token.class, kind=FsIndex.KIND_SORTED, keys = {
- @FsIndexKey(featureName="begin", comparator=FsIndexKey.REVERSE_STANDARD_COMPARE),
- @FsIndexKey(featureName="end", comparator=FsIndexKey.STANDARD_COMPARE)
- }),
- @FsIndex(label="index2", type=Sentence.class, kind=FsIndex.KIND_SET, keys = {
- @FsIndexKey(featureName="begin", comparator=FsIndexKey.STANDARD_COMPARE)
- })
- })
- public static class IndexTestComponent extends JCasAnnotator_ImplBase
- {
- @Override
- public void process(JCas aJCas) throws AnalysisEngineProcessException {
- // Nothing to do
- }
- }
-
- @Test
- public void testAutoDetectIndexes() throws Exception {
- org.apache.uima.resource.metadata.FsIndexCollection fsIndexCollection = createFsIndexCollection();
-
- FsIndexDescription index1 = fsIndexCollection.getFsIndexes()[0];
- assertEquals("Automatically Scanned Index", index1.getLabel());
- assertEquals(Token.class.getName(), index1.getTypeName());
- assertEquals(FsIndexDescription.KIND_SORTED, index1.getKind());
- }
+ @Test
+ public void testCreateIndexCollection() throws Exception {
+ org.apache.uima.resource.metadata.FsIndexCollection fsIndexCollection = createFsIndexCollection(IndexTestComponent.class);
+
+ assertEquals(2, fsIndexCollection.getFsIndexes().length);
+
+ FsIndexDescription index1 = fsIndexCollection.getFsIndexes()[0];
+ assertEquals("index1", index1.getLabel());
+ assertEquals(Token.class.getName(), index1.getTypeName());
+ assertEquals(FsIndexDescription.KIND_SORTED, index1.getKind());
+
+ FsIndexKeyDescription key11 = index1.getKeys()[0];
+ assertEquals("begin", key11.getFeatureName());
+ assertEquals(FsIndexKeyDescription.REVERSE_STANDARD_COMPARE, key11.getComparator());
+
+ FsIndexKeyDescription key12 = index1.getKeys()[1];
+ assertEquals("end", key12.getFeatureName());
+ assertEquals(FsIndexKeyDescription.STANDARD_COMPARE, key12.getComparator());
+
+ FsIndexDescription index2 = fsIndexCollection.getFsIndexes()[1];
+ assertEquals("index2", index2.getLabel());
+ assertEquals(Sentence.class.getName(), index2.getTypeName());
+ assertEquals(FsIndexDescription.KIND_SET, index2.getKind());
+
+ FsIndexKeyDescription key21 = index2.getKeys()[0];
+ assertEquals("begin", key21.getFeatureName());
+ assertEquals(FsIndexKeyDescription.STANDARD_COMPARE, key21.getComparator());
+
+ fsIndexCollection.toXML(new FileOutputStream("target/dummy.xml"));
+ }
+
+ @Test
+ public void testIndexesWork() throws Exception {
+ // Index should be added the descriptor and thus end up in the CAS generated from the
+ // analysis engine.
+ AnalysisEngine desc = createPrimitive(IndexTestComponent.class);
+ JCas jcas = desc.newJCas();
+
+ Token token1 = new Token(jcas, 1, 2);
+ token1.addToIndexes();
+
+ // index1 is a sorted index, so when adding a token twice, both remain in the index
+ Token token2 = new Token(jcas, 3, 4);
+ token2.addToIndexes();
+ token2.addToIndexes();
+
+ Sentence sentence1 = new Sentence(jcas, 1, 2);
+ sentence1.addToIndexes();
+
+ // index2 is a set index, so even when adding a sentence twice, only one remains in the index
+ Sentence sentence2 = new Sentence(jcas, 3, 4);
+ sentence2.addToIndexes();
+ sentence2.addToIndexes();
+
+ FSIndex<FeatureStructure> index1 = jcas.getFSIndexRepository().getIndex("index1");
+ FSIndex<FeatureStructure> index2 = jcas.getFSIndexRepository().getIndex("index2");
+
+ assertEquals(3, index1.size());
+ assertEquals(2, index2.size());
+
+ // AnalysisEngine dumpWriter = createPrimitive(CASDumpWriter.class);
+ // dumpWriter.process(jcas.getCas());
+ }
+
+ @FsIndexCollection(fsIndexes = {
+ @FsIndex(label = "index1", type = Token.class, kind = FsIndex.KIND_SORTED, keys = {
+ @FsIndexKey(featureName = "begin", comparator = FsIndexKey.REVERSE_STANDARD_COMPARE),
+ @FsIndexKey(featureName = "end", comparator = FsIndexKey.STANDARD_COMPARE) }),
+ @FsIndex(label = "index2", type = Sentence.class, kind = FsIndex.KIND_SET, keys = { @FsIndexKey(featureName = "begin", comparator = FsIndexKey.STANDARD_COMPARE) }) })
+ public static class IndexTestComponent extends JCasAnnotator_ImplBase {
+ @Override
+ public void process(JCas aJCas) throws AnalysisEngineProcessException {
+ // Nothing to do
+ }
+ }
+
+ @Test
+ public void testAutoDetectIndexes() throws Exception {
+ org.apache.uima.resource.metadata.FsIndexCollection fsIndexCollection = createFsIndexCollection();
+
+ FsIndexDescription index1 = fsIndexCollection.getFsIndexes()[0];
+ assertEquals("Automatically Scanned Index", index1.getLabel());
+ assertEquals(Token.class.getName(), index1.getTypeName());
+ assertEquals(FsIndexDescription.KIND_SORTED, index1.getKind());
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/JCasBuilderTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/JCasBuilderTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/JCasBuilderTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/JCasBuilderTest.java Thu Jan 10 23:12:33 2013
@@ -36,38 +36,38 @@ import org.junit.rules.TemporaryFolder;
/**
*/
public class JCasBuilderTest extends ComponentTestBase {
- @Rule
- public TemporaryFolder folder = new TemporaryFolder();
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
- @Test
- public void test() throws Exception {
- JCasBuilder jb = new JCasBuilder(jCas);
- jb.add("This sentence is not annotated. ");
- jb.add("But this sentences is annotated. ", Sentence.class);
- int begin = jb.getPosition();
- jb.add("And", Token.class);
- jb.add(" ");
- jb.add("here", Token.class);
- jb.add(" ");
- jb.add("every", Token.class);
- jb.add(" ");
- jb.add("token", Token.class);
- jb.add(" ");
- jb.add("is", Token.class);
- jb.add(".", Token.class);
- jb.add(begin, Sentence.class);
- jb.close();
+ @Test
+ public void test() throws Exception {
+ JCasBuilder jb = new JCasBuilder(jCas);
+ jb.add("This sentence is not annotated. ");
+ jb.add("But this sentences is annotated. ", Sentence.class);
+ int begin = jb.getPosition();
+ jb.add("And", Token.class);
+ jb.add(" ");
+ jb.add("here", Token.class);
+ jb.add(" ");
+ jb.add("every", Token.class);
+ jb.add(" ");
+ jb.add("token", Token.class);
+ jb.add(" ");
+ jb.add("is", Token.class);
+ jb.add(".", Token.class);
+ jb.add(begin, Sentence.class);
+ jb.close();
- File outputFile = new File(folder.getRoot(), "dump-output.txt");
- AnalysisEngine writer = createPrimitive(CASDumpWriter.class,
- CASDumpWriter.PARAM_OUTPUT_FILE, outputFile.getPath());
- writer.process(jb.getJCas());
+ File outputFile = new File(folder.getRoot(), "dump-output.txt");
+ AnalysisEngine writer = createPrimitive(CASDumpWriter.class, CASDumpWriter.PARAM_OUTPUT_FILE,
+ outputFile.getPath());
+ writer.process(jb.getJCas());
- String reference = readFileToString(
- new File("src/test/resources/data/reference/JCasBuilderTest.dump"), "UTF-8").trim();
- String actual = readFileToString(outputFile, "UTF-8").trim();
- actual = actual.replaceAll("\r\n", "\n");
+ String reference = readFileToString(
+ new File("src/test/resources/data/reference/JCasBuilderTest.dump"), "UTF-8").trim();
+ String actual = readFileToString(outputFile, "UTF-8").trim();
+ actual = actual.replaceAll("\r\n", "\n");
- assertEquals(reference, actual);
- }
+ assertEquals(reference, actual);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/JCasFactoryTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/JCasFactoryTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/JCasFactoryTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/JCasFactoryTest.java Thu Jan 10 23:12:33 2013
@@ -33,37 +33,37 @@ import org.junit.Test;
public class JCasFactoryTest extends ComponentTestBase {
- @Test
- public void testXMI() throws IOException {
- JCasFactory.loadJCas(jCas, "src/test/resources/data/docs/test.xmi");
- assertEquals("Me and all my friends are non-conformists.", jCas.getDocumentText());
- }
-
- @Test
- public void testXCAS() throws IOException {
- JCasFactory.loadJCas(jCas, "src/test/resources/data/docs/test.xcas", false);
- assertEquals(
- "... the more knowledge advances the more it becomes possible to condense it into little books.",
- jCas.getDocumentText());
- }
-
- @Test
- public void testFromPath() throws UIMAException {
- jCas = JCasFactory.createJCasFromPath(
- "src/test/resources/org/apache/uima/fit/type/AnalyzedText.xml",
- "src/test/resources/org/apache/uima/fit/type/Sentence.xml",
- "src/test/resources/org/apache/uima/fit/type/Token.xml");
- jCas.setDocumentText("For great 20 minute talks, check out TED.com.");
- AnnotationFactory.createAnnotation(jCas, 0, 3, Token.class);
- assertEquals("For", JCasUtil.selectByIndex(jCas, Token.class, 0).getCoveredText());
- }
-
- @Test
- public void testCreate() throws UIMAException {
- jCas = JCasFactory.createJCas();
- jCas.setDocumentText("For great 20 minute talks, check out TED.com.");
- AnnotationFactory.createAnnotation(jCas, 0, 3, Token.class);
- assertEquals("For", JCasUtil.selectByIndex(jCas, Token.class, 0).getCoveredText());
- }
+ @Test
+ public void testXMI() throws IOException {
+ JCasFactory.loadJCas(jCas, "src/test/resources/data/docs/test.xmi");
+ assertEquals("Me and all my friends are non-conformists.", jCas.getDocumentText());
+ }
+
+ @Test
+ public void testXCAS() throws IOException {
+ JCasFactory.loadJCas(jCas, "src/test/resources/data/docs/test.xcas", false);
+ assertEquals(
+ "... the more knowledge advances the more it becomes possible to condense it into little books.",
+ jCas.getDocumentText());
+ }
+
+ @Test
+ public void testFromPath() throws UIMAException {
+ jCas = JCasFactory.createJCasFromPath(
+ "src/test/resources/org/apache/uima/fit/type/AnalyzedText.xml",
+ "src/test/resources/org/apache/uima/fit/type/Sentence.xml",
+ "src/test/resources/org/apache/uima/fit/type/Token.xml");
+ jCas.setDocumentText("For great 20 minute talks, check out TED.com.");
+ AnnotationFactory.createAnnotation(jCas, 0, 3, Token.class);
+ assertEquals("For", JCasUtil.selectByIndex(jCas, Token.class, 0).getCoveredText());
+ }
+
+ @Test
+ public void testCreate() throws UIMAException {
+ jCas = JCasFactory.createJCas();
+ jCas.setDocumentText("For great 20 minute talks, check out TED.com.");
+ AnnotationFactory.createAnnotation(jCas, 0, 3, Token.class);
+ assertEquals("For", JCasUtil.selectByIndex(jCas, Token.class, 0).getCoveredText());
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/LoggingTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/LoggingTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/LoggingTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/LoggingTest.java Thu Jan 10 23:12:33 2013
@@ -57,257 +57,255 @@ import org.junit.Test;
/**
*/
public class LoggingTest {
- @Test
- public void testLogger() throws Exception {
- final List<LogRecord> records = new ArrayList<LogRecord>();
-
- // Tell the logger to log everything
- ConsoleHandler handler = (ConsoleHandler) LogManager.getLogManager().getLogger("").getHandlers()[0];
- java.util.logging.Level oldLevel = handler.getLevel();
- handler.setLevel(Level.ALL);
- // Capture the logging output without actually logging it
- handler.setFilter( new Filter() {
- public boolean isLoggable(LogRecord record) {
- records.add(record);
- return false;
- }
- });
-
- try {
- JCas jcas = JCasFactory.createJCas();
- createPrimitive(LoggingCasConsumerChristmasTree.class).process(jcas.getCas());
-
- assertEquals(10, records.size());
- assertEquals(Level.FINER, records.get(0).getLevel());
- assertEquals(Level.FINER, records.get(1).getLevel());
- assertEquals(Level.FINE, records.get(2).getLevel());
- assertEquals(Level.FINE, records.get(3).getLevel());
- assertEquals(Level.INFO, records.get(4).getLevel());
- assertEquals(Level.INFO, records.get(5).getLevel());
- assertEquals(Level.WARNING, records.get(6).getLevel());
- assertEquals(Level.WARNING, records.get(7).getLevel());
- assertEquals(Level.SEVERE, records.get(8).getLevel());
- assertEquals(Level.SEVERE, records.get(9).getLevel());
- }
- finally {
- if (oldLevel != null) {
- handler.setLevel(oldLevel);
- handler.setFilter(null);
- }
- }
- }
-
- @Test
- public void testAllKindsOfComponents() throws Exception {
- final List<LogRecord> records = new ArrayList<LogRecord>();
-
- // Tell the logger to log everything
- ConsoleHandler handler = (ConsoleHandler) LogManager.getLogManager().getLogger("").getHandlers()[0];
- java.util.logging.Level oldLevel = handler.getLevel();
- handler.setLevel(Level.ALL);
- handler.setFilter( new Filter() {
- public boolean isLoggable(LogRecord record) {
- records.add(record);
- return true;
- }
- });
-
- try {
- JCas jcas = JCasFactory.createJCas();
-
- createCollectionReader(LoggingCasCollectionReader.class).hasNext();
- assertLogDone(records);
-
- createCollectionReader(LoggingJCasCollectionReader.class).hasNext();
- assertLogDone(records);
-
-// createFlowControllerDescription(LoggingJCasFlowController.class).
-// assertLogDone(records);
-
- createPrimitive(LoggingCasAnnotator.class).process(jcas.getCas());
- assertLogDone(records);
-
- createPrimitive(LoggingJCasAnnotator.class).process(jcas);
- assertLogDone(records);
-
- createPrimitive(LoggingCasConsumer.class).process(jcas.getCas());
- assertLogDone(records);
-
- createPrimitive(LoggingJCasConsumer.class).process(jcas);
- assertLogDone(records);
-
- createPrimitive(LoggingCasMultiplier.class).process(jcas.getCas());
- assertLogDone(records);
-
- createPrimitive(LoggingJCasMultiplier.class).process(jcas);
- assertLogDone(records);
- }
- finally {
- if (oldLevel != null) {
- handler.setLevel(oldLevel);
- handler.setFilter(null);
- }
- }
- }
-
- private void assertLogDone(List<LogRecord> records)
- {
- assertEquals(1, records.size());
- assertEquals(Level.INFO, records.get(0).getLevel());
- records.clear();
- }
-
- public static class LoggingCasConsumerChristmasTree extends CasConsumer_ImplBase {
- @Override
- public void process(CAS aCAS) throws AnalysisEngineProcessException {
- getLogger().setLevel(org.apache.uima.util.Level.ALL);
- trigger();
- getLogger().setLevel(org.apache.uima.util.Level.OFF);
- trigger();
- }
-
- private void trigger()
- {
- if (getLogger().isTraceEnabled()) {
- getLogger().trace("Logging: " + getClass().getName());
- getLogger().trace("Logging: " + getClass().getName(), new IllegalArgumentException());
- }
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Logging: " + getClass().getName());
- getLogger().debug("Logging: " + getClass().getName(), new IllegalArgumentException());
- }
- if (getLogger().isInfoEnabled()) {
- getLogger().info("Logging: " + getClass().getName());
- getLogger().info("Logging: " + getClass().getName(), new IllegalArgumentException());
- }
- if (getLogger().isWarnEnabled()) {
- getLogger().warn("Logging: " + getClass().getName());
- getLogger().warn("Logging: " + getClass().getName(), new IllegalArgumentException());
- }
- if (getLogger().isErrorEnabled()) {
- getLogger().error("Logging: " + getClass().getName());
- getLogger().error("Logging: " + getClass().getName(), new IllegalArgumentException());
- }
- }
- }
-
- public static class LoggingCasMultiplier extends CasMultiplier_ImplBase {
-
- public boolean hasNext() throws AnalysisEngineProcessException {
- getLogger().info("Logging: " + getClass().getName());
- return false;
- }
-
- public AbstractCas next() throws AnalysisEngineProcessException {
- // Never called
- return null;
- }
-
- @Override
- public void process(CAS aCAS) throws AnalysisEngineProcessException {
- // Never called
- }
- }
-
- public static class LoggingJCasMultiplier extends JCasMultiplier_ImplBase {
- public boolean hasNext() throws AnalysisEngineProcessException {
- getLogger().info("Logging: " + getClass().getName());
- return false;
- }
-
- public AbstractCas next() throws AnalysisEngineProcessException {
- // Never called
- return null;
- }
-
- @Override
- public void process(JCas aJCas) throws AnalysisEngineProcessException {
- // Never called
- }
- }
-
- public static class LoggingJCasCollectionReader extends JCasCollectionReader_ImplBase {
- public boolean hasNext() throws IOException, CollectionException {
- getLogger().info("Logging: " + getClass().getName());
- return false;
- }
-
- public Progress[] getProgress() {
- return new Progress[0];
- }
-
- @Override
- public void getNext(JCas jCas) throws IOException, CollectionException {
- // Never called
- }
- }
-
- public static class LoggingResource extends Resource_ImplBase {
- @Override
- public boolean initialize(ResourceSpecifier aSpecifier,
- Map<String, Object> aAdditionalParams) throws ResourceInitializationException {
- boolean ret = super.initialize(aSpecifier, aAdditionalParams);
- getLogger().info("Logging: " + getClass().getName());
- return ret;
- }
- }
-
- public static class LoggingCasCollectionReader extends CasCollectionReader_ImplBase {
- public void getNext(CAS aCAS) throws IOException, CollectionException {
- // Never called
- }
-
- public boolean hasNext() throws IOException, CollectionException {
- getLogger().info("Logging: " + getClass().getName());
- return false;
- }
-
- public Progress[] getProgress() {
- return new Progress[0];
- }
- }
-
- public static class LoggingCasAnnotator extends CasAnnotator_ImplBase {
- @Override
- public void process(CAS aCAS) throws AnalysisEngineProcessException {
- getLogger().info("Logging: " + getClass().getName());
- }
- }
-
- public static class LoggingCasConsumer extends CasConsumer_ImplBase {
- @Override
- public void process(CAS aCAS) throws AnalysisEngineProcessException {
- getLogger().info("Logging: " + getClass().getName());
- }
- }
-
- public static class LoggingJCasAnnotator extends JCasAnnotator_ImplBase {
- @Override
- public void process(JCas aJCas) throws AnalysisEngineProcessException {
- getLogger().info("Logging: " + getClass().getName());
- }
- }
-
- public static class LoggingJCasConsumer extends JCasConsumer_ImplBase {
- @Override
- public void process(JCas aJCas) throws AnalysisEngineProcessException {
- getLogger().info("Logging: " + getClass().getName());
- }
- }
-
- public static class LoggingCasFlowController extends CasFlowController_ImplBase {
- @Override
- public Flow computeFlow(CAS aCAS) throws AnalysisEngineProcessException {
- getLogger().info("Logging: " + getClass().getName());
- return null;
- }
- }
-
- public static class LoggingJCasFlowController extends JCasFlowController_ImplBase {
- @Override
- public Flow computeFlow(JCas aJCas) throws AnalysisEngineProcessException {
- getLogger().info("Logging: " + getClass().getName());
- return null;
- }
- }
+ @Test
+ public void testLogger() throws Exception {
+ final List<LogRecord> records = new ArrayList<LogRecord>();
+
+ // Tell the logger to log everything
+ ConsoleHandler handler = (ConsoleHandler) LogManager.getLogManager().getLogger("")
+ .getHandlers()[0];
+ java.util.logging.Level oldLevel = handler.getLevel();
+ handler.setLevel(Level.ALL);
+ // Capture the logging output without actually logging it
+ handler.setFilter(new Filter() {
+ public boolean isLoggable(LogRecord record) {
+ records.add(record);
+ return false;
+ }
+ });
+
+ try {
+ JCas jcas = JCasFactory.createJCas();
+ createPrimitive(LoggingCasConsumerChristmasTree.class).process(jcas.getCas());
+
+ assertEquals(10, records.size());
+ assertEquals(Level.FINER, records.get(0).getLevel());
+ assertEquals(Level.FINER, records.get(1).getLevel());
+ assertEquals(Level.FINE, records.get(2).getLevel());
+ assertEquals(Level.FINE, records.get(3).getLevel());
+ assertEquals(Level.INFO, records.get(4).getLevel());
+ assertEquals(Level.INFO, records.get(5).getLevel());
+ assertEquals(Level.WARNING, records.get(6).getLevel());
+ assertEquals(Level.WARNING, records.get(7).getLevel());
+ assertEquals(Level.SEVERE, records.get(8).getLevel());
+ assertEquals(Level.SEVERE, records.get(9).getLevel());
+ } finally {
+ if (oldLevel != null) {
+ handler.setLevel(oldLevel);
+ handler.setFilter(null);
+ }
+ }
+ }
+
+ @Test
+ public void testAllKindsOfComponents() throws Exception {
+ final List<LogRecord> records = new ArrayList<LogRecord>();
+
+ // Tell the logger to log everything
+ ConsoleHandler handler = (ConsoleHandler) LogManager.getLogManager().getLogger("")
+ .getHandlers()[0];
+ java.util.logging.Level oldLevel = handler.getLevel();
+ handler.setLevel(Level.ALL);
+ handler.setFilter(new Filter() {
+ public boolean isLoggable(LogRecord record) {
+ records.add(record);
+ return true;
+ }
+ });
+
+ try {
+ JCas jcas = JCasFactory.createJCas();
+
+ createCollectionReader(LoggingCasCollectionReader.class).hasNext();
+ assertLogDone(records);
+
+ createCollectionReader(LoggingJCasCollectionReader.class).hasNext();
+ assertLogDone(records);
+
+ // createFlowControllerDescription(LoggingJCasFlowController.class).
+ // assertLogDone(records);
+
+ createPrimitive(LoggingCasAnnotator.class).process(jcas.getCas());
+ assertLogDone(records);
+
+ createPrimitive(LoggingJCasAnnotator.class).process(jcas);
+ assertLogDone(records);
+
+ createPrimitive(LoggingCasConsumer.class).process(jcas.getCas());
+ assertLogDone(records);
+
+ createPrimitive(LoggingJCasConsumer.class).process(jcas);
+ assertLogDone(records);
+
+ createPrimitive(LoggingCasMultiplier.class).process(jcas.getCas());
+ assertLogDone(records);
+
+ createPrimitive(LoggingJCasMultiplier.class).process(jcas);
+ assertLogDone(records);
+ } finally {
+ if (oldLevel != null) {
+ handler.setLevel(oldLevel);
+ handler.setFilter(null);
+ }
+ }
+ }
+
+ private void assertLogDone(List<LogRecord> records) {
+ assertEquals(1, records.size());
+ assertEquals(Level.INFO, records.get(0).getLevel());
+ records.clear();
+ }
+
+ public static class LoggingCasConsumerChristmasTree extends CasConsumer_ImplBase {
+ @Override
+ public void process(CAS aCAS) throws AnalysisEngineProcessException {
+ getLogger().setLevel(org.apache.uima.util.Level.ALL);
+ trigger();
+ getLogger().setLevel(org.apache.uima.util.Level.OFF);
+ trigger();
+ }
+
+ private void trigger() {
+ if (getLogger().isTraceEnabled()) {
+ getLogger().trace("Logging: " + getClass().getName());
+ getLogger().trace("Logging: " + getClass().getName(), new IllegalArgumentException());
+ }
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Logging: " + getClass().getName());
+ getLogger().debug("Logging: " + getClass().getName(), new IllegalArgumentException());
+ }
+ if (getLogger().isInfoEnabled()) {
+ getLogger().info("Logging: " + getClass().getName());
+ getLogger().info("Logging: " + getClass().getName(), new IllegalArgumentException());
+ }
+ if (getLogger().isWarnEnabled()) {
+ getLogger().warn("Logging: " + getClass().getName());
+ getLogger().warn("Logging: " + getClass().getName(), new IllegalArgumentException());
+ }
+ if (getLogger().isErrorEnabled()) {
+ getLogger().error("Logging: " + getClass().getName());
+ getLogger().error("Logging: " + getClass().getName(), new IllegalArgumentException());
+ }
+ }
+ }
+
+ public static class LoggingCasMultiplier extends CasMultiplier_ImplBase {
+
+ public boolean hasNext() throws AnalysisEngineProcessException {
+ getLogger().info("Logging: " + getClass().getName());
+ return false;
+ }
+
+ public AbstractCas next() throws AnalysisEngineProcessException {
+ // Never called
+ return null;
+ }
+
+ @Override
+ public void process(CAS aCAS) throws AnalysisEngineProcessException {
+ // Never called
+ }
+ }
+
+ public static class LoggingJCasMultiplier extends JCasMultiplier_ImplBase {
+ public boolean hasNext() throws AnalysisEngineProcessException {
+ getLogger().info("Logging: " + getClass().getName());
+ return false;
+ }
+
+ public AbstractCas next() throws AnalysisEngineProcessException {
+ // Never called
+ return null;
+ }
+
+ @Override
+ public void process(JCas aJCas) throws AnalysisEngineProcessException {
+ // Never called
+ }
+ }
+
+ public static class LoggingJCasCollectionReader extends JCasCollectionReader_ImplBase {
+ public boolean hasNext() throws IOException, CollectionException {
+ getLogger().info("Logging: " + getClass().getName());
+ return false;
+ }
+
+ public Progress[] getProgress() {
+ return new Progress[0];
+ }
+
+ @Override
+ public void getNext(JCas jCas) throws IOException, CollectionException {
+ // Never called
+ }
+ }
+
+ public static class LoggingResource extends Resource_ImplBase {
+ @Override
+ public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
+ throws ResourceInitializationException {
+ boolean ret = super.initialize(aSpecifier, aAdditionalParams);
+ getLogger().info("Logging: " + getClass().getName());
+ return ret;
+ }
+ }
+
+ public static class LoggingCasCollectionReader extends CasCollectionReader_ImplBase {
+ public void getNext(CAS aCAS) throws IOException, CollectionException {
+ // Never called
+ }
+
+ public boolean hasNext() throws IOException, CollectionException {
+ getLogger().info("Logging: " + getClass().getName());
+ return false;
+ }
+
+ public Progress[] getProgress() {
+ return new Progress[0];
+ }
+ }
+
+ public static class LoggingCasAnnotator extends CasAnnotator_ImplBase {
+ @Override
+ public void process(CAS aCAS) throws AnalysisEngineProcessException {
+ getLogger().info("Logging: " + getClass().getName());
+ }
+ }
+
+ public static class LoggingCasConsumer extends CasConsumer_ImplBase {
+ @Override
+ public void process(CAS aCAS) throws AnalysisEngineProcessException {
+ getLogger().info("Logging: " + getClass().getName());
+ }
+ }
+
+ public static class LoggingJCasAnnotator extends JCasAnnotator_ImplBase {
+ @Override
+ public void process(JCas aJCas) throws AnalysisEngineProcessException {
+ getLogger().info("Logging: " + getClass().getName());
+ }
+ }
+
+ public static class LoggingJCasConsumer extends JCasConsumer_ImplBase {
+ @Override
+ public void process(JCas aJCas) throws AnalysisEngineProcessException {
+ getLogger().info("Logging: " + getClass().getName());
+ }
+ }
+
+ public static class LoggingCasFlowController extends CasFlowController_ImplBase {
+ @Override
+ public Flow computeFlow(CAS aCAS) throws AnalysisEngineProcessException {
+ getLogger().info("Logging: " + getClass().getName());
+ return null;
+ }
+ }
+
+ public static class LoggingJCasFlowController extends JCasFlowController_ImplBase {
+ @Override
+ public Flow computeFlow(JCas aJCas) throws AnalysisEngineProcessException {
+ getLogger().info("Logging: " + getClass().getName());
+ return null;
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/ResourceCreationSpecifierFactoryTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/ResourceCreationSpecifierFactoryTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/ResourceCreationSpecifierFactoryTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/ResourceCreationSpecifierFactoryTest.java Thu Jan 10 23:12:33 2013
@@ -29,28 +29,28 @@ import org.junit.Test;
public class ResourceCreationSpecifierFactoryTest {
- @Test(expected = IllegalArgumentException.class)
- public void test4() throws Exception {
- ResourceCreationSpecifierFactory.createResourceCreationSpecifier(
- "src/main/resources/org/apache/uima/fit/component/NoOpAnnotator.xml",
- new String[] { "test" });
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void test4() throws Exception {
+ ResourceCreationSpecifierFactory.createResourceCreationSpecifier(
+ "src/main/resources/org/apache/uima/fit/component/NoOpAnnotator.xml",
+ new String[] { "test" });
+ }
- @Test(expected = IllegalArgumentException.class)
- public void test3() throws Exception {
- UimaContextFactory.createUimaContext("test");
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void test3() throws Exception {
+ UimaContextFactory.createUimaContext("test");
+ }
- @Test(expected = IllegalArgumentException.class)
- public void test2() throws Exception {
- ResourceCreationSpecifierFactory.createResourceCreationSpecifier(
- "src/main/resources/org/apache/uima/fit/component/NoOpAnnotator.xml",
- new Object[] { "test", new Point(0, 5) });
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void test2() throws Exception {
+ ResourceCreationSpecifierFactory.createResourceCreationSpecifier(
+ "src/main/resources/org/apache/uima/fit/component/NoOpAnnotator.xml", new Object[] {
+ "test", new Point(0, 5) });
+ }
- @Test(expected = IllegalArgumentException.class)
- public void test1() {
- ResourceCreationSpecifierFactory.setConfigurationParameters(
- (ResourceCreationSpecifier) null, ParameterizedAE.PARAM_BOOLEAN_1);
- }
+ @Test(expected = IllegalArgumentException.class)
+ public void test1() {
+ ResourceCreationSpecifierFactory.setConfigurationParameters((ResourceCreationSpecifier) null,
+ ParameterizedAE.PARAM_BOOLEAN_1);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/SofaMappingFactoryTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/SofaMappingFactoryTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/SofaMappingFactoryTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/SofaMappingFactoryTest.java Thu Jan 10 23:12:33 2013
@@ -29,13 +29,12 @@ import org.junit.Test;
public class SofaMappingFactoryTest {
- @Test
- public void test() {
- SofaMapping sofaMapping = SofaMappingFactory.createSofaMapping(NoOpAnnotator.class,
- "B", "A");
+ @Test
+ public void test() {
+ SofaMapping sofaMapping = SofaMappingFactory.createSofaMapping(NoOpAnnotator.class, "B", "A");
- assertEquals("A", sofaMapping.getAggregateSofaName());
- assertEquals(NoOpAnnotator.class.getName(), sofaMapping.getComponentKey());
- assertEquals("B", sofaMapping.getComponentSofaName());
- }
+ assertEquals("A", sofaMapping.getAggregateSofaName());
+ assertEquals(NoOpAnnotator.class.getName(), sofaMapping.getComponentKey());
+ assertEquals("B", sofaMapping.getComponentSofaName());
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/TypePrioritiesFactoryTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/TypePrioritiesFactoryTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/TypePrioritiesFactoryTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/TypePrioritiesFactoryTest.java Thu Jan 10 23:12:33 2013
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.uima.fit.factory;
import static org.apache.uima.fit.factory.TypePrioritiesFactory.createTypePriorities;
@@ -31,18 +30,18 @@ import org.junit.Test;
/**
* Tests for the {@link TypePrioritiesFactory}.
- *
+ *
*/
public class TypePrioritiesFactoryTest {
- @Test
- public void testCreateTypePrioritiesClassOfQArray() throws Exception {
- TypePriorities prio = createTypePriorities(Annotation.class);
-
- CasCreationUtils.createCas(createTypeSystemDescription(), prio, null);
-
- assertEquals(1, prio.getPriorityLists().length);
- assertEquals(1, prio.getPriorityLists()[0].getTypes().length);
- assertEquals("uima.tcas.Annotation", prio.getPriorityLists()[0].getTypes()[0]);
- }
+ @Test
+ public void testCreateTypePrioritiesClassOfQArray() throws Exception {
+ TypePriorities prio = createTypePriorities(Annotation.class);
+
+ CasCreationUtils.createCas(createTypeSystemDescription(), prio, null);
+
+ assertEquals(1, prio.getPriorityLists().length);
+ assertEquals(1, prio.getPriorityLists()[0].getTypes().length);
+ assertEquals("uima.tcas.Annotation", prio.getPriorityLists()[0].getTypes()[0]);
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/TypeSystemDescriptionFactoryTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/TypeSystemDescriptionFactoryTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/TypeSystemDescriptionFactoryTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/TypeSystemDescriptionFactoryTest.java Thu Jan 10 23:12:33 2013
@@ -18,7 +18,6 @@
*/
package org.apache.uima.fit.factory;
-
import static org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription;
import static org.junit.Assert.assertNotNull;
@@ -31,19 +30,19 @@ import org.junit.Test;
/**
*/
public class TypeSystemDescriptionFactoryTest {
- @Test
- public void testFromPath() throws Exception {
- TypeSystemDescriptionFactory.createTypeSystemDescriptionFromPath(
- "src/test/resources/org/apache/uima/fit/type/AnalyzedText.xml",
- "src/test/resources/org/apache/uima/fit/type/Sentence.xml",
- "src/test/resources/org/apache/uima/fit/type/Token.xml").resolveImports();
- }
+ @Test
+ public void testFromPath() throws Exception {
+ TypeSystemDescriptionFactory.createTypeSystemDescriptionFromPath(
+ "src/test/resources/org/apache/uima/fit/type/AnalyzedText.xml",
+ "src/test/resources/org/apache/uima/fit/type/Sentence.xml",
+ "src/test/resources/org/apache/uima/fit/type/Token.xml").resolveImports();
+ }
- @Test
- public void testScanning() throws Exception {
- TypeSystemDescription tsd = createTypeSystemDescription();
- assertNotNull(tsd.getType(Token.class.getName()));
- assertNotNull(tsd.getType(Sentence.class.getName()));
- assertNotNull(tsd.getType(AnalyzedText.class.getName()));
- }
+ @Test
+ public void testScanning() throws Exception {
+ TypeSystemDescription tsd = createTypeSystemDescription();
+ assertNotNull(tsd.getType(Token.class.getName()));
+ assertNotNull(tsd.getType(Sentence.class.getName()));
+ assertNotNull(tsd.getType(AnalyzedText.class.getName()));
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/UimaContextFactoryTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/UimaContextFactoryTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/UimaContextFactoryTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/UimaContextFactoryTest.java Thu Jan 10 23:12:33 2013
@@ -29,42 +29,42 @@ import org.junit.Test;
public class UimaContextFactoryTest {
- @Test
- public void test() throws ResourceInitializationException {
- UimaContext context = UimaContextFactory.createUimaContext("myBoolean", true, "myBooleans",
- new Boolean[] { true, false, true, false }, "myFloat", 1.0f, "myFloats",
- new Float[] { 2.0f, 2.1f, 3.0f }, "myInt", 1, "myInts", new Integer[] { 2, 3, 4 },
- "myString", "yourString", "myStrings", new String[] { "yourString1", "yourString2",
- "yourString3" });
- assertEquals(true, context.getConfigParameterValue("myBoolean"));
- Boolean[] myBooleans = (Boolean[]) context.getConfigParameterValue("myBooleans");
- assertEquals(4, myBooleans.length);
- assertEquals(true, myBooleans[0]);
- assertEquals(false, myBooleans[1]);
- assertEquals(true, myBooleans[2]);
- assertEquals(false, myBooleans[3]);
-
- assertEquals(1.0f, context.getConfigParameterValue("myFloat"));
- Float[] myFloats = (Float[]) context.getConfigParameterValue("myFloats");
- assertEquals(3, myFloats.length);
- assertEquals(2.0d, myFloats[0].doubleValue(), 0.001d);
- assertEquals(2.1d, myFloats[1].doubleValue(), 0.001d);
- assertEquals(3.0d, myFloats[2].doubleValue(), 0.001d);
-
- assertEquals(1, context.getConfigParameterValue("myInt"));
- Integer[] myInts = (Integer[]) context.getConfigParameterValue("myInts");
- assertEquals(3, myInts.length);
- assertEquals(2L, myInts[0].longValue());
- assertEquals(3L, myInts[1].longValue());
- assertEquals(4L, myInts[2].longValue());
-
- assertEquals("yourString", context.getConfigParameterValue("myString"));
- String[] myStrings = (String[]) context.getConfigParameterValue("myStrings");
- assertEquals(3, myStrings.length);
- assertEquals("yourString1", myStrings[0]);
- assertEquals("yourString2", myStrings[1]);
- assertEquals("yourString3", myStrings[2]);
+ @Test
+ public void test() throws ResourceInitializationException {
+ UimaContext context = UimaContextFactory
+ .createUimaContext("myBoolean", true, "myBooleans", new Boolean[] { true, false, true,
+ false }, "myFloat", 1.0f, "myFloats", new Float[] { 2.0f, 2.1f, 3.0f }, "myInt", 1,
+ "myInts", new Integer[] { 2, 3, 4 }, "myString", "yourString", "myStrings",
+ new String[] { "yourString1", "yourString2", "yourString3" });
+ assertEquals(true, context.getConfigParameterValue("myBoolean"));
+ Boolean[] myBooleans = (Boolean[]) context.getConfigParameterValue("myBooleans");
+ assertEquals(4, myBooleans.length);
+ assertEquals(true, myBooleans[0]);
+ assertEquals(false, myBooleans[1]);
+ assertEquals(true, myBooleans[2]);
+ assertEquals(false, myBooleans[3]);
+
+ assertEquals(1.0f, context.getConfigParameterValue("myFloat"));
+ Float[] myFloats = (Float[]) context.getConfigParameterValue("myFloats");
+ assertEquals(3, myFloats.length);
+ assertEquals(2.0d, myFloats[0].doubleValue(), 0.001d);
+ assertEquals(2.1d, myFloats[1].doubleValue(), 0.001d);
+ assertEquals(3.0d, myFloats[2].doubleValue(), 0.001d);
+
+ assertEquals(1, context.getConfigParameterValue("myInt"));
+ Integer[] myInts = (Integer[]) context.getConfigParameterValue("myInts");
+ assertEquals(3, myInts.length);
+ assertEquals(2L, myInts[0].longValue());
+ assertEquals(3L, myInts[1].longValue());
+ assertEquals(4L, myInts[2].longValue());
+
+ assertEquals("yourString", context.getConfigParameterValue("myString"));
+ String[] myStrings = (String[]) context.getConfigParameterValue("myStrings");
+ assertEquals(3, myStrings.length);
+ assertEquals("yourString1", myStrings[0]);
+ assertEquals("yourString2", myStrings[1]);
+ assertEquals("yourString3", myStrings[2]);
- }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/initializable/InitializableFactoryTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/initializable/InitializableFactoryTest.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/initializable/InitializableFactoryTest.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/initializable/InitializableFactoryTest.java Thu Jan 10 23:12:33 2013
@@ -36,105 +36,107 @@ import org.junit.Test;
*/
public class InitializableFactoryTest {
- @Test
- public void testInitializableFactory() throws Exception {
- UimaContext context = UimaContextFactory.createUimaContext(
- InitializableClass.PARAM_BOOLEAN_PARAMETER, true);
- InitializableClass ic = InitializableFactory.create(context, InitializableClass.class);
- assertTrue(ic.booleanParameter);
-
- NotInitializableClass nic = InitializableFactory.create(context,
- NotInitializableClass.class);
- assertFalse(nic.booleanParameter);
-
- context = UimaContextFactory.createUimaContext(
- InitializableFileNamer.PARAM_STRING_PARAMETER, "goodbye");
- String className = InitializableFileNamer.class.getName();
- XWriterFileNamer fn = InitializableFactory.create(context, className,
- XWriterFileNamer.class);
- assertEquals("goodbye", ((InitializableFileNamer) fn).stringParameter);
-
- className = NotInitializableFileNamer.class.getName();
- fn = InitializableFactory.create(context, className, XWriterFileNamer.class);
- assertEquals("hello", ((NotInitializableFileNamer) fn).stringParameter);
-
- }
-
- @Test(expected = ResourceInitializationException.class)
- public void testBadClass() throws ResourceInitializationException {
- UimaContext context = UimaContextFactory.createUimaContext(
- InitializableClass.PARAM_BOOLEAN_PARAMETER, true);
- InitializableFactory.create(context, NotInitializableClass.class.getName(),
- XWriterFileNamer.class);
- }
-
- @Test(expected = ResourceInitializationException.class)
- public void testBadConstructor() throws ResourceInitializationException {
- UimaContext context = UimaContextFactory.createUimaContext(
- InitializableClass.PARAM_BOOLEAN_PARAMETER, true);
- InitializableFactory.create(context, NoDefaultConstructor.class);
- }
-
- public static class InitializableClass implements Initializable {
-
- public static final String PARAM_BOOLEAN_PARAMETER = ConfigurationParameterFactory
- .createConfigurationParameterName(InitializableClass.class, "booleanParameter");
- @ConfigurationParameter
- public boolean booleanParameter = false;
-
- public void initialize(UimaContext context) throws ResourceInitializationException {
- ConfigurationParameterInitializer.initialize(this, context);
- }
- }
-
- public static class NotInitializableClass {
-
- public static final String PARAM_BOOLEAN_PARAMETER = ConfigurationParameterFactory
- .createConfigurationParameterName(InitializableClass.class, "booleanParameter");
- @ConfigurationParameter
- public boolean booleanParameter = false;
-
- public void initialize(UimaContext context) throws ResourceInitializationException {
- ConfigurationParameterInitializer.initialize(this, context);
- }
- }
-
- public static class InitializableFileNamer implements Initializable, XWriterFileNamer {
-
- public static final String PARAM_STRING_PARAMETER = ConfigurationParameterFactory
- .createConfigurationParameterName(InitializableFileNamer.class, "stringParameter");
- @ConfigurationParameter
- public String stringParameter = "hello";
-
- public void initialize(UimaContext context) throws ResourceInitializationException {
- ConfigurationParameterInitializer.initialize(this, context);
- }
-
- public String nameFile(JCas jCas) {
- return "some_name_for_this_jcas.xmi";
- }
- }
-
- public static class NotInitializableFileNamer implements XWriterFileNamer {
-
- public static final String PARAM_STRING_PARAMETER = ConfigurationParameterFactory
- .createConfigurationParameterName(InitializableFileNamer.class, "stringParameter");
- @ConfigurationParameter
- public String stringParameter = "hello";
-
- public void initialize(UimaContext context) throws ResourceInitializationException {
- ConfigurationParameterInitializer.initialize(this, context);
- }
-
- public String nameFile(JCas jCas) {
- return "some_name_for_this_jcas.xmi";
- }
- }
-
- public static class NoDefaultConstructor {
- public NoDefaultConstructor(String s) {
- // do nothing
- }
- }
+ @Test
+ public void testInitializableFactory() throws Exception {
+ UimaContext context = UimaContextFactory.createUimaContext(
+ InitializableClass.PARAM_BOOLEAN_PARAMETER, true);
+ InitializableClass ic = InitializableFactory.create(context, InitializableClass.class);
+ assertTrue(ic.booleanParameter);
+
+ NotInitializableClass nic = InitializableFactory.create(context, NotInitializableClass.class);
+ assertFalse(nic.booleanParameter);
+
+ context = UimaContextFactory.createUimaContext(InitializableFileNamer.PARAM_STRING_PARAMETER,
+ "goodbye");
+ String className = InitializableFileNamer.class.getName();
+ XWriterFileNamer fn = InitializableFactory.create(context, className, XWriterFileNamer.class);
+ assertEquals("goodbye", ((InitializableFileNamer) fn).stringParameter);
+
+ className = NotInitializableFileNamer.class.getName();
+ fn = InitializableFactory.create(context, className, XWriterFileNamer.class);
+ assertEquals("hello", ((NotInitializableFileNamer) fn).stringParameter);
+
+ }
+
+ @Test(expected = ResourceInitializationException.class)
+ public void testBadClass() throws ResourceInitializationException {
+ UimaContext context = UimaContextFactory.createUimaContext(
+ InitializableClass.PARAM_BOOLEAN_PARAMETER, true);
+ InitializableFactory.create(context, NotInitializableClass.class.getName(),
+ XWriterFileNamer.class);
+ }
+
+ @Test(expected = ResourceInitializationException.class)
+ public void testBadConstructor() throws ResourceInitializationException {
+ UimaContext context = UimaContextFactory.createUimaContext(
+ InitializableClass.PARAM_BOOLEAN_PARAMETER, true);
+ InitializableFactory.create(context, NoDefaultConstructor.class);
+ }
+
+ public static class InitializableClass implements Initializable {
+
+ public static final String PARAM_BOOLEAN_PARAMETER = ConfigurationParameterFactory
+ .createConfigurationParameterName(InitializableClass.class, "booleanParameter");
+
+ @ConfigurationParameter
+ public boolean booleanParameter = false;
+
+ public void initialize(UimaContext context) throws ResourceInitializationException {
+ ConfigurationParameterInitializer.initialize(this, context);
+ }
+ }
+
+ public static class NotInitializableClass {
+
+ public static final String PARAM_BOOLEAN_PARAMETER = ConfigurationParameterFactory
+ .createConfigurationParameterName(InitializableClass.class, "booleanParameter");
+
+ @ConfigurationParameter
+ public boolean booleanParameter = false;
+
+ public void initialize(UimaContext context) throws ResourceInitializationException {
+ ConfigurationParameterInitializer.initialize(this, context);
+ }
+ }
+
+ public static class InitializableFileNamer implements Initializable, XWriterFileNamer {
+
+ public static final String PARAM_STRING_PARAMETER = ConfigurationParameterFactory
+ .createConfigurationParameterName(InitializableFileNamer.class, "stringParameter");
+
+ @ConfigurationParameter
+ public String stringParameter = "hello";
+
+ public void initialize(UimaContext context) throws ResourceInitializationException {
+ ConfigurationParameterInitializer.initialize(this, context);
+ }
+
+ public String nameFile(JCas jCas) {
+ return "some_name_for_this_jcas.xmi";
+ }
+ }
+
+ public static class NotInitializableFileNamer implements XWriterFileNamer {
+
+ public static final String PARAM_STRING_PARAMETER = ConfigurationParameterFactory
+ .createConfigurationParameterName(InitializableFileNamer.class, "stringParameter");
+
+ @ConfigurationParameter
+ public String stringParameter = "hello";
+
+ public void initialize(UimaContext context) throws ResourceInitializationException {
+ ConfigurationParameterInitializer.initialize(this, context);
+ }
+
+ public String nameFile(JCas jCas) {
+ return "some_name_for_this_jcas.xmi";
+ }
+ }
+
+ public static class NoDefaultConstructor {
+ public NoDefaultConstructor(String s) {
+ // do nothing
+ }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator1.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator1.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator1.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator1.java Thu Jan 10 23:12:33 2013
@@ -32,20 +32,19 @@ import org.apache.uima.jcas.JCas;
@SofaCapability(inputSofas = CAS.NAME_DEFAULT_SOFA, outputSofas = ViewNames.PARENTHESES_VIEW)
public class Annotator1 extends JCasAnnotator_ImplBase {
- @Override
- public void process(JCas jCas) throws AnalysisEngineProcessException {
- try {
- JCas parentheticalView = ViewCreatorAnnotator.createViewSafely(jCas,
- ViewNames.PARENTHESES_VIEW);
- jCas = jCas.getView(CAS.NAME_DEFAULT_SOFA);
- String initialText = jCas.getDocumentText();
- String parentheticalText = initialText.replaceAll("[aeiou]+", "($0)");
- parentheticalView.setDocumentText(parentheticalText);
- }
- catch (CASException e) {
- throw new AnalysisEngineProcessException(e);
- }
+ @Override
+ public void process(JCas jCas) throws AnalysisEngineProcessException {
+ try {
+ JCas parentheticalView = ViewCreatorAnnotator.createViewSafely(jCas,
+ ViewNames.PARENTHESES_VIEW);
+ jCas = jCas.getView(CAS.NAME_DEFAULT_SOFA);
+ String initialText = jCas.getDocumentText();
+ String parentheticalText = initialText.replaceAll("[aeiou]+", "($0)");
+ parentheticalView.setDocumentText(parentheticalText);
+ } catch (CASException e) {
+ throw new AnalysisEngineProcessException(e);
+ }
- }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator2.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator2.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator2.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator2.java Thu Jan 10 23:12:33 2013
@@ -32,34 +32,32 @@ import org.apache.uima.jcas.JCas;
*/
@SofaCapability(inputSofas = { CAS.NAME_DEFAULT_SOFA, ViewNames.PARENTHESES_VIEW }, outputSofas = {
- ViewNames.SORTED_VIEW, ViewNames.SORTED_PARENTHESES_VIEW })
+ ViewNames.SORTED_VIEW, ViewNames.SORTED_PARENTHESES_VIEW })
public class Annotator2 extends JCasAnnotator_ImplBase {
- @Override
- public void process(JCas jCas) throws AnalysisEngineProcessException {
- try {
- JCas sortedView = ViewCreatorAnnotator.createViewSafely(jCas, ViewNames.SORTED_VIEW);
- jCas = jCas.getView(CAS.NAME_DEFAULT_SOFA);
- String initialText = jCas.getDocumentText();
- char[] chars = initialText.toCharArray();
- Arrays.sort(chars);
- String sortedText = new String(chars).trim();
- sortedView.setDocumentText(sortedText);
-
- sortedView = ViewCreatorAnnotator.createViewSafely(jCas,
- ViewNames.SORTED_PARENTHESES_VIEW);
- JCas parenthesesView = jCas.getView(ViewNames.PARENTHESES_VIEW);
- String parenthesesText = parenthesesView.getDocumentText();
- chars = parenthesesText.toCharArray();
- Arrays.sort(chars);
- sortedText = new String(chars).trim();
- sortedView.setDocumentText(sortedText);
-
- }
- catch (CASException e) {
- throw new AnalysisEngineProcessException(e);
- }
+ @Override
+ public void process(JCas jCas) throws AnalysisEngineProcessException {
+ try {
+ JCas sortedView = ViewCreatorAnnotator.createViewSafely(jCas, ViewNames.SORTED_VIEW);
+ jCas = jCas.getView(CAS.NAME_DEFAULT_SOFA);
+ String initialText = jCas.getDocumentText();
+ char[] chars = initialText.toCharArray();
+ Arrays.sort(chars);
+ String sortedText = new String(chars).trim();
+ sortedView.setDocumentText(sortedText);
+
+ sortedView = ViewCreatorAnnotator.createViewSafely(jCas, ViewNames.SORTED_PARENTHESES_VIEW);
+ JCas parenthesesView = jCas.getView(ViewNames.PARENTHESES_VIEW);
+ String parenthesesText = parenthesesView.getDocumentText();
+ chars = parenthesesText.toCharArray();
+ Arrays.sort(chars);
+ sortedText = new String(chars).trim();
+ sortedView.setDocumentText(sortedText);
+
+ } catch (CASException e) {
+ throw new AnalysisEngineProcessException(e);
+ }
- }
+ }
}
Modified: uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator3.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator3.java?rev=1431721&r1=1431720&r2=1431721&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator3.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit/src/test/java/org/apache/uima/fit/factory/testAes/Annotator3.java Thu Jan 10 23:12:33 2013
@@ -31,28 +31,27 @@ import org.apache.uima.jcas.JCas;
@SofaCapability(inputSofas = CAS.NAME_DEFAULT_SOFA, outputSofas = ViewNames.REVERSE_VIEW)
public class Annotator3 extends JCasAnnotator_ImplBase {
- @Override
- public void process(JCas jCas) throws AnalysisEngineProcessException {
- try {
- jCas = jCas.getView(CAS.NAME_DEFAULT_SOFA);
- String text = jCas.getDocumentText();
- String reverseText = reverse(text);
- JCas reverseView = ViewCreatorAnnotator.createViewSafely(jCas, ViewNames.REVERSE_VIEW);
- reverseView.setDocumentText(reverseText);
- }
- catch (CASException e) {
- throw new AnalysisEngineProcessException(e);
- }
- }
+ @Override
+ public void process(JCas jCas) throws AnalysisEngineProcessException {
+ try {
+ jCas = jCas.getView(CAS.NAME_DEFAULT_SOFA);
+ String text = jCas.getDocumentText();
+ String reverseText = reverse(text);
+ JCas reverseView = ViewCreatorAnnotator.createViewSafely(jCas, ViewNames.REVERSE_VIEW);
+ reverseView.setDocumentText(reverseText);
+ } catch (CASException e) {
+ throw new AnalysisEngineProcessException(e);
+ }
+ }
- private String reverse(String string) {
- int stringLength = string.length();
- StringBuffer returnValue = new StringBuffer();
+ private String reverse(String string) {
+ int stringLength = string.length();
+ StringBuffer returnValue = new StringBuffer();
- for (int i = stringLength - 1; i >= 0; i--) {
- returnValue.append(string.charAt(i));
- }
- return returnValue.toString();
- }
+ for (int i = stringLength - 1; i >= 0; i--) {
+ returnValue.append(string.charAt(i));
+ }
+ return returnValue.toString();
+ }
}