Search in sources :

Example 11 with EmbedderClassLoader

use of org.jbehave.core.embedder.EmbedderClassLoader in project jbehave-core by jbehave.

the class EmbedderMojoBehaviour method shouldReportFailuresInRunningStoriesWithAnnotatedEmbedderRunner.

@Test(expected = MojoFailureException.class)
public void shouldReportFailuresInRunningStoriesWithAnnotatedEmbedderRunner() throws MojoExecutionException, MojoFailureException {
    // Given
    final EmbedderClassLoader classLoader = new EmbedderClassLoader(this.getClass().getClassLoader());
    RunStoriesWithAnnotatedEmbedderRunner mojo = new RunStoriesWithAnnotatedEmbedderRunner() {

        @Override
        protected Embedder newEmbedder() {
            return embedder;
        }

        @Override
        protected EmbedderClassLoader classLoader() {
            return classLoader;
        }
    };
    String searchInDirectory = "src/test/java/";
    mojo.sourceDirectory = searchInDirectory;
    List<String> includes = asList("**/stories/*.java");
    mojo.includes = includes;
    List<String> excludes = asList();
    mojo.excludes = excludes;
    List<String> classNames = new StoryFinder().findClassNames(searchInDirectory, includes, excludes);
    // When
    doThrow(new RuntimeException()).when(embedder).runStoriesWithAnnotatedEmbedderRunner(classNames);
    mojo.execute();
    // Then fail as expected
    mojo.execute();
}
Also used : StoryFinder(org.jbehave.core.io.StoryFinder) EmbedderClassLoader(org.jbehave.core.embedder.EmbedderClassLoader) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 12 with EmbedderClassLoader

use of org.jbehave.core.embedder.EmbedderClassLoader in project jbehave-core by jbehave.

the class EmbedderMojoBehaviour method shouldReportFailuresInRunningStoriesAsPaths.

@Test(expected = MojoFailureException.class)
public void shouldReportFailuresInRunningStoriesAsPaths() throws MojoExecutionException, MojoFailureException {
    // Given
    final EmbedderClassLoader classLoader = new EmbedderClassLoader(this.getClass().getClassLoader());
    RunStoriesAsPaths mojo = new RunStoriesAsPaths() {

        @Override
        protected Embedder newEmbedder() {
            return embedder;
        }

        @Override
        protected EmbedderClassLoader classLoader() {
            return classLoader;
        }
    };
    String searchInDirectory = "src/test/java/";
    mojo.sourceDirectory = searchInDirectory;
    List<String> includes = asList("**/stories/*.story");
    mojo.includes = includes;
    List<String> excludes = asList();
    mojo.excludes = excludes;
    List<String> storyPaths = new StoryFinder().findPaths(searchInDirectory, includes, excludes);
    // When
    doThrow(new RuntimeException()).when(embedder).runStoriesAsPaths(storyPaths);
    mojo.execute();
// Then fail as expected
}
Also used : StoryFinder(org.jbehave.core.io.StoryFinder) EmbedderClassLoader(org.jbehave.core.embedder.EmbedderClassLoader) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 13 with EmbedderClassLoader

use of org.jbehave.core.embedder.EmbedderClassLoader in project jbehave-core by jbehave.

the class AbstractEmbedderMojo method newEmbedder.

/**
 * Creates an instance of Embedder, either using
 * {@link #injectableEmbedderClass} (if set) or defaulting to
 * {@link #embedderClass}.
 *
 * @return An Embedder
 */
protected Embedder newEmbedder() {
    Embedder embedder = null;
    EmbedderClassLoader classLoader = classLoader();
    if (injectableEmbedderClass != null) {
        embedder = classLoader.newInstance(InjectableEmbedder.class, injectableEmbedderClass).injectedEmbedder();
    } else {
        embedder = classLoader.newInstance(Embedder.class, embedderClass);
    }
    URL codeLocation = codeLocation();
    if (codeLocation != null) {
        embedder.configuration().storyReporterBuilder().withCodeLocation(codeLocation);
    }
    embedder.useClassLoader(classLoader);
    embedder.useEmbedderControls(embedderControls());
    if (executorsClass != null) {
        ExecutorServiceFactory executorServiceFactory = classLoader.newInstance(ExecutorServiceFactory.class, executorsClass);
        embedder.useExecutorService(executorServiceFactory.create(embedder.embedderControls()));
    }
    embedder.useEmbedderMonitor(embedderMonitor());
    if (isNotEmpty(metaFilters)) {
        List<String> filters = new ArrayList<>();
        for (String filter : metaFilters) {
            if (filter != null) {
                filters.add(filter);
            }
        }
        embedder.useMetaFilters(filters);
    }
    if (!systemProperties.isEmpty()) {
        embedder.useSystemProperties(systemProperties);
    }
    return embedder;
}
Also used : EmbedderClassLoader(org.jbehave.core.embedder.EmbedderClassLoader) ArrayList(java.util.ArrayList) Embedder(org.jbehave.core.embedder.Embedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) URL(java.net.URL) ExecutorServiceFactory(org.jbehave.core.embedder.executors.ExecutorServiceFactory)

