Search in sources :

Example 61 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.

the class SpringStepsFactoryBehaviour method beansWithUndefinedTypeOrCannotBeCreatedWillBeIgnored.

@Test
public void beansWithUndefinedTypeOrCannotBeCreatedWillBeIgnored() {
    // Given
    ApplicationContext context = mock(ApplicationContext.class);
    SpringStepsFactory factory = new SpringStepsFactory(new MostUsefulConfiguration(), context);
    // When
    when(context.getBeanDefinitionNames()).thenReturn(new String[] { "fooSteps", "undefined", "blowUp" });
    doAnswer(new Answer<Class<FooSteps>>() {

        public Class<FooSteps> answer(InvocationOnMock invocation) throws Throwable {
            return FooSteps.class;
        }
    }).when(context).getType("fooSteps");
    when(context.getType("undefined")).thenReturn(null);
    doAnswer(new Answer<Class<BlowUp>>() {

        public Class<BlowUp> answer(InvocationOnMock invocation) throws Throwable {
            return BlowUp.class;
        }
    }).when(context).getType("blowUp");
    when(context.getBean("fooSteps")).thenReturn(new FooSteps());
    when(context.getBean("blowUp")).thenThrow(new RuntimeException("Bum!"));
    List<CandidateSteps> candidateSteps = factory.createCandidateSteps();
    // Then
    assertThat(candidateSteps.size(), equalTo(1));
    assertThat(firstStepsInstance(candidateSteps), instanceOf(FooSteps.class));
    verify(context, never()).getBean("undefined");
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 62 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.

the class ConfigurationProducer method getConfiguration.

@Produces
@WeldConfiguration
Configuration getConfiguration() {
    Properties viewResources = new Properties();
    viewResources.setProperty("index", "my-reports-index.ftl");
    viewResources.setProperty("decorateNonHtml", "true");
    TableTransformers tableTransformers = new TableTransformers();
    LoadFromURL resourceLoader = new LoadFromURL();
    return new MostUsefulConfiguration().useStoryControls(new StoryControls().doDryRun(true).doSkipScenariosAfterFailure(true)).useFailureStrategy(new SilentlyAbsorbingFailure()).useStoryLoader(resourceLoader).useStepPatternParser(new RegexPrefixCapturingPatternParser("MyPrefix")).useStoryReporterBuilder(new StoryReporterBuilder().withDefaultFormats().withFormats(CONSOLE, HTML, TXT, XML).withKeywords(new LocalizedKeywords(Locale.ITALIAN)).withRelativeDirectory("my-output-directory").withViewResources(viewResources).withFailureTrace(true)).useParameterConverters(new ParameterConverters(resourceLoader, tableTransformers).addConverters(new CustomConverter(), new MyDateConverter())).useTableTransformers(tableTransformers);
}
Also used : SilentlyAbsorbingFailure(org.jbehave.core.failures.SilentlyAbsorbingFailure) RegexPrefixCapturingPatternParser(org.jbehave.core.parsers.RegexPrefixCapturingPatternParser) StoryReporterBuilder(org.jbehave.core.reporters.StoryReporterBuilder) LoadFromURL(org.jbehave.core.io.LoadFromURL) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ParameterConverters(org.jbehave.core.steps.ParameterConverters) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) StoryControls(org.jbehave.core.embedder.StoryControls) Properties(java.util.Properties) TableTransformers(org.jbehave.core.model.TableTransformers) Produces(javax.enterprise.inject.Produces) WeldConfiguration(org.jbehave.core.annotations.weld.WeldConfiguration)

Example 63 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.

the class PicoStepsFactoryBehaviour method assertThatStepsCanBeCreated.

@Test
public void assertThatStepsCanBeCreated() throws NoSuchFieldException, IllegalAccessException {
    // Given
    MutablePicoContainer parent = createPicoContainer();
    parent.as(Characteristics.USE_NAMES).addComponent(FooSteps.class);
    PicoStepsFactory factory = new PicoStepsFactory(new MostUsefulConfiguration(), parent);
    // When
    List<CandidateSteps> steps = factory.createCandidateSteps();
    // Then
    assertFooStepsFound(steps);
}
Also used : MutablePicoContainer(org.picocontainer.MutablePicoContainer) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 64 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.

the class NeedleStepsFactoryBehaviour method stepsShouldContainInjectedDependencies.

@Test
public void stepsShouldContainInjectedDependencies() throws NoSuchFieldException, IllegalAccessException {
    // Given
    final InjectableStepsFactory factory = new NeedleStepsFactory(new MostUsefulConfiguration(), FooStepsWithDependency.class);
    // When
    List<CandidateSteps> steps = factory.createCandidateSteps();
    // Then
    assertThat(steps.size(), equalTo(1));
    boolean actual1 = steps.get(0) instanceof CandidateSteps;
    assertThat(actual1, is(true));
    Object instance = stepsInstance(steps.get(0));
    boolean actual = instance instanceof FooStepsWithDependency;
    assertThat(actual, is(true));
    FooStepsWithDependency withDependency = (FooStepsWithDependency) instance;
    assertThat(withDependency.getter, is(notNullValue()));
    assertThat((String) withDependency.getter.getValue(), equalTo(ValueGetter.VALUE));
}
Also used : InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 65 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.

the class NeedleStepsFactoryBehaviour method stepsShouldBeCreated.

@Test
public void stepsShouldBeCreated() throws NoSuchFieldException, IllegalAccessException {
    // Given
    final InjectableStepsFactory factory = new NeedleStepsFactory(new MostUsefulConfiguration(), FooSteps.class);
    // When
    List<CandidateSteps> steps = factory.createCandidateSteps();
    // Then
    assertThat(steps.size(), equalTo(1));
    boolean actual1 = steps.get(0) instanceof CandidateSteps;
    assertThat(actual1, is(true));
    Object instance = stepsInstance(steps.get(0));
    boolean actual = instance instanceof FooSteps;
    assertThat(actual, is(true));
}
Also used : InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Aggregations

MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)66 Test (org.junit.Test)52 Configuration (org.jbehave.core.configuration.Configuration)14 CandidateSteps (org.jbehave.core.steps.CandidateSteps)14 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)11 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)8 TableTransformers (org.jbehave.core.model.TableTransformers)8 Method (java.lang.reflect.Method)7 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)7 ParameterConverters (org.jbehave.core.steps.ParameterConverters)7 SimpleDateFormat (java.text.SimpleDateFormat)5 HashMap (java.util.HashMap)5 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)5 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)5 BeforeOrAfterFailed (org.jbehave.core.failures.BeforeOrAfterFailed)5 Failed (org.jbehave.core.steps.AbstractStepResult.Failed)5 ApplicationContext (org.springframework.context.ApplicationContext)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4 PrintStream (java.io.PrintStream)4