-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: unit testing of hibernate
PostPosted: Thu May 31, 2007 12:20 am 
Newbie

Joined: Wed May 30, 2007 12:25 pm
Posts: 1
how can i write testcase using junit for fallowing code:

private RetentionPeriod getDataRetentionPeriod(Long partnerId) throws Exception {
RetentionPeriod period = null;

Session s = null;
Transaction tx = null;

try {
s = HibernateUtil.currentSession();
// start a new transaction
tx = s.beginTransaction();

Query query = s.createQuery("from RetentionPeriod r where r.partnerId = :partnerId");
query.setLong("partnerId", partnerId.longValue());

List periodList = query.list();
period = (periodList.isEmpty()) ? null : (RetentionPeriod) periodList.get(0);

// commit the transaction
tx.commit();
} catch (Exception e) {
// rollback the transaction
if (tx != null)
tx.rollback();
s.clear();
// an exception has occurred
throw e;
}
return period;
}

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 3:09 am 
Beginner
Beginner

Joined: Sat Jan 14, 2006 10:05 am
Posts: 22
Location: spb.ru
Hello

I'm using TestNG, HypersonicSQL, Embedded EJB3 by JBoss (as lightweight JTA and JNDI) for this purpose. Main scenario is bootstrap HSQL datasource, and SessionFactory (for create db schema), then I'am using TestNG for persist domain objects (with tx-demarcation), then it is able to query and modify domain. also I can look to db afer test routine

thats all


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.