Java Code Examples for org.dbunit.DatabaseUnitException

The following examples show how to use org.dbunit.DatabaseUnitException. These examples are extracted from open source projects. 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 Project: sharding-jdbc-1.5.1   Source File: DBUnitUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static IDatabaseConnection getConnection(final DataBaseEnvironment dbEnv, final Connection connection) throws DatabaseUnitException {
    switch (dbEnv.getDatabaseType()) {
        case H2:
            return new H2Connection(connection, "PUBLIC");
        case MySQL:
            return new MySqlConnection(connection, null);
        case PostgreSQL:
            DatabaseConnection databaseConnection = new DatabaseConnection(connection);
            databaseConnection.getConfig().setProperty("http://www.dbunit.org/properties/datatypeFactory", new PostgresqlDataTypeFactory());
            return databaseConnection;
        case Oracle:
            return new OracleConnection(connection, "JDBC");
        case SQLServer:
            return new MsSqlConnection(connection);
        default:
            throw new UnsupportedOperationException(dbEnv.getDatabaseType().name());
    }
}
 
Example 2
@Test
public void assertInsertWithAllPlaceholders() throws SQLException, DatabaseUnitException {
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        for (int i = 1; i <= 10; i++) {
            try (DynamicShardingValueHelper helper = new DynamicShardingValueHelper(i, i);
                 Connection connection = each.getValue().getConnection()) {
                PreparedStatement preparedStatement = connection.prepareStatement(DatabaseTestSQL.INSERT_ORDER_WITH_ALL_PLACEHOLDERS_SQL);
                preparedStatement.setInt(1, i);
                preparedStatement.setInt(2, i);
                preparedStatement.setString(3, "insert");
                preparedStatement.executeUpdate();
            }
        }
        assertDataSet(each.getValue().getConnection(), each.getKey(), "insert", "insert");
    }
}
 
Example 3
@Test
public void assertInsertWithAllPlaceholders() throws SQLException, DatabaseUnitException {
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        for (int i = 1; i <= 10; i++) {
            try (DynamicShardingValueHelper helper = new DynamicDatabaseShardingValueHelper(i);
                 Connection connection = each.getValue().getConnection();
                 PreparedStatement preparedStatement = connection.prepareStatement(DatabaseTestSQL.INSERT_ORDER_WITH_ALL_PLACEHOLDERS_SQL)) {
                preparedStatement.setInt(1, i);
                preparedStatement.setInt(2, i);
                preparedStatement.setString(3, "insert");
                preparedStatement.executeUpdate();
            }
        }
        assertDataSet(each.getValue().getConnection(), each.getKey(), "insert", "insert");
    }
}
 
Example 4
Source Project: jpa-unit   Source File: MsSqlConnectionFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConnection() throws DatabaseUnitException {
    // GIVEN
    final String schema = "foo";

    // WHEN
    final IDatabaseConnection dbConnection = FACTORY.createConnection(connection, schema);

    // THEN
    assertThat(dbConnection, notNullValue());

    final Object typeFactory = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY);
    assertThat(typeFactory, notNullValue());
    assertThat(typeFactory.getClass(), equalTo(MsSqlDataTypeFactory.class));

    assertThat(dbConnection.getSchema(), equalTo(schema));
}
 
Example 5
Source Project: wetech-cms   Source File: UserDaoTest.java    License: 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 Project: database-rider   Source File: ExportDataSetIt.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@DataSet(cleanBefore = true)
public void shouldExportYMLDataSetProgrammatically() throws SQLException, DatabaseUnitException {
    tx().begin();
    User u1 = new User();
    u1.setName("u1");
    EntityManagerProvider.em().persist(u1);
    tx().commit();
    DataSetExporter.getInstance().export(emProvider.connection(), new DataSetExportConfig().outputFileName("target/user.yml"));
    File ymlDataSet = new File("target/user.yml");
    assertThat(ymlDataSet).exists();
    assertThat(contentOf(ymlDataSet)).
            contains("USER:" + NEW_LINE +
                            "  - ID: " + u1.getId() + NEW_LINE +
                            "    NAME: \"u1\"" + NEW_LINE
            );
}
 
