• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Testing db CRUD calls.

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I apologize for rather vague subject line. I have been asked my manager to write a "test bed" for running tests that call dao classes, some thing like Spring without using Spring. I have managed to set up thread local connection to both Daos and my test class. That way I have the same connection attributes. Now what I would like to do in my test class is have my DAO class make a db call (say insert) and then use the same connection in my test class to query if the insert really worked) and rollback the changes after my test has been executed. That way the database will roll back to its known state after every test run.

I have an AOP interceptor/listener where I can invoke the connection commit/rollback. But I want to be able to see the results of my insert query in the db before I can query the database. I have set auto commit to false. Are they any configurations that I need to make to the connection to make this possible?

Thanks,

Kartik
 
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

I don't understand what you are trying to do in this part of your explanation:

But I want to be able to see the results of my insert query in the db before I can query the database.


 
kartik krishnan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Jan,

Thanks for replying. I know it is a little vague but I don't know how to explain it myself. To write a pseudo code, it would be some thing like this



I know that Spring some thing like this but we don't use Spring in our project so any help would be appreciated.

Thanks,

Kartik
 
Jan Cumps
Bartender
Posts: 2662
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I move this thread to our Testing forum.
It is related to databases and JDBC, but I think that what you are looking for is a test pattern to verify your CRUD operations, and not JDBC help with these CRUD operations.
 
kartik krishnan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess what I am looking for is a way to set up connection metadata such that if I run an insert query, i should be able to see my changes. After rollback, I should not be able to. Do I have changes to connection' isolation or any other metadata?

Thanks,

Kartik
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

have you ever tried to use a DBUnit?
 
kartik krishnan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have used DbUnit but DBUnit Composite transaction first inserts the database into the database and then deletes it. I call stored procedures with CallableStatements. If it goes wrong, then I have invalid data in my database.
 
Leonardo Rafaeli
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but as far I know there is a configuration that allows you to keep you database in a know state without cleaning it up.

I mean, you can populate your base, execute your tests and after the test data will be there

is that you want?

Leo
 
kartik krishnan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Leo: Thanks for replying. I only want the test data during the execution of test method and not persisted in the database. Ideally, the data would be deleted or the entire operation could be rolled back after the test execution is complete.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic