[overlord-commits] Overlord SVN: r98 - in cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src: test/org/jboss/tools/overlord/jbossesb/model/actions and 1 other directory.

overlord-commits at lists.jboss.org overlord-commits at lists.jboss.org
Wed Jul 2 09:36:41 EDT 2008


Author: objectiser
Date: 2008-07-02 09:36:41 -0400 (Wed, 02 Jul 2008)
New Revision: 98

Added:
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterActionTest.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ParallelActionTest.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBLanguageModel.java
Modified:
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterAction.java
   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/test/org/jboss/tools/overlord/jbossesb/model/actions/ESBActionTestUtil.java
   cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java
Log:
Unit tests for message router and parallel - also validating the structure of the custom properties.

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterAction.java	2008-07-02 11:28:53 UTC (rev 97)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterAction.java	2008-07-02 13:36:41 UTC (rev 98)
@@ -62,28 +62,31 @@
 		
 		org.w3c.dom.NodeList nl=getPropertyChildNodes(PATHS);
 		
-		for (int i=0; i < nl.getLength(); i++) {
+		for (int i=0; nl != null && i < nl.getLength(); i++) {
 			
 			org.w3c.dom.Node n=nl.item(i);
 			
 			if (n instanceof org.w3c.dom.Element) {
 				if (n.getNodeName().equals(ROUTE)) {
-					String category=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
-					String name=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
-					String initiate=((org.w3c.dom.Element)n).getAttribute(INITIATE);
-
-					// Lookup service associated with category and name
-					ESBService service=getService().getModel().getService(category, name);
-				
-					// Initialize link, even if service is null - this will be
-					// reported as a validation error later
-					getLinks().add(new ESBLink(category, name, service, true));
+					if (((org.w3c.dom.Element)n).hasAttribute(SERVICE_CATEGORY) &&
+							((org.w3c.dom.Element)n).hasAttribute(SERVICE_NAME)) {
+						String category=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
+						String name=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
+						String initiate=((org.w3c.dom.Element)n).getAttribute(INITIATE);
+	
+						// Lookup service associated with category and name
+						ESBService service=getService().getModel().getService(category, name);
 					
-					if (service != null) {
-						if (initiate != null && initiate.equalsIgnoreCase("true")) {
-							m_initiateServices.add(service);
-						} else {
-							m_services.add(service);
+						// Initialize link, even if service is null - this will be
+						// reported as a validation error later
+						getLinks().add(new ESBLink(category, name, service, true));
+						
+						if (service != null) {
+							if (initiate != null && initiate.equalsIgnoreCase("true")) {
+								m_initiateServices.add(service);
+							} else {
+								m_services.add(service);
+							}
 						}
 					}
 				}
@@ -160,6 +163,43 @@
 									service.getName()}), null);
 			}
 		}
