-
1. Re: Testing Pageflows
acerberus Jul 13, 2009 11:24 PM (in response to acerberus)It might have something todo with the conversation handling. When adding an 'assert isLongRunningConversation();' to the first request after the invokeAction statement, it is asserted that we are in fact in a long running conversation. When adding the assertion into the invokeApplication method of the second request I get an assertion error.
Strangely, the conversation seems to be propagated to the second request, if I do not start a pageflow but only a plain conversation. Could this be a bug in the pageflow handling in seamtest or am I doing something completely wrong here?
-
2. Re: Testing Pageflows
acerberus Jul 17, 2009 3:57 PM (in response to acerberus)Am I really the first person who tries to test pageflows, or am I missing something so obvious that you don't want to tell me :D? Come on .. there has to be someone out there who tried this before. Please, help. Or are pageflows really not testable at the moment?
-
3. Re: Testing Pageflows
versilov Nov 21, 2009 9:26 PM (in response to acerberus)I've got the problem with pageflows also.
I extended the checkout pageflow from dvdstore example — added an address form into it.
I also expanded the test to test this form with FacesRequest.
Strange problem — after executing faces requests for /address.xhtml page, invokeApplication() and renderResponse() methods for testing /confirm.xhtml are not invoked!Here's the code:
public long makeOrder() throws Exception {
String id = new FacesRequest("/product.xhtml") {
@Override
protected void beforeRequest() {
setParameter("id", "41");
}
}.run();
log.info("Before product.xhtml cid=" + id);
id = new FacesRequest("/product.xhtml", id) {
@Override
protected void invokeApplication() throws Exception {
invokeAction("#{search.addToCart}");
}
}.run();
log.info("Before checkout.xhtml cid=" + id);
id = new NonFacesRequest("/checkout.xhtml", id) {
}.run();
log.info("Before checkout.xhtml cid=" + id);
id = new FacesRequest("/checkout.xhtml", id) {
@Override
protected void applyRequestValues() throws Exception {
setValue("#{identity.username}", "user1");
setValue("#{identity.password}", "password");
}
protected void invokeApplication() throws Exception {
invokeAction("#{identity.login}");
}
@Override
protected void renderResponse() throws Exception {
assert getValue("#{identity.loggedIn}").equals(Boolean.TRUE);
User currentUser = (User) getValue("#{currentUser}");
assert currentUser.getUserName().equals("user1");
}
}.run();
log.info("Before checkout.xhtml cid=" + id);
id = new FacesRequest("/checkout.xhtml", id) {
@Override
protected void invokeApplication() throws Exception {
invokeAction("#{checkout.createOrder}");
Order order = (Order) getValue("#{currentOrder}");
assert order!=null;
}
@Override
protected void renderResponse() {
assert Manager.instance().isLongRunningConversation();
}
}.run();
log.info("Before address.xhtml cid=" + id);
id = new NonFacesRequest("/address.xhtml", id) {
}.run();
log.info("Before address.xhtml cid=" + id);
id = new FacesRequest("/address.xhtml", id) {
@Override
protected void applyRequestValues() throws Exception {
setValue("#{currentOrder.customer.address1}", "Malholland drive, 35-40");
}
@Override
protected void invokeApplication() throws Exception {
log.info("Submitting address...");
invokeAction("#{checkout.submitAddress}");
}
@Override
protected void renderResponse() {
assert Manager.instance().isLongRunningConversation();
}
}.run();
log.info("before confirm.xhtml cid=" + id);
id = new NonFacesRequest("/confirm.xhtml", id) {
}.run();
final Wrapper<Long> orderId = new Wrapper<Long>();
log.info("Before confirm.xhtml cid=" + id);
FacesRequest fr = new FacesRequest("/confirm.xhtml", id) {
@Override
protected void invokeApplication() throws Exception {
log.info("Invoking submitOrder...");
invokeAction("#{checkout.submitOrder}");
}
@Override
protected void renderResponse() throws Exception {
Order order = (Order) getValue("#{completedOrder}");
assert order!=null;
log.info("OrderId: " + order.getOrderId());
assert order.getCustomer().getUserName().equals("user1");
assert order.getStatus().equals(Status.OPEN);
assert Manager.instance().isLongRunningConversation();
orderId.setValue(order.getOrderId());
assert orderId.getValue() != null;
}
};
fr.run();
return orderId.getValue();
}