[jboss-svn-commits] JBL Code SVN: r10298 - labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sat Mar 17 07:07:49 EDT 2007
Author: mark.little at jboss.com
Date: 2007-03-17 07:07:49 -0400 (Sat, 17 Mar 2007)
New Revision: 10298
Added:
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/InvokerUnitTest.java
Log:
fixed unit test to delete files after use.
Added: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/InvokerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/InvokerUnitTest.java (rev 0)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/message/InvokerUnitTest.java 2007-03-17 11:07:49 UTC (rev 10298)
@@ -0,0 +1,274 @@
+/*
+ * 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.listeners.message;
+
+import java.io.File;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.log4j.xml.DOMConfigurator;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+import org.jboss.soa.esb.listeners.RegistryUtil;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.testutils.FileUtil;
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+import org.jboss.soa.esb.util.AbstractCommandVehicle;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+class CommandVehicle extends AbstractCommandVehicle
+{
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String getCommandValuesTag()
+ {
+ return "foobar";
+ }
+
+ @Override
+ public String getCommandOpcodeKey()
+ {
+ return "barfoo";
+ }
+
+ public enum Operation
+ {
+ SomeOperation
+ }
+
+ public CommandVehicle()
+ {
+ this(CommandVehicle.Operation.SomeOperation);
+ }
+
+ public CommandVehicle(Enum command)
+ {
+ super(command);
+ }
+
+ public CommandVehicle(Message message)
+ {
+ super(message);
+ }
+
+ public Object getReturnCode()
+ {
+ return "ReturnCode";
+ }
+}
+
+public class InvokerUnitTest extends TestCase
+{
+
+ protected final void setup()
+ {
+ try
+ {
+ DOMConfigurator.configure(TestEnvironmentUtil.getUserDir("product",
+ "../product")
+ + "/etc/test/resources/log4j.xml");
+ TestEnvironmentUtil.setESBPropertiesFileToUse("product",
+ "../product");
+ // Set the juddi properties file in System so juddi will pick it up
+ // later and use the test values.
+ String juddiPropertiesFile = "/org/jboss/soa/esb/listeners/juddi-unittest.properties";
+ System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
+ // Read this properties file to get the db connection string
+ Properties props = new Properties();
+ InputStream inStream = Class.class
+ .getResourceAsStream(juddiPropertiesFile);
+
+ props.load(inStream);
+ mDbDriver = props.getProperty("juddi.jdbcDriver");
+ mDbUrl = props.getProperty("juddi.jdbcUrl");
+ mDbUsername = props.getProperty("juddi.jdbcUsername");
+ mDbPassword = props.getProperty("juddi.jdbcPassword");
+
+ String database = "not tested yet";
+ if ("org.hsqldb.jdbcDriver".equals(mDbDriver))
+ {
+ database = "hsqldb";
+ // Bring up hsql on default port 9001
+ HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir(
+ "product", "../product")
+ + "/build/hsqltestdb", "juddi");
+ }
+ else if ("com.mysql.jdbc.Driver".equals(mDbDriver))
+ {
+ database = "mysql";
+ } // add and test your own database..
+
+ // Get the registry-schema create scripts
+ String sqlDir = TestEnvironmentUtil.getUserDir("product",
+ "../product")
+ + "/install/jUDDI-registry/sql/" + database + "/";
+ // Drop what is there now, if exists. We want to start fresh.
+ String sqlDropCmd = FileUtil.readTextFile(new File(sqlDir
+ + "drop_database.sql"));
+ String sqlCreateCmd = FileUtil.readTextFile(new File(sqlDir
+ + "create_database.sql"));
+ String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir
+ + "insert_publishers.sql"));
+
+ try
+ {
+ Class.forName(mDbDriver);
+ }
+ catch (Exception e)
+ {
+ System.out.println("ERROR: failed to load " + database
+ + " JDBC driver.");
+ e.printStackTrace();
+ return;
+ }
+ con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
+ Statement stmnt = con.createStatement();
+ stmnt.execute(sqlDropCmd);
+ stmnt.execute(sqlCreateCmd);
+ stmnt.execute(sqlInsertPubCmd);
+ stmnt.close();
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ System.out
+ .println("We should stop testing, since we don't have a db.");
+ assertTrue(false);
+ }
+ }
+
+ protected final void tearDown()
+ {
+ try
+ {
+ Thread.sleep(1000);
+ Statement stmnt = con.createStatement();
+
+ stmnt.execute("SHUTDOWN");
+ stmnt.close();
+
+ con.close();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void testInvalidParameters() throws Exception
+ {
+ setup();
+
+ CommandVehicle command = new CommandVehicle();
+
+ try
+ {
+ Invoker.invoke(command, null, null);
+ fail();
+ }
+ catch (RegistryException ex)
+ {
+ }
+
+ try
+ {
+ Invoker.invoke(command, "foo", "bar");
+ fail();
+ }
+ catch (RegistryException ex)
+ {
+ }
+
+ final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
+ final String tmpDirForm = tmpDir.toURL().toExternalForm();
+ FileEpr epr = new FileEpr(tmpDirForm);
+
+ epr.setInputSuffix(".testFile");
+ epr.setPostDelete(true);
+ epr.setPostSuffix(".unitProcessedOK");
+
+ ConfigTree tree = new ConfigTree("test");
+
+ tree.setAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG,
+ "eprmanager");
+ tree.setAttribute(ListenerTagNames.SERVICE_NAME_TAG, "foobar");
+
+ RegistryUtil.register(tree, epr);
+
+ try
+ {
+ Invoker.invoke(command, "eprmanager", "foobar");
+ }
+ catch (Exception ex)
+ {
+ fail();
+ }
+
+ try
+ {
+ Invoker
+ .invokeAndAwaitResponse(command, "eprmanager", "foobar",
+ 100);
+ }
+ catch (Exception ex)
+ {
+ }
+
+ File[] files = tmpDir.listFiles();
+
+ for (int i = 0; i < files.length; i++)
+ {
+ if (files[i].getName().equals(".unitProcessedOK"))
+ {
+ try
+ {
+ files[i].delete();
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+ }
+
+ private static String mDbDriver;
+
+ private static String mDbUrl;
+
+ private static String mDbUsername;
+
+ private static String mDbPassword;
+
+ private static Connection con;
+}
More information about the jboss-svn-commits
mailing list