[overlord-commits] Overlord SVN: r218 - in cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src: java/org/jboss/tools/overlord/jbossesb/model/change and 2 other directories.
overlord-commits at lists.jboss.org
overlord-commits at lists.jboss.org
Tue Aug 5 12:44:24 EDT 2008
Author: objectiser
Date: 2008-08-05 12:44:24 -0400 (Tue, 05 Aug 2008)
New Revision: 218
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ParallelModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/WhenModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/WhileModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/ParallelModelChangeRuleTest.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/WhenModelChangeRuleTest.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/WhileModelChangeRuleTest.java
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/ParallelAction.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/java/org/jboss/tools/overlord/jbossesb/model/actions/WhileAction.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/IfModelChangeRule.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/change/IfModelChangeRuleTest.java
Log:
Parallel, When and While generation with unit tests.
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties 2008-08-05 10:27:12 UTC (rev 217)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties 2008-08-05 16:44:24 UTC (rev 218)
@@ -43,5 +43,4 @@
_SWITCH_ONE_OR_MORE_PATHS=Switch action must specify atleast one case
_UNKNOWN_PROPERTY=Property '{0}' is unknown for this action
_WHEN_ONE_OR_MORE_PATHS=When action must specify atleast one entry
-_WHEN_PATH_AFTER_JOIN=When path must not be defined after a join
_WHILE_PATH_AFTER_EXIT=While path must not be defined after an exit
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/ParallelAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/ParallelAction.java 2008-08-05 10:27:12 UTC (rev 217)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/ParallelAction.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -272,6 +272,52 @@
}
}
+ /**
+ * This method adds a path to the parallel action.
+ *
+ * @param category The service category
+ * @param name The service name
+ * @param immediate Whether invocation should be immediate
+ * @param join Whether the path is for the parallel, or join
+ * @param position The position
+ */
+ public void addPath(String category, String name,
+ boolean immediate, boolean join, int position) {
+
+ org.w3c.dom.NodeList nl=
+ getAction().getElementsByTagName(PROPERTY_ELEMENT);
+
+ org.w3c.dom.Element paths=null;
+
+ for (int i=0; paths == null && i < nl.getLength(); i++) {
+ if (nl.item(i) instanceof org.w3c.dom.Element) {
+ String propName=((org.w3c.dom.Element)nl.item(i)).getAttribute(NAME_ATTR);
+
+ if (propName != null && propName.equals(PATHS)) {
+ paths = (org.w3c.dom.Element)nl.item(i);
+ }
+ }
+ }
+
+ if (paths == null) {
+ paths = getAction().getOwnerDocument().createElement(PROPERTY_ELEMENT);
+ paths.setAttribute(NAME_ATTR, PATHS);
+
+ getAction().appendChild(paths);
+ }
+
+ org.w3c.dom.Element path=
+ getAction().getOwnerDocument().createElement(join ? JOIN : PATH);
+ path.setAttribute(SERVICE_CATEGORY, category);
+ path.setAttribute(SERVICE_NAME, name);
+
+ if (immediate) {
+ path.setAttribute(IMMEDIATE, Boolean.TRUE.toString());
+ }
+
+ paths.appendChild(path);
+ }
+
private java.util.List<ESBService> m_services=new java.util.Vector<ESBService>();
private String m_joinCategory=null;
private String m_joinName=null;
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-08-05 10:27:12 UTC (rev 217)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhenAction.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -31,7 +31,6 @@
private static final String SERVICE_NAME = "service-name";
private static final String SERVICE_CATEGORY = "service-category";
private static final String WHEN = "when";
- private static final String JOIN = "join";
private static final String PATHS = "paths";
/**
@@ -90,20 +89,6 @@
m_services.add(service);
}
}
-
- } else if (n.getNodeName().equals(JOIN)) {
- if (((org.w3c.dom.Element)n).hasAttribute(SERVICE_CATEGORY) &&
- ((org.w3c.dom.Element)n).hasAttribute(SERVICE_NAME)) {
- m_joinCategory=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
- m_joinName=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
-
- // Lookup service associated with category and name
- m_joinService=getService().getModel().getService(m_joinCategory, m_joinName);
-
- // Initialize link, even if service is null - this will be
- // reported as a validation error later
- getLinks().add(new ESBLink(m_joinCategory, m_joinName, m_joinService, true));
- }
}
}
}
@@ -137,9 +122,6 @@
org.w3c.dom.NodeList nl=getPropertyChildNodes(PATHS);
int pathCount=0;
- boolean f_joined=false;
- boolean f_pathAfterJoin=false;
- boolean f_multipleJoins=false;
boolean f_serviceDetailsMissing=false;
for (int i=0; nl != null && i < nl.getLength(); i++) {
@@ -149,22 +131,11 @@
if (n instanceof org.w3c.dom.Element) {
if (n.getNodeName().equals(WHEN)) {
pathCount++;
-
- if (f_joined) {
- f_pathAfterJoin = true;
- }
if (((org.w3c.dom.Element)n).hasAttribute(SERVICE_CATEGORY) == false ||
((org.w3c.dom.Element)n).hasAttribute(SERVICE_NAME) == false) {
f_serviceDetailsMissing = true;
}
- } else if (n.getNodeName().equals(JOIN)) {
-
- if (f_joined) {
- f_multipleJoins = true;
- }
-
- f_joined = true;
}
}
}
@@ -178,22 +149,6 @@
new String[]{}), null);
}
- if (f_pathAfterJoin) {
- l.error(this, org.scribble.util.MessageUtil.format(
- java.util.PropertyResourceBundle.getBundle(
- "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
- "_WHEN_PATH_AFTER_JOIN",
- new String[]{}), null);
- }
-
- if (f_multipleJoins) {
- l.error(this, org.scribble.util.MessageUtil.format(
- java.util.PropertyResourceBundle.getBundle(
- "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
- "_MULTIPLE_JOINS",
- new String[]{}), null);
- }
-
if (f_serviceDetailsMissing) {
l.error(this, org.scribble.util.MessageUtil.format(
java.util.PropertyResourceBundle.getBundle(
@@ -237,6 +192,46 @@
}
}
+ /**
+ * This method adds a path to the when action.
+ *
+ * @param category The service category
+ * @param name The service name
+ * @param position The position
+ */
+ public void addPath(String category, String name,
+ int position) {
+
+ org.w3c.dom.NodeList nl=
+ getAction().getElementsByTagName(PROPERTY_ELEMENT);
+
+ org.w3c.dom.Element paths=null;
+
+ for (int i=0; paths == null && i < nl.getLength(); i++) {
+ if (nl.item(i) instanceof org.w3c.dom.Element) {
+ String propName=((org.w3c.dom.Element)nl.item(i)).getAttribute(NAME_ATTR);
+
+ if (propName != null && propName.equals(PATHS)) {
+ paths = (org.w3c.dom.Element)nl.item(i);
+ }
+ }
+ }
+
+ if (paths == null) {
+ paths = getAction().getOwnerDocument().createElement(PROPERTY_ELEMENT);
+ paths.setAttribute(NAME_ATTR, PATHS);
+
+ getAction().appendChild(paths);
+ }
+
+ org.w3c.dom.Element path=
+ getAction().getOwnerDocument().createElement(WHEN);
+ path.setAttribute(SERVICE_CATEGORY, category);
+ path.setAttribute(SERVICE_NAME, name);
+
+ paths.appendChild(path);
+ }
+
private java.util.List<ESBService> m_services=new java.util.Vector<ESBService>();
private String m_joinCategory=null;
private String m_joinName=null;
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhileAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhileAction.java 2008-08-05 10:27:12 UTC (rev 217)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhileAction.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -34,6 +34,8 @@
private static final String WHILE = "while";
private static final String EXIT = "exit";
private static final String PATHS = "paths";
+ public static final String MESSAGE_ELEMENT="message";
+ public static final String TYPE_ATTR="type";
/**
* The constructor for the action.
@@ -301,6 +303,66 @@
}
}
+ /**
+ * This method adds a path to the when action.
+ *
+ * @param category The service category
+ * @param name The service name
+ * @param position The position
+ */
+ public void addPath(String category, String name, boolean exit,
+ java.util.List<MessageSignature> messageTypes,
+ int position) {
+
+ org.w3c.dom.NodeList nl=
+ getAction().getElementsByTagName(PROPERTY_ELEMENT);
+
+ org.w3c.dom.Element paths=null;
+
+ for (int i=0; paths == null && i < nl.getLength(); i++) {
+ if (nl.item(i) instanceof org.w3c.dom.Element) {
+ String propName=((org.w3c.dom.Element)nl.item(i)).getAttribute(NAME_ATTR);
+
+ if (propName != null && propName.equals(PATHS)) {
+ paths = (org.w3c.dom.Element)nl.item(i);
+ }
+ }
+ }
+
+ if (paths == null) {
+ paths = getAction().getOwnerDocument().createElement(PROPERTY_ELEMENT);
+ paths.setAttribute(NAME_ATTR, PATHS);
+
+ getAction().appendChild(paths);
+ }
+
+ org.w3c.dom.Element path=
+ getAction().getOwnerDocument().createElement(exit?EXIT:WHILE);
+ path.setAttribute(SERVICE_CATEGORY, category);
+ path.setAttribute(SERVICE_NAME, name);
+
+ paths.appendChild(path);
+
+ for (int i=0; i < messageTypes.size(); i++) {
+ org.w3c.dom.Element mt=
+ getAction().getOwnerDocument().createElement(MESSAGE_ELEMENT);
+
+ if (messageTypes.get(i).getTypes().size() == 1) {
+ TypeReference ref=messageTypes.get(i).getTypes().get(0);
+ String type="";
+
+ if (ref.getNamespace() != null) {
+ type += "{"+ref.getNamespace()+"}";
+ }
+ type += ref.getLocalpart();
+
+ mt.setAttribute(TYPE_ATTR, type);
+
+ path.appendChild(mt);
+ }
+ }
+ }
+
private String m_loopCategory=null;
private String m_loopName=null;
private ESBService m_loopService=null;
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/IfModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/IfModelChangeRule.java 2008-08-05 10:27:12 UTC (rev 217)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/IfModelChangeRule.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -178,19 +178,21 @@
switchAction.addCase(subService.getCategory(),
subService.getName(), interactions, i);
- java.util.Iterator<Interaction> iter=interactions.iterator();
-
- while (iter.hasNext()) {
- Interaction interaction=iter.next();
+ if (interactions != null) {
+ java.util.Iterator<Interaction> iter=interactions.iterator();
- //TODO: Only deals with single type for now
- // If a receive and not a response, then
- // add to the gateway
- if (InteractionUtil.isSend(interaction) == false &&
- interaction.getReplyToLabel() == null &&
- interaction.getMessageSignature().getTypes().size()==1) {
-
- messageTypes.add(interaction.getMessageSignature());
+ while (iter.hasNext()) {
+ Interaction interaction=iter.next();
+
+ //TODO: Only deals with single type for now
+ // If a receive and not a response, then
+ // add to the gateway
+ if (InteractionUtil.isSend(interaction) == false &&
+ interaction.getReplyToLabel() == null &&
+ interaction.getMessageSignature().getTypes().size()==1) {
+
+ messageTypes.add(interaction.getMessageSignature());
+ }
}
}
}
@@ -220,19 +222,21 @@
switchAction.addCase(subService.getCategory(),
subService.getName(), interactions, -1);
- java.util.Iterator<Interaction> iter=interactions.iterator();
-
- while (iter.hasNext()) {
- Interaction interaction=iter.next();
+ if (interactions != null) {
+ java.util.Iterator<Interaction> iter=interactions.iterator();
- //TODO: Only deals with single type for now
- // If a receive and not a response, then
- // add to the gateway
- if (InteractionUtil.isSend(interaction) == false &&
- interaction.getReplyToLabel() == null &&
- interaction.getMessageSignature().getTypes().size()==1) {
-
- messageTypes.add(interaction.getMessageSignature());
+ while (iter.hasNext()) {
+ Interaction interaction=iter.next();
+
+ //TODO: Only deals with single type for now
+ // If a receive and not a response, then
+ // add to the gateway
+ if (InteractionUtil.isSend(interaction) == false &&
+ interaction.getReplyToLabel() == null &&
+ interaction.getMessageSignature().getTypes().size()==1) {
+
+ messageTypes.add(interaction.getMessageSignature());
+ }
}
}
}
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ParallelModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ParallelModelChangeRule.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ParallelModelChangeRule.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -0,0 +1,146 @@
+/*
+ * 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.change;
+
+import java.util.logging.Logger;
+
+import org.jboss.tools.overlord.jbossesb.model.*;
+import org.jboss.tools.overlord.jbossesb.model.actions.*;
+import org.jboss.tools.overlord.jbossesb.model.util.*;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.scribble.model.analysis.*;
+import org.scribble.conversation.model.*;
+import org.scribble.extensions.*;
+
+/**
+ * This is the model change rule for the Parallel grouping construct.
+ */
+ at RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class ParallelModelChangeRule extends AbstractModelChangeRule {
+
+ /**
+ * This method determines whether the rule is appropriate
+ * for the supplied type of model, parent (in the context) and
+ * model object.
+ *
+ * @param context The context
+ * @param model The model
+ * @param mobj The model object causing the change
+ * @return Whether the rule supports the supplied information
+ */
+ @Override
+ protected boolean isChangeSupported(ModelChangeContext context,
+ Model model, ModelObject mobj) {
+ boolean ret=false;
+
+ if (mobj instanceof Parallel &&
+ context.getParent() instanceof ESBService &&
+ model instanceof ESBLanguageModel) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method adds a new model object, within a
+ * parent model object, with the details supplied in
+ * another model object. The supplied model object
+ * will usually be from a different model representation
+ * (e.g. due to a merge), so the details will be
+ * copied and placed in the representation associated
+ * with the supplied model and parent model object.
+ *
+ * @param context The context
+ * @param model The model being changed
+ * @param mobj The model object details to be inserted
+ * @param position The position, where relevant
+ * @return Whether the change has been applied
+ */
+ @Override
+ public boolean insert(ModelChangeContext context,
+ Model model, ModelObject mobj, int position) {
+ ESBLanguageModel esbModel=(ESBLanguageModel)model;
+ ESBService service=(ESBService)context.getParent();
+ Parallel parallel=(Parallel)mobj;
+
+ ParallelAction parAction=new ParallelAction(service);
+
+ service.addAction(parAction, position);
+
+ for (int i=0; i < parallel.getBlocks().size(); i++) {
+ Block b=parallel.getBlocks().get(i);
+
+ ESBService subService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(subService);
+
+ context.setParent(subService);
+
+ for (int j=0; j < b.getContents().size(); j++) {
+ context.insert(model, b.getContents().get(j), j);
+ }
+
+ boolean immediate=true;
+
+ // Get lookahead analyser
+ LookaheadAnalyser la=(LookaheadAnalyser)
+ RegistryFactory.getRegistry().getExtension(
+ LookaheadAnalyser.class, null);
+
+ if (la == null) {
+ logger.severe("Failed to get lookahead analyser");
+ } else {
+ java.util.Iterator<Interaction> iter=
+ la.getInteractions(b, true).iterator();
+
+ while (immediate && iter.hasNext()) {
+ Interaction interaction=iter.next();
+
+ // If interaction is a receive, then immediate
+ // invocation will be false
+ immediate = InteractionUtil.isSend(interaction);
+ }
+ }
+
+ parAction.addPath(subService.getCategory(),
+ subService.getName(), immediate, false, i);
+ }
+
+ // Create the join service
+ ESBService joinService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(joinService);
+
+ context.setParent(joinService);
+
+ parAction.addPath(joinService.getCategory(),
+ joinService.getName(), false, true, -1);
+
+ return(true);
+ }
+
+ private static Logger logger = Logger.getLogger("org.jboss.tools.overlord.jbossesb.model.change");
+}
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/WhenModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/WhenModelChangeRule.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/WhenModelChangeRule.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -0,0 +1,204 @@
+/*
+ * 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.change;
+
+import java.util.logging.Logger;
+
+import org.jboss.tools.overlord.jbossesb.model.*;
+import org.jboss.tools.overlord.jbossesb.model.actions.*;
+import org.jboss.tools.overlord.jbossesb.model.util.*;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.scribble.model.analysis.*;
+import org.scribble.conversation.model.*;
+import org.scribble.extensions.*;
+
+/**
+ * This is the model change rule for the When grouping construct.
+ */
+ at RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class WhenModelChangeRule extends AbstractModelChangeRule {
+
+ /**
+ * This method determines whether the rule is appropriate
+ * for the supplied type of model, parent (in the context) and
+ * model object.
+ *
+ * @param context The context
+ * @param model The model
+ * @param mobj The model object causing the change
+ * @return Whether the rule supports the supplied information
+ */
+ @Override
+ protected boolean isChangeSupported(ModelChangeContext context,
+ Model model, ModelObject mobj) {
+ boolean ret=false;
+
+ if (mobj instanceof When &&
+ context.getParent() instanceof ESBService &&
+ model instanceof ESBLanguageModel) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method adds a new model object, within a
+ * parent model object, with the details supplied in
+ * another model object. The supplied model object
+ * will usually be from a different model representation
+ * (e.g. due to a merge), so the details will be
+ * copied and placed in the representation associated
+ * with the supplied model and parent model object.
+ *
+ * @param context The context
+ * @param model The model being changed
+ * @param mobj The model object details to be inserted
+ * @param position The position, where relevant
+ * @return Whether the change has been applied
+ */
+ @Override
+ public boolean insert(ModelChangeContext context,
+ Model model, ModelObject mobj, int position) {
+ ESBLanguageModel esbModel=(ESBLanguageModel)model;
+ ESBService service=(ESBService)context.getParent();
+ When when=(When)mobj;
+
+ // Check if context role is decision maker
+ if (when.getRoles().contains(context.getRole())) {
+ WhenAction action=new WhenAction(service);
+
+ service.addAction(action, position);
+
+ for (int i=0; i < when.getConditionalBlocks().size(); i++) {
+ ConditionalBlock b=when.getConditionalBlocks().get(i);
+
+ ESBService subService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(subService);
+
+ context.setParent(subService);
+
+ for (int j=0; j < b.getContents().size(); j++) {
+ context.insert(model, b.getContents().get(j), j);
+ }
+
+ action.addPath(subService.getCategory(),
+ subService.getName(), i);
+ }
+ } else {
+
+ // Switch action, as role is a decision observer
+ SwitchAction switchAction=new SwitchAction(service);
+
+ // Get lookahead analyser
+ LookaheadAnalyser la=(LookaheadAnalyser)
+ RegistryFactory.getRegistry().getExtension(
+ LookaheadAnalyser.class, null);
+
+ if (la == null) {
+ logger.severe("Failed to find lookahead analyser");
+ }
+
+ service.addAction(switchAction, position);
+
+ java.util.List<MessageSignature> messageTypes=
+ new java.util.Vector<MessageSignature>();
+
+ for (int i=0; i < when.getConditionalBlocks().size(); i++) {
+ ConditionalBlock cb=when.getConditionalBlocks().get(i);
+
+ ESBService subService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(subService);
+
+ context.setParent(subService);
+
+ for (int j=0; j < cb.getContents().size(); j++) {
+ context.insert(model, cb.getContents().get(j), j);
+ }
+
+ java.util.Set<Interaction> interactions=null;
+
+ if (la != null) {
+ interactions = la.getInteractions(cb);
+ }
+
+ switchAction.addCase(subService.getCategory(),
+ subService.getName(), interactions, i);
+
+ if (interactions != null) {
+ java.util.Iterator<Interaction> iter=interactions.iterator();
+
+ while (iter.hasNext()) {
+ Interaction interaction=iter.next();
+
+ //TODO: Only deals with single type for now
+ // If a receive and not a response, then
+ // add to the gateway
+ if (InteractionUtil.isSend(interaction) == false &&
+ interaction.getReplyToLabel() == null &&
+ interaction.getMessageSignature().getTypes().size()==1) {
+
+ messageTypes.add(interaction.getMessageSignature());
+ }
+ }
+ }
+ }
+
+ // Only record message router 'routes' if the switch
+ // receives request interactions, and it is the first
+ // session based action in the service
+ if (messageTypes.size() > 0 &&
+ service.getFirstSessionBasedAction() == switchAction) {
+ ESBService gwService=
+ esbModel.getGatewayService();
+
+ if (gwService != null) {
+ ESBAction gwAction=gwService.getGatewayAction();
+
+ if (gwAction instanceof MessageRouterAction) {
+ MessageRouterAction mra=(MessageRouterAction)
+ gwAction;
+
+ mra.addRoute(service.getCategory(),
+ service.getName(),
+ false, messageTypes);
+ }
+ }
+ }
+
+ if (service.getFirstSessionBasedAction() == switchAction &&
+ when.getEnclosingDefinition() instanceof Conversation) {
+ switchAction.setBusinessObjectType(ConversationUtil.getBusinessObjectType(
+ ((Conversation)when.getEnclosingDefinition())));
+ }
+ }
+
+ return(true);
+ }
+
+ private static Logger logger = Logger.getLogger("org.jboss.tools.overlord.jbossesb.model.change");
+}
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/WhileModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/WhileModelChangeRule.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/WhileModelChangeRule.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -0,0 +1,159 @@
+/*
+ * 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.change;
+
+import java.util.logging.Logger;
+
+import org.jboss.tools.overlord.jbossesb.model.*;
+import org.jboss.tools.overlord.jbossesb.model.actions.*;
+import org.jboss.tools.overlord.jbossesb.model.util.*;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.scribble.model.analysis.*;
+import org.scribble.conversation.model.*;
+import org.scribble.extensions.*;
+
+/**
+ * This is the model change rule for the While repetition construct.
+ */
+ at RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class WhileModelChangeRule extends AbstractModelChangeRule {
+
+ /**
+ * This method determines whether the rule is appropriate
+ * for the supplied type of model, parent (in the context) and
+ * model object.
+ *
+ * @param context The context
+ * @param model The model
+ * @param mobj The model object causing the change
+ * @return Whether the rule supports the supplied information
+ */
+ @Override
+ protected boolean isChangeSupported(ModelChangeContext context,
+ Model model, ModelObject mobj) {
+ boolean ret=false;
+
+ if (mobj instanceof While &&
+ context.getParent() instanceof ESBService &&
+ model instanceof ESBLanguageModel) {
+ ret = true;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method adds a new model object, within a
+ * parent model object, with the details supplied in
+ * another model object. The supplied model object
+ * will usually be from a different model representation
+ * (e.g. due to a merge), so the details will be
+ * copied and placed in the representation associated
+ * with the supplied model and parent model object.
+ *
+ * @param context The context
+ * @param model The model being changed
+ * @param mobj The model object details to be inserted
+ * @param position The position, where relevant
+ * @return Whether the change has been applied
+ */
+ @Override
+ public boolean insert(ModelChangeContext context,
+ Model model, ModelObject mobj, int position) {
+ ESBLanguageModel esbModel=(ESBLanguageModel)model;
+ ESBService service=(ESBService)context.getParent();
+ While whileElem=(While)mobj;
+
+ WhileAction action=new WhileAction(service);
+
+ service.addAction(action, position);
+
+ ESBService subService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(subService);
+
+ context.setParent(subService);
+
+ for (int j=0; j < whileElem.getBlock().getContents().size(); j++) {
+ context.insert(model, whileElem.getBlock().getContents().get(j), j);
+ }
+
+
+ java.util.List<MessageSignature> messageTypes=
+ new java.util.Vector<MessageSignature>();
+
+ // Check if context role is NOT the decision maker
+ if (whileElem.getRoles().contains(context.getRole()) == false) {
+
+ // Get lookahead analyser
+ LookaheadAnalyser la=(LookaheadAnalyser)
+ RegistryFactory.getRegistry().getExtension(
+ LookaheadAnalyser.class, null);
+
+ if (la == null) {
+ logger.severe("Failed to find lookahead analyser");
+ }
+
+ java.util.Set<Interaction> interactions=null;
+
+ if (la != null) {
+ interactions = la.getInteractions(whileElem.getBlock());
+ }
+
+ if (interactions != null) {
+ java.util.Iterator<Interaction> iter=interactions.iterator();
+
+ while (iter.hasNext()) {
+ Interaction interaction=iter.next();
+
+ if (InteractionUtil.isSend(interaction) == false &&
+ interaction.getMessageSignature().getTypes().size()==1) {
+
+ messageTypes.add(interaction.getMessageSignature());
+ }
+ }
+ }
+
+ }
+
+ action.addPath(subService.getCategory(),
+ subService.getName(), false, messageTypes, -1);
+
+ // Create exit service
+ ESBService exitService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(exitService);
+
+ context.setParent(exitService);
+
+ action.addPath(exitService.getCategory(),
+ exitService.getName(), true,
+ new java.util.Vector<MessageSignature>(), -1);
+
+ return(true);
+ }
+
+ private static Logger logger = Logger.getLogger("org.jboss.tools.overlord.jbossesb.model.change");
+}
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-08-05 10:27:12 UTC (rev 217)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhenActionTest.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -193,109 +193,6 @@
}
}
- public void testValidateOutOfOrderJoin() {
- 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\" /><join service-category=\"cat3\" " +
- "service-name=\"name3\" /><when 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");
-
- 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);
-
- WhenAction action=new WhenAction(service, elem);
- action.initializeLinks();
-
- service.getActions().add(action);
-
- TestModelListener l=new TestModelListener();
-
- l.addExpectedError(org.scribble.util.MessageUtil.format(
- java.util.PropertyResourceBundle.getBundle(
- "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
- "_WHEN_PATH_AFTER_JOIN",
- new String[]{}));
-
- action.validate(l);
-
- if (l.isValid() == false) {
- fail(l.invalidMessage());
- }
- }
-
- public void testValidateOnlyOneJoin() {
- 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\" /><join service-category=\"cat3\" " +
- "service-name=\"name3\" /><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");
-
- 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);
-
- WhenAction action=new WhenAction(service, elem);
- action.initializeLinks();
-
- service.getActions().add(action);
-
- TestModelListener l=new TestModelListener();
-
- l.addExpectedError(org.scribble.util.MessageUtil.format(
- java.util.PropertyResourceBundle.getBundle(
- "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
- "_MULTIPLE_JOINS",
- new String[]{}));
-
- action.validate(l);
-
- if (l.isValid() == false) {
- fail(l.invalidMessage());
- }
- }
-
public void testConvert() {
TestESBService service=new TestESBService();
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/IfModelChangeRuleTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/IfModelChangeRuleTest.java 2008-08-05 10:27:12 UTC (rev 217)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/IfModelChangeRuleTest.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -332,6 +332,10 @@
public void testInsertSwitchAction() {
IfModelChangeRule rule=new IfModelChangeRule();
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(null);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
TestESBLanguageModel model=new TestESBLanguageModel();
TestESBService service=(TestESBService)
@@ -412,6 +416,10 @@
public void testInsertSwitchMultipleCaseAction() {
IfModelChangeRule rule=new IfModelChangeRule();
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(null);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
TestESBLanguageModel model=new TestESBLanguageModel();
TestESBService service=(TestESBService)
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/ParallelModelChangeRuleTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/ParallelModelChangeRuleTest.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/ParallelModelChangeRuleTest.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -0,0 +1,445 @@
+/*
+ * 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.change;
+
+import junit.framework.TestCase;
+
+import org.jboss.tools.overlord.jbossesb.model.*;
+import org.jboss.tools.overlord.jbossesb.model.actions.*;
+import org.scribble.model.*;
+import org.scribble.model.analysis.*;
+import org.scribble.model.change.*;
+import org.scribble.conversation.model.*;
+
+public class ParallelModelChangeRuleTest extends TestCase {
+
+ public void testInsertParallelAction() {
+ ParallelModelChangeRule rule=new ParallelModelChangeRule();
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(null);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ Role role=new Role();
+ role.setName("role1");
+
+ context.setRole(role);
+
+ Parallel mobj=new Parallel();
+
+ Block cb1=new Block();
+ mobj.getBlocks().add(cb1);
+
+ Block cb2=new Block();
+ mobj.getBlocks().add(cb2);
+
+ Block cb3=new Block();
+ mobj.getBlocks().add(cb3);
+
+ if (rule.insert(context, model, mobj, -1) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof ParallelAction) == false) {
+ fail("Action was not ParallelAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 5) {
+ fail("Five services expected: "+model.getServices().size());
+ }
+
+ ESBService s1=null;
+ ESBService s2=null;
+ ESBService s3=null;
+ ESBService join=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((s1 == null || s2 == null || s3 == null ||
+ join == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ s1 = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ s2 = serv;
+ }
+ if (serv.getName().endsWith("__2")) {
+ s3 = serv;
+ }
+ if (serv.getName().endsWith("__3")) {
+ join = serv;
+ }
+ }
+
+ ParallelAction action=(ParallelAction)service.getActions().get(0);
+
+ org.w3c.dom.NodeList paths=action.getPropertyChildNodes("paths");
+
+ if (paths.getLength() != 4) {
+ fail("Four path children expected: "+paths.getLength());
+ }
+
+ org.w3c.dom.Element elem=(org.w3c.dom.Element)paths.item(0);
+
+ if (elem.getNodeName().equals("path") == false) {
+ fail("path(1) expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s1.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s1.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s1.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s1.getName());
+ }
+
+ if (elem.getAttribute("immediate").equals("true") == false) {
+ fail("path(1) immediate not set");
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(1);
+
+ if (elem.getNodeName().equals("path") == false) {
+ fail("path(2) expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s2.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s2.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s2.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s2.getName());
+ }
+
+ if (elem.getAttribute("immediate").equals("true") == false) {
+ fail("path(2) immediate not set");
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(2);
+
+ if (elem.getNodeName().equals("path") == false) {
+ fail("path(3) expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s3.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s3.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s3.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s3.getName());
+ }
+
+ if (elem.getAttribute("immediate").equals("true") == false) {
+ fail("path(3) immediate not set");
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(3);
+
+ if (elem.getNodeName().equals("join") == false) {
+ fail("join expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(join.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+join.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(join.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+join.getName());
+ }
+
+ if (elem.hasAttribute("immediate")) {
+ fail("Join should not be immediate");
+ }
+ }
+
+ public void testInsertParallelActionWithImmediateFalse() {
+ ParallelModelChangeRule rule=new ParallelModelChangeRule();
+
+ java.util.Set<Interaction> interactions=new java.util.HashSet<Interaction>();
+
+ TestLookaheadAnalyser tla=new TestLookaheadAnalyser();
+ tla.setInteractions(interactions);
+
+ Role role=new Role();
+
+ role.setName("role1");
+
+ Interaction interaction=new Interaction();
+ interaction.setToRole(role);
+
+ interactions.add(interaction);
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(tla);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ context.setRole(role);
+
+ Conversation conv=new Conversation();
+ ModelName mname=new ModelName();
+ conv.setModelName(mname);
+
+ mname.setLocatedRole(role);
+
+ Parallel mobj=new Parallel();
+ conv.getBlock().getContents().add(mobj);
+
+ Block cb1=new Block();
+ mobj.getBlocks().add(cb1);
+
+ cb1.getContents().add(interaction);
+
+ if (rule.insert(context, model, mobj, -1) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof ParallelAction) == false) {
+ fail("Action was not ParallelAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 3) {
+ fail("Three services expected: "+model.getServices().size());
+ }
+
+ ESBService s1=null;
+ ESBService join=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((s1 == null || join == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ s1 = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ join = serv;
+ }
+ }
+
+ ParallelAction action=(ParallelAction)service.getActions().get(0);
+
+ org.w3c.dom.NodeList paths=action.getPropertyChildNodes("paths");
+
+ if (paths.getLength() != 2) {
+ fail("Two path children expected: "+paths.getLength());
+ }
+
+ org.w3c.dom.Element elem=(org.w3c.dom.Element)paths.item(0);
+
+ if (elem.getNodeName().equals("path") == false) {
+ fail("path(1) expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s1.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s1.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s1.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s1.getName());
+ }
+
+ if (elem.hasAttribute("immediate")) {
+ fail("path(1) should not be immediate");
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(1);
+
+ if (elem.getNodeName().equals("join") == false) {
+ fail("join expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(join.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+join.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(join.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+join.getName());
+ }
+
+ if (elem.hasAttribute("immediate")) {
+ fail("Join should not be immediate");
+ }
+ }
+
+ public void testInsertParallelActionWithImmediateTrue() {
+ ParallelModelChangeRule rule=new ParallelModelChangeRule();
+
+ java.util.Set<Interaction> interactions=new java.util.HashSet<Interaction>();
+
+ TestLookaheadAnalyser tla=new TestLookaheadAnalyser();
+ tla.setInteractions(interactions);
+
+ Role role=new Role();
+ role.setName("role1");
+
+ Interaction interaction=new Interaction();
+ interaction.setFromRole(role);
+
+ interactions.add(interaction);
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(tla);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ context.setRole(role);
+
+ Conversation conv=new Conversation();
+ ModelName mname=new ModelName();
+ conv.setModelName(mname);
+
+ mname.setLocatedRole(role);
+
+ Parallel mobj=new Parallel();
+ conv.getBlock().getContents().add(mobj);
+
+ Block cb1=new Block();
+ mobj.getBlocks().add(cb1);
+
+ cb1.getContents().add(interaction);
+
+ if (rule.insert(context, model, mobj, -1) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof ParallelAction) == false) {
+ fail("Action was not ParallelAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 3) {
+ fail("Three services expected: "+model.getServices().size());
+ }
+
+ ESBService s1=null;
+ ESBService join=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((s1 == null || join == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ s1 = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ join = serv;
+ }
+ }
+
+ ParallelAction action=(ParallelAction)service.getActions().get(0);
+
+ org.w3c.dom.NodeList paths=action.getPropertyChildNodes("paths");
+
+ if (paths.getLength() != 2) {
+ fail("Two path children expected: "+paths.getLength());
+ }
+
+ org.w3c.dom.Element elem=(org.w3c.dom.Element)paths.item(0);
+
+ if (elem.getNodeName().equals("path") == false) {
+ fail("path(1) expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s1.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s1.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s1.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s1.getName());
+ }
+
+ if (elem.getAttribute("immediate").equals("true") == false) {
+ fail("path(1) should be immediate");
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(1);
+
+ if (elem.getNodeName().equals("join") == false) {
+ fail("join expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(join.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+join.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(join.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+join.getName());
+ }
+
+ if (elem.hasAttribute("immediate")) {
+ fail("Join should not be immediate");
+ }
+ }
+}
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/WhenModelChangeRuleTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/WhenModelChangeRuleTest.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/WhenModelChangeRuleTest.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -0,0 +1,372 @@
+/*
+ * 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.change;
+
+import junit.framework.TestCase;
+
+import org.jboss.tools.overlord.jbossesb.model.*;
+import org.jboss.tools.overlord.jbossesb.model.actions.*;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.scribble.conversation.model.*;
+
+public class WhenModelChangeRuleTest extends TestCase {
+
+ public void testInsertWhenAction() {
+ WhenModelChangeRule rule=new WhenModelChangeRule();
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(null);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ Role role=new Role();
+ role.setName("role1");
+
+ context.setRole(role);
+
+ When mobj=new When();
+
+ ConditionalBlock cb1=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb1);
+
+ ConditionalBlock cb2=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb2);
+
+ ConditionalBlock cb3=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb3);
+
+ mobj.getRoles().add(role);
+
+ if (rule.insert(context, model, mobj, -1) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof WhenAction) == false) {
+ fail("Action was not WhenAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 4) {
+ fail("Four services expected: "+model.getServices().size());
+ }
+
+ ESBService s1=null;
+ ESBService s2=null;
+ ESBService s3=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((s1 == null || s2 == null ||
+ s3 == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ s1 = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ s2 = serv;
+ }
+ if (serv.getName().endsWith("__2")) {
+ s3 = serv;
+ }
+ }
+
+ WhenAction action=(WhenAction)service.getActions().get(0);
+
+ org.w3c.dom.NodeList paths=action.getPropertyChildNodes("paths");
+
+ if (paths.getLength() != 3) {
+ fail("Three path children expected: "+paths.getLength());
+ }
+
+ org.w3c.dom.Element elem=(org.w3c.dom.Element)paths.item(0);
+
+ if (elem.getNodeName().equals("when") == false) {
+ fail("when(1) expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s1.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s1.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s1.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s1.getName());
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(1);
+
+ if (elem.getNodeName().equals("when") == false) {
+ fail("when(2) expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s2.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s2.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s2.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s2.getName());
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(2);
+
+ if (elem.getNodeName().equals("when") == false) {
+ fail("when(3) expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s3.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s3.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s3.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s3.getName());
+ }
+ }
+
+ public void testInsertSwitchAction() {
+ WhenModelChangeRule rule=new WhenModelChangeRule();
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(null);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ Role role1=new Role();
+ role1.setName("role1");
+
+ Role role2=new Role();
+ role2.setName("role2");
+
+ context.setRole(role1);
+
+ When mobj=new When();
+
+ mobj.getRoles().add(role2);
+
+ ConditionalBlock cb1=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb1);
+
+ if (rule.insert(context, model, mobj, -1) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof SwitchAction) == false) {
+ fail("Action was not SwitchAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 2) {
+ fail("Two services expected: "+model.getServices().size());
+ }
+
+ ESBService switchService=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while (switchService == null && iter.hasNext()) {
+ switchService = iter.next();
+ if (switchService == service) {
+ switchService = null;
+ }
+ }
+
+ SwitchAction action=(SwitchAction)service.getActions().get(0);
+
+ org.w3c.dom.NodeList paths=action.getPropertyChildNodes("paths");
+
+ if (paths.getLength() != 1) {
+ fail("Only one path child expected: "+paths.getLength());
+ }
+
+ org.w3c.dom.Element elem=(org.w3c.dom.Element)paths.item(0);
+
+ if (elem.getNodeName().equals("case") == false) {
+ fail("Switch expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(switchService.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+switchService.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(switchService.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+switchService.getName());
+ }
+ }
+
+ public void testInsertSwitchMultipleCaseAction() {
+ WhenModelChangeRule rule=new WhenModelChangeRule();
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(null);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ Role role1=new Role();
+ role1.setName("role1");
+
+ Role role2=new Role();
+ role2.setName("role2");
+
+ context.setRole(role1);
+
+ When mobj=new When();
+
+ mobj.getRoles().add(role2);
+
+ ConditionalBlock cb1=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb1);
+
+ ConditionalBlock cb2=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb2);
+
+ ConditionalBlock cb3=new ConditionalBlock();
+ mobj.getConditionalBlocks().add(cb3);
+
+ if (rule.insert(context, model, mobj, -1) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof SwitchAction) == false) {
+ fail("Action was not SwitchAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 4) {
+ fail("Four services expected: "+model.getServices().size());
+ }
+
+ ESBService caseService1=null;
+ ESBService caseService2=null;
+ ESBService caseService3=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((caseService1 == null || caseService2 == null ||
+ caseService3 == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ caseService1 = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ caseService2 = serv;
+ }
+ if (serv.getName().endsWith("__2")) {
+ caseService3 = serv;
+ }
+ }
+
+ SwitchAction action=(SwitchAction)service.getActions().get(0);
+
+ org.w3c.dom.NodeList paths=action.getPropertyChildNodes("paths");
+
+ if (paths.getLength() != 3) {
+ fail("Three path children expected: "+paths.getLength());
+ }
+
+ org.w3c.dom.Element elem=(org.w3c.dom.Element)paths.item(0);
+
+ if (elem.getNodeName().equals("case") == false) {
+ fail("Case expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(caseService1.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+caseService1.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(caseService1.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+caseService1.getName());
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(1);
+
+ if (elem.getNodeName().equals("case") == false) {
+ fail("Case expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(caseService2.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+caseService2.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(caseService2.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+caseService2.getName());
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(2);
+
+ if (elem.getNodeName().equals("case") == false) {
+ fail("Else expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(caseService3.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+caseService3.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(caseService3.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+caseService3.getName());
+ }
+ }
+}
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/WhileModelChangeRuleTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/WhileModelChangeRuleTest.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/WhileModelChangeRuleTest.java 2008-08-05 16:44:24 UTC (rev 218)
@@ -0,0 +1,420 @@
+/*
+ * 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.change;
+
+import junit.framework.TestCase;
+
+import org.jboss.tools.overlord.jbossesb.model.*;
+import org.jboss.tools.overlord.jbossesb.model.actions.*;
+import org.scribble.model.*;
+import org.scribble.model.analysis.TestLookaheadAnalyser;
+import org.scribble.model.change.*;
+import org.scribble.conversation.model.*;
+
+public class WhileModelChangeRuleTest extends TestCase {
+
+ public void testInsertWhileActionInitiator() {
+ WhileModelChangeRule rule=new WhileModelChangeRule();
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ java.util.Set<Interaction> interactions=new java.util.HashSet<Interaction>();
+
+ TestLookaheadAnalyser tla=new TestLookaheadAnalyser();
+ tla.setInteractions(interactions);
+
+ Role role=new Role();
+ role.setName("role1");
+
+ Interaction interaction=new Interaction();
+ interaction.setToRole(role);
+
+ TypeReference ref=new TypeReference();
+ ref.setNamespace("ns");
+ ref.setLocalpart("lp");
+
+ MessageSignature msig=new MessageSignature();
+ interaction.setMessageSignature(msig);
+ msig.getTypes().add(ref);
+
+ interactions.add(interaction);
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(tla);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ context.setRole(role);
+
+ Conversation conv=new Conversation();
+ ModelName mname=new ModelName();
+ conv.setModelName(mname);
+
+ mname.setLocatedRole(role);
+
+ While mobj=new While();
+ conv.getBlock().getContents().add(mobj);
+
+ mobj.getRoles().add(role);
+
+ if (rule.insert(context, model, mobj, -1) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof WhileAction) == false) {
+ fail("Action was not WhileAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 3) {
+ fail("Three services expected: "+model.getServices().size());
+ }
+
+ ESBService s1=null;
+ ESBService s2=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((s1 == null || s2 == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ s1 = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ s2 = serv;
+ }
+ }
+
+ WhileAction action=(WhileAction)service.getActions().get(0);
+
+ org.w3c.dom.NodeList paths=action.getPropertyChildNodes("paths");
+
+ if (paths.getLength() != 2) {
+ fail("Two path children expected: "+paths.getLength());
+ }
+
+ org.w3c.dom.Element elem=(org.w3c.dom.Element)paths.item(0);
+
+ if (elem.getNodeName().equals("while") == false) {
+ fail("while expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s1.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s1.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s1.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s1.getName());
+ }
+
+ // Check no message types
+ org.w3c.dom.NodeList mtypeNL=elem.getElementsByTagName("message");
+
+ if (mtypeNL.getLength() != 0) {
+ fail("Should have no message types: "+mtypeNL.getLength());
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(1);
+
+ if (elem.getNodeName().equals("exit") == false) {
+ fail("exit expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s2.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s2.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s2.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s2.getName());
+ }
+ }
+
+ public void testInsertWhileActionRecipient() {
+ WhileModelChangeRule rule=new WhileModelChangeRule();
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ java.util.Set<Interaction> interactions=new java.util.HashSet<Interaction>();
+
+ TestLookaheadAnalyser tla=new TestLookaheadAnalyser();
+ tla.setInteractions(interactions);
+
+ Role role=new Role();
+ role.setName("role1");
+
+ Interaction interaction=new Interaction();
+ interaction.setToRole(role);
+
+ TypeReference ref=new TypeReference();
+ ref.setNamespace("ns");
+ ref.setLocalpart("lp");
+
+ MessageSignature msig=new MessageSignature();
+ interaction.setMessageSignature(msig);
+ msig.getTypes().add(ref);
+
+ interactions.add(interaction);
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(tla);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ context.setRole(role);
+
+ Conversation conv=new Conversation();
+ ModelName mname=new ModelName();
+ conv.setModelName(mname);
+
+ mname.setLocatedRole(role);
+
+ While mobj=new While();
+ conv.getBlock().getContents().add(mobj);
+
+ mobj.getBlock().getContents().add(interaction);
+
+ if (rule.insert(context, model, mobj, -1) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof WhileAction) == false) {
+ fail("Action was not WhileAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 3) {
+ fail("Three services expected: "+model.getServices().size());
+ }
+
+ ESBService s1=null;
+ ESBService s2=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((s1 == null || s2 == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ s1 = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ s2 = serv;
+ }
+ }
+
+ WhileAction action=(WhileAction)service.getActions().get(0);
+
+ org.w3c.dom.NodeList paths=action.getPropertyChildNodes("paths");
+
+ if (paths.getLength() != 2) {
+ fail("Two path children expected: "+paths.getLength());
+ }
+
+ org.w3c.dom.Element elem=(org.w3c.dom.Element)paths.item(0);
+
+ if (elem.getNodeName().equals("while") == false) {
+ fail("while expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s1.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s1.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s1.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s1.getName());
+ }
+
+ // Check no message types
+ org.w3c.dom.NodeList mtypeNL=elem.getElementsByTagName("message");
+
+ if (mtypeNL.getLength() != 1) {
+ fail("Should have single message type: "+mtypeNL.getLength());
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(1);
+
+ if (elem.getNodeName().equals("exit") == false) {
+ fail("exit expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s2.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s2.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s2.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s2.getName());
+ }
+ }
+
+ public void testInsertWhileActionRecipientNoRecvLookahead() {
+ WhileModelChangeRule rule=new WhileModelChangeRule();
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+
+ TestESBService service=(TestESBService)
+ model.createService("testcategory", "testname");
+
+ model.addService(service);
+
+ TestModelChangeContext context=new TestModelChangeContext();
+ context.setParent(service);
+
+ java.util.Set<Interaction> interactions=new java.util.HashSet<Interaction>();
+
+ TestLookaheadAnalyser tla=new TestLookaheadAnalyser();
+ tla.setInteractions(interactions);
+
+ Role role=new Role();
+ role.setName("role1");
+
+ Interaction interaction=new Interaction();
+ interaction.setFromRole(role);
+
+ TypeReference ref=new TypeReference();
+ ref.setNamespace("ns");
+ ref.setLocalpart("lp");
+
+ MessageSignature msig=new MessageSignature();
+ interaction.setMessageSignature(msig);
+ msig.getTypes().add(ref);
+
+ interactions.add(interaction);
+
+ org.scribble.extensions.TestSingleExtensionRegistry reg=
+ new org.scribble.extensions.TestSingleExtensionRegistry(tla);
+ org.scribble.extensions.RegistryFactory.setRegistry(reg);
+
+ context.setRole(role);
+
+ Conversation conv=new Conversation();
+ ModelName mname=new ModelName();
+ conv.setModelName(mname);
+
+ mname.setLocatedRole(role);
+
+ While mobj=new While();
+ conv.getBlock().getContents().add(mobj);
+
+ mobj.getBlock().getContents().add(interaction);
+
+ if (rule.insert(context, model, mobj, -1) == false) {
+ fail("Failed to insert");
+ }
+
+ // Check actions
+ if (service.getActions().size() != 1) {
+ fail("Expecting 1 action: "+service.getActions().size());
+ }
+
+ if ((service.getActions().get(0) instanceof WhileAction) == false) {
+ fail("Action was not WhileAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 3) {
+ fail("Three services expected: "+model.getServices().size());
+ }
+
+ ESBService s1=null;
+ ESBService s2=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+
+ while ((s1 == null || s2 == null) && iter.hasNext()) {
+ ESBService serv = iter.next();
+ if (serv.getName().endsWith("__0")) {
+ s1 = serv;
+ }
+ if (serv.getName().endsWith("__1")) {
+ s2 = serv;
+ }
+ }
+
+ WhileAction action=(WhileAction)service.getActions().get(0);
+
+ org.w3c.dom.NodeList paths=action.getPropertyChildNodes("paths");
+
+ if (paths.getLength() != 2) {
+ fail("Two path children expected: "+paths.getLength());
+ }
+
+ org.w3c.dom.Element elem=(org.w3c.dom.Element)paths.item(0);
+
+ if (elem.getNodeName().equals("while") == false) {
+ fail("while expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s1.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s1.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s1.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s1.getName());
+ }
+
+ // Check no message types
+ org.w3c.dom.NodeList mtypeNL=elem.getElementsByTagName("message");
+
+ if (mtypeNL.getLength() != 0) {
+ fail("Should have no message type: "+mtypeNL.getLength());
+ }
+
+ elem=(org.w3c.dom.Element)paths.item(1);
+
+ if (elem.getNodeName().equals("exit") == false) {
+ fail("exit expected but got: "+elem.getNodeName());
+ }
+
+ if (elem.getAttribute("service-category").equals(s2.getCategory()) == false) {
+ fail("Service category '"+elem.getAttribute("service-category")+
+ "' not expected: "+s2.getCategory());
+ }
+
+ if (elem.getAttribute("service-name").equals(s2.getName()) == false) {
+ fail("Service name '"+elem.getAttribute("service-name")+
+ "' not expected: "+s2.getName());
+ }
+ }
+}
More information about the overlord-commits
mailing list