Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VaadinSession fails to be created in unit tests for new Spring Boot 1.4 #79

Closed
vaadin-bot opened this issue Sep 20, 2016 · 8 comments
Closed

Comments

@vaadin-bot
Copy link
Collaborator

vaadin-bot commented Sep 20, 2016

Originally by aricooperman on 2016-09-01 16:12:35 +0300


I upgraded my spring boot version to 1.4 and updated the annotations as described here:

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes#test-utilities-and-classes

I also reverted back and in both cases when I run a unit test that requires I load a web environment and/or loads a Vaadin specific Configuration class I get this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vaadinServiceFactory': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No VaadinService bound to current thread
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:127)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1600)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:67)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:54)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.beforeTestMethod(ResetMocksTestExecutionListener.java:44)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:269)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalStateException: No VaadinService bound to current thread
at org.vaadin.spring.context.VaadinServiceFactory.getObject(VaadinServiceFactory.java:22)
at org.vaadin.spring.context.VaadinServiceFactory.getObject(VaadinServiceFactory.java:14)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
... 29 more

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vaadinServiceFactory': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No VaadinService bound to current thread
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:127)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1600)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:67)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.resetMocks(ResetMocksTestExecutionListener.java:54)
at org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener.afterTestMethod(ResetMocksTestExecutionListener.java:49)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:319)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:94)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalStateException: No VaadinService bound to current thread
at org.vaadin.spring.context.VaadinServiceFactory.getObject(VaadinServiceFactory.java:22)
at org.vaadin.spring.context.VaadinServiceFactory.getObject(VaadinServiceFactory.java:14)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
... 28 more


Imported from https://dev.vaadin.com/ issue #20212

@vaadin-bot
Copy link
Collaborator Author

Originally by aricooperman on 2016-09-01 16:14:29 +0300


I will also note that I can start up my application just fine with Boot 1.4 and Vaadin 7.6.8, it is just (from what I can tell so far) the unit tests failing

@vaadin-bot
Copy link
Collaborator Author

Originally by eiswind on 2016-09-14 08:58:43 +0300


Hi, did anyone look into this? Its the same with the old deprecated and the new annotations. Both fail with the mentioned exception. I have no option of downgrading, and currently none of my integration tests are running. My guess is a threading or scope issue.

@Artur- Artur- added bug and removed Defect labels Sep 20, 2016
@aspan
Copy link

aspan commented Sep 20, 2016

I ran into the same problem when upgrading to spring boot 1.4.0. The problem is with the new ResetMocksTestExecutionListener. A workaround is to manually add the @TestExecutionListeners annotation to your test case without the ResetMocksTestExecutionListener.
e.g.

@TestExecutionListeners({
        org.springframework.test.context.web.ServletTestExecutionListener.class,
        org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener.class,
        org.springframework.test.context.support.DependencyInjectionTestExecutionListener.class,
        org.springframework.test.context.support.DirtiesContextTestExecutionListener.class,
        org.springframework.test.context.transaction.TransactionalTestExecutionListener.class,
        org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener.class,
        org.springframework.security.test.context.support.WithSecurityContextTestExecutionListener.class
})

@hesara hesara added track2 and removed track2 labels Oct 12, 2016
@aricooperman
Copy link

Does no one else have this issue when upgrading to boot 1.4? I update to boot 1.4.2 and Spring Vaadin Starter 1.0.2 and the issue persists

@snicoll
Copy link
Contributor

snicoll commented Nov 16, 2016

would anyone be able to create a sample project and create an issue (https://github.com/spring-projects/spring-boot/issues). It looks like we're not checking the scope as we should there. Thank you!

@Switcher05
Copy link

I have had the identical issue and fixed it by aspen's comment adding the TestExecutionListeners.

@philwebb
Copy link

I believe this is fixed as of Spring Boot 1.4.5

@rafaelmembrives
Copy link

I upgrade from Spring Boot 1.4.1 to 1.4.5 and the error is gone.

Thank you very much!

@pleku pleku added this to P3 - Spring & CDI Low Priority in OLD Vaadin Flow bugs & maintenance (Vaadin 10+) May 16, 2019
@TatuLund TatuLund closed this as completed Nov 2, 2019
OLD Vaadin Flow bugs & maintenance (Vaadin 10+) automation moved this from P3 - FW 7 / 8 Spring & CDI Low Priority to Closed - pending release Nov 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

10 participants