Hi Sathish,
It's completely plausible to use @Given to *setup initial data* for
scenarios (just for that). And I'm using this approach since JB 2.0 with
annotations and Guice.
My first approach was to use DBunit, but I give it up because I couldn't
do all things that was needed ( to use hibernate)... So I've created my
own classes for that.
Basically, I've created 4 classes: PersinstenceControler,
PersitenceContext (where I inject the connection info from a .properties
file that I can setup using maven resources), an Generic DAO and an
BusinessEntity (that contain metadata info about the entities). All
objects are injected on Step classes using Guice.
Unfortunately I don't know springs and I can't give you all the code,
but this method of my PersistenceControler can give you an idea how I do
to create transactions. Hope can help you:
// this method will insert rows on an Entity Table using a Jbehave
ExampleTable
private List<Boolean> createPersistentsObjects(
BusinessEntity businessEntity, EntityExamplesTable
objectsTable,
Class<?> javaEntityClass) {
if (isFakeMode()) {
// when on fake mode just return a empty list
return Lists.newArrayList(true);
} else {
List<Boolean> results = Lists.newArrayList();
for (Map<String, String> objectRow : objectsTable.getRows()) {
Object javaEntity = null;
try {
* Transaction transaction = getSessionFactory()
.getCurrentSession().beginTransaction();
/// *this search for the JavaEntity associated with
businessEntity on the MetaData Repository
javaEntity = searchUnique(buildSearchCriteria(
javaEntityClass, objectsTable));
if (javaEntity == null) {
javaEntity = javaEntityClass.newInstance();
fillFrameworkRequestedNotNullValues(businessEntity,
javaEntity);
fillBusinessEntityValues(businessEntity,
javaEntity,
objectRow);
create(javaEntity);
}
transaction.commit();
results.add(true);
} catch (Exception e) {
results.add(false);
}
}
return results;
}
}
cheers
Cristiano
On 27/02/11 15:09, Sathish Kumar wrote:
Hi,
I have a test like this:
Given I have book ISBN001 that sells at 20 $
Given the discount is 10 %
When i shop for the book ISBN001
Then the price of the book must be 18 $
Is it a good idea to to use JPA/Hibernate to setup test data in @Given?
I cant get Hibernate to work without using
AbstractTransactionalJUnitSpringTest.
Webapp cannot access data since Transaction in @Given are not
committed to DB.
It's more tempting and readable to use data setup in @Given than a
dbunit file.
Is there any way to get this working?
Thanks,
Sathish
On Sun, Feb 27, 2011 at 11:05 PM, Brian Repko
<brian.re...@learnthinkcode.com
<mailto:brian.re...@learnthinkcode.com>> wrote:
Don't make the tests transactional...that is more for unit testing
than
ATDD/BDD/functional testing. I'll start with a clean database (use
dbunit but only to wipe the data - or have hibernate/spring startup
do that) but then let my tests actually hit the database.
Brian
----- Original message -----
From: "Sathish Kumar" <sathish...@gmail.com
<mailto:sathish...@gmail.com>>
To: user@jbehave.codehaus.org <mailto:user@jbehave.codehaus.org>
Date: Sun, 27 Feb 2011 21:24:28 +0530
Subject: [jbehave-user] Test data setup considerations
Hi,
Are there any good practices for Test data setup with JBehave.
I tried the following approaches:
1. Use DbUnit to setup data and Run scenarios (Works perfectly)
2. Use builder/factory and Given methods to setup data
Ex: Given the store has book titled Spring which sells at 20 $
will internally use BookFactory to persist book and Then will
check the webapp.
I haven't had success in the 2nd approach due to Transactions not
being committed.
Do you have any suggestions on this?
Thanks,
Sathish
---
Brian Repko
LearnThinkCode, Inc. <http://www.learnthinkcode.com>
email: brian.re...@learnthinkcode.com
<mailto:brian.re...@learnthinkcode.com>
phone: +1 612 229 6779