Skip to content

Commit

Permalink
Merge pull request #1113 from NASA-PDS/issue_1102
Browse files Browse the repository at this point in the history
Refactoring of automated cucumber tests
  • Loading branch information
jordanpadams authored Feb 5, 2025
2 parents 349bf8f + 35e3d6f commit 60be77c
Show file tree
Hide file tree
Showing 76 changed files with 708 additions and 953 deletions.
51 changes: 25 additions & 26 deletions src/main/java/gov/nasa/pds/tools/label/LabelValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,31 @@ public double getTotalTimeElapsed() {
* responsible for doing the transformations of the schematrons.
*/
public LabelValidator() throws ParserConfigurationException, TransformerConfigurationException {
this.clear();
}

/**
* Pass in a list of schemas to validate against.
*
* @param schemaFiles A list of schema URLs.
*
*/
public void setSchema(List<URL> schemaFiles) {
this.userSchemaFiles.addAll(schemaFiles);
LOG.debug("setSchema:schemaFiles.size(),schemaFiles {},{}", schemaFiles.size(), schemaFiles);
}

/**
* Pass in a list of transformed schematrons to validate against.
*
* @param schematrons A list of transformed schematrons.
*/
public void setSchematrons(List<String> schematrons) {
userSchematronTransformers = schematrons;
LOG.debug("setSchematrons:schematrons.size(),schematrons {}", schematrons.size());
}
public void clear() throws ParserConfigurationException, TransformerConfigurationException {
this.configurations.clear();
this.configurations.put(SCHEMA_CHECK, true);
this.configurations.put(SCHEMATRON_CHECK, true);
cachedParser = null;
Expand Down Expand Up @@ -191,32 +216,6 @@ public LabelValidator() throws ParserConfigurationException, TransformerConfigur
documentValidators.add(new DefaultDocumentValidator());
schematronTransformer = new SchematronTransformer();
}

/**
* Pass in a list of schemas to validate against.
*
* @param schemaFiles A list of schema URLs.
*
*/
public void setSchema(List<URL> schemaFiles) {
this.userSchemaFiles.addAll(schemaFiles);
LOG.debug("setSchema:schemaFiles.size(),schemaFiles {},{}", schemaFiles.size(), schemaFiles);
}

/**
* Pass in a list of transformed schematrons to validate against.
*
* @param schematrons A list of transformed schematrons.
*/
public void setSchematrons(List<String> schematrons) {
userSchematronTransformers = schematrons;
LOG.debug("setSchematrons:schematrons.size(),schematrons {}", schematrons.size());
}
public void clear() {
this.userSchemaFiles.clear();
this.userSchematronFiles.clear();
this.userSchematronTransformers.clear();
}
/**
* Pass in a hash map of schematron URLs to its transformed schematron object. This is used when
* validating a label against it's referenced schematron.
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/gov/nasa/pds/validate/ValidateLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.TimeZone;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
Expand Down Expand Up @@ -291,8 +292,6 @@ public ValidateLauncher() throws TransformerConfigurationException {
checkInbetweenFields = false;
pdfErrorDir = "";
setLabelExtension(Constants.DEFAULT_LABEL_EXTENSION);

this.flushValidators();
}

/**
Expand Down Expand Up @@ -1783,7 +1782,7 @@ public int processMain(String[] args) throws Exception {
* validation data between runs, which can cause issues, specifically when using varying
* dictionaries and catalog files.
*/
public void flushValidators() {
public void flushValidators() throws ParserConfigurationException, TransformerConfigurationException {
if (this.factory != null) {
this.factory.flush();
}
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/cucumber/CucumberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
@CucumberOptions(plugin = {"pretty", "html:target/cucumber.html"},
features = "src/test/resources/features/", glue = "cucumber")
public class CucumberTest {

public CucumberTest() {}

}
57 changes: 57 additions & 0 deletions src/test/java/cucumber/SingleScenerio.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cucumber;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import gov.nasa.pds.validate.ValidateLauncher;
import gov.nasa.pds.validate.constants.TestConstants;

public class SingleScenerio {
public static void main(String[] args) throws NumberFormatException, IOException {
if (args.length > 2 || args.length == 0) {
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;
}

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 engine = new StepDefs();
System.out.println("an_and");
engine.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));
System.out.println("execute_validate");
engine.execute_validate (scenerio[4].strip().substring(1,scenerio[4].strip().length()-1));
System.out.println ("compare_to_the");
engine.compare_to_the(scenerio[5].strip().isBlank() ? null :
scenerio[5].strip().substring(1, scenerio[5].strip().length()-1));
System.out.println ("success");
return;
}
}
}
}
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;
}
}
Loading

0 comments on commit 60be77c

Please sign in to comment.