Unit testing Seam components
sujeet Nov 6, 2008 3:40 PMHi,
I am new to Seam technology, using TestNG for unit Tesing.
In this test case I am trying to insert some data into database.
Can you please let me know where I am wrong.
Code snippet and logs are given below:
public class UserRoleTest extends SeamTest{
private EntityManagerFactory emf;
public EntityManagerFactory getEntityManagerFactory()
{
return emf;
}
@BeforeClass
public void init() throws Exception
{
super.init();
emf=Persistence.createEntityManagerFactory("provisioning");
}
@AfterClass
public void destroy()
{
emf.close();
}
@Test
public void testUserRole() throws Exception {
EntityManager em=getEntityManagerFactory().createEntityManager();
em.getTransaction().begin();
UserRole userRole=new UserRole();
userRole.setIdUserRole(3);
userRole.setRole("minoadmin1");
userRole.setRoleDescription("admin123");
em.getTransaction().commit();
em.close();
}
}
and the error I am getting is :
[testng] [Parser] Running:
[testng] D:\Seamworks\ProvisioningServer\src\org\domain\mino\ps\test\testng.xml
[testng] WARN [org.jboss.seam.security.RuleBasedIdentity] no security rule base available - please install a RuleBase with the name 'securityRules' if permission checks are required.
[testng] FAILED: testUserRole
[testng] java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
[testng] at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:317)
[testng] at org.domain.mino.ps.test.UserRoleTest.testUserRole(UserRoleTest.java:50)
[testng] ... Removed 22 stack frames
[testng] ===============================================
[testng] Login
[testng] Tests run: 1, Failures: 1, Skips: 0
[testng] ===============================================
[testng] ===============================================
[testng] ProvisioningServer
[testng] Total tests run: 1, Failures: 1, Skips: 0
[testng] ===============================================
[echo] You can increase the logging by editing bootstrap/log4j.xml
BUILD SUCCESSFUL
Total time: 33 seconds
I am new to Seam technology, using TestNG for unit Tesing.
In this test case I am trying to insert some data into database.
Can you please let me know where I am wrong.
Code snippet and logs are given below:
public class UserRoleTest extends SeamTest{
private EntityManagerFactory emf;
public EntityManagerFactory getEntityManagerFactory()
{
return emf;
}
@BeforeClass
public void init() throws Exception
{
super.init();
emf=Persistence.createEntityManagerFactory("provisioning");
}
@AfterClass
public void destroy()
{
emf.close();
}
@Test
public void testUserRole() throws Exception {
EntityManager em=getEntityManagerFactory().createEntityManager();
em.getTransaction().begin();
UserRole userRole=new UserRole();
userRole.setIdUserRole(3);
userRole.setRole("minoadmin1");
userRole.setRoleDescription("admin123");
em.getTransaction().commit();
em.close();
}
}
and the error I am getting is :
[testng] [Parser] Running:
[testng] D:\Seamworks\ProvisioningServer\src\org\domain\mino\ps\test\testng.xml
[testng] WARN [org.jboss.seam.security.RuleBasedIdentity] no security rule base available - please install a RuleBase with the name 'securityRules' if permission checks are required.
[testng] FAILED: testUserRole
[testng] java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
[testng] at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:317)
[testng] at org.domain.mino.ps.test.UserRoleTest.testUserRole(UserRoleTest.java:50)
[testng] ... Removed 22 stack frames
[testng] ===============================================
[testng] Login
[testng] Tests run: 1, Failures: 1, Skips: 0
[testng] ===============================================
[testng] ===============================================
[testng] ProvisioningServer
[testng] Total tests run: 1, Failures: 1, Skips: 0
[testng] ===============================================
[echo] You can increase the logging by editing bootstrap/log4j.xml
BUILD SUCCESSFUL
Total time: 33 seconds