-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#184 Adding tests for the Workflow normalization
- Loading branch information
1 parent
969c9c0
commit 01cd51a
Showing
6 changed files
with
178 additions
and
72 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
ml2wf/src/test/java/com/ml2wf/v2/testutils/TreeTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.ml2wf.v2.testutils; | ||
|
||
import com.ml2wf.v2.tree.wf.factory.IWorkflowFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public abstract class TreeTestBase { | ||
|
||
/** | ||
* {@code ClassLoader}'s instance used to get resources. | ||
* | ||
* @see ClassLoader | ||
*/ | ||
protected static ClassLoader classLoader = TreeTestBase.class.getClassLoader(); | ||
|
||
protected final IWorkflowFactory workflowFactory; | ||
} |
69 changes: 69 additions & 0 deletions
69
ml2wf/src/test/java/com/ml2wf/v2/testutils/XMLWorkflowTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.ml2wf.v2.testutils; | ||
|
||
import com.ml2wf.util.FileHandler; | ||
import com.ml2wf.util.Pair; | ||
import com.ml2wf.v2.tree.wf.Workflow; | ||
import com.ml2wf.v2.xml.XMLWorkflowFactory; | ||
import io.vavr.control.Try; | ||
import org.apache.commons.io.FileUtils; | ||
|
||
import java.io.File; | ||
import java.net.URISyntaxException; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class XMLWorkflowTestBase extends TreeTestBase { | ||
|
||
/** | ||
* Meta workflows' directory. | ||
*/ | ||
protected static final String META_DIRECTORY = "./wf_meta/"; | ||
|
||
public XMLWorkflowTestBase() { | ||
super(new XMLWorkflowFactory()); | ||
} | ||
|
||
/** | ||
* Returns a {@code Stream} containing all meta-workflows located under the | ||
* {@link #META_DIRECTORY} directory. | ||
* | ||
* @return a {@code Stream} containing all meta-workflows located under the | ||
* {@link #META_DIRECTORY} directory | ||
* | ||
* @throws URISyntaxException | ||
* | ||
* @see FileUtils | ||
*/ | ||
protected static Stream<File> metaFiles() throws URISyntaxException { | ||
File instanceDir = new File( | ||
Objects.requireNonNull(classLoader.getResource(META_DIRECTORY)).toURI()); | ||
return new HashSet<>(FileUtils.listFiles(instanceDir, FileHandler.getWfExtensions(), true)).stream(); | ||
} | ||
|
||
protected Pair<Workflow, Workflow> getReferenceInstanceWorkflows(File file) { | ||
Try<Workflow> tryReferenceWorkflow = workflowFactory.workflowFromFile(file); | ||
assertTrue(tryReferenceWorkflow.isSuccess()); | ||
// the workflow to instantiate that will be compared to the reference one | ||
Try<Workflow> tryWorkflowToInstantiate = workflowFactory.workflowFromFile(file); | ||
assertTrue(tryWorkflowToInstantiate.isSuccess()); | ||
Workflow workflowToInstantiate = tryWorkflowToInstantiate.get(); | ||
// instantiating | ||
workflowToInstantiate.instantiate(); | ||
return new Pair<>(tryReferenceWorkflow.get(), workflowToInstantiate); | ||
} | ||
|
||
protected Pair<Workflow, Workflow> getReferenceNormalizedWorkflows(File file) { | ||
Try<Workflow> tryReferenceWorkflow = workflowFactory.workflowFromFile(file); | ||
assertTrue(tryReferenceWorkflow.isSuccess()); | ||
// the workflow to instantiate that will be compared to the reference one | ||
Try<Workflow> tryWorkflowToInstantiate = workflowFactory.workflowFromFile(file); | ||
assertTrue(tryWorkflowToInstantiate.isSuccess()); | ||
Workflow workflowToInstantiate = tryWorkflowToInstantiate.get(); | ||
// instantiating | ||
workflowToInstantiate.normalize(); | ||
return new Pair<>(tryReferenceWorkflow.get(), workflowToInstantiate); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
ml2wf/src/test/java/com/ml2wf/v2/tree/wf/TestWorkflowNormalization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.ml2wf.v2.tree.wf; | ||
|
||
import com.ml2wf.v2.testutils.XMLWorkflowTestBase; | ||
import com.ml2wf.v2.testutils.assertions.ForEachTaskAssertion; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.io.File; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class TestWorkflowNormalization extends XMLWorkflowTestBase { | ||
|
||
@ParameterizedTest | ||
@MethodSource("metaFiles") | ||
@DisplayName("Testing that the normalization updates the workflow's tasks names as expected") | ||
void testNormalizationUpdatesNames(File file) { | ||
ForEachTaskAssertion.builder() | ||
.workflowPair(getReferenceNormalizedWorkflows(file)) | ||
.forEachTask((referenceTask, instantiatedTask) -> { | ||
assertEquals(referenceTask.getId(), instantiatedTask.getId()); | ||
assertFalse(instantiatedTask.getName().contains(" ")); | ||
assertEquals(referenceTask.getName().replace(" ", "_"), | ||
instantiatedTask.getName()); | ||
}) | ||
.afterTasksIteration((referenceProcessIterator, instanceProcessIterator) -> | ||
assertFalse(referenceProcessIterator.hasNext() || instanceProcessIterator.hasNext()) | ||
) | ||
.afterProcessesIteration((referenceInstanceProcess, referenceInstanceWorkflows) -> | ||
assertFalse(referenceInstanceProcess.hasNext() || referenceInstanceWorkflows.hasNext()) | ||
) | ||
.build() | ||
.verify(); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("metaFiles") | ||
@DisplayName("Testing that the normalization does not impact the iteration") | ||
void testNormalizationDoesNotImpactIteration(File file) { | ||
ForEachTaskAssertion.builder() | ||
.workflowPair(getReferenceNormalizedWorkflows(file)) | ||
.forEachTask((referenceTask, instantiatedTask) -> { | ||
assertEquals(referenceTask.getId(), instantiatedTask.getId()); | ||
// note that we don't test the tasks' names as it is not the purpose of this test | ||
}) | ||
.afterTasksIteration((referenceProcessIterator, instanceProcessIterator) -> | ||
assertFalse(referenceProcessIterator.hasNext() || instanceProcessIterator.hasNext()) | ||
) | ||
.afterProcessesIteration((referenceInstanceProcess, referenceInstanceWorkflows) -> | ||
assertFalse(referenceInstanceProcess.hasNext() || referenceInstanceWorkflows.hasNext()) | ||
) | ||
.build() | ||
.verify(); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("metaFiles") | ||
@DisplayName("Testing that the normalization does not impact the documentation") | ||
void testNormalizationDoesNotImpactTheDocumentation(File file) { | ||
ForEachTaskAssertion.builder() | ||
.workflowPair(getReferenceNormalizedWorkflows(file)) | ||
.forEachTask((referenceTask, instantiatedTask) -> { | ||
assertEquals(referenceTask.getId(), instantiatedTask.getId()); | ||
if (referenceTask.getDocumentation() != null) { | ||
assertEquals(referenceTask.getDocumentation().getId(), | ||
instantiatedTask.getDocumentation().getId()); | ||
assertTrue(instantiatedTask.getDocumentation().getContent() | ||
.contains(referenceTask.getDocumentation().getContent())); | ||
} | ||
}) | ||
.afterTasksIteration((referenceProcessIterator, instanceProcessIterator) -> | ||
assertFalse(referenceProcessIterator.hasNext() || instanceProcessIterator.hasNext()) | ||
) | ||
.afterProcessesIteration((referenceInstanceProcess, referenceInstanceWorkflows) -> | ||
assertFalse(referenceInstanceProcess.hasNext() || referenceInstanceWorkflows.hasNext()) | ||
) | ||
.build() | ||
.verify(); | ||
} | ||
} |