org.dbunit.operation.DatabaseOperation Java Examples

The following examples show how to use org.dbunit.operation.DatabaseOperation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestUserDao.java    From SpringCloud with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindByArgs() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    SystemContext.setOrder("desc");
    SystemContext.setSort("id");
    SystemContext.setPageSize(3);
    SystemContext.setPageOffset(0);
    Pager<User> expected = userDao.find("from User where id>=? and id<=?", new Object[] { 1, 10 });
    List<User> actuals = Arrays.asList(new User(10, "admin10"), new User(9, "admin9"), new User(8, "admin8"));
    assertNotNull(expected);
    assertTrue(expected.getTotal() == 10);
    assertTrue(expected.getOffset() == 0);
    assertTrue(expected.getSize() == 3);
    EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
Example #2
Source File: CleanupStrategyProviderTest.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    initialDataSet = new FlatXmlDataSetBuilder().build(new File("src/test/resources/test-data.xml"));
    connection = new DatabaseConnection(DriverManager.getConnection(CONNECTION_URL, USER_NAME, PASSWORD));

    final DatabaseOperation operation = DatabaseOperation.CLEAN_INSERT;
    operation.execute(connection, initialDataSet);

    connection.getConnection().createStatement().execute(
            "insert into XML_TABLE_1(id, version, value_1, value_2, value_3, value_4, value_5) values(10, 'Record 10 version', 'Record 10 Value 1', 'Record 10 Value 2', 'Record 10 Value 3', 'Record 10 Value 4', 'Record 10 Value 5');");
    connection.getConnection().commit();

    connection.getConnection().createStatement().execute(
            "merge into XML_TABLE_3(id, version, value_8, value_9) values(11, 'Record 11 version', 'Record 11 Value 8', 'Record 11 Value 9');");
    connection.getConnection().commit();

    assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(4));
    assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(1));
    assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(1));
}
 
Example #3
Source File: TestUserDao.java    From SpringCloud with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindByArgsAndAlias() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    SystemContext.removeOrder();
    SystemContext.removeSort();
    SystemContext.setPageSize(3);
    SystemContext.setPageOffset(0);
    Map<String, Object> alias = new HashMap<String, Object>();
    alias.put("ids", Arrays.asList(1, 2, 4, 5, 6, 7, 8, 10));
    Pager<User> expected = userDao.find("from User where id>=? and id<=? and id in (:ids)", new Object[] { 1, 10 },
            alias);
    List<User> actuals = Arrays.asList(new User(1, "admin1"), new User(2, "admin2"), new User(4, "admin4"));
    assertNotNull(expected);
    assertTrue(expected.getTotal() == 8);
    assertTrue(expected.getOffset() == 0);
    assertTrue(expected.getSize() == 3);
    EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
Example #4
Source File: CleanupStrategyProvider.java    From jpa-unit with Apache License 2.0 6 votes vote down vote up
@Override
public CleanupStrategyExecutor<IDatabaseConnection, IDataSet> usedTablesOnlyStrategy() {
    return (final IDatabaseConnection connection, final List<IDataSet> initialDataSets, final String... tablesToExclude) -> {
        if (initialDataSets.isEmpty()) {
            return;
        }

        try {
            IDataSet dataSet = excludeTables(mergeDataSets(initialDataSets), tablesToExclude);
            dataSet = new FilteredDataSet(new DatabaseSequenceFilter(connection), dataSet);
            DatabaseOperation.DELETE_ALL.execute(connection, dataSet);
        } catch (final SQLException | DatabaseUnitException e) {
            throw new DbFeatureException(UNABLE_TO_CLEAN_DATABASE, e);
        }
    };
}
 
