Skip to content

Commit

Permalink
Issue #71: Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanpadams committed Aug 19, 2019
1 parent 844f4c8 commit 88dcbfe
Show file tree
Hide file tree
Showing 8 changed files with 12,271 additions and 59 deletions.
118 changes: 59 additions & 59 deletions src/test/java/gov/nasa/pds/validate/ValidationIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ void setUp() throws Exception {
FileUtils.forceMkdir(this.outputData);
}

// /**
// * @throws java.lang.Exception
// */
// @AfterEach
// void tearDown() throws Exception {
// FileUtils.forceDelete(this.outputData);
// }
/**
* @throws java.lang.Exception
*/
@AfterEach
void tearDown() throws Exception {
FileUtils.forceDelete(this.outputData);
}

@Test
void testPDS543() {
Expand Down Expand Up @@ -100,66 +100,46 @@ void testPDS543() {
fail("Test Failed Due To Exception: " + e.getMessage());
}
}

@Test
@Disabled
void testGithub71() {
void testGithub28() {
try {
// Setup paths
System.setProperty("resources.home", TestConstants.RESOURCES_DIR);
String testPath = Utility.getAbsolutePath(TestConstants.TEST_DATA_DIR + "/github71");
String testPath = Utility.getAbsolutePath(TestConstants.TEST_DATA_DIR + "/github28");
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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!--\n" +
"<!DOCTYPE catalog PUBLIC \"-//OASIS//DTD XML Catalogs V1.1//EN\" \"http://www.oasis-open.org/committee\\\n" +
"s/entity/release/1.1/catalog.dtd\">\n" +
"-->\n" +
"<catalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">\n" +
" <rewriteURI uriStartString=\"http://pds.nasa.gov/pds4\" rewritePrefix=\"file://"+ testPath +"\" />\n" +
" <rewriteURI uriStartString=\"https://pds.nasa.gov/pds4\" rewritePrefix=\"file://"+ testPath +"\" />\n" +
"</catalog>";
File report = new File(outFilePath + File.separator + "report_github28_1.json");

BufferedWriter writer = new BufferedWriter(new FileWriter(catFile));
writer.write(catText);
writer.close();

// First test that we get an invalid context product error
System.out.println(testPath + File.separator + "test_add_context_products.xml");
String[] args = {
// "-r", report.getAbsolutePath(),
"-r", report.getAbsolutePath(),
"-s", "json",
"--no-data-check",
testPath + File.separator + "ELE_MOM.xml"
testPath + File.separator + "test_add_context_products.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.");

// Make sure we have 1 error as expected
assertEquals(reportJson.getAsJsonObject("summary").get("totalErrors").getAsInt(), 1, "One error expected for invalid context reference test.");

report = new File(outFilePath + File.separator + "report_github71_2.json");
// First test that we get an invalid context product error
// Now test with added context products
report = new File(outFilePath + File.separator + "report_github28_2.json");
String[] args2 = {
"-r", report.getAbsolutePath(),
"-s", "json",
"-C", catFile,
"--no-data-check",
"-t", testPath + File.separator + "ELE_MOM.xml"
"--add-context-products", testPath + File.separator + "new_context.json",
"-t" , testPath + File.separator + "test_add_context_products.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.");

assertEquals(reportJson.getAsJsonObject("summary").get("totalErrors").getAsInt(), 0, "No errors expected for add additional context test.");

} catch (ExitException e) {
assertEquals(0, e.status, "Exit status");
Expand All @@ -170,45 +150,65 @@ void testGithub71() {
}

@Test
@Disabled
// For some reason the logging isn't working properly so ignoring this test for now.
void testGithub28() {
void testGithub71() {
try {
// Setup paths
System.setProperty("resources.home", TestConstants.RESOURCES_DIR);
String testPath = Utility.getAbsolutePath(TestConstants.TEST_DATA_DIR + "/github28");
String testPath = Utility.getAbsolutePath(TestConstants.TEST_DATA_DIR + "/github71");
String outFilePath = TestConstants.TEST_OUT_DIR;
File report = new File(outFilePath + File.separator + "report_github28_1.json");
File report = new File(outFilePath + File.separator + "report_github71_1.json");
String catFile =outFilePath + File.separator + "catalog.xml";

// Create catalog file
String catText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<!--\n" +
"<!DOCTYPE catalog PUBLIC \"-//OASIS//DTD XML Catalogs V1.1//EN\" \"http://www.oasis-open.org/committee\\\n" +
"s/entity/release/1.1/catalog.dtd\">\n" +
"-->\n" +
"<catalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">\n" +
" <rewriteURI uriStartString=\"http://pds.nasa.gov/pds4\" rewritePrefix=\"file://"+ testPath +"\" />\n" +
" <rewriteURI uriStartString=\"https://pds.nasa.gov/pds4\" rewritePrefix=\"file://"+ testPath +"\" />\n" +
"</catalog>";

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",
testPath + File.separator + "test_add_context_products.xml"
"--no-data-check",
"-t", testPath + File.separator + "ELE_MOM.xml"
};

ValidateLauncher.main(args);

Gson gson = new Gson();
JsonObject reportJson = gson.fromJson(new FileReader(report), JsonObject.class);

// Make sure we have 1 error as expected
assertEquals(reportJson.getAsJsonObject("summary").get("totalErrors").getAsInt(), 1, "One error expected for invalid context reference test.");
// TODO Bug due to executing Github28 prior to this. It will still attempt context resolution after being unable to parse
// the label properly, so for some reason the code still use the context from previous run
JsonObject message = reportJson.getAsJsonObject("summary").get("messageTypes").getAsJsonArray().get(1).getAsJsonObject();

// Now test with added context products
report = new File(outFilePath + File.separator + "report_github28_2.json");
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",
"--add-context-products", testPath + File.separator + "new_context.json",
"-t" , testPath + File.separator + "test_add_context_products.xml",

"-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, "No errors expected for add additional context test.");
assertEquals(reportJson.getAsJsonObject("summary").get("totalErrors").getAsInt(), 0, "Zero errors expected.");

} catch (ExitException e) {
assertEquals(0, e.status, "Exit status");
Expand Down
Loading

0 comments on commit 88dcbfe

Please sign in to comment.