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 2015/11/04 21:08:40 UTC

svn commit: r1712627 - in /uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima: cas/impl/FSBagIndexTest.java cas/impl/Id2FSTest.java jcas/test/CASTestSetup.java jcas/test/JCasTest.java

Author: schor
Date: Wed Nov  4 20:08:39 2015
New Revision: 1712627

URL: http://svn.apache.org/viewvc?rev=1712627&view=rev
Log:
[UIMA-4674] update some tests for class renames, fix one edge-issue with CASTestSetup, fix JCasTest to reflect different order of initialization and error detection, replace refs that accessed _Type files with alternatives, update expected exceptions to be Java exceptions instead of UIMA exceptions where appropriate.

Modified:
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/impl/FSBagIndexTest.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/impl/Id2FSTest.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/test/CASTestSetup.java
    uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/test/JCasTest.java

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/impl/FSBagIndexTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/impl/FSBagIndexTest.java?rev=1712627&r1=1712626&r2=1712627&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/impl/FSBagIndexTest.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/impl/FSBagIndexTest.java Wed Nov  4 20:08:39 2015
@@ -22,8 +22,6 @@ package org.apache.uima.cas.impl;
 import java.io.File;
 import java.util.Arrays;
 
-import junit.framework.TestCase;
-
 import org.apache.uima.UIMAFramework;
 import org.apache.uima.cas.FSIndex;
 import org.apache.uima.cas.TypeSystem;
@@ -35,6 +33,8 @@ import org.apache.uima.test.junit_extens
 import org.apache.uima.util.CasCreationUtils;
 import org.apache.uima.util.XMLInputSource;
 
