/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2010, 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.unit;

import org.jboss.jca.adapters.ArquillianJCATestUtils;
import org.jboss.jca.embedded.dsl.InputStreamDescriptor;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptor;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
 * Test cases for wrapper
 *
 * @author <a href="mailto:jesper.pedersen@jboss.org">Jesper Pedersen</a>
 */
@RunWith(Arquillian.class)
public class WrapperTestCase
{

   //-------------------------------------------------------------------------------------||
   //---------------------- GIVEN --------------------------------------------------------||
   //-------------------------------------------------------------------------------------||

   /**
    * Define the deployment
    * @return The deployment archive
    * @throws Exception in case of errors
    */
   @Deployment(order = 1)
   public static ResourceAdapterArchive createArchive() throws Exception
   {
      return ArquillianJCATestUtils.buildShrinkwrapJdbcLocal();
   }

   /**
    * Define the -ds.xml
    * @return The deployment archive
    * @throws Exception in case of errors
    */
   @Deployment(order = 2)
   public static Descriptor createDescriptor() throws Exception
   {
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      InputStreamDescriptor isd = new InputStreamDescriptor("h2-ds.xml",
                                                            cl.getResourceAsStream("h2-ds.xml"));
      return isd;
   }

   //-------------------------------------------------------------------------------------||
   //---------------------- WHEN  --------------------------------------------------------||
   //-------------------------------------------------------------------------------------||
   //
   @Resource(mappedName = "java:/H2DS")
   private DataSource ds;

   //-------------------------------------------------------------------------------------||
   //---------------------- THEN  --------------------------------------------------------||
   //-------------------------------------------------------------------------------------||

   /**
    * Case 1
    * @exception Throwable Thrown if case of an error
    */
   @Test
   public void testSelf() throws Throwable
   {
      assertNotNull(ds);
      Connection c = ds.getConnection();
      assertNotNull(c);

      Connection c2 = c.unwrap(Connection.class);
      assertEquals(c, c2);

      c.close();
   }

   /**
    * Case 2
    * @exception Throwable Thrown if case of an error
    */
   @Test
   public void testDirect() throws Throwable
   {
      assertNotNull(ds);
      Connection c = ds.getConnection();
      assertNotNull(c);

      org.h2.jdbc.JdbcConnection c2 = c.unwrap(org.h2.jdbc.JdbcConnection.class);
      assertNotNull(c2);

      c.close();
   }
}

@@ -1212,127 +1212,8 @@
 ion;
-%0Aimport java.sql.PreparedStatement;%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0Aimport java.sql.Statement;
 %0A%0Aim
@@ -1690,45 +1690,8 @@
 rue;
-%0Aimport static org.junit.Assert.fail;
 %0A%0A/*
@@ -3653,16 +3653,338 @@
 oid test
+IsWraperForSelf() throws Throwable%0A   %7B%0A      assertNotNull(ds);%0A      Connection c = ds.getConnection();%0A      assertNotNull(c);%0A%0A      assertTrue(c.isWrapperFor(Connection.class));%0A%0A      c.close();%0A   %7D%0A%0A   /**%0A    * Case 1%0A    * @exception Throwable Thrown if case of an error%0A    */%0A   @Test%0A   public void testUnwrap
 Self() t
@@ -3991,32 +3991,32 @@
 hrows Throwable%0A
-
    %7B%0A      asser
@@ -4305,16 +4305,22 @@
 oid test
+Unwrap
 Direct()
@@ -4507,32 +4507,32 @@
 nection.class);%0A
-
       assertNotN
@@ -4537,24 +4537,359 @@
 tNull(c2);%0A%0A
+      c.close();%0A   %7D%0A%0A   /**%0A    * Case 2%0A    * @exception Throwable Thrown if case of an error%0A    */%0A   @Test%0A   public void testIsWrapperForDirect() throws Throwable%0A   %7B%0A      assertNotNull(ds);%0A      Connection c = ds.getConnection();%0A      assertNotNull(c);%0A%0A      assertTrue(c.isWrapperFor(org.h2.jdbc.JdbcConnection.class));%0A%0A
       c.clos

Add isWrapperFor tests