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 2017/09/28 01:59:15 UTC

svn commit: r1809934 - in /uima/uimaj/trunk/uimaj-document-annotation/src/test: java/org/apache/uima/jcas/tcas/ java/test/ resources/ resources/ExampleCas/

Author: schor
Date: Thu Sep 28 01:59:15 2017
New Revision: 1809934

URL: http://svn.apache.org/viewvc?rev=1809934&view=rev
Log:
[UIMA-5588] add test case

Added:
    uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/
    uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/DocMeta.java
    uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/DocMeta_Type.java
    uima/uimaj/trunk/uimaj-document-annotation/src/test/resources/
    uima/uimaj/trunk/uimaj-document-annotation/src/test/resources/ExampleCas/
    uima/uimaj/trunk/uimaj-document-annotation/src/test/resources/ExampleCas/testTypeSystem_docmetadata.xml
Modified:
    uima/uimaj/trunk/uimaj-document-annotation/src/test/java/org/apache/uima/jcas/tcas/DocumentAnnotationTest.java

Modified: uima/uimaj/trunk/uimaj-document-annotation/src/test/java/org/apache/uima/jcas/tcas/DocumentAnnotationTest.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-document-annotation/src/test/java/org/apache/uima/jcas/tcas/DocumentAnnotationTest.java?rev=1809934&r1=1809933&r2=1809934&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-document-annotation/src/test/java/org/apache/uima/jcas/tcas/DocumentAnnotationTest.java (original)
+++ uima/uimaj/trunk/uimaj-document-annotation/src/test/java/org/apache/uima/jcas/tcas/DocumentAnnotationTest.java Thu Sep 28 01:59:15 2017
@@ -18,17 +18,36 @@
  */
 package org.apache.uima.jcas.tcas;
 
-import junit.framework.TestCase;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
 
+import org.apache.uima.UIMAFramework;
 import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.SerialFormat;
+import org.apache.uima.cas.impl.BinaryCasSerDes4.CasCompare;
+import org.apache.uima.cas.impl.BinaryCasSerDes6;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.resource.metadata.impl.TypePriorities_impl;
 import org.apache.uima.resource.metadata.impl.TypeSystemDescription_impl;
 import org.apache.uima.test.junit_extension.JUnitExtension;
 import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.CasIOUtils;
+import org.apache.uima.util.XMLInputSource;
+
+import junit.framework.TestCase;
+import test.DocMeta;
 
 
 public class DocumentAnnotationTest extends TestCase {
   JCas jcas;
+  private CAS source;
+  private CAS target;
   
   public void setUp() throws Exception {
     try {
@@ -56,4 +75,42 @@ public class DocumentAnnotationTest exte
       JUnitExtension.handleException(e);
     }
   }  
+  
+  public void testDocMeta() throws Exception {
+    File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem_docmetadata.xml");
+    TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
+            new XMLInputSource(typeSystemFile));
+    
+    source = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), null);
+    target = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), null);
+    
+    jcas = source.getJCas();
+    
+    tstSerdesB4Sofa(SerialFormat.XMI);
+//    tstSerdesB4Sofa(SerialFormat.XCAS); // is ok (manual check) but compare cas util doesn't handle shift in ordering of FSs
+    tstSerdesB4Sofa(SerialFormat.BINARY);
+    tstSerdesB4Sofa(SerialFormat.COMPRESSED);
+    tstSerdesB4Sofa(SerialFormat.COMPRESSED_FILTERED);    
+  }
+  
+  private void tstSerdesB4Sofa(SerialFormat format) throws IOException, ResourceInitializationException {
+    source.reset();
+    target.reset();
+    
+    new DocMeta(jcas).addToIndexes();
+    
+    jcas.setDocumentText("something");
+    
+    new Annotation(jcas);
+    
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    CasIOUtils.save(source, bos, format);
+    bos.close();
+    
+    CasIOUtils.load(new ByteArrayInputStream(bos.toByteArray()), target);
+//    AnnotationFS c = target.getDocumentAnnotation();
+//    System.out.println(c);
+//    System.out.println(target.getDocumentAnnotation());
+    assertTrue(new BinaryCasSerDes6(source).compareCASes((CASImpl)source, (CASImpl)target));
+  }
 }

