[JBoss Seam] - Re: Uni testing and datasource problem
by jagin
The last working example is not very good because for every @Test method we have to createEntityManagerFactory. I don't think it's a good idea.
So i found a better solution:
| public class MyTest extends SeamTest {
| private EntityManagerFactory emf;
|
| @Override
| @BeforeClass
| public void init() throws Exception {
| super.init();
| emf = Persistence.createEntityManagerFactory("ezapp");
| }
|
| @Override
| @AfterClass
| public void cleanup() throws Exception {
| emf.close();
| super.cleanup();
| }
|
| @Test
| public void testFindByUsername() {
| EntityManager em = emf.createEntityManager();
| em.getTransaction().begin();
|
| em.getTransaction().rollback();
| em.close();
| }
| }
|
First we have to extend SeamTest even if we are not going to use it's functionality in our unit test. But we need to initialize embedded container which is started in SeamTest.init(). So we override this method, call super.init() to initialize container and next we create our EntityManagerFactory. We close EntityManagerFactory in overrided cleanup() method.
Regards
Jarek
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117392#4117392
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117392
18 years, 3 months
[JBoss Seam] - Entity/Session bean coupling
by parszab
Hi All,
I tried to google about my question and search the forum, but found no answer -- there might be, though, sorry if so!
I'm building an application that will need both a SWing and a web UI. I decided to use Seam, because of the great features it has.
It seems to me, however, that this way my Sesson beans have to be to closely coupled to the web UI, and won't be available to be called from the Swing UI.
Entity beans contain data about the contexts, that's no more that a bit disturging, since the swing clients can simply ignore that. But the session beans returning FacesMessages, and string values to manage the page flowm in and outjecting etc. -- that is too close coupling for me.
My question is: is there a pattern that could be used in these cases? Like introducing a new layer for the web to access the commonly used session beans? Or anything like that?
Thanks in advance!
PSz
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117391#4117391
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117391
18 years, 3 months
[JBoss Seam] - Re: Uni testing and datasource problem
by jagin
Please help me with the problem !! I've been strugling with this for two days (all weekend) and have no idea whats wrong. I'm new to JBoss Seam but not new to java web development but I have no idea what's wrong. It drives me crazy!
Can anybody try to generate any simple application with seam-gen and put to src/test test MyTest.java like this:
| import javax.persistence.EntityManager;
| import javax.persistence.EntityManagerFactory;
| import javax.persistence.Persistence;
|
| import org.jboss.seam.mock.SeamTest;
| import org.testng.annotations.AfterClass;
| import org.testng.annotations.BeforeClass;
| import org.testng.annotations.Test;
|
| public class MyTest {
|
| private EntityManagerFactory emf;
|
| public EntityManagerFactory getEntityManagerFactory() {
| return emf;
| }
|
| @BeforeClass
| public void init() {
| emf = Persistence.createEntityManagerFactory("project_name");
| }
|
| @AfterClass
| public void destroy() {
| emf.close();
| }
|
| @Test
| public void testFindByUsername() {
| EntityManager em = emf.createEntityManager();
| em.getTransaction().begin();
|
| //...
|
| em.getTransaction().rollback();
| em.close();
| }
| }
|
as a project_name put your name of the project.
and MyTest.xml like this:
| <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
|
| <suite name="My Test" verbose="2" parallel="false">
|
| <test name="My Test">
| <classes>
| <class name="MyTest"/>
| </classes>
| </test>
|
| </suite>
|
next try to ant test and tell me if the test goes with no error?
For me it looks that the persistant.xml file is read before any initialization by Jboss Embedded. I check that application.xml, components.xml, ejb-jar.xml, jboss-app.xml are not read.
Please help me. I'm stucked.
Regards
Jarek
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117386#4117386
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117386
18 years, 3 months