Hi Markus,
I extended the SeamTest class for JUnit4 and it works fine. However, to be
honest, you may find moving to TestNG is preferable, I'm still tossing it up.
Here's what I hacked out very quickly, I overrode the begin method to set up my
em and tm, so that I could use those to set up test data in my setUp(). If you
don't need that, maybe you can even subclass SeamTest directly.
| public class BaseSeamTest extends SeamTest {
| protected EntityManager em;
| protected TransactionManager tm;
|
|
| @Override
| public void begin() {
| super.begin();
| if (em == null) {
| try {
| em = (EntityManager)
getInitialContext().lookup("java:/EntityManagers/localUnitTestEM");
| tm = (TransactionManager)
getInitialContext().lookup("java:/TransactionManager");
| } catch (NamingException e) {
| throw new RuntimeException(e);
| }
| }
| }
| }
|
|
| public class LoginTest extends BaseSeamTest {
|
| @Test
| public void testFailedLogin() throws Exception {
| new Script() {
| @Override
| protected void updateModelValues() throws Exception {
| assertFalse(isSessionInvalid());
| final User user = (User) Component.getInstance("user",
true);
| assertNotNull(user);
| user.setLogin("LoginTest_testLogin");
| user.setPassword("password");
| }
|
| @Override
| protected void invokeApplication() throws Exception {
| Login login = (Login) Component.getInstance("login", true);
| assertEquals(null, login.login());
| }
|
| @Override
| protected void renderResponse() throws Exception {
| final Iterator messages =
FacesContext.getCurrentInstance().getMessages();
| final FacesMessage message = (FacesMessage) messages.next();
| assertEquals("LoginAction_InvalidLogin",
message.getDetail());
| assertFalse(messages.hasNext());
| }
| }.run();
| }
| .......
|
I hope that helps,
Daniel.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3979217#3979217
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3979217
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user