Paul,
Here you go. This code uses the test data builders discussed in the
book Growing Object-Oriented Software, Guided by Tests. It also uses
the UnitOfWork pattern also discussed in the book. The second @Given
uses JPA under the covers to persist objects in the database for the
benefit of @When (not shown). I'd like to use something like a Spring
@Transactional annotation, eliminating the need for the UnitOfWork
class and allowing me to inline the establishingDomain() method.
NB: Database setup is required because the SUT uses a shared database
and doesn't offer the functionality to actually create plans,
providers, and participants. Other (harder to test) applications that
use the same database offer the said create functionality. In a single
system that had all the functionality, I would consider using an
application based interface instead.
public class FirstAvailableClaimDateSteps extends TransactionalSteps {
private String planType;
private Date firstAvailableClaimDate;
private Provider provider;
private InsurancePlan plan;
private Participant participant;
public FirstAvailableClaimDateSteps() {
...
}
�...@given("today is $date")
public void todayIs(Date today) {
setToday(today);
}
�...@given("a policy for a <planType> provider plan with a first
available claim date of <firstAvailableClaimDate>")
public void participantPolicy(@Named("planType") String planType,
�...@named("firstAvailableClaimDate") Date firstAvailableClaimDate) {
this.planType = planType;
this.firstAvailableClaimDate = firstAvailableClaimDate;
establishDomain();
}
private void establishDomain() {
transact(new UnitOfWork() {
public void work() {
establishingDomain();
}
});
}
private void establishingDomain() {
provider = establishing(aProvider().withReasonableDefaults());
plan = establishing(anInsurancePlan().withReasonableDefaults()
.offeredBy(provider)
.withFirstAvailableClaimDate(firstAvailableClaimDate)
.withPlanType(planType));
participant = establishing(aParticipant().withReasonableDefaults());
policy = establishing(aPolicy().heldBy(participant).basedOn(plan));
}
...
}
On Fri, Feb 19, 2010 at 10:36 AM, Paul Hammant <[email protected]> wrote:
> Probably not. Show us a code snippet of what you're expecting.
>
> Regards,
>
> - Paul
>
> On Feb 19, 2010, at 7:05 AM, Christopher Gardner wrote:
>
>> Are transactional attributes supported? They would certainly make
>> @Given's less verbose in the case of say JPA for setup.
>>
>> On Fri, Feb 19, 2010 at 5:58 AM, Mauro Talevi
>> <[email protected]> wrote:
>>> Hi all,
>>>
>>> Steps class-level dependency injection is now supported in JBehave 2.5:
>>>
>>> http://jbehave.org/reference/latest/dependency-injection.html
>>>
>>> It supports 3 major containers most widely used (Pico, Spring, Guice).
>>> Each container support is provided via a separate extension module.
>>>
>>> The trader example has been updated to show the behaviour for all 3
>>> containers (using the same Steps classes used without dependency injection).
>>>
>>> A snapshot of latest revision has been deployed. Feedback is most
>>> welcome as always. For those that can't use snapshots we could deploy a
>>> beta.
>>>
>>> Cheers
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>> http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email