Skip to content

Commit

Permalink
Add more precise unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gegic committed Jan 18, 2024
1 parent 61dc457 commit be75930
Show file tree
Hide file tree
Showing 7 changed files with 1,270 additions and 6 deletions.
52 changes: 46 additions & 6 deletions src/test/java/de/gwdg/metadataqa/marc/cli/CompletenessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.gwdg.metadataqa.marc.cli.utils.RecordIterator;
import junit.framework.TestCase;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -66,9 +67,22 @@ public void completeness_alephseq() throws Exception {
for (String outputFile : outputFiles) {
File output = new File(outputDir, outputFile);
assertTrue(output.exists());
output.delete();
assertFalse(output.exists());
}

// Now compare the output files with the expected ones
File expectedFile = new File(getTestResource("alephseq/expected-results/completeness/marc-elements.csv"));
File actualFile = new File(outputDir, "marc-elements.csv");
String expected = org.apache.commons.io.FileUtils.readFileToString(expectedFile, "UTF-8").replaceAll("\r\n", "\n");
String actual = org.apache.commons.io.FileUtils.readFileToString(actualFile, "UTF-8").replaceAll("\r\n", "\n");

Assert.assertEquals(expected, actual);

expectedFile = new File(getTestResource("alephseq/expected-results/completeness/packages.csv"));
actualFile = new File(outputDir, "packages.csv");
expected = org.apache.commons.io.FileUtils.readFileToString(expectedFile, "UTF-8").replaceAll("\r\n", "\n");
actual = org.apache.commons.io.FileUtils.readFileToString(actualFile, "UTF-8").replaceAll("\r\n", "\n");

Assert.assertEquals(expected, actual);
}

@Test
Expand All @@ -87,9 +101,22 @@ public void completeness_pica() throws Exception {
for (String outputFile : outputFiles) {
File output = new File(outputDir, outputFile);
assertTrue(output.exists());
output.delete();
assertFalse(output.exists());
}

// Now compare the output files with the expected ones
File expectedFile = new File(getTestResource("pica/expected-results/completeness/marc-elements.csv"));
File actualFile = new File(outputDir, "marc-elements.csv");
String expected = org.apache.commons.io.FileUtils.readFileToString(expectedFile, "UTF-8").replaceAll("\r\n", "\n");
String actual = org.apache.commons.io.FileUtils.readFileToString(actualFile, "UTF-8").replaceAll("\r\n", "\n");

Assert.assertEquals(expected, actual);

expectedFile = new File(getTestResource("pica/expected-results/completeness/packages.csv"));
actualFile = new File(outputDir, "packages.csv");
expected = org.apache.commons.io.FileUtils.readFileToString(expectedFile, "UTF-8").replaceAll("\r\n", "\n");
actual = org.apache.commons.io.FileUtils.readFileToString(actualFile, "UTF-8").replaceAll("\r\n", "\n");

Assert.assertEquals(expected, actual);
}

@Test
Expand Down Expand Up @@ -356,9 +383,22 @@ public void completeness_whenUnimarc() throws Exception {
for (String outputFile : outputFiles) {
File output = new File(outputDir, outputFile);
assertTrue(output.exists());
output.delete();
assertFalse(output.exists());
}

// Now compare the output files with the expected ones
File expectedFile = new File(getTestResource("unimarc/expected-results/completeness/marc-elements.csv"));
File actualFile = new File(outputDir, "marc-elements.csv");
String expected = org.apache.commons.io.FileUtils.readFileToString(expectedFile, "UTF-8").replaceAll("\r\n", "\n");
String actual = org.apache.commons.io.FileUtils.readFileToString(actualFile, "UTF-8").replaceAll("\r\n", "\n");

Assert.assertEquals(expected, actual);

expectedFile = new File(getTestResource("unimarc/expected-results/completeness/packages.csv"));
actualFile = new File(outputDir, "packages.csv");
expected = org.apache.commons.io.FileUtils.readFileToString(expectedFile, "UTF-8").replaceAll("\r\n", "\n");
actual = org.apache.commons.io.FileUtils.readFileToString(actualFile, "UTF-8").replaceAll("\r\n", "\n");

Assert.assertEquals(expected, actual);
}

}
Loading

0 comments on commit be75930

Please sign in to comment.