[jboss-svn-commits] JBL Code SVN: r10416 - in labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util: jbpm and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Mar 21 18:04:47 EDT 2007


Author: estebanschifman
Date: 2007-03-21 18:04:47 -0400 (Wed, 21 Mar 2007)
New Revision: 10416

Added:
   labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/AbstractCommandVehicleUnitTest.java
   labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/jbpm/
   labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/jbpm/CommandVehicleUnitTest.java
Log:
Unit tests for Command vehicles (Abstract and jBPM)

Added: labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/AbstractCommandVehicleUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/AbstractCommandVehicleUnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/AbstractCommandVehicleUnitTest.java	2007-03-21 22:04:47 UTC (rev 10416)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.util;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * AbstractCommandVehicle unit tests.
+ * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
+ */
+public class AbstractCommandVehicleUnitTest extends TestCase {
+	
+	static class MyVehicle extends AbstractCommandVehicle
+	{
+		private static final long serialVersionUID = 1L;
+		@Override
+		public String getCommandOpcodeKey() { return "myCmdOpcodeKey"; }
+		@Override
+		public String getCommandValuesTag() { return "CMD_VALUES_TAG"; }
+		@Override
+		public Operation operatorFromString(String value) {return Operation.valueOf(value); }
+		
+		public static final String VAL1 = "value1_tag";
+
+		public enum Operation
+		{
+			oper1
+			,oper2
+		}
+
+		public MyVehicle(Enum command) 		{ super(command); }
+		public MyVehicle(Message message)	{ super(message); }
+
+		public void 	setVal1(String obj)	{ super.setValue(VAL1, obj); }
+		public String	getVal1()			{ return (String)_values.get(VAL1); }
+	}
+
+	public void test_01() 
+	{
+		String compareValue = "12345";
+		
+		MyVehicle vh1 = new MyVehicle(MyVehicle.Operation.oper1);
+		vh1.setVal1(compareValue);
+		Message msg = vh1.toCommandMessage();
+		
+		MyVehicle newVh = new MyVehicle(msg);
+		assertEquals(MyVehicle.Operation.oper1, newVh.getOperator());
+		assertEquals(compareValue, newVh.getVal1());
+	}
+	
+	public void test_02() 
+	{
+		String compareValue = "ZZZZZZZZZZZZZZ";
+		
+		MyVehicle vh1 = new MyVehicle(MyVehicle.Operation.oper2);
+		vh1.setVal1(compareValue);
+		Message msg = vh1.toCommandMessage();
+		
+		MyVehicle newVh = new MyVehicle(msg);
+		assertEquals(MyVehicle.Operation.oper2, newVh.getOperator());
+		assertEquals(compareValue, newVh.getVal1());
+	}
+	
+}