Example #5
Source File: UserDaoTest.java    From wetech-cms with MIT License 6 votes vote down vote up
@Test
public void testFindSQLByArgsAndAlias() throws DatabaseUnitException, SQLException {
	IDataSet ds = createDateSet("t_user");
	DatabaseOperation.CLEAN_INSERT.execute(dbunitCon,ds);
	SystemContext.removeOrder();
	SystemContext.removeSort();
	SystemContext.setPageSize(3);
	SystemContext.setPageOffset(0);
	Map<String,Object> alias = new HashMap<String,Object>();
	alias.put("ids", Arrays.asList(1,2,4,5,6,7,8,10));
	Pager<User> expected = userDao.findUserBySql("select * from t_user where id>=? and id<=? and id in (:ids)", new Object[]{1,10},alias,User.class,true);
	List<User> actuals = Arrays.asList(new User(1,"admin1"),new User(2,"admin2"),new User(4,"admin4"));
	assertNotNull(expected);
	assertTrue(expected.getTotal()==8);
	assertTrue(expected.getOffset()==0);
	assertTrue(expected.getSize()==3);
	EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
Example #6
Source File: TestUserDao.java    From SpringCloud with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindSQLByArgs() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    SystemContext.setOrder("desc");
    SystemContext.setSort("id");
    SystemContext.setPageSize(3);
    SystemContext.setPageOffset(0);
    Pager<User> expected = userDao.findUserBySql("select * from t_user where id>=? and id<=?",
            new Object[] { 1, 10 }, User.class, true);
    List<User> actuals = Arrays.asList(new User(10, "admin10"), new User(9, "admin9"), new User(8, "admin8"));
    assertNotNull(expected);
    assertTrue(expected.getTotal() == 10);
    assertTrue(expected.getOffset() == 0);
    assertTrue(expected.getSize() == 3);
    EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
Example #7
Source File: TestUserDao.java    From SpringCloud with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindSQLByArgsAndAlias() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    SystemContext.removeOrder();
    SystemContext.removeSort();
    SystemContext.setPageSize(3);
    SystemContext.setPageOffset(0);
    Map<String, Object> alias = new HashMap<String, Object>();
    alias.put("ids", Arrays.asList(1, 2, 4, 5, 6, 7, 8, 10));
    Pager<User> expected = userDao.findUserBySql("select * from t_user where id>=? and id<=? and id in (:ids)",
            new Object[] { 1, 10 }, alias, User.class, true);
    List<User> actuals = Arrays.asList(new User(1, "admin1"), new User(2, "admin2"), new User(4, "admin4"));
    assertNotNull(expected);
    assertTrue(expected.getTotal() == 8);
    assertTrue(expected.getOffset() == 0);
    assertTrue(expected.getSize() == 3);
    EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
Example #8
Source File: UserDaoTest.java    From wetech-cms with MIT License 6 votes vote down vote up
@Test
public void testFindSQLByArgs() throws DatabaseUnitException, SQLException {
	IDataSet ds = createDateSet("t_user");
	DatabaseOperation.CLEAN_INSERT.execute(dbunitCon,ds);
	SystemContext.setOrder("desc");
	SystemContext.setSort("id");
	SystemContext.setPageSize(3);
	SystemContext.setPageOffset(0);
	Pager<User> expected = userDao.findUserBySql("select * from t_user where id>=? and id<=?", new Object[]{1,10},User.class,true);
	List<User> actuals = Arrays.asList(new User(10,"admin10"),new User(9,"admin9"),new User(8,"admin8"));
	assertNotNull(expected);
	assertTrue(expected.getTotal()==10);
	assertTrue(expected.getOffset()==0);
	assertTrue(expected.getSize()==3);
	EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
Example #9
Source File: DataSetExecutorImpl.java    From database-rider with Apache License 2.0 6 votes vote down vote up
private DatabaseOperation getOperation(DataSetConfig dataSetConfig) {
    SeedStrategy strategy = dataSetConfig.getstrategy();
    if (getRiderDataSource().getDBType() == RiderDataSource.DBType.MSSQL && dataSetConfig.isFillIdentityColumns()) {
        switch (strategy) {
            case INSERT:
                return InsertIdentityOperation.INSERT;
            case REFRESH:
                return InsertIdentityOperation.REFRESH;
            case CLEAN_INSERT:
                return InsertIdentityOperation.CLEAN_INSERT;
            case TRUNCATE_INSERT:
                return new CompositeOperation(DatabaseOperation.TRUNCATE_TABLE,
                        InsertIdentityOperation.INSERT);
        }
    }
    return strategy.getOperation();
}
 
Example #10
Source File: Fixtures.java    From base-framework with Apache License 2.0 6 votes vote down vote up
/**
 * 对XML文件中的数据在H2数据库中执行Operation.
 * 
 * @param xmlFilePaths 符合Spring Resource路径格式的文件列表.
 */
private static void execute(DatabaseOperation operation, DataSource dataSource, String... xmlFilePaths)
		throws DatabaseUnitException, SQLException {
	//注意这里HardCode了使用H2的Connetion
	IDatabaseConnection connection = new H2Connection(dataSource.getConnection(), null);

	for (String xmlPath : xmlFilePaths) {
		try {
			InputStream input = resourceLoader.getResource(xmlPath).getInputStream();
			IDataSet dataSet = new FlatXmlDataSetBuilder().setColumnSensing(true).build(input);
			operation.execute(connection, dataSet);
		} catch (IOException e) {
			logger.warn(xmlPath + " file not found", e);
		}finally{
			connection.close();
		}
	}
}
 
Example #11
Source File: UserDaoTest.java    From wetech-cms with MIT License 6 votes vote down vote up
@Test
public void testFindByArgsAndAlias() throws DatabaseUnitException, SQLException {
	IDataSet ds = createDateSet("t_user");
	DatabaseOperation.CLEAN_INSERT.execute(dbunitCon,ds);
	SystemContext.removeOrder();
	SystemContext.removeSort();
	SystemContext.setPageSize(3);
	SystemContext.setPageOffset(0);
	Map<String,Object> alias = new HashMap<String,Object>();
	alias.put("ids", Arrays.asList(1,2,4,5,6,7,8,10));
	Pager<User> expected = userDao.find("from User where id>=? and id<=? and id in (:ids)", new Object[]{1,10},alias);
	List<User> actuals = Arrays.asList(new User(1,"admin1"),new User(2,"admin2"),new User(4,"admin4"));
	assertNotNull(expected);
	assertTrue(expected.getTotal()==8);
	assertTrue(expected.getOffset()==0);
	assertTrue(expected.getSize()==3);
	EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
Example #12
Source File: UserDaoTest.java    From wetech-cms with MIT License 6 votes vote down vote up
@Test
public void testFindByArgs() throws DatabaseUnitException, SQLException {
	IDataSet ds = createDateSet("t_user");
	DatabaseOperation.CLEAN_INSERT.execute(dbunitCon,ds);
	SystemContext.setOrder("desc");
	SystemContext.setSort("id");
	SystemContext.setPageSize(3);
	SystemContext.setPageOffset(0);
	Pager<User> expected = userDao.find("from User where id>=? and id<=?", new Object[]{1,10});
	List<User> actuals = Arrays.asList(new User(10,"admin10"),new User(9,"admin9"),new User(8,"admin8"));
	assertNotNull(expected);
	assertTrue(expected.getTotal()==10);
	assertTrue(expected.getOffset()==0);
	assertTrue(expected.getSize()==3);
	EntitiesHelper.assertUsers(expected.getDatas(), actuals);
}
 
Example #13
Source File: TestUserDao.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoad() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    User u = userDao.load(1);
    EntitiesHelper.assertUser(u);
}
 
Example #14
Source File: TestUserDao.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Test(expected = ObjectNotFoundException.class)
public void testDelete() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    userDao.delete(1);
    User tu = userDao.load(1);
    System.out.println(tu.getUsername());
}
 
Example #15
Source File: UserDaoTest.java    From wetech-cms with MIT License 5 votes vote down vote up
@Test
public void testLoad() throws DatabaseUnitException, SQLException {
	IDataSet ds = createDateSet("t_user");
	DatabaseOperation.CLEAN_INSERT.execute(dbunitCon,ds);
	User u = userDao.load(1);
	EntitiesHelper.assertUser(u);
}
 
Example #16
Source File: BasePaymentModuleDBTestCase.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
protected AbstractDatabaseTester createDatabaseTester() throws Exception {
    AbstractDatabaseTester dbTester = new JdbcDatabaseTester("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:testyespaydb", "sa", "");
    dbTester.setSetUpOperation(DatabaseOperation.REFRESH);
    dbTester.setTearDownOperation(DatabaseOperation.NONE);
    dbTester.setDataSet(createDataSet());
    return dbTester;
}
 
Example #17
Source File: ProarcDatabaseTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testUpgrade() throws Exception {
    ProarcDatabaseV1 v1 = new ProarcDatabaseV1();
    ProarcDatabaseV2 v2 = new ProarcDatabaseV2();
    ProarcDatabaseV3 v3 = new ProarcDatabaseV3();
    ProarcDatabaseV4 v4 = new ProarcDatabaseV4();
    final IDatabaseConnection con = support.getConnection();
    try {
        // clear DB
        dropSchema(schema);
        dropSchema(v4);
        dropSchema(v3);
        dropSchema(v2);
        dropSchema(v1);
        v1.init(emireCfg);
        assertEquals(1, ProarcDatabase.schemaExists(schema, con.getConnection()));

        IDataSet db = support.loadFlatXmlDataStream(getClass(), "proarc_v1.xml", true);
        try {
            DatabaseOperation.INSERT.execute(con, db);
            con.getConnection().commit();
        } finally {
            support.clearDtdSchema();
        }
        schema.init(emireCfg);
        assertEquals(ProarcDatabase.VERSION, ProarcDatabase.schemaExists(schema, con.getConnection()));
    } finally {
        con.close();
        dropSchema(schema);
        dropSchema(v1);
    }
}
 
Example #18
Source File: AbstractModelTest.java    From pnc with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts data into database from the dbunit XML file
 * 
 * @param em Entity manager
 * @param datasetPath Path to DBunit dataset file
 * @throws Exception Thrown in case of any error during the operation
 */
protected void initDatabaseUsingDataset(EntityManager em, String datasetPath) throws Exception {
    IDatabaseConnection connection = new DatabaseConnection(em.unwrap(SessionImpl.class).connection());
    connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
    FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder();
    flatXmlDataSetBuilder.setColumnSensing(true);
    InputStream dataSetStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(datasetPath);
    IDataSet dataSet = flatXmlDataSetBuilder.build(dataSetStream);
    DatabaseOperation.INSERT.execute(connection, dataSet);
}
 
Example #19
Source File: DatabaseTaskHandler.java    From development with Apache License 2.0 5 votes vote down vote up
public static void cleanDatabase() throws IOException, DataSetException,
        DatabaseUnitException, SQLException {
    String filePath = ROOT_PATH + "javares/devscripts/deleteDbContent.xml";
    String tableList = DatabaseTaskHandler.class.getResource(".").getFile()
            + filePath;
    IDataSet dataToDelete = new FlatXmlDataSetBuilder().build(new File(
            tableList));
    DatabaseOperation.DELETE_ALL.execute(dbConn, dataToDelete);
}
 
Example #20
Source File: WebResourceDAOImplTest.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
public WebResourceDAOImplTest(String testName) {
    super(testName);
    setInputDataFileName(getInputDataFilePath()+INPUT_DATA_SET_FILENAME);
    auditDAO = (AuditDAO)
            springBeanFactory.getBean("auditDAO");
    webresourceDAO = (WebResourceDAO)
            springBeanFactory.getBean("webresourceDAO");
    setTeardownOperationValue(DatabaseOperation.DELETE);
}
 
Example #21
Source File: ContentDAOImplTest.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
public ContentDAOImplTest(String testName) {
    super(testName);
    setInputDataFileName(getInputDataFilePath()+INPUT_DATA_SET_FILENAME);
    webresourceDAO = (WebResourceDAO)
            springBeanFactory.getBean("webresourceDAO");
    auditDAO = (AuditDAO)
            springBeanFactory.getBean("auditDAO");
    contentDAO = (ContentDAO)
            springBeanFactory.getBean("contentDAO");
    setTeardownOperationValue(DatabaseOperation.DELETE);
}
 
Example #22
Source File: AuditDAOImplTest.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
public AuditDAOImplTest(String testName) {
    super(testName);
    setInputDataFileName(getInputDataFilePath()+INPUT_DATA_SET_FILENAME);
    auditDAO = (AuditDAO)
            springBeanFactory.getBean("auditDAO");
    if (!testName.equalsIgnoreCase("testFindAuditWithTest")) {
        setTeardownOperationValue(DatabaseOperation.DELETE);
    }
}
 
Example #23
Source File: DatabaseConfigurationTestHelper.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the internal data source. This method also initializes the
 * database.
 *
 * @return the data source
 * @throws Exception if an error occurs
 */
private DataSource setUpDataSource() throws Exception
{
    final BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(DATABASE_DRIVER);
    ds.setUrl(DATABASE_URL);
    ds.setUsername(DATABASE_USERNAME);
    ds.setPassword(DATABASE_PASSWORD);
    ds.setDefaultAutoCommit(!isAutoCommit());

    // prepare the database
    final Connection conn = ds.getConnection();
    final IDatabaseConnection connection = new DatabaseConnection(conn);
    final IDataSet dataSet = new XmlDataSet(new FileInputStream(
            ConfigurationAssert.getTestFile("dataset.xml")));

    try
    {
        DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
    }
    finally
    {
        if (!isAutoCommit())
        {
            conn.commit();
        }
        connection.close();
    }

    return ds;
}
 
Example #24
Source File: AbstractDBUnitHibernateMemoryTest.java    From livingdoc-confluence with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This composite operation performs a deleteAllFromDatabase operation
 * followed by an insertIntoDatabase operation. This is the safest approach
 * to ensure that the database is in a known state. This is appropriate for
 * tests that require the database to only contain a specific set of data.
 *
 * @param dataSet
 * @throws Exception
 */
protected void cleanInsertIntoDatabase(IDataSet dataSet) throws Exception {
    IDatabaseConnection connection = null;

    try {
        connection = getConnection();
        DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
    } finally {
        closeConnection(connection);
    }
}
 
Example #25
Source File: TestDatabase.java    From development with Apache License 2.0 5 votes vote down vote up
public void insertData(URL dataSetUrl) throws Exception {
    System.out.println("Insert test data.");
    final IDataSet dataSet = loadDataSet(dataSetUrl);
    final DatabaseConnection connection = new DatabaseConnection(
            getDBconnection());
    DatabaseOperation.INSERT.execute(connection, dataSet);
}
 
Example #26
Source File: TestUserDao.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Test
public void testListByArgs() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    SystemContext.setOrder("desc");
    SystemContext.setSort("id");
    List<User> expected = userDao.list("from User where id>? and id<?", new Object[] { 1, 4 });
    List<User> actuals = Arrays.asList(new User(3, "admin3"), new User(2, "admin2"));
    assertNotNull(expected);
    assertTrue(expected.size() == 2);
    EntitiesHelper.assertUsers(expected, actuals);
}
 
