Seam Testing with JUnit
laxmiram Jul 20, 2010 2:43 AMHi All,
Need help on integrating Seam project for testing with JUnit. i have no clues to where and how to start. i tried created a seam web project using eclipse, created few seam actions.i tried to run the <clasNameTest>.xml as JUNIT test, it says "No Test found for JUnit 3".
given below are my action, actiontest and corresponding xml.
RegistrationBean.java
<headers>
@Stateful
@Scope(SESSION)
@Name("Registration")
public class RegistrationBean implements Registration
{
@Logger private Log log;
@PersistenceContext
private EntityManager em;
@In StatusMessages statusMessages;
String customerName;
private short customerStatus = 4;
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public void saveCustomer()
{
try {
// implement your business logic here
log.info("Registration.saveCustomer() action called");
log.info("Customer Name" + customerName);
statusMessages.add("saveCustomer");
//my entity
CasStatusRef tcsr = em.find(CasStatusRef.class, customerStatus);
Customer tc = new Customer();
tc.setCasStatusRef(tcsr);
tc.setFName(this.getCustomerName());
em.persist(tc);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Remove
public void destroy() {
}
// add additional action methods
}
ActionTest.java
package com.tcs.tib.tcaretest.test;
import org.testng.annotations.Test;
import org.jboss.seam.mock.SeamTest;
public class TcareRegistrationTest extends SeamTest {
@Test
public void test_saveCustomer() throws Exception {
new FacesRequest() {
@Override
protected void updateModelValues() throws Exception
{
setValue("#{Registration.customerName}", "testing-JUNIT");
}
@Override
protected void invokeApplication() {
//call action methods here
invokeMethod("#{Registration.saveCustomer}");
}
}.run();
}
}
actionTest.xml
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="Registration Tests" verbose="2" parallel="false">
<test name="Registration Test">
<classes>
<class name="com.abc.bcd.pjttest.test.RegistrationTest"/>
</classes>
</test>
</suite>
Note: right click of this xml, didn't gimme the option to run as JUNIT. hence i tried to configure it and run.
kindly guide me.
Lakshmi
Need help on integrating Seam project for testing with JUnit. i have no clues to where and how to start. i tried created a seam web project using eclipse, created few seam actions.i tried to run the <clasNameTest>.xml as JUNIT test, it says "No Test found for JUnit 3".
given below are my action, actiontest and corresponding xml.
RegistrationBean.java
<headers>
@Stateful
@Scope(SESSION)
@Name("Registration")
public class RegistrationBean implements Registration
{
@Logger private Log log;
@PersistenceContext
private EntityManager em;
@In StatusMessages statusMessages;
String customerName;
private short customerStatus = 4;
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public void saveCustomer()
{
try {
// implement your business logic here
log.info("Registration.saveCustomer() action called");
log.info("Customer Name" + customerName);
statusMessages.add("saveCustomer");
//my entity
CasStatusRef tcsr = em.find(CasStatusRef.class, customerStatus);
Customer tc = new Customer();
tc.setCasStatusRef(tcsr);
tc.setFName(this.getCustomerName());
em.persist(tc);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Remove
public void destroy() {
}
// add additional action methods
}
ActionTest.java
package com.tcs.tib.tcaretest.test;
import org.testng.annotations.Test;
import org.jboss.seam.mock.SeamTest;
public class TcareRegistrationTest extends SeamTest {
@Test
public void test_saveCustomer() throws Exception {
new FacesRequest() {
@Override
protected void updateModelValues() throws Exception
{
setValue("#{Registration.customerName}", "testing-JUNIT");
}
@Override
protected void invokeApplication() {
//call action methods here
invokeMethod("#{Registration.saveCustomer}");
}
}.run();
}
}
actionTest.xml
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="Registration Tests" verbose="2" parallel="false">
<test name="Registration Test">
<classes>
<class name="com.abc.bcd.pjttest.test.RegistrationTest"/>
</classes>
</test>
</suite>
Note: right click of this xml, didn't gimme the option to run as JUNIT. hence i tried to configure it and run.
kindly guide me.
Lakshmi