Missing configuration possibilities in DBUnit?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Missing configuration possibilities in DBUnit?

TheStijn
All,

I've been digging a bit deeper into dbunit the last few days whilst trying to solve some issues I had.
It seems to me that many thing that should be configurable (in unitils.properties or through annotations) are not.

Some examples:
- I, as many, encountered the well known NoSuchColumnException while using mysql. The first solution was to not use the DefaultMetadataHandler but MySQLMetadataHandler. I searched & searched but did not find a way to configure this. The only option seemed to be to write something like DataBaseConfig.setProperty... in your unit test. This so calls for an annotation because for this I would have to rewrite met unit classes completely since I do not refer to dbunit in my tests themselves (simply use some annotations that are available):

e.g.
@RunWith(UnitilsJUnit4TestClassRunner.class)
@Transactional(TransactionMode.ROLLBACK)
@SpringApplicationContext( {
                "classpath:com/m4w/common/props/spring/common-data-test.xml",
                "classpath:com/m4w/common/props/spring/common-dao.xml" })
@DataSet(loadStrategy = RefreshLoadStrategy.class)
public class CustomerAddressPhoneTest extends AbstractHibernateDAOTest {

    @SpringBeanByType
    private UserDAO userDAO;

    @Test
    public void getCustomerFromUser() {
        User u = userDAO.getById(1L);
        Customer c = u.getCustomer();
        Assert.assertNotNull(c);
    }
}

For the moment (very dirty but just for testing) I simply took DatabaseConfig into my project and changed the code.

This led me to the next problem:

<cat id="1" />
<cat id="2" parent="1" />

When the table cat is populated there are no errors but the parent of cat with id 2 is null.
This, because I did not define the column parent_id in the first row.
Suggested solution is to use a DTD, which I did but this did not resolve anything.
After some debugging I am not even sure if this DTD is even considered. I assumed dbunit would see this was a FlatXmlDataSet but it doesn't look like it. It just created a default CachedDataSet. Again, I did not find a way, other than programmatically, to indicate dbunit that it is a flatxml ds.

I post this message in the hope that either:
1. someone calls me an idiote and points me to some configuration mechanism I was not aware of
2. someone tells me this will be available in the next release of dbunit
3. it can lead to some interesting discussion

thanks,
Stijn
Reply | Threaded
Open this post in threaded view
|

Re: Missing configuration possibilities in DBUnit?

Matthias Gommeringer
Hi Stijn,

with respect to your 2nd question: you also can use the columnSensing feature which is not enabled by default (because of backwards compatibility). Therefor use this constructor, for example:

boolean columnSensing = true;
File xmlFile = new File(...);
IDataSet ds = new FlatXmlDataSet(xmlFile, false, columnSensing);


looking at your first question it would really be nice to have an annotations subproject in dbunit. If you like feel free to contribute some code ;-)
Actually everything that can be configured via the DatabaseConfig is also configurable via ant. See parameter "dbconfig" in http://www.dbunit.org/anttask.html


HTH.
matthias

> -----Ursprüngliche Nachricht-----
> Von: "TheStijn" <[hidden email]>
> Gesendet: 01.07.09 15:12:22
> An: [hidden email]
> Betreff: [dbunit-user]  Missing configuration possibilities in DBUnit?