Example #27
Source File: AbstractSQLTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
@Before
public final void importDataSet() throws Exception {
    for (DatabaseType databaseType : CURRENT_TEST_MODE.databaseTypes()) {
        DataBaseEnvironment dbEnv = new DataBaseEnvironment(databaseType);
        for (String each : getDataSetFiles()) {
            InputStream is = AbstractSQLTest.class.getClassLoader().getResourceAsStream(each);
            IDataSet dataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(is));
            IDatabaseTester databaseTester = new ShardingJdbcDatabaseTester(dbEnv.getDriverClassName(), dbEnv.getURL(getDatabaseName(each)),
                    dbEnv.getUsername(), dbEnv.getPassword(), dbEnv.getSchema(getDatabaseName(each)));
            databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
            databaseTester.setDataSet(dataSet);
            databaseTester.onSetup();
        }
    }
}
 
Example #28
Source File: TestUserDao.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Test
public void testListByArgsAndAlias() throws DatabaseUnitException, SQLException {
    IDataSet ds = createDateSet("t_user");
    DatabaseOperation.CLEAN_INSERT.execute(dbunitCon, ds);
    SystemContext.setOrder("asc");
    SystemContext.setSort("id");
    Map<String, Object> alias = new HashMap<String, Object>();
    alias.put("ids", Arrays.asList(1, 2, 3, 5, 6, 7, 8, 9, 10));
    List<User> expected = userDao.list("from User where id>? and id<? and id in(:ids)", new Object[] { 1, 5 },
            alias);
    List<User> actuals = Arrays.asList(new User(2, "admin2"), new User(3, "admin3"));
    assertNotNull(expected);
    assertTrue(expected.size() == 2);
    EntitiesHelper.assertUsers(expected, actuals);
}
 