Example 7
Source Project: jpa-unit   Source File: HsqldbConnectionFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConnection() throws DatabaseUnitException {
    // GIVEN
    final String schema = "foo";

    // WHEN
    final IDatabaseConnection dbConnection = FACTORY.createConnection(connection, schema);

    // THEN
    assertThat(dbConnection, notNullValue());

    final Object typeFactory = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY);
    assertThat(typeFactory, notNullValue());
    assertThat(typeFactory.getClass(), equalTo(HsqldbDataTypeFactory.class));

    assertThat(dbConnection.getSchema(), equalTo(schema));
}
 
Example 8
Source Project: jpa-unit   Source File: Oracle10ConnectionFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Ignore("oracle jdbc required in classpath")
public void testCreateConnection() throws DatabaseUnitException, SQLException {
    // GIVEN
    final String schema = "foo";

    // WHEN
    final IDatabaseConnection dbConnection = FACTORY.createConnection(connection, schema);

    // THEN
    assertThat(dbConnection, notNullValue());

    final Object typeFactory = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY);
    assertThat(typeFactory, notNullValue());
    assertThat(typeFactory.getClass(), equalTo(Oracle10DataTypeFactory.class));

    assertThat(dbConnection.getSchema(), equalTo(schema));
}
 
Example 9
Source Project: jpa-unit   Source File: NetezzaConnectionFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConnection() throws DatabaseUnitException {
    // GIVEN
    final String schema = "foo";

    // WHEN
    final IDatabaseConnection dbConnection = FACTORY.createConnection(connection, schema);

    // THEN
    assertThat(dbConnection, notNullValue());

    final Object typeFactory = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY);
    assertThat(typeFactory, notNullValue());
    assertThat(typeFactory.getClass(), equalTo(NetezzaDataTypeFactory.class));

    final Object metadataHandler = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER);
    assertThat(metadataHandler, notNullValue());
    assertThat(metadataHandler.getClass(), equalTo(NetezzaMetadataHandler.class));

    assertThat(dbConnection.getSchema(), equalTo(schema));
}
 
Example 10
Source Project: database-rider   Source File: ExportNullPropertiesIt.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotExportNullColumnsInYMLDataSet() throws SQLException, DatabaseUnitException {
    DataSetExporter.getInstance().export(new DatabaseConnection(emProvider.connection()), new DataSetExportConfig().outputFileName("target/userWithNullProperty.yml"));
    File ymlDataSet = new File("target/userWithNullProperty.yml");
    assertThat(ymlDataSet).exists();
    assertThat(contentOf(ymlDataSet)).
            contains("FOLLOWER:" + NEW_LINE +
                            "" + NEW_LINE +
                            "SEQUENCE:" + NEW_LINE +
                            "  - SEQ_NAME: \"SEQ_GEN\"" + NEW_LINE +
                            "    SEQ_COUNT: 50" + NEW_LINE +
                            "" + NEW_LINE +
                            "TWEET:" + NEW_LINE +
                            "" + NEW_LINE +
                            "USER:" + NEW_LINE +
                            "  - ID: 1" + NEW_LINE + NEW_LINE
            );
}
 
Example 11
Source Project: database-rider   Source File: ExportNullPropertiesIt.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotExportNullColumnsInJSONDataSet() throws SQLException, DatabaseUnitException{
    DataSetExporter.getInstance().export(new DatabaseConnection(emProvider.connection()), new DataSetExportConfig().
            dataSetFormat(DataSetFormat.JSON).outputFileName("target/userWithNullProperty.json"));
    File jsonDataSet = new File("target/userWithNullProperty.json");
    assertThat(jsonDataSet).exists();
    assertThat(contentOf(jsonDataSet).replaceAll("\r","")).isEqualTo(("{"+NEW_LINE +
            "  \"FOLLOWER\": ["+NEW_LINE +
            "  ],"+NEW_LINE +
            "  \"SEQUENCE\": ["+NEW_LINE +
            "    {"+NEW_LINE +
            "      \"SEQ_NAME\": \"SEQ_GEN\","+NEW_LINE +
            "      \"SEQ_COUNT\": 50"+NEW_LINE +
            "    }"+NEW_LINE +
            "  ],"+NEW_LINE +
            "  \"TWEET\": ["+NEW_LINE +
            "  ],"+NEW_LINE +
            "  \"USER\": ["+NEW_LINE +
            "    {"+NEW_LINE +
            "      \"ID\": 1"+NEW_LINE +
            "    }"+NEW_LINE +
            "  ]"+NEW_LINE +
            "}").replaceAll("\r",""));

}
 
