atom feed2 messages in [appfuse-user] DBUNIT & BLOB
FromSent OnAttachments
Mailing GOSSETOct 20, 2006 12:33 am 
nhoj_pOct 31, 2006 2:31 am 
Subject:Re: [appfuse-user] DBUNIT & BLOB
From:nhoj_p (
Date:Oct 31, 2006 2:31:19 am


The solution I use when handling lob data types is to use the ReplacementDataSet. Basically setup the dataset as usual but leave a marker in the data set where the lob needs to go, then using the replacement data set you can subsitute it with the real data at runtime. The approach is not just limited for blob/clob data type, it can be used for any dynamic data.

Base data set loaded at start of dbunit test: <dataset> <table name="TMP"> <column>ID</column> <column>BLOB_COL</column> <row> <value>1</value> <value>BLOB_ID_1</value> <row> </table> </dataset>

Verify data set loaded after test executed to verify database populated as expected: <dataset> <table name="TMP"> <column>ID</column> <column>BLOB_COL</column> <row> <value>1</value> <value>BLOB_ID_1</value> <row> <row> <value>2</value> <value>BLOB_ID_2</value> <row> </table> </dataset>

Sample unit test, creates single row in database, loads expectations, loads actuals, verifies expectations matches actuals: public void testTmp throws Exception { // create single row in tmp table containing ID 2 and blob "row 2 blob".getBytes("UTF-8");

/* load expectations */ final InputStream expIn = this.getClass.getResourceAsStream("/Tmp-verify.xml"); final IDataSet tmpExpDataSet = new XmlDataSet(expIn); final ReplacementDataSet tmpExpReplacementDataSet = new ReplacementDataSet(tmpExpDataSet); tmpExpReplacementDataSet.addReplacementObject("BLOB_ID_1", "row 1 blob".getBytes("UTF-8")); // this row also needs to be in the getDataSet method tmpExpReplacementDataSet.addReplacementObject("BLOB_ID_2", "row 2 blob".getBytes("UTF-8")); final ITable tmpExpTable = tmpExpReplacementDataSet.getTable("TMP"); final ITable expTable = new SortedTable(tmpExpTable);

/* load actuals */ final IDatabaseConnection actIn = this.getConnection(); final IDataSet tmpActDataSet = actIn.createDataSet(); final ITable tmpActTable = tmpActDataSet.getTable("TMP"); final ITable actTable = new SortedTable(tmpActTable);

/* verify expectations match actuals */ Assertion.assertEquals(expTable, actTable); }

There maybe a better approach but this works for me.


Mailing GOSSET wrote:


i'm trying to load a blob whit dbunit like this :

<dataset> <table name='maTABLE'> <column>monBLOB</column> ... <row> <value>file://.........</value>

but i don't find the solution to declare the file to load in blob :( like "file://c:/...." or "c:\....." or whatever ? :(

have you solution, i don't find anymore on google.