uima-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [uima-uimaj] reckart commented on a change in pull request #39: [UIMA-6225] Unable to install a pear package into a directory containing special character like <,> or &
Date Thu, 07 May 2020 18:08:54 GMT

reckart commented on a change in pull request #39:
URL: https://github.com/apache/uima-uimaj/pull/39#discussion_r421696199



##########
File path: uimaj-core/src/test/java/org/apache/uima/pear/util/TestPearInstallationVerification.java
##########
@@ -19,107 +19,76 @@
 
 package org.apache.uima.pear.util;
 
-import java.io.File;
+import static org.apache.uima.pear.tools.InstallationController.TestStatus.TEST_SUCCESSFUL;
+import static org.apache.uima.test.junit_extension.JUnitExtension.getFile;
+import static org.assertj.core.api.Assertions.assertThat;
 
-import org.junit.Assert;
-import junit.framework.TestCase;
+import java.io.File;
+import java.io.IOException;
 
+import org.apache.uima.UIMAException;
+import org.apache.uima.UIMARuntimeException;
 import org.apache.uima.pear.tools.InstallationController.TestStatus;
 import org.apache.uima.pear.tools.InstallationTester;
 import org.apache.uima.pear.tools.PackageBrowser;
 import org.apache.uima.pear.tools.PackageInstaller;
-import org.apache.uima.test.junit_extension.JUnitExtension;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.InvalidXMLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 
 /**
  * Test the pear installation verification
- * 
  */
-public class TestPearInstallationVerification extends TestCase {
+public class TestPearInstallationVerification {
 
   // Temporary working directory, used to install the pear package
-  private File tempInstallDir = null;
+  public @Rule TemporaryFolder temp = new TemporaryFolder();
+  
+  @Test
+  public void testAePearVerification() throws Exception {
+    assertThatPearInstalls(
+            getFile("pearTests/analysisEngine.pear"), 
+            temp.newFolder("pear_verification_test_tmp"));
+  }
 
-  /**
-   * @see junit.framework.TestCase#setUp()
-   */
-  protected void setUp() throws Exception {
-    
-    // create temporary working directory
-    File tempFile = File.createTempFile("pear_verification_test_", "tmp");
-    if (tempFile.delete()) {
-      File tempDir = tempFile;
-      if (tempDir.mkdirs())
-        this.tempInstallDir = tempDir;
-    }
+  @Test
+  public void testCcPearVerification() throws Exception {
+    assertThatPearInstalls(
+            getFile("pearTests/casConsumer.pear"), 
+            temp.newFolder("pear_verification_test_tmp"));
   }
 
-  /**
-   * @see junit.framework.TestCase#tearDown()
-   */
-  protected void tearDown() throws Exception {
-    if (this.tempInstallDir != null) {
-      FileUtil.deleteDirectory(this.tempInstallDir);
-    }
+  @Test
+  public void testTsPearVerification() throws Exception {
+    assertThatPearInstalls(
+            getFile("pearTests/typeSystem.pear"), 
+            temp.newFolder("pear_verification_test_tmp"));
   }
 
-  
-  public void testAePearVerification() throws Exception {
-    
-     //get pear file to install
-    File pearFile = JUnitExtension.getFile("pearTests/analysisEngine.pear");
-    Assert.assertNotNull("analysisEngine.pear file not found", pearFile);
-    
-    // Install PEAR package without verification
-    PackageBrowser instPear = PackageInstaller.installPackage(
-            this.tempInstallDir, pearFile, false);
-    
-    //check package browser
-    Assert.assertNotNull("PackageBrowser is null", instPear);
-       
-    InstallationTester installTester = new InstallationTester(instPear);
-    TestStatus status = installTester.doTest();
-    
-    Assert.assertEquals(status.getRetCode(), TestStatus.TEST_SUCCESSFUL);
+  // TODO: create testcases for ci, cr, cpe pear packages
+
+  @Test
+  public void thatSpecialXmlCharactersInTargetPathDoNotBreakInstallation() throws Exception
{
+    assertThatPearInstalls(
+            getFile("pearTests/analysisEngine.pear"),
+            temp.newFolder("<>'\"&"));
   }
 
-  public void testCcPearVerification() throws Exception {
-    
-    //get pear file to install
-   File pearFile = JUnitExtension.getFile("pearTests/casConsumer.pear");
-   Assert.assertNotNull("casConsumer.pear file not found", pearFile);
-   
-   // Install PEAR package without verification
-   PackageBrowser instPear = PackageInstaller.installPackage(
-           this.tempInstallDir, pearFile, false);
-   
-   //check package browser
-   Assert.assertNotNull("PackageBrowser is null", instPear);
-      
-   InstallationTester installTester = new InstallationTester(instPear);
-   TestStatus status = installTester.doTest();
-   
-   Assert.assertEquals(status.getRetCode(), TestStatus.TEST_SUCCESSFUL);
- }
+  private void assertThatPearInstalls(File pearFile, File targetDir) throws InvalidXMLException,
+          ResourceInitializationException, UIMARuntimeException, UIMAException, IOException
{
+    assertThat(pearFile).as("PEAR file %s not found", pearFile).isNotNull();
 
-  public void testTsPearVerification() throws Exception {
-    
-    //get pear file to install
-   File pearFile = JUnitExtension.getFile("pearTests/typeSystem.pear");
-   Assert.assertNotNull("typeSystem.pear file not found", pearFile);
-   
-   // Install PEAR package without verification
-   PackageBrowser instPear = PackageInstaller.installPackage(
-           this.tempInstallDir, pearFile, false);
-   
-   //check package browser
-   Assert.assertNotNull("PackageBrowser is null", instPear);
-      
-   InstallationTester installTester = new InstallationTester(instPear);
-   TestStatus status = installTester.doTest();
-   
-   Assert.assertEquals(status.getRetCode(), TestStatus.TEST_SUCCESSFUL);
- }
+    // Install PEAR package without verification
+    PackageBrowser instPear = PackageInstaller.installPackage(targetDir, pearFile, false);
 
-  //TODO: create testcases for ci, cr, cpe pear packages
+    // Check package browser
+    assertThat(instPear).as("PackageBrowser is null").isNotNull();

Review comment:
       You assume that I am using junit assert but I use AssertJ.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message