Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbUnit and binary data

I use DbUnit for unit-testing of my DAO objects. It works great so far.

I have a problem, I have field ob type byte[] which is stored as BLOB in the database. The column is not-null. How can I specify the value for this column in the XML dataset file, that DbUnit uses? The value can be nothing fancy, 5 bytes will be enough. I would like to avoid necessity to create extra binary files just for this.

Any suggestions?

like image 478
Ula Krukar Avatar asked Jan 21 '10 08:01

Ula Krukar


1 Answers

After all I solved it like that:

XML dataset file:

<?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <!-- image_content is string '12345' Base64 encoded -->
    <IMAGE IMAGE_ID="1" IMAGE_CONTENT="MTIzNDU="/>
</dataset>

DbUnit has built-in support for Base64 encoded data, it transformes correctly into byte array.

Test case code:

assertEquals("12345".getBytes(), image.getContent());
like image 112
Ula Krukar Avatar answered Sep 22 '22 15:09

Ula Krukar