You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by st...@apache.org on 2016/08/21 12:59:23 UTC

[06/50] [abbrv] incubator-taverna-common-activities git commit: CWLUtil test cases

CWLUtil test cases


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/commit/c191822b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/c191822b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/c191822b

Branch: refs/heads/cwl-browse
Commit: c191822b801d47c9f71a1535422b226ac90e0b44
Parents: c815a14
Author: ThilinaManamgoda <ma...@gmail.com>
Authored: Mon Jul 4 23:36:17 2016 +0530
Committer: ThilinaManamgoda <ma...@gmail.com>
Committed: Mon Jul 4 23:36:17 2016 +0530

----------------------------------------------------------------------
 taverna-cwl-utilities/CWLFiles/customtool1.cwl  |  67 ++++++++++++
 .../CWLFiles/customtoolrecord.cwl               |  41 ++++++++
 taverna-cwl-utilities/pom.xml                   |   7 ++
 .../apache/taverna/cwl/utilities/CWLUtil.java   |  14 ++-
 .../taverna/cwl/utilities/CWLUtilTest.java      | 103 +++++++++++++++++++
 5 files changed, 227 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c191822b/taverna-cwl-utilities/CWLFiles/customtool1.cwl
----------------------------------------------------------------------
diff --git a/taverna-cwl-utilities/CWLFiles/customtool1.cwl b/taverna-cwl-utilities/CWLFiles/customtool1.cwl
new file mode 100644
index 0000000..227ba16
--- /dev/null
+++ b/taverna-cwl-utilities/CWLFiles/customtool1.cwl
@@ -0,0 +1,67 @@
+################################################################################
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#     contributor license agreements.  See the NOTICE file distributed with
+#     this work for additional information regarding copyright ownership.
+#     The ASF licenses this file to You under the Apache License, Version 2.0
+#     (the "License"); you may not use this file except in compliance with
+#     the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#     Unless required by applicable law or agreed to in writing, software
+#     distributed under the License is distributed on an "AS IS" BASIS,
+#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#     See the License for the specific language governing permissions and
+#     limitations under the License.
+#################################################################################
+
+
+#!/usr/bin/env cwl-runner
+
+class: CommandLineTool
+cwlVersion: cwl:draft-3
+
+$namespaces:
+ edam: http://edamontology.org/
+  
+inputs:
+  - id: input_1
+    type: int
+    label: input 1 testing label
+    description: this is a short description of input 1
+    format: edam:format_2323
+
+  - id: input_2
+    type:
+      type: array
+      items: int
+    label: input 2 testing label
+    description: this is a short description of input 2
+    format: $expression
+
+  - id: input_3
+    type: String
+    label: input 3 testing label
+    description: this is a short description of input 3
+    format: noNameSpace:testing
+
+outputs:
+  - id: output_1
+    type: int
+    label: output 1 testing label
+    description: this is a short description of output 1
+    format: just a string
+
+  - id: output_2
+    type: String
+    label: output 2 testing label
+    description: this is a short description of output 2
+    format: ["edam:format_2323", just a string]
+    
+label: This is a short description of the tool
+
+description: |
+ This is a much longer description of the tool. This can be displayed in
+ the service detail panel	 	 
+
+basecommand: echo

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c191822b/taverna-cwl-utilities/CWLFiles/customtoolrecord.cwl
----------------------------------------------------------------------
diff --git a/taverna-cwl-utilities/CWLFiles/customtoolrecord.cwl b/taverna-cwl-utilities/CWLFiles/customtoolrecord.cwl
new file mode 100644
index 0000000..f008bdb
--- /dev/null
+++ b/taverna-cwl-utilities/CWLFiles/customtoolrecord.cwl
@@ -0,0 +1,41 @@
+################################################################################
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#     contributor license agreements.  See the NOTICE file distributed with
+#     this work for additional information regarding copyright ownership.
+#     The ASF licenses this file to You under the Apache License, Version 2.0
+#     (the "License"); you may not use this file except in compliance with
+#     the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+#     Unless required by applicable law or agreed to in writing, software
+#     distributed under the License is distributed on an "AS IS" BASIS,
+#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#     See the License for the specific language governing permissions and
+#     limitations under the License.
+#################################################################################
+
+#!/usr/bin/env cwl-runner
+
+class: CommandLineTool
+cwlVersion: cwl:draft-3
+
+inputs:
+  - id: input_1
+    type: record
+
+  - id: input_2
+    type:
+      type: array
+      items: int
+  - id: input_3
+    type: String
+
+outputs:
+  - id: output_1
+    type: int
+
+  - id: ouput_2
+    type: String
+
+basecommand: echo

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c191822b/taverna-cwl-utilities/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-cwl-utilities/pom.xml b/taverna-cwl-utilities/pom.xml
index 5316b02..0eb2095 100644
--- a/taverna-cwl-utilities/pom.xml
+++ b/taverna-cwl-utilities/pom.xml
@@ -20,5 +20,12 @@
 	<artifactId>taverna-cwl-utilities</artifactId>
 	<packaging>bundle</packaging>
 	<name>Apache Taverna CWL Activity</name>
+<dependencies>
 
+<dependency>
+			<groupId>org.yaml</groupId>
+			<artifactId>snakeyaml</artifactId>
+			<version>1.17</version>
+		</dependency>
+</dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c191822b/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/CWLUtil.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/CWLUtil.java b/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/CWLUtil.java
index a7d944b..300891f 100644
--- a/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/CWLUtil.java
+++ b/taverna-cwl-utilities/src/main/java/org/apache/taverna/cwl/utilities/CWLUtil.java
@@ -34,6 +34,10 @@ public class CWLUtil {
 		processNameSpace();
 	}
 
