Skip to content

Commit

Permalink
all tests should pass
Browse files Browse the repository at this point in the history
Bulk of the work is done. Made the report.json match (give or take) for the tests from when run on main as well. If they are wrong, they are as wrong as they ere anyway.

Added a new test function for running single scenerios as though typed in on the command line. cut-n-paste is no longer your friend when translating scenerios to command lines. However, what it should look like is printed out so you can just grab it from there now.
  • Loading branch information
Al Niessner authored and Al Niessner committed Jan 24, 2025
1 parent 9b64749 commit d6ae5e4
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/test/java/cucumber/StepDefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -32,8 +33,8 @@ public class StepDefs {
* @throws java.lang.Exception
*/
void setUp() throws Exception {
FileUtils.forceMkdir(this.datasink.toFile()); // Create directory if one does not already exist.
System.setProperty("resources.home", TestConstants.RESOURCES_DIR);
this.makeSink();
this.launcher = new ValidateLauncher();
this.datasink.resolve("cucumber.success").toFile().delete();
this.datasink.resolve("cucumber.failed").toFile().createNewFile();
Expand All @@ -47,16 +48,23 @@ void tearDown() throws Exception {
CrossLabelFileAreaReferenceChecker.reset();
}

public void makeSink() throws IOException {
FileUtils.forceMkdir(this.datasink.toFile()); // Create directory if one does not already exist.
}
private String normalize (String s) {
return s
.replace("{datasink}", this.datasink.toAbsolutePath().toString())
.replace("{datasrc}", this.datasrc.toAbsolutePath().toString())
.replace("%20", " ");
}
private List<String> resolveArgumentStrings(String args) {
public List<String> resolveArgumentStrings(String args, boolean noReportInArgs) {
boolean catalogNext = false, manifestNext = false;
List<String> resolved = new ArrayList<String>(Arrays.asList("--report-file",
this.datasink.resolve("report.json").toString(), "--report-style", "json"));
List<String> resolved = new ArrayList<String>();

if (noReportInArgs) {
resolved.addAll(Arrays.asList("--report-file",
this.datasink.resolve("report.json").toString(), "--report-style", "json"));
}
for (String arg : args.split("\\s+")) {
if (arg.contains("{reportDir}") || arg.contains("{resourceDir}")) {
throw new IllegalArgumentException("{reportDir} and {resourceDir} are no longer valid.");
Expand All @@ -82,11 +90,13 @@ private List<String> resolveArgumentStrings(String args) {
if (arg.equals("-C") || arg.equals("--catalog")) {
catalogNext = true;
}
if (arg.equals("-r}") || arg.equals("--report-file")) {
throw new IllegalArgumentException("Defining the report file is no longer valid.");
}
if (arg.equals("-s") || arg.equals("--report-style")) {
throw new IllegalArgumentException("{Defining the report style is no longer valid.");
if (noReportInArgs) {
if (arg.equals("-r}") || arg.equals("--report-file")) {
throw new IllegalArgumentException("Defining the report file is no longer valid.");
}
if (arg.equals("-s") || arg.equals("--report-style")) {
throw new IllegalArgumentException("{Defining the report style is no longer valid.");
}
}
if (arg.equals("--target-manifest") ) {
manifestNext = true;
Expand All @@ -110,9 +120,9 @@ public void an_and(Integer issueNumber, Integer count, String datasrc) {

@When("execute validate with {string}")
public void execute_validate(String args) {
List<String> arguments = this.resolveArgumentStrings(args);
try {
this.setUp();
List<String> arguments = this.resolveArgumentStrings(args, true);
this.launcher.processMain(arguments.toArray(new String[0]));
this.tearDown();
} catch (ExitException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package gov.nasa.pds.validate;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import javax.xml.transform.TransformerConfigurationException;
import cucumber.StepDefs;
import gov.nasa.pds.validate.constants.TestConstants;

public class RunFeatureScenerioAsValidateFromCLI {
public static void main(String[] args) throws IOException, TransformerConfigurationException {
if (args.length > 2) {
System.out.println ("usage: <issue number> <subtest>");
System.out.println (" <issue number> is the first column in the feature file like 1066");
System.out.println (" <subtest> is the second column and should be omitted if there are no subtests for the <issue number>");
return;
}

ArrayList<String> validate_args = new ArrayList<String>();
for (File file : Paths.get(TestConstants.TEST_DATA_DIR, "features").toFile().listFiles((dir, name) -> name.endsWith(".feature"))) {
for (String line : Files.readAllLines(file.toPath())) {
line = line.strip();
if (line.startsWith("|")) {
String[] scenerio = line.split("\\|");
if (scenerio[1].strip().equals(args[0])) {
if (args.length == 1 && !scenerio[2].strip().isBlank()) {
System.out.println ("Scenerio " + args[0] + " requires a subtest value too.");
return;
}
if (args.length == 2 && scenerio[2].strip().isBlank()) {
System.out.println ("Scenerio " + args[0] + " does not require a subtest value.");
return;
}
if (args.length == 2 && !args[1].equals(scenerio[2].strip())) continue;
StepDefs helper = new StepDefs();
helper.an_and(
Integer.valueOf(scenerio[1].strip()),
args.length == 1 ? null : Integer.valueOf(scenerio[2].strip()),
scenerio[3].strip().substring(1, scenerio[3].strip().length()-1));
validate_args.addAll(helper.resolveArgumentStrings(scenerio[4].strip().substring(1,scenerio[4].strip().length()-1), false));
break;
}
}
}
if (validate_args.size() > 0) break;
}
if (validate_args.size() == 0) {
System.out.print ("Could not find issue number " + args[0]);
if (args.length == 2) System.out.print (" and subtest " + args[1]);
System.out.println();
return;
}
System.out.println ("Same as: validate " + String.join(" ", validate_args));
if (System.getProperty("resources.home") == null) {
System.setProperty("resources.home", TestConstants.RESOURCES_DIR);
}
ValidateLauncher.main(validate_args.toArray(new String[0]));
}
}
2 changes: 2 additions & 0 deletions src/test/resources/github50/target-manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{datasrc}/ele_evt_12hr_orbit_2011-2012.xml
{datasrc}/ele_evt_8hr_orbit_2012-2013.xml

0 comments on commit d6ae5e4

Please sign in to comment.