// Path: src/test/java/net/chandol/logjdbc/_testhelper/LogReadableTestBase.java
// public abstract class LogReadableTestBase {
//     @Before
//     public void beforeRemoveLog() {
//         TestAppender.cleanEvents();
//     }
// 
//     @After
//     public void afterRemoveLog() {
//         TestAppender.cleanEvents();
//     }
// 
//     protected static List<LoggingEvent> getLogs() {
//         return TestAppender.getEvents();
//     }
// 
//     protected static List<String> getLogMessages() {
//         List<String> logMessages = new ArrayList<>();
//         for(LoggingEvent event : getLogs())
//             logMessages.add(event.getMessage());
// 
//         return logMessages;
//     }
// 
//     protected static List<LoggingEvent> getRecentLogs(int size) {
//         List<LoggingEvent> logs = getLogs();
//         int logSize = logs.size();
//         return TestAppender.getEvents().subList(logSize - size, logSize);
//     }
// 
//     protected static List<String> getRecentLogMessages(int size) {
//         List<String> logMessages = new ArrayList<>();
//         for(LoggingEvent event : getRecentLogs(size))
//             logMessages.add(event.getMessage());
// 
//         return logMessages;
//     }
// 
//     protected static int getLogSize() {
//         return getLogs().size();
//     }
// }
// 
// Path: src/test/java/net/chandol/logjdbc/_fixture/DummyDataSource.java
// public static DataSource getDummyH2DataSource() {
//     JdbcDataSource dataSource = new JdbcDataSource();
//     dataSource.setURL("jdbc:h2:mem:test");
//     dataSource.setUser("sa");
//     dataSource.setPassword("sa");
//     return dataSource;
// }


import ch.qos.logback.classic.spi.LoggingEvent;
import net.chandol.logjdbc._testhelper.LogReadableTestBase;
import org.junit.Assert;
import org.junit.Test;
import javax.sql.DataSource;
import java.sql.*;
import static net.chandol.logjdbc._fixture.DummyDataSource.getDummyH2DataSource;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
package net.chandol.logjdbc;






public class LogJdbcDataSourceIntegrationTest extends LogReadableTestBase {

    @Test
    public void coreIntegrationTest() throws SQLException {
        // create datasource
        DataSource h2DataSource = getDummyH2DataSource();
        DataSource dataSource = new LogJdbcDataSource(h2DataSource);

        // open connection
        Connection connection = dataSource.getConnection();

        // create statement
        Statement statement = connection.createStatement();
        statement.execute("CREATE TABLE CUSTOMERS (ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25), SALARY DECIMAL(18, 2), PRIMARY KEY (ID));");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (2, '김동표', 25, '서울', 1500.00 );");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (3, '송준호', 23, '부산', 2000.00 );");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (4, '문종현', 25, '대전', 6500.00 );");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (5, '심인보', 27, '대구', 8500.00 );");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (6, '박세종', 22, '울산', 4500.00 );");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (7, 'Tester', 21, 'Texas', 1500.00 );");

        // create preparedStatement
        PreparedStatement pstmt1 = connection.prepareStatement("SELECT * FROM CUSTOMERS WHERE ID=?");
        pstmt1.setLong(1, 3);
        ResultSet resultSet1 = pstmt1.executeQuery();

        while (resultSet1.next()) {
        }

        PreparedStatement pstmt2 = connection.prepareStatement("SELECT * FROM CUSTOMERS");
        ResultSet resultSet2 = pstmt2.executeQuery();

// Path: src/test/java/net/chandol/logjdbc/_testhelper/LogReadableTestBase.java
// public abstract class LogReadableTestBase {
//     @Before
//     public void beforeRemoveLog() {
//         TestAppender.cleanEvents();
//     }
// 
//     @After
//     public void afterRemoveLog() {
//         TestAppender.cleanEvents();
//     }
// 
//     protected static List<LoggingEvent> getLogs() {
//         return TestAppender.getEvents();
//     }
// 
//     protected static List<String> getLogMessages() {
//         List<String> logMessages = new ArrayList<>();
//         for(LoggingEvent event : getLogs())
//             logMessages.add(event.getMessage());
// 
//         return logMessages;
//     }
// 
//     protected static List<LoggingEvent> getRecentLogs(int size) {
//         List<LoggingEvent> logs = getLogs();
//         int logSize = logs.size();
//         return TestAppender.getEvents().subList(logSize - size, logSize);
//     }
// 
//     protected static List<String> getRecentLogMessages(int size) {
//         List<String> logMessages = new ArrayList<>();
//         for(LoggingEvent event : getRecentLogs(size))
//             logMessages.add(event.getMessage());
// 
//         return logMessages;
//     }
// 
//     protected static int getLogSize() {
//         return getLogs().size();
//     }
// }
// 
// Path: src/test/java/net/chandol/logjdbc/_fixture/DummyDataSource.java
// public static DataSource getDummyH2DataSource() {
//     JdbcDataSource dataSource = new JdbcDataSource();
//     dataSource.setURL("jdbc:h2:mem:test");
//     dataSource.setUser("sa");
//     dataSource.setPassword("sa");
//     return dataSource;
// }


// Path: src/test/java/net/chandol/logjdbc/LogJdbcDataSourceIntegrationTest.java
import ch.qos.logback.classic.spi.LoggingEvent;
import net.chandol.logjdbc._testhelper.LogReadableTestBase;
import org.junit.Assert;
import org.junit.Test;
import javax.sql.DataSource;
import java.sql.*;
import static net.chandol.logjdbc._fixture.DummyDataSource.getDummyH2DataSource;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;

package net.chandol.logjdbc;






public class LogJdbcDataSourceIntegrationTest extends LogReadableTestBase {

    @Test
    public void coreIntegrationTest() throws SQLException {
        // create datasource
        DataSource h2DataSource = getDummyH2DataSource();
        DataSource dataSource = new LogJdbcDataSource(h2DataSource);

        // open connection
        Connection connection = dataSource.getConnection();

        // create statement
        Statement statement = connection.createStatement();
        statement.execute("CREATE TABLE CUSTOMERS (ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25), SALARY DECIMAL(18, 2), PRIMARY KEY (ID));");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (2, '김동표', 25, '서울', 1500.00 );");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (3, '송준호', 23, '부산', 2000.00 );");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (4, '문종현', 25, '대전', 6500.00 );");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (5, '심인보', 27, '대구', 8500.00 );");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (6, '박세종', 22, '울산', 4500.00 );");
        statement.execute("INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (7, 'Tester', 21, 'Texas', 1500.00 );");

        // create preparedStatement
        PreparedStatement pstmt1 = connection.prepareStatement("SELECT * FROM CUSTOMERS WHERE ID=?");
        pstmt1.setLong(1, 3);
        ResultSet resultSet1 = pstmt1.executeQuery();

        while (resultSet1.next()) {
        }

        PreparedStatement pstmt2 = connection.prepareStatement("SELECT * FROM CUSTOMERS");
        ResultSet resultSet2 = pstmt2.executeQuery();

        while (resultSet2.next()) {