use of org.dbunit.dataset.IDataSet in project nextprot-api by calipho-sib.
the class GenerateDTD method generateUserDTD.
@Test
public void generateUserDTD() throws Exception {
IDatabaseConnection connection = new DatabaseConnection(dsLocator.getUserDataSource().getConnection());
// write DTD file
IDataSet dataSet = connection.createDataSet();
Writer out = new OutputStreamWriter(new FileOutputStream("user.dtd"));
FlatDtdWriter datasetWriter = new FlatDtdWriter(out);
datasetWriter.setContentModel(FlatDtdWriter.CHOICE);
// You could also use the sequence model which is the default
// datasetWriter.setContentModel(FlatDtdWriter.SEQUENCE);
datasetWriter.write(dataSet);
// delete file after the test
new File(dtdFile).delete();
}
use of org.dbunit.dataset.IDataSet in project nextprot-api by calipho-sib.
the class GenerateDTDForUserSchema method generateDTD.
@Test
public void generateDTD() throws Exception {
IDatabaseConnection connection = new DatabaseConnection(dsLocator.getDataSource().getConnection());
// write DTD file
IDataSet dataSet = connection.createDataSet();
Writer out = new OutputStreamWriter(new FileOutputStream(dtdFile));
FlatDtdWriter datasetWriter = new FlatDtdWriter(out);
datasetWriter.setContentModel(FlatDtdWriter.CHOICE);
// You could also use the sequence model which is the default
// datasetWriter.setContentModel(FlatDtdWriter.SEQUENCE);
datasetWriter.write(dataSet);
// delete file after the test
new File(dtdFile).delete();
}
use of org.dbunit.dataset.IDataSet in project nextprot-api by calipho-sib.
the class GenerateUserDTD method generateUserDTD.
/**
* This method should be executed every times the db schema change.
* The schema is defined in main/resources/db.migration/*.sql.
* The generated file user.dtd should go
* @throws Exception
*/
@Test
public void generateUserDTD() throws Exception {
IDatabaseConnection connection = new DatabaseConnection(dsLocator.getUserDataSource().getConnection(), "np_users");
// write DTD file
IDataSet dataSet = connection.createDataSet();
Writer out = new OutputStreamWriter(new FileOutputStream(dtdFile));
FlatDtdWriter datasetWriter = new FlatDtdWriter(out);
datasetWriter.setContentModel(FlatDtdWriter.CHOICE);
datasetWriter.write(dataSet);
}
use of org.dbunit.dataset.IDataSet in project api-core by ca-cwds.
the class CaseDaoTest method testCreate.
@Ignore
@Test
public void testCreate() throws Exception {
cleanAll("/dbunit/Case.xml");
executeInTransaction(sessionFactory, (sessionFactory) -> {
Case c = new Case();
// TODO: populate Case
caseDao.create(c);
});
IDataSet expectedDataSet = readXmlDataSet("/dbunit/Case.xml");
ITable expectedTable = expectedDataSet.getTable("CASE_T");
IDataSet actualDataSet = dbUnitConnection.createDataSet(new String[] { "CASE_T" });
ITable actualTable = actualDataSet.getTable("CASE_T");
Assertion.assertEquals(expectedTable, actualTable);
}
use of org.dbunit.dataset.IDataSet in project activityinfo by bedatadriven.
the class ExtractWholeDbUnit method main.
/**
* Utility to create a dbunit xml file from a local mysql database
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Connection jdbcConnection = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PW);
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
String currentDir = System.getProperty("user.dir");
String pathname = filepath(currentDir, "server", "src", "test", "resources", "dbunit", XML_FILE_NAME);
System.out.println("Current directory: " + currentDir);
System.out.println("File: " + pathname);
File file = new File(pathname);
if (!file.exists() && !file.createNewFile()) {
throw new RuntimeException("Unable to create file: " + file.getAbsolutePath());
}
// full database export
IDataSet fullDataSet = connection.createDataSet();
FlatXmlDataSet.write(fullDataSet, new FileOutputStream(file, false));
}
Aggregations