From b462a601f0bcf7160f4a63f221099c40abde1882 Mon Sep 17 00:00:00 2001 From: Jordan Padams Date: Fri, 16 Aug 2019 19:18:11 -0700 Subject: [PATCH] Issue #71: Add unit test to ensure catalog file success --- .../validate/ValidationIntegrationTests.java | 85 +++++++++++++++++-- 1 file changed, 78 insertions(+), 7 deletions(-) diff --git a/src/test/java/gov/nasa/pds/validate/ValidationIntegrationTests.java b/src/test/java/gov/nasa/pds/validate/ValidationIntegrationTests.java index 840e46fbc..4c208f674 100644 --- a/src/test/java/gov/nasa/pds/validate/ValidationIntegrationTests.java +++ b/src/test/java/gov/nasa/pds/validate/ValidationIntegrationTests.java @@ -5,8 +5,10 @@ import static org.junit.jupiter.api.Assertions.*; +import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; +import java.io.FileWriter; import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.AfterEach; @@ -38,9 +40,9 @@ void setUp() throws Exception { FileUtils.forceMkdir(this.outputData); } - /** - * @throws java.lang.Exception - */ +// /** +// * @throws java.lang.Exception +// */ // @AfterEach // void tearDown() throws Exception { // FileUtils.forceDelete(this.outputData); @@ -53,7 +55,7 @@ void testPDS543() { System.setProperty("resources.home", TestConstants.RESOURCES_DIR); String testPath = Utility.getAbsolutePath(TestConstants.TEST_DATA_DIR + "/PDS-543"); String outFilePath = TestConstants.TEST_OUT_DIR; - File report = new File(outFilePath + File.separator + "report.json"); + File report = new File(outFilePath + File.separator + "report_PDS543.json"); File expected = new File(testPath + File.separator + "report.expected.json"); String[] args = { @@ -101,14 +103,82 @@ void testPDS543() { @Test @Disabled + void testGithub71() { + try { + // Setup paths + System.setProperty("resources.home", TestConstants.RESOURCES_DIR); + String testPath = Utility.getAbsolutePath(TestConstants.TEST_DATA_DIR + "/github71"); + String outFilePath = TestConstants.TEST_OUT_DIR; + File report = new File(outFilePath + File.separator + "report_github71_1.json"); + String catFile =outFilePath + File.separator + "catalog.xml"; + + // Create catalog file + String catText = "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + ""; + + BufferedWriter writer = new BufferedWriter(new FileWriter(catFile)); + writer.write(catText); + writer.close(); + + // First test that we get an invalid context product error + String[] args = { +// "-r", report.getAbsolutePath(), + "-s", "json", + "--no-data-check", + testPath + File.separator + "ELE_MOM.xml" + }; + + ValidateLauncher.main(args); + + Gson gson = new Gson(); + JsonObject reportJson = gson.fromJson(new FileReader(report), JsonObject.class); + JsonObject message = reportJson.getAsJsonObject("summary").get("messageTypes").getAsJsonArray().get(0).getAsJsonObject(); + + System.out.println(message); + assertEquals(message.get("messageType").getAsString(), "error.label.unresolvable_resource", "error.label.unresolvable_resource expected."); + assertEquals(message.get("total").getAsInt(), 1, "One error expected."); + + report = new File(outFilePath + File.separator + "report_github71_2.json"); + // First test that we get an invalid context product error + String[] args2 = { + "-r", report.getAbsolutePath(), + "-s", "json", + "-C", catFile, + "--no-data-check", + "-t", testPath + File.separator + "ELE_MOM.xml" + }; + + ValidateLauncher.main(args2); + + gson = new Gson(); + reportJson = gson.fromJson(new FileReader(report), JsonObject.class); + assertEquals(reportJson.getAsJsonObject("summary").get("totalErrors").getAsInt(), 0, "Zero errors expected."); + + } catch (ExitException e) { + assertEquals(0, e.status, "Exit status"); + } catch (Exception e) { + e.printStackTrace(); + fail("Test Failed Due To Exception: " + e.getMessage()); + } + } + + @Test + @Disabled + // For some reason the logging isn't working properly so ignoring this test for now. void testGithub28() { try { // Setup paths System.setProperty("resources.home", TestConstants.RESOURCES_DIR); String testPath = Utility.getAbsolutePath(TestConstants.TEST_DATA_DIR + "/github28"); String outFilePath = TestConstants.TEST_OUT_DIR; - File report = new File(outFilePath + File.separator + "report.json"); - File expected = new File(testPath + File.separator + "report.expected.json"); + File report = new File(outFilePath + File.separator + "report_github28_1.json"); // First test that we get an invalid context product error String[] args = { @@ -126,11 +196,12 @@ void testGithub28() { assertEquals(reportJson.getAsJsonObject("summary").get("totalErrors").getAsInt(), 1, "One error expected for invalid context reference test."); // Now test with added context products + report = new File(outFilePath + File.separator + "report_github28_2.json"); String[] args2 = { "-r", report.getAbsolutePath(), "-s", "json", "--add-context-products", testPath + File.separator + "new_context.json", - testPath + File.separator + "test_add_context_products.xml", + "-t" , testPath + File.separator + "test_add_context_products.xml", }; ValidateLauncher.main(args2);