Hi Deepak, What you're about to write here is an integration test, not a unit test. In other words, I would really think again about whether it is a good idea to mock your whole database, including all sorts of constraints checking, instead of simply using an actual database for your tests. I promise you, you will not be happy if you continue the down the mocking path.
If this requirement cannot be changed (and you should insist that it can!), well, then I suggest you implement a full-fledged state machine that keeps track of all statements executed in the right order to assess whether an insert to the parent table has been performed before the insert to the child table. In other words, you'll be parsing the SQL statements, calculating the outcome of such statement, implementing foreign key constraints, etc., and then throwing a SQLException. Eventually, you'll also add transaction support and ACID-ness to your mock database. In other words, you'll be implementing an *actual* database, which brings us back to: why not just use an actual database for these tests, e.g. H2 :-) The MockConnection was added to jOOQ for very simple use cases, and as a simple database proxy where some statements can be intercepted easily. Cheers Lukas 2014-05-23 9:12 GMT+02:00 <[email protected]>: > Hi Lukas, > i have a DB - with 2 tables . table 1(Hierarchy) - Hid ,Hname and > table 2 (Levels)- Hid ,Lid,Lname. > in Table 1 Hid is primary key and In table two the Hid is the foreign > key. > When we directly try to insert into table 2 it gives foreign key > vilation and it is working fine with JOOQ implementation > > But my requirement is to mock the two tables using JOOQ > MockExecuteContext and test the same . i mean i will try to insert using > the provider class > ( Result<HierarchyLevelRecord> resultLevel > =create.newResult(HierarchyLevel.HIERARCHY_LEVEL) and it should fail in > the test DB as well . but this is not happening . > > TheMocked Db Constarints are not effective in MockExecuteContext . how can > this be achieved through JOOQ. > > Thanks, > Deepak > > -- > You received this message because you are subscribed to the Google Groups > "jOOQ User Group" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "jOOQ User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