Added: uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/DocMeta.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/DocMeta.java?rev=1809934&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/DocMeta.java (added)
+++ uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/DocMeta.java Thu Sep 28 01:59:15 2017
@@ -0,0 +1,101 @@
+
+
+/* First created by JCasGen Sun Sep 24 15:24:44 EDT 2017 */
+package test;
+
+import org.apache.uima.jcas.JCas; 
+import org.apache.uima.jcas.JCasRegistry;
+import org.apache.uima.jcas.cas.TOP_Type;
+
+import org.apache.uima.jcas.tcas.DocumentAnnotation;
+
+
+/** 
+ * Updated by JCasGen Sun Sep 24 15:24:44 EDT 2017
+ * XML source: C:/au/svnCheckouts/trunk/uimaj-current/uimaj/uimaj-document-annotation/src/test/resources/ExampleCas/testTypeSystem_docmetadata.xml
+ * @generated */
+public class DocMeta extends DocumentAnnotation {
+  /** @generated
+   * @ordered 
+   */
+  @SuppressWarnings ("hiding")
+  public final static int typeIndexID = JCasRegistry.register(DocMeta.class);
+  /** @generated
+   * @ordered 
+   */
+  @SuppressWarnings ("hiding")
+  public final static int type = typeIndexID;
+  /** @generated
+   * @return index of the type  
+   */
+  @Override
+  public              int getTypeIndexID() {return typeIndexID;}
+ 
+  /** Never called.  Disable default constructor
+   * @generated */
+  protected DocMeta() {/* intentionally empty block */}
+    
+  /** Internal - constructor used by generator 
+   * @generated
+   * @param addr low level Feature Structure reference
+   * @param type the type of this Feature Structure 
+   */
+  public DocMeta(int addr, TOP_Type type) {
+    super(addr, type);
+    readObject();
+  }
+  
+  /** @generated
+   * @param jcas JCas to which this Feature Structure belongs 
+   */
+  public DocMeta(JCas jcas) {
+    super(jcas);
+    readObject();   
+  } 
+
+  /** @generated
+   * @param jcas JCas to which this Feature Structure belongs
+   * @param begin offset to the begin spot in the SofA
+   * @param end offset to the end spot in the SofA 
+  */  
+  public DocMeta(JCas jcas, int begin, int end) {
+    super(jcas);
+    setBegin(begin);
+    setEnd(end);
+    readObject();
+  }   
+
+  /** 
+   * <!-- begin-user-doc -->
+   * Write your own initialization here
+   * <!-- end-user-doc -->
+   *
+   * @generated modifiable 
+   */
+  private void readObject() {/*default - does nothing empty block */}
+     
+ 
+    
+  //*--------------*
+  //* Feature: feat
+
+  /** getter for feat - gets 
+   * @generated
+   * @return value of the feature 
+   */
+  public String getFeat() {
+    if (DocMeta_Type.featOkTst && ((DocMeta_Type)jcasType).casFeat_feat == null)
+      jcasType.jcas.throwFeatMissing("feat", "test.DocMeta");
+    return jcasType.ll_cas.ll_getStringValue(addr, ((DocMeta_Type)jcasType).casFeatCode_feat);}
+    
+  /** setter for feat - sets  
+   * @generated
+   * @param v value to set into the feature 
+   */
+  public void setFeat(String v) {
+    if (DocMeta_Type.featOkTst && ((DocMeta_Type)jcasType).casFeat_feat == null)
+      jcasType.jcas.throwFeatMissing("feat", "test.DocMeta");
+    jcasType.ll_cas.ll_setStringValue(addr, ((DocMeta_Type)jcasType).casFeatCode_feat, v);}    
+  }
+
+    
\ No newline at end of file

