i am trying to test my JSf
aplication with Arquillian
. The problem i am facing is that i am unable to inject the Managed Bean
named TicketBean
in to my test class which is TicketBeanTest
. What i have tried so far to inject the TicketBean
in to TicketBeanTest
was,
- tried using
@ManagedProperty
but did not work , threwNullPointerException
when i called any method onTicketBean
- tried using
@inject
but thewjava.lang.RuntimeException
, statingcould not inject member
-
tried using
@Before public void instantiate(){ ticketBean=new TicketBean(); }
but it failed to call
@PostConstruct
method insideTicketBean
, so againNullPointerException
while callingDAO
method from insideTicketBean
. i am testing my application inJBoss AS
container.
following is my Test Class,
@RunWith(Arquillian.class)
public class TicketBeanTest {
@Inject
TicketBean ticketBean;
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(TicketBean.class, Ticket.class, TicketDao.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
@Before
public void instantiate() {
ticketBean = new TicketBean();
}
@Test
public void dotest() {
Ticket ticket = new Ticket();
ticket.setSummary("JUnite-Arquillian Test");
ticket.setDescription("Testing from Arquillian");
ticket.setPriority(2);
ticket.setStatus(2);
ticket.setAssignedTo("alok.dac");
ticket.setProject(100);
ticket.setTicketId(2);
Assert.assertEquals("home", ticketBean.updateTicket(ticket));
}
@Ignore
@Test
public void should_Return_true() {
Assert.assertTrue(ticketBean.testArquillian());
}
}
following is the TicketBean
class ,
@ManagedBean(name = "ticketBean")
public class TicketBean implements Serializable {
private transient TicketDao tDao;
@PostConstruct
public void init() {
this.tDao = new TicketDao();
}
public String updateTicket(Ticket ticket) {
boolean flag = this.tDao.updateTicket(ticket);
if (flag) {
FacesContext.getCurrentInstance().addMessage(
"",
new FacesMessage(FacesMessage.SEVERITY_INFO,
"Ticket Updated Successfully !", ""));
return "home";
}
FacesContext.getCurrentInstance().addMessage(
"",
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Ticket Updated Failed ! ",
"Some error occured , Try Again !"));
return Constants.ERRPAGE;
}
}
Aucun commentaire:
Enregistrer un commentaire