/** @throws Exception */ @BeforeClass(alwaysRun = true) protected void prepareDataSet() throws Exception { logger.entry(); if (!prepareSettings()) { logger.info("No dataset required"); return; } dbUnitConnection = getConnection(); if (!(testDataHelpers.size() > 0)) throw new RuntimeException("No dataset found"); for (TestDataHelper helper : testDataHelpers) { logger.debug("PREPARING dataset for " + helper.getRawDataFile()); InputStream input = Thread.currentThread() .getContextClassLoader() .getResourceAsStream(helper.getRawDataFile()); ReplacementDataSet ds = new ReplacementDataSet( new FlatXmlDataSetBuilder() .setColumnSensing(true) .setCaseSensitiveTableNames(false) .build(input)); ds.addReplacementObject("[NULL]", null); ds.addReplacementObject("[ne]", "≠"); ds.addReplacementObject("[NOW]", Calendar.getInstance().getTime()); helper.setTranslatedDataSet(ds); } logger.exit(); }
/** @param files */ protected void addBeforeClassTestDataFiles(String[] files) { for (String file : files) { TestDataHelper helper = new TestDataHelper(file); helper.addBeforeTestClassOperation(InsertIdentityOperation.CLEAN_INSERT); testDataHelpers.add(helper); } }
/** @throws Exception */ @AfterClass protected void afterTestClass() throws Exception { logger.entry(); for (TestDataHelper helper : testDataHelpers) { for (DatabaseOperation op : helper.getAfterTestClassOperations()) { op.execute(dbUnitConnection, helper.getTranslatedDataSet()); } } logger.exit(); }
/** @throws Exception */ @AfterMethod(alwaysRun = true) protected void afterTestMethod() throws Exception { logger.entry(); if (dbUnitConnection != null) { for (TestDataHelper helper : testDataHelpers) { for (DatabaseOperation op : helper.getAfterTestMethodOperations()) { op.execute(dbUnitConnection, helper.getTranslatedDataSet()); } } } logger.exit(); }
/** @throws Exception */ @BeforeMethod(alwaysRun = true) protected void beforeTestMethod() throws Exception { logger.entry(); if (dbUnitConnection != null) { for (TestDataHelper helper : testDataHelpers) { for (DatabaseOperation op : helper.getBeforeTestMethodOperations()) { logger.debug("RUNNING DB OPERATIONS FOR: " + helper.getRawDataFile()); op.execute(dbUnitConnection, helper.getTranslatedDataSet()); } } } logger.exit(); }
/** @throws Exception */ @BeforeClass( alwaysRun = true, dependsOnMethods = {"prepareDataSet"}) protected void beforeTestClass() throws Exception { logger.entry(); if (dbUnitConnection != null) { for (TestDataHelper helper : testDataHelpers) { for (DatabaseOperation op : helper.getBeforeTestClassOperations()) { logger.debug("RUNNING DB OPERATIONS FOR: " + helper.getRawDataFile()); op.execute(dbUnitConnection, helper.getTranslatedDataSet()); } } } else { logger.error("DB CONNECTION IS NULL, NOT RUNNING beforeTestClass operations"); } logger.exit(); }