+	public LinkedHashMap getNameSpace() {
+		return nameSpace;
+	}
+
 	public void processNameSpace() {
 
 		if (cwlFile.containsKey("$namespaces")) {
@@ -58,7 +62,7 @@ public class CWLUtil {
 		return processdetails(cwlFile.get(OUTPUTS));
 	}
 
-	private HashMap<String, Integer> process(Object inputs) {
+	public HashMap<String, Integer> process(Object inputs) {
 
 		HashMap<String, Integer> result = new HashMap<>();
 
@@ -131,7 +135,7 @@ public class CWLUtil {
 		return result;
 	}
 
-	private void extractLabel(Map input, PortDetail detail) {
+	public  void extractLabel(Map input, PortDetail detail) {
 		if (input != null)
 			if (input.containsKey(LABEL)) {
 				detail.setLabel((String) input.get(LABEL));
@@ -140,7 +144,7 @@ public class CWLUtil {
 			}
 	}
 
-	private void extractDescription(Map input, PortDetail detail) {
+	public void extractDescription(Map input, PortDetail detail) {
 		if (input != null)
 			if (input.containsKey(DESCRIPTION)) {
 				detail.setDescription((String) input.get(DESCRIPTION));
@@ -149,7 +153,7 @@ public class CWLUtil {
 			}
 	}
 
-	private void extractFormat(Map input, PortDetail detail) {
+	public void extractFormat(Map input, PortDetail detail) {
 		if (input != null)
 			if (input.containsKey(FORMAT)) {
 
@@ -170,7 +174,7 @@ public class CWLUtil {
 			}
 	}
 
-	private void figureOutFormats(String formatInfoString, PortDetail detail) {
+	public void figureOutFormats(String formatInfoString, PortDetail detail) {
 		if (formatInfoString.startsWith("$")) {
 
 			detail.addFormat(formatInfoString);

http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/c191822b/taverna-cwl-utilities/src/test/java/org/apache/taverna/cwl/utilities/CWLUtilTest.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-utilities/src/test/java/org/apache/taverna/cwl/utilities/CWLUtilTest.java b/taverna-cwl-utilities/src/test/java/org/apache/taverna/cwl/utilities/CWLUtilTest.java
new file mode 100644
index 0000000..6f5a4ad
--- /dev/null
+++ b/taverna-cwl-utilities/src/test/java/org/apache/taverna/cwl/utilities/CWLUtilTest.java
@@ -0,0 +1,103 @@
+package org.apache.taverna.cwl.utilities;
+
+import static org.junit.Assert.*;
+
+import java.io.FileInputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.yaml.snakeyaml.Yaml;
+
+public class CWLUtilTest {
+	Map cwlFile;
+	CWLUtil cwlUtil;
+	Map input;
+
+	@Before
+	public void setUp() throws Exception {
+		Yaml reader = new Yaml();
+		Path path = Paths.get("CWLFiles", "customtool1.cwl");
+		cwlFile = (Map) reader.load(new FileInputStream(path.toFile()));
+		cwlUtil = new CWLUtil(cwlFile);
+		input = ((ArrayList<Map>) cwlFile.get("inputs")).get(0);
+	}
+
+	@Test
+	public void processNameSpaceTest() {
+		LinkedHashMap nameSpace = cwlUtil.getNameSpace();
+
+		assertEquals(1, nameSpace.size());
+		assertTrue(nameSpace.containsKey("edam"));
+		assertEquals("http://edamontology.org/", nameSpace.get("edam"));
+	}
+
+	@Test
+	public void extractLabelTest() {
+		PortDetail detail = new PortDetail();
+
+		cwlUtil.extractLabel(null, detail);
+		assertEquals(null, detail.getLabel());
+
+		cwlUtil.extractLabel(input, detail);
+		assertEquals("input 1 testing label", detail.getLabel());
+
+	}
+
+	@Test
+	public void extractDescriptionTest() {
+		PortDetail detail = new PortDetail();
+
+		cwlUtil.extractDescription(null, detail);
+		assertEquals(null, detail.getDescription());
+
+		cwlUtil.extractDescription(input, detail);
+		assertEquals("this is a short description of input 1", detail.getDescription());
+
+	}
+
+	@Test
+	public void figureOutFormatsTest() {
+		PortDetail detail = new PortDetail();
+		detail.setFormat(new ArrayList<String>());
+		cwlUtil.figureOutFormats("edam:1245", detail);
+		assertEquals("http://edamontology.org/1245", detail.getFormat().get(0));
+
+		cwlUtil.figureOutFormats("$formatExpression", detail);
+		assertEquals("$formatExpression", detail.getFormat().get(1));
+
+		// format that doesn't defined in the name space
+
+		cwlUtil.figureOutFormats("formatkey: not Defined", detail);
+		assertEquals("formatkey: not Defined", detail.getFormat().get(2));
+	}
+
+	@Test
+	public void processTest() {
+
+		HashMap<String, Integer> actual = cwlUtil.process(((ArrayList<Map>) cwlFile.get("inputs")));
+
+		HashMap<String, Integer> expected = new HashMap<>();
+		expected.put("input_1", 0);
+		expected.put("input_2", 1);
+		expected.put("input_3", 0);
+		for (Map.Entry<String, Integer> input : expected.entrySet()) {
+			assertEquals(input.getValue(), actual.get(input.getKey()));
+		}
+		
+		actual = cwlUtil.process(((ArrayList<Map>) cwlFile.get("outputs")));
+		expected = new HashMap<>();
+		expected.put("output_1", 0);
+		expected.put("output_2", 0);
+		for (Map.Entry<String, Integer> input : expected.entrySet()) {
+			assertEquals(input.getValue(), actual.get(input.getKey()));
+		}
+	}
+}