SpringJUnitStory source:
@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();
}
}
}
On Sun, Feb 27, 2011 at 9:41 PM, Sathish Kumar <[email protected]> wrote:
> 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
>>>>
>>>
>>>
>>
>