Search in sources :

Example 6 with Embeddable

use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldThrowExceptionUponFailingStoriesAsEmbeddablesInBatchIfIgnoreFailureInStoriesFlagIsNotSet.

@Test(expected = RunningEmbeddablesFailed.class)
public void shouldThrowExceptionUponFailingStoriesAsEmbeddablesInBatchIfIgnoreFailureInStoriesFlagIsNotSet() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doBatch(true);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    String myStoryName = MyStory.class.getName();
    String myOtherStoryName = MyOtherEmbeddable.class.getName();
    List<String> classNames = asList(myStoryName, myOtherStoryName);
    Embeddable myStory = new MyFailingEmbeddable();
    Embeddable myOtherStory = new MyOtherEmbeddable();
    EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
    when(classLoader.newInstance(Embeddable.class, myStoryName)).thenReturn(myStory);
    when(classLoader.newInstance(Embeddable.class, myOtherStoryName)).thenReturn(myOtherStory);
    // When
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    embedder.useClassLoader(classLoader);
    embedder.runAsEmbeddables(classNames);
// Then fail as expected
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Embeddable(org.jbehave.core.Embeddable) Test(org.junit.Test)

Example 7 with Embeddable

use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldRunStoriesAsEmbeddables.

@Test
public void shouldRunStoriesAsEmbeddables() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls();
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    String myEmbeddableName = MyEmbeddable.class.getName();
    String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
    List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
    Embeddable myEmbeddable = new MyEmbeddable();
    Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
    List<Embeddable> embeddables = asList(myEmbeddable, myOtherEmbeddable);
    EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
    when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
    when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
    // When
    Configuration configuration = new MostUsefulConfiguration();
    CandidateSteps steps = mock(CandidateSteps.class);
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    embedder.useClassLoader(classLoader);
    embedder.useConfiguration(configuration);
    embedder.useCandidateSteps(asList(steps));
    embedder.runAsEmbeddables(classNames);
    // Then
    for (Embeddable embeddable : embeddables) {
        assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
    }
}
Also used : PrintStream(java.io.PrintStream) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Embeddable(org.jbehave.core.Embeddable) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Test(org.junit.Test)

Example 8 with Embeddable

use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.

the class Embedder method reportStepdocsAsEmbeddables.

public void reportStepdocsAsEmbeddables(List<String> classNames) {
    EmbedderControls embedderControls = embedderControls();
    if (embedderControls.skip()) {
        embedderMonitor.embeddablesSkipped(classNames);
        return;
    }
    for (Embeddable embeddable : embeddables(classNames, classLoader())) {
        if (embeddable instanceof ConfigurableEmbedder) {
            ConfigurableEmbedder configurableEmbedder = (ConfigurableEmbedder) embeddable;
            Embedder configuredEmbedder = configurableEmbedder.configuredEmbedder();
            List<CandidateSteps> steps = configuredEmbedder.candidateSteps();
            if (steps.isEmpty()) {
                steps = configuredEmbedder.stepsFactory().createCandidateSteps();
            }
            reportStepdocs(configuredEmbedder.configuration(), steps);
        } else {
            embedderMonitor.embeddableNotConfigurable(embeddable.getClass().getName());
        }
    }
}
Also used : ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) CandidateSteps(org.jbehave.core.steps.CandidateSteps) Embeddable(org.jbehave.core.Embeddable)

Example 9 with Embeddable

use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldNotThrowExceptionUponFailingStoriesAsEmbeddablesIfIgnoreFailureFlagsAreSet.

@Test
public void shouldNotThrowExceptionUponFailingStoriesAsEmbeddablesIfIgnoreFailureFlagsAreSet() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doIgnoreFailureInStories(true).doIgnoreFailureInView(true);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    String myEmbeddableName = MyFailingEmbeddable.class.getName();
    String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
    List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
    Embeddable myEmbeddable = new MyFailingEmbeddable();
    Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
    EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
    when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
    when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
    // When
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    embedder.useClassLoader(classLoader);
    embedder.runAsEmbeddables(classNames);
    // Then
    assertThat(out.toString(), containsString("Running embeddable " + myEmbeddableName));
    assertThat(out.toString(), containsString("Failed to run embeddable " + myEmbeddableName));
    assertThat(out.toString(), containsString("Running embeddable " + myOtherEmbeddableName));
    assertThat(out.toString(), not(containsString("Failed to run embeddable " + myOtherEmbeddableName)));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Embeddable(org.jbehave.core.Embeddable) Test(org.junit.Test)

Example 10 with Embeddable

use of org.jbehave.core.Embeddable in project jbehave-core by jbehave.

the class EmbedderBehaviour method shouldNotGenerateViewWhenRunningStoriesAsEmbeddablesIfGenerateViewAfterStoriesFlagIsNotSet.

@Test
public void shouldNotGenerateViewWhenRunningStoriesAsEmbeddablesIfGenerateViewAfterStoriesFlagIsNotSet() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doGenerateViewAfterStories(false);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    String myEmbeddableName = MyEmbeddable.class.getName();
    String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
    List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
    Embeddable myEmbeddable = new MyEmbeddable();
    Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
    List<Embeddable> embeddables = asList(myEmbeddable, myOtherEmbeddable);
    EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
    when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
    when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
    // When
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    embedder.useClassLoader(classLoader);
    embedder.runAsEmbeddables(classNames);
    // Then
    for (Embeddable embeddable : embeddables) {
        assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
    }
    assertThat(out.toString(), not(containsString("Generating stories view")));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Embeddable(org.jbehave.core.Embeddable) Test(org.junit.Test)

Aggregations

Embeddable (org.jbehave.core.Embeddable)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 OutputStream (java.io.OutputStream)10 PrintStream (java.io.PrintStream)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)10 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)10 Test (org.junit.Test)10 ConfigurableEmbedder (org.jbehave.core.ConfigurableEmbedder)2 Configuration (org.jbehave.core.configuration.Configuration)2 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)2 UnderscoredCamelCaseResolver (org.jbehave.core.io.UnderscoredCamelCaseResolver)2 CandidateSteps (org.jbehave.core.steps.CandidateSteps)2 IOException (java.io.IOException)1 BatchFailures (org.jbehave.core.failures.BatchFailures)1 AnnotatedEmbedderRunner (org.jbehave.core.junit.AnnotatedEmbedderRunner)1