[jboss-cvs] JBossAS SVN: r109392 - in projects/jboss-jca/trunk/adapters/src/test: resources and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Nov 19 08:12:04 EST 2010


Author: maeste
Date: 2010-11-19 08:12:04 -0500 (Fri, 19 Nov 2010)
New Revision: 109392

Added:
   projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/ValidConnectionCheckerTestCase.java
Modified:
   projects/jboss-jca/trunk/adapters/src/test/resources/h2-valid-connection-checker-ds.xml
Log:
making ValidConnectiontheckerTestCase working without mock or any injection

Added: projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/ValidConnectionCheckerTestCase.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/ValidConnectionCheckerTestCase.java	                        (rev 0)
+++ projects/jboss-jca/trunk/adapters/src/test/java/org/jboss/jca/adapters/jdbc/spi/ValidConnectionCheckerTestCase.java	2010-11-19 13:12:04 UTC (rev 109392)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jca.adapters.jdbc.spi;
+
+import org.jboss.jca.adapters.jdbc.spi.testimpl.TestValidConnectionChecker;
+import org.jboss.jca.embedded.EmbeddedJCA;
+
+import java.io.File;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ *
+ * A StaleConectionCheckerTestCase.
+ *
+ * @author <a href="stefano.maestri at jboss.com">Stefano Maestri</a>
+ *
+ */
+public class ValidConnectionCheckerTestCase
+{
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * shouldInjectCorrectStaleConnectionChecker
+    * @throws Throwable in case of error
+    */
+   @Test
+   public void shouldInjectCorrectStaleConnectionChecker() throws Throwable
+   {
+      /*
+       * Embedded
+       */
+      EmbeddedJCA embedded = null;
+
+      try
+      {
+         // Create and set an embedded JCA instance
+         embedded = new EmbeddedJCA();
+
+         // Startup
+         embedded.startup();
+
+         // Deploy jdbc-local.rar
+         embedded.deploy(getURL("jdbc-local.rar"));
+
+         // Deploy H2 datasource
+         URL url = getURL("test/h2-valid-connection-checker-ds.xml");
+
+         embedded.deploy(url);
+
+         Context context = null;
+
+         try
+         {
+            context = new InitialContext();
+
+            DataSource ds = (DataSource) context.lookup("java:/H2DS");
+            assertNotNull(ds);
+
+            Connection c = ds.getConnection();
+            assertNotNull(c);
+            c.close();
+            c = ds.getConnection();
+
+            Statement st = c.createStatement();
+            st.execute("dssd");
+
+         }
+         catch (SQLException e)
+         {
+            // nothing we need an exception ;)
+         }
+
+         finally
+         {
+            assertThat(TestValidConnectionChecker.isConstructorInvoked(), is(true));
+
+            assertThat(TestValidConnectionChecker.isMethodInvoked(), is(true));
+
+            //assertThat(TestValidConnectionChecker.getInjectedInteger(), is(100));
+
+            if (context != null)
+            {
+               try
+               {
+                  context.close();
+               }
+               catch (NamingException ne)
+               {
+                  // Ignore
+               }
+            }
+         }
+
+      }
+      finally
+      {
+         if (embedded != null)
+         {
+            // Undeploy H2 datasource
+            embedded.undeploy(getURL("test/h2-stale-connection-checker-ds.xml"));
+
+            // Undeploy jdbc-local.rar
+            embedded.undeploy(getURL("jdbc-local.rar"));
+
+            // Shutdown embedded
+            embedded.shutdown();
+
+            // Set embedded to null
+            embedded = null;
+         }
+      }
+
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Helper Methods -----------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Get the URL for a test archive
+    * @param archive The name of the test archive
+    * @return The URL to the archive
+    * @throws Throwable throwable exception
+    */
+   private static URL getURL(String archive) throws Throwable
+   {
+      File f = new File(System.getProperty("archives.dir") + File.separator + archive);
+      return f.toURI().toURL();
+   }
+
+}

Modified: projects/jboss-jca/trunk/adapters/src/test/resources/h2-valid-connection-checker-ds.xml
===================================================================
--- projects/jboss-jca/trunk/adapters/src/test/resources/h2-valid-connection-checker-ds.xml	2010-11-19 13:11:18 UTC (rev 109391)
+++ projects/jboss-jca/trunk/adapters/src/test/resources/h2-valid-connection-checker-ds.xml	2010-11-19 13:12:04 UTC (rev 109392)
@@ -12,12 +12,10 @@
       <password>sa</password>
     </security>
     <validation>
-      <valid-connection-checker-class-name>org.jboss.jca.adapters.jdbc.spi.testimpl.TestValidConnectionChecker
-      </valid-connection-checker-class-name>
+      <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.spi.testimpl.TestValidConnectionChecker"></valid-connection-checker>
       <validate-on-match>true</validate-on-match>
       <background-validation>true</background-validation>
       <background-validation-minutes>1</background-validation-minutes>
-      <ping-time-out>5</ping-time-out>
     </validation>
   </datasource>
 </datasources>
\ No newline at end of file



More information about the jboss-cvs-commits mailing list