>
> All,
>
> I've been digging a bit deeper into dbunit the last few days whilst trying
> to solve some issues I had.
> It seems to me that many thing that should be configurable (in
> unitils.properties or through annotations) are not.
>
> Some examples:
> - I, as many, encountered the well known NoSuchColumnException while using
> mysql. The first solution was to not use the DefaultMetadataHandler but
> MySQLMetadataHandler. I searched & searched but did not find a way to
> configure this. The only option seemed to be to write something like
> DataBaseConfig.setProperty... in your unit test. This so calls for an
> annotation because for this I would have to rewrite met unit classes
> completely since I do not refer to dbunit in my tests themselves (simply use
> some annotations that are available):
>
> e.g.
> @RunWith(UnitilsJUnit4TestClassRunner.class)
> @Transactional(TransactionMode.ROLLBACK)
> @SpringApplicationContext( {
>                
> "classpath:com/m4w/common/props/spring/common-data-test.xml",
>                 "classpath:com/m4w/common/props/spring/common-dao.xml" })
> @DataSet(loadStrategy = RefreshLoadStrategy.class)
> public class CustomerAddressPhoneTest extends AbstractHibernateDAOTest {
>
>     @SpringBeanByType
>     private UserDAO userDAO;
>
>     @Test
>     public void getCustomerFromUser() {
>         User u = userDAO.getById(1L);
>         Customer c = u.getCustomer();
>         Assert.assertNotNull(c);
>     }
> }
>
> For the moment (very dirty but just for testing) I simply took
> DatabaseConfig into my project and changed the code.
>
> This led me to the next problem:
>
> <cat id="1" />
> <cat id="2" parent="1" />
>
> When the table cat is populated there are no errors but the parent of cat
> with id 2 is null.
> This, because I did not define the column parent_id in the first row.
> Suggested solution is to use a DTD, which I did but this did not resolve
> anything.
> After some debugging I am not even sure if this DTD is even considered. I
> assumed dbunit would see this was a FlatXmlDataSet but it doesn't look like
> it. It just created a default CachedDataSet. Again, I did not find a way,
> other than programmatically, to indicate dbunit that it is a flatxml ds.
>
> I post this message in the hope that either:
> 1. someone calls me an idiote and points me to some configuration mechanism
> I was not aware of
> 2. someone tells me this will be available in the next release of dbunit
> 3. it can lead to some interesting discussion
>
> thanks,
> Stijn
> --
> View this message in context: http://www.nabble.com/Missing-configuration-possibilities-in-DBUnit--tp24288574p24288574.html
> Sent from the DBUnit - Users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


________________________________________________________________
Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/


------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Missing configuration possibilities in DBUnit?

TheStijn
Matthias,

I'm aware of the column sensing feature in FlatXmlProducer but the problem is already before this. There's no way to tell dbunit, through condiguration/annotation, that the input file is a FlatXmlFile.

Thanks for the ant suggestion, I must admit I had not looked into this yet but I certainly will. I already see that here you can specify the xml format and the metadata handler so it certainly looks promising :-).

regards,
Stijn

Matthias Gommeringer wrote
Hi Stijn,

with respect to your 2nd question: you also can use the columnSensing feature which is not enabled by default (because of backwards compatibility). Therefor use this constructor, for example:

boolean columnSensing = true;
File xmlFile = new File(...);
IDataSet ds = new FlatXmlDataSet(xmlFile, false, columnSensing);


looking at your first question it would really be nice to have an annotations subproject in dbunit. If you like feel free to contribute some code ;-)
Actually everything that can be configured via the DatabaseConfig is also configurable via ant. See parameter "dbconfig" in http://www.dbunit.org/anttask.html


HTH.
matthias

> -----Ursprüngliche Nachricht-----
> Von: "TheStijn" <stijn.geukens@gmail.com>
> Gesendet: 01.07.09 15:12:22
> An: dbunit-user@lists.sourceforge.net
> Betreff: [dbunit-user]  Missing configuration possibilities in DBUnit?


