Hi Gerhard, i can't agree on reliability if i am "emulating" prod environment using embedded containers but thats my opinion and also not the idea of this thread (arq x test-control).
About the external container, do we have any documentation on how to build one? Can I take [1] as reference to create a JPA adapter? [1] https://github.com/apache/deltaspike/blob/master/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MyFacesContainerAdapter.java 2015-04-07 11:16 GMT-03:00 Gerhard Petracek <[email protected]>: > hi rafael, > > arquillian follows a different idea, but it isn't more reliable. > > the basic idea of test-control is: > test your application as it is. if you need special handling for tests, use > specialized/alternative beans in the test-classpath (and/or @Exclude + > project-stage). > (for sure there are some limitations for web-applications per definition.) > > if you are using deltaspike-cdictrl-openejb (instead of the modules for owb > or weld), you get ejb support as well. > (if you need any other embedded ejb-container which supports the same, you > need to integrate it manually via your own cdictrl-module or via > org.apache.deltaspike.testcontrol.spi.ExternalContainer) > > if you are using weld, you just need to know the bda-rules (and the > global-alternative feature or @javax.annotation.Priority) to use > specialized/alternative beans for your tests. > > regards, > gerhard > > http://www.irian.at > > Your JavaEE powerhouse - > JavaEE Consulting, Development and > Courses in English and German > > Professional Support for Apache > MyFaces, DeltaSpike and OpenWebBeans > > > > 2015-04-07 13:17 GMT+02:00 Rafael Pestano <[email protected]>: > > > Hi Karl, didnt saw your message. > > > > I think arquillian configuration is not that hard. I can try to add it to > > the github repo mentioned in this thread. > > Em 07/04/2015 08:12, "Rafael Pestano" <[email protected]> escreveu: > > > > > I see, > > > > > > In simple words I think test control would give more speed and > arquillian > > > more reliabie tests. > > > > > > So if we got transaction support and data store management in test > > control > > > I think the module would receive more adoption. > > > Em 07/04/2015 06:43, "Thomas Hug" <[email protected]> escreveu: > > > > > >> Thnx for the clarification Rafael! Most of DS (including the data > > module) > > >> is tested with Arquillian, so can't comment much on a DS test control > > >> approach... > > >> > > >> On Tue, Apr 7, 2015 at 11:30 AM, Rafael Pestano <[email protected]> > > >> wrote: > > >> > > >> > Hi Thomas, no specific reason, just want to see how far I can go > with > > ds > > >> > and know when I need to use a framework or another. > > >> > Em 07/04/2015 04:24, "Thomas Hug" <[email protected]> escreveu: > > >> > > > >> > > Hi Rafael > > >> > > Any specific reason not to use Arquillian? You can also integrate > > the > > >> > > persistence extension which works already nicely with DBUnit. > > >> > > > > >> > > On Tue, Apr 7, 2015 at 12:04 AM, Rafael Pestano < > > [email protected]> > > >> > > wrote: > > >> > > > > >> > > > Hi again, > > >> > > > > > >> > > > I have evolved a bit my example and could managed to test > > >> > UserRepository > > >> > > > from Gerhard ee6-ds-dm, sources are here: > > >> > > > https://github.com/rmpestano/ee6-ds-demo/ > > >> > > > <https://github.com/rmpestano/ee6-ds-demo/> > > >> > > > > > >> > > > first thing i did was to disable application > EntityManagerProduces > > >> in > > >> > > unit > > >> > > > tests (remember i want to use my in memory db for tests): > > >> > > > > > >> > > > @Exclude(ifProjectStage = ProjectStage.UnitTest.class) > > >> > > > public class EntityManagerProducer { > > >> > > > > > >> > > > @PersistenceContext(unitName = "demoApplicationPU") > > >> > > > private EntityManager entityManagerProxy; > > >> > > > > > >> > > > @Produces > > >> > > > public EntityManager exposeDependentEntityManager() { > > >> > > > return entityManagerProxy; > > >> > > > } > > >> > > > > > >> > > > } > > >> > > > > > >> > > > > > >> > > > then i've create my producer in test sources: > > >> > > > > > >> > > > public class TestEntityManagerProducer { > > >> > > > > > >> > > > private EntityManager entityManager; > > >> > > > > > >> > > > @Produces > > >> > > > @ApplicationScoped > > >> > > > public EntityManager exposeDependentEntityManager() > > >> > > > { > > >> > > > entityManager = > > >> > > > > > >> > > > Persistence.createEntityManagerFactory("TEST_PU").createEntityManager(); > > >> > > > return entityManager; > > >> > > > } > > >> > > > > > >> > > > public void closeEntityManager(@Disposes EntityManager > > >> entityManager) > > >> > > > { > > >> > > > if (entityManager.isOpen()) > > >> > > > { > > >> > > > entityManager.close(); > > >> > > > } > > >> > > > } > > >> > > > > > >> > > > } > > >> > > > > > >> > > > > > >> > > > And here is my repository test: > > >> > > > > > >> > > > @RunWith(CdiTestRunner.class) > > >> > > > @TestControl(projectStage = ProjectStage.UnitTest.class) > > >> > > > public class UserRepositoryTest { > > >> > > > > > >> > > > > > >> > > > @Inject > > >> > > > UserRepository userRepository; > > >> > > > > > >> > > > > > >> > > > @Before > > >> > > > public void tearUp(){ > > >> > > > User u = new User("testUser","first","last"); > > >> > > > userRepository.save(u); > > >> > > > assertNotNull(u.getId()); > > >> > > > assertEquals(userRepository.count(), 1); > > >> > > > } > > >> > > > > > >> > > > @After > > >> > > > public void tearDown(){ > > >> > > > > > >> > > > > > >> > > > > > >> > > > > >> > > > >> > > > userRepository.getEntityManager().remove(userRepository.findUser("testUser")); > > >> > > > } > > >> > > > > > >> > > > > > >> > > > @Test > > >> > > > public void shouldFindUser() { > > >> > > > User user = userRepository.findUser("testUser"); > > >> > > > assertNotNull(user); > > >> > > > assertEquals(user.getUserName(),"testUser"); > > >> > > > } > > >> > > > > > >> > > > > > >> > > > } > > >> > > > > > >> > > > I have added deltaspike-jpa module to the project to have > > >> transaction > > >> > > > support: > > >> > > > > > >> > > > @Transactional > > >> > > > public User save(User user) { > > >> > > > if (user.isTransient()) { > > >> > > > entityManager.persist(user); > > >> > > > } else { > > >> > > > user = entityManager.merge(user); > > >> > > > } > > >> > > > return user; > > >> > > > } > > >> > > > > > >> > > > without it, i could not insert users during tests (@Before) > > >> > > > > > >> > > > here is test persistence.xml: > > >> > > > > > >> > > > <persistence version="2.0" > > >> > > > xmlns="http://java.sun.com/xml/ns/persistence" > > >> > > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > >> > > > xsi:schemaLocation="http://java.sun.com/xml/ns/persistence > > >> > > > http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> > > >> > > > > > >> > > > <persistence-unit name="TEST_PU" > > >> transaction-type="RESOURCE_LOCAL"> > > >> > > > > <provider>org.hibernate.ejb.HibernatePersistence</provider> > > >> > > > <class>org.os890.demo.ee6.ds.domain.user.User</class> > > >> > > > <properties> > > >> > > > <property name="hibernate.dialect" > > >> > > > value="org.hibernate.dialect.H2Dialect" /> > > >> > > > <property name="javax.persistence.jdbc.driver" > > >> > > > value="org.hsqldb.jdbcDriver" /> > > >> > > > <property name="javax.persistence.jdbc.url" > > >> > > > value="jdbc:hsqldb:mem:." /> > > >> > > > <property name="javax.persistence.jdbc.user" > > value="sa" > > >> /> > > >> > > > <property name="javax.persistence.jdbc.password" > > >> value="" > > >> > /> > > >> > > > <property name="hibernate.show_sql" value="true" /> > > >> > > > <property name="hibernate.connection.shutdown" > > >> > value="true"/> > > >> > > > <property name="hibernate.hbm2ddl.auto" > > >> > value="create-drop"/> > > >> > > > </properties> > > >> > > > </persistence-unit> > > >> > > > > > >> > > > </persistence> > > >> > > > > > >> > > > > > >> > > > finally the dependencies I've added to project: > > >> > > > > > >> > > > <dependency> > > >> > > > <groupId>org.apache.deltaspike.modules</groupId> > > >> > > > <artifactId>deltaspike-jpa-module-api</artifactId> > > >> > > > <version>${ds.version}</version> > > >> > > > </dependency> > > >> > > > > > >> > > > <dependency> > > >> > > > <groupId>org.apache.deltaspike.modules</groupId> > > >> > > > <artifactId>deltaspike-jpa-module-impl</artifactId> > > >> > > > <version>${ds.version}</version> > > >> > > > <scope>runtime</scope> > > >> > > > </dependency> > > >> > > > <dependency> > > >> > > > <groupId>org.hibernate</groupId> > > >> > > > <artifactId>hibernate-entitymanager</artifactId> > > >> > > > <version>4.2.18.Final</version> > > >> > > > <scope>test</scope> > > >> > > > </dependency> > > >> > > > > > >> > > > <dependency> > > >> > > > <groupId>hsqldb</groupId> > > >> > > > <artifactId>hsqldb</artifactId> > > >> > > > <version>1.8.0.10</version> > > >> > > > <scope>test</scope> > > >> > > > </dependency> > > >> > > > > > >> > > > > > >> > > > Any other advices? > > >> > > > > > >> > > > I hope it helps someone ;) > > >> > > > > > >> > > > 2015-04-06 17:12 GMT-03:00 Rafael Pestano <[email protected] > >: > > >> > > > > > >> > > > > Hi everyone, > > >> > > > > > > >> > > > > besides OpenEJB and cdi-control-ejb used in [1] what are the > > >> > > alternatives > > >> > > > > (in terms of Destaspike) for testing JPA based repositories? > > >> > > > > > > >> > > > > > > >> > > > > For out container integration tests i usually use something > like > > >> > this: > > >> > > > > > > >> > > > > @Before > > >> > > > > public void inicializarCenario() throws Exception { > > >> > > > > startConnection(); > > >> > > > > } > > >> > > > > > > >> > > > > @After > > >> > > > > public void finalizarCenario() { > > >> > > > > closeConnection(); > > >> > > > > } > > >> > > > > > > >> > > > > public void startConnection() { > > >> > > > > emf = Persistence.createEntityManagerFactory("TEST_PU"); > > >> > > > > em = emf.createEntityManager(); > > >> > > > > em.getTransaction().begin(); > > >> > > > > } > > >> > > > > > > >> > > > > public void closeConnection() { > > >> > > > > em.getTransaction().commit(); > > >> > > > > emf.close(); > > >> > > > > } > > >> > > > > > > >> > > > > TEST_PU is in test resources and usually uses in memory db, > > >> something > > >> > > > like > > >> > > > > below: > > >> > > > > > > >> > > > > <persistence version="2.0" > > >> > > > > xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi=" > > >> > > > > http://www.w3.org/2001/XMLSchema-instance" > > >> > > > > xsi:schemaLocation="http://java.sun.com/xml/ns/persistence > > >> > > > > http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> > > >> > > > > > > >> > > > > <persistence-unit name="TEST_PU" > > >> transaction-type="RESOURCE_LOCAL"> > > >> > > > > > > >> > > <provider>org.hibernate.ejb.HibernatePersistence</provider> > > >> > > > > <properties> > > >> > > > > <property name="hibernate.dialect" > > >> > > > value="org.hibernate.dialect.H2Dialect" > > >> > > > > /> > > >> > > > > <property name="javax.persistence.jdbc.driver" > > >> > > > > value="org.hsqldb.jdbcDriver" /> > > >> > > > > <property name="javax.persistence.jdbc.url" > > >> > > > > value="jdbc:hsqldb:mem:." /> > > >> > > > > <property name="javax.persistence.jdbc.user" > > >> value="sa" > > >> > /> > > >> > > > > <property name="javax.persistence.jdbc.password" > > >> value="" > > >> > > /> > > >> > > > > <property name="hibernate.show_sql" value="true" > /> > > >> > > > > <property name="hibernate.connection.shutdown" > > >> > > value="true"/> > > >> > > > > <property name="hibernate.hbm2ddl.auto" > > >> > > value="create-drop"/> > > >> > > > > </properties> > > >> > > > > </persistence-unit> > > >> > > > > </persistence> > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > The idea is to be "lighweight" and boot only JPA container so > my > > >> > > > > repositories can use the "test entityManager? > > >> > > > > > > >> > > > > I think of something like this: > > >> > > > > > > >> > > > > @RunWith(CdiTestRunner.class) > > >> > > > > @TestControl(startPersistentUnits("TEST_PU")) > > >> > > > > public class UserRepositoryTest { > > >> > > > > > > >> > > > > @Inject > > >> > > > > UserRepository userRepository; > > >> > > > > > > >> > > > > @Test > > >> > > > > public void shouldInserUser(){ > > >> > > > > User u = new User(); > > >> > > > > userRepository.save(u); > > >> > > > > assertFalse(user.isTransient()); > > >> > > > > } > > >> > > > > > > >> > > > > } > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > Can we reach somethink like that with Deltaspike test control? > > >> > > > > > > >> > > > > I also would like to integrate with dbunit so I can feed this > > test > > >> > > > > datasource but thats another story > > >> > > > > > > >> > > > > WDYT? > > >> > > > > > > >> > > > > > > >> > > > > > > >> > > > > [1] > > >> > > > > > > >> > > > > > >> > > > > >> > > > >> > > > https://github.com/os890/ee6-ds-demo/blob/master/src/test/java/org/os890/demo/ee6/test/PageBeanTest.java > > >> > > > > > > >> > > > > > > >> > > > > -- > > >> > > > > <http://www.advancedit.com.br/>Att, > > >> > > > > > > >> > > > > Rafael M. Pestano > > >> > > > > > > >> > > > > Desenvolvedor Java Cia. de Processamento de Dados do Rio > Grande > > do > > >> > Sul > > >> > > > > http://rpestano.wordpress.com/ > > >> > > > > @realpestano <https://twitter.com/realpestano> > > >> > > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > -- > > >> > > > <http://www.advancedit.com.br/>Att, > > >> > > > > > >> > > > Rafael M. Pestano > > >> > > > > > >> > > > Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande > do > > >> Sul > > >> > > > http://rpestano.wordpress.com/ > > >> > > > @realpestano <https://twitter.com/realpestano> > > >> > > > > > >> > > > > >> > > > >> > > > > > > -- <http://www.advancedit.com.br/>Att, Rafael M. Pestano Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul http://rpestano.wordpress.com/ @realpestano <https://twitter.com/realpestano>
