Re: Tapestry-jpa, unit testing and (servlet)context
I'll try to provide something next week or the week after. Charles 2014-07-18 4:20 GMT+02:00 Lance Java lance.j...@googlemail.com: What is the procedure for me to provide a patch ? Developing it and creating an issue with the patch attached ? That's a great start. Some things to keep in mind 1. To be consistent with tapestry-hibernate, a new gradle submodule for tapestry-jpa-core is required. This will only have tapestry-ioc as a dependency. This will contain JpaCoreModule and the core jpa services. 2. tapestry-jpa-core needs a jar manifest entry for JpaCoreModule. 3. Test case for tapestry-jpa-core starting a registry without tapestry-core Cheers, Lance. On 17 Jul 2014 23:30, Charlouze m...@charlouze.com wrote: To Kalle: I'm a fan of the less I mock, the better I am. Also, I think it's easier to import module classes and let them do the job. This way, the full stack is tested. I let JpaModule instanciate what it needs ... To Lance: It's seems that hibernate modules and jpa are quite similar. What is the procedure for me to provide a patch ? Developing it and creating an issue with the patch attached ? 2014-07-17 23:05 GMT+02:00 Lance Java lance.j...@googlemail.com: I think it's a good idea to split tapestry-jpa in the same way as tapestry-hibernate. See HibernateCoreModule and HibernateModule to see how it's split. On 17 Jul 2014 21:47, Charlouze m...@charlouze.com wrote: I will do what you said but maybe i could open a ticket for this issue and propose a patch for tapestry-jpa, what do you think ? 2014-07-17 22:32 GMT+02:00 Lance Java lance.j...@googlemail.com: Ah, I haven't used tapestry-jpa myself. tapestry-hibernate is split into two modules to allow for this type of testing. If this is the case, you may need to override ApplicationGlobals and provide a mock ServletContext as I said initially. On 17 Jul 2014 17:37, Charlouze m...@charlouze.com wrote: I have separated modules for the service tier and the web tier but tapestry-jpa requires tapestry web modules... IMO, it should not but that's the way it is (maybe JpaModule should be divided into two modules). Anyway, I would have the same problem with beanvalidation module. I'll take a look at the tapestry sources for examples 2014-07-17 17:29 GMT+02:00 Lance Java lance.j...@googlemail.com : On second thought of you are unit testing just your jpa classes you shouldn't need the ServletContext to be mocked. Note that tapestry modules have been split in such a way that Web services are separated from core services. I think your test should not require any web modules. This might require you to split your custom module into 2 modules (web and core) but will make testing easier. On 17 Jul 2014 16:20, Lance Java lance.j...@googlemail.com wrote: I'm not sure exactly what you're doing but you probably need to override the ApplicationGlobals service such that getServletContext() returns an appropriate mock. If you're using junit, you might want to try the new TapestryIOCJunit4ClassRunner. See the tapestry sources for example test cases. On 17 Jul 2014 16:02, Charlouze m...@charlouze.com wrote: Hello everyone. I'm currently setting up an application using T5.4-b13. For unit testing, I use junit, unitils-dbunit, spock (with spock-tapestry and spock-unitils extension). In my specification I added @submodule annotation with every needed module (Tapestry, Jpa, beanValidator and my custom module). My problem is that there are no context and therefore, my tests do not pass the assert context != null in ContextResource class constructor. Does anyone know what can I do ? Thanks in advance Charles.
Re: Tapestry-jpa, unit testing and (servlet)context
On second thought of you are unit testing just your jpa classes you shouldn't need the ServletContext to be mocked. Note that tapestry modules have been split in such a way that Web services are separated from core services. I think your test should not require any web modules. This might require you to split your custom module into 2 modules (web and core) but will make testing easier. On 17 Jul 2014 16:20, Lance Java lance.j...@googlemail.com wrote: I'm not sure exactly what you're doing but you probably need to override the ApplicationGlobals service such that getServletContext() returns an appropriate mock. If you're using junit, you might want to try the new TapestryIOCJunit4ClassRunner. See the tapestry sources for example test cases. On 17 Jul 2014 16:02, Charlouze m...@charlouze.com wrote: Hello everyone. I'm currently setting up an application using T5.4-b13. For unit testing, I use junit, unitils-dbunit, spock (with spock-tapestry and spock-unitils extension). In my specification I added @submodule annotation with every needed module (Tapestry, Jpa, beanValidator and my custom module). My problem is that there are no context and therefore, my tests do not pass the assert context != null in ContextResource class constructor. Does anyone know what can I do ? Thanks in advance Charles.
Re: Tapestry-jpa, unit testing and (servlet)context
I have separated modules for the service tier and the web tier but tapestry-jpa requires tapestry web modules... IMO, it should not but that's the way it is (maybe JpaModule should be divided into two modules). Anyway, I would have the same problem with beanvalidation module. I'll take a look at the tapestry sources for examples 2014-07-17 17:29 GMT+02:00 Lance Java lance.j...@googlemail.com: On second thought of you are unit testing just your jpa classes you shouldn't need the ServletContext to be mocked. Note that tapestry modules have been split in such a way that Web services are separated from core services. I think your test should not require any web modules. This might require you to split your custom module into 2 modules (web and core) but will make testing easier. On 17 Jul 2014 16:20, Lance Java lance.j...@googlemail.com wrote: I'm not sure exactly what you're doing but you probably need to override the ApplicationGlobals service such that getServletContext() returns an appropriate mock. If you're using junit, you might want to try the new TapestryIOCJunit4ClassRunner. See the tapestry sources for example test cases. On 17 Jul 2014 16:02, Charlouze m...@charlouze.com wrote: Hello everyone. I'm currently setting up an application using T5.4-b13. For unit testing, I use junit, unitils-dbunit, spock (with spock-tapestry and spock-unitils extension). In my specification I added @submodule annotation with every needed module (Tapestry, Jpa, beanValidator and my custom module). My problem is that there are no context and therefore, my tests do not pass the assert context != null in ContextResource class constructor. Does anyone know what can I do ? Thanks in advance Charles.
Re: Tapestry-jpa, unit testing and (servlet)context
Ah, I haven't used tapestry-jpa myself. tapestry-hibernate is split into two modules to allow for this type of testing. If this is the case, you may need to override ApplicationGlobals and provide a mock ServletContext as I said initially. On 17 Jul 2014 17:37, Charlouze m...@charlouze.com wrote: I have separated modules for the service tier and the web tier but tapestry-jpa requires tapestry web modules... IMO, it should not but that's the way it is (maybe JpaModule should be divided into two modules). Anyway, I would have the same problem with beanvalidation module. I'll take a look at the tapestry sources for examples 2014-07-17 17:29 GMT+02:00 Lance Java lance.j...@googlemail.com: On second thought of you are unit testing just your jpa classes you shouldn't need the ServletContext to be mocked. Note that tapestry modules have been split in such a way that Web services are separated from core services. I think your test should not require any web modules. This might require you to split your custom module into 2 modules (web and core) but will make testing easier. On 17 Jul 2014 16:20, Lance Java lance.j...@googlemail.com wrote: I'm not sure exactly what you're doing but you probably need to override the ApplicationGlobals service such that getServletContext() returns an appropriate mock. If you're using junit, you might want to try the new TapestryIOCJunit4ClassRunner. See the tapestry sources for example test cases. On 17 Jul 2014 16:02, Charlouze m...@charlouze.com wrote: Hello everyone. I'm currently setting up an application using T5.4-b13. For unit testing, I use junit, unitils-dbunit, spock (with spock-tapestry and spock-unitils extension). In my specification I added @submodule annotation with every needed module (Tapestry, Jpa, beanValidator and my custom module). My problem is that there are no context and therefore, my tests do not pass the assert context != null in ContextResource class constructor. Does anyone know what can I do ? Thanks in advance Charles.
Re: Tapestry-jpa, unit testing and (servlet)context
You might find this stack overflow question useful, it's about tapestry-hibernate but has some parallels. http://stackoverflow.com/questions/15664815/how-to-test-dao-layer-in-tapestry-dependent-projects On 17 Jul 2014 21:32, Lance Java lance.j...@googlemail.com wrote: Ah, I haven't used tapestry-jpa myself. tapestry-hibernate is split into two modules to allow for this type of testing. If this is the case, you may need to override ApplicationGlobals and provide a mock ServletContext as I said initially. On 17 Jul 2014 17:37, Charlouze m...@charlouze.com wrote: I have separated modules for the service tier and the web tier but tapestry-jpa requires tapestry web modules... IMO, it should not but that's the way it is (maybe JpaModule should be divided into two modules). Anyway, I would have the same problem with beanvalidation module. I'll take a look at the tapestry sources for examples 2014-07-17 17:29 GMT+02:00 Lance Java lance.j...@googlemail.com: On second thought of you are unit testing just your jpa classes you shouldn't need the ServletContext to be mocked. Note that tapestry modules have been split in such a way that Web services are separated from core services. I think your test should not require any web modules. This might require you to split your custom module into 2 modules (web and core) but will make testing easier. On 17 Jul 2014 16:20, Lance Java lance.j...@googlemail.com wrote: I'm not sure exactly what you're doing but you probably need to override the ApplicationGlobals service such that getServletContext() returns an appropriate mock. If you're using junit, you might want to try the new TapestryIOCJunit4ClassRunner. See the tapestry sources for example test cases. On 17 Jul 2014 16:02, Charlouze m...@charlouze.com wrote: Hello everyone. I'm currently setting up an application using T5.4-b13. For unit testing, I use junit, unitils-dbunit, spock (with spock-tapestry and spock-unitils extension). In my specification I added @submodule annotation with every needed module (Tapestry, Jpa, beanValidator and my custom module). My problem is that there are no context and therefore, my tests do not pass the assert context != null in ContextResource class constructor. Does anyone know what can I do ? Thanks in advance Charles.
Re: Tapestry-jpa, unit testing and (servlet)context
I will do what you said but maybe i could open a ticket for this issue and propose a patch for tapestry-jpa, what do you think ? 2014-07-17 22:32 GMT+02:00 Lance Java lance.j...@googlemail.com: Ah, I haven't used tapestry-jpa myself. tapestry-hibernate is split into two modules to allow for this type of testing. If this is the case, you may need to override ApplicationGlobals and provide a mock ServletContext as I said initially. On 17 Jul 2014 17:37, Charlouze m...@charlouze.com wrote: I have separated modules for the service tier and the web tier but tapestry-jpa requires tapestry web modules... IMO, it should not but that's the way it is (maybe JpaModule should be divided into two modules). Anyway, I would have the same problem with beanvalidation module. I'll take a look at the tapestry sources for examples 2014-07-17 17:29 GMT+02:00 Lance Java lance.j...@googlemail.com: On second thought of you are unit testing just your jpa classes you shouldn't need the ServletContext to be mocked. Note that tapestry modules have been split in such a way that Web services are separated from core services. I think your test should not require any web modules. This might require you to split your custom module into 2 modules (web and core) but will make testing easier. On 17 Jul 2014 16:20, Lance Java lance.j...@googlemail.com wrote: I'm not sure exactly what you're doing but you probably need to override the ApplicationGlobals service such that getServletContext() returns an appropriate mock. If you're using junit, you might want to try the new TapestryIOCJunit4ClassRunner. See the tapestry sources for example test cases. On 17 Jul 2014 16:02, Charlouze m...@charlouze.com wrote: Hello everyone. I'm currently setting up an application using T5.4-b13. For unit testing, I use junit, unitils-dbunit, spock (with spock-tapestry and spock-unitils extension). In my specification I added @submodule annotation with every needed module (Tapestry, Jpa, beanValidator and my custom module). My problem is that there are no context and therefore, my tests do not pass the assert context != null in ContextResource class constructor. Does anyone know what can I do ? Thanks in advance Charles.
Re: Tapestry-jpa, unit testing and (servlet)context
What are you instantiating in tapestry-jpa that needs context? To test your persistence layer, you should only need an entityManager. You could have something like this as a base class for unit testing: public abstract class BasePersistenceTest { private static Class?[] entities = new Class[] { DataEntity.class, UserAccount.class, ... }; private final static PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer() { public void configure(final TapestryPersistenceUnitInfo unitInfo) { for (Class? entityClass : entities) unitInfo.addManagedClass(entityClass); } }; protected EntityManagerSource emSource; protected EntityManager em; public BasePersistenceTest() { emSource = new EntityManagerSourceImpl(LoggerFactory.getLogger(BasePersistenceTest.class), new ClasspathResource( persistence.xml), configurer, CollectionFactory.String, PersistenceUnitConfigurer newMap()); } @Before public void createEntityManager() { em = emSource.create(persistence); } Then mock/instantiate services as needed on top to test your persistence logic. Kalle On Thu, Jul 17, 2014 at 1:32 PM, Lance Java lance.j...@googlemail.com wrote: Ah, I haven't used tapestry-jpa myself. tapestry-hibernate is split into two modules to allow for this type of testing. If this is the case, you may need to override ApplicationGlobals and provide a mock ServletContext as I said initially. On 17 Jul 2014 17:37, Charlouze m...@charlouze.com wrote: I have separated modules for the service tier and the web tier but tapestry-jpa requires tapestry web modules... IMO, it should not but that's the way it is (maybe JpaModule should be divided into two modules). Anyway, I would have the same problem with beanvalidation module. I'll take a look at the tapestry sources for examples 2014-07-17 17:29 GMT+02:00 Lance Java lance.j...@googlemail.com: On second thought of you are unit testing just your jpa classes you shouldn't need the ServletContext to be mocked. Note that tapestry modules have been split in such a way that Web services are separated from core services. I think your test should not require any web modules. This might require you to split your custom module into 2 modules (web and core) but will make testing easier. On 17 Jul 2014 16:20, Lance Java lance.j...@googlemail.com wrote: I'm not sure exactly what you're doing but you probably need to override the ApplicationGlobals service such that getServletContext() returns an appropriate mock. If you're using junit, you might want to try the new TapestryIOCJunit4ClassRunner. See the tapestry sources for example test cases. On 17 Jul 2014 16:02, Charlouze m...@charlouze.com wrote: Hello everyone. I'm currently setting up an application using T5.4-b13. For unit testing, I use junit, unitils-dbunit, spock (with spock-tapestry and spock-unitils extension). In my specification I added @submodule annotation with every needed module (Tapestry, Jpa, beanValidator and my custom module). My problem is that there are no context and therefore, my tests do not pass the assert context != null in ContextResource class constructor. Does anyone know what can I do ? Thanks in advance Charles.
Re: Tapestry-jpa, unit testing and (servlet)context
I think it's a good idea to split tapestry-jpa in the same way as tapestry-hibernate. See HibernateCoreModule and HibernateModule to see how it's split. On 17 Jul 2014 21:47, Charlouze m...@charlouze.com wrote: I will do what you said but maybe i could open a ticket for this issue and propose a patch for tapestry-jpa, what do you think ? 2014-07-17 22:32 GMT+02:00 Lance Java lance.j...@googlemail.com: Ah, I haven't used tapestry-jpa myself. tapestry-hibernate is split into two modules to allow for this type of testing. If this is the case, you may need to override ApplicationGlobals and provide a mock ServletContext as I said initially. On 17 Jul 2014 17:37, Charlouze m...@charlouze.com wrote: I have separated modules for the service tier and the web tier but tapestry-jpa requires tapestry web modules... IMO, it should not but that's the way it is (maybe JpaModule should be divided into two modules). Anyway, I would have the same problem with beanvalidation module. I'll take a look at the tapestry sources for examples 2014-07-17 17:29 GMT+02:00 Lance Java lance.j...@googlemail.com: On second thought of you are unit testing just your jpa classes you shouldn't need the ServletContext to be mocked. Note that tapestry modules have been split in such a way that Web services are separated from core services. I think your test should not require any web modules. This might require you to split your custom module into 2 modules (web and core) but will make testing easier. On 17 Jul 2014 16:20, Lance Java lance.j...@googlemail.com wrote: I'm not sure exactly what you're doing but you probably need to override the ApplicationGlobals service such that getServletContext() returns an appropriate mock. If you're using junit, you might want to try the new TapestryIOCJunit4ClassRunner. See the tapestry sources for example test cases. On 17 Jul 2014 16:02, Charlouze m...@charlouze.com wrote: Hello everyone. I'm currently setting up an application using T5.4-b13. For unit testing, I use junit, unitils-dbunit, spock (with spock-tapestry and spock-unitils extension). In my specification I added @submodule annotation with every needed module (Tapestry, Jpa, beanValidator and my custom module). My problem is that there are no context and therefore, my tests do not pass the assert context != null in ContextResource class constructor. Does anyone know what can I do ? Thanks in advance Charles.
Re: Tapestry-jpa, unit testing and (servlet)context
To Kalle: I'm a fan of the less I mock, the better I am. Also, I think it's easier to import module classes and let them do the job. This way, the full stack is tested. I let JpaModule instanciate what it needs ... To Lance: It's seems that hibernate modules and jpa are quite similar. What is the procedure for me to provide a patch ? Developing it and creating an issue with the patch attached ? 2014-07-17 23:05 GMT+02:00 Lance Java lance.j...@googlemail.com: I think it's a good idea to split tapestry-jpa in the same way as tapestry-hibernate. See HibernateCoreModule and HibernateModule to see how it's split. On 17 Jul 2014 21:47, Charlouze m...@charlouze.com wrote: I will do what you said but maybe i could open a ticket for this issue and propose a patch for tapestry-jpa, what do you think ? 2014-07-17 22:32 GMT+02:00 Lance Java lance.j...@googlemail.com: Ah, I haven't used tapestry-jpa myself. tapestry-hibernate is split into two modules to allow for this type of testing. If this is the case, you may need to override ApplicationGlobals and provide a mock ServletContext as I said initially. On 17 Jul 2014 17:37, Charlouze m...@charlouze.com wrote: I have separated modules for the service tier and the web tier but tapestry-jpa requires tapestry web modules... IMO, it should not but that's the way it is (maybe JpaModule should be divided into two modules). Anyway, I would have the same problem with beanvalidation module. I'll take a look at the tapestry sources for examples 2014-07-17 17:29 GMT+02:00 Lance Java lance.j...@googlemail.com: On second thought of you are unit testing just your jpa classes you shouldn't need the ServletContext to be mocked. Note that tapestry modules have been split in such a way that Web services are separated from core services. I think your test should not require any web modules. This might require you to split your custom module into 2 modules (web and core) but will make testing easier. On 17 Jul 2014 16:20, Lance Java lance.j...@googlemail.com wrote: I'm not sure exactly what you're doing but you probably need to override the ApplicationGlobals service such that getServletContext() returns an appropriate mock. If you're using junit, you might want to try the new TapestryIOCJunit4ClassRunner. See the tapestry sources for example test cases. On 17 Jul 2014 16:02, Charlouze m...@charlouze.com wrote: Hello everyone. I'm currently setting up an application using T5.4-b13. For unit testing, I use junit, unitils-dbunit, spock (with spock-tapestry and spock-unitils extension). In my specification I added @submodule annotation with every needed module (Tapestry, Jpa, beanValidator and my custom module). My problem is that there are no context and therefore, my tests do not pass the assert context != null in ContextResource class constructor. Does anyone know what can I do ? Thanks in advance Charles.
Re: Tapestry-jpa, unit testing and (servlet)context
What is the procedure for me to provide a patch ? Developing it and creating an issue with the patch attached ? That's a great start. Some things to keep in mind 1. To be consistent with tapestry-hibernate, a new gradle submodule for tapestry-jpa-core is required. This will only have tapestry-ioc as a dependency. This will contain JpaCoreModule and the core jpa services. 2. tapestry-jpa-core needs a jar manifest entry for JpaCoreModule. 3. Test case for tapestry-jpa-core starting a registry without tapestry-core Cheers, Lance. On 17 Jul 2014 23:30, Charlouze m...@charlouze.com wrote: To Kalle: I'm a fan of the less I mock, the better I am. Also, I think it's easier to import module classes and let them do the job. This way, the full stack is tested. I let JpaModule instanciate what it needs ... To Lance: It's seems that hibernate modules and jpa are quite similar. What is the procedure for me to provide a patch ? Developing it and creating an issue with the patch attached ? 2014-07-17 23:05 GMT+02:00 Lance Java lance.j...@googlemail.com: I think it's a good idea to split tapestry-jpa in the same way as tapestry-hibernate. See HibernateCoreModule and HibernateModule to see how it's split. On 17 Jul 2014 21:47, Charlouze m...@charlouze.com wrote: I will do what you said but maybe i could open a ticket for this issue and propose a patch for tapestry-jpa, what do you think ? 2014-07-17 22:32 GMT+02:00 Lance Java lance.j...@googlemail.com: Ah, I haven't used tapestry-jpa myself. tapestry-hibernate is split into two modules to allow for this type of testing. If this is the case, you may need to override ApplicationGlobals and provide a mock ServletContext as I said initially. On 17 Jul 2014 17:37, Charlouze m...@charlouze.com wrote: I have separated modules for the service tier and the web tier but tapestry-jpa requires tapestry web modules... IMO, it should not but that's the way it is (maybe JpaModule should be divided into two modules). Anyway, I would have the same problem with beanvalidation module. I'll take a look at the tapestry sources for examples 2014-07-17 17:29 GMT+02:00 Lance Java lance.j...@googlemail.com: On second thought of you are unit testing just your jpa classes you shouldn't need the ServletContext to be mocked. Note that tapestry modules have been split in such a way that Web services are separated from core services. I think your test should not require any web modules. This might require you to split your custom module into 2 modules (web and core) but will make testing easier. On 17 Jul 2014 16:20, Lance Java lance.j...@googlemail.com wrote: I'm not sure exactly what you're doing but you probably need to override the ApplicationGlobals service such that getServletContext() returns an appropriate mock. If you're using junit, you might want to try the new TapestryIOCJunit4ClassRunner. See the tapestry sources for example test cases. On 17 Jul 2014 16:02, Charlouze m...@charlouze.com wrote: Hello everyone. I'm currently setting up an application using T5.4-b13. For unit testing, I use junit, unitils-dbunit, spock (with spock-tapestry and spock-unitils extension). In my specification I added @submodule annotation with every needed module (Tapestry, Jpa, beanValidator and my custom module). My problem is that there are no context and therefore, my tests do not pass the assert context != null in ContextResource class constructor. Does anyone know what can I do ? Thanks in advance Charles.