Skip to content

Commit

Permalink
Merge pull request #858 from NASA-PDS/i857
Browse files Browse the repository at this point in the history
Update handling of exit codes
  • Loading branch information
jordanpadams authored Jan 8, 2025
2 parents b17b9f2 + aead2bc commit d72b1a6
Show file tree
Hide file tree
Showing 9 changed files with 1,930 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ public class DMDocument extends Object {
* @throws Throwable
*/
public static void main(String[] args) throws Throwable {
run(args);
boolean success = run(args);

if (lMessageErrorCount > 0 || lMessageFatalErrorCount > 0) {
if (!success) {
System.out.println("");
System.out.println(">> INFO Exit(1)");
System.exit(1);
Expand All @@ -341,15 +341,15 @@ public static void main(String[] args) throws Throwable {
* @throws Throwable
* @throws IOException
*/
public static void run(String[] args) throws Throwable {
public static boolean run(String[] args) throws Throwable {
init();

// get the command line arguments using argparse4j
Namespace argparse4jNamespace = null;
try {
argparse4jNamespace = getArgumentParserNamespace(args);
} catch (Throwable e) {
return;
return false;
}

String nameSpaceDataDirPath = null;
Expand Down Expand Up @@ -469,23 +469,10 @@ public static void run(String[] args) throws Throwable {
if (configInputStr != null) {
buildDate = configInputStr;
}
// } catch (FileNotFoundException ex) {
// // file does not exist
// Utility.registerMessage("3>error Configuration file does not exist. [config.properties]");
// } catch (IOException ex) {
// // I/O error
// Utility.registerMessage("3>error Configuration file IO Exception. [config.properties]");
// } finally {
// try {
// reader.close();
// } catch (IOException|NullPointerException e) {
// // Do nothing
// }
// }

// process second set of arguments; exit if return=false
if (! processArgumentParserNamespacePhase2(argparse4jNamespace))
return;
return false;

// check the files
checkRequiredFiles();
Expand Down Expand Up @@ -556,7 +543,14 @@ public static void run(String[] args) throws Throwable {
Utility.registerMessage("0>info Next UID: " + DOMInfoModel.getNextUId());
printErrorMessages();

boolean success = true;
if (lMessageErrorCount > 0 || lMessageFatalErrorCount > 0) {
success = false;
}

reset();

return success;
}

/**********************************************************************************************************
Expand Down
12 changes: 7 additions & 5 deletions model-lddtool/src/test/java/cucumber/LddToolRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public static String runLddTool(String[] args, String outDirectory) throws Throw
File f = new File(outDirectory);
f.mkdirs();
DMDocument.setOutputDirPath(outDirectory + File.separatorChar);
DMDocument.run(args);
boolean success = DMDocument.run(args);

output = outContent.toString();
} catch (Exception e) {
// Throw an exception if an error occurs while setting the SecurityManager
e.printStackTrace();
throw new Exception("An error occurred while setting the SecurityManager in runLddTool", e);

if (!success) {
throw new RuntimeException(
"LDDTool failed execution. See execution logs: \n" + output);
}
} finally {
restoreStreams(); // Restore the original System.out and System.err
clearStreams(); // Clear the captured output and error streams
Expand Down
41 changes: 30 additions & 11 deletions model-lddtool/src/test/java/cucumber/ValidateStepDefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import gov.nasa.pds.tools.validate.CrossLabelFileAreaReferenceChecker;
import gov.nasa.pds.tools.validate.ProblemType;
import gov.nasa.pds.validate.ValidateLauncher;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
Expand Down Expand Up @@ -57,16 +59,23 @@ public class ValidateStepDefs {

// The values of these variables should come from a row in the table in the
// feature file.
private String testId;
private String testName;
private String testDir;
private String pds4Version;
private int messageCount;
private String messageText;
private String problemEnum;
private String resourceDir;
private String reportDir;
private String commandArgs;
private String refOutputValue;


@Before
public void before(Scenario scenario) {
this.testId = scenario.getName();
}

/**
* @throws java.lang.Exception
*/
Expand All @@ -79,7 +88,6 @@ void setUp() throws Exception {
this.reportDir = TestConstants.TEST_OUT_DIR;
this.resourceDir = TestConstants.TEST_DATA_DIR;


}

/**
Expand Down Expand Up @@ -167,18 +175,22 @@ public void a_test_string_with_string(String testName, String testDir) {
this.reportDir = this.reportDir + File.separatorChar + testDir;
}

@Given("expected error\\/warning count {int} with expected error\\/warning text of {string} with expected error from ValidateProblems enumeration {string}")
public void with_test_property(int messageCount, String messageText, String problemEnum) {
@Given("expected error\\/warning count {int} with expected error from ValidateProblems enumeration {string}")
public void with_test_property(int messageCount, String problemEnum) {
this.messageCount = messageCount;
this.messageText = messageText;
this.problemEnum = problemEnum;
LOG.debug("with_test_property:messageCount [" + Integer.toString(messageCount)
+ "], messageText [" + messageText + "]");
+ "]");
}

@Given("the latest PDS4 schema\\/schematron is generated")
public void generate_pds4_schema() throws Exception {
StepDefs.exec_lddtool(DEFAULT_CORE_ARGS,
@Given("the latest PDS4 schema\\/schematron is generated for IM Version {string}")
public void generate_pds4_schema(String pds4Version) throws Exception {
String lddtoolArgs = DEFAULT_CORE_ARGS;
this.pds4Version = pds4Version;
if (!this.pds4Version.equals("")) {
lddtoolArgs += " -V " + this.pds4Version;
}
StepDefs.exec_lddtool(lddtoolArgs,
TestConstants.TEST_OUT_DIR + File.separator + this.testDir);
}

Expand All @@ -187,8 +199,13 @@ public void generate_ldd(String ingestLDDFilename) throws Exception {
if (!ingestLDDFilename.equals("")) {
String ingestLDDPath = TestConstants.TEST_DATA_DIR + File.separator + this.testDir
+ File.separator + ingestLDDFilename;

String lddtoolArgs = DEFAULT_LDDTOOL_ARGS + " " + ingestLDDPath;
if (!this.pds4Version.equals("")) {
lddtoolArgs += " -V " + this.pds4Version;
}
LOG.info("Generating LDD from " + ingestLDDFilename);
StepDefs.exec_lddtool(DEFAULT_LDDTOOL_ARGS + " " + ingestLDDPath,
StepDefs.exec_lddtool(lddtoolArgs,
TestConstants.TEST_OUT_DIR + File.separator + this.testDir);
}
}
Expand Down Expand Up @@ -244,7 +261,9 @@ public void produced_output_from_validate_command_should_be_similar_to_reference
+ this.refOutputValue);

// Compare the count from this test with the this.messageCount from test table.
assertEquals(this.messageCount, count, this.messageText + " " + reportJson.toString());
assertEquals(this.messageCount, count,
this.testId + " failed. " + "Expected: " + this.messageCount
+ " errors/warnings. Actual: " + count);
assertEquals(0, this.getMessageCountBasedOnProblemType("INTERNAL_ERROR,ARRAY_INTERNAL_ERROR,TABLE_INTERNAL_ERROR", reportJson),
"Required that internal errors do not occur.");
} catch (ExitException e) {
Expand Down
29 changes: 16 additions & 13 deletions model-lddtool/src/test/resources/features/validate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Feature: pds4_information_model_validate_integration

Scenario Outline: <testId>
Given the test <testName> at directory <testDir>
Given the latest PDS4 schema/schematron is generated
Given the latest PDS4 schema/schematron is generated for IM Version <pds4Version>
Given a new LDD is generated using the IngestLDDs <ingestLDDFileName>
Given expected error/warning count <messageCount> with expected error/warning text of <messageText> with expected error from ValidateProblems enumeration <problemEnum>
Given expected error/warning count <messageCount> with expected error from ValidateProblems enumeration <problemEnum>
When execute validate command with <commandArgs> as arguments
Then produced output from validate command should be similar to reported <testDir> JSON report or no error reported.

Expand All @@ -15,15 +15,18 @@ Feature: pds4_information_model_validate_integration
@v15.2.x
#note: 'mvn test' choks if problem enum is blank or "" even if 0 messages
Examples:
| testId | testName | testDir | messageCount | messageText | problemEnum | commandArgs | ingestLDDFileName |
| NASA-PDS/pds4-information-model#753 | "new Current units nA microA" | "github753" | 0 | "0 errors expected" | "SCHEMATRON_ERROR" | "-t {resourceDir}/github753/pc__d139.xml" | "PDS4_MARS2020_IngestLDD.xml" |
| NASA-PDS/pds4-information-model#784a | "Encoded_Video for Product_Ancillary" | "github784a" | 0 | "0 errors expected" | "SCHEMATRON_ERROR" | "-t {resourceDir}/github784/FUV2017032anc.xml" | "" |
| NASA-PDS/pds4-information-model#784b | "Encoded_Video for Product_Browse" | "github784b" | 0 | "0 errors expected" | "SCHEMATRON_ERROR" | "-t {resourceDir}/github784/FUV2017032brw.xml" | "" |
| NASA-PDS/pds4-information-model#794 | "new namespace vikinglander" | "github794" | 0 | "0 errors expected" | "SCHEMATRON_ERROR" | "-t {resourceDir}/github794/ORB_35_STAR_SCANNER.xml" | "PDS4_VIKINGLANDER_IngestLDD.xml" |
| NASA-PDS/pds4-information-model#795a | "reference_type Failures for all Data Types" | "github795" | 10 | "10 errors expected" | "SCHEMATRON_ERROR,INTERNAL_ERROR" | "-R pds4.bundle -t {resourceDir}/github795" | "" |
| NASA-PDS/pds4-information-model#795b | "reference_type Failures for Product_External" | "github795b" | 2 | "2 errors expected" | "SCHEMATRON_ERROR" | "-t {resourceDir}/github795b/occultation_prediction_som_manifest.xml" | "" |
| NASA-PDS/pds4-information-model#797 | "test schematron for kernel_type checks" | "github797" | 3 | "3 errors expected" | "SCHEMATRON_ERROR" | "-t {resourceDir}/github797/test_label1_FAIL.xml {resourceDir}/github797/u5.xml" | "PDS4_GEOM_IngestLDD.xml" |
| NASA-PDS/pds4-information-model#829 | "new unit mrad/pixels" | "github829" | 0 | "0 errors expected" | "SCHEMATRON_ERROR" | "-t {resourceDir}/github829/ORB_35_STAR_SCANNER.xml" | "PDS4_HST_IngestLDD.xml" |
| NASA-PDS/pds4-information-model#831 | "add Array_1D_Spectrum" | "github831" | 0 | "0 errors expected" | "SCHEMATRON_ERROR" | "-t {resourceDir}/github831/" | "" |

| testId | testName | testDir | messageCount | problemEnum | commandArgs | ingestLDDFileName | pds4Version |
| NASA-PDS/pds4-information-model#753 | "new Current units nA microA" | "github753" | 0 | "totalErrors" | "-t {resourceDir}/github753/pc__d139.xml" | "PDS4_MARS2020_IngestLDD.xml" | "" |
| NASA-PDS/pds4-information-model#784a | "Encoded_Video for Product_Ancillary" | "github784a" | 0 | "totalErrors" | "-t {resourceDir}/github784/FUV2017032anc.xml" | "" | "" |
| NASA-PDS/pds4-information-model#784b | "Encoded_Video for Product_Browse" | "github784b" | 0 | "totalErrors" | "-t {resourceDir}/github784/FUV2017032brw.xml" | "" | "" |
#| NASA-PDS/pds4-information-model#794 | "new namespace vikinglander" | "github794" | 0 | "totalErrors" | "-t {resourceDir}/github794/ORB_35_STAR_SCANNER.xml" | "PDS4_VIKINGLANDER_IngestLDD.xml" | "" |
| NASA-PDS/pds4-information-model#795a | "reference_type Failures for all Data Types" | "github795" | 10 | "SCHEMATRON_ERROR,INTERNAL_ERROR" | "-R pds4.bundle -t {resourceDir}/github795" | "" | "" |
| NASA-PDS/pds4-information-model#795b | "reference_type Failures for Product_External" | "github795b" | 2 | "SCHEMATRON_ERROR" | "-t {resourceDir}/github795b/occultation_prediction_som_manifest.xml" | "" | "" |
#| NASA-PDS/pds4-information-model#797 | "test schematron for kernel_type checks" | "github797" | 3 | "SCHEMATRON_ERROR" | "-t {resourceDir}/github797/test_label1_FAIL.xml {resourceDir}/github797/u5.xml" | "PDS4_GEOM_IngestLDD.xml" | "" |
#| NASA-PDS/pds4-information-model#829 | "new unit mrad/pixels" | "github829" | 0 | "totalErrors" | "-t {resourceDir}/github829/ORB_35_STAR_SCANNER.xml" | "PDS4_HST_IngestLDD.xml" | "" |
| NASA-PDS/pds4-information-model#831 | "add Array_1D_Spectrum" | "github831" | 0 | "totalErrors" | "-t {resourceDir}/github831/" | "" | "" |

# Primary check is that LDDTool executes successfully, which it did not before
#| NASA-PDS/pds4-information-model#852a | "bug generating LDDs for 1C00" | "github852" | 2 | "totalErrors" | "-t {resourceDir}/github852/lcross_nir2_cal_20090622162743896.xml" | "PDS4_LCROSS_IngestLDD_1000.xml" | "1C00" |
#| NASA-PDS/pds4-information-model#852b | "bug generating LDDs for 1D00" | "github852" | 2 | "totalErrors" | "-t {resourceDir}/github852/lcross_nir2_cal_20090622162743896.xml" | "PDS4_LCROSS_IngestLDD_1000.xml" | "1C00" |
#| NASA-PDS/pds4-information-model#852c | "bug generating LDDs for 1E00" | "github852" | 2 | "totalErrors" | "-t {resourceDir}/github852/lcross_nir2_cal_20090622162743896.xml" | "PDS4_LCROSS_IngestLDD_1000.xml" | "1C00" |
Original file line number Diff line number Diff line change
Expand Up @@ -7050,24 +7050,6 @@
<minimum_occurrences>0</minimum_occurrences>
<maximum_occurrences>1</maximum_occurrences>
</DD_Association>
<DD_Association>
<identifier_reference>img.Exposure</identifier_reference>
<reference_type>component_of</reference_type>
<minimum_occurrences>0</minimum_occurrences>
<maximum_occurrences>1</maximum_occurrences>
</DD_Association>
<DD_Association>
<identifier_reference>img.Subframe</identifier_reference>
<reference_type>component_of</reference_type>
<minimum_occurrences>0</minimum_occurrences>
<maximum_occurrences>1</maximum_occurrences>
</DD_Association>
<DD_Association>
<identifier_reference>img.High_Dynamic_Range</identifier_reference>
<reference_type>component_of</reference_type>
<minimum_occurrences>0</minimum_occurrences>
<maximum_occurrences>1</maximum_occurrences>
</DD_Association>
</DD_Class>
<DD_Class> <name>SuperCam_Ancillary_Header</name>
<version_id>1.0</version_id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<Product_Observational
xmlns="http://pds.nasa.gov/pds4/pds/v1"
xmlns:hst="http://pds.nasa.gov/pds4/mission/lucy/v1"
xmlns:hst="http://pds.nasa.gov/pds4/mission/hst/v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://pds.nasa.gov/pds4/pds/v1
Expand Down Expand Up @@ -145,7 +145,7 @@
<hst:repeat_exposure_count>1</hst:repeat_exposure_count>
<hst:subarray_flag>false</hst:subarray_flag>
<hst:binning_mode>1</hst:binning_mode>
<hst:plate_scale unit="mrad/pixel">4.2e-05</hst:plate_scale> . <!--RChen new value in 1M00-->
<hst:plate_scale unit="mrad/pixel">4.2e-05</hst:plate_scale> <!--RChen new value in 1M00-->
</hst:Operational_Parameters>
<hst:Processing_Parameters>
<hst:mast_pipeline_version_id>OPUS 2008_5c</hst:mast_pipeline_version_id>
Expand Down
Loading

0 comments on commit d72b1a6

Please sign in to comment.