>
> All,
>
> I've been digging a bit deeper into dbunit the last few days whilst trying
> to solve some issues I had.
> It seems to me that many thing that should be configurable (in
> unitils.properties or through annotations) are not.
>
> Some examples:
> - I, as many, encountered the well known NoSuchColumnException while using
> mysql. The first solution was to not use the DefaultMetadataHandler but
> MySQLMetadataHandler. I searched & searched but did not find a way to
> configure this. The only option seemed to be to write something like
> DataBaseConfig.setProperty... in your unit test. This so calls for an
> annotation because for this I would have to rewrite met unit classes
> completely since I do not refer to dbunit in my tests themselves (simply use
> some annotations that are available):
>
> e.g.
> @RunWith(UnitilsJUnit4TestClassRunner.class)
> @Transactional(TransactionMode.ROLLBACK)
> @SpringApplicationContext( {
>                
> "classpath:com/m4w/common/props/spring/common-data-test.xml",
>                 "classpath:com/m4w/common/props/spring/common-dao.xml" })
> @DataSet(loadStrategy = RefreshLoadStrategy.class)
> public class CustomerAddressPhoneTest extends AbstractHibernateDAOTest {
>
>     @SpringBeanByType
>     private UserDAO userDAO;
>
>     @Test
>     public void getCustomerFromUser() {
>         User u = userDAO.getById(1L);
>         Customer c = u.getCustomer();
>         Assert.assertNotNull(c);
>     }
> }
>
> For the moment (very dirty but just for testing) I simply took
> DatabaseConfig into my project and changed the code.
>
> This led me to the next problem:
>
> <cat id="1" />
> <cat id="2" parent="1" />
>
> When the table cat is populated there are no errors but the parent of cat
> with id 2 is null.
> This, because I did not define the column parent_id in the first row.
> Suggested solution is to use a DTD, which I did but this did not resolve
> anything.
> After some debugging I am not even sure if this DTD is even considered. I
> assumed dbunit would see this was a FlatXmlDataSet but it doesn't look like
> it. It just created a default CachedDataSet. Again, I did not find a way,
> other than programmatically, to indicate dbunit that it is a flatxml ds.
>
> I post this message in the hope that either:
> 1. someone calls me an idiote and points me to some configuration mechanism
> I was not aware of
> 2. someone tells me this will be available in the next release of dbunit
> 3. it can lead to some interesting discussion
>
> thanks,
> Stijn
> --
> View this message in context: http://www.nabble.com/Missing-configuration-possibilities-in-DBUnit--tp24288574p24288574.html
> Sent from the DBUnit - Users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
> dbunit-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


________________________________________________________________
Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/


------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
dbunit-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Missing configuration possibilities in DBUnit?

Matthias Gommeringer
In reply to this post by TheStijn
Hi Stijn,

that is a good point. If you use the ant task you do have the different filetypes configurable as XML attributes. Could you provide a quick example how you'd expect this behavior configurable in Java? Maybe an additional DatasetBuilder class would make sense here?

