Improve testing the nested workflow tool

- Check if nesting processor doesn't already have a bound activity


Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/commit/2530da32
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/tree/2530da32
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/diff/2530da32

Branch: refs/heads/master
Commit: 2530da3221a6317671367041c20e85709927b685
Parents: 3efbf08
Author: Majdi Haouech <m.haou...@criteo.com>
Authored: Tue Aug 7 23:29:07 2018 +0200
Committer: Majdi Haouech <m.haou...@criteo.com>
Committed: Tue Aug 7 23:29:07 2018 +0200

----------------------------------------------------------------------
 .../taverna/scufl2/api/common/Scufl2Tools.java   | 10 ++++------
 .../scufl2/api/common/TestScufl2Tools.java       | 19 +++++++------------
 2 files changed, 11 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/2530da32/taverna-scufl2-api/src/main/java/org/apache/taverna/scufl2/api/common/Scufl2Tools.java
----------------------------------------------------------------------
diff --git 
a/taverna-scufl2-api/src/main/java/org/apache/taverna/scufl2/api/common/Scufl2Tools.java
 
b/taverna-scufl2-api/src/main/java/org/apache/taverna/scufl2/api/common/Scufl2Tools.java
index 0823e3b..bb5bcbe 100644
--- 
a/taverna-scufl2-api/src/main/java/org/apache/taverna/scufl2/api/common/Scufl2Tools.java
+++ 
b/taverna-scufl2-api/src/main/java/org/apache/taverna/scufl2/api/common/Scufl2Tools.java
@@ -764,12 +764,10 @@ public class Scufl2Tools {
                if(nestedWorkflowForProcessor(processor, profile) != null) {
                        throw new IllegalStateException("Processor " + 
processor + " already has a nested workflow");
                }
-               try {
-                       processor.getActivity(profile);
-                       throw new IllegalStateException("Processor " + 
processor + " already has a bound activity");
-               } catch(IndexOutOfBoundsException e) {
-                       // Processor should have no bound activity, which is 
the case here.
-               }
+        List<ProcessorBinding> processorBindings = 
processorBindingsForProcessor(processor, profile);
+        if(processorBindings.size() != 0) {
+            throw new IllegalStateException("Processor " + processor + 
"already has a binding")
+        }
 
                Activity activity = createActivityFromProcessor(processor, 
profile);
                activity.setType(NESTED_WORKFLOW);

http://git-wip-us.apache.org/repos/asf/incubator-taverna-language/blob/2530da32/taverna-scufl2-api/src/test/java/org/apache/taverna/scufl2/api/common/TestScufl2Tools.java
----------------------------------------------------------------------
diff --git 
a/taverna-scufl2-api/src/test/java/org/apache/taverna/scufl2/api/common/TestScufl2Tools.java
 
b/taverna-scufl2-api/src/test/java/org/apache/taverna/scufl2/api/common/TestScufl2Tools.java
index 179553b..f336af0 100644
--- 
a/taverna-scufl2-api/src/test/java/org/apache/taverna/scufl2/api/common/TestScufl2Tools.java
+++ 
b/taverna-scufl2-api/src/test/java/org/apache/taverna/scufl2/api/common/TestScufl2Tools.java
@@ -51,6 +51,7 @@ import 
org.apache.taverna.scufl2.api.profiles.ProcessorPortBinding;
 import org.apache.taverna.scufl2.api.profiles.Profile;
 import org.junit.Before;
 import org.junit.Test;
+import sun.security.krb5.Config;
 
 
 public class TestScufl2Tools extends ExampleWorkflow {
@@ -81,19 +82,13 @@ public class TestScufl2Tools extends ExampleWorkflow {
 
                assertEquals(child, nested);
 
-               boolean found = false;
+               ProcessorBinding binding = processor.getBinding(profile);
+               Activity activity = binding.getBoundActivity();
+        Configuration configuration = activity.getConfiguration();
 
-               for(Activity activity: profile.getActivities()) {
-                       
if(activity.getType().equals(Scufl2Tools.NESTED_WORKFLOW)) {
-                               for(Configuration config: 
tools.configurationsFor(activity, profile)) {
-                                       String nestedWorkflowName = 
config.getJson().get("nestedWorkflow").asText();
-                                       Workflow wf = 
workflowBundle.getWorkflows().getByName(nestedWorkflowName);
-                                       found |= (wf != null && 
nestedWorkflowName.equals(child.getName()));
-                               }
-                       }
-               }
-
-               assertTrue(found);
+        assertEquals(activity.getType(), Scufl2Tools.NESTED_WORKFLOW);
+        String nestedWorkflowName = 
configuration.getJson().get("nestedWorkflow").asText();
+        assertEquals(nestedWorkflowName, child.getName());
        }
        
        @Test

Reply via email to