Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
import nl.uu.cs.ape.solver.solutionStructure.ModuleNode;
import nl.uu.cs.ape.solver.solutionStructure.SolutionWorkflow;
import nl.uu.cs.ape.solver.solutionStructure.TypeNode;
import nl.uu.cs.ape.utils.APEResources;
import nl.uu.cs.ape.utils.APEUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;

import org.json.JSONArray;
import org.json.JSONObject;

import lombok.extern.slf4j.Slf4j;

/**
Expand Down Expand Up @@ -96,16 +101,17 @@ private String getInputsInCWL(boolean formatForCwlInputsYmlFile) {
.append(typeNode.getFormat())
.append("\n");
if (formatForCwlInputsYmlFile) {
/* TODO: FIX THIS. IT CANNOT BE HARDCODED. */
// Load resources file
JSONObject availableDataJson = APEResources.getJSONResource("default_cwl_creator_data.json");

Map<String, String> availableData = new HashMap<>();
availableData.put("http://edamontology.org/format_3244", // mzML
"https://raw.githubusercontent.com/Workflomics/DemoKit/main/data/inputs/2021-10-8_Ecoli.mzML");
availableData.put("http://edamontology.org/format_1929", // FASTA
"https://raw.githubusercontent.com/Workflomics/DemoKit/main/data/inputs/up00000062.fasta");
availableData.put("http://edamontology.org/format_2196_plain", // OBO format_p
"https://raw.githubusercontent.com/Workflomics/DemoKit/main/data/inputs/go.obo");
availableData.put("http://edamontology.org/format_3475_plain", // TSV_p
"https://raw.githubusercontent.com/Workflomics/DemoKit/main/data/inputs/goa_human_smaller.gaf");
for (JSONObject entry : APEUtils.getJSONListFromJson(availableDataJson, "inputs")) {
String format = entry.getString("format");
String data = entry.getString("data");

availableData.put(format, data);
log.trace("Read default CWL creator config format and data {} : {}", format, data);
}
String inputPath = availableData.containsKey(currTypeFormat) ? availableData.get(currTypeFormat)
: "set_full_path_to_the_file_with_extension_here";
inputsInCWL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package nl.uu.cs.ape.sat.test.utils;
package nl.uu.cs.ape.utils;

import org.apache.commons.io.IOUtils;
import org.json.JSONObject;

import lombok.extern.slf4j.Slf4j;

import static nl.uu.cs.ape.sat.test.utils.Evaluation.fail;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
Expand All @@ -18,26 +16,26 @@
import java.util.Objects;

