Package utils

Examples of utils.TestDatabase


public class SqlLoaderTest {

    @Test
    public void testListParameter() throws Exception {
        TestDatabase testDatabase = new TestDatabase();
        testDatabase.setUpDatabase();

        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("login", Arrays.asList("login1", "login2"));
            SqlDataLoader sqlDataLoader = new SqlDataLoader(testDatabase.getDs());
            BandData rootBand = new BandData("band1", null, BandOrientation.HORIZONTAL);
            rootBand.setData(Collections.<String, Object>emptyMap());

            List<Map<String, Object>> result = sqlDataLoader.loadData(
                    new ReportQueryImpl("", "select login, password from user where login in ${login}", "sql", null, null), rootBand, params);
            printResult(result);
            Assert.assertEquals(2, result.size());
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail();
        } finally {
            testDatabase.stop();
        }
    }
View Full Code Here


    }


    @Test
    public void testArrayParameter() throws Exception {
        TestDatabase testDatabase = new TestDatabase();
        testDatabase.setUpDatabase();

        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("login", new String[]{"login1", "login2"});
            SqlDataLoader sqlDataLoader = new SqlDataLoader(testDatabase.getDs());
            BandData rootBand = new BandData("band1", null, BandOrientation.HORIZONTAL);
            rootBand.setData(Collections.<String, Object>emptyMap());

            List<Map<String, Object>> result = sqlDataLoader.loadData(
                    new ReportQueryImpl("", "select login, password from user where login in ${login}", "sql", null, null), rootBand, params);
            printResult(result);
            Assert.assertEquals(2, result.size());
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail();
        } finally {
            testDatabase.stop();
        }


    }
View Full Code Here

    }

    @Test
    public void testFunctionParameter() throws Exception {
        TestDatabase testDatabase = new TestDatabase();
        testDatabase.setUpDatabase();

        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("login", "login");
            SqlDataLoader sqlDataLoader = new SqlDataLoader(testDatabase.getDs());
            BandData rootBand = new BandData("band1", null, BandOrientation.HORIZONTAL);
            rootBand.setData(Collections.<String, Object>emptyMap());

            List<Map<String, Object>> result = sqlDataLoader.loadData(
                    new ReportQueryImpl("", "select login, password from user where login = CONCAT(${login}, '1')", "sql", null, null), rootBand, params);
            printResult(result);
            Assert.assertEquals(1, result.size());

            params.put("login", null);
            result = sqlDataLoader.loadData(
                    new ReportQueryImpl("", "select login, password from user [[where login = CONCAT(${login}, '1')]]", "sql", null, null), rootBand, params);
            printResult(result);
            Assert.assertEquals(3, result.size());

            params.put("login", "ABCD");
            result = sqlDataLoader.loadData(
                    new ReportQueryImpl("", "select login, password from user [[where login = CONCAT(${login}, '1')]]", "sql", null, null), rootBand, params);
            printResult(result);
            Assert.assertEquals(0, result.size());
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail();
        } finally {
            testDatabase.stop();
        }
    }
View Full Code Here

public class ReportingTest {

    @Test
    public void testReporting() throws Exception {
        TestDatabase testDatabase = new TestDatabase();
        testDatabase.setUpDatabase();
        Report report = createReport();

        Reporting reporting = new Reporting();
        reporting.setFormatterFactory(new DefaultFormatterFactory());
        reporting.setLoaderFactory(new DefaultLoaderFactory().setSqlDataLoader(new PropertiesSqlLoaderFactory(new DefaultPropertiesLoader("./modules/core/test/reporting.properties")).create()));

        ReportOutputDocument reportOutputDocument = reporting.runReport(new RunParams(report).templateCode("XLS"), new FileOutputStream("./result/smoke/result.xls"));

        Assert.assertEquals("myFileName.xls", reportOutputDocument.getDocumentName());

        testDatabase.stop();
    }
View Full Code Here

public class CustomTemplateTest {

