/*
 * This file is part of JEJDBC 
 * https://github.com/perbone/jejdbc/
 * 
 * Copyright 2013-2017 Paulo Perbone
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package io.perbone.jejdbc.jdbc;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Driver class test suit.
 * 
 * @author Paulo Perbone <pauloperbone@yahoo.com>
 * @since 0.1.0
 */
public class DriverTest
{
    private static final String URL_SAMPLE_CLIENT = "jdbc:jejdbc://localhost:5101/sampledb";
    private static final String URL_SAMPLE_LOCAL = "jdbc:jejdbc:/tmp/sampledb";
    private static final String URL_SAMPLE_WRONG = "jdbc:foo://localhost:5101";
    private static final String DRIVER_CLASS_PATH = "io.perbone.jejdbc.jdbc.Driver";

    @BeforeClass
    public static void initialSetup()
    {
    }

    @Test
    public void loadDriver()
    {
        try
        {
            Class.forName(DRIVER_CLASS_PATH);
        }
        catch (final ClassNotFoundException e)
        {
            fail(e.getMessage());
        }
    }

    @Test
    public void getDriver()
    {
        Driver driver = null;

        try
        {
            driver = DriverManager.getDriver(URL_SAMPLE_CLIENT);

            assertNotNull(driver);
            assertTrue(driver.getClass().equals(io.perbone.jejdbc.jdbc.Driver.class));
        }
        catch (final SQLException e)
        {
            fail(e.getMessage());
        }

        try
        {
            driver = DriverManager.getDriver(URL_SAMPLE_LOCAL);

            assertNotNull(driver);
            assertTrue(driver.getClass().equals(io.perbone.jejdbc.jdbc.Driver.class));
        }
        catch (final SQLException e)
        {
            fail(e.getMessage());
        }

        driver = null;

        try
        {
            driver = DriverManager.getDriver(URL_SAMPLE_WRONG);
        }
        catch (final SQLException e)
        {
        }

        assertNull(driver);
    }

    @Test
    public void testAcceptsURL()
    {
        try
        {
            Driver driver = new io.perbone.jejdbc.jdbc.Driver();

            assertTrue(driver.acceptsURL(URL_SAMPLE_CLIENT));
            assertFalse(driver.acceptsURL(URL_SAMPLE_WRONG));
        }
        catch (final SQLException e)
        {
            fail(e.getMessage());
        }
    }

    @Test
    public void testExceptionMessages()
    {
        Driver driver = new io.perbone.jejdbc.jdbc.Driver();

        try
        {
            driver.acceptsURL(null);
        }
        catch (final SQLException e)
        {
            System.out.println(e.getMessage());
        }

        try
        {
            driver.getParentLogger();
        }
        catch (final SQLException e)
        {
            System.out.println(e.getMessage());
        }
    }
}
@@ -913,16 +913,44 @@
 .fail;%0A%0A
+import java.sql.Connection;%0A
 import j
@@ -1212,16 +1212,102 @@
 rTest%0A%7B%0A
+    private static final String DRIVER_CLASS_PATH = %22io.perbone.jejdbc.jdbc.Driver%22;%0A%0A
     priv
@@ -1514,21 +1514,19 @@
 _SAMPLE_
-WRONG
+BAD
  = %22jdbc
@@ -1552,93 +1552,8 @@
 01%22;
-%0A    private static final String DRIVER_CLASS_PATH = %22io.perbone.jejdbc.jdbc.Driver%22;
 %0A%0A  
@@ -2649,21 +2649,19 @@
 _SAMPLE_
-WRONG
+BAD
 );%0A     
@@ -3014,13 +3014,11 @@
 PLE_
-WRONG
+BAD
 ));%0A
@@ -3159,152 +3159,455 @@
 test
-ExceptionMessages()%0A    %7B%0A        Driver driver = new io.perbone.jejdbc.jdbc.Driver();%0A%0A        try%0A        %7B%0A            driver.acceptsURL(null
+Connection()%0A    %7B%0A        try%0A        %7B%0A            Driver driver = DriverManager.getDriver(URL_SAMPLE_LOCAL);%0A%0A            Connection conn = driver.connect(URL_SAMPLE_CLIENT, null);%0A            assertNotNull(conn);%0A            conn.close();%0A%0A            conn = driver.connect(URL_SAMPLE_LOCAL, null);%0A            assertNotNull(conn);%0A            conn.close();%0A%0A            conn = driver.connect(URL_SAMPLE_BAD, null);%0A            assertNull(conn
 );%0A 
@@ -3674,34 +3674,20 @@
         
-System.out.println
+fail
 (e.getMe
@@ -3710,43 +3710,140 @@
   %7D%0A
-%0A
     
+%7D%0A%0A
     
-try%0A        %7B
+@Test(expected = SQLException.class)%0A    public void testExceptionMessagesAcceptsURL() throws SQLException
 %0A    
+%7B%0A
         
 driv
@@ -3842,42 +3842,70 @@
     
-driver.getParentLogg
+Driver driver = new io.perbone.jejdbc.jdbc.Driv
 er();%0A
+%0A
         
 %7D%0A  
@@ -3904,113 +3904,232 @@
     
-%7D
+driver.acceptsURL(null);
 %0A    
+%7D%0A%0A
     
-catch (final SQLException e)%0A        %7B%0A            System.out.println(e.getMessage()
+@Test(expected = SQLException.class)%0A    public void testExceptionMessagesGetParentLogger() throws SQLException%0A    %7B%0A        Driver driver = new io.perbone.jejdbc.jdbc.Driver(
 );%0A
+%0A
         
 %7D%0A  
@@ -4120,21 +4120,45 @@
 );%0A%0A        
-%7D
+driver.getParentLogger();
 %0A    %7D%0A%7D

Add initial connection test