+import junit.framework.TestCase;
+
 public class FSBagIndexTest extends TestCase {
 
   private TypeSystemDescription typeSystemDescription;
@@ -49,7 +49,7 @@ public class FSBagIndexTest extends Test
   File indexesFile = JUnitExtension.getFile("ExampleCas/testIndexes.xml");
 
   
-  FSBagIndex bi;
+  FsIndex_bag bi;
   
   
   protected void setUp() throws Exception {
@@ -63,8 +63,8 @@ public class FSBagIndexTest extends Test
     bi = cbi();
   }
   
-  private FSBagIndex cbi() {
-    return new FSBagIndex(cas, ts.getType("uima.cas.TOP"), 16, FSIndex.BAG_INDEX);
+  private FsIndex_bag cbi() {
+    return new FsIndex_bag(cas, ts.getType("uima.cas.TOP"), 16, FSIndex.BAG_INDEX);
   }
 
   protected void tearDown() throws Exception {

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/impl/Id2FSTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/impl/Id2FSTest.java?rev=1712627&r1=1712626&r2=1712627&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/impl/Id2FSTest.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/cas/impl/Id2FSTest.java Wed Nov  4 20:08:39 2015
@@ -48,8 +48,7 @@ public class Id2FSTest extends TestCase
     }
   }
 
-  public void testStuff() throws InterruptedException {
-    // the normal cas APIs use the gc mode
+  public void testId2fs() throws InterruptedException {
     
     TOP fs1 = new TOP(jcas);
 
@@ -77,24 +76,28 @@ public class Id2FSTest extends TestCase
     assertTrue(fsh == cas.getFsFromId(2));
     
     for (int i = 1; i < 20; i++) {
+      TOP fs = null; // for debugging
       boolean caught = false;
       try {
-        TOP fs = cas.getFsFromId(i + 2);
-      } catch (CASRuntimeException e) {
+        fs = cas.getFsFromId_checked(i + 2);
+      } catch (LowLevelException e) {
         caught = true;
       }
+      if (!caught) {
+        System.out.println("debug " + fs);
+      }
       assertTrue(caught);
       
       caught = false;
       try {
-        TOP fs = cas.getFsFromId_checked(i + 2);
-      } catch (CASRuntimeException e) {
+        fs = cas.getFsFromId_checked(i + 2);
+      } catch (LowLevelException e) {
         caught = true;
       }
       assertTrue(caught);
     }
     
-    Id2FS id2fs = new Id2FS(false);  // non gc mode
+    Id2FS id2fs = new Id2FS(); 
     cas.reset();
     fs1 = new TOP(jcas);
     
@@ -116,7 +119,7 @@ public class Id2FSTest extends TestCase
     Thread.sleep(10);  // in case gc needs time to finish 
     for (int i = 0; i < 20; i++) {
       TOP fs = id2fs.get(i + 2);
-      assertEquals(fs._id, i + 2);
+      assertNull(fs);
     }    
   }
 

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/test/CASTestSetup.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/test/CASTestSetup.java?rev=1712627&r1=1712626&r2=1712627&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/test/CASTestSetup.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/test/CASTestSetup.java Wed Nov  4 20:08:39 2015
@@ -174,7 +174,8 @@ public class CASTestSetup implements Ann
     tsm.addFeature("plainInt", typeRoot, typeInteger);
     tsm.addFeature("plainFloat", typeRoot, typeFloat);
     tsm.addFeature("plainString", typeRoot, typeString);
-    tsm.addFeature("plainRef", typeRoot, typeRef);
+//    tsm.addFeature("plainRef", typeRoot, typeRef);
+    tsm.addFeature("plainRef", typeRoot, typeRoot);
 
     if (bad != BAD_MISSING_TYPE_IN_CAS)
       tsm.addType("aa.MissingInCas", topType);
@@ -201,7 +202,7 @@ public class CASTestSetup implements Ann
     try {
       tsm.addType("some.new.Name", group1);
     } catch (CASAdminException e) {
-      TestCase.assertTrue(e.getError() == CASAdminException.TYPE_IS_INH_FINAL);
+      TestCase.assertTrue(e.getMessageKey() == CASAdminException.TYPE_IS_INH_FINAL);
       exc = true;
     }
     TestCase.assertTrue(exc);
@@ -209,7 +210,7 @@ public class CASTestSetup implements Ann
     try {
       tsm.addFeature("some.new.Name", group1, typeString);
     } catch (CASAdminException e) {
-      TestCase.assertTrue(e.getError() == CASAdminException.TYPE_IS_FEATURE_FINAL);
+      TestCase.assertTrue(e.getMessageKey() == CASAdminException.TYPE_IS_FEATURE_FINAL);
       exc = true;
     }
     TestCase.assertTrue(exc);

Modified: uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/test/JCasTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/test/JCasTest.java?rev=1712627&r1=1712626&r2=1712627&view=diff
==============================================================================
--- uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/test/JCasTest.java (original)
+++ uima/uimaj/branches/experiment-v3-jcas/uimaj-core/src/test/java/org/apache/uima/jcas/test/JCasTest.java Wed Nov  4 20:08:39 2015
@@ -21,8 +21,6 @@ package org.apache.uima.jcas.test;
 
 import java.util.Iterator;
 
-import junit.framework.TestCase;
-
 import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
 import org.apache.uima.cas.CASRuntimeException;
@@ -50,19 +48,18 @@ import org.apache.uima.jcas.cas.NonEmpty
 import org.apache.uima.jcas.cas.NonEmptyIntegerList;
 import org.apache.uima.jcas.cas.NonEmptyStringList;
 import org.apache.uima.jcas.cas.StringArray;
-import org.apache.uima.jcas.cas.TOP_Type;
 import org.apache.uima.jcas.tcas.Annotation;
-import org.apache.uima.jcas.tcas.Annotation_Type;
 import org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl;
 import org.apache.uima.test.junit_extension.JUnitExtension;
 import org.apache.uima.util.CasCreationUtils;
 
-import x.y.z.EndOfSentence;
-import x.y.z.Sentence;
-import x.y.z.Token;
 import aa.ConcreteType;
 import aa.MissingFeatureInCas;
 import aa.Root;
+import junit.framework.TestCase;
+import x.y.z.EndOfSentence;
+import x.y.z.Sentence;
+import x.y.z.Token;
 
 /**
  * Class comment for CASTest.java goes here.
@@ -103,14 +100,17 @@ public class JCasTest extends TestCase {
 	}
 
 	public void checkOkMissingImport(Exception e1) {
-		if (e1 instanceof CASException) {
+		if (e1 instanceof CASRuntimeException) {
 			System.out.print("setup caught CAS Exception with message: ");
 			String m = e1.getMessage();
 			System.out.println(m);
-			if (!m
-					.equals("Error initializing JCas: Error: can't access feature information from CAS in initializing JCas type: aa.Root, feature: testMissingImport\n")) {
-				assertTrue(false);
-			}
+			assertEquals(m, "The JCas cannot be initialized.  The following errors occurred: "
+			    + "\nUnable to find required getPlainRef method for JCAS type aa.Root with return type of org.apache.uima.jcas.cas.TOP."
+			    + "\nUnable to find required setPlainRef method for JCAS type aa.Root with argument type of org.apache.uima.jcas.cas.TOP.\n");
+//			if (!m
+//					.equals("Error initializing JCas: Error: can't access feature information from CAS in initializing JCas type: aa.Root, feature: testMissingImport\n")) {
+//				assertTrue(false);
+//			}
 		} else
 			assertTrue(false);
 	}
@@ -142,30 +142,10 @@ public class JCasTest extends TestCase {
 			JCas localJcas = null;
 			boolean errFound = false;
 			try {
+			  // error happens during setup
 				localCas = CASInitializer.initCas(new CASTestSetup(CASTestSetup.BAD_MISSING_FEATURE_IN_CAS));
-				ts = this.cas.getTypeSystem();
-				try {
-					localJcas = localCas.getJCas();
-				} catch (Exception e1) {
-					assertTrue(false);
-					return;
-				}
-			} catch (Exception e) {
-				// System.out.println("\n" + e.toString());
-				assertTrue(false);
-			}
-			// error happens when we try and ref the missing feature
-			MissingFeatureInCas t = new MissingFeatureInCas(localJcas);
-			try {
-				t.setHaveThisOne(1);
-			} catch (Exception e) {
-				assertTrue(false);
-			}
-			try {
-				t.setMissingThisOne((float) 1.0);
-				assertTrue(false); // above should throw
 			} catch (CASRuntimeException e) {
-				assertTrue(e.getMessageKey().equals(CASRuntimeException.INAPPROP_FEAT));
+				assertTrue(e.getMessageKey().equals(CASException.JCAS_INIT_ERROR));
 			}
 		} catch (Exception e) {
 			JUnitExtension.handleException(e);
@@ -245,28 +225,23 @@ public class JCasTest extends TestCase {
 			}
 
 			try {
-				jcas.getRequiredFeature(jcas.getType(Annotation.type).casType, "begin");
+				jcas.getRequiredFeature(jcas.getCasType(Annotation.type), "begin");
 			} catch (CASException e2) {
 				assertTrue(false);
 			}
 			try {
-				jcas.getRequiredFeature(jcas.getType(Annotation.type).casType, "Begin");
+				jcas.getRequiredFeature(jcas.getCasType(Annotation.type), "Begin");
 				assertTrue(false);
 			} catch (CASException e2) {
 				System.out.print("This error msg expected: ");
 				System.out.println(e2);
 			}
-
 			CAS localCas = jcas.getCas();
 			assertTrue(localCas == this.cas);
 			LowLevelCAS ll_cas = jcas.getLowLevelCas();
 			assertTrue(ll_cas == this.cas);
 			CASImpl casImpl = jcas.getCasImpl();
 			assertTrue(casImpl == this.cas);
-			TOP_Type type = jcas.getType(org.apache.uima.jcas.tcas.Annotation.type);
-			assertTrue(type instanceof org.apache.uima.jcas.tcas.Annotation_Type);
-			type = jcas.getType(Annotation.typeIndexID);
-			assertTrue(type instanceof Annotation_Type);
 
 			Annotation a1 = new Annotation(jcas, 4, 5);
 		} catch (Exception e) {
@@ -307,18 +282,20 @@ public class JCasTest extends TestCase {
 
 			// error paths
 			// array out of bounds
+			boolean caught = false;
 			try {
 				r2.getArrayString(2);
-			} catch (LowLevelException e) {
-				if (e.getError() != LowLevelException.ARRAY_INDEX_OUT_OF_RANGE)
-					assertTrue(false);
+			} catch (ArrayIndexOutOfBoundsException e) {
+			  caught = true;
 			}
+			assertTrue(caught);
+			caught = false;
 			try {
 				r2.setArrayString(-1, "should fail");
-			} catch (LowLevelException e) {
-				if (e.getError() != LowLevelException.ARRAY_INDEX_OUT_OF_RANGE)
-					assertTrue(false);
+			} catch (ArrayIndexOutOfBoundsException e) {
+				caught = true;
 			}
+      assertTrue(caught);
 
 			// null values
 			r2.setArrayString(0, null);
@@ -329,12 +306,13 @@ public class JCasTest extends TestCase {
 			r2.setPlainString(null);
 			assertTrue(null == r2.getPlainString());
 			assertTrue(null == r2.getPlainRef());
+			caught = false;
 			try {
 				r2.getArrayRef(0);
-			} catch (LowLevelException e) {
-				if (e.getError() != LowLevelException.NULL_ARRAY_ACCESS)
-					assertTrue(false);
+			} catch (NullPointerException e) {
+			  caught = true;
 			}
+			assertTrue(caught);
 			assertTrue(null == r2.getArrayString());
 			assertTrue(null == r2.getArrayRef());
 
@@ -461,7 +439,7 @@ public class JCasTest extends TestCase {
 				CAS cas2 = CASInitializer.initCas(new CASTestSetup());
 				TypeSystem ts2 = cas2.getTypeSystem();
 				JCas jcas2 = cas2.getJCas();
-				assertTrue(jcas.getType(Annotation.type) != jcas2.getType(Annotation.type));
+				assertTrue(jcas.getCasType(Annotation.type) != jcas2.getCasType(Annotation.type));
 			} catch (Exception e) {
 				checkOkMissingImport(e);
 			}
@@ -574,14 +552,14 @@ public class JCasTest extends TestCase {
 			fsList.setTail(fsList1);
 			EmptyFSList emptyFsList = new EmptyFSList(jcas);
 
-			try {
-				emptyFsList.getNthElement(0);
-				assertTrue(false); // error if we get here
-			} catch (CASRuntimeException e) {
-				assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_ON_EMPTY_LIST));
-				System.out.print("Expected Error: ");
-				System.out.println(e.getMessage());
-			}
+//			try {
+//				emptyFsList.getNthElement(0);
+//				assertTrue(false); // error if we get here
+//			} catch (CASRuntimeException e) {
+//				assertTrue(e.getMessageKey().equals(CASRuntimeException.JCAS_GET_NTH_ON_EMPTY_LIST));
+//				System.out.print("Expected Error: ");
+//				System.out.println(e.getMessage());
+//			}
 
 			try {
 				fsList.getNthElement(-1);
@@ -748,7 +726,7 @@ public class JCasTest extends TestCase {
     jcas.setDocumentText("This is a test.");
     try {
       //this should throw an exception
-      jcas.getType(Sentence.type);
+      jcas.getCasType(Sentence.type);
       fail(); 
     } catch(CASRuntimeException e) {
     }