/**
* The {@code TestUtil} class is used to read contents of resource files more
* The {@code APEResources} class is used to read contents of resource files more
* easily, as functional tests will make use of json files in the test resource
* folders.
*
* @author Maurin Voshol
*/
@Slf4j
public class TestResources {
public class APEResources {

/**
* @param resource: relative path of a resource in the test resource folder
* @return the absolute path of a resource that can be used by the library.
*/
public static String getAbsoluteResourcePath(String resource) {
try {
return Paths.get(Objects.requireNonNull(TestResources.class.getClassLoader().getResource(resource)).toURI())
return Paths.get(Objects.requireNonNull(APEResources.class.getClassLoader().getResource(resource)).toURI())
.toAbsolutePath().toString();
} catch (URISyntaxException | NullPointerException e) {
e.printStackTrace();
fail("Could not retrieve resource '%s'", resource);
log.error("Could not retrieve resource '{}'", resource);
return null;
}
}
Expand All @@ -58,11 +56,11 @@ public static String getAbsoluteRoot() {
public static String getTextResource(String resource, Charset charset) {
try {
return IOUtils.toString(
Objects.requireNonNull(TestResources.class.getClassLoader().getResourceAsStream(resource)),
Objects.requireNonNull(APEResources.class.getClassLoader().getResourceAsStream(resource)),
charset);
} catch (IOException e) {
e.printStackTrace();
fail("Could not retrieve %s resource '%s' ", charset, resource);
log.error("Could not retrieve {} resource '{}' ", charset, resource);
return null;
}
}
Expand All @@ -84,7 +82,7 @@ public static JSONObject getJSONResource(String resource) {
}

public static String writeFile(String relativePath, String content) {
Path absolutePath = Paths.get(TestResources.getAbsoluteRoot()).resolve(relativePath).toAbsolutePath();
Path absolutePath = Paths.get(APEResources.getAbsoluteRoot()).resolve(relativePath).toAbsolutePath();
Path absoluteParentPath = absolutePath.getParent();
try {
File folder = absoluteParentPath.toFile();
Expand All @@ -106,7 +104,7 @@ public static String writeFile(String relativePath, String content) {
}

public static JSONObject getConfigResource(String base_config_path, String ontology_path, String tools_path,
String constraints_path, String solution_dir_path) {
String constraints_path, String solution_dir_path) {
return getJSONResource(base_config_path)
// add paths to the other files to the configuration
.put("ontology_path", getAbsoluteResourcePath(ontology_path))
Expand Down
25 changes: 25 additions & 0 deletions src/main/resources/default_cwl_creator_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

{
"inputs": [
{
"_comment" : "MZML format and data",
"format": "http://edamontology.org/format_3244",
"data" : "https://raw.githubusercontent.com/Workflomics/DemoKit/main/data/inputs/2021-10-8_Ecoli.mzML"
},
{
"_comment" : "FASTA format and data",
"format": "http://edamontology.org/format_1929",
"data" : "https://raw.githubusercontent.com/Workflomics/DemoKit/main/data/inputs/up00000062.fasta"
},
{
"_comment" : "plain OBO format and data (plain means any OBO variant)",
"format": "http://edamontology.org/format_2196_plain",
"data" : "https://raw.githubusercontent.com/Workflomics/DemoKit/main/data/inputs/go.obo"
},
{
"_comment" : "plain TSV format and data (plain means any TSV variant)",
"format": "http://edamontology.org/format_3475_plain",
"data" : "https://raw.githubusercontent.com/Workflomics/DemoKit/main/data/inputs/goa_human.gaf"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import nl.uu.cs.ape.configuration.tags.APEConfigTag;
import nl.uu.cs.ape.configuration.tags.validation.ValidationResults;
import nl.uu.cs.ape.domain.APEDomainSetup;
import nl.uu.cs.ape.sat.test.utils.TestResources;
import nl.uu.cs.ape.utils.APEResources;
import nl.uu.cs.ape.utils.APEUtils;

import org.json.JSONObject;
Expand All @@ -19,6 +19,7 @@
import java.util.List;
import java.util.stream.Collectors;

import static nl.uu.cs.ape.sat.test.utils.Evaluation.fail;
import static nl.uu.cs.ape.sat.test.utils.Evaluation.success;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -50,12 +51,17 @@ public void infoOutputTest() {

@Test
public void coreValidationTest() {
final JSONObject correct_config = TestResources.getJSONResource("cli/gmt/base_config.json")
// add paths to the other files to the configuration
.put("ontology_path", TestResources.getAbsoluteResourcePath("cli/gmt/GMT_UseCase_taxonomy.owl"))
.put("tool_annotations_path", TestResources.getAbsoluteResourcePath("cli/gmt/tool_annotations.json"))
.put("constraints_path", TestResources.getAbsoluteResourcePath("cli/gmt/constraints_e0.json"))
.put("solutions_dir_path", TestResources.getAbsoluteResourcePath("cli/gmt"));
final JSONObject correct_config = APEResources.getJSONResource("cli/gmt/base_config.json");
if (correct_config.isEmpty())
{
fail("Could not retrieve resource '%s' ", "cli/gmt/base_config.json");
} else {
// add paths to the other files to the configuration
correct_config.put("ontology_path", APEResources.getAbsoluteResourcePath("cli/gmt/GMT_UseCase_taxonomy.owl"))
.put("tool_annotations_path", APEResources.getAbsoluteResourcePath("cli/gmt/tool_annotations.json"))
.put("constraints_path", APEResources.getAbsoluteResourcePath("cli/gmt/constraints_e0.json"))
.put("solutions_dir_path", APEResources.getAbsoluteResourcePath("cli/gmt"));
}

ValidationResults results = APECoreConfig.validate(correct_config);

Expand Down Expand Up @@ -107,12 +113,17 @@ public void coreValidationTest() {

@Test
public void runValidationTest() throws IOException, OWLOntologyCreationException {
final JSONObject correct_config = TestResources.getJSONResource("cli/gmt/base_config.json")
// add paths to the other files to the configuration
.put("ontology_path", TestResources.getAbsoluteResourcePath("cli/gmt/GMT_UseCase_taxonomy.owl"))
.put("tool_annotations_path", TestResources.getAbsoluteResourcePath("cli/gmt/tool_annotations.json"))
.put("constraints_path", TestResources.getAbsoluteResourcePath("cli/gmt/constraints_e0.json"))
.put("solutions_dir_path", TestResources.getAbsoluteResourcePath("cli/gmt"));
final JSONObject correct_config = APEResources.getJSONResource("cli/gmt/base_config.json");
if (correct_config.isEmpty())
{
fail("Could not retrieve resource '%s' ", "cli/gmt/base_config.json");
} else {
// add paths to the other files to the configuration
correct_config.put("ontology_path", APEResources.getAbsoluteResourcePath("cli/gmt/GMT_UseCase_taxonomy.owl"))
.put("tool_annotations_path", APEResources.getAbsoluteResourcePath("cli/gmt/tool_annotations.json"))
.put("constraints_path", APEResources.getAbsoluteResourcePath("cli/gmt/constraints_e0.json"))
.put("solutions_dir_path", APEResources.getAbsoluteResourcePath("cli/gmt"));
}

APEDomainSetup domainSetup = new APE(correct_config).getDomainSetup();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import nl.uu.cs.ape.models.Range;
import nl.uu.cs.ape.models.enums.ConfigEnum;
import nl.uu.cs.ape.sat.test.utils.Evaluation;
import nl.uu.cs.ape.sat.test.utils.TestResources;
import nl.uu.cs.ape.utils.APEResources;

import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -33,13 +33,13 @@ class APEConfigTest {
* A correct template construct that is converted to a String at initialisation.
*/
private static final String jsonTemplate = new JSONObject()
.put("ontology_path", TestResources.getAbsoluteResourcePath("template/ontology.owl"))
.put("ontology_path", APEResources.getAbsoluteResourcePath("template/ontology.owl"))
.put("ontologyPrefixIRI", "http://www.co-ode.org/ontologies/ont.owl#")
.put("toolsTaxonomyRoot", "ToolsTaxonomy")
.put("dataDimensionsTaxonomyRoots", new String[] { "TypesTaxonomy" })
.put("tool_annotations_path", TestResources.getAbsoluteResourcePath("template/tool_annotations.json"))
.put("constraints_path", TestResources.getAbsoluteResourcePath("template/constraints.json"))
.put("solutions_dir_path", TestResources.getAbsoluteResourcePath("template"))
.put("tool_annotations_path", APEResources.getAbsoluteResourcePath("template/tool_annotations.json"))
.put("constraints_path", APEResources.getAbsoluteResourcePath("template/constraints.json"))
.put("solutions_dir_path", APEResources.getAbsoluteResourcePath("template"))
.put("tool_seq_repeat", false)
.put("solution_length", new JSONObject().put(Range.MIN_TAG, 1).put(Range.MAX_TAG, 5))
.put("solutions", 5)
Expand Down Expand Up @@ -169,7 +169,7 @@ public void testIncorrectFilePaths() {
final String[] pathTags = new String[] { "ontology_path", "tool_annotations_path" };
final String[] wrongPaths = new String[] { null, "", "./does/not/exist.json", "does/not/exist.json",
"./does/not/exist/", "does/not/exist/",
TestResources.getAbsoluteResourcePath("") + "\\doesnotexist.json" };
APEResources.getAbsoluteResourcePath("") + "\\doesnotexist.json" };

for (String tag : pathTags) {
for (String path : wrongPaths) {
Expand Down Expand Up @@ -197,7 +197,7 @@ public void testIncorrectDirectoryPaths() {

final String[] pathTags = new String[] { "solutions_dir_path" };
final String[] wrongPaths = new String[] { "file.json",
TestResources.getAbsoluteResourcePath("") + "\\file.json" };
APEResources.getAbsoluteResourcePath("") + "\\file.json" };

for (String tag : pathTags) {
for (String path : wrongPaths) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/nl/uu/cs/ape/sat/test/utils/GitHubRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.Objects;

import nl.uu.cs.ape.utils.APEResources;
import static nl.uu.cs.ape.sat.test.utils.Evaluation.fail;
import static nl.uu.cs.ape.sat.test.utils.Evaluation.success;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -33,7 +34,7 @@ public class GitHubRepo {
private HashMap<Integer, TempFile> files;

public GitHubRepo(String repository, String commitOrBranch) {
this.absoluteLocalRoot = Paths.get(TestResources.getAbsoluteRoot(), "temp").toString();
this.absoluteLocalRoot = Paths.get(APEResources.getAbsoluteRoot(), "temp").toString();
this.repository = repository;
this.commit = commitOrBranch;
this.files = new HashMap<>();
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/nl/uu/cs/ape/test/sat/ape/CLITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import nl.uu.cs.ape.Main;
import nl.uu.cs.ape.configuration.APERunConfig;
import nl.uu.cs.ape.sat.test.utils.TestResources;
import nl.uu.cs.ape.utils.APEResources;

import org.apache.commons.io.FileUtils;
import org.json.JSONObject;
Expand Down Expand Up @@ -50,7 +50,7 @@ void run(String base_config_path, String ontology_path, String tools_path, Strin

// absolute solution_dir_path
final Path solution_path = Paths
.get(Objects.requireNonNull(TestResources.getAbsoluteResourcePath(solution_dir_path)));
.get(Objects.requireNonNull(APEResources.getAbsoluteResourcePath(solution_dir_path)));

// absolute Figures and Executables directories
final Path figures_path = solution_path.resolve(APERunConfig.FIGURES_FOLDER_NAME);
Expand All @@ -68,16 +68,16 @@ void run(String base_config_path, String ontology_path, String tools_path, Strin
}

// get the base configuration file
final JSONObject config_content = TestResources.getConfigResource(
final JSONObject config_content = APEResources.getConfigResource(
base_config_path,
ontology_path,
tools_path,
constraints_path,
solution_dir_path);

// create a new configuration file
final String config_path = TestResources
.writeFile(Paths.get(Objects.requireNonNull(TestResources.getAbsoluteResourcePath(solution_dir_path)))
final String config_path = APEResources
.writeFile(Paths.get(Objects.requireNonNull(APEResources.getAbsoluteResourcePath(solution_dir_path)))
.resolve("config.json").toAbsolutePath().toString(), config_content.toString(2));

Main.main(new String[] {
Expand All @@ -87,14 +87,14 @@ void run(String base_config_path, String ontology_path, String tools_path, Strin
// check whether images are produced correctly
assertTrue(Files.exists(figures_path));
final int figures_amount_generated = Objects.requireNonNull(
Paths.get(Objects.requireNonNull(TestResources.getAbsoluteResourcePath(solution_dir_path)))
Paths.get(Objects.requireNonNull(APEResources.getAbsoluteResourcePath(solution_dir_path)))
.resolve(APERunConfig.FIGURES_FOLDER_NAME).toFile().list()).length;
assertEquals(config_content.getInt("number_of_generated_graphs"), figures_amount_generated);

// check whether scripts are produced correctly
assertTrue(Files.exists(executables_path));
final int executables_amount_generated = Objects.requireNonNull(
Paths.get(Objects.requireNonNull(TestResources.getAbsoluteResourcePath(solution_dir_path)))
Paths.get(Objects.requireNonNull(APEResources.getAbsoluteResourcePath(solution_dir_path)))
.resolve(APERunConfig.EXECUTABLES_FOLDER_NAME).toFile().list()).length;
assertEquals(config_content.getInt("number_of_execution_scripts"), executables_amount_generated);
}
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/nl/uu/cs/ape/test/sat/ape/UseCaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import nl.uu.cs.ape.APE;
import nl.uu.cs.ape.configuration.APEConfigException;
import nl.uu.cs.ape.sat.test.utils.GitHubRepo;
import nl.uu.cs.ape.sat.test.utils.TestResources;
import nl.uu.cs.ape.utils.APEResources;
import nl.uu.cs.ape.utils.APEUtils;
import nl.uu.cs.ape.solver.solutionStructure.SolutionsList;

Expand Down Expand Up @@ -173,7 +173,11 @@ private static class UseCase {

public UseCase(String useCasePath, GitHubRepo repo) {

JSONObject useCase = TestResources.getJSONResource(useCasePath);
JSONObject useCase = APEResources.getJSONResource(useCasePath);
if (useCase.isEmpty())
{
fail("Could not retrieve resource '%s' ", useCasePath);
}

// read name
this.name = useCase.getString("name");
Expand Down
Loading