use of org.dbunit.dataset.IDataSet in project ovirt-engine by oVirt.
the class BaseDaoTestCase method initTestCase.
@BeforeClass
public static void initTestCase() throws Exception {
if (dataSource == null) {
try {
dataSource = createDataSource();
final IDataSet dataset = initDataSet();
// load data from fixtures to DB
DatabaseOperation.CLEAN_INSERT.execute(getConnection(), dataset);
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
builder.bind("java:/ENGINEDataSource", dataSource);
builder.activate();
initialized = true;
} catch (Exception e) {
/*
* note: without logging current maven setting does NOT produce stacktrace/message for following AssertionError.
* this error log is absolutely vital to actually see, what went wrong!
*/
LoggerFactory.getLogger(BaseDaoTestCase.class).error("Unable to init tests", e);
/*
* note: re-throwing exception here is absolutely vital. Without it, all tests of first executed
* descendant test class will be normally executed. With added assumption using Assume then all tests
* will be skipped and successful tests execution will be pronounced. This exception will cause first of
* executed descendant test class fail and it's constructor will not be even reached.
*/
throw new AssertionError("Unable to init tests", e);
}
}
}
use of org.dbunit.dataset.IDataSet in project api-core by ca-cwds.
the class BasePersistenceTest method cleanAll.
/**
* //Cleans all tables mentioned in XML dataset
*/
protected void cleanAll(String dataSetFilePath) throws Exception {
IDataSet dataSet = readXmlDataSet(dataSetFilePath);
cleanAll(dataSet);
}
use of org.dbunit.dataset.IDataSet in project api-core by ca-cwds.
the class BasePersistenceTest method cleanAllAndInsert.
/**
* Cleans and populates tables mentioned in XML dataset
*/
protected void cleanAllAndInsert(String dataSetFilePath) throws Exception {
IDataSet dataSet = readXmlDataSet(dataSetFilePath);
cleanAllAndInsert(dataSet);
}
use of org.dbunit.dataset.IDataSet in project api-core by ca-cwds.
the class BasePersistenceTest method readXmlDataSet.
protected IDataSet readXmlDataSet(String dataSetFilePath) throws Exception {
DataFileLoader loader = new FlatXmlDataFileLoader();
IDataSet dataSet = loader.load(dataSetFilePath);
ReplacementDataSet replacementDataSet = new ReplacementDataSet(dataSet);
replacementDataSet.addReplacementObject("[NULL]", null);
return replacementDataSet;
}
use of org.dbunit.dataset.IDataSet in project api-core by ca-cwds.
the class ClientDaoTest method testCreate.
@Test
public void testCreate() throws Exception {
final String expectedFilePath = "/dbunit/Client/insert/Client_after_insert.xml";
cleanAll(expectedFilePath);
executeInTransaction(sessionFactory, (sessionFactory) -> {
NameType nameType = nameTypeDao.find((short) 1313);
assertNotNull(nameType);
assertEquals("Legal", nameType.getShortDescription().trim());
assertTrue(nameType.getSystemId().equals(new Short((short) 1313)));
Client c = new Client();
c.setIdentifier("AaiU7IW0Rt");
// ADJDEL_IND
c.setAdjudicatedDelinquentIndicator(false);
// ADPTN_STCD
c.setAdoptionStatus(AdoptionStatus.NOT_FREE);
// ALN_REG_NO
c.setAlienRegistrationNumber("AlienRegNum");
// BIRTH_DT
c.setBirthDate(LocalDate.of(1972, 8, 17));
c.setBirthFacilityName("BirthFacilityName");
// BIRTH_CITY
c.setBirthCity("Sacramento");
// CHLD_CLT_B
c.setChildClientIndicator(false);
// COM_FST_NM
c.setCommonFirstName("Tumbling");
// COM_LST_NM
c.setCommonLastName("Lazenby");
// COM_MID_NM
c.setCommonMiddleName("Midname");
// CONF_EFIND
c.setConfidentialityInEffectIndicator(false);
// CREATN_DT
c.setCreationDate(LocalDate.of(2004, 8, 17));
// DRV_LIC_NO
c.setDriverLicenseNumber("license");
// GENDER_CD
c.setGender(Gender.MALE);
// INCAPC_CD
c.setIncapacitatedParentStatus(IncapacitatedParentStatus.UNKNOWN);
// LITRATE_CD
c.setLiterateStatus(LiterateStatus.UNKNOWN);
// MAR_HIST_B
c.setMaritalCohabitationHistoryIndicator(false);
// MILT_STACD
c.setMilitaryStatus(MilitaryStatus.NO_INFORMATION_AVAILABLE);
// NMPRFX_DSC
c.setNamePrefixDescription("prefix");
// NAME_TPC
c.setNameType(nameType);
// SENSTV_IND
c.setSensitivity(Sensitivity.NOT_APPLICABLE);
// SS_NO
c.setSocialSecurityNumber("977000271");
// SSN_CHG_CD
c.setSocialSecurityNumberChangedCode("O");
// SUFX_TLDSC
c.setSuffixTitleDescription("Jr.");
// UNEMPLY_CD
c.setParentUnemployedStatus(ParentUnemployedStatus.UNKNOWN);
// COMMNT_DSC
c.setCommentDescription("CommentDescription");
// EST_DOB_CD
c.setDateOfBirthStatus(DateOfBirthStatus.ESTIMATED);
// HISP_CD
c.setHispanicOrigin(HispanicOrigin.UNDETERMINED);
// COTH_DESC
c.setCurrentlyOtherDescription("CurrentlyOtherDescription");
c.setPreviousOtherDescription("PreviousOtherDescription");
// SOCPLC_CD
c.setSoc158placementsStatus(Soc158placementsStatus.NO_SOC_158_PLACEMENTS);
// LST_UPD_ID
c.setLastUpdateId("0Rt");
// B_STATE_C
c.setBirthStateCode((short) 0);
// B_CNTRY_C
c.setBirthCountryCode((short) 0);
// I_CNTRY_C
c.setImmigrationCountryCode((short) 0);
// D_STATE_C
c.setDriverLicenseStateCode((short) 0);
// IMGT_STC
c.setImmigrationStatusCode((short) 0);
// MRTL_STC
c.setMaritalStatusCode((short) 0);
// P_ETHNCTYC
c.setPrimaryEthnicityCode((short) 0);
// S_LANG_TC
c.setSecondaryLanguageCode((short) 0);
// P_LANG_TPC
c.setPrimaryLanguageCode((short) 0);
// RLGN_TPC
c.setReligionCode((short) 0);
dao.create(c);
});
IDataSet expectedDataSet = readXmlDataSet(expectedFilePath);
ITable expectedTable = expectedDataSet.getTable("CLIENT_T");
IDataSet actualDataSet = dbUnitConnection.createDataSet(new String[] { "CLIENT_T" });
ITable actualTable = actualDataSet.getTable("CLIENT_T");
assertTableEquals(expectedTable, actualTable);
}
Aggregations