DatasetBuilder builder = new DatasetBuilder();
builder.setFormat("flatXml");
builder.setInput(new File("C://blabla");
//...further config
IDataSet ds = builder.createDataset();

Or did I get something wrong?

regards,
matthias


> -----Ursprüngliche Nachricht-----
> Von: "TheStijn" <[hidden email]>
> Gesendet: 01.07.09 18:01:21
> An: [hidden email]
> Betreff: Re: [dbunit-user] Missing configuration possibilities in DBUnit?


>
> Matthias,
>
> I'm aware of the column sensing feature in FlatXmlProducer but the problem
> is already before this. There's no way to tell dbunit, through
> condiguration/annotation, that the input file is a FlatXmlFile.
>
> Thanks for the ant suggestion, I must admit I had not looked into this yet
> but I certainly will. I already see that here you can specify the xml format
> and the metadata handler so it certainly looks promising :-).
>
> regards,
> Stijn
>
>
> Matthias Gommeringer wrote:
> >
> > Hi Stijn,
> >
> > with respect to your 2nd question: you also can use the columnSensing
> > feature which is not enabled by default (because of backwards
> > compatibility). Therefor use this constructor, for example:
> >
> > boolean columnSensing = true;
> > File xmlFile = new File(...);
> > IDataSet ds = new FlatXmlDataSet(xmlFile, false, columnSensing);
> >
> >
> > looking at your first question it would really be nice to have an
> > annotations subproject in dbunit. If you like feel free to contribute some
> > code ;-)
> > Actually everything that can be configured via the DatabaseConfig is also
> > configurable via ant. See parameter "dbconfig" in
> > http://www.dbunit.org/anttask.html
> >
> >
> > HTH.
> > matthias
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: "TheStijn" <[hidden email]>
> >> Gesendet: 01.07.09 15:12:22
> >> An: [hidden email]
> >> Betreff: [dbunit-user]  Missing configuration possibilities in DBUnit?
> >
> >
> >>
> >> All,
> >>
> >> I've been digging a bit deeper into dbunit the last few days whilst
> >> trying
> >> to solve some issues I had.
> >> It seems to me that many thing that should be configurable (in
> >> unitils.properties or through annotations) are not.
> >>
> >> Some examples:
> >> - I, as many, encountered the well known NoSuchColumnException while
> >> using
> >> mysql. The first solution was to not use the DefaultMetadataHandler but
> >> MySQLMetadataHandler. I searched & searched but did not find a way to
> >> configure this. The only option seemed to be to write something like
> >> DataBaseConfig.setProperty... in your unit test. This so calls for an
> >> annotation because for this I would have to rewrite met unit classes
> >> completely since I do not refer to dbunit in my tests themselves (simply
> >> use
> >> some annotations that are available):
> >>
> >> e.g.
> >> @RunWith(UnitilsJUnit4TestClassRunner.class)
> >> @Transactional(TransactionMode.ROLLBACK)
> >> @SpringApplicationContext( {
> >>                
> >> "classpath:com/m4w/common/props/spring/common-data-test.xml",
> >>                 "classpath:com/m4w/common/props/spring/common-dao.xml" })
> >> @DataSet(loadStrategy = RefreshLoadStrategy.class)
> >> public class CustomerAddressPhoneTest extends AbstractHibernateDAOTest {
> >>
> >>     @SpringBeanByType
> >>     private UserDAO userDAO;
> >>
> >>     @Test
> >>     public void getCustomerFromUser() {
> >>         User u = userDAO.getById(1L);
> >>         Customer c = u.getCustomer();
> >>         Assert.assertNotNull(c);
> >>     }
> >> }
> >>
> >> For the moment (very dirty but just for testing) I simply took
> >> DatabaseConfig into my project and changed the code.
> >>
> >> This led me to the next problem:
> >>
> >> <cat id="1" />
> >> <cat id="2" parent="1" />
> >>
> >> When the table cat is populated there are no errors but the parent of cat
> >> with id 2 is null.
> >> This, because I did not define the column parent_id in the first row.
> >> Suggested solution is to use a DTD, which I did but this did not resolve
> >> anything.
> >> After some debugging I am not even sure if this DTD is even considered. I
> >> assumed dbunit would see this was a FlatXmlDataSet but it doesn't look
> >> like
> >> it. It just created a default CachedDataSet. Again, I did not find a way,
> >> other than programmatically, to indicate dbunit that it is a flatxml ds.
> >>
> >> I post this message in the hope that either:
> >> 1. someone calls me an idiote and points me to some configuration
> >> mechanism
> >> I was not aware of
> >> 2. someone tells me this will be available in the next release of dbunit
> >> 3. it can lead to some interesting discussion
> >>
> >> thanks,
> >> Stijn
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Missing-configuration-possibilities-in-DBUnit--tp24288574p24288574.html
> >> Sent from the DBUnit - Users mailing list archive at Nabble.com.
> >>
> >>
> >> ------------------------------------------------------------------------------
> >> _______________________________________________
> >> dbunit-user mailing list
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/dbunit-user
> >>
> >
> >
> > ________________________________________________________________
> > Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
> > für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/
> >
> >
> > ------------------------------------------------------------------------------
> > _______________________________________________
> > dbunit-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/dbunit-user
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Missing-configuration-possibilities-in-DBUnit--tp24288574p24292382.html
> Sent from the DBUnit - Users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Missing configuration possibilities in DBUnit?