Property changes on: labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/AbstractCommandVehicleUnitTest.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/jbpm/CommandVehicleUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/jbpm/CommandVehicleUnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/jbpm/CommandVehicleUnitTest.java	2007-03-21 22:04:47 UTC (rev 10416)
@@ -0,0 +1,153 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.util.jbpm;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.message.Message;
+import org.jbpm.graph.def.ProcessDefinition;
+
+/**
+ * jBPM CommandVehicle unit tests.
+ * @author <a href="mailto:schifest at heuristica.com.ar">Esteban</a>
+ */
+public class CommandVehicleUnitTest extends TestCase {
+	
+	static Logger _logger = Logger.getLogger(CommandVehicleUnitTest.class);
+
+	public void test_badProcessDefinition() 
+	{
+		CommandVehicle.Operation oper = CommandVehicle.Operation.deployProcessDefinition;
+		CommandVehicle vhc = new CommandVehicle(oper);
+		try
+		{
+			_logger.info("An exception is supposed to be thrown");
+			vhc.setProcessDefinition("This is invalid");
+		}
+		catch (Exception e)
+		{
+			// OK - it's supposed to fail
+			return;
+		}
+		fail("It's not supposed to fall through");
+	}
+	
+	public void test_goodProcessDefinition() 
+	{
+		CommandVehicle.Operation oper = CommandVehicle.Operation.deployProcessDefinition;
+		CommandVehicle vhc = new CommandVehicle(oper);
+		vhc.setProcessDefinition(getGoodProcessDefinition());
+	}
+
+	public void test_toMsgAndBack()
+	{
+		CommandVehicle.Operation oper = CommandVehicle.Operation.getTokenVariables;
+		CommandVehicle vhc = new CommandVehicle(oper);
+
+		Object returnCode	= new Long(4848433);
+		vhc.setReturnCode		(returnCode);
+
+		ProcessDefinition processDef = ProcessDefinition.parseXmlString(getGoodProcessDefinition());
+		vhc.setProcessDefinition(processDef);
+
+		vhc.setProcessDefinitionName("foo");
+		vhc.setProcessVersion	(99);
+		vhc.setInstanceId		(88);
+		vhc.setTokenId			(77);
+		vhc.setTransitionName	("pirulo");
+		vhc.setCurrentNodeName	("FooNode");
+
+		Set<String> names = new HashSet<String>();
+		names.addAll(Arrays.asList(new String[] {"var1","var3","var5"}));
+		vhc.setVariableNames(names);
+
+		Map<String,Object> varValues = new HashMap<String, Object>();
+		varValues.put("key1", "VVV111");
+		varValues.put("key222",new Long(446699));
+		vhc.setVariableValues(varValues);
+		
+		vhc.setUserObject		("Travelling object");
+
+		Exception exc = new Exception("Ex Cep Tion");
+		vhc.setException		(exc);
+		vhc.setErrorMessage		("ERRMSG");
+
+
+		Message msg = vhc.toCommandMessage();
+		CommandVehicle back = new CommandVehicle(msg);
+		
+		assertEquals(oper			,back.getOperator());
+		_logger.info("Operation OK");
+		assertEquals(returnCode		,back.getReturnCode());
+		_logger.info("Return code OK");
+		assertEquals(processDef		,back.getProcessDefinition());
+		_logger.info("Process definition OK");
+		assertEquals("foo"			,back.getProcessDefinitionName());
+		_logger.info("Process definition NAME OK");
+		assertEquals(99				,back.getProcessVersion());
+		_logger.info("Process version OK");
+		assertEquals(88				,back.getInstanceId());
+		_logger.info("Instance ID OK");
+		assertEquals(77				,back.getTokenId());
+		_logger.info("Token ID OK");
+		assertEquals("pirulo"		,back.getTransitionName());
+		_logger.info("Transition name OK");
+		assertEquals("FooNode"		,back.getCurrentNodeName());
+		_logger.info("Current node name OK");
+		assertEquals(names			,back.getVariableNames());
+		_logger.info("Variable names OK");
+		assertEquals(varValues		,back.getVariableValues());
+		_logger.info("Variable values OK");
+		assertEquals("Travelling object",back.getUserObject());
+		_logger.info("User object OK");
+		assertEquals(exc			,back.getException());
+		_logger.info("Exception OK");
+		assertEquals("ERRMSG"		,back.getErrorMessage());
+		_logger.info("Error message OK");
+	}
+	
+	private String getGoodProcessDefinition()
+	{
+		StringBuilder xml = new StringBuilder()
+		.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
+		.append("<process-definition")
+		.append(" xmlns='urn:jbpm.org:jpdl-3.1' name='simple'>")
+		.append(" <start-state name='start'>")
+		.append("   <transition name='to_state' to='first'/>")
+		.append(" </start-state>")
+		.append(" <state name='first'>")
+		.append("   <transition name='to_end' to='end'/>")
+		.append(" </state>")
+		.append(" <end-state name='end'/>")
+		.append("</process-definition>")
+		;
+		return xml.toString();
+	}
+	
+}


Property changes on: labs/jbossesb/branches/JBESB_4_0_MP1/product/core/rosetta/tests/src/org/jboss/soa/esb/util/jbpm/CommandVehicleUnitTest.java
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the jboss-svn-commits mailing list