[overlord-commits] Overlord SVN: r220 - 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
Wed Aug 6 11:56:30 EDT 2008
Author: objectiser
Date: 2008-08-06 11:56:29 -0400 (Wed, 06 Aug 2008)
New Revision: 220
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/RunModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/RunModelChangeRuleTest.java
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/PerformAction.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationModelChangeRule.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/util/ConversationUtil.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/util/InteractionUtil.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/ConversationInteractionModelChangeRuleTest.java
Log:
Add test for run/perform.
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/PerformAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/PerformAction.java 2008-08-06 13:32:47 UTC (rev 219)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/PerformAction.java 2008-08-06 15:56:29 UTC (rev 220)
@@ -47,6 +47,18 @@
}
/**
+ * This constructor initializes the DOM element for
+ * the action.
+ *
+ * @param service The reference to the service in which
+ * the action will be contained
+ */
+ public PerformAction(ESBService service) {
+ super(service, ESBActionFactory.getConversationAction(
+ PerformAction.class));
+ }
+
+ /**
* This method initializes the links with the ESB service descriptors
* identified in each path of the action.
*/
@@ -167,6 +179,48 @@
}
}
+ /**
+ * This method sets the destination service descriptor properties.
+ *
+ * @param category The category
+ * @param name The name
+ */
+ public void setDestination(String category, String name) {
+
+ org.w3c.dom.Element prop=getPropertyElement(SERVICE_CATEGORY);
+
+ if (prop != null) {
+ prop.setAttribute(VALUE_ATTR, category);
+ }
+
+ prop = getPropertyElement(SERVICE_NAME);
+
+ if (prop != null) {
+ prop.setAttribute(VALUE_ATTR, name);
+ }
+ }
+
+ /**
+ * This method sets the return destination service descriptor properties.
+ *
+ * @param category The category
+ * @param name The name
+ */
+ public void setReturnDestination(String category, String name) {
+
+ org.w3c.dom.Element prop=getPropertyElement(RETURN_SERVICE_CATEGORY);
+
+ if (prop != null) {
+ prop.setAttribute(VALUE_ATTR, category);
+ }
+
+ prop = getPropertyElement(RETURN_SERVICE_NAME);
+
+ if (prop != null) {
+ prop.setAttribute(VALUE_ATTR, name);
+ }
+ }
+
private String m_category=null;
private String m_name=null;
private ESBService m_service=null;
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationModelChangeRule.java 2008-08-06 13:32:47 UTC (rev 219)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/ConversationModelChangeRule.java 2008-08-06 15:56:29 UTC (rev 220)
@@ -79,24 +79,10 @@
String namespace=((Model)conv.getModel()).
getNamespace().getName();
- String qualifier="";
- Definition defn=conv;
+ String category=ConversationUtil.getServiceCategory(conv);
- // Create a hierarchical name related to the conversation
- while (defn != null) {
- qualifier = "."+defn.getModelName().getName();
-
- if (defn.getParent() instanceof Definition) {
- defn = (Definition)defn.getParent();
- } else {
- defn = null;
- }
- }
-
- String category = namespace + qualifier;
-
- String name=conv.getModelName().getLocatedRole().getName();
+ String name=ConversationUtil.getServiceName(conv);
String sdname="";
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/RunModelChangeRule.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/RunModelChangeRule.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/change/RunModelChangeRule.java 2008-08-06 15:56:29 UTC (rev 220)
@@ -0,0 +1,109 @@
+/*
+ * 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 Run composition construct.
+ */
+ at RegistryInfo(extension=ModelChangeRule.class,notation=ESBLanguageModel.JBOSSESB_NOTATION)
+public class RunModelChangeRule 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 Run &&
+ 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();
+ Run run=(Run)mobj;
+
+ PerformAction action=new PerformAction(service);
+
+ service.addAction(action, position);
+
+ String category=ConversationUtil.getServiceCategory(run.getDefinition());
+ String name=ConversationUtil.getServiceName(run.getDefinition());
+
+ action.setDestination(category, name);
+
+ // Create return service
+ ESBService returnService=
+ esbModel.createService(service.getCategory(),
+ esbModel.getUniqueServiceName(service.getCategory(),
+ service.getName()));
+
+ esbModel.addService(returnService);
+
+ context.setParent(returnService);
+
+ action.setReturnDestination(returnService.getCategory(),
+ returnService.getName());
+
+ 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/java/org/jboss/tools/overlord/jbossesb/model/util/ConversationUtil.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/util/ConversationUtil.java 2008-08-06 13:32:47 UTC (rev 219)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/util/ConversationUtil.java 2008-08-06 15:56:29 UTC (rev 220)
@@ -18,6 +18,8 @@
package org.jboss.tools.overlord.jbossesb.model.util;
import org.scribble.conversation.model.*;
+import org.scribble.model.Definition;
+import org.scribble.model.Model;
/**
* This class contains utility functions related to the
@@ -78,4 +80,58 @@
return(ret);
}
+
+ /**
+ * This method returns the business object type accessor method
+ * for the variable's name.
+ *
+ * @param name The variable name
+ * @return The accessor method
+ */
+ public static String getVariableAccessorMethod(String name) {
+ String ret="get"+Character.toUpperCase(name.charAt(0))+name.substring(1);
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the business object type modifier method
+ * for the variable's name.
+ *
+ * @param name The variable name
+ * @return The modifier method
+ */
+ public static String getVariableModifierMethod(String name) {
+ String ret="set"+Character.toUpperCase(name.charAt(0))+name.substring(1);
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the service category associated with
+ * the supplied conversation.
+ *
+ * @param conv The conversation
+ * @return The service category
+ */
+ public static String getServiceCategory(Conversation conv) {
+ String ret=((Model)conv.getModel()).
+ getNamespace().getName();
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the service name associated with
+ * the supplied conversation.
+ *
+ * @param conv The conversation
+ * @return The service name
+ */
+ public static String getServiceName(Conversation conv) {
+ String ret=conv.getModelName().getName()+"_"+
+ conv.getModelName().getLocatedRole().getName();
+
+ return(ret);
+ }
}
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/util/InteractionUtil.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/util/InteractionUtil.java 2008-08-06 13:32:47 UTC (rev 219)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/util/InteractionUtil.java 2008-08-06 15:56:29 UTC (rev 220)
@@ -109,7 +109,7 @@
* for the role's service category.
*
* @param roleName The role
- * @return The service category property
+ * @return The service category accessor method
*/
public static String getRoleServiceCategoryAccessorMethod(String roleName) {
String ret=roleName+SERVICE_CATEGORY_ACCESSOR_SUFFIX;
@@ -124,7 +124,7 @@
* for the role's service name.
*
* @param roleName The role
- * @return The service name property
+ * @return The service name accessor method
*/
public static String getRoleServiceNameAccessorMethod(String roleName) {
String ret=roleName+SERVICE_NAME_ACCESSOR_SUFFIX;
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/ConversationInteractionModelChangeRuleTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/ConversationInteractionModelChangeRuleTest.java 2008-08-06 13:32:47 UTC (rev 219)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/ConversationInteractionModelChangeRuleTest.java 2008-08-06 15:56:29 UTC (rev 220)
@@ -339,7 +339,6 @@
model.addService(service);
-
TestModelChangeContext context=new TestModelChangeContext();
context.setParent(service);
@@ -472,7 +471,7 @@
action.getPropertyValue(
SendMessageAction.RESPONSE_SERVICE_CATEGORY)+
"' invalid, expecting: "+
- service.getCategory());
+ newService.getCategory());
}
if (newService.getName().equals(action.getPropertyValue(
@@ -481,7 +480,7 @@
action.getPropertyValue(
SendMessageAction.RESPONSE_SERVICE_NAME)+
"' invalid, expecting: "+
- service.getName());
+ newService.getName());
}
}
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/RunModelChangeRuleTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/RunModelChangeRuleTest.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/change/RunModelChangeRuleTest.java 2008-08-06 15:56:29 UTC (rev 220)
@@ -0,0 +1,147 @@
+/*
+ * 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.jboss.tools.overlord.jbossesb.model.util.ConversationUtil;
+import org.jboss.tools.overlord.jbossesb.model.util.InteractionUtil;
+import org.scribble.model.*;
+import org.scribble.model.change.*;
+import org.scribble.conversation.model.*;
+
+public class RunModelChangeRuleTest extends TestCase {
+
+ public void testInsertPerformAction() {
+ String runName="subconv";
+
+ RunModelChangeRule rule=new RunModelChangeRule();
+
+ 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);
+
+ ConversationModel cm=new ConversationModel();
+
+ Namespace ns=new Namespace();
+ cm.setNamespace(ns);
+ ns.setName("ns");
+
+ Conversation conv=new Conversation();
+ ModelName mname=new ModelName();
+ mname.setLocatedRole(role);
+ conv.setModelName(mname);
+
+ cm.setConversation(conv);
+
+ Conversation subconv=new Conversation();
+ ModelName submname=new ModelName();
+ submname.setName(runName);
+ submname.setLocatedRole(role);
+ subconv.setModelName(mname);
+
+ Run mobj=new Run();
+ mobj.setInlineDefinition(subconv);
+
+ conv.getBlock().getContents().add(mobj);
+
+
+ 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 PerformAction) == false) {
+ fail("Action was not PerformAction: "+service.getActions().get(0));
+ }
+
+ if (model.getServices().size() != 2) {
+ fail("Two services expected: "+model.getServices().size());
+ }
+
+ PerformAction action=(PerformAction)service.getActions().get(0);
+
+ ESBService newService=null;
+ java.util.Iterator<ESBService> iter=model.getServices().iterator();
+ while (newService == null && iter.hasNext()) {
+ ESBService s=iter.next();
+
+ if (s != service) {
+ newService = s;
+ }
+ }
+
+ if (newService == null) {
+ fail("Other service not found");
+ }
+
+ // Check details
+ if (ConversationUtil.getServiceCategory(mobj.getDefinition()).equals(action.getPropertyValue(
+ PerformAction.SERVICE_CATEGORY)) == false) {
+ fail("Perform service category '"+
+ action.getPropertyValue(
+ PerformAction.SERVICE_CATEGORY)+
+ "' invalid, expecting: "+
+ ConversationUtil.getServiceCategory(mobj.getDefinition()));
+ }
+
+ if (ConversationUtil.getServiceName(mobj.getDefinition()).equals(action.getPropertyValue(
+ PerformAction.SERVICE_NAME)) == false) {
+ fail("Perform service name '"+
+ action.getPropertyValue(
+ PerformAction.SERVICE_NAME)+
+ "' invalid, expecting: "+
+ ConversationUtil.getServiceName(mobj.getDefinition()));
+ }
+ if (newService.getCategory().equals(action.getPropertyValue(
+ PerformAction.RETURN_SERVICE_CATEGORY)) == false) {
+ fail("Perform return service category '"+
+ action.getPropertyValue(
+ PerformAction.RETURN_SERVICE_CATEGORY)+
+ "' invalid, expecting: "+
+ newService.getCategory());
+ }
+
+ if (newService.getName().equals(action.getPropertyValue(
+ PerformAction.RETURN_SERVICE_NAME)) == false) {
+ fail("Perform return service name '"+
+ action.getPropertyValue(
+ PerformAction.RETURN_SERVICE_NAME)+
+ "' invalid, expecting: "+
+ newService.getName());
+ }
+ }
+}
More information about the overlord-commits
mailing list