    @Test
    public void testReporting() throws Exception {
        TestDatabase testDatabase = new TestDatabase();
        testDatabase.setUpDatabase();
        Report report = createReport();

        Reporting reporting = new Reporting();
        reporting.setFormatterFactory(new DefaultFormatterFactory());
        reporting.setLoaderFactory(new DefaultLoaderFactory().setSqlDataLoader(new PropertiesSqlLoaderFactory(new DefaultPropertiesLoader("./modules/core/test/reporting.properties")).create()));

        ReportOutputDocument reportOutputDocument = reporting.runReport(new RunParams(report), new FileOutputStream("./result/smoke/result.custom"));

        Assert.assertEquals("myFileName.txt", reportOutputDocument.getDocumentName());

        testDatabase.stop();
    }
View Full Code Here

*/

public class BookStoreTest {
    @Test
    public void testBookStoreReport() throws Exception {
        TestDatabase testDatabase = new TestDatabase();
        testDatabase.setUpDatabase();

        Connection connection = testDatabase.getDs().getConnection();
        try {
            connection.createStatement().executeUpdate("drop table store;");
        } catch (SQLException e) {
            //ignore
        }
        try {
            connection.createStatement().executeUpdate("drop table book;");
        } catch (SQLException e) {
            //ignore
        }

        connection.createStatement().executeUpdate("create table store (id integer, name varchar, address varchar);");
        connection.createStatement().executeUpdate("create table book(id integer, name varchar, author varchar, price decimal, store_id integer);");

        connection.createStatement().executeUpdate("insert into store values(1, 'Main store', 'Some street');");
        connection.createStatement().executeUpdate("insert into store values(2, 'Secondary store', 'Another street');");

        connection.createStatement().executeUpdate("insert into book values(1, 'Concurrency in practice', 'Brian Goetz', 10.0, 1);");
        connection.createStatement().executeUpdate("insert into book values(2, 'Concurrency in practice', 'Brian Goetz', 10.0, 1);");
        connection.createStatement().executeUpdate("insert into book values(2, 'Concurrency in practice', 'Brian Goetz', 10.0, 1);");
        connection.createStatement().executeUpdate("insert into book values(3, 'Effective Java', 'Josh Bloch', 20.0, 2);");
        connection.createStatement().executeUpdate("insert into book values(4, 'Effective Java', 'Josh Bloch', 20.0, 2);");
        connection.createStatement().executeUpdate("insert into book values(4, 'Effective Java', 'Josh Bloch', 20.0, 2);");
        connection.createStatement().executeUpdate("insert into book values(5, 'Effective Java', 'Josh Bloch', 20.0, 1);");
        connection.createStatement().executeUpdate("insert into book values(5, 'Effective Java', 'Josh Bloch', 20.0, 1);");
        connection.createStatement().executeUpdate("insert into book values(6, 'Concurrency in practice', 'Brian Goetz', 10.0, 2);");
        connection.createStatement().executeUpdate("insert into book values(7, 'Refactoring', 'Martin Fowler', 15.0, 2);");
        connection.createStatement().executeUpdate("insert into book values(8, 'Refactoring', 'Martin Fowler', 15.0, 2);");
        connection.createStatement().executeUpdate("insert into book values(8, 'Refactoring', 'Martin Fowler', 15.0, 2);");
        connection.createStatement().executeUpdate("insert into book values(9, 'Refactoring', 'Martin Fowler', 15.0, 1);");

        connection.commit();

        Report report = new DefaultXmlReader().parseXml(FileUtils.readFileToString(new File("./modules/core/test/sample/bookstore/bookstore.xml")));
        System.out.println();

        Reporting reporting = new Reporting();
        reporting.setFormatterFactory(new DefaultFormatterFactory());
        reporting.setLoaderFactory(new DefaultLoaderFactory()
                .setGroovyDataLoader(new GroovyDataLoader(new DefaultScriptingImpl()))
                .setSqlDataLoader(new SqlDataLoader(testDatabase.getDs())));

        ReportOutputDocument reportOutputDocument = reporting.runReport(new RunParams(report), new FileOutputStream("./result/sample/bookstore.xls"));

        testDatabase.stop();
    }
View Full Code Here

public class DataLoadersTest {

