_testInvalidDescriptor(JUnitExtension
.getFile("TextAnalysisEngineImplTest/InvalidConfigParams" + i + ".xml"));
}
// try a descriptor with configuration parameter overrides - should work
XMLInputSource in = new XMLInputSource(JUnitExtension
.getFile("TextAnalysisEngineImplTest/AggregateTaeWithConfigParamOverrides.xml"));
AnalysisEngineDescription desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
AggregateAnalysisEngine_impl ae = new AggregateAnalysisEngine_impl();
ae.initialize(desc, Collections.EMPTY_MAP);
PrimitiveAnalysisEngine_impl delegate1 = (PrimitiveAnalysisEngine_impl) ae._getASB()
.getComponentAnalysisEngines().get("Annotator1");
PrimitiveAnalysisEngine_impl delegate2 = (PrimitiveAnalysisEngine_impl) ae._getASB()
.getComponentAnalysisEngines().get("Annotator2");
FlowControllerContainer flowController = ((ASB_impl) ae._getASB())
.getFlowControllerContainer();
String strVal1 = (String) delegate1.getUimaContext().getConfigParameterValue("en",
"StringParam");
Assert.assertEquals("override", strVal1);
String strVal2 = (String) delegate2.getUimaContext().getConfigParameterValue("en",
"StringParam");
Assert.assertEquals("en", strVal2);
String strVal3 = (String) flowController.getUimaContext().getConfigParameterValue("en",
"StringParam");
Assert.assertEquals("en", strVal3);
Integer intVal1 = (Integer) delegate1.getUimaContext().getConfigParameterValue("en",
"IntegerParam");
Assert.assertEquals(100, intVal1.intValue());
Integer intVal2 = (Integer) delegate2.getUimaContext().getConfigParameterValue("en",
"IntegerParam");
Assert.assertEquals(100, intVal2.intValue());
Integer intVal3 = (Integer) flowController.getUimaContext().getConfigParameterValue("en",
"IntegerParam");
Assert.assertEquals(100, intVal3.intValue());
String[] strArrVal1 = (String[]) delegate1.getUimaContext().getConfigParameterValue("en",
"StringArrayParam");
Assert.assertEquals(Arrays.asList(new String[] { "override" }), Arrays.asList(strArrVal1));
String[] strArrVal2 = (String[]) delegate2.getUimaContext().getConfigParameterValue("en",
"StringArrayParam");
Assert.assertEquals(Arrays.asList(new String[] { "override" }), Arrays.asList(strArrVal2));
String[] strArrVal3 = (String[]) flowController.getUimaContext().getConfigParameterValue(
"en", "StringArrayParam");
Assert.assertEquals(Arrays.asList(new String[] { "override" }), Arrays.asList(strArrVal3));
// anotherdescriptor with configuration parameter overrides (this time no groups)
in = new XMLInputSource(JUnitExtension
.getFile("TextAnalysisEngineImplTest/AggregateTaeWithConfigParamOverrides2.xml"));
desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
ae = new AggregateAnalysisEngine_impl();
ae.initialize(desc, Collections.EMPTY_MAP);
delegate1 = (PrimitiveAnalysisEngine_impl) ae._getASB().getComponentAnalysisEngines().get(
"Annotator1");
delegate2 = (PrimitiveAnalysisEngine_impl) ae._getASB().getComponentAnalysisEngines().get(
"Annotator2");
flowController = ((ASB_impl) ae._getASB()).getFlowControllerContainer();
strVal1 = (String) delegate1.getUimaContext().getConfigParameterValue("StringParam");
Assert.assertEquals("override", strVal1);
strVal2 = (String) delegate2.getUimaContext().getConfigParameterValue("StringParam");
Assert.assertEquals("myString", strVal2);
strVal3 = (String) flowController.getUimaContext().getConfigParameterValue("StringParam");
Assert.assertEquals("myString", strVal3);
intVal1 = (Integer) delegate1.getUimaContext().getConfigParameterValue("IntegerParam");
Assert.assertEquals(100, intVal1.intValue());
intVal2 = (Integer) delegate2.getUimaContext().getConfigParameterValue("IntegerParam");
Assert.assertEquals(100, intVal2.intValue());
intVal3 = (Integer) flowController.getUimaContext().getConfigParameterValue("IntegerParam");
Assert.assertEquals(100, intVal3.intValue());
strArrVal1 = (String[]) delegate1.getUimaContext()
.getConfigParameterValue("StringArrayParam");
Assert.assertEquals(Arrays.asList(new String[] { "override" }), Arrays.asList(strArrVal1));
strArrVal2 = (String[]) delegate2.getUimaContext()
.getConfigParameterValue("StringArrayParam");
Assert.assertEquals(Arrays.asList(new String[] { "override" }), Arrays.asList(strArrVal2));
strArrVal3 = (String[]) flowController.getUimaContext().getConfigParameterValue(
"StringArrayParam");
Assert.assertEquals(Arrays.asList(new String[] { "override" }), Arrays.asList(strArrVal3));
// try a descriptor that's invalid due to an unsatisfied resource dependency
_testInvalidDescriptor(JUnitExtension
.getFile("TextAnalysisEngineImplTest/UnsatisfiedResourceDependency.xml"));
ae.destroy();
// anotherdescriptor with configuration parameter overrides (this time no groups)
in = new XMLInputSource(JUnitExtension
.getFile("TextAnalysisEngineImplTest/AggregateTaeWithConfigParamOverrides2.xml"));
desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
ae = new AggregateAnalysisEngine_impl();
ae.initialize(desc, Collections.EMPTY_MAP);
// test an aggregate TAE containing a CAS Consumer
in = new XMLInputSource(JUnitExtension
.getFile("TextAnalysisEngineImplTest/AggregateTaeWithCasConsumer.xml"));
desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
ae = new AggregateAnalysisEngine_impl();
ae.initialize(desc, Collections.EMPTY_MAP);
delegate1 = (PrimitiveAnalysisEngine_impl) ae._getASB().getComponentAnalysisEngines().get(
"Annotator");
delegate2 = (PrimitiveAnalysisEngine_impl) ae._getASB().getComponentAnalysisEngines().get(
"CasConsumer");
assertTrue(delegate1.getAnalysisEngineMetaData().getOperationalProperties().getModifiesCas());
assertFalse(delegate2.getAnalysisEngineMetaData().getOperationalProperties().getModifiesCas());
ae.destroy();
// try an aggregate with no components (tests that empty flow works)
in = new XMLInputSource(JUnitExtension
.getFile("TextAnalysisEngineImplTest/EmptyAggregate.xml"));
desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
FixedFlow emptyFlow = (FixedFlow) desc.getAnalysisEngineMetaData().getFlowConstraints();
assertNotNull(emptyFlow.getFixedFlow());
assertTrue(emptyFlow.getFixedFlow().length == 0);
ae = new AggregateAnalysisEngine_impl();
ae.initialize(desc, Collections.EMPTY_MAP);
ae.destroy();
// aggregate with duplicate group overrides
in = new XMLInputSource(JUnitExtension
.getFile("TextAnalysisEngineImplTest/AggregateWithDuplicateGroupOverrides.xml"));
desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
ae = new AggregateAnalysisEngine_impl();
ae.initialize(desc, Collections.EMPTY_MAP);
delegate1 = (PrimitiveAnalysisEngine_impl) ae._getASB().getComponentAnalysisEngines().get(
"Annotator1");
delegate2 = (PrimitiveAnalysisEngine_impl) ae._getASB().getComponentAnalysisEngines().get(
"Annotator2");
String commonParamA = (String) delegate1.getUimaContext().getConfigParameterValue("a",
"CommonParam");
Assert.assertEquals("AggregateParam1a", commonParamA);
String ann1_groupBParamBC = (String) delegate1.getUimaContext().getConfigParameterValue("b",
"BCParam");
Assert.assertEquals("AggregateParam2b", ann1_groupBParamBC);
String ann2_groupBParamBC = (String) delegate2.getUimaContext().getConfigParameterValue("b",
"BCParam");
Assert.assertEquals("AggregateParam3b", ann2_groupBParamBC);
ae.destroy();
// descriptor with configuration parameter external overrides
// implicitly load settings values from the system property UimaExternalSettings
String resDir = "src/test/resources/TextAnalysisEngineImplTest/";
System.setProperty("UimaExternalOverrides", resDir+"testExternalOverride.settings,"+resDir+"testExternalOverride2.settings");
in = new XMLInputSource(JUnitExtension.getFile("TextAnalysisEngineImplTest/AnnotatorWithExternalOverrides.xml"));
desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
ae1 = new PrimitiveAnalysisEngine_impl();
ae1.initialize(desc, null);
String[] arrayParam = (String[]) ae1.getUimaContext().getConfigParameterValue("StringArrayParam");
Assert.assertNotNull(arrayParam);
Assert.assertEquals(5, arrayParam.length);
String[] expect = { "Prefix", "-", "Suffix", "->", "Prefix-Suffix" };
Assert.assertTrue(Arrays.equals(expect, arrayParam));
Integer[] intArr = (Integer[]) ae1.getUimaContext().getConfigParameterValue("IntegerArrayParam");
Assert.assertEquals(4, intArr.length);
Float[] floats = (Float[]) ae1.getUimaContext().getConfigParameterValue("FloatArrayParam");
Assert.assertTrue(floats != null && floats.length == 0); // Should be an empty array
System.clearProperty("UimaExternalOverrides");
ae1.destroy();
// aggregate with delegate with configuration parameter external overrides
// use aggregate so the annotator can run tests based on the context.
// load settings explicitly, ignoring system property
System.setProperty("UimaExternalOverrides", "missing file"); // Will fail if used
in = new XMLInputSource(JUnitExtension.getFile("TextAnalysisEngineImplTest/AggregateWithExternalOverrides.xml"));
desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(in);
Map<String,Object> additionalParams = new HashMap<String,Object>();
Settings extSettings = new Settings_impl();
FileInputStream fis = new FileInputStream(new File(resDir,"testExternalOverride2.settings"));
extSettings.load(fis);