Example 12
Source Project: jpa-unit   Source File: PostgresqlConnectionFactoryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConnection() throws DatabaseUnitException {
    // GIVEN
    final String schema = "foo";

    // WHEN
    final IDatabaseConnection dbConnection = FACTORY.createConnection(connection, schema);

    // THEN
    assertThat(dbConnection, notNullValue());

    final Object typeFactory = dbConnection.getConfig().getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY);
    assertThat(typeFactory, notNullValue());
    assertThat(typeFactory.getClass(), not(equalTo(DefaultDataTypeFactory.class)));

    assertThat(dbConnection.getSchema(), equalTo(schema));
}
 
Example 13
Source Project: jpa-unit   Source File: SqlDbFeatureExecutor.java    License: Apache License 2.0 6 votes vote down vote up
@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 14
Source Project: wetech-cms   Source File: UserDaoTest.java    License: 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 15
Source Project: wetech-cms   Source File: KeywordDaoTest.java    License: MIT License 5 votes vote down vote up
@After
public void tearDown() throws DatabaseUnitException, SQLException, IOException {
	SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
	Session s = holder.getSession(); 
	s.flush();
	TransactionSynchronizationManager.unbindResource(sessionFactory);
	this.resumeTable();
}
 
Example 16
Source Project: sharding-jdbc-1.5.1   Source File: AbstractSQLAssertTest.java    License: Apache License 2.0 5 votes vote down vote up
private void assertSelectSql(final boolean isPreparedStatement, final ShardingDataSource shardingDataSource, final SQLAssertData data, final File expectedDataSetFile)
        throws MalformedURLException, SQLException, DatabaseUnitException {
    if (isPreparedStatement) {
        executeQueryWithPreparedStatement(shardingDataSource, getParameters(data), expectedDataSetFile);
    } else {
        executeQueryWithStatement(shardingDataSource, getParameters(data), expectedDataSetFile);
    }
}
 
Example 17
Source Project: sharding-jdbc-1.5.1   Source File: AbstractSQLAssertTest.java    License: Apache License 2.0 5 votes vote down vote up
private void executeQueryWithPreparedStatement(final ShardingDataSource dataSource, final List<String> parameters, final File file)
        throws MalformedURLException, SQLException, DatabaseUnitException {
    try (Connection conn = dataSource.getConnection();
         PreparedStatement preparedStatement = conn.prepareStatement(replacePreparedStatement(sql))) {
        setParameters(preparedStatement, parameters);
        ReplacementDataSet expectedDataSet = new ReplacementDataSet(new FlatXmlDataSetBuilder().build(file));
        expectedDataSet.addReplacementObject("[null]", null);
        for (ITable each : expectedDataSet.getTables()) {
            String tableName = each.getTableMetaData().getTableName();
            ITable actualTable = DBUnitUtil.getConnection(new DataBaseEnvironment(DatabaseType.valueFrom(conn.getMetaData().getDatabaseProductName())), conn)
                    .createTable(tableName, preparedStatement);
            assertEquals(expectedDataSet.getTable(tableName), actualTable);
        }
    }
}
 
Example 18
Source Project: wetech-cms   Source File: UserDaoTest.java    License: MIT License 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 19
Source Project: sharding-jdbc-1.5.1   Source File: AbstractSQLAssertTest.java    License: Apache License 2.0 5 votes vote down vote up
private void assertResult(final Connection connection, final File file) throws MalformedURLException, SQLException, DatabaseUnitException {
    ITableIterator expectedTableIterator = new FlatXmlDataSetBuilder().build(file).iterator();
    try (Connection conn = connection) {
        while (expectedTableIterator.next()) {
            ITable expectedTable = expectedTableIterator.getTable();
            String actualTableName = expectedTable.getTableMetaData().getTableName();
            String verifySql = "SELECT * FROM " + actualTableName + " WHERE status = '" + getStatus(file) + "'";
            ITable actualTable = DBUnitUtil.getConnection(new DataBaseEnvironment(DatabaseType.valueFrom(conn.getMetaData().getDatabaseProductName())), conn)
                    .createQueryTable(actualTableName, verifySql);
            assertEquals(expectedTable, actualTable);
        }
    }
}
 
