Hi,
I've attached the SpringJUnitStory which i'm using to extend from
*AbstractTransactionalJUnit4SpringContextTests
*and use it to run individual stories with Spring support.
I have a custom Embedder configuration which is shared by both
SpringJunitStory and StoryRunner.

I'll be happy to contribute if you think this is useful.

Thanks,
Sathish

On Sun, Feb 27, 2011 at 9:17 PM, Paul Hammant <[email protected]> wrote:

> Was that successful for you Sathish?
>
> If yes, it might be a good thing to contribute back to the jbehave-spring
> module ?
>
> - Paul
>
>
> On Sun, Feb 27, 2011 at 9:35 AM, Sathish Kumar <[email protected]>wrote:
>
>> I looked at JUnitStory code and replicated that in my custom Test class
>> which also extends from AbstractTransactionalJUnit4SpringContextTests
>>
>> Sathish
>>
>>
>> On Sun, Feb 27, 2011 at 7:07 PM, Brian Repko <
>> [email protected]> wrote:
>>
>>>
>>> I'd suggest looking at the spring-security example for this.
>>>
>>> Brian
>>>
>>>  ----- Original message -----
>>> From: "Sathish Kumar" <[email protected]>
>>> To: [email protected]
>>> Date: Sun, 27 Feb 2011 16:52:19 +0530
>>> Subject: [jbehave-user] Spring support for JBehave JUnitStory
>>>
>>> Hi,
>>> I've got my story tests extend JUnitStory and an Embedder for running all
>>> stories.
>>> Now i can run tests during build using Embedder and individual tests in
>>> IDE.
>>>
>>> I looked at the TraderEmbedderWithSpringJUnit4ClassRunner which adds
>>> Spring integration.
>>> Some of my story tests require Hibernate SessionFactory for data setup.
>>> Since stories already extend JUnitStory, i can't extend
>>> AbstractTransactionalJUnit4SpringContextTests and i'm not able to get
>>> Autowiring working in Story tests.
>>>
>>> Is there a way to Autowire session factory or existing Spring beans when
>>> running stories individually?
>>>
>>> Thanks,
>>> Sathish
>>>
>>> ---
>>> Brian Repko
>>> LearnThinkCode, Inc. <http://www.learnthinkcode.com>
>>> email: [email protected]
>>> phone: +1 612 229 6779
>>>
>>
>>
>
import org.jbehave.core.Embeddable;
import org.jbehave.core.embedder.Embedder;
import org.jbehave.core.io.StoryPathResolver;
import org.jbehave.core.steps.spring.SpringStepsFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static java.util.Arrays.asList;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext.xml", "classpath:applicationContext-test.xml"})
public abstract class SpringJUnitStory extends AbstractTransactionalJUnit4SpringContextTests {

    @Autowired
    protected ApplicationContext context;

    private Embedder embedder;

    @Before
    public void setup() {
        embedder = configuredEmbedder();
        embedder.useCandidateSteps(new SpringStepsFactory(embedder.configuration(), context).createCandidateSteps());
    }

    public abstract Embedder configuredEmbedder();

    @Test
    public void run() throws Throwable {
        StoryPathResolver pathResolver = embedder.configuration().storyPathResolver();
        String storyPath = pathResolver.resolve((Class<? extends Embeddable>) this.getClass());
        try {
            embedder.runStoriesAsPaths(asList(storyPath));
        } finally {
            embedder.generateCrossReference();
        }
    }

}
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to