[overlord-commits] Overlord SVN: r99 - 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 10:16:46 EDT 2008
Author: objectiser
Date: 2008-07-02 10:16:46 -0400 (Wed, 02 Jul 2008)
New Revision: 99
Added:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/IfActionTest.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/SwitchActionTest.java
Modified:
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/IfAction.java
cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties
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/SwitchAction.java
Log:
Unit tests for IfAction and SwitchAction.
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/IfAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/IfAction.java 2008-07-02 13:36:41 UTC (rev 98)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/IfAction.java 2008-07-02 14:16:46 UTC (rev 99)
@@ -65,15 +65,18 @@
(n.getNodeName().equals(IF) ||
n.getNodeName().equals(ELSEIF) ||
n.getNodeName().equals(ELSE))) {
- String category=((org.w3c.dom.Element)n).getAttribute(SERVICE_CATEGORY);
- String name=((org.w3c.dom.Element)n).getAttribute(SERVICE_NAME);
-
- // 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);
+
+ // 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));
+ }
}
}
}
@@ -98,9 +101,70 @@
public void validate(ModelListener l) {
super.validate(l);
- // TODO: Validate if/elseif/else order, if decision-method
- // specified, that method exists, if expression, then
- // validate the expression etc.
+ org.w3c.dom.NodeList nl=getPropertyChildNodes(PATHS);
+ boolean f_if=false;
+ boolean f_else=false;
+ boolean f_orderWrong=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(IF)) {
+ if (f_if) {
+ f_orderWrong = true;
+ }
+
+ f_if = 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(ELSEIF)) {
+
+ if (f_if == false || f_else) {
+ f_orderWrong = 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(ELSE)) {
+
+ if (f_if == false || f_else) {
+ f_orderWrong = true;
+ }
+
+ f_else = 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_if == false || f_orderWrong)) {
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+ "_IF_ORDER_WRONG",
+ 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 13:36:41 UTC (rev 98)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/Messages.properties 2008-07-02 14:16:46 UTC (rev 99)
@@ -18,6 +18,7 @@
_CANNOT_INITIATE_NON_ROOT=Cannot 'initiate' non-root service descriptor for category '{0}' and name '{1}'
_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
_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
@@ -29,3 +30,4 @@
_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
+_SWITCH_ONE_OR_MORE_PATHS=Switch action must specify one or more cases
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-07-02 13:36:41 UTC (rev 98)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/PerformAction.java 2008-07-02 14:16:46 UTC (rev 99)
@@ -56,9 +56,11 @@
m_category=getPropertyValue(SERVICE_CATEGORY);
m_name=getPropertyValue(SERVICE_NAME);
- m_service=getService().getModel().getService(m_category, m_name);
+ if (m_category != null && m_name != null) {
+ m_service=getService().getModel().getService(m_category, m_name);
- getLinks().add(new ESBLink(m_category, m_name, m_service, true));
+ getLinks().add(new ESBLink(m_category, m_name, m_service, true));
+ }
m_joinCategory=getPropertyValue(JOIN_SERVICE_CATEGORY);
m_joinName=getPropertyValue(JOIN_SERVICE_NAME);
Modified: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/SwitchAction.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/SwitchAction.java 2008-07-02 13:36:41 UTC (rev 98)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/java/org/jboss/tools/overlord/jbossesb/model/actions/SwitchAction.java 2008-07-02 14:16:46 UTC (rev 99)
@@ -61,15 +61,18 @@
if (n instanceof org.w3c.dom.Element &&
n.getNodeName().equals(CASE)) {
- 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 (((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));
+ }
}
}
}
@@ -85,6 +88,54 @@
}
/**
+ * 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);
+ int pathCount=0;
+ 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(CASE)) {
+ pathCount++;
+
+ 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 < 1) {
+ l.error(this, org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+ "_SWITCH_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);
+ }
+ }
+
+ /**
* This method converts the ESB action into an equivalent
* behavioural description for conformance checking.
*
Added: cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/IfActionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/IfActionTest.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/IfActionTest.java 2008-07-02 14:16:46 UTC (rev 99)
@@ -0,0 +1,292 @@
+/*
+ * 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 IfActionTest 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);
+
+ IfAction action=new IfAction(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><if service-category=\"cat1\" " +
+ "service-name=\"name1\" /><elseif service-category=\"cat2\" " +
+ "service-name=\"name2\" /><else service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(service);
+
+ service.setModel(model);
+
+ IfAction action=new IfAction(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 testValidateNoPathsContent() {
+ 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);
+
+ 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);
+
+ IfAction action=new IfAction(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"),
+ "_IF_ORDER_WRONG",
+ new String[]{}));
+
+ action.validate(l);
+
+ if (l.isValid() == false) {
+ fail(l.invalidMessage());
+ }
+ }
+
+ public void testValidateOnlyOneIf() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><if service-category=\"cat1\" " +
+ "service-name=\"name1\" /><elseif service-category=\"cat2\" " +
+ "service-name=\"name2\" /><if service-category=\"cat3\" " +
+ "service-name=\"name3\" /><else service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestESBService other3=new TestESBService();
+ other3.setCategory("cat3");
+ other3.setName("name3");
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(other3);
+ model.addService(service);
+
+ service.setModel(model);
+
+ IfAction action=new IfAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ TestModelListener l=new TestModelListener();
+
+ l.addExpectedError(org.scribble.util.MessageUtil.format(
+ java.util.PropertyResourceBundle.getBundle(
+ "org.jboss.tools.overlord.jbossesb.model.actions.Messages"),
+ "_IF_ORDER_WRONG",
+ new String[]{}));
+
+ action.validate(l);
+
+ if (l.isValid() == false) {
+ fail(l.invalidMessage());
+ }
+ }
+
+ public void testValidateOutOfOrderElse() {
+ TestESBService service=new TestESBService();
+
+ java.util.Map<String,String> props=new java.util.Hashtable<String,String>();
+ props.put("paths", "<property><if service-category=\"cat1\" " +
+ "service-name=\"name1\" /><else service-category=\"cat3\" " +
+ "service-name=\"name3\" /><elseif 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);
+
+ IfAction action=new IfAction(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"),
+ "_IF_ORDER_WRONG",
+ 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><if service-category=\"cat1\" " +
+ "service-name=\"name1\" /><elseif " +
+ "service-name=\"name2\" /><else service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ TestESBService other2=new TestESBService();
+ other2.setCategory("cat2");
+ other2.setName("name2");
+
+ TestESBService other3=new TestESBService();
+ other3.setCategory("cat3");
+ other3.setName("name3");
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(other1);
+ model.addService(other2);
+ model.addService(other3);
+ model.addService(service);
+
+ service.setModel(model);
+
+ IfAction action=new IfAction(service, elem);
+ action.initializeLinks();
+
+ service.getActions().add(action);
+
+ 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/SwitchActionTest.java
===================================================================
--- cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/SwitchActionTest.java (rev 0)
+++ cdl/trunk/tools/plugins/org.jboss.tools.overlord.jbossesb/src/test/org/jboss/tools/overlord/jbossesb/model/actions/SwitchActionTest.java 2008-07-02 14:16:46 UTC (rev 99)
@@ -0,0 +1,189 @@
+/*
+ * 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 SwitchActionTest 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);
+
+ SwitchAction action=new SwitchAction(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><case service-category=\"cat1\" " +
+ "service-name=\"name1\" /><case service-category=\"cat2\" " +
+ "service-name=\"name2\" /><case service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBLanguageModel model=new TestESBLanguageModel();
+ model.addService(service);
+
+ service.setModel(model);
+
+ SwitchAction action=new SwitchAction(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 testValidateLessThanOnePath() {
+ 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);
+
+ 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);
+
+ SwitchAction action=new SwitchAction(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"),
+ "_SWITCH_ONE_OR_MORE_PATHS",
+ 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><case service-category=\"cat1\" " +
+ "service-name=\"name1\" /><case " +
+ "service-name=\"name2\" /><case service-category=\"cat3\" " +
+ "service-name=\"name3\" /></property>");
+
+ org.w3c.dom.Element elem=ESBActionTestUtil.getAction(null, null, props);
+
+ TestESBService other1=new TestESBService();
+ other1.setCategory("cat1");
+ other1.setName("name1");
+
+ 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);
+
+ SwitchAction action=new SwitchAction(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());
+ }
+ }
+}
More information about the overlord-commits
mailing list