You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@taverna.apache.org by haouech <gi...@git.apache.org> on 2018/06/12 22:40:13 UTC

[GitHub] incubator-taverna-language pull request #38: Cwlparser

GitHub user haouech opened a pull request:

    https://github.com/apache/incubator-taverna-language/pull/38

    Cwlparser

    This is a pull request that adds structural import for a CWL workflow to Apache Taverna.
    The current code parses the cwl file to extract inputs, outputs and steps of a workflow, and then converts them to a Taverna workflow containing ports, processors and data links.
    
    In the tests, we try to compare expected objects (like InputWorkflowPort) with the newly created workflow from the cwl file. We do this by using the default equality of Taverna components (Implemented inside AbstractNamed class) but this way we try to compare the name and the parent of two objects. 
    Currently, we set the parent of the expected object to be the same as the parent of the created object, but this will modify the parent as well to point to the same object in the end and thus we'll have two equal objects all the time. 
    What we can do is set objects' parents to null before comparing and in that way we will compare the names and not the parents.
    
    Is there another approach or is the current one correct?

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/haouech/incubator-taverna-language cwlparser

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-taverna-language/pull/38.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #38
    
----
commit 309109286ee0ef07c5744de67c3f83463eb6713b
Author: Majdi Haouech <m....@...>
Date:   2018-05-21T13:26:57Z

    First commit, Add YAML file parser

commit 252e3d8b11914b16a8212ef86d1cf435017209fe
Author: Majdi Haouech <m....@...>
Date:   2018-05-21T13:29:02Z

    Add helper functions

commit 4d32489097c032f9a6c0786af2f033767811acc3
Author: Majdi Haouech <m....@...>
Date:   2018-05-21T13:37:15Z

    Parse inputs, add tests

commit ecc3b6729c0dccfe0943475b3207c255b1bb3cb1
Author: Majdi Haouech <m....@...>
Date:   2018-06-04T09:33:03Z

    Add CWL components

commit 6d6dc20086ca9b8e0f1c0ff0eccd9b58b936e452
Author: Majdi Haouech <m....@...>
Date:   2018-06-04T09:33:46Z

    Add CWL Parser, import helper from common activities

commit ba2941396dd0bc724d40d9b73589575aca246677
Author: Majdi Haouech <m....@...>
Date:   2018-06-04T09:38:01Z

    Add jackson and snackyaml dependencies

commit ee6b282edad17a1095af7a3c6a885c383ca71ee5
Author: Majdi Haouech <m....@...>
Date:   2018-06-04T09:38:37Z

    Add dummy test and workflow example

commit 881a409608e4fd8d6b820b8e9e54f1eb5e3c6d16
Author: Majdi Haouech <m....@...>
Date:   2018-06-11T14:51:06Z

    Split CWL parser and converter

commit 4ee2f5bc021c236aea248b0917a57d00b4d6ae66
Author: Majdi Haouech <m....@...>
Date:   2018-06-11T14:52:26Z

    Add main parser that parses the structure of a CWL workflow

commit 62c3615bf2bbd4a50d6bc864b399bfeb4064743d
Author: Majdi Haouech <m....@...>
Date:   2018-06-11T14:53:09Z

    Add parser tests

commit 289583c8e692d7531ca853a354eaeb6be0948c15
Author: Majdi Haouech <m....@...>
Date:   2018-06-11T15:01:24Z

    Fix wild card imports

----


---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by stain <gi...@git.apache.org>.
Github user stain commented on a diff in the pull request:

    https://github.com/apache/incubator-taverna-language/pull/38#discussion_r196754260
  
    --- Diff: taverna-scufl2-cwl/src/test/resources/1st-tool.cwl ---
    @@ -0,0 +1,10 @@
    +cwlVersion: v1.0
    --- End diff --
    
    As commented above, add Apache license headers if these are your own files.


