Search in sources :

Example 41 with IDataSet

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();
}
Also used : FileOutputStream(java.io.FileOutputStream) FlatDtdWriter(org.dbunit.dataset.xml.FlatDtdWriter) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) OutputStreamWriter(java.io.OutputStreamWriter) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) File(java.io.File) FlatDtdWriter(org.dbunit.dataset.xml.FlatDtdWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Example 42 with IDataSet

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();
}
Also used : FileOutputStream(java.io.FileOutputStream) FlatDtdWriter(org.dbunit.dataset.xml.FlatDtdWriter) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) OutputStreamWriter(java.io.OutputStreamWriter) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) File(java.io.File) FlatDtdWriter(org.dbunit.dataset.xml.FlatDtdWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Example 43 with IDataSet

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);
}
Also used : FileOutputStream(java.io.FileOutputStream) FlatDtdWriter(org.dbunit.dataset.xml.FlatDtdWriter) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) OutputStreamWriter(java.io.OutputStreamWriter) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) Writer(java.io.Writer) FlatDtdWriter(org.dbunit.dataset.xml.FlatDtdWriter) OutputStreamWriter(java.io.OutputStreamWriter) UserResourceBaseTest(org.nextprot.api.user.dao.test.base.UserResourceBaseTest) Test(org.junit.Test)

Example 44 with IDataSet

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

Example 45 with IDataSet

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));
}
Also used : FileOutputStream(java.io.FileOutputStream) Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) File(java.io.File)

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