package org.obolibrary.robot;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.semanticweb.HermiT.ReasonerFactory;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;

/** Tests for ValidateOperationTest */
public class ValidateOperationTest extends CoreTest {

  /**
   * Test of the validation operation on a sample 'immune exposures' CSV file.
   *
   * @throws IOException
   */
  @Test
  public void testImmuneExposuresValidation() throws Exception, IOException {
    IOHelper ioHelper = new IOHelper();

    InputStream csvStream = this.getClass().getResourceAsStream("/immune_exposures.csv");
    assert (csvStream != null);
    List<List<String>> csvData = ioHelper.readCSV(csvStream);
    assert (csvData != null);

    InputStream owlStream = this.getClass().getResourceAsStream("/immune_exposures.owl");
    assert (owlStream != null);
    OWLOntology ontology = ioHelper.loadOntology(owlStream);
    assert (ontology != null);

    StringWriter writer = new StringWriter();
    OWLReasonerFactory reasonerFactory = new ReasonerFactory();
    ValidateOperation.validate(csvData, ontology, reasonerFactory, writer);

    String expectedPath = this.getClass().getResource("/immune_exposures-result.txt").getPath();
    assertNotEquals(expectedPath, "");
    String expectedResult = FileUtils.readFileToString(new File(expectedPath));
    assertEquals(writer.toString(), expectedResult);
  }
}

@@ -136,16 +136,82 @@
 Stream;%0A
+import java.io.ByteArrayOutputStream;%0Aimport java.io.PrintStream;%0A
 import j
@@ -1253,216 +1253,616 @@
     
-StringWriter writer = new StringWriter();%0A    OWLReasonerFactory reasonerFactory = new ReasonerFactory();%0A    ValidateOperation.validate(csvData, ontology, reasonerFactory, writer);%0A%0A    String expectedPath =
+// Redirect STDOUT to an OutputStream wrapped in a PrintStream:%0A    ByteArrayOutputStream outStream = new ByteArrayOutputStream();%0A    PrintStream prStream = new PrintStream(outStream);%0A    System.setOut(prStream);%0A%0A    // Call validate() with an outputPath of null to send output to STDOUT:%0A    OWLReasonerFactory reasonerFactory = new ReasonerFactory();%0A    ValidateOperation.validate(csvData, ontology, reasonerFactory, null);%0A%0A    // Compare the output with the contents of a file in the resources directory which contains%0A    // the output we expect to get:%0A    String fileWithExpectedContents =%0A       
  thi
@@ -1949,28 +1949,40 @@
 tEquals(
-expectedPath
+fileWithExpectedContents
 , %22%22);%0A 
@@ -2048,20 +2048,32 @@
 ile(
-expectedPath
+fileWithExpectedContents
 ));%0A
@@ -2093,14 +2093,17 @@
 als(
-writer
+outStream
 .toS

fix unit test for ValidateOperation that got broken after the previous commit