當前位置: 首頁>>代碼示例>>Java>>正文


Java DatabaseUnitException類代碼示例

本文整理匯總了Java中org.dbunit.DatabaseUnitException的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseUnitException類的具體用法?Java DatabaseUnitException怎麽用?Java DatabaseUnitException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DatabaseUnitException類屬於org.dbunit包,在下文中一共展示了DatabaseUnitException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: insertData

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
/**
 * Inserts the file of the dbUnit compliant flat xml file into the database
 * used by the system.
 * 
 * @param dbSrcFileName
 *            The name of the file to be imported.
 * @throws IOException
 * @throws DataSetException
 * @throws DatabaseUnitException
 * @throws SQLException
 */
public static void insertData(String dbSourceFileLocation)
        throws IOException, DataSetException, DatabaseUnitException,
        SQLException {
    if (dbSourceFileLocation == null) {
        return;
    }
    ReplacementDataSet dataSet = new ReplacementDataSet(
            new FlatXmlDataSetBuilder()
                    .build(new File(dbSourceFileLocation)));
    dataSet.addReplacementObject("[NULL]", null);
    Date now = new Date();
    dataSet.addReplacementObject("[SYSDATE]", Long.valueOf(now.getTime()));
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
    dataSet.addReplacementObject("[SYSTIMESTAMP]", sdf.format(now));

    DatabaseOperation.INSERT.execute(dbConn, dataSet);
}
 
開發者ID:servicecatalog,項目名稱:development,代碼行數:29,代碼來源:DatabaseTaskHandler.java

示例2: setSpecificSequence

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
private void setSpecificSequence(final IDatabaseConnection connection, final String tableName) throws SQLException, DatabaseUnitException {
    final List<String> databaseNames = new ArrayList<>();
    databaseNames.add(tableName);
    final PreparedStatement preparedStatement = connection.getConnection().prepareStatement("SELECT id from " + tableName + " order by id desc");
    try (ResultSet rs = preparedStatement.executeQuery()) {
        if (rs.next()) {
            final long maxId = rs.getLong(1);
            final long sequenceId = maxId + 1;
            new RestartBrpSequenceOperation(sequenceId).execute(connection, databaseNames);
        }
    } finally {
        try {
            preparedStatement.close();
        } catch (SQLException s) {
            LOGGER.error("Kon preparedStatement niet sluiten");
        }
    }
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:19,代碼來源:DBUnitBrpUtil.java

示例3: initEntityManager

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
/**
 * Set up memory database and insert data from test-dataset.xml
 * 
 * @throws DatabaseUnitException
 * @throws HibernateException
 * @throws SQLException
 */
@BeforeClass
public static void initEntityManager() throws HibernateException, DatabaseUnitException, SQLException {
    entityManagerFactory = Persistence.createEntityManagerFactory("listing-test-db");
    entityManager = entityManagerFactory.createEntityManager();
    connection = new DatabaseConnection(((SessionImpl) (entityManager.getDelegate())).connection());
    connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());

    InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(datasetXml);
    if (inputStream != null) {
        FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder();
        flatXmlDataSetBuilder.setColumnSensing(true);
        dataset = flatXmlDataSetBuilder.build(inputStream);
        DatabaseOperation.CLEAN_INSERT.execute(connection, dataset);
    }
}
 
開發者ID:coodoo-io,項目名稱:coodoo-listing,代碼行數:23,代碼來源:AbstractDbUnitTest.java

示例4: testGetEmotion

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
@Test
public void testGetEmotion() throws DatabaseUnitException, Exception {
	final Map<String, List<YearAndValue>> year2Embedding = db
			.getEmotion(CORPUS, "bar");
	assertEquals(
			Lists.newArrayList(new YearAndValue(1910, 0.4f),
					new YearAndValue(1930, 0.7f)),
			year2Embedding.get("valence"));
	assertEquals(
			Lists.newArrayList(new YearAndValue(1910, 0.5f),
					new YearAndValue(1930, -3f)),
			year2Embedding.get("arousal"));
	assertEquals(
			Lists.newArrayList(new YearAndValue(1910, 6f),
					new YearAndValue(1930, 5.55f)),
			year2Embedding.get("dominance"));
}
 
