Search in sources :

Example 36 with MostUsefulConfiguration

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

the class EmbedderBehaviour method shouldRunStoriesAsPaths.

@SuppressWarnings("unchecked")
@Test
public void shouldRunStoriesAsPaths() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls();
    EmbedderMonitor embedderMonitor = mock(EmbedderMonitor.class);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    List<? extends Class<? extends Embeddable>> embeddables = asList(MyStory.class, MyOtherEmbeddable.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    InjectableStepsFactory stepsFactory = embedder.stepsFactory();
    MetaFilter filter = embedder.metaFilter();
    final StoryReporter storyReporter = mock(StoryReporter.class);
    MostUsefulConfiguration configuration = new MostUsefulConfiguration() {

        @Override
        public StoryReporter storyReporter(String storyPath) {
            return storyReporter;
        }
    };
    embedder.useConfiguration(configuration);
    StoryPathResolver resolver = configuration.storyPathResolver();
    List<String> storyPaths = new ArrayList<>();
    Map<String, Story> stories = new HashMap<>();
    for (Class<? extends Embeddable> embeddable : embeddables) {
        String storyPath = resolver.resolve(embeddable);
        storyPaths.add(storyPath);
        Story story = mockStory(Meta.EMPTY);
        stories.put(storyPath, story);
        when(performableTree.storyOfPath(configuration, storyPath)).thenReturn(story);
        when(story.getPath()).thenReturn(storyPath);
        assertThat(configuration.storyReporter(storyPath), sameInstance(storyReporter));
    }
    RunContext runContext = new RunContext(configuration, stepsFactory, embedderMonitor, filter, new BatchFailures());
    when(performableTree.newRunContext(isA(Configuration.class), isA(InjectableStepsFactory.class), isA(EmbedderMonitor.class), isA(MetaFilter.class), isA(BatchFailures.class))).thenReturn(runContext);
    // When
    embedder.runStoriesAsPaths(storyPaths);
    // Then
    for (String storyPath : storyPaths) {
        verify(performableTree).perform(Matchers.isA(RunContext.class), Matchers.eq(stories.get(storyPath)));
        assertThat(out.toString(), containsString("Running story " + storyPath));
    }
    assertThatReportsViewGenerated(out);
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) PrintStream(java.io.PrintStream) InjectableStepsFactory(org.jbehave.core.steps.InjectableStepsFactory) StoryPathResolver(org.jbehave.core.io.StoryPathResolver) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) HashMap(java.util.HashMap) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) BatchFailures(org.jbehave.core.failures.BatchFailures) RunContext(org.jbehave.core.embedder.PerformableTree.RunContext) JUnitStory(org.jbehave.core.junit.JUnitStory) Story(org.jbehave.core.model.Story) Test(org.junit.Test)

Example 37 with MostUsefulConfiguration

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

the class StoryManagerBehaviour method shouldEnsureStoryReportOutputDirectoryExistsWhenWritingStoryDurations.

@Test
public void shouldEnsureStoryReportOutputDirectoryExistsWhenWritingStoryDurations() throws IOException {
    Configuration configuration = new MostUsefulConfiguration();
    configuration.storyReporterBuilder().withRelativeDirectory("inexistent");
    File outputDirectory = configuration.storyReporterBuilder().outputDirectory();
    FileUtils.deleteDirectory(outputDirectory);
    assertThat(outputDirectory.exists(), is(false));
    StoryManager manager = new StoryManager(configuration, stepsFactory, embedderControls, embedderMonitor, executorService, performableTree);
    Collection<RunningStory> runningStories = new ArrayList<>();
    manager.writeStoryDurations(runningStories);
    assertThat(outputDirectory.exists(), is(true));
}
Also used : RunningStory(org.jbehave.core.embedder.StoryManager.RunningStory) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 38 with MostUsefulConfiguration

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

the class ConfigurableEmbedderBehaviour method shouldAllowOverrideOfDefaultConfiguration.

