Search in sources :

Example 21 with IDataSet

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);
        }
    }
}
Also used : SimpleNamingContextBuilder(org.springframework.mock.jndi.SimpleNamingContextBuilder) IDataSet(org.dbunit.dataset.IDataSet) BeforeClass(org.junit.BeforeClass)

Example 22 with IDataSet

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);
}
Also used : IDataSet(org.dbunit.dataset.IDataSet)

Example 23 with IDataSet

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);
}
Also used : IDataSet(org.dbunit.dataset.IDataSet)

Example 24 with IDataSet

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;
}
Also used : FlatXmlDataFileLoader(org.dbunit.util.fileloader.FlatXmlDataFileLoader) DataFileLoader(org.dbunit.util.fileloader.DataFileLoader) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) FlatXmlDataFileLoader(org.dbunit.util.fileloader.FlatXmlDataFileLoader) IDataSet(org.dbunit.dataset.IDataSet)

Example 25 with IDataSet

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);
}
Also used : NameType(gov.ca.cwds.data.legacy.cms.entity.syscodes.NameType) ITable(org.dbunit.dataset.ITable) ChildClient(gov.ca.cwds.data.legacy.cms.entity.ChildClient) Client(gov.ca.cwds.data.legacy.cms.entity.Client) IDataSet(org.dbunit.dataset.IDataSet) Test(org.junit.Test) BaseCwsCmsInMemoryPersistenceTest(gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)

Aggregations

IDataSet (org.dbunit.dataset.IDataSet)54 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)21 DatabaseConnection (org.dbunit.database.DatabaseConnection)16 Test (org.junit.Test)15 ITable (org.dbunit.dataset.ITable)13 Connection (java.sql.Connection)12 FileOutputStream (java.io.FileOutputStream)11 File (java.io.File)10 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)8 XmlDataSet (org.dbunit.dataset.xml.XmlDataSet)8 InputStream (java.io.InputStream)7 InputStreamReader (java.io.InputStreamReader)7 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)7 OutputStreamWriter (java.io.OutputStreamWriter)5 Writer (java.io.Writer)5 IDatabaseTester (org.dbunit.IDatabaseTester)5 FileInputStream (java.io.FileInputStream)4 FlatDtdWriter (org.dbunit.dataset.xml.FlatDtdWriter)4 BaseCwsCmsInMemoryPersistenceTest (gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)3 DatabaseEnvironment (io.shardingjdbc.core.common.env.DatabaseEnvironment)3