[jboss-svn-commits] JBL Code SVN: r6551 - labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Oct 3 09:56:09 EDT 2006
Author: mark.little at jboss.com
Date: 2006-10-03 09:56:03 -0400 (Tue, 03 Oct 2006)
New Revision: 6551
Added:
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ByteArrayToStringUnitTest.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToCSVStringUnitTest.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToFileWriterUnitTest.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToXStreamUnitTest.java
Log:
Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ByteArrayToStringUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ByteArrayToStringUnitTest.java 2006-10-03 13:55:44 UTC (rev 6550)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ByteArrayToStringUnitTest.java 2006-10-03 13:56:03 UTC (rev 6551)
@@ -0,0 +1,48 @@
+/*
+ * 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.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+/**
+ * ByteArrayToString unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ByteArrayToStringUnitTest extends TestCase {
+
+ public void test() throws ActionProcessingException {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ properties.add(new KeyValuePair("encoding", "UTF-8"));
+ ByteArrayToString byteArrayToString = new ByteArrayToString("actionName", properties);
+
+ String decodedBytes = (String)byteArrayToString.process("TestString".getBytes());
+ assertEquals("TestString", decodedBytes);
+ }
+}
Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToCSVStringUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToCSVStringUnitTest.java 2006-10-03 13:55:44 UTC (rev 6550)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToCSVStringUnitTest.java 2006-10-03 13:56:03 UTC (rev 6551)
@@ -0,0 +1,74 @@
+/*
+ * 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.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+/**
+ * ObjectToCSVString unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ObjectToCSVStringUnitTest extends TestCase {
+
+ public void test() throws ConfigurationException, ActionProcessingException {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ properties.add(new KeyValuePair(ObjectToCSVString.BEAN_PROPERTIES_PROP, "name"));
+ ObjectToCSVString processor = new ObjectToCSVString("ObjectToCSVString", properties);
+ assertEquals("Tom Fennelly", processor.process(new TestBean()));
+
+ properties.clear();
+ properties.add(new KeyValuePair(ObjectToCSVString.BEAN_PROPERTIES_PROP, "name,age"));
+ processor = new ObjectToCSVString("ObjectToCSVString", properties);
+ assertEquals("Tom Fennelly,21", processor.process(new TestBean()));
+
+ properties.clear();
+ properties.add(new KeyValuePair(ObjectToCSVString.BEAN_PROPERTIES_PROP, "id,name,phone,age"));
+ processor = new ObjectToCSVString("ObjectToCSVString", properties);
+ assertEquals(",Tom Fennelly,,21", processor.process(new TestBean()));
+
+ properties.clear();
+ properties.add(new KeyValuePair(ObjectToCSVString.BEAN_PROPERTIES_PROP, "id"));
+ processor = new ObjectToCSVString("ObjectToCSVString", properties);
+ assertEquals("", processor.process(new TestBean()));
+ }
+
+ private class TestBean {
+ private String name = "Tom Fennelly";
+ private int age = 21; // hehehehe
+
+ public int getAge() {
+ return age;
+ }
+ public String getName() {
+ return name;
+ }
+ }
+}
Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToFileWriterUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToFileWriterUnitTest.java 2006-10-03 13:55:44 UTC (rev 6550)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToFileWriterUnitTest.java 2006-10-03 13:56:03 UTC (rev 6551)
@@ -0,0 +1,96 @@
+/*
+ * 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.actions;
+
+import java.io.File;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+/**
+ * Unit tests for ObjectToFileWriter.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ObjectToFileWriterUnitTest extends TestCase {
+
+ private static final String A_STRING = "write something to file";
+ private File file = new File("./ObjectToFileWriter.tst");
+ private List<KeyValuePair> properties;
+
+ @Override
+ protected void setUp() throws Exception {
+ properties = new ArrayList<KeyValuePair>();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ file.delete();
+ }
+
+ public void test_writeWithNoAppend() throws ConfigurationException, ActionProcessingException {
+ properties.add(new KeyValuePair("file", file.getPath()));
+
+ // Write something fo file and check it was written..
+ writeAndCheck(A_STRING, A_STRING);
+ // And do it all again to make sure the contents are not appended i.e. the file is overwritten...
+ writeAndCheck(A_STRING, A_STRING);
+ }
+
+ public void test_writeWithBytes() throws ConfigurationException, ActionProcessingException, UnsupportedEncodingException {
+ properties.add(new KeyValuePair("file", file.getPath()));
+
+ // Write bytes to the file...
+ writeAndCheck(A_STRING.getBytes("UTF-8"), A_STRING);
+ }
+
+ public void test_writeWithAppend() throws ConfigurationException, ActionProcessingException {
+ properties.add(new KeyValuePair("file", file.getPath()));
+ properties.add(new KeyValuePair("append", "true"));
+
+ // Write something to file and check it was written..
+ writeAndCheck(A_STRING, A_STRING);
+ // And do it all again to make sure the contents are appended i.e. the file is not overwritten...
+ writeAndCheck(A_STRING, A_STRING + A_STRING);
+ }
+
+
+ private void writeAndCheck(Object objectToWrite, String expected) throws ConfigurationException, ActionProcessingException {
+ // Use the ObjectToFileWriter to write something to file...
+ ObjectToFileWriter fileWriter = new ObjectToFileWriter("ObjectToFileWriter-Test", properties);
+ fileWriter.process(objectToWrite);
+
+ // Use the FileToByteArray processor to read the file contents back...
+ FileToByteArray fileToByteArray = new FileToByteArray();
+ byte[] fileContent = (byte[])fileToByteArray.process(file);
+
+ // Make sure the contents are as expected...
+ String fileContentString = new String(fileContent);
+ assertEquals(expected, fileContentString);
+ }
+}
Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToXStreamUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToXStreamUnitTest.java 2006-10-03 13:55:44 UTC (rev 6550)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/actions/ObjectToXStreamUnitTest.java 2006-10-03 13:56:03 UTC (rev 6551)
@@ -0,0 +1,110 @@
+/*
+ * 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.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.helpers.KeyValuePair;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+
+/**
+ * ObjectToXStream unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class ObjectToXStreamUnitTest extends TestCase {
+
+ public void test_default() throws ActionProcessingException {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ ObjectToXStream objectToXStream = new ObjectToXStream("TestBean-Serialiser", properties);
+
+ String xml = (String)objectToXStream.process(new TestBean("Tom", "1234"));
+ XStream xstream = new XStream(new DomDriver());
+ TestBean bean = new TestBean();
+
+ assertTrue("Expected [<TestBean>]. Got [" + xml + "]", xml.startsWith("<TestBean>"));
+ xstream.alias("TestBean", TestBean.class);
+ xstream.fromXML(xml, bean);
+
+ assertEquals("Tom", bean.getName());
+ assertEquals("1234", bean.getPhone());
+ }
+
+ public void test_with_package() throws ActionProcessingException {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ properties.add(new KeyValuePair("exclude-package", "false"));
+ ObjectToXStream objectToXStream = new ObjectToXStream("TestBean-Serialiser", properties);
+
+ String xml = (String)objectToXStream.process(new TestBean("Tom", "1234"));
+ XStream xstream = new XStream(new DomDriver());
+ TestBean bean = new TestBean();
+
+ assertTrue("Expected start with [<" + TestBean.class.getName() + ">]. Got [" + xml + "]", xml.startsWith("<" + TestBean.class.getName() + ">"));
+ xstream.fromXML(xml, bean);
+
+ assertEquals("Tom", bean.getName());
+ assertEquals("1234", bean.getPhone());
+ }
+
+ public void test_with_alias() throws ActionProcessingException {
+ List<KeyValuePair> properties = new ArrayList<KeyValuePair>();
+
+ properties.add(new KeyValuePair("class-alias", "TomsClass"));
+ ObjectToXStream objectToXStream = new ObjectToXStream("TestBean-Serialiser", properties);
+
+ String xml = (String)objectToXStream.process(new TestBean("Tom", "1234"));
+ XStream xstream = new XStream(new DomDriver());
+ xstream.alias("TomsClass", TestBean.class);
+ TestBean bean = new TestBean();
+
+ assertTrue("Expected start with [<TomsClass>]. Got [" + xml + "]", xml.startsWith("<TomsClass>"));
+ xstream.fromXML(xml, bean);
+
+ assertEquals("Tom", bean.getName());
+ assertEquals("1234", bean.getPhone());
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
More information about the jboss-svn-commits
mailing list