@Test
public void shouldAllowOverrideOfDefaultConfiguration() throws Throwable {
    // Given
    Embedder embedder = mock(Embedder.class);
    Configuration configuration = mock(Configuration.class);
    StoryPathResolver pathResolver = mock(StoryPathResolver.class);
    when(embedder.configuration()).thenReturn(configuration);
    when(configuration.storyPathResolver()).thenReturn(pathResolver);
    Class<MyStory> storyClass = MyStory.class;
    String storyPath = "/path/to/story";
    when(pathResolver.resolve(storyClass)).thenReturn(storyPath);
    CandidateSteps steps = mock(CandidateSteps.class);
    // When
    MyStory story = new MyStory(new MostUsefulConfiguration(), steps);
    assertThat(story.configuration(), is(not(sameInstance(configuration))));
    story.useConfiguration(configuration);
    assertThat(story.configuration(), is(sameInstance(configuration)));
    story.useEmbedder(embedder);
    story.run();
    // Then
    verify(embedder).useConfiguration(configuration);
    verify(embedder).useCandidateSteps(Mockito.eq(Arrays.asList(steps)));
    verify(embedder).runStoriesAsPaths(asList(storyPath));
}
Also used : StoryPathResolver(org.jbehave.core.io.StoryPathResolver) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Embedder(org.jbehave.core.embedder.Embedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 39 with MostUsefulConfiguration

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

the class StepCreatorBehaviour method shouldHandleTargetInvocationFailureInBeforeOrAfterStep.

@Test
public void shouldHandleTargetInvocationFailureInBeforeOrAfterStep() throws IntrospectionException {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    MostUsefulConfiguration configuration = new MostUsefulConfiguration();
    InjectableStepsFactory stepsFactory = new InstanceStepsFactory(configuration, stepsInstance);
    StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, configuration.parameterConverters(), new ParameterControls(), null, new SilentStepMonitor());
    // When
    Method method = SomeSteps.methodFor("aFailingBeforeScenarioMethod");
    StepResult stepResult = stepCreator.createBeforeOrAfterStep(method, Meta.EMPTY).perform(null);
    // Then
    assertThat(stepResult, instanceOf(Failed.class));
    assertThat(stepResult.getFailure(), instanceOf(UUIDExceptionWrapper.class));
    Throwable cause = stepResult.getFailure().getCause();
    assertThat(cause, instanceOf(BeforeOrAfterFailed.class));
    assertThat(cause.getMessage(), org.hamcrest.Matchers.equalTo("Method aFailingBeforeScenarioMethod (annotated with @BeforeScenario in class org.jbehave.core.steps.SomeSteps) failed: java.lang.RuntimeException"));
}
Also used : MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) BeforeOrAfterFailed(org.jbehave.core.failures.BeforeOrAfterFailed) Failed(org.jbehave.core.steps.AbstractStepResult.Failed) Method(java.lang.reflect.Method) BeforeOrAfterFailed(org.jbehave.core.failures.BeforeOrAfterFailed) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 40 with MostUsefulConfiguration

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

the class StepCreatorBehaviour method shouldDescribeStepToReporterBeforeExecutingParametrisedStep.

@Test
public void shouldDescribeStepToReporterBeforeExecutingParametrisedStep() throws IntrospectionException {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    InjectableStepsFactory stepsFactory = new InstanceStepsFactory(new MostUsefulConfiguration(), stepsInstance);
    StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, null, new ParameterControls(), null, new SilentStepMonitor());
    StoryReporter storyReporter = mock(StoryReporter.class);
    // When
    Method method = SomeSteps.methodFor("aMethod");
    ((ParametrisedStep) stepCreator.createParametrisedStep(method, "When I run", "I run", null)).describeTo(storyReporter);
    // Then
    verify(storyReporter).beforeStep("When I run");
}
Also used : StoryReporter(org.jbehave.core.reporters.StoryReporter) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Method(java.lang.reflect.Method) 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