The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

rikvdk (8) [Avatar] Offline
#1
Hi,

Why does the dao in listing 17.6 invokes createTables()? First this method is not defined in interface and second you don't want that application code creates tables.

I like to read this book especially to learn quickly setup good unit and database tests. Many best practises about (database) testing together with Spring, Hibernate, Wicket and Easymock are appreciated. Thanks.

Regards,
Rik
felipe.leme (18) [Avatar] Offline
#2
Re: Create tables in listing 17.6
Hi Rik,

> Why does the dao in listing 17.6 invokes createTables()?

To create the tables smilie. Seriously, the idea is to create the tables from the test case, as we are using an in-memory database.

>First this method is not defined in interface and second you don't want that application code creates
> tables.

You're right, this method is not defined in the DAO interface, and applications should not call it. I defined it in the DAO implementation initially, then moved to a DatabaseGenerator class, then back to the DAO implementation (which ended up in the book). And to be honest, the reason for this confusion is that I've been using Hibernate for so many years that I don't care about tables creation anymore smilie

Anyway, it was a good catch - I will change it back to a separate database creation class, or mention in the notes that we are explicitly creating the tables because it's an embedded database.

> I like to read this book especially to learn quickly setup good unit and database tests.

In that aspect, did you like what you read on chapter 17?

> Many best practises about (database) testing together with Spring, Hibernate, Wicket and
> Easymock are appreciated.

Chapter 18 will handle Hibernate, and how to use Easymock to replace DAOs when you test the business layer. We might mention some Spring integration in this chapter, but not too extensive - Spring will be covered in another chapter (which is not focused on database, though). But I don't think we will cover Wicket, sorry.

Thanks for the feedback,

-- Felipe
rikvdk (8) [Avatar] Offline
#3
Re: Create tables in listing 17.6
Hi Felipe,

Thanks for your quick reply, I had to finish reading the chapter yet smilie

I'm also not interested in tables creation because I use a local database for testing which is a import of production database without all user data. So it contains only configuration data. So for my tests I do not use a different DBMS. I do not want to get bothered with differences between DBMS's, database is local so it is fast enough and it is always running so not startup time.

I read chapter 17 except part about EL because I dislike expression languages. It's clear for me and it contains solutions. As always the real problems come if you start to use it but this chapter gives a good baseground.

Some (little) remarks about listing 17.20 and 17.21 :
- It contains 'assertUser( user);' Where does the method assert() comes from?
- Use of field id is not totally clear. This field is not set in class AbstractDbUnitTemplateTestCase and no value is set in testGetUserById().

Regards,
Rik
felipe.leme (18) [Avatar] Offline
#4
Re: Create tables in listing 17.6
> Thanks for your quick reply,

You're welcome. I will try to answer the questions ASAP.

>I read chapter 17 except part about EL because I dislike expression languages.

I particularly like EL because of my JSP/JSTL background. But the idea of that section was to show a possible solution and lead the way for another ones (one could use Velocity, for example).

> It's clear for me and it contains solutions.

Good.

> As always the real problems come if you start to use it but this chapter gives a good baseground.

I agree. No matter how much easier a technology (like DbUnit, Spring, Hibernate, etc..) makes your life, there is always some challenges, and no book will cover all of them. But if the book gave you some background and insights, then we did our part smilie

> - It contains 'assertUser( user);' Where does the method assert() comes from?

assert() is staticly imported from JUnit's. I think I explained that earlier on, but I will double check.

> - Use of field id is not totally clear.

The idea is that this id is updated as test cases run, so the tests would pass regardless of being run standalone or in a suite.

> This field is not set in class AbstractDbUnitTemplateTestCase
> and no value is set in testGetUserById().

Its initial value does not matter (it's 0, initially), what is important is that it is updated when new objects are added. I will explicitly initialized it, anyways, to make it clearer.

-- Felipe
rikvdk (8) [Avatar] Offline
#5
Re: Create tables in listing 17.6
HI Felipe,

>> - It contains 'assertUser( user);' Where does the method assert() comes from?

>assert() is staticly imported from JUnit's. I think I explained that earlier on, but I will double check.

Sorry, I made a typo. I mentioned assertUser() as in mine first sentence.

Regards,
Rik
felipe.leme (18) [Avatar] Offline
#6
Re: Create tables in listing 17.6
Sorry, I made a typo. I mentioned assertUser() as in mine first sentence.

Ah, ok, my bad, should have realized it smilie.

Hmm, that method is defined on EntitiesHelper, but it looks like it's not included in the text (although it is available for download). Thanks again for pointing out, I will include it on the next review.