TheStijn
Matthias,
 
I believe it should be configurable through annotations (for class specific config) & through plain old properties  file (for all classes).
But I'm not even sure if this is something for the DBUnit project or rather the Unitils project or do those share the developers?
 
More specifically I was thinking about enriching the @DataSet annotation: add property to indicate which implementation of IDataSet is to be used.
In the properties a similar way of working as for other properties
org.dbunit...IDataSet.implClass=...
 
This way you can easily specify which DataSet type to use or even easily create your own and configure dbunit to use this.
regards,
Stijn
Matthias Gommeringer wrote
Hi Stijn,

that is a good point. If you use the ant task you do have the different filetypes configurable as XML attributes. Could you provide a quick example how you'd expect this behavior configurable in Java? Maybe an additional DatasetBuilder class would make sense here?

DatasetBuilder builder = new DatasetBuilder();
builder.setFormat("flatXml");
builder.setInput(new File("C://blabla");
//...further config
IDataSet ds = builder.createDataset();

Or did I get something wrong?

regards,
matthias


> -----Ursprüngliche Nachricht-----
> Von: "TheStijn" <stijn.geukens@gmail.com>
> Gesendet: 01.07.09 18:01:21
> An: dbunit-user@lists.sourceforge.net
> Betreff: Re: [dbunit-user] Missing configuration possibilities in DBUnit?


>
> Matthias,
>
> I'm aware of the column sensing feature in FlatXmlProducer but the problem
> is already before this. There's no way to tell dbunit, through
> condiguration/annotation, that the input file is a FlatXmlFile.
>
> Thanks for the ant suggestion, I must admit I had not looked into this yet
> but I certainly will. I already see that here you can specify the xml format
> and the metadata handler so it certainly looks promising :-).
>
> regards,
> Stijn
>
>
> Matthias Gommeringer wrote:
> >
> > Hi Stijn,
> >
> > with respect to your 2nd question: you also can use the columnSensing
> > feature which is not enabled by default (because of backwards
> > compatibility). Therefor use this constructor, for example:
> >
> > boolean columnSensing = true;
> > File xmlFile = new File(...);
> > IDataSet ds = new FlatXmlDataSet(xmlFile, false, columnSensing);
> >
> >
> > looking at your first question it would really be nice to have an
> > annotations subproject in dbunit. If you like feel free to contribute some
> > code ;-)
> > Actually everything that can be configured via the DatabaseConfig is also
> > configurable via ant. See parameter "dbconfig" in
> > http://www.dbunit.org/anttask.html
> >
> >
> > HTH.
> > matthias
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: "TheStijn" <stijn.geukens@gmail.com>
> >> Gesendet: 01.07.09 15:12:22
> >> An: dbunit-user@lists.sourceforge.net
> >> Betreff: [dbunit-user]  Missing configuration possibilities in DBUnit?
> >
> >
> >>
> >> All,
> >>
> >> I've been digging a bit deeper into dbunit the last few days whilst
> >> trying
> >> to solve some issues I had.
> >> It seems to me that many thing that should be configurable (in
> >> unitils.properties or through annotations) are not.
> >>
> >> Some examples:
> >> - I, as many, encountered the well known NoSuchColumnException while
> >> using
> >> mysql. The first solution was to not use the DefaultMetadataHandler but
> >> MySQLMetadataHandler. I searched & searched but did not find a way to
> >> configure this. The only option seemed to be to write something like
> >> DataBaseConfig.setProperty... in your unit test. This so calls for an
> >> annotation because for this I would have to rewrite met unit classes
> >> completely since I do not refer to dbunit in my tests themselves (simply
> >> use
> >> some annotations that are available):
> >>
> >> e.g.
> >> @RunWith(UnitilsJUnit4TestClassRunner.class)
> >> @Transactional(TransactionMode.ROLLBACK)
> >> @SpringApplicationContext( {
> >>                
> >> "classpath:com/m4w/common/props/spring/common-data-test.xml",
> >>                 "classpath:com/m4w/common/props/spring/common-dao.xml" })
> >> @DataSet(loadStrategy = RefreshLoadStrategy.class)
> >> public class CustomerAddressPhoneTest extends AbstractHibernateDAOTest {
> >>
> >>     @SpringBeanByType
> >>     private UserDAO userDAO;
> >>
> >>     @Test
> >>     public void getCustomerFromUser() {
> >>         User u = userDAO.getById(1L);
> >>         Customer c = u.getCustomer();
> >>         Assert.assertNotNull(c);
> >>     }
> >> }
> >>
> >> For the moment (very dirty but just for testing) I simply took
> >> DatabaseConfig into my project and changed the code.
> >>
> >> This led me to the next problem:
> >>
> >> <cat id="1" />
> >> <cat id="2" parent="1" />
> >>
> >> When the table cat is populated there are no errors but the parent of cat
> >> with id 2 is null.
> >> This, because I did not define the column parent_id in the first row.
> >> Suggested solution is to use a DTD, which I did but this did not resolve
> >> anything.
> >> After some debugging I am not even sure if this DTD is even considered. I
> >> assumed dbunit would see this was a FlatXmlDataSet but it doesn't look
> >> like
> >> it. It just created a default CachedDataSet. Again, I did not find a way,
> >> other than programmatically, to indicate dbunit that it is a flatxml ds.
> >>
> >> I post this message in the hope that either:
> >> 1. someone calls me an idiote and points me to some configuration
> >> mechanism
> >> I was not aware of
> >> 2. someone tells me this will be available in the next release of dbunit
> >> 3. it can lead to some interesting discussion
> >>
> >> thanks,
> >> Stijn
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Missing-configuration-possibilities-in-DBUnit--tp24288574p24288574.html
> >> Sent from the DBUnit - Users mailing list archive at Nabble.com.
> >>
> >>
> >> ------------------------------------------------------------------------------
> >> _______________________________________________
> >> dbunit-user mailing list
> >> dbunit-user@lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/dbunit-user
> >>
> >
> >
> > ________________________________________________________________
> > Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
> > für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/
> >
> >
> > ------------------------------------------------------------------------------
> > _______________________________________________
> > dbunit-user mailing list
> > dbunit-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/dbunit-user
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Missing-configuration-possibilities-in-DBUnit--tp24288574p24292382.html
> Sent from the DBUnit - Users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
> dbunit-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
dbunit-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Missing configuration possibilities in DBUnit?