    @Test
    public void testSqlLoader() throws Exception {
        TestDatabase testDatabase = new TestDatabase();
        testDatabase.setUpDatabase();

        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("startDate", new Timestamp(new Date().getTime()));
            params.put("start", "login%");
            SqlDataLoader sqlDataLoader = new SqlDataLoader(testDatabase.getDs());
            BandData rootBand = new BandData("band1", null, BandOrientation.HORIZONTAL);
            rootBand.setData(Collections.<String, Object>emptyMap());

            List<Map<String, Object>> result = sqlDataLoader.loadData(
                    new ReportQueryImpl("", "select login as \"Login\", password as \"Password\" from user where create_ts > ${startDate} and login like ${start} limit 10", "sql", null, null), rootBand, params);
            printResult(result);
            Assert.assertNotNull(result.get(0).get("Login"));
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail();
        }

        testDatabase.stop();
    }
View Full Code Here

        testDatabase.stop();
    }

    @Test
    public void testCaseSensitiveSqlLoader() throws Exception {
        TestDatabase testDatabase = new TestDatabase();
        testDatabase.setUpDatabase();

        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("startDate", new Timestamp(new Date().getTime()));
            params.put("start", "login%");
            SqlDataLoader sqlDataLoader = new SqlDataLoader(testDatabase.getDs());
            BandData rootBand = new BandData("band1", null, BandOrientation.HORIZONTAL);
            rootBand.setData(Collections.<String, Object>emptyMap());

            List<Map<String, Object>> result = sqlDataLoader.loadData(
                    new ReportQueryImpl("", "select login as Login, password as Password from user where create_ts > ${startDate} and login like ${start} limit 10", "sql", null, null), rootBand, params);
            printResult(result);
            Assert.assertNotNull(result.get(0).get("Login"));
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail();
        }

        testDatabase.stop();
    }
View Full Code Here

*/

public class BreakdownTest {
    @Test
    public void testBreakdownReport() throws Exception {
        TestDatabase testDatabase = new TestDatabase();
        testDatabase.setUpDatabase();

        Connection connection = testDatabase.getDs().getConnection();
        try {
            connection.createStatement().executeUpdate("drop table month_batch;");
        } catch (SQLException e) {
            //ignore
        }
        try {
            connection.createStatement().executeUpdate("drop table sold_item;");
        } catch (SQLException e) {
            //ignore
        }

        connection.createStatement().executeUpdate("create table month_batch (month varchar);");
        connection.createStatement().executeUpdate("create table sold_item (month varchar, name varchar, price decimal);");

        connection.createStatement().executeUpdate("insert into month_batch  values('Jan');");
        connection.createStatement().executeUpdate("insert into month_batch  values('Feb');");
        connection.createStatement().executeUpdate("insert into month_batch  values('March');");

        connection.createStatement().executeUpdate("insert into sold_item values('Jan', 'Apple', 100);");
        connection.createStatement().executeUpdate("insert into sold_item values('Jan', 'Cucumber', 200);");
        connection.createStatement().executeUpdate("insert into sold_item values('Jan', 'Tomato', 300);");

        connection.createStatement().executeUpdate("insert into sold_item values('Feb', 'Apple', 200);");
        connection.createStatement().executeUpdate("insert into sold_item values('Feb', 'Cucumber', 200);");

        connection.createStatement().executeUpdate("insert into sold_item values('March', 'Tomato', 500);");

        connection.commit();

        Report report = new DefaultXmlReader().parseXml(FileUtils.readFileToString(new File("./modules/core/test/sample/financedetails/breakdown.xml")));
        System.out.println();

        Reporting reporting = new Reporting();
        reporting.setFormatterFactory(new DefaultFormatterFactory());
        reporting.setLoaderFactory(new DefaultLoaderFactory()
                .setGroovyDataLoader(new GroovyDataLoader(new DefaultScriptingImpl()))
                .setSqlDataLoader(new SqlDataLoader(testDatabase.getDs())));

        ReportOutputDocument reportOutputDocument = reporting.runReport(new RunParams(report), new FileOutputStream("./result/sample/breakdown.xls"));

        testDatabase.stop();
    }
View Full Code Here

TOP

Related Classes of utils.TestDatabase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.