Example 20
Source Project: sharding-jdbc-1.5.1   Source File: AbstractHintTest.java    License: Apache License 2.0 5 votes vote down vote up
protected void assertDataSet(final String expectedDataSetFile, final DynamicShardingValueHelper helper, 
                             final Connection connection, final String sql, 
                             final DatabaseType type, final Object... params) throws SQLException, DatabaseUnitException {
    try (DynamicShardingValueHelper anotherHelper = helper) {
        assertDataSetEquals(expectedDataSetFile, connection, sql, type, params);
    }
}
 
Example 21
Source Project: sharding-jdbc-1.5.1   Source File: AbstractHintTest.java    License: Apache License 2.0 5 votes vote down vote up
private void assertDataSetEquals(final String expectedDataSetFile, final Connection connection, 
                                 final String sql, final DatabaseType type, final Object[] params) throws SQLException, DatabaseUnitException {
    try (
            Connection conn = connection;
            PreparedStatement ps = conn.prepareStatement(sql)) {
        int i = 1;
        for (Object param : params) {
            ps.setObject(i++, param);
        }
        ITable actualTable = DBUnitUtil.getConnection(new DataBaseEnvironment(type), connection).createTable("t_order", ps);
        IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(AbstractHintTest.class.getClassLoader()
                .getResourceAsStream(expectedDataSetFile)));
        assertEquals(expectedDataSet.getTable("t_order"), actualTable);
    }
}
 
Example 22
Source Project: Zebra   Source File: SingleDBBaseTestCase.java    License: Apache License 2.0 5 votes vote down vote up
protected DatabaseOperation getSetUpOperation() throws Exception {
	parseCreateTableScriptFile();

	initSpringContext();

	return new CompositeOperation(new DatabaseOperation[] { new DatabaseOperation() {

		@Override
		public void execute(IDatabaseConnection connection, IDataSet dataSet)
				throws DatabaseUnitException, SQLException {

			DatabaseConfig databaseConfig = connection.getConfig();
			IStatementFactory statementFactory = (IStatementFactory) databaseConfig
					.getProperty(DatabaseConfig.PROPERTY_STATEMENT_FACTORY);
			IBatchStatement statement = statementFactory.createBatchStatement(connection);
			try {
				int count = 0;
				for (SingleCreateTableScriptEntry entry : createdTableList) {
					statement.addBatch(entry.getCreateTableScript());
					count++;
				}

				if (count > 0) {
					statement.executeBatch();
					statement.clearBatch();
				}
			} finally {
				statement.close();
			}
		}
	}, DatabaseOperation.CLEAN_INSERT });
}
 
Example 23
@Test
public void assertSelectBetweenWithSingleTable() throws SQLException, DatabaseUnitException {
    String sql = replacePreparedStatement(DatabaseTestSQL.SELECT_BETWEEN_WITH_SINGLE_TABLE_SQL);
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        assertDataSet("integrate/dataset/db/expect/select/SelectBetweenWithSingleTable.xml", new DynamicShardingValueHelper(Lists.newArrayList(10, 12),
                        ShardingOperator.BETWEEN, Lists.newArrayList(1001, 1200), ShardingOperator.BETWEEN), each.getValue().getConnection(),
                sql, each.getKey(), 10, 12, 1001, 1200);
        assertDataSet("integrate/dataset/Empty.xml", new DynamicShardingValueHelper(Lists.newArrayList(10, 12),
                ShardingOperator.BETWEEN, Lists.newArrayList(1309, 1408), ShardingOperator.BETWEEN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 1309, 1408);
    }
}
 