Example 14 with EmbedderClassLoader

use of org.jbehave.core.embedder.EmbedderClassLoader in project jbehave-core by jbehave.

the class AbstractEmbedderTask method newEmbedder.

/**
 * Creates an instance of Embedder, either using
 * {@link #injectableEmbedderClass} (if set) or defaulting to
 * {@link #embedderClass}.
 *
 * @return An Embedder
 */
protected Embedder newEmbedder() {
    Embedder embedder = null;
    EmbedderClassLoader classLoader = classLoader();
    if (injectableEmbedderClass != null) {
        embedder = classLoader.newInstance(InjectableEmbedder.class, injectableEmbedderClass).injectedEmbedder();
    } else {
        embedder = classLoader.newInstance(Embedder.class, embedderClass);
    }
    URL codeLocation = codeLocation();
    if (codeLocation != null) {
        embedder.configuration().storyReporterBuilder().withCodeLocation(codeLocation);
    }
    embedder.useClassLoader(classLoader);
    embedder.useEmbedderControls(embedderControls());
    if (executorsClass != null) {
        ExecutorServiceFactory executorServiceFactory = classLoader.newInstance(ExecutorServiceFactory.class, executorsClass);
        embedder.useExecutorService(executorServiceFactory.create(embedder.embedderControls()));
    }
    embedder.useEmbedderMonitor(embedderMonitor());
    if (!metaFilters.isEmpty()) {
        embedder.useMetaFilters(metaFilters);
    }
    if (!systemProperties.isEmpty()) {
        embedder.useSystemProperties(systemProperties);
    }
    return embedder;
}
Also used : EmbedderClassLoader(org.jbehave.core.embedder.EmbedderClassLoader) Embedder(org.jbehave.core.embedder.Embedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) URL(java.net.URL) ExecutorServiceFactory(org.jbehave.core.embedder.executors.ExecutorServiceFactory)

Example 15 with EmbedderClassLoader

use of org.jbehave.core.embedder.EmbedderClassLoader in project jbehave-core by jbehave.

the class EmbedderTaskBehaviour method shouldMapStoriesAsEmbeddables.

@Test
public void shouldMapStoriesAsEmbeddables() {
    // Given
    final EmbedderClassLoader classLoader = new EmbedderClassLoader(this.getClass().getClassLoader());
    MapStoriesAsEmbeddables task = new MapStoriesAsEmbeddables() {

        @Override
        protected Embedder newEmbedder() {
            return embedder;
        }

        @Override
        protected EmbedderClassLoader classLoader() {
            return classLoader;
        }
    };
    String searchInDirectory = "src/test/java/";
    task.setSourceDirectory(searchInDirectory);
    task.setOutputDirectory("target/test-classes");
    List<String> includes = asList("**/*StoryMaps.java");
    task.setIncludes(StringUtils.join(includes, "'"));
    List<String> excludes = asList();
    task.setExcludes(StringUtils.join(excludes, "'"));
    List<String> classNames = new StoryFinder().findClassNames(searchInDirectory, includes, excludes);
    // When
    task.execute();
    // Then
    verify(embedder).runAsEmbeddables(classNames);
}
Also used : StoryFinder(org.jbehave.core.io.StoryFinder) EmbedderClassLoader(org.jbehave.core.embedder.EmbedderClassLoader) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

EmbedderClassLoader (org.jbehave.core.embedder.EmbedderClassLoader)17 Matchers.containsString (org.hamcrest.Matchers.containsString)15 StoryFinder (org.jbehave.core.io.StoryFinder)15 Test (org.junit.Test)15 URL (java.net.URL)2 ConfigurableEmbedder (org.jbehave.core.ConfigurableEmbedder)2 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)2 Embedder (org.jbehave.core.embedder.Embedder)2 ExecutorServiceFactory (org.jbehave.core.embedder.executors.ExecutorServiceFactory)2 ArrayList (java.util.ArrayList)1