Search in sources :

Example 1 with Embeddable

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

the class EmbedderBehaviour method shouldMapStoriesAsEmbeddables.

@Test
public void shouldMapStoriesAsEmbeddables() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    String myEmbeddableName = MyStoryMaps.class.getName();
    List<String> classNames = asList(myEmbeddableName);
    Embeddable myEmbeddable = new MyStoryMaps();
    List<Embeddable> embeddables = asList(myEmbeddable);
    EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
    when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
    // When
    Configuration configuration = new MostUsefulConfiguration();
    Embedder embedder = embedderWith(performableTree, new EmbedderControls(), monitor);
    embedder.useClassLoader(classLoader);
    embedder.useConfiguration(configuration);
    embedder.runAsEmbeddables(classNames);
    // Then
    for (Embeddable embeddable : embeddables) {
        assertThat(out.toString(), containsString("Running embeddable " + embeddable.getClass().getName()));
    }
    assertThat(MyStoryMaps.run, is(true));
}
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) Test(org.junit.Test)

Example 2 with Embeddable

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

the class EmbedderBehaviour method shouldNotRunStoriesAsEmbeddablesIfAbstract.

@Test
public void shouldNotRunStoriesAsEmbeddablesIfAbstract() 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 = MyAbstractEmbeddable.class.getName();
    String myOtherEmbeddableName = MyOtherEmbeddable.class.getName();
    List<String> classNames = asList(myEmbeddableName, myOtherEmbeddableName);
    Embeddable myEmbeddable = new MyEmbeddable();
    Embeddable myOtherEmbeddable = new MyOtherEmbeddable();
    EmbedderClassLoader classLoader = mock(EmbedderClassLoader.class);
    when(classLoader.isAbstract(myEmbeddableName)).thenReturn(true);
    when(classLoader.newInstance(Embeddable.class, myEmbeddableName)).thenReturn(myEmbeddable);
    when(classLoader.isAbstract(myOtherEmbeddableName)).thenReturn(false);
    when(classLoader.newInstance(Embeddable.class, myOtherEmbeddableName)).thenReturn(myOtherEmbeddable);
    // When
    Embedder embedder = embedderWith(performableTree, embedderControls, monitor);
    embedder.useClassLoader(classLoader);
    embedder.configuration().useStoryPathResolver(new UnderscoredCamelCaseResolver());
    embedder.runAsEmbeddables(classNames);
    // Then
    assertThat(out.toString(), not(containsString("Running embeddable " + myEmbeddableName)));
    assertThat(out.toString(), containsString("Running 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) UnderscoredCamelCaseResolver(org.jbehave.core.io.UnderscoredCamelCaseResolver) Embeddable(org.jbehave.core.Embeddable) Test(org.junit.Test)

Example 3 with Embeddable

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

the class EmbedderBehaviour method shouldThrowExceptionUponFailingStoriesAsEmbeddablesIfIgnoreFailureInStoriesFlagIsNotSet.

@Test(expected = RunningEmbeddablesFailed.class)
public void shouldThrowExceptionUponFailingStoriesAsEmbeddablesIfIgnoreFailureInStoriesFlagIsNotSet() 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 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 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 4 with Embeddable

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

the class EmbedderBehaviour method shouldNotRunStoriesAsEmbeddablesIfSkipFlagIsSet.

@Test
public void shouldNotRunStoriesAsEmbeddablesIfSkipFlagIsSet() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doSkip(true);
    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.configuration().useStoryPathResolver(new UnderscoredCamelCaseResolver());
    embedder.runAsEmbeddables(classNames);
    // Then
    for (Embeddable embeddable : embeddables) {
        assertThat(out.toString(), not(containsString("Running embeddable " + embeddable.getClass().getName())));
    }
}
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) UnderscoredCamelCaseResolver(org.jbehave.core.io.UnderscoredCamelCaseResolver) Embeddable(org.jbehave.core.Embeddable) Test(org.junit.Test)

Example 5 with Embeddable

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

the class EmbedderBehaviour method shouldRunFailingStoriesAsEmbeddablesInBatchIfBatchFlagIsSet.

@Test
public void shouldRunFailingStoriesAsEmbeddablesInBatchIfBatchFlagIsSet() throws Throwable {
    // Given
    PerformableTree performableTree = mock(PerformableTree.class);
    EmbedderControls embedderControls = new EmbedderControls().doBatch(true).doIgnoreFailureInStories(true).doIgnoreFailureInView(true);
    OutputStream out = new ByteArrayOutputStream();
    EmbedderMonitor monitor = new PrintStreamEmbedderMonitor(new PrintStream(out));
    String myStoryName = MyFailingEmbeddable.class.getName();
    String myOtherStoryName = MyOtherEmbeddable.class.getName();
    List<String> classNames = asList(myStoryName, myOtherStoryName);
    Embeddable myStory = new MyFailingEmbeddable();
    Embeddable myOtherStory = new MyOtherEmbeddable();
    List<Embeddable> embeddables = asList(myStory, myOtherStory);
    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
    for (Embeddable embeddable : embeddables) {
        String storyName = embeddable.getClass().getName();
        assertThat(out.toString(), containsString("Running embeddable " + storyName));
    }
    assertThat(out.toString(), containsString("Failed to run batch"));
}
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