Matthias Gommeringer
In reply to this post by TheStijn
Hi Stijn,

currently dbunit does not support any annotations since it is still java 1.4 compatible. It also does not know of property files for configuration datasets to be used. To me it might be an interesting discussion whether or not it would make sense to move some of the unitils functionality into the dbunit project.

Perhaps we can get some other opinions from users here?

I'd say if you look at how things are right now your feature should be added to the unitils project.

regards,
matthias

> -----Ursprüngliche Nachricht-----
> Von: "TheStijn" <[hidden email]>
> Gesendet: 03.07.09 08:03:40
> An: [hidden email]
> Betreff: Re: [dbunit-user] Missing configuration possibilities in DBUnit?


>
> Matthias,
>  
> I believe it should be configurable through annotations (for class specific
> config) & through plain old properties  file (for all classes).
> But I'm not even sure if this is something for the DBUnit project or rather
> the Unitils project or do those share the developers?
>  
> More specifically I was thinking about enriching the @DataSet annotation:
> add property to indicate which implementation of IDataSet is to be used.
> In the properties a similar way of working as for other properties
> org.dbunit...IDataSet.implClass=...
>  
> This way you can easily specify which DataSet type to use or even easily
> create your own and configure dbunit to use this.
> regards,
> Stijn
>
> Matthias Gommeringer wrote:
> >
> > Hi Stijn,
> >
> > that is a good point. If you use the ant task you do have the different
> > filetypes configurable as XML attributes. Could you provide a quick
> > example how you'd expect this behavior configurable in Java? Maybe an
> > additional DatasetBuilder class would make sense here?
> >
> > DatasetBuilder builder = new DatasetBuilder();
> > builder.setFormat("flatXml");
> > builder.setInput(new File("C://blabla");
> > //...further config
> > IDataSet ds = builder.createDataset();
> >
> > Or did I get something wrong?
> >
> > regards,
> > matthias
> >
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: "TheStijn" <[hidden email]>
> >> Gesendet: 01.07.09 18:01:21
> >> An: [hidden email]
> >> Betreff: Re: [dbunit-user] Missing configuration possibilities in DBUnit?
> >
> >
> >>
> >> Matthias,
> >>
> >> I'm aware of the column sensing feature in FlatXmlProducer but the
> >> problem
> >> is already before this. There's no way to tell dbunit, through
> >> condiguration/annotation, that the input file is a FlatXmlFile.
> >>
> >> Thanks for the ant suggestion, I must admit I had not looked into this
> >> yet
> >> but I certainly will. I already see that here you can specify the xml
> >> format
> >> and the metadata handler so it certainly looks promising :-).
> >>
> >> regards,
> >> Stijn
> >>
> >>
> >> Matthias Gommeringer wrote:
> >> >
> >> > Hi Stijn,
> >> >
> >> > with respect to your 2nd question: you also can use the columnSensing
> >> > feature which is not enabled by default (because of backwards
> >> > compatibility). Therefor use this constructor, for example:
> >> >
> >> > boolean columnSensing = true;
> >> > File xmlFile = new File(...);
> >> > IDataSet ds = new FlatXmlDataSet(xmlFile, false, columnSensing);
> >> >
> >> >
> >> > looking at your first question it would really be nice to have an
> >> > annotations subproject in dbunit. If you like feel free to contribute
> >> some
> >> > code ;-)
> >> > Actually everything that can be configured via the DatabaseConfig is
> >> also
> >> > configurable via ant. See parameter "dbconfig" in
> >> > http://www.dbunit.org/anttask.html
> >> >
> >> >
> >> > HTH.
> >> > matthias
> >> >
> >> >> -----Ursprüngliche Nachricht-----
> >> >> Von: "TheStijn" <[hidden email]>
> >> >> Gesendet: 01.07.09 15:12:22
> >> >> An: [hidden email]
> >> >> Betreff: [dbunit-user]  Missing configuration possibilities in DBUnit?
> >> >
> >> >
> >> >>
> >> >> All,
> >> >>
> >> >> I've been digging a bit deeper into dbunit the last few days whilst
> >> >> trying
> >> >> to solve some issues I had.
> >> >> It seems to me that many thing that should be configurable (in
> >> >> unitils.properties or through annotations) are not.
> >> >>
> >> >> Some examples:
> >> >> - I, as many, encountered the well known NoSuchColumnException while
> >> >> using
> >> >> mysql. The first solution was to not use the DefaultMetadataHandler
> >> but
> >> >> MySQLMetadataHandler. I searched & searched but did not find a way to
> >> >> configure this. The only option seemed to be to write something like
> >> >> DataBaseConfig.setProperty... in your unit test. This so calls for an
> >> >> annotation because for this I would have to rewrite met unit classes
> >> >> completely since I do not refer to dbunit in my tests themselves
> >> (simply
> >> >> use
> >> >> some annotations that are available):
> >> >>
> >> >> e.g.
> >> >> @RunWith(UnitilsJUnit4TestClassRunner.class)
> >> >> @Transactional(TransactionMode.ROLLBACK)
> >> >> @SpringApplicationContext( {
> >> >>                
> >> >> "classpath:com/m4w/common/props/spring/common-data-test.xml",
> >> >>                 "classpath:com/m4w/common/props/spring/common-dao.xml"
> >> })
> >> >> @DataSet(loadStrategy = RefreshLoadStrategy.class)
> >> >> public class CustomerAddressPhoneTest extends AbstractHibernateDAOTest
> >> {
> >> >>
> >> >>     @SpringBeanByType
> >> >>     private UserDAO userDAO;
> >> >>
> >> >>     @Test
> >> >>     public void getCustomerFromUser() {
> >> >>         User u = userDAO.getById(1L);
> >> >>         Customer c = u.getCustomer();
> >> >>         Assert.assertNotNull(c);
> >> >>     }
> >> >> }
> >> >>
> >> >> For the moment (very dirty but just for testing) I simply took
> >> >> DatabaseConfig into my project and changed the code.
> >> >>
> >> >> This led me to the next problem:
> >> >>
> >> >> <cat id="1" />
> >> >> <cat id="2" parent="1" />
> >> >>
> >> >> When the table cat is populated there are no errors but the parent of
> >> cat
> >> >> with id 2 is null.
> >> >> This, because I did not define the column parent_id in the first row.
> >> >> Suggested solution is to use a DTD, which I did but this did not
> >> resolve
> >> >> anything.
> >> >> After some debugging I am not even sure if this DTD is even
> >> considered. I
> >> >> assumed dbunit would see this was a FlatXmlDataSet but it doesn't look
> >> >> like
> >> >> it. It just created a default CachedDataSet. Again, I did not find a
> >> way,
> >> >> other than programmatically, to indicate dbunit that it is a flatxml
> >> ds.
> >> >>
> >> >> I post this message in the hope that either:
> >> >> 1. someone calls me an idiote and points me to some configuration
> >> >> mechanism
> >> >> I was not aware of
> >> >> 2. someone tells me this will be available in the next release of
> >> dbunit
> >> >> 3. it can lead to some interesting discussion
> >> >>
> >> >> thanks,
> >> >> Stijn
> >> >> --
> >> >> View this message in context:
> >> >>
> >> http://www.nabble.com/Missing-configuration-possibilities-in-DBUnit--tp24288574p24288574.html
> >> >> Sent from the DBUnit - Users mailing list archive at Nabble.com.
> >> >>
> >> >>
> >> >>
> >> ------------------------------------------------------------------------------
> >> >> _______________________________________________
> >> >> dbunit-user mailing list
> >> >> [hidden email]
> >> >> https://lists.sourceforge.net/lists/listinfo/dbunit-user
> >> >>
> >> >
> >> >
> >> > ________________________________________________________________
> >> > Neu: WEB.DE Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
> >> > für nur 19,99 Euro/mtl.!* http://produkte.web.de/go/02/
> >> >
> >> >
> >> >
> >> ------------------------------------------------------------------------------
> >> > _______________________________________________
> >> > dbunit-user mailing list
> >> > [hidden email]
> >> > https://lists.sourceforge.net/lists/listinfo/dbunit-user
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Missing-configuration-possibilities-in-DBUnit--tp24288574p24292382.html
> >> Sent from the DBUnit - Users mailing list archive at Nabble.com.
> >>
> >>
> >> ------------------------------------------------------------------------------
> >> _______________________________________________
> >> dbunit-user mailing list
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/dbunit-user
> >>
> >
> >
> > ______________________________________________________
> > GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
> > Jetzt freischalten unter http://movieflat.web.de
> >
> >
> > ------------------------------------------------------------------------------
> > _______________________________________________
> > dbunit-user mailing list
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/dbunit-user
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Missing-configuration-possibilities-in-DBUnit--tp24288574p24303391.html
> Sent from the DBUnit - Users mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>


______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


------------------------------------------------------------------------------
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user