}
public void testSetAndGet() {
this.cas.reset();
FsVariables fsvars = FsVariableFactory.newInstance();
fsvars.init(this.cas);
// Declare some variables.
fsvars.declareFsVariable(name1, this.annotType1);
fsvars.declareFsVariable(name2, this.annotType2);
fsvars.declareFsVariable(name3, this.annotType3);
fsvars.declareFsVariable(name4, this.annotType1);
fsvars.declareFsVariable(name5, this.annotType2);
fsvars.declareFsVariable(name6, this.annotType3);
// Create some values.
AnnotationFS annot1 = this.cas.createAnnotation(this.annotType1, 1, 1);
AnnotationFS annot2 = this.cas.createAnnotation(this.annotType2, 2, 2);
AnnotationFS annot3 = this.cas.createAnnotation(this.annotType3, 3, 3);
AnnotationFS annot4 = this.cas.createAnnotation(this.annotType1, 4, 4);
AnnotationFS annot5 = this.cas.createAnnotation(this.annotType2, 5, 5);
AnnotationFS annot6 = this.cas.createAnnotation(this.annotType3, 6, 6);
// Check that values are null, set value, check it's not null.
assertNull(fsvars.getVariableValue(name1));
assertNull(fsvars.getVariableValue(name2));
assertNull(fsvars.getVariableValue(name3));
assertNull(fsvars.getVariableValue(name4));
assertNull(fsvars.getVariableValue(name5));
assertNull(fsvars.getVariableValue(name6));
fsvars.setVariable(name1, annot1);
assertNotNull(fsvars.getVariableValue(name1));
fsvars.setVariable(name2, annot2);
assertNotNull(fsvars.getVariableValue(name2));
fsvars.setVariable(name3, annot3);
assertNotNull(fsvars.getVariableValue(name3));
fsvars.setVariable(name4, annot4);
assertNotNull(fsvars.getVariableValue(name4));
fsvars.setVariable(name5, annot5);
assertNotNull(fsvars.getVariableValue(name5));
fsvars.setVariable(name6, annot6);
assertNotNull(fsvars.getVariableValue(name6));
AnnotationFS annot = (AnnotationFS) fsvars.getVariableValue(name1);
assertTrue(annot.getIntValue(this.beginFeat) == 1);
annot1.setIntValue(this.beginFeat, 42);
assertTrue(annot.getIntValue(this.beginFeat) == 42);
annot = (AnnotationFS) fsvars.getVariableValue(name1);
assertTrue(annot.getIntValue(this.beginFeat) == 42);
fsvars.setVariable(name1, annot4);
annot = (AnnotationFS) fsvars.getVariableValue(name1);
assertTrue(annot.getIntValue(this.beginFeat) == 4);
boolean caughtExc = false;
try {
fsvars.setVariable(name2, annot1);
} catch (FsVariablesException e) {
caughtExc = true;
}
assertTrue(caughtExc);
annot = (AnnotationFS) fsvars.getVariableValue(name2);
assertNotNull(annot);
assertTrue(annot.getIntValue(this.beginFeat) == 2);
}