Search in sources :

Example 6 with ObjectFactory

use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.

the class SpringFactoryTest method shouldFailIfClassWithSpringComponentAnnotationsIsFound.

@Test
void shouldFailIfClassWithSpringComponentAnnotationsIsFound() {
    final ObjectFactory factory = new SpringFactory();
    Executable testMethod = () -> factory.addClass(WithComponentAnnotation.class);
    CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
    assertThat(actualThrown.getMessage(), is(equalTo("Glue class io.cucumber.spring.componentannotation.WithComponentAnnotation was annotated with @Component; marking it as a candidate for auto-detection by Spring. Glue classes are detected and registered by Cucumber. Auto-detection of glue classes by spring may lead to duplicate bean definitions. Please remove the @Component annotation")));
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 7 with ObjectFactory

use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.

the class SpringFactoryTest method shouldBeStoppableWhenFacedWithMissingContextConfiguration.

@Test
void shouldBeStoppableWhenFacedWithMissingContextConfiguration() {
    final ObjectFactory factory = new SpringFactory();
    factory.addClass(WithoutContextConfiguration.class);
    IllegalStateException exception = assertThrows(IllegalStateException.class, factory::start);
    assertThat(exception.getMessage(), containsString("Failed to load ApplicationContext"));
    assertDoesNotThrow(factory::stop);
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) Test(org.junit.jupiter.api.Test)

Example 8 with ObjectFactory

use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.

the class SpringFactoryTest method shouldFailIfMultipleClassesWithSpringAnnotationsAreFound.

@Test
void shouldFailIfMultipleClassesWithSpringAnnotationsAreFound() {
    final ObjectFactory factory = new SpringFactory();
    factory.addClass(WithSpringAnnotations.class);
    Executable testMethod = () -> factory.addClass(BellyStepDefinitions.class);
    CucumberBackendException actualThrown = assertThrows(CucumberBackendException.class, testMethod);
    assertThat(actualThrown.getMessage(), startsWith("Glue class class io.cucumber.spring.contextconfig.BellyStepDefinitions and class io.cucumber.spring.SpringFactoryTest$WithSpringAnnotations are both annotated with @CucumberContextConfiguration.\n" + "Please ensure only one class configures the spring context"));
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test)

Example 9 with ObjectFactory

use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.

the class SpringFactoryTest method shouldRespectCommonAnnotationsInStepDefs.

@Test
void shouldRespectCommonAnnotationsInStepDefs() {
    final ObjectFactory factory = new SpringFactory();
    factory.addClass(WithSpringAnnotations.class);
    factory.start();
    WithSpringAnnotations stepdef = factory.getInstance(WithSpringAnnotations.class);
    factory.stop();
    assertThat(stepdef, is(notNullValue()));
    assertTrue(stepdef.isAutowired());
}
Also used : ObjectFactory(io.cucumber.core.backend.ObjectFactory) Test(org.junit.jupiter.api.Test)

Example 10 with ObjectFactory

use of io.cucumber.core.backend.ObjectFactory in project cucumber-jvm by cucumber.

the class SpringFactoryTest method shouldGlueScopedSpringBeanBehaveLikeGlueLifecycle.

@Test
void shouldGlueScopedSpringBeanBehaveLikeGlueLifecycle() {
    final ObjectFactory factory = new SpringFactory();
    factory.addClass(WithSpringAnnotations.class);
    // Scenario 1
    factory.start();
    long bellyInstance1 = factory.getInstance(Belly.class).getInstanceId();
    long glueInstance1 = factory.getInstance(GlueScopedComponent.class).getInstanceId();
    factory.stop();
    // Scenario 2
    factory.start();
    long bellyInstance2 = factory.getInstance(Belly.class).getInstanceId();
    long glueInstance2 = factory.getInstance(GlueScopedComponent.class).getInstanceId();
    factory.stop();
    assertAll(() -> assertThat(glueInstance1, is(not(glueInstance2))), () -> assertThat(glueInstance2, is(not(glueInstance1))), () -> assertThat(bellyInstance1, is(bellyInstance2)), () -> assertThat(bellyInstance2, is(bellyInstance1)));
}
Also used : GlueScopedComponent(io.cucumber.spring.beans.GlueScopedComponent) ObjectFactory(io.cucumber.core.backend.ObjectFactory) Belly(io.cucumber.spring.beans.Belly) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectFactory (io.cucumber.core.backend.ObjectFactory)29 Test (org.junit.jupiter.api.Test)27 Backend (io.cucumber.core.backend.Backend)5 TestSnippet (io.cucumber.core.snippets.TestSnippet)4 BellyBean (io.cucumber.spring.beans.BellyBean)4 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)3 Glue (io.cucumber.core.backend.Glue)3 HookDefinition (io.cucumber.core.backend.HookDefinition)3 DirtiesContextBellyStepDefinitions (io.cucumber.spring.dirtiescontextconfig.DirtiesContextBellyStepDefinitions)3 Executable (org.junit.jupiter.api.function.Executable)3 Belly (io.cucumber.spring.beans.Belly)2 GlueScopedComponent (io.cucumber.spring.beans.GlueScopedComponent)2 AutowiresThirdStepDef (io.cucumber.spring.commonglue.AutowiresThirdStepDef)2 OneStepDef (io.cucumber.spring.commonglue.OneStepDef)2 BellyStepDefinitions (io.cucumber.spring.contextconfig.BellyStepDefinitions)2 DirtiesContextBellyMetaStepDefinitions (io.cucumber.spring.metaconfig.dirties.DirtiesContextBellyMetaStepDefinitions)2 InOrder (org.mockito.InOrder)2 BackendProviderService (io.cucumber.core.backend.BackendProviderService)1 DefaultObjectFactory (io.cucumber.core.backend.DefaultObjectFactory)1 StaticHookDefinition (io.cucumber.core.backend.StaticHookDefinition)1