[overlord-commits] Overlord SVN: r109 - in cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src: test/org/jboss/tools/overlord/jbossesb/model/actions and 1 other directory.
overlord-commits at lists.jboss.org
overlord-commits at lists.jboss.org
Thu Jul 3 11:36:42 EDT 2008
Author: objectiser
Date: 2008-07-03 11:36:42 -0400 (Thu, 03 Jul 2008)
New Revision: 109
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestActivity.java
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/IfAction.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhenAction.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/IfActionTest.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ParallelActionTest.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/SwitchActionTest.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhenActionTest.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhileActionTest.java
Log:
Unit tests for conversion of the grouping constructs.
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/IfAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/IfAction.java 2008-07-03 10:13:24 UTC (rev 108)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/IfAction.java 2008-07-03 15:36:42 UTC (rev 109)
@@ -188,22 +188,34 @@
org.w3c.dom.Node n=nl.item(i);
- if (n instanceof org.w3c.dom.Element &&
- (n.getNodeName().equals(IF) ||
- n.getNodeName().equals(ELSEIF) ||
- n.getNodeName().equals(ELSE))) {
- String category=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
- String name=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
-
- // TODO: Convert the conditional expression if defined
-
- ConditionalBlock cond=new ConditionalBlock();
- choice.getConditionalBlocks().add(cond);
-
- ESBService service=getService().getModel().getService(category, name);
-
- if (service != null) {
- service.convert(cond.getContents(), context);
+ if (n instanceof org.w3c.dom.Element) {
+ if (n.getNodeName().equals(IF) ||
+ n.getNodeName().equals(ELSEIF)) {
+ String category=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
+ String name=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
+
+ // TODO: Convert the conditional expression if defined
+
+ ConditionalBlock cond=new ConditionalBlock();
+ choice.getConditionalBlocks().add(cond);
+
+ ESBService service=getService().getModel().getService(category, name);
+
+ if (service != null) {
+ service.convert(cond.getContents(), context);
+ }
+ } else if (n.getNodeName().equals(ELSE)) {
+ String category=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
+ String name=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
+
+ Block block=new Block();
+ choice.setElseBlock(block);
+
+ ESBService service=getService().getModel().getService(category, name);
+
+ if (service != null) {
+ service.convert(block.getContents(), context);
+ }
}
}
}
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhenAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhenAction.java 2008-07-03 10:13:24 UTC (rev 108)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhenAction.java 2008-07-03 15:36:42 UTC (rev 109)
@@ -215,9 +215,7 @@
m_services.get(i).convert(block.getContents(), context);
- if (block.getContents().size() > 0) {
- elem.getConditionalBlocks().add(block);
- }
+ elem.getConditionalBlocks().add(block);
}
if (m_joinService != null) {
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/IfActionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/IfActionTest.java 2008-07-03 10:13:24 UTC (rev 108)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/IfActionTest.java 2008-07-03 15:36:42 UTC (rev 109)
@@ -18,6 +18,8 @@
package org.jboss.tools.overlord.jbossesb.model.actions;
import junit.framework.TestCase;
+import org.scribble.model.*;
+import org.scribble.conversation.model.*;
public class IfActionTest extends TestCase {
@@ -289,4 +291,162 @@
fail(l.invalidMessage());
}
}
+
+ public void testConvert() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><if service-category=\"cat1\" " +
+ "service-name=\"name1\" /><elseif service-category=\"cat2\" " +
+ "service-name=\"name2\" /><else service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestActivity act1=new TestActivity();
+ other1.getContents().add(act1);
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestActivity act2=new TestActivity();
+ other2.getContents().add(act2);
+
+ TestESBService other3=new TestESBService();
+ other3.setCategory("cat3");
+ other3.setName("name3");
+
+ TestActivity act3=new TestActivity();
+ other3.getContents().add(act3);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(other3);
+ model.addService(service);
+
+ service.setModel(model);
+
+ IfAction action=new IfAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ java.util.List<Activity> activities=new java.util.Vector<Activity>();
+
+ action.convert(activities, null);
+
+ if (activities.size() != 1) {
+ fail("Expecting one activity, but got: "+activities.size());
+ }
+
+ Activity act=activities.get(0);
+
+ if ((act instanceof If) == false) {
+ fail("Expecting an 'If' activity");
+ }
+
+ If ifAction=(If)act;
+
+ if (ifAction.getConditionalBlocks().size() != 2) {
+ fail("Expecting two conditional blocks: "+ifAction.getConditionalBlocks().size());
+ }
+
+ if (ifAction.getConditionalBlocks().get(0).getContents().size() != 1 ||
+ ifAction.getConditionalBlocks().get(0).getContents().get(0) != act1) {
+ fail("First conditional block should have 1 activity = act1");
+ }
+
+ if (ifAction.getConditionalBlocks().get(1).getContents().size() != 1 ||
+ ifAction.getConditionalBlocks().get(1).getContents().get(0) != act2) {
+ fail("Second conditional block should have 1 activity = act2");
+ }
+
+ if (ifAction.getElseBlock() == null) {
+ fail("Else block not defined");
+ }
+
+ if (ifAction.getElseBlock().getContents().size() != 1 ||
+ ifAction.getElseBlock().getContents().get(0) != act3) {
+ fail("Else block should have 1 activity = act3");
+ }
+ }
+
+ public void testConvertNotExcludingEmptyPaths() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><if service-category=\"cat1\" " +
+ "service-name=\"name1\" /><elseif service-category=\"cat2\" " +
+ "service-name=\"name2\" /><else service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestESBService other3=new TestESBService();
+ other3.setCategory("cat3");
+ other3.setName("name3");
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(other3);
+ model.addService(service);
+
+ service.setModel(model);
+
+ IfAction action=new IfAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ java.util.List<Activity> activities=new java.util.Vector<Activity>();
+
+ action.convert(activities, null);
+
+ if (activities.size() != 1) {
+ fail("Expecting one activity, but got: "+activities.size());
+ }
+
+ Activity act=activities.get(0);
+
+ if ((act instanceof If) == false) {
+ fail("Expecting an 'If' activity");
+ }
+
+ If ifAction=(If)act;
+
+ if (ifAction.getConditionalBlocks().size() != 2) {
+ fail("Expecting two conditional blocks: "+ifAction.getConditionalBlocks().size());
+ }
+
+ if (ifAction.getConditionalBlocks().get(0).getContents().size() != 0) {
+ fail("First conditional block should be empty");
+ }
+
+ if (ifAction.getConditionalBlocks().get(1).getContents().size() != 0) {
+ fail("Second conditional block should be empty");
+ }
+
+ if (ifAction.getElseBlock() == null) {
+ fail("Else block not defined");
+ }
+
+ if (ifAction.getElseBlock().getContents().size() != 0) {
+ fail("Else block should have be empty");
+ }
+ }
}
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ParallelActionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ParallelActionTest.java 2008-07-03 10:13:24 UTC (rev 108)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ParallelActionTest.java 2008-07-03 15:36:42 UTC (rev 109)
@@ -17,6 +17,10 @@
*/
package org.jboss.tools.overlord.jbossesb.model.actions;
+import org.scribble.conversation.model.*;
+import org.scribble.model.Activity;
+import org.jboss.tools.overlord.jbossesb.model.*;
+
import junit.framework.TestCase;
public class ParallelActionTest extends TestCase {
@@ -291,4 +295,164 @@
fail(l.invalidMessage());
}
}
+
+ public void testConvert() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><path service-category=\"cat1\" " +
+ "service-name=\"name1\" /><path service-category=\"cat2\" " +
+ "service-name=\"name2\" /><join service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestActivity act1=new TestActivity();
+ other1.getContents().add(act1);
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestActivity act2=new TestActivity();
+ other2.getContents().add(act2);
+
+ TestESBService other3=new TestESBService();
+ other3.setCategory("cat3");
+ other3.setName("name3");
+
+ TestActivity act3=new TestActivity();
+ other3.getContents().add(act3);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(other3);
+ model.addService(service);
+
+ service.setModel(model);
+
+ ParallelAction action=new ParallelAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ java.util.List<Activity> activities=new java.util.Vector<Activity>();
+
+ action.convert(activities, new DefaultConversionContext());
+
+ if (activities.size() != 2) {
+ fail("Expecting two activities, but got: "+activities.size());
+ }
+
+ Activity act=activities.get(0);
+
+ if ((act instanceof Parallel) == false) {
+ fail("Expecting an 'Parallel' activity");
+ }
+
+ Parallel parallelAction=(Parallel)act;
+
+ if (parallelAction.getBlocks().size() != 2) {
+ fail("Expecting two blocks: "+parallelAction.getBlocks().size());
+ }
+
+ if (parallelAction.getBlocks().get(0).getContents().size() != 1 ||
+ parallelAction.getBlocks().get(0).getContents().get(0) != act1) {
+ fail("First conditional block should have 1 activity = act1");
+ }
+
+ if (parallelAction.getBlocks().get(1).getContents().size() != 1 ||
+ parallelAction.getBlocks().get(1).getContents().get(0) != act2) {
+ fail("Second conditional block should have 1 activity = act2");
+ }
+
+ if (activities.get(1) != act3) {
+ fail("Activity after parallel should be act3");
+ }
+ }
+
+ /* Miss out test for now, until conformance checking fixed
+ * so that it ignores 'invisible' activities
+ *
+ public void testConvertNotExcludingEmptyPaths() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><path service-category=\"cat1\" " +
+ "service-name=\"name1\" /><path service-category=\"cat2\" " +
+ "service-name=\"name2\" /><join service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestActivity act1=new TestActivity();
+ other1.getContents().add(act1);
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestESBService other3=new TestESBService();
+ other3.setCategory("cat3");
+ other3.setName("name3");
+
+ TestActivity act3=new TestActivity();
+ other3.getContents().add(act3);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(other3);
+ model.addService(service);
+
+ service.setModel(model);
+
+ ParallelAction action=new ParallelAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ java.util.List<Activity> activities=new java.util.Vector<Activity>();
+
+ action.convert(activities, new DefaultConversionContext());
+
+ if (activities.size() != 2) {
+ fail("Expecting two activities, but got: "+activities.size());
+ }
+
+ Activity act=activities.get(0);
+
+ if ((act instanceof Parallel) == false) {
+ fail("Expecting an 'Parallel' activity");
+ }
+
+ Parallel parallelAction=(Parallel)act;
+
+ if (parallelAction.getBlocks().size() != 2) {
+ fail("Expecting two blocks: "+parallelAction.getBlocks().size());
+ }
+
+ if (parallelAction.getBlocks().get(0).getContents().size() != 1 ||
+ parallelAction.getBlocks().get(0).getContents().get(0) != act1) {
+ fail("First conditional block should have 1 activity = act1");
+ }
+
+ if (parallelAction.getBlocks().get(1).getContents().size() != 0) {
+ fail("Second conditional block should be empty");
+ }
+
+ if (activities.get(1) != act3) {
+ fail("Activity after parallel should be act3");
+ }
+ }
+ */
}
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/SwitchActionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/SwitchActionTest.java 2008-07-03 10:13:24 UTC (rev 108)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/SwitchActionTest.java 2008-07-03 15:36:42 UTC (rev 109)
@@ -17,6 +17,9 @@
*/
package org.jboss.tools.overlord.jbossesb.model.actions;
+import org.scribble.conversation.model.If;
+import org.scribble.model.Activity;
+
import junit.framework.TestCase;
public class SwitchActionTest extends TestCase {
@@ -186,4 +189,170 @@
fail(l.invalidMessage());
}
}
+
+ public void testConvert() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><case service-category=\"cat1\" " +
+ "service-name=\"name1\" /><case service-category=\"cat2\" " +
+ "service-name=\"name2\" /><case service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestActivity act1=new TestActivity();
+ other1.getContents().add(act1);
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestActivity act2=new TestActivity();
+ other2.getContents().add(act2);
+
+ TestESBService other3=new TestESBService();
+ other3.setCategory("cat3");
+ other3.setName("name3");
+
+ TestActivity act3=new TestActivity();
+ other3.getContents().add(act3);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(other3);
+ model.addService(service);
+
+ service.setModel(model);
+
+ SwitchAction action=new SwitchAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ java.util.List<Activity> activities=new java.util.Vector<Activity>();
+
+ action.convert(activities, null);
+
+ if (activities.size() != 1) {
+ fail("Expecting one activity, but got: "+activities.size());
+ }
+
+ Activity act=activities.get(0);
+
+ if ((act instanceof If) == false) {
+ fail("Expecting an 'If' activity");
+ }
+
+ If ifAction=(If)act;
+
+ if (ifAction.getConditionalBlocks().size() != 3) {
+ fail("Expecting three conditional blocks: "+ifAction.getConditionalBlocks().size());
+ }
+
+ if (ifAction.getConditionalBlocks().get(0).getContents().size() != 1 ||
+ ifAction.getConditionalBlocks().get(0).getContents().get(0) != act1) {
+ fail("First conditional block should have 1 activity = act1");
+ }
+
+ if (ifAction.getConditionalBlocks().get(1).getContents().size() != 1 ||
+ ifAction.getConditionalBlocks().get(1).getContents().get(0) != act2) {
+ fail("Second conditional block should have 1 activity = act2");
+ }
+
+ if (ifAction.getConditionalBlocks().get(2).getContents().size() != 1 ||
+ ifAction.getConditionalBlocks().get(2).getContents().get(0) != act3) {
+ fail("Third conditional block should have 1 activity = act3");
+ }
+
+ if (ifAction.getElseBlock() != null) {
+ fail("Else block should not be defined");
+ }
+ }
+
+ public void testConvertNotExcludingEmptyPaths() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><case service-category=\"cat1\" " +
+ "service-name=\"name1\" /><case service-category=\"cat2\" " +
+ "service-name=\"name2\" /><case service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestActivity act1=new TestActivity();
+ other1.getContents().add(act1);
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestESBService other3=new TestESBService();
+ other3.setCategory("cat3");
+ other3.setName("name3");
+
+ TestActivity act3=new TestActivity();
+ other3.getContents().add(act3);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(other3);
+ model.addService(service);
+
+ service.setModel(model);
+
+ SwitchAction action=new SwitchAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ java.util.List<Activity> activities=new java.util.Vector<Activity>();
+
+ action.convert(activities, null);
+
+ if (activities.size() != 1) {
+ fail("Expecting one activity, but got: "+activities.size());
+ }
+
+ Activity act=activities.get(0);
+
+ if ((act instanceof If) == false) {
+ fail("Expecting an 'If' activity");
+ }
+
+ If ifAction=(If)act;
+
+ if (ifAction.getConditionalBlocks().size() != 3) {
+ fail("Expecting three conditional blocks: "+ifAction.getConditionalBlocks().size());
+ }
+
+ if (ifAction.getConditionalBlocks().get(0).getContents().size() != 1 ||
+ ifAction.getConditionalBlocks().get(0).getContents().get(0) != act1) {
+ fail("First conditional block should have 1 activity = act1");
+ }
+
+ if (ifAction.getConditionalBlocks().get(1).getContents().size() != 0) {
+ fail("Second conditional block should be empty");
+ }
+
+ if (ifAction.getConditionalBlocks().get(2).getContents().size() != 1 ||
+ ifAction.getConditionalBlocks().get(2).getContents().get(0) != act3) {
+ fail("Third conditional block should have 1 activity = act3");
+ }
+
+ if (ifAction.getElseBlock() != null) {
+ fail("Else block should not be defined");
+ }
+ }
}
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestActivity.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestActivity.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestActivity.java 2008-07-03 15:36:42 UTC (rev 109)
@@ -0,0 +1,22 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.tools.overlord.jbossesb.model.actions;
+
+public class TestActivity extends org.scribble.model.Activity {
+
+}
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java 2008-07-03 10:13:24 UTC (rev 108)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java 2008-07-03 15:36:42 UTC (rev 109)
@@ -29,9 +29,12 @@
public class TestESBService implements org.jboss.tools.overlord.jbossesb.model.ESBService {
public void convert(List<Activity> activities, ConversionContext context) {
- // TODO Auto-generated method stub
-
+ activities.addAll(m_contents);
}
+
+ public List<Activity> getContents() {
+ return(m_contents);
+ }
public List<ESBAction> getActions() {
return(m_actions);
@@ -146,4 +149,5 @@
private boolean m_sessionBased=false;
private boolean m_createSession=false;
private Class<?> m_sessionClass=null;
+ private List<Activity> m_contents=new java.util.Vector<Activity>();
}
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhenActionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhenActionTest.java 2008-07-03 10:13:24 UTC (rev 108)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhenActionTest.java 2008-07-03 15:36:42 UTC (rev 109)
@@ -17,6 +17,9 @@
*/
package org.jboss.tools.overlord.jbossesb.model.actions;
+import org.scribble.conversation.model.*;
+import org.scribble.model.*;
+
import junit.framework.TestCase;
public class WhenActionTest extends TestCase {
@@ -289,4 +292,162 @@
fail(l.invalidMessage());
}
}
+
+ public void testConvert() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><when service-category=\"cat1\" " +
+ "service-name=\"name1\" /><when service-category=\"cat2\" " +
+ "service-name=\"name2\" /><when service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestActivity act1=new TestActivity();
+ other1.getContents().add(act1);
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestActivity act2=new TestActivity();
+ other2.getContents().add(act2);
+
+ TestESBService other3=new TestESBService();
+ other3.setCategory("cat3");
+ other3.setName("name3");
+
+ TestActivity act3=new TestActivity();
+ other3.getContents().add(act3);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(other3);
+ model.addService(service);
+
+ service.setModel(model);
+
+ WhenAction action=new WhenAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ java.util.List<Activity> activities=new java.util.Vector<Activity>();
+
+ action.convert(activities, null);
+
+ if (activities.size() != 1) {
+ fail("Expecting one activity, but got: "+activities.size());
+ }
+
+ Activity act=activities.get(0);
+
+ if ((act instanceof When) == false) {
+ fail("Expecting an 'When' activity");
+ }
+
+ When whenAction=(When)act;
+
+ if (whenAction.getConditionalBlocks().size() != 3) {
+ fail("Expecting three conditional blocks: "+whenAction.getConditionalBlocks().size());
+ }
+
+ if (whenAction.getConditionalBlocks().get(0).getContents().size() != 1 ||
+ whenAction.getConditionalBlocks().get(0).getContents().get(0) != act1) {
+ fail("First conditional block should have 1 activity = act1");
+ }
+
+ if (whenAction.getConditionalBlocks().get(1).getContents().size() != 1 ||
+ whenAction.getConditionalBlocks().get(1).getContents().get(0) != act2) {
+ fail("Second conditional block should have 1 activity = act2");
+ }
+
+ if (whenAction.getConditionalBlocks().get(2).getContents().size() != 1 ||
+ whenAction.getConditionalBlocks().get(2).getContents().get(0) != act3) {
+ fail("Second conditional block should have 1 activity = act3");
+ }
+ }
+
+ public void testConvertNotExcludingEmptyPath() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><when service-category=\"cat1\" " +
+ "service-name=\"name1\" /><when service-category=\"cat2\" " +
+ "service-name=\"name2\" /><when service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestActivity act1=new TestActivity();
+ other1.getContents().add(act1);
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestESBService other3=new TestESBService();
+ other3.setCategory("cat3");
+ other3.setName("name3");
+
+ TestActivity act3=new TestActivity();
+ other3.getContents().add(act3);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(other3);
+ model.addService(service);
+
+ service.setModel(model);
+
+ WhenAction action=new WhenAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ java.util.List<Activity> activities=new java.util.Vector<Activity>();
+
+ action.convert(activities, null);
+
+ if (activities.size() != 1) {
+ fail("Expecting one activity, but got: "+activities.size());
+ }
+
+ Activity act=activities.get(0);
+
+ if ((act instanceof When) == false) {
+ fail("Expecting an 'When' activity");
+ }
+
+ When whenAction=(When)act;
+
+ if (whenAction.getConditionalBlocks().size() != 3) {
+ fail("Expecting three conditional blocks: "+whenAction.getConditionalBlocks().size());
+ }
+
+ if (whenAction.getConditionalBlocks().get(0).getContents().size() != 1 ||
+ whenAction.getConditionalBlocks().get(0).getContents().get(0) != act1) {
+ fail("First conditional block should have 1 activity = act1");
+ }
+
+ if (whenAction.getConditionalBlocks().get(1).getContents().size() != 0) {
+ fail("Second conditional block should be empty");
+ }
+
+ if (whenAction.getConditionalBlocks().get(2).getContents().size() != 1 ||
+ whenAction.getConditionalBlocks().get(2).getContents().get(0) != act3) {
+ fail("Third conditional block should have 1 activity = act3");
+ }
+ }
}
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhileActionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhileActionTest.java 2008-07-03 10:13:24 UTC (rev 108)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhileActionTest.java 2008-07-03 15:36:42 UTC (rev 109)
@@ -17,6 +17,10 @@
*/
package org.jboss.tools.overlord.jbossesb.model.actions;
+import org.scribble.conversation.model.*;
+import org.scribble.model.*;
+import org.jboss.tools.overlord.jbossesb.model.*;
+
import junit.framework.TestCase;
public class WhileActionTest extends TestCase {
@@ -324,4 +328,127 @@
fail(l.invalidMessage());
}
}
+
+ public void testConvert() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><while service-category=\"cat1\" " +
+ "service-name=\"name1\" /><exit service-category=\"cat2\" " +
+ "service-name=\"name2\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestActivity act1=new TestActivity();
+ other1.getContents().add(act1);
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestActivity act2=new TestActivity();
+ other2.getContents().add(act2);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(service);
+
+ service.setModel(model);
+
+ WhileAction action=new WhileAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ java.util.List<Activity> activities=new java.util.Vector<Activity>();
+
+ action.convert(activities, new DefaultConversionContext());
+
+ if (activities.size() != 2) {
+ fail("Expecting two activities, but got: "+activities.size());
+ }
+
+ Activity act=activities.get(0);
+
+ if ((act instanceof While) == false) {
+ fail("Expecting an 'While' activity");
+ }
+
+ While whileAction=(While)act;
+
+ if (whileAction.getBlock().getContents().size() != 1) {
+ fail("Expecting one entry in while block: "+whileAction.getBlock().getContents().size());
+ }
+
+ if (whileAction.getBlock().getContents().get(0) != act1) {
+ fail("While block should have 1 activity = act1");
+ }
+
+ if (activities.get(1) != act2) {
+ fail("Activity following while should be act2");
+ }
+ }
+
+ public void testConvertNotExcludingEmptyBody() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><while service-category=\"cat1\" " +
+ "service-name=\"name1\" /><exit service-category=\"cat2\" " +
+ "service-name=\"name2\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestActivity act2=new TestActivity();
+ other2.getContents().add(act2);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(service);
+
+ service.setModel(model);
+
+ WhileAction action=new WhileAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ java.util.List<Activity> activities=new java.util.Vector<Activity>();
+
+ action.convert(activities, new DefaultConversionContext());
+
+ if (activities.size() != 2) {
+ fail("Expecting two activities, but got: "+activities.size());
+ }
+
+ Activity act=activities.get(0);
+
+ if ((act instanceof While) == false) {
+ fail("Expecting an 'While' activity");
+ }
+
+ While whileAction=(While)act;
+
+ if (whileAction.getBlock().getContents().size() != 0) {
+ fail("Expecting zero entries in while block: "+whileAction.getBlock().getContents().size());
+ }
+
+ if (activities.get(1) != act2) {
+ fail("Activity following while should be act2");
+ }
+ }
}
More information about the overlord-commits
mailing list