This is an automated email from the ASF dual-hosted git repository.

mawiesne pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp-sandbox.git


The following commit(s) were added to refs/heads/main by this push:
     new 57c9c03  fixes XmiCasDB creatuib issues in CS connector tests raised 
only on Win* environments
57c9c03 is described below

commit 57c9c03eb258296a8d36eb26bf8be3aab4565d26
Author: Martin Wiesner <[email protected]>
AuthorDate: Sun Apr 27 19:00:46 2025 +0200

    fixes XmiCasDB creatuib issues in CS connector tests raised only on Win* 
environments
---
 .../opennlp/corpus_server/connector/AbstractCSTest.java | 17 +++++++++++------
 .../corpus_server/connector/CSCollectionReaderTest.java | 14 ++++++++------
 2 files changed, 19 insertions(+), 12 deletions(-)

diff --git 
a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/AbstractCSTest.java
 
b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/AbstractCSTest.java
index 00390b8..ded8472 100644
--- 
a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/AbstractCSTest.java
+++ 
b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/AbstractCSTest.java
@@ -40,15 +40,10 @@ public abstract class AbstractCSTest {
   }
 
   protected static final URL BASE_LOCATION = 
AbstractCSTest.class.getProtectionDomain().getCodeSource().getLocation();
-  protected static final String BASE_PATH = BASE_LOCATION.toExternalForm();
 
   protected static void cleanTestDB() throws IOException {
     try {
-      URI baseURI = BASE_LOCATION.toURI();
-      String mainPath = Paths.get(baseURI).toString().
-              replace("file:", "").replace("/test-classes", "");
-      String dbDir = mainPath + File.separator + DerbyCorporaStore.DB_NAME;
-      Path p = Path.of(dbDir);
+      Path p = Path.of(getDBPathWithName());
       if (p.toFile().exists()) {
         try (var dirStream = Files.walk(p)) {
           
dirStream.map(Path::toFile).sorted(Comparator.reverseOrder()).forEach(File::delete);
@@ -58,4 +53,14 @@ public abstract class AbstractCSTest {
       throw new IOException("Can't clean Test DB!", e);
     }
   }
+
+  protected static String getDBPath() throws URISyntaxException {
+    URI baseURI = BASE_LOCATION.toURI();
+    return Paths.get(baseURI).toString().
+            replace("file:", "").replace("/test-classes", "") + File.separator;
+  }
+
+  private static String getDBPathWithName() throws URISyntaxException {
+    return getDBPath() + DerbyCorporaStore.DB_NAME;
+  }
 }
diff --git 
a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCollectionReaderTest.java
 
b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCollectionReaderTest.java
index 0ef0d8c..ae89afd 100644
--- 
a/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCollectionReaderTest.java
+++ 
b/corpus-server/corpus-server-connector/src/test/java/org/apache/opennlp/corpus_server/connector/CSCollectionReaderTest.java
@@ -22,6 +22,7 @@ import org.apache.opennlp.corpus_server.store.CorporaStore;
 import org.apache.opennlp.corpus_server.store.CorpusStore;
 import org.apache.uima.UIMAFramework;
 import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.CASException;
 import org.apache.uima.cas.impl.XmiCasSerializer;
 import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.cas.text.AnnotationIndex;
@@ -34,10 +35,12 @@ import org.apache.uima.util.XMLInputSource;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
+import org.xml.sax.SAXException;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -60,13 +63,12 @@ class CSCollectionReaderTest extends AbstractCSTest {
          ByteArrayOutputStream os = new ByteArrayOutputStream()) {
       TypeSystemDescription tsd = UimaUtil.createTypeSystemDescription(in);
       tsd.toXML(os);
-      CorporaStore cs = new DerbyCorporaStore();
-      cs.initialize(BASE_PATH.replace("file:", "").replace("/test-classes", 
""));
-      byte[] indexMapping = new byte[] {};
-      cs.createCorpus("wikinews", os.toByteArray(), indexMapping);
+      final CorporaStore cs = new DerbyCorporaStore();
+      cs.initialize(getDBPath());
+      cs.createCorpus("wikinews", os.toByteArray(), new byte[] {});
 
       os.reset();
-      CAS cas = UimaUtil.createEmptyCAS(tsd);
+      final CAS cas = UimaUtil.createEmptyCAS(tsd);
       cas.setDocumentText("this is a test text");
       Annotation a = new Annotation(cas.getJCas());
       a.setBegin(0);
@@ -77,7 +79,7 @@ class CSCollectionReaderTest extends AbstractCSTest {
       CorpusStore wikiNews = cs.getCorpus("wikinews");
       wikiNews.addCAS("111", os.toByteArray());
       wikiNews.addCAS("222", os.toByteArray());
-    } catch (Exception e) {
+    } catch (CASException | IOException | SAXException | URISyntaxException e) 
{
       fail(e.getLocalizedMessage());
     }
   }

Reply via email to