開發者ID:hellrich,項目名稱:JeSemE,代碼行數:18,代碼來源:TestDatabaseService.java

示例5: shouldExportYMLDataSetProgrammatically

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
@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: 1" + NEW_LINE +
                            "    NAME: \"u1\"" + NEW_LINE
            );
}
 
開發者ID:database-rider,項目名稱:database-rider,代碼行數:18,代碼來源:ExportDataSetIt.java

示例6: shouldExportJSONDataSetProgrammatically

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
@Test
@DataSet(cleanBefore = true)
public void shouldExportJSONDataSetProgrammatically() throws SQLException, DatabaseUnitException, FileNotFoundException {
    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.json").dataSetFormat(DataSetFormat.JSON));
    File jsonDataSet = new File("target/user.json");
    assertThat(jsonDataSet).exists();
    assertThat(contentOf(jsonDataSet)).contains("\"USER\": [" + NEW_LINE +
            "    {" + NEW_LINE +
            "      \"ID\": " + u1.getId() +
            "," + NEW_LINE +
            "      \"NAME\": \"u1\"" + NEW_LINE +
            "    }" + NEW_LINE +
            "  ]");
}
 
開發者ID:database-rider,項目名稱:database-rider,代碼行數:21,代碼來源:ExportDataSetIt.java

示例7: shouldExportDataSetUsingSubSelectToFilterRows

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
@Test
@DataSet("datasets/yml/users.yml")
public void shouldExportDataSetUsingSubSelectToFilterRows() throws SQLException, DatabaseUnitException {
    DataSetExporter.getInstance().export(new DatabaseConnection(emProvider.connection()),
            new DataSetExportConfig().
                    outputFileName("target/querySubselect.yml").
                    //export only users that have tweets
                    queryList(new String[]{"select * from user u where u.id in" +
                            " (select t.user_id from tweet t)"})
    );
    File ymlDataSet = new File("target/querySubselect.yml");
    assertThat(ymlDataSet).exists();
    assertThat(contentOf(ymlDataSet)).
        isEqualTo("user:"+NEW_LINE +
                "  - ID: 1"+NEW_LINE +
                "    NAME: \"@realpestano\""+NEW_LINE+NEW_LINE);
}
 
開發者ID:database-rider,項目名稱:database-rider,代碼行數:18,代碼來源:ExportDataSetIt.java

示例8: shouldNotExportNullColumnsInYMLDataSet

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
@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
            );
}
 
開發者ID:database-rider,項目名稱:database-rider,代碼行數:19,代碼來源:ExportNullPropertiesIt.java

示例9: shouldNotExportNullColumnsInJSONDataSet

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
@Test
public void shouldNotExportNullColumnsInJSONDataSet() throws SQLException, DatabaseUnitException{
    DataSetExporter.getInstance().export(new DatabaseConnection(emProvider.connection()), new DataSetExportConfig().
            dataSetFormat(DataSetFormat.JSON).outputFileName("target/userWithNullProperty.json"));
    File xmlDataSet = new File("target/userWithNullProperty.json");
    assertThat(xmlDataSet).exists();
    assertThat(contentOf(xmlDataSet).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",""));

}
 
開發者ID:database-rider,項目名稱:database-rider,代碼行數:26,代碼來源:ExportNullPropertiesIt.java

示例10: createVerifyDataAfterFeature

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
@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);
        }
    };
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:20,代碼來源:SqlDbFeatureExecutor.java