Example #29
Source File: UserDaoTest.java    From wetech-cms with MIT License 5 votes vote down vote up
@Test
public void testListSQLByArgsAndAlias() throws DatabaseUnitException, SQLException {
	IDataSet ds = createDateSet("t_user");
	DatabaseOperation.CLEAN_INSERT.execute(dbunitCon,ds);
	SystemContext.setOrder("asc");
	SystemContext.setSort("id");
	Map<String,Object> alias = new HashMap<String,Object>();
	alias.put("ids", Arrays.asList(1,2,3,5,6,7,8,9,10));
	List<User> expected = userDao.listUserBySql("select * from t_user where id>? and id<? and id in(:ids)", new Object[]{1,5},alias,User.class,true);
	List<User> actuals = Arrays.asList(new User(2,"admin2"),new User(3,"admin3"));
	assertNotNull(expected);
	assertTrue(expected.size()==2);
	EntitiesHelper.assertUsers(expected, actuals);
}
 
Example #30
Source File: OldSchoolDbUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
private static IDatabaseTester initDatabaseTester() throws Exception {
    JdbcDatabaseTester tester = new JdbcDatabaseTester(JDBC_DRIVER, JDBC_URL, USER, PASSWORD);
    tester.setDataSet(initDataSet());
    tester.setSetUpOperation(DatabaseOperation.REFRESH);
    tester.setTearDownOperation(DatabaseOperation.DELETE_ALL);
    return tester;
}