Added: uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/DocMeta_Type.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/DocMeta_Type.java?rev=1809934&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/DocMeta_Type.java (added)
+++ uima/uimaj/trunk/uimaj-document-annotation/src/test/java/test/DocMeta_Type.java Thu Sep 28 01:59:15 2017
@@ -0,0 +1,69 @@
+
+/* First created by JCasGen Sun Sep 24 15:24:44 EDT 2017 */
+package test;
+
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.JCasRegistry;
+import org.apache.uima.cas.impl.TypeImpl;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.impl.FeatureImpl;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.jcas.tcas.DocumentAnnotation_Type;
+
+/** 
+ * Updated by JCasGen Sun Sep 24 15:24:44 EDT 2017
+ * @generated */
+public class DocMeta_Type extends DocumentAnnotation_Type {
+  /** @generated */
+  @SuppressWarnings ("hiding")
+  public final static int typeIndexID = DocMeta.typeIndexID;
+  /** @generated 
+     @modifiable */
+  @SuppressWarnings ("hiding")
+  public final static boolean featOkTst = JCasRegistry.getFeatOkTst("test.DocMeta");
+ 
+  /** @generated */
+  final Feature casFeat_feat;
+  /** @generated */
+  final int     casFeatCode_feat;
+  /** @generated
+   * @param addr low level Feature Structure reference
+   * @return the feature value 
+   */ 
+  public String getFeat(int addr) {
+        if (featOkTst && casFeat_feat == null)
+      jcas.throwFeatMissing("feat", "test.DocMeta");
+    return ll_cas.ll_getStringValue(addr, casFeatCode_feat);
+  }
+  /** @generated
+   * @param addr low level Feature Structure reference
+   * @param v value to set 
+   */    
+  public void setFeat(int addr, String v) {
+        if (featOkTst && casFeat_feat == null)
+      jcas.throwFeatMissing("feat", "test.DocMeta");
+    ll_cas.ll_setStringValue(addr, casFeatCode_feat, v);}
+    
+  
+
+
+
+  /** initialize variables to correspond with Cas Type and Features
+	 * @generated
+	 * @param jcas JCas
+	 * @param casType Type 
+	 */
+  public DocMeta_Type(JCas jcas, Type casType) {
+    super(jcas, casType);
+    casImpl.getFSClassRegistry().addGeneratorForType((TypeImpl)this.casType, getFSGenerator());
+
+ 
+    casFeat_feat = jcas.getRequiredFeatureDE(casType, "feat", "uima.cas.String", featOkTst);
+    casFeatCode_feat  = (null == casFeat_feat) ? JCas.INVALID_FEATURE_CODE : ((FeatureImpl)casFeat_feat).getCode();
+
+  }
+}
+
+
+
+    
\ No newline at end of file

Added: uima/uimaj/trunk/uimaj-document-annotation/src/test/resources/ExampleCas/testTypeSystem_docmetadata.xml
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-document-annotation/src/test/resources/ExampleCas/testTypeSystem_docmetadata.xml?rev=1809934&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-document-annotation/src/test/resources/ExampleCas/testTypeSystem_docmetadata.xml (added)
+++ uima/uimaj/trunk/uimaj-document-annotation/src/test/resources/ExampleCas/testTypeSystem_docmetadata.xml Thu Sep 28 01:59:15 2017
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
+    <name>docmetadata</name>
+    <description/>
+    <version>1.0</version>
+    <vendor/>
+  <types>
+    <typeDescription>
+      <name>test.DocMeta</name>
+      <description/>
+      <supertypeName>uima.tcas.DocumentAnnotation</supertypeName>
+      <features>
+        <featureDescription>
+          <name>feat</name>
+          <description/>
+          <rangeTypeName>uima.cas.String</rangeTypeName>
+        </featureDescription>
+      </features>
+    </typeDescription>
+  </types>
+</typeSystemDescription>