示例11: openConnection

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
public static IDatabaseConnection openConnection(final BasicDataSource ds) {
    try {
        final Connection connection = ds.getConnection();

        for (final DbUnitConnectionFactory impl : SERVICE_LOADER) {
            if (impl.supportsDriver(ds.getDriverClassName())) {
                return impl.createConnection(connection);
            }
        }

        // fall back if no specific implementation is available
        return new DatabaseConnection(connection);
    } catch (final DatabaseUnitException | SQLException e) {
        throw new JpaUnitException(e);
    }
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:17,代碼來源:DatabaseConnectionFactory.java

示例12: createConnection

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
@Override
public IDatabaseConnection createConnection(final Connection connection) throws DatabaseUnitException {
    final IDatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
    dbUnitConnection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory());

    return dbUnitConnection;
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:8,代碼來源:PostgresqlConnectionFactory.java

示例13: insertDbUnitTestdata

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
/**
 * Inserts test data in DbUnit XML format.
 *
 * @param entityManager
 *           the EntityManager
 * @param dbUnitTestdata
 *           test file stream
 */
public static void insertDbUnitTestdata(EntityManager entityManager, final InputStream dbUnitTestdata) {

   entityManager.unwrap(Session.class).doWork(new Work() {

      @Override
      public void execute(Connection connection) throws SQLException {
         // Insert Testdata
         try {
            LOGGER.debug("INSERTing testdata");
            DatabaseConnection databaseConnection = new DatabaseConnection(connection);
            databaseConnection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
               new MySqlDataTypeFactory());

            FlatXmlDataSet dataSet = new FlatXmlDataSet(
               new FlatXmlProducer(new InputSource(dbUnitTestdata), false, true));
            DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
            LOGGER.debug("INSERTing testdata ... done");
         } catch (DatabaseUnitException e) {
            throw new SQLException(e);
         }
      }

   });
}
 
開發者ID:kaiwinter,項目名稱:testcontainers-examples,代碼行數:33,代碼來源:DockerDatabaseTestUtil.java

示例14: cleanDB

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
/**
 * Will clean the dataBase before each test
 * 
 * @throws SQLException
 * @throws DatabaseUnitException
 */
@Before
public void cleanDB() throws DatabaseUnitException, SQLException {
	// DatabaseOperation.TRUNCATE_TABLE.execute(connection, dataset);
	DatabaseOperation.CLEAN_INSERT.execute(connection, dataset);
	// try {
	// EntityManagerHelper.beginTransaction();
	// } catch (RuntimeException e) {
	// e.printStackTrace();
	// if (EntityManagerHelper.getEntityManager() != null &&
	// EntityManagerHelper.getEntityManager().isOpen()) {
	// EntityManagerHelper.rollback();
	// }
	// EntityManagerHelper.closeEntityManager();
	// throw e;
	// }
}
 
開發者ID:infinitiessoft,項目名稱:keystone4j,代碼行數:23,代碼來源:AbstractIntegratedTest.java

示例15: cleanDB

import org.dbunit.DatabaseUnitException; //導入依賴的package包/類
/**
 * Will clean the dataBase before each test
 * 
 * @throws SQLException
 * @throws DatabaseUnitException
 */
@Before
public void cleanDB() throws DatabaseUnitException, SQLException {
	// DatabaseOperation.TRUNCATE_TABLE.execute(connection, dataset);
	DatabaseOperation.CLEAN_INSERT.execute(connection, dataset);
	try {
		EntityManagerHelper.beginTransaction();
	} catch (RuntimeException e) {
		e.printStackTrace();
		if (EntityManagerHelper.getEntityManager() != null && EntityManagerHelper.getEntityManager().isOpen()) {
			EntityManagerHelper.rollback();
		}
		EntityManagerHelper.closeEntityManager();
		throw e;
	}
}
 
開發者ID:infinitiessoft,項目名稱:keystone4j,代碼行數:22,代碼來源:AbstractDbUnitJpaTest.java


注:本文中的org.dbunit.DatabaseUnitException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。