package io.github.mattshen.dbkit.core;


import io.github.mattshen.dbkit.core.utils.JdbcUtils;
import io.github.mattshen.dbkit.core.utils.ResultSetExtractor;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class DbAccessorTest {

    static DbAccessor dbAccessor = null;

    @BeforeClass
    public static void setUp() throws Exception {
        dbAccessor = DbAccessor.getInstance();
        dbAccessor.connect();
    }

    @AfterClass
    public static void tearDown() throws SQLException {
        dbAccessor.close();
    }

    @Test
    public void basic_query_should_work() throws Exception {
        List<String> result = dbAccessor.query("select 1", rs -> rs.getString(1));
        Assert.assertTrue(result.size() == 1);
        Assert.assertTrue(result.get(0).equals("1"));
    }

    @Test
    public void get_shemas_should_work() throws Exception {
        List<Map<String, Object>> schemas = dbAccessor.getSchemas(JdbcUtils::extractToMap);
        Assert.assertTrue(schemas.size() >= 0);
    }

    @Test
    public void get_catalogs_should_work() throws Exception {
        List<Map<String, Object>> catalogs = dbAccessor.getCatalogs(JdbcUtils::extractToMap);
        System.out.println(catalogs);
        Assert.assertTrue(catalogs.size() > 0);
    }

    @Test
    public void get_tables_should_work() throws Exception {
        List<Object> tables = dbAccessor.getTables(JdbcUtils::extractToMap);
        tables.forEach(System.out::println);
        Assert.assertTrue(tables.size() > 0);
    }

}

@@ -1315,46 +1315,8 @@
 p);%0A
-        System.out.println(catalogs);%0A
     
@@ -1517,53 +1517,8 @@
 p);%0A
-        tables.forEach(System.out::println);%0A
     

remove system.out.println