Search in sources :

Example 1 with ConfigurableEmbedder

use of org.jbehave.core.ConfigurableEmbedder 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 2 with ConfigurableEmbedder

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

the class AnnotationBuilderBehaviour method shouldCreateEmbeddableInstanceFromConfigurableEmbedder.

@Test
public void shouldCreateEmbeddableInstanceFromConfigurableEmbedder() {
    AnnotationBuilder annotatedConfigurable = new AnnotationBuilder(AnnotedConfigurable.class);
    Object instance = annotatedConfigurable.embeddableInstance();
    assertThat(instance, Matchers.instanceOf(ConfigurableEmbedder.class));
    Embedder embedder = ((ConfigurableEmbedder) instance).configuredEmbedder();
    assertThat(embedder.configuration().keywords(), instanceOf(MyKeywords.class));
    assertThat(embedder.metaFilters(), equalTo(asList("+embedder configurable")));
    assertThatStepsInstancesAre(embedder.stepsFactory().createCandidateSteps(), MySteps.class);
}
Also used : ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Embedder(org.jbehave.core.embedder.Embedder) Test(org.junit.Test)

Example 3 with ConfigurableEmbedder

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

the class AnnotationBuilderBehaviour method shouldCreateEmbeddableInstanceFromConfigurableEmbedderWithoutStepsFactory.

@Test
public void shouldCreateEmbeddableInstanceFromConfigurableEmbedderWithoutStepsFactory() {
    AnnotationBuilder annotatedConfigurable = new AnnotationBuilder(AnnotedConfigurableWithoutStepsFactory.class);
    Object instance = annotatedConfigurable.embeddableInstance();
    assertThat(instance, Matchers.instanceOf(ConfigurableEmbedder.class));
    Embedder embedder = ((ConfigurableEmbedder) instance).configuredEmbedder();
    assertThat(embedder.configuration().keywords(), instanceOf(MyKeywords.class));
    assertThat(embedder.metaFilters(), equalTo(asList("+embedder configurable")));
    assertThatStepsInstancesAre(embedder.candidateSteps(), MySteps.class);
}
Also used : ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) UsingEmbedder(org.jbehave.core.annotations.UsingEmbedder) ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Embedder(org.jbehave.core.embedder.Embedder) Test(org.junit.Test)

Example 4 with ConfigurableEmbedder

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

the class AnnotationBuilder method injectEmbedder.

protected Object injectEmbedder(Embedder embedder, Class<?> annotatedClass) {
    try {
        Object instance = annotatedClass.newInstance();
        if (instance instanceof Embeddable) {
            Embeddable embeddable = (Embeddable) instance;
            embeddable.useEmbedder(embedder);
        }
        if (instance instanceof ConfigurableEmbedder) {
            ConfigurableEmbedder configurableEmbedder = (ConfigurableEmbedder) instance;
            configurableEmbedder.useConfiguration(embedder.configuration());
            configurableEmbedder.addSteps(embedder.candidateSteps());
            configurableEmbedder.useStepsFactory(embedder.stepsFactory());
        }
        return instance;
    } catch (Exception e) {
        annotationMonitor.elementCreationFailed(annotatedClass, e);
        throw new InstantiationFailed(annotatedClass, e);
    }
}
Also used : ConfigurableEmbedder(org.jbehave.core.ConfigurableEmbedder) IOException(java.io.IOException) Embeddable(org.jbehave.core.Embeddable)

Aggregations

ConfigurableEmbedder (org.jbehave.core.ConfigurableEmbedder)4 Embeddable (org.jbehave.core.Embeddable)2 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)2 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)2 Embedder (org.jbehave.core.embedder.Embedder)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 CandidateSteps (org.jbehave.core.steps.CandidateSteps)1