You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2014/11/13 16:15:35 UTC

svn commit: r1639363 - in /uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl: XCASDeserializerTest.java XmiCasDeserializerTest.java

Author: schor
Date: Thu Nov 13 15:15:34 2014
New Revision: 1639363

URL: http://svn.apache.org/r1639363
Log:
[UIMA-4099] new check for wrong sofa in add-to-indices caught some invalid operations in test cases where they were adding subtypes of AnnotationBase to the wrong view.  Fix those tests to use an example Type which is not a subtype of AnnotationBase

Modified:
    uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XCASDeserializerTest.java
    uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java

Modified: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XCASDeserializerTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XCASDeserializerTest.java?rev=1639363&r1=1639362&r2=1639363&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XCASDeserializerTest.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XCASDeserializerTest.java Thu Nov 13 15:15:34 2014
@@ -36,12 +36,14 @@ import junit.framework.TestCase;
 import org.apache.uima.UIMAFramework;
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.FSIndex;
+import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.Feature;
 import org.apache.uima.cas.FeatureStructure;
 import org.apache.uima.cas.IntArrayFS;
 import org.apache.uima.cas.StringArrayFS;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.cas.TOP;
 import org.apache.uima.resource.metadata.FsIndexDescription;
 import org.apache.uima.resource.metadata.TypeSystemDescription;
 import org.apache.uima.resource.metadata.impl.TypePriorities_impl;
@@ -260,15 +262,20 @@ public class XCASDeserializerTest extend
     CAS cas2 = cas.createView("OtherSofa");
     cas2.setDocumentText("This is only a test");
 
-    // create an annotation and add to index of both views
-    AnnotationFS anAnnot = cas.createAnnotation(cas.getAnnotationType(), 0, 5);
-    cas.getIndexRepository().addFS(anAnnot);
-    cas2.getIndexRepository().addFS(anAnnot);
-    FSIndex tIndex = cas.getAnnotationIndex();
-    FSIndex t2Index = cas2.getAnnotationIndex();
-    assertTrue(tIndex.size() == 2); // document annot and this one
-    assertTrue(t2Index.size() == 2); // ditto
-
+    // Change this test to create an instance of TOP because you cannot add an annotation to other than 
+    //   the view it is created in. https://issues.apache.org/jira/browse/UIMA-4099
+    // create a TOP and add to index of both views
+    Type topType = cas.getTypeSystem().getTopType();
+    FeatureStructure aTOP = (FeatureStructure) cas.createFS(topType);
+    cas.getIndexRepository().addFS(aTOP);
+    cas2.getIndexRepository().addFS(aTOP); 
+    FSIterator<FeatureStructure> it = cas.getIndexRepository().getAllIndexedFS(topType);
+    FSIterator<FeatureStructure> it2 = cas2.getIndexRepository().getAllIndexedFS(topType);
+    it.next(); it.next();
+    it2.next(); it2.next(); 
+    assertFalse(it.hasNext());
+    assertFalse(it2.hasNext());
+     
     // serialize
     StringWriter sw = new StringWriter();
     XMLSerializer xmlSer = new XMLSerializer(sw, false);
@@ -293,9 +300,15 @@ public class XCASDeserializerTest extend
       assertEquals("This is only a test", newCas2.getDocumentText());
 
       // check that annotation is still indexed in both views
-      assertTrue(tIndex.size() == 2); // document annot and this one
-      assertTrue(t2Index.size() == 2); // ditto
-      newCas.reset();
+      it = newCas.getIndexRepository().getAllIndexedFS(topType);
+      it2 = newCas2.getIndexRepository().getAllIndexedFS(topType);
+      it.next(); it.next();
+      it2.next(); it2.next(); 
+      assertFalse(it.hasNext());
+      assertFalse(it2.hasNext());
+//      assertTrue(tIndex.size() == 2); // document annot and this one
+//      assertTrue(t2Index.size() == 2); // ditto
+      newCas.reset();  // testing if works after cas reset, go around loop 2nd time
     }
   }
 

Modified: uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java?rev=1639363&r1=1639362&r2=1639363&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/XmiCasDeserializerTest.java Thu Nov 13 15:15:34 2014
@@ -489,14 +489,19 @@ public class XmiCasDeserializerTest exte
       CAS cas2 = cas.createView("OtherSofa");
       cas2.setDocumentText("This is only a test");
 
-      // create an annotation and add to index of both views
-      AnnotationFS anAnnot = cas.createAnnotation(cas.getAnnotationType(), 0, 5);
-      cas.getIndexRepository().addFS(anAnnot);
-      cas2.getIndexRepository().addFS(anAnnot);
-      FSIndex tIndex = cas.getAnnotationIndex();
-      FSIndex t2Index = cas2.getAnnotationIndex();
-      assertTrue(tIndex.size() == 2); // document annot and this one
-      assertTrue(t2Index.size() == 2); // ditto
+      // Change this test to create an instance of TOP because you cannot add an annotation to other than 
+      //   the view it is created in. https://issues.apache.org/jira/browse/UIMA-4099
+      // create a TOP and add to index of both views
+      Type topType = cas.getTypeSystem().getTopType();
+      FeatureStructure aTOP = (FeatureStructure) cas.createFS(topType);
+      cas.getIndexRepository().addFS(aTOP);
+      cas2.getIndexRepository().addFS(aTOP); 
+      FSIterator<FeatureStructure> it = cas.getIndexRepository().getAllIndexedFS(topType);
+      FSIterator<FeatureStructure> it2 = cas2.getIndexRepository().getAllIndexedFS(topType);
+      it.next(); it.next();
+      it2.next(); it2.next(); 
+      assertFalse(it.hasNext());
+      assertFalse(it2.hasNext());
 
       // serialize
       StringWriter sw = new StringWriter();
@@ -523,8 +528,14 @@ public class XmiCasDeserializerTest exte
         assertEquals("This is only a test", newCas2.getDocumentText());
 
         // check that annotation is still indexed in both views
-        assertTrue(tIndex.size() == 2); // document annot and this one
-        assertTrue(t2Index.size() == 2); // ditto
+        // check that annotation is still indexed in both views
+        it = newCas.getIndexRepository().getAllIndexedFS(topType);
+        it2 = newCas2.getIndexRepository().getAllIndexedFS(topType);
+        it.next(); it.next();
+        it2.next(); it2.next(); 
+        assertFalse(it.hasNext());
+//        assertFalse(it2.hasNext());        assertTrue(tIndex.size() == 2); // document annot and this one
+//        assertTrue(t2Index.size() == 2); // ditto
 
         newCas.reset();
       }