---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by stain <gi...@git.apache.org>.
Github user stain commented on a diff in the pull request:

    https://github.com/apache/incubator-taverna-language/pull/38#discussion_r196754088
  
    --- Diff: taverna-scufl2-cwl/src/test/java/org/apache/taverna/scufl2/cwl/TestParser.java ---
    @@ -0,0 +1,96 @@
    +package org.apache.taverna.scufl2.cwl;
    +
    +
    +import java.util.Set;
    +import java.util.HashSet;
    +
    +import org.junit.Before;
    +import org.junit.Test;
    +import static org.junit.Assert.assertEquals;
    +
    +import org.yaml.snakeyaml.Yaml;
    +
    +import com.fasterxml.jackson.core.type.TypeReference;
    +import com.fasterxml.jackson.databind.JsonNode;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.fasterxml.jackson.databind.node.ArrayNode;
    +
    +import org.apache.taverna.scufl2.api.core.Workflow;
    +import org.apache.taverna.scufl2.api.core.Processor;
    +import org.apache.taverna.scufl2.api.core.DataLink;
    +
    +import org.apache.taverna.scufl2.api.common.NamedSet;
    +
    +import org.apache.taverna.scufl2.api.port.InputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.OutputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.InputProcessorPort;
    +
    +
    +public class TestParser {
    +    private static final String HELLO_WORLD_CWL = "/hello_world.cwl";
    +
    +    private static JsonNode cwlFile;
    +    private WorkflowParser parser;
    +    private Workflow workflow;
    +
    +    @Before
    +    public void initialize() {
    +
    +        Yaml reader = new Yaml();
    +        ObjectMapper mapper = new ObjectMapper();
    +        cwlFile = mapper.valueToTree(reader.load(TestParser.class.getResourceAsStream(HELLO_WORLD_CWL)));
    +        System.out.println(cwlFile);
    +        this.parser = new WorkflowParser(cwlFile);
    +
    +        this.workflow = parser.buildWorkflow();
    +    }
    +
    +    @Test
    +    public void testParseInputs() throws Exception {
    +
    +        NamedSet<InputWorkflowPort> workflowInputs = workflow.getInputPorts();
    +        NamedSet<InputWorkflowPort> expectedInputs = new NamedSet<>();
    +        expectedInputs.add(new InputWorkflowPort(workflow, "name"));
    +
    +        assertEquals(expectedInputs, workflowInputs);
    +    }
    +
    +    @Test
    +    public void testParseOutputs() throws Exception {
    +
    +        NamedSet<OutputWorkflowPort> workflowOutputs = workflow.getOutputPorts();
    +        NamedSet<OutputWorkflowPort> expectedOutputs = new NamedSet<>();
    +
    +        assertEquals(expectedOutputs, workflowOutputs);
    +    }
    +
    +    @Test
    +    public void testParseProcessors() throws Exception {
    +
    +        NamedSet<Processor> workflowProcessors = workflow.getProcessors();
    +        NamedSet<Processor> expectedProcessors = new NamedSet<>();
    +        expectedProcessors.add(new Processor(workflow, "step1"));
    +
    +        assertEquals(expectedProcessors, workflowProcessors);
    +    }
    +
    +    @Test
    +    public void testParseDataLinks() throws Exception {
    +
    +        Set<DataLink> workflowDataLinks = workflow.getDataLinks();
    +        Set<DataLink> expectedDataLinks = new HashSet<>();
    +        Set<Processor> processorSet = workflow.getProcessors();
    +        // processorSet has one processor
    +        Processor processor = processorSet.iterator().next();
    --- End diff --
    
    perhaps you can get it from [processorSet.getByName()](https://github.com/apache/incubator-taverna-language/blob/master/taverna-scufl2-api/src/main/java/org/apache/taverna/scufl2/api/common/NamedSet.java#L196) if you type `processorSet` as `NamedSet` instead.



---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-taverna-language/pull/38


---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by haouech <gi...@git.apache.org>.
Github user haouech commented on a diff in the pull request:

    https://github.com/apache/incubator-taverna-language/pull/38#discussion_r197053732
  
    --- Diff: taverna-scufl2-cwl/src/test/java/org/apache/taverna/scufl2/cwl/TestParser.java ---
    @@ -0,0 +1,96 @@
    +package org.apache.taverna.scufl2.cwl;
    +
    +
    +import java.util.Set;
    +import java.util.HashSet;
    +
    +import org.junit.Before;
    +import org.junit.Test;
    +import static org.junit.Assert.assertEquals;
    +
    +import org.yaml.snakeyaml.Yaml;
    +
    +import com.fasterxml.jackson.core.type.TypeReference;
    +import com.fasterxml.jackson.databind.JsonNode;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.fasterxml.jackson.databind.node.ArrayNode;
    +
    +import org.apache.taverna.scufl2.api.core.Workflow;
    +import org.apache.taverna.scufl2.api.core.Processor;
    +import org.apache.taverna.scufl2.api.core.DataLink;
    +
    +import org.apache.taverna.scufl2.api.common.NamedSet;
    +
    +import org.apache.taverna.scufl2.api.port.InputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.OutputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.InputProcessorPort;
    +
    +
    +public class TestParser {
    +    private static final String HELLO_WORLD_CWL = "/hello_world.cwl";
    +
    +    private static JsonNode cwlFile;
    +    private WorkflowParser parser;
    +    private Workflow workflow;
    +
    +    @Before
    +    public void initialize() {
    +
    +        Yaml reader = new Yaml();
    +        ObjectMapper mapper = new ObjectMapper();
    +        cwlFile = mapper.valueToTree(reader.load(TestParser.class.getResourceAsStream(HELLO_WORLD_CWL)));
    +        System.out.println(cwlFile);
    +        this.parser = new WorkflowParser(cwlFile);
    +
    +        this.workflow = parser.buildWorkflow();
    +    }
    +
    +    @Test
    +    public void testParseInputs() throws Exception {
    +
    +        NamedSet<InputWorkflowPort> workflowInputs = workflow.getInputPorts();
    +        NamedSet<InputWorkflowPort> expectedInputs = new NamedSet<>();
    +        expectedInputs.add(new InputWorkflowPort(workflow, "name"));
    +
    +        assertEquals(expectedInputs, workflowInputs);
    +    }
    +
    +    @Test
    +    public void testParseOutputs() throws Exception {
    +
    +        NamedSet<OutputWorkflowPort> workflowOutputs = workflow.getOutputPorts();
    +        NamedSet<OutputWorkflowPort> expectedOutputs = new NamedSet<>();
    +
    +        assertEquals(expectedOutputs, workflowOutputs);
    +    }
    +
    +    @Test
    +    public void testParseProcessors() throws Exception {
    +
    +        NamedSet<Processor> workflowProcessors = workflow.getProcessors();
    +        NamedSet<Processor> expectedProcessors = new NamedSet<>();
    +        expectedProcessors.add(new Processor(workflow, "step1"));
    +
    +        assertEquals(expectedProcessors, workflowProcessors);
    +    }
    +
    +    @Test
    +    public void testParseDataLinks() throws Exception {
    +
    +        Set<DataLink> workflowDataLinks = workflow.getDataLinks();
    +        Set<DataLink> expectedDataLinks = new HashSet<>();
    +        Set<Processor> processorSet = workflow.getProcessors();
    +        // processorSet has one processor
    --- End diff --
    
    Done.


---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by stain <gi...@git.apache.org>.
Github user stain commented on a diff in the pull request:

    https://github.com/apache/incubator-taverna-language/pull/38#discussion_r196753530
  
    --- Diff: taverna-scufl2-cwl/src/test/java/org/apache/taverna/scufl2/cwl/TestParser.java ---
    @@ -0,0 +1,96 @@
    +package org.apache.taverna.scufl2.cwl;
    +
    +
    +import java.util.Set;
    +import java.util.HashSet;
    +
    +import org.junit.Before;
    +import org.junit.Test;
    +import static org.junit.Assert.assertEquals;
    +
    +import org.yaml.snakeyaml.Yaml;
    +
    +import com.fasterxml.jackson.core.type.TypeReference;
    +import com.fasterxml.jackson.databind.JsonNode;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.fasterxml.jackson.databind.node.ArrayNode;
    +
    +import org.apache.taverna.scufl2.api.core.Workflow;
    +import org.apache.taverna.scufl2.api.core.Processor;
    +import org.apache.taverna.scufl2.api.core.DataLink;
    +
    +import org.apache.taverna.scufl2.api.common.NamedSet;
    +
    +import org.apache.taverna.scufl2.api.port.InputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.OutputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.InputProcessorPort;
    +
    +
    +public class TestParser {
    +    private static final String HELLO_WORLD_CWL = "/hello_world.cwl";
    +
    +    private static JsonNode cwlFile;
    +    private WorkflowParser parser;
    +    private Workflow workflow;
    +
    +    @Before
    +    public void initialize() {
    +
    +        Yaml reader = new Yaml();
    +        ObjectMapper mapper = new ObjectMapper();
    +        cwlFile = mapper.valueToTree(reader.load(TestParser.class.getResourceAsStream(HELLO_WORLD_CWL)));
    +        System.out.println(cwlFile);
    +        this.parser = new WorkflowParser(cwlFile);
    +
    +        this.workflow = parser.buildWorkflow();
    +    }
    +
    +    @Test
    +    public void testParseInputs() throws Exception {
    +
    +        NamedSet<InputWorkflowPort> workflowInputs = workflow.getInputPorts();
    +        NamedSet<InputWorkflowPort> expectedInputs = new NamedSet<>();
    +        expectedInputs.add(new InputWorkflowPort(workflow, "name"));
    --- End diff --
    
    
    
    This would use the same `workflow` instance from the parser, As the [`InputWorkflowPort` constructor](https://github.com/apache/incubator-taverna-language/blob/master/taverna-scufl2-api/src/main/java/org/apache/taverna/scufl2/api/port/InputWorkflowPort.java#L48) with a parent will effectively be calling [inputPort.setParent(workflow)](https://github.com/apache/incubator-taverna-language/blob/master/taverna-scufl2-api/src/main/java/org/apache/taverna/scufl2/api/port/InputWorkflowPort.java#L73) which would insert the expected port into `parent.getInputPorts()`.
    
    Now in this test the expected parent is the same as the parsed parent, so the expected port is [added](https://github.com/apache/incubator-taverna-language/blob/master/taverna-scufl2-api/src/main/java/org/apache/taverna/scufl2/api/common/NamedSet.java#L73) to the already populated `NamedSet`, replacing the parsed `InputWorkflowPort` (as if the parsing worked, it has the same name). Thus these collections will generally match because it's the very same JVM instance - we have lost the parsed port which may otherwise be wrong.
    
    Rather you need to make the equivalent tree of expected objects, and make both orphaned. This is because all WorkflowBeans have an [`.equals`](https://github.com/apache/incubator-taverna-language/blob/master/taverna-scufl2-api/src/main/java/org/apache/taverna/scufl2/api/common/AbstractNamed.java#L103) that simply checks `.getName()`, and optionally `.getParent()` and `.getType()`.
    
    So we can short-circuit this ancestor comparisons by setting parent to null at some point in parsed and expected - that messing about is OK for unit tests as `@Before` is started fresh for each `@Test`.
    
    Something like
    
    ```java
    workflow.setParent(null) // Orphaned
    expectedWorkflow = new Workflow(workflow.getName()); // same name
    expectedInputs = expectedWorkflow.getInputPorts();
    expectedInputs.add(new InputWorkflowPort(expectedWorkflow, "name"));
    ```
    
    I understand if you have concerns about this weird parenting equality check and those constructors, we can raise that on dev@taverna as a separate discussion thread to see if we can change it to something more intuitive.


---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by haouech <gi...@git.apache.org>.
Github user haouech commented on a diff in the pull request:

    https://github.com/apache/incubator-taverna-language/pull/38#discussion_r197054058
  
    --- Diff: taverna-scufl2-cwl/src/test/resources/1st-tool.cwl ---
    @@ -0,0 +1,10 @@
    +cwlVersion: v1.0
    --- End diff --
    
    I will add all the headers. Thanks


---

Re: [GitHub] incubator-taverna-language issue #38: Cwlparser

Posted by Stian Soiland-Reyes <st...@apache.org>.
On Thu, 21 Jun 2018 08:43:40 +0000 (UTC), haouech <gi...@git.apache.org> wrote:
> Github user haouech commented on the issue:
> 
>     https://github.com/apache/incubator-taverna-language/pull/38
>   
>     Thank you so much for the comments.

Merged - thank you Majdi! 

We should try to get a new pull request ready for the Phase 2 GSOC
evaluation next week.

-- 
Stian Soiland-Reyes
https://orcid.org/0000-0001-9842-9718


[GitHub] incubator-taverna-language issue #38: Cwlparser

Posted by haouech <gi...@git.apache.org>.
Github user haouech commented on the issue:

    https://github.com/apache/incubator-taverna-language/pull/38
  
    Thank you so much for the comments.


---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by haouech <gi...@git.apache.org>.
Github user haouech commented on a diff in the pull request:

    https://github.com/apache/incubator-taverna-language/pull/38#discussion_r197053583
  
    --- Diff: taverna-scufl2-cwl/src/test/java/org/apache/taverna/scufl2/cwl/TestParser.java ---
    @@ -0,0 +1,96 @@
    +package org.apache.taverna.scufl2.cwl;
    +
    +
    +import java.util.Set;
    +import java.util.HashSet;
    +
    +import org.junit.Before;
    +import org.junit.Test;
    +import static org.junit.Assert.assertEquals;
    +
    +import org.yaml.snakeyaml.Yaml;
    +
    +import com.fasterxml.jackson.core.type.TypeReference;
    +import com.fasterxml.jackson.databind.JsonNode;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.fasterxml.jackson.databind.node.ArrayNode;
    +
    +import org.apache.taverna.scufl2.api.core.Workflow;
    +import org.apache.taverna.scufl2.api.core.Processor;
    +import org.apache.taverna.scufl2.api.core.DataLink;
    +
    +import org.apache.taverna.scufl2.api.common.NamedSet;
    +
    +import org.apache.taverna.scufl2.api.port.InputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.OutputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.InputProcessorPort;
    +
    +
    +public class TestParser {
    +    private static final String HELLO_WORLD_CWL = "/hello_world.cwl";
    +
    +    private static JsonNode cwlFile;
    +    private WorkflowParser parser;
    +    private Workflow workflow;
    +
    +    @Before
    +    public void initialize() {
    +
    +        Yaml reader = new Yaml();
    +        ObjectMapper mapper = new ObjectMapper();
    +        cwlFile = mapper.valueToTree(reader.load(TestParser.class.getResourceAsStream(HELLO_WORLD_CWL)));
    +        System.out.println(cwlFile);
    +        this.parser = new WorkflowParser(cwlFile);
    +
    +        this.workflow = parser.buildWorkflow();
    +    }
    +
    +    @Test
    +    public void testParseInputs() throws Exception {
    +
    +        NamedSet<InputWorkflowPort> workflowInputs = workflow.getInputPorts();
    +        NamedSet<InputWorkflowPort> expectedInputs = new NamedSet<>();
    +        expectedInputs.add(new InputWorkflowPort(workflow, "name"));
    --- End diff --
    
    I understand. I will make the workflows orphans and create the same structure for the parsed and the expected workflows.


---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by haouech <gi...@git.apache.org>.
Github user haouech commented on a diff in the pull request:

    https://github.com/apache/incubator-taverna-language/pull/38#discussion_r197053923
  
    --- Diff: taverna-scufl2-cwl/src/test/java/org/apache/taverna/scufl2/cwl/TestParser.java ---
    @@ -0,0 +1,96 @@
    +package org.apache.taverna.scufl2.cwl;
    +
    +
    +import java.util.Set;
    +import java.util.HashSet;
    +
    +import org.junit.Before;
    +import org.junit.Test;
    +import static org.junit.Assert.assertEquals;
    +
    +import org.yaml.snakeyaml.Yaml;
    +
    +import com.fasterxml.jackson.core.type.TypeReference;
    +import com.fasterxml.jackson.databind.JsonNode;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.fasterxml.jackson.databind.node.ArrayNode;
    +
    +import org.apache.taverna.scufl2.api.core.Workflow;
    +import org.apache.taverna.scufl2.api.core.Processor;
    +import org.apache.taverna.scufl2.api.core.DataLink;
    +
    +import org.apache.taverna.scufl2.api.common.NamedSet;
    +
    +import org.apache.taverna.scufl2.api.port.InputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.OutputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.InputProcessorPort;
    +
    +
    +public class TestParser {
    +    private static final String HELLO_WORLD_CWL = "/hello_world.cwl";
    +
    +    private static JsonNode cwlFile;
    +    private WorkflowParser parser;
    +    private Workflow workflow;
    +
    +    @Before
    +    public void initialize() {
    +
    +        Yaml reader = new Yaml();
    +        ObjectMapper mapper = new ObjectMapper();
    +        cwlFile = mapper.valueToTree(reader.load(TestParser.class.getResourceAsStream(HELLO_WORLD_CWL)));
    +        System.out.println(cwlFile);
    +        this.parser = new WorkflowParser(cwlFile);
    +
    +        this.workflow = parser.buildWorkflow();
    +    }
    +
    +    @Test
    +    public void testParseInputs() throws Exception {
    +
    +        NamedSet<InputWorkflowPort> workflowInputs = workflow.getInputPorts();
    +        NamedSet<InputWorkflowPort> expectedInputs = new NamedSet<>();
    +        expectedInputs.add(new InputWorkflowPort(workflow, "name"));
    +
    +        assertEquals(expectedInputs, workflowInputs);
    +    }
    +
    +    @Test
    +    public void testParseOutputs() throws Exception {
    +
    +        NamedSet<OutputWorkflowPort> workflowOutputs = workflow.getOutputPorts();
    +        NamedSet<OutputWorkflowPort> expectedOutputs = new NamedSet<>();
    +
    +        assertEquals(expectedOutputs, workflowOutputs);
    +    }
    +
    +    @Test
    +    public void testParseProcessors() throws Exception {
    +
    +        NamedSet<Processor> workflowProcessors = workflow.getProcessors();
    +        NamedSet<Processor> expectedProcessors = new NamedSet<>();
    +        expectedProcessors.add(new Processor(workflow, "step1"));
    +
    +        assertEquals(expectedProcessors, workflowProcessors);
    +    }
    +
    +    @Test
    +    public void testParseDataLinks() throws Exception {
    +
    +        Set<DataLink> workflowDataLinks = workflow.getDataLinks();
    +        Set<DataLink> expectedDataLinks = new HashSet<>();
    +        Set<Processor> processorSet = workflow.getProcessors();
    +        // processorSet has one processor
    +        Processor processor = processorSet.iterator().next();
    --- End diff --
    
    This will be much clearer. I'll do it.


---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by stain <gi...@git.apache.org>.
Github user stain commented on a diff in the pull request:

    https://github.com/apache/incubator-taverna-language/pull/38#discussion_r196753724
  
    --- Diff: taverna-scufl2-cwl/src/test/java/org/apache/taverna/scufl2/cwl/TestParser.java ---
    @@ -0,0 +1,96 @@
    +package org.apache.taverna.scufl2.cwl;
    +
    +
    +import java.util.Set;
    +import java.util.HashSet;
    +
    +import org.junit.Before;
    +import org.junit.Test;
    +import static org.junit.Assert.assertEquals;
    +
    +import org.yaml.snakeyaml.Yaml;
    +
    +import com.fasterxml.jackson.core.type.TypeReference;
    +import com.fasterxml.jackson.databind.JsonNode;
    +import com.fasterxml.jackson.databind.ObjectMapper;
    +import com.fasterxml.jackson.databind.node.ArrayNode;
    +
    +import org.apache.taverna.scufl2.api.core.Workflow;
    +import org.apache.taverna.scufl2.api.core.Processor;
    +import org.apache.taverna.scufl2.api.core.DataLink;
    +
    +import org.apache.taverna.scufl2.api.common.NamedSet;
    +
    +import org.apache.taverna.scufl2.api.port.InputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.OutputWorkflowPort;
    +import org.apache.taverna.scufl2.api.port.InputProcessorPort;
    +
    +
    +public class TestParser {
    +    private static final String HELLO_WORLD_CWL = "/hello_world.cwl";
    +
    +    private static JsonNode cwlFile;
    +    private WorkflowParser parser;
    +    private Workflow workflow;
    +
    +    @Before
    +    public void initialize() {
    +
    +        Yaml reader = new Yaml();
    +        ObjectMapper mapper = new ObjectMapper();
    +        cwlFile = mapper.valueToTree(reader.load(TestParser.class.getResourceAsStream(HELLO_WORLD_CWL)));
    +        System.out.println(cwlFile);
    +        this.parser = new WorkflowParser(cwlFile);
    +
    +        this.workflow = parser.buildWorkflow();
    +    }
    +
    +    @Test
    +    public void testParseInputs() throws Exception {
    +
    +        NamedSet<InputWorkflowPort> workflowInputs = workflow.getInputPorts();
    +        NamedSet<InputWorkflowPort> expectedInputs = new NamedSet<>();
    +        expectedInputs.add(new InputWorkflowPort(workflow, "name"));
    +
    +        assertEquals(expectedInputs, workflowInputs);
    +    }
    +
    +    @Test
    +    public void testParseOutputs() throws Exception {
    +
    +        NamedSet<OutputWorkflowPort> workflowOutputs = workflow.getOutputPorts();
    +        NamedSet<OutputWorkflowPort> expectedOutputs = new NamedSet<>();
    +
    +        assertEquals(expectedOutputs, workflowOutputs);
    +    }
    +
    +    @Test
    +    public void testParseProcessors() throws Exception {
    +
    +        NamedSet<Processor> workflowProcessors = workflow.getProcessors();
    +        NamedSet<Processor> expectedProcessors = new NamedSet<>();
    +        expectedProcessors.add(new Processor(workflow, "step1"));
    +
    +        assertEquals(expectedProcessors, workflowProcessors);
    +    }
    +
    +    @Test
    +    public void testParseDataLinks() throws Exception {
    +
    +        Set<DataLink> workflowDataLinks = workflow.getDataLinks();
    +        Set<DataLink> expectedDataLinks = new HashSet<>();
    +        Set<Processor> processorSet = workflow.getProcessors();
    +        // processorSet has one processor
    --- End diff --
    
    Test should verify that it's just one.


---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by stain <gi...@git.apache.org>.
Github user stain commented on a diff in the pull request:

    https://github.com/apache/incubator-taverna-language/pull/38#discussion_r196747756
  
    --- Diff: taverna-scufl2-cwl/src/test/java/org/apache/taverna/scufl2/cwl/TestParser.java ---
    @@ -0,0 +1,96 @@
    +package org.apache.taverna.scufl2.cwl;
    --- End diff --
    
    Would you add the Apache license header also to the test source code?
    
    If the CWL files are your own (I understood so) then could they also have the Apache license header? You will probably need to use [`#` YAML comments](http://yaml.org/spec/1.2/spec.html#id2780069) below the `#!/usr/bin/env cwlrunner` shebang header.


---

[GitHub] incubator-taverna-language pull request #38: Cwlparser

Posted by haouech <gi...@git.apache.org>.
Github user haouech commented on a diff in the pull request:

    https://github.com/apache/incubator-taverna-language/pull/38#discussion_r197052772
  
    --- Diff: taverna-scufl2-cwl/src/test/java/org/apache/taverna/scufl2/cwl/TestParser.java ---
    @@ -0,0 +1,96 @@
    +package org.apache.taverna.scufl2.cwl;
    --- End diff --
    
    Yes the CWL files are my own, I will add the header.


---