You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2007/02/13 15:08:02 UTC
svn commit: r507010 - in /incubator/uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java
test/java/org/apache/uima/cas/test/GetAllIndexedTest.java
Author: twgoetz
Date: Tue Feb 13 06:08:02 2007
New Revision: 507010
URL: http://svn.apache.org/viewvc?view=rev&rev=507010
Log:
Jira UIMA-297: fix bugs uncovered by unit tests; check in unit tests.
https://issues.apache.org/jira/browse/UIMA-297
Modified:
incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java
incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GetAllIndexedTest.java
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java?view=diff&rev=507010&r1=507009&r2=507010
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIteratorAggregate.java Tue Feb 13 06:08:02 2007
@@ -115,6 +115,7 @@
if (current.isValid()) {
return;
}
+ ++this.iteratorIndex;
}
// If we get here, the iterator is no longer valid, there are no more elements.
}
@@ -138,6 +139,7 @@
if (current.isValid()) {
return;
}
+ --this.iteratorIndex;
}
// If we get here, the iterator is no longer valid, there are no more elements.
}
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GetAllIndexedTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GetAllIndexedTest.java?view=diff&rev=507010&r1=507009&r2=507010
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GetAllIndexedTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/GetAllIndexedTest.java Tue Feb 13 06:08:02 2007
@@ -76,7 +76,10 @@
private Type annotationBaseType;
-// private Type tokenType;
+ // Count the number of FSs created in a test case.
+ private int fsCount = 0;
+
+ // private Type tokenType;
// private Type sentenceType;
@@ -89,7 +92,6 @@
*/
protected void setUp() throws Exception {
super.setUp();
-// this.casMgr = initCAS();
File descriptorFile = JUnitExtension.getFile("CASTests/desc/typePriorityTestCaseDescriptor.xml");
assertTrue("Descriptor must exist: " + descriptorFile.getAbsolutePath(), descriptorFile.exists());
@@ -130,25 +132,47 @@
this.annotationBaseType = null;
this.otherAnnotationType = null;
}
+
+ private final FSIterator getAllIndexed() {
+ return getAllIndexed(this.cas.getTypeSystem().getTopType());
+ }
+
+ private final FSIterator getAllIndexed(Type type) {
+ return this.cas.getIndexRepository().getAllIndexedFS(type);
+ }
+
+ private final int getIteratorSize(FSIterator it) {
+ int count = 0;
+ for (it.moveToFirst(); it.isValid(); it.moveToNext()) {
+ ++count;
+ }
+ return count;
+ }
+ private final void addFS(FeatureStructure fs) {
+ this.cas.getIndexRepository().addFS(fs);
+ ++this.fsCount;
+ assertTrue(getIteratorSize(getAllIndexed()) == this.fsCount);
+ }
+
/**
* Test driver.
*/
public void testGetAllIndexed() throws Exception {
+ this.fsCount = 0;
+ this.cas.reset();
FeatureStructure docAnnotation = this.cas.getDocumentAnnotation();
assertNotNull(docAnnotation);
+ ++this.fsCount;
+ assertTrue(getIteratorSize(getAllIndexed()) == this.fsCount);
final FeatureStructure otherAnnotationFS = this.cas.createFS(this.otherAnnotationType);
- final FeatureStructure annotationFS = this.cas.createFS(this.annotationType);
+ FeatureStructure annotationFS = this.cas.createFS(this.annotationType);
final FeatureStructure annotationBaseFS = this.cas.createFS(this.annotationBaseType);
- this.cas.addFsToIndexes(annotationFS);
- this.cas.addFsToIndexes(otherAnnotationFS);
- this.cas.addFsToIndexes(annotationBaseFS);
- FSIndexRepository ir = this.cas.getIndexRepository();
- FSIterator it = ir.getAllIndexedFS(this.annotationBaseType);
- while (it.isValid()) {
- System.out.println(it.get().getType().getName());
- it.moveToNext();
- }
+ addFS(annotationFS);
+ addFS(otherAnnotationFS);
+ addFS(annotationBaseFS);
+ addFS(this.cas.createFS(this.cas.getTypeSystem().getTopType()));
+ assertTrue(getIteratorSize(this.cas.getAnnotationIndex().iterator()) == 2);
}
public static void main(String[] args) {