[overlord-commits] Overlord SVN: r101 - 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 11:29:46 EDT 2008
Author: objectiser
Date: 2008-07-02 11:29:45 -0400 (Wed, 02 Jul 2008)
New Revision: 101
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhileActionTest.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/WhenAction.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhileAction.java
Log:
Unit tests for validating WhileAction.
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 14:49:42 UTC (rev 100)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties 2008-07-02 15:29:45 UTC (rev 101)
@@ -20,6 +20,8 @@
_CANNOT_SESSION_BASED_ACTIONS_WITH_ROUTER=Cannot define MessageRouterAction with session based actions in service descriptor
_IF_ORDER_WRONG=IfAction must have an 'if' path, followed by zero or more 'elseif' paths and ending with an optional 'else' path
_MULTIPLE_JOINS=Action has multiple joins
+_MUST_DEFINE_SINGLE_WHILE_PATH=While action must have a single 'while' path
+_MUST_DEFINE_SINGLE_WHILE_EXIT=While action must have a single 'exit' path
_MUST_INITIATE_ROOT=Must 'initiate' root service descriptor for category '{0}' and name '{1}'
_NOT_FOUND_VARIABLE=Variable '{0}' could not be found on session type '{1}'
_NOT_FOUND_PERFORM_CREATE_SESSION=Perform action can only invoke a service descriptor that starts with a CreateSessionAction
@@ -33,3 +35,4 @@
_SWITCH_ONE_OR_MORE_PATHS=Switch action must specify atleast one case
_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/WhenAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhenAction.java 2008-07-02 14:49:42 UTC (rev 100)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhenAction.java 2008-07-02 15:29:45 UTC (rev 101)
@@ -117,6 +117,10 @@
public void validate(ModelListener l) {
super.validate(l);
+ // TODO: Valid if decision-method
+ // specified, that method exists, if expression, then
+ // validate the expression etc.
+
org.w3c.dom.NodeList nl=getPropertyChildNodes(PATHS);
int pathCount=0;
boolean f_joined=false;
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-07-02 14:49:42 UTC (rev 100)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/WhileAction.java 2008-07-02 15:29:45 UTC (rev 101)
@@ -63,31 +63,37 @@
if (n instanceof org.w3c.dom.Element) {
if (n.getNodeName().equals(WHILE)) {
- m_loopCategory=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
- m_loopName=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
-
- // Lookup service associated with category and name
- m_loopService=getService().getModel().getService(m_loopCategory, m_loopName);
-
- String immediate=((org.w3c.dom.Element)n).getAttribute(IMMEDIATE);
+ if (((org.w3c.dom.Element)n).hasAttribute(SERVICE_CATEGORY) &&
+ ((org.w3c.dom.Element)n).hasAttribute(SERVICE_NAME)) {
+ m_loopCategory=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
+ m_loopName=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
+
+ // Lookup service associated with category and name
+ m_loopService=getService().getModel().getService(m_loopCategory, m_loopName);
- // Initialize link, even if service is null - this will be
- // reported as a validation error later
- getLinks().add(new ESBLink(m_loopCategory, m_loopName, m_loopService,
- (immediate != null && immediate.equalsIgnoreCase("true"))));
+ String immediate=((org.w3c.dom.Element)n).getAttribute(IMMEDIATE);
+
+ // Initialize link, even if service is null - this will be
+ // reported as a validation error later
+ getLinks().add(new ESBLink(m_loopCategory, m_loopName, m_loopService,
+ (immediate != null && immediate.equalsIgnoreCase("true"))));
+ }
} else if (n.getNodeName().equals(EXIT)) {
- m_exitCategory=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
- m_exitName=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
-
- // Lookup service associated with category and name
- m_exitService=getService().getModel().getService(m_exitCategory, m_exitName);
-
- String immediate=((org.w3c.dom.Element)n).getAttribute(IMMEDIATE);
+ if (((org.w3c.dom.Element)n).hasAttribute(SERVICE_CATEGORY) &&
+ ((org.w3c.dom.Element)n).hasAttribute(SERVICE_NAME)) {
+ m_exitCategory=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
+ m_exitName=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
+
+ // Lookup service associated with category and name
+ m_exitService=getService().getModel().getService(m_exitCategory, m_exitName);
- // Initialize link, even if service is null - this will be
- // reported as a validation error later
- getLinks().add(new ESBLink(m_exitCategory, m_exitName, m_exitService,
- (immediate != null && immediate.equalsIgnoreCase("true"))));
+ String immediate=((org.w3c.dom.Element)n).getAttribute(IMMEDIATE);
+
+ // Initialize link, even if service is null - this will be
+ // reported as a validation error later
+ getLinks().add(new ESBLink(m_exitCategory, m_exitName, m_exitService,
+ (immediate != null && immediate.equalsIgnoreCase("true"))));
+ }
}
}
}
@@ -144,6 +150,83 @@
// TODO: Validate that the loop service returns back to the
// while action for all paths
+ org.w3c.dom.NodeList nl=getPropertyChildNodes(PATHS);
+ boolean f_while=false;
+ boolean f_exit=false;
+ boolean f_multipleWhiles=false;
+ boolean f_multipleExits=false;
+ boolean f_serviceDetailsMissing=false;
+ boolean f_pathAfterExit=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(WHILE)) {
+
+ if (f_while) {
+ f_multipleWhiles = true;
+ }
+
+ if (f_exit) {
+ f_pathAfterExit = true;
+ }
+
+ f_while = 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(EXIT)) {
+
+ if (f_exit) {
+ f_multipleExits = true;
+ }
+
+ f_exit = 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 && (f_while == false || f_multipleWhiles)) {
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+ "_MUST_DEFINE_SINGLE_WHILE_PATH",
+ new String[]{}), null);
+ }
+
+ if (nl != null && (f_exit == false || f_multipleExits)) {
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+ "_MUST_DEFINE_SINGLE_WHILE_EXIT",
+ new String[]{}), null);
+ }
+
+ if (f_pathAfterExit) {
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+ "_WHILE_PATH_AFTER_EXIT",
+ 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);
+ }
}
/**
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhileActionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhileActionTest.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/WhileActionTest.java 2008-07-02 15:29:45 UTC (rev 101)
@@ -0,0 +1,327 @@
+/*
+ * 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 WhileActionTest 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);
+
+ WhileAction action=new WhileAction(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><while service-category=\"cat1\" " +
+ "service-name=\"name1\" /><exit service-category=\"cat2\" " +
+ "service-name=\"name2\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(service);
+
+ service.setModel(model);
+
+ WhileAction action=new WhileAction(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"}));
+
+ action.validate(l);
+
+ if (l.isValid() == false) {
+ fail(l.invalidMessage());
+ }
+ }
+
+ public void testValidateOneWhilePath() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><while service-category=\"cat1\" " +
+ "service-name=\"name1\" /></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);
+
+ WhileAction action=new WhileAction(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_DEFINE_SINGLE_WHILE_EXIT",
+ new String[]{}));
+
+ action.validate(l);
+
+ if (l.isValid() == false) {
+ fail(l.invalidMessage());
+ }
+ }
+
+ public void testValidateOneWhileExit() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><exit service-category=\"cat2\" " +
+ "service-name=\"name2\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(service);
+
+ service.setModel(model);
+
+ WhileAction action=new WhileAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ TestModelListener l=new TestModelListener();
+
+ l.addExpectedError(org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+ "_MUST_DEFINE_SINGLE_WHILE_PATH",
+ new String[]{}));
+
+ action.validate(l);
+
+ if (l.isValid() == false) {
+ fail(l.invalidMessage());
+ }
+ }
+
+ public void testValidateMissingServiceDetails1() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><while " +
+ "service-name=\"name2\" /><exit 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);
+
+ WhileAction action=new WhileAction(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());
+ }
+ }
+
+ public void testValidateMissingServiceDetails2() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><while service-category=\"cat2\" " +
+ "service-name=\"name2\" /><exit " +
+ "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);
+
+ WhileAction action=new WhileAction(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());
+ }
+ }
+
+ public void testValidateOutOfOrderExit() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><exit service-category=\"cat1\" " +
+ "service-name=\"name1\" /><while 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);
+
+ WhileAction action=new WhileAction(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"),
+ "_WHILE_PATH_AFTER_EXIT",
+ new String[]{}));
+
+ action.validate(l);
+
+ if (l.isValid() == false) {
+ fail(l.invalidMessage());
+ }
+ }
+}
More information about the overlord-commits
mailing list