org.dbunit.dataset.IDataSet Java Examples
The following examples show how to use
org.dbunit.dataset.IDataSet.
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: EmpireBatchDaoTest.java From proarc with GNU General Public License v3.0 | 6 votes |
@Test public void testUpdate() throws Exception { IDataSet db = database( support.loadFlatXmlDataStream(getClass(), "user.xml"), support.loadFlatXmlDataStream(getClass(), "batch.xml") ); support.cleanInsert(support.getConnection(tx), db); tx.commit(); Batch batch = dao.find(1); State expectedState = State.INGESTING; batch.setState(expectedState); String expectedLog = "updated log"; batch.setLog(expectedLog); Timestamp timestamp = batch.getTimestamp(); dao.update(batch); tx.commit(); batch = dao.find(1); assertEquals(expectedState, batch.getState()); assertEquals(expectedLog, batch.getLog()); assertTrue(timestamp.before(batch.getTimestamp())); }
Example #2
Source File: EmpireWorkflowJobDaoTest.java From proarc with GNU General Public License v3.0 | 6 votes |
@Test public void testView() throws Exception { IDataSet db = database( support.loadFlatXmlDataStream(getClass(), "user.xml"), support.loadFlatXmlDataStream(getClass(), "wf_job.xml") ); support.cleanInsert(support.getConnection(tx), db); tx.commit(); JobFilter filter = new JobFilter(); filter.setId(BigDecimal.ONE); filter.setLabel("Monograph1"); List<JobView> jobs = dao.view(filter); assertEquals(1, jobs.size()); JobView job0 = jobs.get(0); assertEquals(BigDecimal.ONE, job0.getId()); assertEquals("job.ndk", job0.getProfileName()); assertEquals("test", job0.getUserName()); }
Example #3
Source File: TestUserDao.java From SpringCloud with Apache License 2.0 | 6 votes |
@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 #4
Source File: UserDaoTest.java From wetech-cms with MIT License | 6 votes |
@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 #5
Source File: SqlDbFeatureExecutor.java From jpa-unit with Apache License 2.0 | 6 votes |
@Override protected DbFeature<IDatabaseConnection> createVerifyDataAfterFeature(final ExpectedDataSets expectedDataSets) { return (final IDatabaseConnection connection) -> { try { final IDataSet currentDataSet = connection.createDataSet(); final IDataSet expectedDataSet = mergeDataSets(loadDataSets(Arrays.asList(expectedDataSets.value()))); final DataSetComparator dataSetComparator = new DataSetComparator(expectedDataSets.orderBy(), expectedDataSets.excludeColumns(), expectedDataSets.strict(), getColumnFilter(expectedDataSets)); final AssertionErrorCollector errorCollector = new AssertionErrorCollector(); dataSetComparator.compare(currentDataSet, expectedDataSet, errorCollector); errorCollector.report(); } catch (final SQLException | DatabaseUnitException e) { throw new DbFeatureException("Could not execute DB contents verification feature", e); } }; }
Example #6
Source File: EmpireWorkflowParameterDaoTest.java From proarc with GNU General Public License v3.0 | 6 votes |
@Test public void testRemove() throws Exception { IDataSet db = database( support.loadFlatXmlDataStream(getClass(), "user.xml"), support.loadFlatXmlDataStream(getClass(), "wf_job.xml"), support.loadFlatXmlDataStream(getClass(), "wf_task.xml"), support.loadFlatXmlDataStream(getClass(), "wf_param.xml") ); support.cleanInsert(support.getConnection(tx), db); tx.commit(); Task task = new Task().addId(BigDecimal.ONE); List<TaskParameter> params = dao.find(task.getId()); assertEquals(2, params.size()); dao.remove(task.getId()); tx.commit(); params = dao.find(task.getId()); assertEquals(0, params.size()); }
Example #7
Source File: EmpireWorkflowMaterialDaoTest.java From proarc with GNU General Public License v3.0 | 6 votes |
@Test public void testFindJob() throws Exception { IDataSet db = database( support.loadFlatXmlDataStream(getClass(), "user.xml"), support.loadFlatXmlDataStream(getClass(), "wf_job.xml"), support.loadFlatXmlDataStream(getClass(), "wf_task.xml"), support.loadFlatXmlDataStream(getClass(), "wf_material.xml") ); support.cleanInsert(support.getConnection(tx), db); tx.commit(); Material m = new Material(); m.setId(BigDecimal.ONE); Job job = dao.findJob(m); assertNotNull(job); assertEquals(BigDecimal.ONE, job.getId()); }
Example #8
Source File: DataSetBuilderExporterIt.java From database-rider with Apache License 2.0 | 6 votes |
@Test public void shouldExportEmptyTablesUsingColumnValuesSyntax() { executor.createDataSet(new DataSetConfig("yml/empty.yml")); IDataSet iDataSet = createDataSetFromDatabase(); File outputDir = Paths.get("target/FromEmptyYamlColumnValuesSyntax.java").toAbsolutePath().toFile(); new DataSetBuilderExporter().export(iDataSet, new BuilderExportConfig(BuilderType.COLUMNS_VALUES, outputDir)); assertThat(contentOf(outputDir)). contains("DataSetBuilder builder = new DataSetBuilder();" + NEW_LINE + "IDataSet dataSet = builder" + NEW_LINE + " .table(\"FOLLOWER\")" + NEW_LINE + " .table(\"SEQUENCE\")" + NEW_LINE + " .columns(\"SEQ_NAME\", \"SEQ_COUNT\")" + NEW_LINE + " .values(\"SEQ_GEN\", 0)" + NEW_LINE + " .table(\"TWEET\")" + NEW_LINE + " .table(\"USER\").build();"); }
Example #9
Source File: TestUserDao.java From SpringCloud with Apache License 2.0 | 6 votes |
@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 #10
Source File: Fixtures.java From base-framework with Apache License 2.0 | 6 votes |
/** * 对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: DatabaseTaskHandler.java From development with Apache License 2.0 | 6 votes |
public static void dropTables(String filePath) throws DataSetException, IOException, SQLException { IDataSet tablesToDelete = new FlatXmlDataSetBuilder().build(new File( filePath)); String[] tableNames = tablesToDelete.getTableNames(); Statement stmt = conn.createStatement(); String queryString = "DROP TABLE %s CASCADE"; for (int i = tableNames.length - 1; i >= 0; i--) { // first drop constraints to the table deleteConstraints(tableNames[i]); // now drop the table itself String tableName = tableNames[i]; try { String query = String.format(queryString, tableName); stmt.executeUpdate(query); System.out.println(query); } catch (SQLException e) { System.out.println(e.getMessage()); } } stmt.close(); }
Example #12
Source File: KylinTestBase.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
protected void verifyResultContent(String queryFolder) throws Exception { logger.info("---------- verify result content in folder: " + queryFolder); List<File> sqlFiles = getFilesFromFolder(new File(queryFolder), ".sql"); for (File sqlFile : sqlFiles) { String queryName = StringUtils.split(sqlFile.getName(), '.')[0]; String sql = getTextFromFile(sqlFile); File expectResultFile = new File(sqlFile.getParent(), sqlFile.getName() + ".expected.xml"); IDataSet expect = new FlatXmlDataSetBuilder().build(expectResultFile); // Get expected table named "expect". FIXME Only support default table name ITable expectTable = expect.getTable("expect"); // execute Kylin logger.info("Query Result from Kylin - " + queryName + " (" + queryFolder + ")"); IDatabaseConnection kylinConn = new DatabaseConnection(cubeConnection); ITable kylinTable = executeQuery(kylinConn, queryName, sql, false); // compare the result assertTableEquals(expectTable, kylinTable); } }
Example #13
Source File: EmpireWorkflowTaskDaoTest.java From proarc with GNU General Public License v3.0 | 6 votes |
@Test public void testView() throws Exception { IDataSet db = database( support.loadFlatXmlDataStream(getClass(), "user.xml"), support.loadFlatXmlDataStream(getClass(), "wf_job.xml"), support.loadFlatXmlDataStream(getClass(), "wf_task.xml") ); support.cleanInsert(support.getConnection(tx), db); tx.commit(); TaskFilter filter = new TaskFilter(); filter.setJobId(BigDecimal.ONE); filter.setJobLabel("Monograph1"); List<TaskView> tasks = dao.view(filter); assertEquals(1, tasks.size()); TaskView t = tasks.get(0); assertEquals(BigDecimal.ONE, t.getId()); assertEquals(State.STARTED, t.getState()); assertEquals("Monograph1", t.getJobLabel()); assertEquals("test", t.getUserName()); filter = new TaskFilter(); filter.setProfileName(Arrays.asList("task.id1", "task.id2")); tasks = dao.view(filter); assertEquals(2, tasks.size()); }
Example #14
Source File: DataSetLoaderProviderTest.java From jpa-unit with Apache License 2.0 | 6 votes |
@Test public void testCsvLoaderLoadUsingProperResource() throws Exception { // WHEN final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.csvLoader(); // THEN assertThat(loader, notNullValue()); // WHEN final IDataSet dataSet = loader.load(getFile("test-data")); // THEN assertThat(dataSet, notNullValue()); final List<String> tableNames = Arrays.asList(dataSet.getTableNames()); assertThat(tableNames.size(), equalTo(2)); assertThat(tableNames, hasItems("CSV_TABLE_1", "CSV_TABLE_2")); final ITable table1 = dataSet.getTable("CSV_TABLE_1"); assertThat(table1.getRowCount(), equalTo(3)); final ITable table2 = dataSet.getTable("CSV_TABLE_2"); assertThat(table2.getRowCount(), equalTo(1)); }
Example #15
Source File: UserDaoTest.java From wetech-cms with MIT License | 6 votes |
@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 #16
Source File: UserManagerSqlTest.java From proarc with GNU General Public License v3.0 | 5 votes |
@Before public void setUp() throws Exception { // fedora init fedora = new FedoraTestSupport(); fedora.cleanUp(); remoteStorage = fedora.getRemoteStorage(); // rdbms init db = new DbUnitSupport(); EmpireDaoFactory daos = new EmpireDaoFactory(db.getEmireCfg()); daos.init(); DataSource dataSource = EasyMock.createMock(DataSource.class); EasyMock.expect(dataSource.getConnection()).andAnswer(new IAnswer<Connection>() { @Override public Connection answer() throws Throwable { return db.getEmireCfg().getConnection(); } }).anyTimes(); IDataSet database = database( // XXX related fedora objects do not exist! db.loadFlatXmlDataStream(EmpireUserDaoTest.class, "user.xml") // db.loadFlatXmlDataStream(getClass(), "group.xml") ); final IDatabaseConnection con = db.getConnection(); try { db.cleanInsert(con, database); db.initSequences(con.getConnection(), 10, db.getEmireCfg().getSchema().tableUser.id.getSequenceName()); db.initSequences(con.getConnection(), 10, db.getEmireCfg().getSchema().tableUserGroup.id.getSequenceName()); con.getConnection().commit(); } finally { con.getConnection().close(); } EasyMock.replay(dataSource); manager = new UserManagerSql(dataSource, temp.getRoot(), remoteStorage, daos); }
Example #17
Source File: AbstractDBUnitHibernateMemoryTest.java From livingdoc-confluence with GNU General Public License v3.0 | 5 votes |
protected void assertTableEmpty(Class<?> peristentClass) throws Exception { // Fetch database data after executing your code IDataSet databaseDataSet = getConnection().createDataSet(); ITable actualTable = databaseDataSet.getTable(getTableName(peristentClass)); assertTrue(actualTable.getRowCount() == 0); }
Example #18
Source File: UserDaoTest.java From wetech-cms with MIT License | 5 votes |
@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 #19
Source File: DataSetProviderIt.java From database-rider with Apache License 2.0 | 5 votes |
@Override public IDataSet provide() { DataSetBuilder builder = new DataSetBuilder(); ColumnSpec id = ColumnSpec.of("ID"); ColumnSpec name = ColumnSpec.of("NAME"); IDataSet dataSet = builder .table("USER") //start adding rows to 'USER' table .row() .column("ID", 1) .column(name, "@dbunit") .row() //keeps adding rows to the current table .column(id, 2) .column("NAME", "@dbrider") .table("TWEET") //starts adding rows to 'TWEET' table .row() .column("ID", "abcdef12345") .column("CONTENT", "dbunit rules!") .column("DATE", "[DAY,NOW]") .table("FOLLOWER") .row() .column(id, 1) .column("USER_ID", 9999) .column("FOLLOWER_ID", 9999) .table("USER")// we still can add rows to table already added to the dataset .row() .column("ID", 3) .column(name, "@new row") .build(); return dataSet; }
Example #20
Source File: CleanupStrategyProviderTest.java From jpa-unit with Apache License 2.0 | 5 votes |
@Test public void testStrictCleanupWithInitialDataSets() throws Exception { // GIVEN final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.strictStrategy(); assertThat(strategyExecutor, notNullValue()); // WHEN strategyExecutor.execute(connection, Arrays.asList(initialDataSet)); // THEN assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(0)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(0)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(0)); }
Example #21
Source File: EmpireWorkflowJobDaoTest.java From proarc with GNU General Public License v3.0 | 5 votes |
@Test public void testCreate() throws Exception { IDataSet db = database( support.loadFlatXmlDataStream(getClass(), "user.xml") ); support.cleanInsert(support.getConnection(tx), db); Job job = dao.create(); job.addCreated(dbTimestamp).addFinanced("financed").addLabel("label") .addNote("note").addOwnerId(BigDecimal.ONE).addPriority(1) .addProfileName("profile").setState(State.OPEN).addTimestamp(dbTimestamp); dao.update(job); tx.commit(); Job result = dao.find(job.getId()); assertNotNull(result); assertEquals(job.getCreated(), result.getCreated()); assertEquals(job.getFinanced(), result.getFinanced()); assertEquals(job.getId(), result.getId()); assertEquals(job.getLabel(), result.getLabel()); assertEquals(job.getNote(), result.getNote()); assertEquals(job.getOwnerId(), result.getOwnerId()); assertEquals(job.getPriority(), result.getPriority()); assertEquals(job.getProfileName(), result.getProfileName()); assertEquals(job.getState(), result.getState()); assertEquals(job.getTimestamp(), result.getTimestamp()); }
Example #22
Source File: DatabaseConfigurationTestHelper.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * 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 #23
Source File: SchemaUpgradeTestBase.java From development with Apache License 2.0 | 5 votes |
protected IDataSet loadDataSet(URL source) throws Exception { final FlatXmlDataSetBuilder xmlData = new FlatXmlDataSetBuilder(); xmlData.setColumnSensing(true); final ReplacementDataSet set = new ReplacementDataSet( xmlData.build(source)); set.addReplacementObject("[NULL]", null); return set; }
Example #24
Source File: AttachmentDaoTest.java From wetech-cms with MIT License | 5 votes |
@Before public void setUp() throws SQLException, IOException, DatabaseUnitException { //此时最好不要使用Spring的Transactional来管理,因为dbunit是通过jdbc来处理connection,再使用spring在一些编辑操作中会造成事务shisu Session s = sessionFactory.openSession(); TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(s)); this.backupAllTable(); IDataSet ds = createDateSet("topic"); DatabaseOperation.CLEAN_INSERT.execute(dbunitCon,ds); }
Example #25
Source File: EmpireWorkflowTaskDaoTest.java From proarc with GNU General Public License v3.0 | 5 votes |
private IDataSet database(IDataSet... ds) throws Exception { ReplacementDataSet rds = new ReplacementDataSet(new CompositeDataSet(ds)); rds.addReplacementObject("{$user.home}", "relative/path/"); dbTimestamp = new Timestamp(System.currentTimeMillis()); rds.addReplacementObject("{$now}", dbTimestamp); return rds; }
Example #26
Source File: DataSetLoaderProvider.java From jpa-unit with Apache License 2.0 | 5 votes |
@Override public DataSetLoader<IDataSet> xmlLoader() { return (final File path) -> { try (InputStream in = new FileInputStream(path)) { final FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder(); flatXmlDataSetBuilder.setColumnSensing(true); return defineReplaceableExpressions(flatXmlDataSetBuilder.build(in)); } catch (final DataSetException e) { throw new IOException(e); } }; }
Example #27
Source File: AbstractDaoTestCase.java From Asqatasun with GNU Affero General Public License v3.0 | 5 votes |
/** * Charge le jeu de données à partir d'un fichier XML d'import */ @Override protected IDataSet getDataSet() throws Exception { FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder(); FlatXmlDataSet loadedDataSet = flatXmlDataSetBuilder.build(new FileInputStream( getInputDataFileName())); return loadedDataSet; }
Example #28
Source File: HsqldbSequenceResetter.java From JavaSpringMvcBlog with MIT License | 5 votes |
@Override public void execute(IDatabaseConnection connection, IDataSet dataSet) throws DatabaseUnitException, SQLException { String[] tables = dataSet.getTableNames(); Statement statement = connection.getConnection().createStatement(); for (String table : tables) { statement.execute("TRUNCATE TABLE " + table + " RESTART IDENTITY AND COMMIT NO CHECK"); } }
Example #29
Source File: DataSetBuilderTest.java From database-rider with Apache License 2.0 | 5 votes |
@Test public void shouldGenerateFlatXmlDataSet() throws DataSetException, IOException { DataSetBuilder builder = new DataSetBuilder(); ColumnSpec id = ColumnSpec.of("ID"); builder.table("USER") .row() .column("ID", 1) .column("NAME", "@realpestano") .table("USER") .row().column(id, 2) .column("NAME", "@dbunit") .table("TWEET") .row() .column("ID", "abcdef12345") .column("CONTENT", "dbunit rules!") .column("DATE", "[DAY,NOW]") .table("FOLLOWER") .row() .column(id, 1) .column("USER_ID", 1) .column("FOLLOWER_ID", 2) .build(); IDataSet dataSet = builder.build(); File datasetFile = Files.createTempFile("rider-dataset", ".xml").toFile(); FileOutputStream fos = new FileOutputStream(datasetFile); FlatXmlDataSet.write(dataSet, fos); assertThat(contentOf(datasetFile)). contains("<?xml version='1.0' encoding='UTF-8'?>"+NEW_LINE + "<dataset>"+NEW_LINE + " <USER ID=\"1\" NAME=\"@realpestano\"/>"+NEW_LINE + " <USER ID=\"2\" NAME=\"@dbunit\"/>"+NEW_LINE + " <TWEET ID=\"abcdef12345\" CONTENT=\"dbunit rules!\" DATE=\"[DAY,NOW]\"/>"+NEW_LINE + " <FOLLOWER ID=\"1\" USER_ID=\"1\" FOLLOWER_ID=\"2\"/>"+NEW_LINE + "</dataset>"); }
Example #30
Source File: TestUserDao.java From SpringCloud with Apache License 2.0 | 5 votes |
@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); }