|
|
quot;); loginForm.setPassword(quot;aquot;); ServletExternalContext externalContext = new ServletExternalContext(servletContext,request,resp onse); externalContext.getSessionMap().put(quot;loginFormquot;,lo ginForm); ApplicationView view = applicationView(signalEvent(quot;submitquot;,externalConte xt)); assertViewNameEquals(quot;patientquot;,view); assertFlowExecutionEnded(); }
junit.framework.ComparisonFailure: The view name is wrong: expected:lt;patientgt; but was:lt;loginForwardgt;
because i am not able to retrive username and password from LoginForm , as i am passing as EXternalContext , but in action i am retrieving as context.getFlowScope.
How to test this senario, can you give me example.
The sessionMap of the external context is the from session and not flow scope.
As far as I can see you are putting the loginForm in the from session:
externalContext.getSessionMap().put(quot;loginFormquot;,lo ginForm);
And your action is trying to retreive it from the flow scope:
LoginForm loginForm = (LoginForm)context.getFlowScope().get(LOGIN_FORM);When running your flow normally (i.e. not in a unit test), who is responsible for putting the loginForm in the flow scope?
Erwin
public LoginFlowAction() {
setFormObjectName(LOGIN_FORM);
setFormObjectClass(LoginForm.class);
setFormObjectScope(ScopeType.FLOW);
}
protected Object createFormObject(RequestContext context) throws Exception {
LoginForm loginForm = null; if (context.getFlowExecutionContext().getDefinition() .getId().equals(quot;login-flowquot;)){ loginForm = createFormObjectForLogin(context); }
return loginForm;
}
private LoginForm createFormObjectForLogin(RequestContext context) throws InstantiationException, IllegalAccessException{
LoginForm loginForm; if (this.getFormObjectClass()== null) {
throw new IllegalStateException(quot;Cannot create form object without formObjectClass being set -- quot;
+ quot;either set formObjectClass or override this methodquot;);
}
if (logger.isDebugEnabled()) {
logger.debug(quot;Creating new form object of class [quot; + this.getFormObjectClass().getName() + quot;]quot;);
}
loginForm = (LoginForm) this.getFormObjectClass().newInstance();
String username = (String) context.getRequestParameters().get(Constants.USERN AME);
String password = (String) context.getRequestParameters().get(Constants.PASSW ORD);
loginForm.setUsername(username);
loginForm.setPassword(password); return loginForm;
}This API above will make show how , i am creating LoginForm and then in other api i am retrieving using FlowScope.
Originally Posted by klr8The sessionMap of the external context is the from session and not flow scope.
As far as I can see you are putting the loginForm in the from session:
externalContext.getSessionMap().put(quot;loginFormquot;,lo ginForm);
And your action is trying to retreive it from the flow scope:
LoginForm loginForm = (LoginForm)context.getFlowScope().get(LOGIN_FORM);When running your flow normally (i.e. not in a unit test), who is responsible for putting the loginForm in the flow scope?
Erwin
public class LoginFlowAction extends FormAction{
private ILoginService loginService;
private ILookUpService lookupService;
private WordGeneratorWrapper wordGeneratorWrapper;
private Map userRoleMap; private int maximumCounterValue;
public static final String LOGIN_FORM = quot;loginFormquot;;
private IEventPublisher forgotPasswordEventPublisher;
public LoginFlowAction() {
setFormObjectName(LOGIN_FORM);
setFormObjectClass(LoginForm.class);
setFormObjectScope(ScopeType.FLOW);
}
/** * The API createFormObject() is used to create a new form object by * instantiating the configured form object class. * @param context - the action execution context, for accessing and setting data in quot;flow scopequot; or quot;request scopequot; * @return the form object * @throws java.lang.Exception - the form object could not be created */
protected Object createFormObject(RequestContext context) throws Exception {
LoginForm loginForm = null; if (context.getFlowExecutionContext().getDefinition() .getId().equals(quot;login-flowquot;)){ loginForm = createFormObjectForLogin(context); }
/*if (context.getFlowExecutionContext().getFlow().getId ().equals(quot;login-flowquot;)){ loginForm = createFormObjectForLogin(context); }*/ return loginForm;
}
/*** The API createFormObjectForLogin() is used to create the login form object that is* used in the login flow.* @param context - The action execution context* @return* @throws InstantiationException* @throws IllegalAccessException*/
private LoginForm createFormObjectForLogin(RequestContext context) throws InstantiationException, IllegalAccessException{
LoginForm loginForm; if (this.getFormObjectClass()== null) {
throw new IllegalStateException(quot;Cannot create form object without formObjectClass being set -- quot;
+ quot;either set formObjectClass or override this methodquot;);
}
if (logger.isDebugEnabled()) {
logger.debug(quot;Creating new form object of class [quot; + this.getFormObjectClass().getName() + quot;]quot;);
}
loginForm = (LoginForm) this.getFormObjectClass().newInstance();
String username = (String) context.getRequestParameters().get(Constants.USERN AME);
String password = (String) context.getRequestParameters().get(Constants.PASSW ORD);
loginForm.setUsername(username);
loginForm.setPassword(password); return loginForm;
}
I resending , How i am setting LoginForm to FlowScope. I think that will help to get idea.
I have more than 3 criteria where , i am facing same problem. |
|