-
1. Re: Problems with SessionContext while testing DAO
wrxsti Apr 12, 2010 4:51 AM (in response to wrxsti)My Test Code
@RunWith(Arquillian.class)
public class TestExmple {@Deployment
public static JavaArchive createTestArchive() throws ClassNotFoundException {Class cls = org.jboss.seam.contexts.Contexts.class;
Package pkg = cls.getPackage();
Class cls2 = org.jboss.seam.log.Logging.class;
Package pkg2 = cls2.getPackage();
Class cls3 = org.jboss.seam.intercept.Interceptor.class;
Package pkg3 = cls3.getPackage();
Class cls4 = org.jboss.seam.ejb.SeamInterceptor.class;
Package pkg4 = cls4.getPackage();
Class cls5 = org.jboss.seam.Component.class;
Package pkg5 = cls5.getPackage();
Class cls6 = org.jboss.seam.annotations.intercept.InterceptorType.class;
Package pkg6 = cls6.getPackage();return Archives.create("test.jar", JavaArchive.class).addClasses(User.class, UserDao.class, UserDaoImpl.class,BasicDao.class,BasicDaoImpl.class
,Entity.class,ContextKey.class,org.jboss.seam.contexts.Contexts.class)
.addPackage(pkg).addPackage(pkg2)
.addPackage(pkg3).addPackage(pkg4)
.addPackage(pkg5)
.addPackage(pkg6)
.addManifestResource(
"persistence.xml",
ArchivePaths.create("persistence.xml"))
.addManifestResource("jboss-saasp-ds.xml", ArchivePaths.create("jboss-saasp-ds.xml"))
.addManifestResource("ejb-jar.xml", ArchivePaths.create("ejb-jar.xml"));}
// @EJB
private UserDaoImpl userRepository=new UserDaoImpl();@Test
public void testCanPersistUserObject() {
User u = new User();
userRepository.saveUser(u);
u.setName("igor");
u.setPassword("fsdf");
u.setRole("user");
u.setTenantId(1);
List<User> users = userRepository.findUserByName("igor");
Assert.assertNotNull(users);
Assert.assertTrue(users.size() == 1);}
} -
2. Re: Problems with SessionContext while testing DAO
aslak Apr 13, 2010 8:32 AM (in response to wrxsti)Basically the problem is that Seam is never started.
Currently we don't have any special Seam 2 support in Arquillian, http://community.jboss.org/message/532388
And at the time being we don't really support returning a WebArchive as your @Deployment so you could add the right SeamListeners etc in your web.xml.
You can try to manually bootstrap Seam like the SeamListener with some Mocks, something like:
{code:java}
@Test public void myTest() { HttpSession session = new MockHttpSession(new MockServletContext()); ServletLifecycle.beginSession(session); ..testCode.. ServletLifecycle.endSession(session); } {code}