+		
+		org.w3c.dom.NodeList nl=getPropertyChildNodes(PATHS);
+		boolean f_serviceDetailsMissing=false;
+		int routeCount=0;
+		
+		for (int i=0; nl != null && i < nl.getLength(); i++) {
+			
+			org.w3c.dom.Node n=nl.item(i);
+			
+			if (n instanceof org.w3c.dom.Element) {
+				if (n.getNodeName().equals(ROUTE)) {
+					routeCount++;
+					
+					if (((org.w3c.dom.Element)n).hasAttribute(SERVICE_CATEGORY) == false ||
+							((org.w3c.dom.Element)n).hasAttribute(SERVICE_NAME) == false) {
+						f_serviceDetailsMissing = true;
+					}
+				}
+			}
+		}
+
+		// Report any errors
+		if (nl != null && routeCount < 1) {
+			l.error(this, org.scribble.util.MessageUtil.format(
+					java.util.PropertyResourceBundle.getBundle(
+					"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+						"_ROUTER_ONE_OR_MORE_PATHS",
+						new String[]{}), null);					
+		}
+		
+		if (f_serviceDetailsMissing) {
+			l.error(this, org.scribble.util.MessageUtil.format(
+					java.util.PropertyResourceBundle.getBundle(
+					"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+						"_PATH_SERVICE_DETAILS_MISSING",
+						new String[]{}), null);								
+		}
 	}
 
 	/**

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-07-02 11:28:53 UTC (rev 97)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties	2008-07-02 13:36:41 UTC (rev 98)
@@ -23,4 +23,9 @@
 _NOT_FOUND_PERFORM_CREATE_SESSION=Perform action can only invoke a service descriptor that starts with a CreateSessionAction
 _NOT_SPECIFIED_CONVERSATION_TYPE=Conversation type must be specified on root service descriptor
 _NOT_SPECIFIED_REQ_RESP_EPR=Send does not contain request service category/name or response client EPR
-_MUST_BE_FIRST_ACTION='{0}' action must be first in the service descriptor
\ No newline at end of file
+_MUST_BE_FIRST_ACTION='{0}' action must be first in the service descriptor
+_PARALLEL_MORE_THAN_TWO_PATHS=Parallel action must specify two or more paths
+_PARALLEL_MULTIPLE_JOINS=Parallel action has multiple joins
+_PARALLEL_PATH_AFTER_JOIN=Parallel path must not be defined after a join
+_PATH_SERVICE_DETAILS_MISSING=One or more paths are missing the service cateogry and/or name
+_ROUTER_ONE_OR_MORE_PATHS=MessageRouter action must specify one or more routes

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-07-02 11:28:53 UTC (rev 97)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/ParallelAction.java	2008-07-02 13:36:41 UTC (rev 98)
@@ -62,29 +62,35 @@
 			
 			if (n instanceof org.w3c.dom.Element) {
 				if (n.getNodeName().equals(PATH)) {
-					String category=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
-					String name=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
+					if (((org.w3c.dom.Element)n).hasAttribute(SERVICE_CATEGORY) &&
+							((org.w3c.dom.Element)n).hasAttribute(SERVICE_NAME)) {
+						String category=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
+						String name=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
 					
-					// Lookup service associated with category and name
-					ESBService service=getService().getModel().getService(category, name);
-					
-					// Initialize link, even if service is null - this will be
-					// reported as a validation error later
-					getLinks().add(new ESBLink(category, name, service, true));
-					
-					if (service != null) {
-						m_services.add(service);
+						// Lookup service associated with category and name
+						ESBService service=getService().getModel().getService(category, name);
+						
+						// Initialize link, even if service is null - this will be
+						// reported as a validation error later
+						getLinks().add(new ESBLink(category, name, service, true));
+						
+						if (service != null) {
+							m_services.add(service);
+						}
 					}
 				} else if (n.getNodeName().equals(JOIN)) {
-					m_joinCategory=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
-					m_joinName=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
+					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));
+						// 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));
+					}
 				}
 			}
 		}
@@ -101,6 +107,89 @@
 	}	
 
 	/**
+	 * This method validates the ESB action and reports warnings or
+	 * errors to the supplied model listener.
+	 * 
+	 * @param l The model listener
+	 */
+	@Override
+	public void validate(ModelListener l) {
+		super.validate(l);
+
+		org.w3c.dom.NodeList nl=getPropertyChildNodes(PATHS);
+		boolean f_joined=false;
+		int pathCount=0;
+		boolean f_pathAfterJoin=false;
+		boolean f_multipleJoins=false;
+		boolean f_serviceDetailsMissing=false;
+		
+		for (int i=0; nl != null && i < nl.getLength(); i++) {
+			
+			org.w3c.dom.Node n=nl.item(i);
+			
+			if (n instanceof org.w3c.dom.Element) {
+				if (n.getNodeName().equals(PATH)) {
+					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;
+					
+					if (((org.w3c.dom.Element)n).hasAttribute(SERVICE_CATEGORY) == false ||
+							((org.w3c.dom.Element)n).hasAttribute(SERVICE_NAME) == false) {
+						f_serviceDetailsMissing = true;
+					}
+				}
+			}
+		}
+		
+		// Report any errors
+		if (nl != null && pathCount < 2) {
+			l.error(this, org.scribble.util.MessageUtil.format(
+					java.util.PropertyResourceBundle.getBundle(
+					"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+						"_PARALLEL_MORE_THAN_TWO_PATHS",
+						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"),
+						"_PARALLEL_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"),
+						"_PARALLEL_MULTIPLE_JOINS",
+						new String[]{}), null);								
+		}
+		
+		if (f_serviceDetailsMissing) {
+			l.error(this, org.scribble.util.MessageUtil.format(
+					java.util.PropertyResourceBundle.getBundle(
+					"org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+						"_PATH_SERVICE_DETAILS_MISSING",
+						new String[]{}), null);								
+		}
+	}
+		
+	/**
 	 * This method converts the ESB action into an equivalent
 	 * behavioural description for conformance checking.
 	 * 

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ESBActionTestUtil.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ESBActionTestUtil.java	2008-07-02 11:28:53 UTC (rev 97)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ESBActionTestUtil.java	2008-07-02 13:36:41 UTC (rev 98)
@@ -17,11 +17,14 @@
  */
 package org.jboss.tools.overlord.jbossesb.model.actions;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
 public class ESBActionTestUtil {
 
 	public static org.w3c.dom.Element getAction(String actionClass,
 				java.util.Map<String,String> simpleProps,
-				java.util.Map<String,org.w3c.dom.Element> customProps) {
+				java.util.Map<String,String> customProps) {
 		
 		org.w3c.dom.Element ret=null;
 		
@@ -51,6 +54,45 @@
 						property.setAttribute("value", value);
 					}
 				}
+				
+				if (customProps != null) {
+					java.util.Iterator<String> props=customProps.keySet().iterator();
+					
+					while (props.hasNext()) {
+						String key=props.next();
+						String value=customProps.get(key);
+						
+						// Transform the text representation to DOM
+						DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
+						fact.setNamespaceAware(true);
+						
+						java.io.InputStream xmlstr=
+							new java.io.ByteArrayInputStream(value.getBytes());
+
+						DocumentBuilder builder=fact.newDocumentBuilder();
+						org.w3c.dom.Document valuedoc=builder.parse(xmlstr);
+						org.w3c.dom.Element valueroot=valuedoc.getDocumentElement();
+												
+						org.w3c.dom.NodeList nl=valueroot.getChildNodes();
+						
+						org.w3c.dom.Element property=ret.getOwnerDocument().createElement("property");
+						ret.appendChild(property);
+						
+						property.setAttribute("name", key);
+						
+						for (int i=0; i < nl.getLength(); i++) {
+							if (nl.item(i) instanceof org.w3c.dom.Element) {
+								org.w3c.dom.Node valueelem=
+									nl.item(i).cloneNode(true);
+								
+								doc.adoptNode(valueelem);
+								
+								property.appendChild(valueelem);								
+							}
+						}
+					}
+					
+				}
 			}
 		} catch(Exception e) {
 			e.printStackTrace();

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterActionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterActionTest.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/MessageRouterActionTest.java	2008-07-02 13:36:41 UTC (rev 98)
@@ -0,0 +1,247 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.tools.overlord.jbossesb.model.actions;
+
+import junit.framework.TestCase;
+
+public class MessageRouterActionTest extends TestCase {
+
+	public void testValidatePathsSpecified() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		
+		org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, props, null);
+		
+		MessageRouterAction action=new MessageRouterAction(service, elem);
+		
+		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.Messages"),
+							"_NOT_SPECIFIED_PROPERTY",
+							new String[]{"paths"}));
+		
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+
+	public void testValidateSessionBasedService() {
+		TestESBService service=new TestESBService();
+		service.setSessionBased(true);
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		props.put("paths", "<property><route service-category=\"cat1\" " +
+					"service-name=\"name1\" /></property>");
+		
+		org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+		
+		MessageRouterAction action=new MessageRouterAction(service, elem);
+		
+		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"),
+							"_CANNOT_SESSION_BASED_ACTIONS_WITH_ROUTER",
+							new String[]{}));
+		
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+
+	public void testValidateServiceNotFound() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		props.put("paths", "<property><route service-category=\"cat1\" " +
+				"service-name=\"name1\" /></property>");
+		
+		org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+		
+		TestESBLanguageModel model=new TestESBLanguageModel();
+		model.addService(service);
+		
+		service.setModel(model);
+		
+		MessageRouterAction action=new MessageRouterAction(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.Messages"),
+							"_NOT_FOUND_SERVICE_DESCRIPTOR",
+							new String[]{"cat1","name1"}));
+				
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+
+	public void testValidateInitiateServiceNotRoot() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		props.put("paths", "<property><route service-category=\"cat1\" " +
+				"service-name=\"name1\" initiate=\"true\" /></property>");
+		
+		org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+		
+		TestESBService other=new TestESBService();
+		other.setCategory("cat1");
+		other.setName("name1");
+		
+		TestESBLanguageModel model=new TestESBLanguageModel();
+		model.addService(other);
+		model.addService(service);
+		
+		service.setModel(model);
+		
+		MessageRouterAction action=new MessageRouterAction(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"),
+							"_CANNOT_INITIATE_NON_ROOT",
+							new String[]{other.getCategory(), 
+									other.getName()}));
+				
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+
+	public void testValidateNotInitiateRootService() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		props.put("paths", "<property><route service-category=\"cat1\" " +
+				"service-name=\"name1\" /></property>");
+		
+		org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+		
+		TestESBService other=new TestESBService();
+		other.setCategory("cat1");
+		other.setName("name1");
+		other.setRoot(true);
+		
+		TestESBLanguageModel model=new TestESBLanguageModel();
+		model.addService(other);
+		model.addService(service);
+		
+		service.setModel(model);
+		
+		MessageRouterAction action=new MessageRouterAction(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"),
+							"_MUST_INITIATE_ROOT",
+							new String[]{other.getCategory(), 
+									other.getName()}));
+				
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+	
+	public void testValidateNoRoutes() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		props.put("paths", "<property></property>");
+		
+		org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+		
+		MessageRouterAction action=new MessageRouterAction(service, elem);
+		
+		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"),
+							"_ROUTER_ONE_OR_MORE_PATHS",
+							new String[]{}));
+		
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+	
+	public void testValidateServiceDetailsMissing() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		props.put("paths", "<property><route service-category=\"cat1\" /></property>");
+		
+		org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+		
+		MessageRouterAction action=new MessageRouterAction(service, elem);
+		
+		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"),
+							"_PATH_SERVICE_DETAILS_MISSING",
+							new String[]{}));
+		
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+}

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ParallelActionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ParallelActionTest.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/ParallelActionTest.java	2008-07-02 13:36:41 UTC (rev 98)
@@ -0,0 +1,294 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.tools.overlord.jbossesb.model.actions;
+
+import junit.framework.TestCase;
+
+public class ParallelActionTest extends TestCase {
+
+	public void testValidatePathsSpecified() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		
+		org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, props, null);
+		
+		ParallelAction action=new ParallelAction(service, elem);
+		
+		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.Messages"),
+							"_NOT_SPECIFIED_PROPERTY",
+							new String[]{"paths"}));
+		
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+
+	public void testValidateServiceNotFound() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		props.put("paths", "<property><path service-category=\"cat1\" " +
+				"service-name=\"name1\" /><path service-category=\"cat2\" " +
+				"service-name=\"name2\" /><join service-category=\"cat3\" " +
+				"service-name=\"name3\" /></property>");
+		
+		org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+		
+		TestESBLanguageModel model=new TestESBLanguageModel();
+		model.addService(service);
+		
+		service.setModel(model);
+		
+		ParallelAction action=new ParallelAction(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.Messages"),
+					"_NOT_FOUND_SERVICE_DESCRIPTOR",
+					new String[]{"cat1","name1"}));
+		l.addExpectedError(org.scribble.util.MessageUtil.format(
+				java.util.PropertyResourceBundle.getBundle(
+				"org.jboss.tools.overlord.jbossesb.model.Messages"),
+					"_NOT_FOUND_SERVICE_DESCRIPTOR",
+					new String[]{"cat2","name2"}));
+		l.addExpectedError(org.scribble.util.MessageUtil.format(
+				java.util.PropertyResourceBundle.getBundle(
+				"org.jboss.tools.overlord.jbossesb.model.Messages"),
+					"_NOT_FOUND_SERVICE_DESCRIPTOR",
+					new String[]{"cat3","name3"}));
+				
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+
+	public void testValidateLessThanTwoPaths() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		props.put("paths", "<property><path service-category=\"cat1\" " +
+				"service-name=\"name1\" /><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("cat3");
+		other2.setName("name3");
+		
+		TestESBLanguageModel model=new TestESBLanguageModel();
+		model.addService(other1);
+		model.addService(other2);
+		model.addService(service);
+		
+		service.setModel(model);
+		
+		ParallelAction action=new ParallelAction(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"),
+							"_PARALLEL_MORE_THAN_TWO_PATHS",
+							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><path service-category=\"cat1\" " +
+				"service-name=\"name1\" /><path 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);
+		
+		ParallelAction action=new ParallelAction(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"),
+							"_PARALLEL_MULTIPLE_JOINS",
+							new String[]{}));
+				
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+	
+	public void testValidateOutOfOrderJoin() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		props.put("paths", "<property><path service-category=\"cat1\" " +
+				"service-name=\"name1\" /><join service-category=\"cat3\" " +
+				"service-name=\"name3\" /><path 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);
+		
+		ParallelAction action=new ParallelAction(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"),
+							"_PARALLEL_PATH_AFTER_JOIN",
+							new String[]{}));
+				
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+	
+	public void testValidateMissingServiceDetails() {
+		TestESBService service=new TestESBService();
+
+		java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+		props.put("paths", "<property><path service-category=\"cat1\" " +
+				"service-name=\"name1\" /><path " +
+				"service-name=\"name2\" /><join service-category=\"cat3\" " +
+				"service-name=\"name3\" /></property>");
+		
+		org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+		
+		TestESBService other1=new TestESBService();
+		other1.setCategory("cat1");
+		other1.setName("name1");
+		
+		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);
+		
+		ParallelAction action=new ParallelAction(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"),
+							"_PATH_SERVICE_DETAILS_MISSING",
+							new String[]{}));
+				
+		action.validate(l);
+		
+		if (l.isValid() == false) {
+			fail(l.invalidMessage());
+		}
+	}
+}

Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBLanguageModel.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBLanguageModel.java	                        (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBLanguageModel.java	2008-07-02 13:36:41 UTC (rev 98)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ */
+package org.jboss.tools.overlord.jbossesb.model.actions;
+
+import java.util.Collection;
+
+import org.jboss.tools.overlord.jbossesb.model.ESBService;
+import org.scribble.model.ModelListener;
+import org.scribble.model.ModelReference;
+
+public class TestESBLanguageModel implements org.jboss.tools.overlord.jbossesb.model.ESBLanguageModel {
+
+	public String getContents() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public ModelReference getModelReference() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public void addService(ESBService service) {
+		m_services.put(service.getCategory()+":"+service.getName(), service);
+	}
+	
+	public ESBService getService(String category, String name) {
+		return(m_services.get(category+":"+name));
+	}
+
+	public Collection<ESBService> getServices() {
+		return(m_services.values());
+	}
+
+	public void validate(ModelListener l) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	private java.util.Map<String,ESBService> m_services=new java.util.Hashtable<String,ESBService>();
+}

Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java	2008-07-02 11:28:53 UTC (rev 97)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/TestESBService.java	2008-07-02 13:36:41 UTC (rev 98)
@@ -37,9 +37,12 @@
 		return(m_actions);
 	}
 