Example 24
@Test
public void assertSelectInWithSingleTable() throws SQLException, DatabaseUnitException {
    String sql = replacePreparedStatement(DatabaseTestSQL.SELECT_IN_WITH_SINGLE_TABLE_SQL);
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        assertDataSet("integrate/dataset/db/expect/select/SelectInWithSingleTable_0.xml", new DynamicShardingValueHelper(Lists.newArrayList(10, 12, 15),
                ShardingOperator.IN, Lists.newArrayList(1000, 1201), ShardingOperator.IN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 15, 1000, 1201);
        assertDataSet("integrate/dataset/db/expect/select/SelectInWithSingleTable_1.xml", new DynamicShardingValueHelper(Lists.newArrayList(10, 12, 15),
                ShardingOperator.IN, Lists.newArrayList(1000, 1101), ShardingOperator.IN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 15, 1000, 1101);
        assertDataSet("integrate/dataset/Empty.xml", new DynamicShardingValueHelper(Lists.newArrayList(10, 12, 15),
                ShardingOperator.IN, Lists.newArrayList(1309, 1408), ShardingOperator.IN), each.getValue().getConnection(), sql, each.getKey(), 10, 12, 15, 1309, 1408);
    }
}
 
Example 25
@Test
public void assertSelectEqualsWithSingleTable() throws SQLException, DatabaseUnitException {
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        String sql = replacePreparedStatement(DatabaseTestSQL.SELECT_EQUALS_WITH_SINGLE_TABLE_SQL);
        assertDataSet("integrate/dataset/db/expect/select/SelectEqualsWithSingleTable_0.xml", new DynamicDatabaseShardingValueHelper(10), 
                each.getValue().getConnection(), sql, each.getKey(), 10, 1000);
        assertDataSet("integrate/dataset/db/expect/select/SelectEqualsWithSingleTable_1.xml", new DynamicDatabaseShardingValueHelper(12), 
                each.getValue().getConnection(), sql, each.getKey(), 12, 1201);
        assertDataSet("integrate/dataset/Empty.xml", new DynamicDatabaseShardingValueHelper(12), 
                each.getValue().getConnection(), sql, each.getKey(), 12, 1000);
    }
}
 
Example 26
Source Project: wetech-cms   Source File: UserDaoTest.java    License: MIT License 5 votes vote down vote up
@After
public void tearDown() throws DatabaseUnitException, SQLException, IOException {
	SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
	Session s = holder.getSession(); 
	s.flush();
	TransactionSynchronizationManager.unbindResource(sessionFactory);
	//this.resumeTable();
}
 
Example 27
Source Project: wetech-cms   Source File: UserDaoTest.java    License: MIT License 5 votes vote down vote up
@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("t_user");
//		DatabaseOperation.CLEAN_INSERT.execute(dbunitCon,ds);
	}
 
Example 28
@Test
public void assertUpdateWithoutAlias() throws SQLException, DatabaseUnitException {
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        updateWithoutAlias(each);
        assertDataSet(each.getValue().getConnection(), each.getKey(), "update", "updated");
    }
}
 
Example 29
@Test
public void assertUpdateWithAlias() throws SQLException, DatabaseUnitException {
    for (Map.Entry<DatabaseType, ShardingDataSource> each : shardingDataSources.entrySet()) {
        if (DatabaseType.H2 == each.getKey() || DatabaseType.MySQL == each.getKey()) {
            updateWithAlias(each);
        }
    }
}
 
Example 30
private void updateWithAlias(final Map.Entry<DatabaseType, ShardingDataSource> dataSourceEntry) throws SQLException, DatabaseUnitException {
    for (int i = 10; i < 30; i++) {
        for (int j = 0; j < 2; j++) {
            try (DynamicShardingValueHelper helper = new DynamicShardingValueHelper(i, i * 100 + j);
                 Connection connection = dataSourceEntry.getValue().getConnection()) {
                PreparedStatement preparedStatement = connection.prepareStatement(DatabaseTestSQL.UPDATE_WITH_ALIAS_SQL);
                preparedStatement.setString(1, "updated");
                preparedStatement.setInt(2, i * 100 + j);
                preparedStatement.setInt(3, i);
                assertThat(preparedStatement.executeUpdate(), is(1));
            }
        }
    }
    assertDataSet(dataSourceEntry.getValue().getConnection(), dataSourceEntry.getKey(), "update", "updated");
}