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:36 UTC
[19/50] [abbrv] incubator-taverna-common-activities git commit: unit
tests
unit tests
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/626919d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/tree/626919d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/diff/626919d5
Branch: refs/heads/cwl-browse
Commit: 626919d5bc0960ecc7940c1c031b0e5f18cd5637
Parents: 4e8f8d0
Author: ThilinaManamgoda <ma...@gmail.com>
Authored: Sat Jul 23 13:42:55 2016 +0530
Committer: ThilinaManamgoda <ma...@gmail.com>
Committed: Sat Jul 23 13:42:55 2016 +0530
----------------------------------------------------------------------
.../ui/serviceprovider/CwlServiceProvider.java | 122 ++++++++++++-------
.../ui/view/CwlActivityContextViewFactory.java | 1 +
.../src/main/resources/CWLFiles/customtool1.cwl | 2 +-
.../serviceprovider/CwlServiceProviderTest.java | 19 +++
.../view/CwlActivityContextViewFactoryTest.java | 25 ++++
taverna-cwl-activity/pom.xml | 46 +++----
.../src/main/resources/CWLFiles/customtool1.cwl | 2 +-
.../taverna/cwl/CwlActivityFactoryTest.java | 86 +++++++++----
8 files changed, 211 insertions(+), 92 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/626919d5/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java b/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java
index 44672aa..56c462f 100644
--- a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java
+++ b/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProvider.java
@@ -23,7 +23,9 @@ import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
@@ -51,71 +53,102 @@ public class CwlServiceProvider extends AbstractConfigurableServiceProvider impl
public static final String DEFAULT_PATH_1 = "/usr/share/commonwl/";
public static final String DEFAULT_PATH_2 = "/usr/local/share/commonwl/";
- public static final String DEFAULT_PATH_3 = "$HOME/.local/share/commonwl";
-
+ public static final String XDF_DATA_HOME = "XDF_DATA_HOME";
+ public static final String COMMONWL = "commonwl/";
private static Logger logger = Logger.getLogger(CwlServiceProvider.class);
CwlServiceProvider() {
- //FIXME
+ // FIXME
super(getDefaultConfiguration());
}
private static final String providerName = "CWL Services";
private static final URI providerId = CwlServiceDesc.ACTIVITY_TYPE.resolve("#provider");
-
-
@Override
public void findServiceDescriptionsAsync(FindServiceDescriptionsCallBack callBack) {
- // TODO default and configurable provider
-
// get the location of the cwl tool from the workbench
- Path path = getPath();
- // figure out the dots in the path ex: /maanadev/../cwltools
- Path normalizedPath = path.normalize();
-
- DirectoryStream<Path> stream = null;
- try {
- stream = Files.newDirectoryStream(normalizedPath, "*.cwl");
- } catch (IOException e) {
- logger.warn("Path is not correct !");
- return;
- }
- // create stream with parallel capabilities
- Stream<Path> paralleStream = StreamSupport.stream(stream.spliterator(), true);
+ ArrayList<Path> paths = getPath();
- paralleStream.forEach(p -> {
- Yaml reader = getYamlReader();
-
- Map cwlFile;
- try (FileInputStream file = new FileInputStream(path.toFile())) {
- cwlFile = (Map) reader.load(file);
- JsonNode config = createJsonNode(p, cwlFile);
- // Creating CWl service Description
- CwlServiceDesc cwlServiceDesc = createCWLDesc(config);
- // return the service description
- callBack.partialResults(Arrays.asList(cwlServiceDesc));
+ for (Path path : paths) {
+ // figure out the dots in the path ex: /maanadev/../cwltools
+ Path normalizedPath = path.normalize();
+ DirectoryStream<Path> stream = null;
+ try {
+ stream = Files.newDirectoryStream(normalizedPath, "*.cwl");
} catch (IOException e) {
+ logger.warn("Path is not correct !");
+ return;
+ }
+ // create stream with parallel capabilities
+ Stream<Path> paralleStream = StreamSupport.stream(stream.spliterator(), true);
- logger.warn("File not Found !");
+ paralleStream.forEach(p -> {
+ Yaml reader = getYamlReader();
- }
+ Map cwlFile;
+ try (FileInputStream file = new FileInputStream(path.toFile())) {
+ cwlFile = (Map) reader.load(file);
+ JsonNode config = createJsonNode(p, cwlFile);
+ // Creating CWl service Description
+ CwlServiceDesc cwlServiceDesc = createCWLDesc(config);
+ // return the service description
+ callBack.partialResults(Arrays.asList(cwlServiceDesc));
+
+ } catch (IOException e) {
- });
+ logger.warn("File not Found !");
- callBack.finished();
+ }
+ });
+
+ callBack.finished();
+ }
+
+ }
+/**
+ * This method checks whether provided path is valid or not and if it's valid the it's added to the list
+ * @param defaultPaths arrylist to hold valid paths
+ * @param path
+ * @param path1 if there is no second path argument this should be set to null
+ */
+ public void addPath(ArrayList<Path> defaultPaths, String path, String path1) {
+
+ Path defaultPath;
+ if (path1 == null)
+ defaultPath = Paths.get(path);
+ else
+ defaultPath = Paths.get(path, path1);
+
+ if (defaultPath.isAbsolute())
+ defaultPaths.add(defaultPath);
}
- private Path getPath() {
- return Paths.get(getConfiguration().getJsonAsObjectNode().get("path").asText());
+ private ArrayList<Path> getPath() {
+ String userInput = getConfiguration().getJsonAsObjectNode().get("path").asText();
+ // If user haven't provided a PATH
+ if (userInput.isEmpty()||userInput==null) {
+ ArrayList<Path> defaultPaths = new ArrayList<>();
+ addPath(defaultPaths, DEFAULT_PATH_1, null);
+ addPath(defaultPaths, DEFAULT_PATH_2, null);
+ addPath(defaultPaths, XDF_DATA_HOME, COMMONWL);
+ return defaultPaths;
+ }
+
+ return (ArrayList<Path>) Arrays.asList(Paths.get(userInput));
}
+
/**
- * This method is creating a JsonNode object which contains Tool as a map and it's Path,Name
- * @param p Path of the CWL tool
- * @param cwlFile Output of the YAML reader
+ * This method is creating a JsonNode object which contains Tool as a map
+ * and it's Path,Name
+ *
+ * @param p
+ * Path of the CWL tool
+ * @param cwlFile
+ * Output of the YAML reader
* @return
*/
private JsonNode createJsonNode(Path p, Map cwlFile) {
@@ -127,10 +160,14 @@ public class CwlServiceProvider extends AbstractConfigurableServiceProvider impl
((ObjectNode) root).put(CWL_PATH, p.toString());
return root;
}
+
/**
*
- * This method creates CwlServiceDesc which hold the configuration of the tool and the tool name
- * @param node JsonnNode which holds the final configuration of the tool
+ * This method creates CwlServiceDesc which hold the configuration of the
+ * tool and the tool name
+ *
+ * @param node
+ * JsonnNode which holds the final configuration of the tool
* @return
*/
@@ -186,7 +223,6 @@ public class CwlServiceProvider extends AbstractConfigurableServiceProvider impl
return false;
}
-
private static Configuration getDefaultConfiguration() {
Configuration c = new Configuration();
ObjectNode conf = c.getJsonAsObjectNode();
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/626919d5/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/view/CwlActivityContextViewFactory.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/view/CwlActivityContextViewFactory.java b/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/view/CwlActivityContextViewFactory.java
index 3967cc1..0e10086 100644
--- a/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/view/CwlActivityContextViewFactory.java
+++ b/taverna-cwl-activity-ui/src/main/java/org/apache/taverna/cwl/ui/view/CwlActivityContextViewFactory.java
@@ -20,6 +20,7 @@ import java.net.URI;
import java.util.Arrays;
import java.util.List;
+import org.apache.taverna.cwl.CwlDumyActivity;
import org.apache.taverna.scufl2.api.activity.Activity;
import org.apache.taverna.workbench.configuration.colour.ColourManager;
import org.apache.taverna.workbench.ui.views.contextualviews.ContextualView;
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/626919d5/taverna-cwl-activity-ui/src/main/resources/CWLFiles/customtool1.cwl
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity-ui/src/main/resources/CWLFiles/customtool1.cwl b/taverna-cwl-activity-ui/src/main/resources/CWLFiles/customtool1.cwl
index cc36f02..b140207 100644
--- a/taverna-cwl-activity-ui/src/main/resources/CWLFiles/customtool1.cwl
+++ b/taverna-cwl-activity-ui/src/main/resources/CWLFiles/customtool1.cwl
@@ -52,7 +52,7 @@ outputs:
description: this is a short description of output 1
format: just a string
- - id: ouput_2
+ - id: output_2
type: String
label: output 2 testing label
description: this is a short description of output 2
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/626919d5/taverna-cwl-activity-ui/src/test/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProviderTest.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity-ui/src/test/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProviderTest.java b/taverna-cwl-activity-ui/src/test/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProviderTest.java
new file mode 100644
index 0000000..cfc50b1
--- /dev/null
+++ b/taverna-cwl-activity-ui/src/test/java/org/apache/taverna/cwl/ui/serviceprovider/CwlServiceProviderTest.java
@@ -0,0 +1,19 @@
+package org.apache.taverna.cwl.ui.serviceprovider;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class CwlServiceProviderTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void test() {
+ fail("Not yet implemented");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/626919d5/taverna-cwl-activity-ui/src/test/java/org/apache/taverna/cwl/ui/view/CwlActivityContextViewFactoryTest.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity-ui/src/test/java/org/apache/taverna/cwl/ui/view/CwlActivityContextViewFactoryTest.java b/taverna-cwl-activity-ui/src/test/java/org/apache/taverna/cwl/ui/view/CwlActivityContextViewFactoryTest.java
new file mode 100644
index 0000000..873dd78
--- /dev/null
+++ b/taverna-cwl-activity-ui/src/test/java/org/apache/taverna/cwl/ui/view/CwlActivityContextViewFactoryTest.java
@@ -0,0 +1,25 @@
+package org.apache.taverna.cwl.ui.view;
+
+import static org.junit.Assert.*;
+
+import org.apache.taverna.cwl.CwlDumyActivity;
+import org.apache.taverna.scufl2.api.activity.Activity;
+import org.apache.taverna.workbench.configuration.colour.ColourManager;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CwlActivityContextViewFactoryTest {
+
+ @Before
+ public void setUp() throws Exception {
+ ColourManager colourManager=null;
+ CwlDumyActivity activity =new CwlDumyActivity();
+ //CwlContextualView contextualView = new CwlContextualView((Activity)activity,colourManager);
+ }
+
+ @Test
+ public void test() {
+ fail("Not yet implemented");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/626919d5/taverna-cwl-activity/pom.xml
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity/pom.xml b/taverna-cwl-activity/pom.xml
index eaecd6f..10c6ad6 100644
--- a/taverna-cwl-activity/pom.xml
+++ b/taverna-cwl-activity/pom.xml
@@ -1,22 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
-
- 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.
-
--->
+ 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.
+ -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -71,11 +65,11 @@
<version>${jackson.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.taverna.workbench</groupId>
- <artifactId>taverna-activity-palette-api</artifactId>
- <version>${taverna.workbench.version}</version>
- </dependency>
+ <dependency>
+ <groupId>org.apache.taverna.workbench</groupId>
+ <artifactId>taverna-activity-palette-api</artifactId>
+ <version>${taverna.workbench.version}</version>
+ </dependency>
<dependency>
@@ -85,14 +79,14 @@
<type>bundle</type>
</dependency>
</dependencies>
-<!-- Added these properties to configure new dependencies -->
+ <!-- Added these properties to configure new dependencies -->
<properties>
- <taverna.language.version>0.15.1-incubating</taverna.language.version>
+ <taverna.language.version>0.15.1-incubating</taverna.language.version>
<taverna.osgi.version>0.2.1-incubating</taverna.osgi.version>
<taverna.workbench.version>3.1.0-incubating-SNAPSHOT</taverna.workbench.version>
</properties>
<repositories>
- <repository>
+ <repository>
<id>apache.snapshots</id>
<name>Apache Snapshot Repository</name>
<url>http://repository.apache.org/snapshots</url>
@@ -100,7 +94,7 @@
<enabled>false</enabled>
</releases>
</repository>
-
+
</repositories>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/626919d5/taverna-cwl-activity/src/main/resources/CWLFiles/customtool1.cwl
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity/src/main/resources/CWLFiles/customtool1.cwl b/taverna-cwl-activity/src/main/resources/CWLFiles/customtool1.cwl
index cc36f02..b140207 100644
--- a/taverna-cwl-activity/src/main/resources/CWLFiles/customtool1.cwl
+++ b/taverna-cwl-activity/src/main/resources/CWLFiles/customtool1.cwl
@@ -52,7 +52,7 @@ outputs:
description: this is a short description of output 1
format: just a string
- - id: ouput_2
+ - id: output_2
type: String
label: output 2 testing label
description: this is a short description of output 2
http://git-wip-us.apache.org/repos/asf/incubator-taverna-common-activities/blob/626919d5/taverna-cwl-activity/src/main/test/java/org/apache/taverna/cwl/CwlActivityFactoryTest.java
----------------------------------------------------------------------
diff --git a/taverna-cwl-activity/src/main/test/java/org/apache/taverna/cwl/CwlActivityFactoryTest.java b/taverna-cwl-activity/src/main/test/java/org/apache/taverna/cwl/CwlActivityFactoryTest.java
index d8c3b09..d423991 100644
--- a/taverna-cwl-activity/src/main/test/java/org/apache/taverna/cwl/CwlActivityFactoryTest.java
+++ b/taverna-cwl-activity/src/main/test/java/org/apache/taverna/cwl/CwlActivityFactoryTest.java
@@ -1,14 +1,21 @@
package org.apache.taverna.cwl;
-
-
import static org.junit.Assert.assertEquals;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
import org.apache.log4j.Logger;
+import org.apache.taverna.workflowmodel.Edits;
+import org.apache.taverna.workflowmodel.impl.EditsImpl;
+import org.apache.taverna.workflowmodel.processor.activity.ActivityConfigurationException;
+import org.apache.taverna.workflowmodel.processor.activity.ActivityInputPort;
+import org.apache.taverna.workflowmodel.processor.activity.ActivityOutputPort;
import org.junit.Before;
import org.junit.Test;
import org.yaml.snakeyaml.Yaml;
@@ -21,43 +28,80 @@ public class CwlActivityFactoryTest {
private static Logger logger = Logger.getLogger(CwlActivityFactoryTest.class);
CwlActivityFactory cwlActivityFactory;
public static final String CWL_CONF = "cwl_conf";
- private JsonNode root;
-
+ private JsonNode root;
+
@Before
public void setUp() throws Exception {
- System.out.println("1");
cwlActivityFactory = new CwlActivityFactory();
+ Edits edits = new EditsImpl();
+ cwlActivityFactory.setEdits(edits);
+
Yaml reader = new Yaml();
- ObjectMapper mapper = new ObjectMapper();
+ ObjectMapper mapper = new ObjectMapper();
ObjectNode cwlFile = null;
try {
- cwlFile = mapper.valueToTree(reader.load(new FileInputStream(getClass().getResource("/CWLFiles/customtool1.cwl").getPath())));
+ cwlFile = mapper.valueToTree(
+ reader.load(new FileInputStream(getClass().getResource("/CWLFiles/customtool1.cwl").getPath())));
} catch (IllegalArgumentException | FileNotFoundException e) {
System.out.println(e);
- }
-
- root =mapper.createObjectNode();
+ }
+
+ root = mapper.createObjectNode();
((ObjectNode) root).put(CWL_CONF, cwlFile);
}
@Test
public void testSchemaJson() {
ObjectMapper objectMapper = new ObjectMapper();
- try {
- assertEquals(cwlActivityFactory.getActivityConfigurationSchema(), objectMapper.readTree(getClass().getResource("/schema.json")));
+ try {
+ assertEquals(cwlActivityFactory.getActivityConfigurationSchema(),
+ objectMapper.readTree(getClass().getResource("/schema.json")));
} catch (IOException e) {
logger.error(e);
}
-
+
}
- @Test //FIXME
+
+ @Test // FIXME
public void testgetInputPorts() {
-
-// try {
-// cwlActivityFactory.getInputPorts(root);
-// } catch (ActivityConfigurationException e) {
-// logger.error(e);
-//
-// }
+ Set<ActivityInputPort> set = null;
+ try {
+ set = cwlActivityFactory.getInputPorts(root);
+ } catch (ActivityConfigurationException e) {
+ logger.error(e);
+
+ }
+ assertEquals(3, set.size());
+ Map<String, Integer> expected = new HashMap<>();
+ expected.put("input_2", 1);
+ expected.put("input_3", 0);
+ expected.put("input_1", 0);
+ Iterator<ActivityInputPort> itr = set.iterator();
+ while (itr.hasNext()) {
+ ActivityInputPort input = itr.next();
+ int expectedDepth = expected.get(input.getName());
+ assertEquals(expectedDepth, input.getDepth());
+ }
+ }
+
+ @Test // FIXME
+ public void testgetOutputPorts() {
+ Set<ActivityOutputPort> set = null;
+ try {
+ set = cwlActivityFactory.getOutputPorts(root);
+ } catch (ActivityConfigurationException e) {
+ logger.error(e);
+
+ }
+ assertEquals(2, set.size());
+ Map<String, Integer> expected = new HashMap<>();
+ expected.put("output_1", 0);
+ expected.put("output_2", 0);
+ Iterator<ActivityOutputPort> itr = set.iterator();
+ while (itr.hasNext()) {
+ ActivityOutputPort output = itr.next();
+ int expectedDepth = expected.get(output.getName());
+ assertEquals(expectedDepth, output.getDepth());
+ }
}
}