/*
 * 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 = "jdbc:jejdbc://localhost:5101";
    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()
    {
        try
        {
            Driver driver = DriverManager.getDriver(URL_SAMPLE);

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

        Driver 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));
            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());
        }
    }
}
@@ -1226,16 +1226,23 @@
 L_SAMPLE
+_CLIENT
  = %22jdbc
@@ -1257,32 +1257,121 @@
 //localhost:5101
+/sampledb%22;%0A    private static final String URL_SAMPLE_LOCAL = %22jdbc:jejdbc:/tmp/sampledb
 %22;%0A    private s
@@ -1858,32 +1858,63 @@
 tDriver()%0A    %7B%0A
+        Driver driver = null;%0A%0A
         try%0A    
@@ -1923,39 +1923,32 @@
   %7B%0A            
-Driver 
 driver = DriverM
@@ -1974,16 +1974,23 @@
 L_SAMPLE
+_CLIENT
 );%0A%0A    
@@ -2209,38 +2209,342 @@
      %7D%0A%0A        
-Driver
+try%0A        %7B%0A            driver = DriverManager.getDriver(URL_SAMPLE_LOCAL);%0A%0A            assertNotNull(driver);%0A            assertTrue(driver.getClass().equals(io.perbone.jejdbc.jdbc.Driver.class));%0A        %7D%0A        catch (final SQLException e)%0A        %7B%0A            fail(e.getMessage());%0A        %7D%0A%0A       
  driver = null;%0A
@@ -2689,32 +2689,33 @@
     %7B%0A        %7D%0A
+%0A
         assertNu
@@ -2921,16 +2921,23 @@
 L_SAMPLE
+_CLIENT
 ));%0A    

Add initial LOCAL URL test