+	public void setCategory(String cat) {
+		m_category = cat;
+	}
+	
 	public String getCategory() {
-		// TODO Auto-generated method stub
-		return null;
+		return(m_category);
 	}
 
 	public String getConversationType() {
@@ -47,10 +50,17 @@
 		return null;
 	}
 
+	public void setName(String name) {
+		m_name = name;
+	}
+	
 	public String getName() {
-		// TODO Auto-generated method stub
-		return null;
+		return(m_name);
 	}
+	
+	public void setModel(ESBLanguageModel model) {
+		m_model = model;
+	}
 
 	public ESBLanguageModel getModel() {
 		return(m_model);
@@ -107,9 +117,12 @@
 		return(m_root);
 	}
 
+	public void setSessionBased(boolean bool) {
+		m_sessionBased = bool;
+	}
+	
 	public boolean isSessionBased() {
-		// TODO Auto-generated method stub
-		return false;
+		return(m_sessionBased);
 	}
 
 	public void validate(ModelListener l) {
@@ -117,8 +130,11 @@
 		
 	}
 
+	private String m_category=null;
+	private String m_name=null;
 	private ESBLanguageModel m_model=null;
 	private List<ESBAction> m_actions=new java.util.Vector<ESBAction>();
 	private boolean m_root=false;
+	private boolean m_sessionBased=false;
 	private Class<?> m_sessionClass=null;
 }




More information about the overlord-commits mailing list