dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19842
[Bug 1073864] Re: [branch web-api-test specific] tests fails when has data in DB
[Analysis]
----------------------------------------------------
For DHIS system, there's a OpenSessionInViewFilter filter initialized in web.xml, which means, when a HTTP request from a client comes, this filter would be called before servlets serve, which promises an opened Hibernate Session.
But with spring-mvc-test, I don't know if this filter is called.
--
You received this bug notification because you are a member of DHIS 2
developers, which is subscribed to DHIS.
https://bugs.launchpad.net/bugs/1073864
Title:
[branch web-api-test specific] tests fails when has data in DB
Status in DHIS 2 - District Health Information Software:
In Progress
Bug description:
This bug is branch web-api-test specific!
[Steps to Reproduce]
------------------------------------------------
1. locate the hibernate.properties that the system would use, use a non-transient database, either PostGreSQL or MySQL is OK.
2. Change the config option hibernate.hbm2ddl.auto to none
3. Start up the DHIS system and log in to insert a admin:district user into user table.
4. Start the Unit-Test MainTest.java
Expected Result:
Tests pass
Real Result:
Tests fail with the following exception.
[Description]
------------------------------------------------
The Controller specific tests, which utilized spring-test-mvc framework, could not work when there are data resides in the database.
However, when the table is empty, everything goes well.
Take the case of MainTest.testDefaultUser, which test the resource
/users. It could work the the user table is empty, but when it's not,
the exception happens.
[Logs]
------------------------------------------------
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.hisp.dhis.user.User.groups, no session or session was closed
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.springframework.test.web.server.MockMvc.perform(MockMvc.java:77)
at org.hisp.dhis.api.controller.main.MainTest.testDefaultUser(MainTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.hisp.dhis.user.User.groups, no session or session was closed
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:393)
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:385)
at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:378)
at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:112)
at org.hibernate.collection.internal.PersistentSet.iterator(PersistentSet.java:180)
at org.hisp.dhis.api.utils.WebUtils.generateLinks(WebUtils.java:136)
at org.hisp.dhis.api.utils.WebUtils.generateLinks(WebUtils.java:74)
at org.hisp.dhis.api.controller.AbstractCrudController.getObjectList(AbstractCrudController.java:82)
at org.hisp.dhis.api.controller.AbstractCrudController$$FastClassByCGLIB$$3565baa0.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:618)
at org.hisp.dhis.api.controller.user.UserController$$EnhancerByCGLIB$$a5cc1793.getObjectList(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.test.web.server.TestDispatcherServlet.doService(TestDispatcherServlet.java:73)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
... 29 more
To manage notifications about this bug go to:
https://bugs.launchpad.net/dhis2/+bug/1073864/+subscriptions
References