use of com.adobe.acs.commons.forms.Form in project acs-aem-commons by Adobe-Consulting-Services.
the class PostRedirectGetFormHelperImplTest method shouldRedirectForRenderForm.
@Test
public void shouldRedirectForRenderForm() throws Exception {
request.setParameterMap(ImmutableMap.<String, Object>of(":form", "x"));
final SlingHttpServletResponse spiedResponse = spy(response);
final Form form = formHelper.getForm("x", request, response);
formHelper.renderForm(form, requestResource, request, spiedResponse);
// check a redirect was requested
verify(spiedResponse).sendRedirect(redirectCaptor.capture());
PathInfo redirectPathInfo = new PathInfo(redirectCaptor.getValue());
// check where we are being redirected to
assertThat(redirectPathInfo.getExtension(), is(equalTo("html")));
assertThat(redirectPathInfo.getResourcePath(), is(equalTo("/test")));
assertThat(redirectPathInfo.getSuffix(), startsWith(SUFFIX));
}
use of com.adobe.acs.commons.forms.Form in project acs-aem-commons by Adobe-Consulting-Services.
the class PostRedirectGetFormHelperImplTest method shouldMapSingleParam.
@Test
public void shouldMapSingleParam() throws Exception {
request.setParameterMap(ImmutableMap.<String, Object>of(":form", "x", "hello", "world"));
final Form form = formHelper.getForm("x", request, response);
assertThat(form.get("hello"), is(equalTo("world")));
}
use of com.adobe.acs.commons.forms.Form in project acs-aem-commons by Adobe-Consulting-Services.
the class PostRedirectGetFormHelperImplTest method shouldMapFormName.
@Test
public void shouldMapFormName() throws Exception {
request.setParameterMap(ImmutableMap.<String, Object>of(":form", "demo"));
final Form form = formHelper.getForm("demo", request, response);
assertThat(form.getName(), is(equalTo("demo")));
}
use of com.adobe.acs.commons.forms.Form in project acs-aem-commons by Adobe-Consulting-Services.
the class PostRedirectGetFormHelperImplTest method shouldMapFirstValueOfMultiParams.
@Test
public void shouldMapFirstValueOfMultiParams() throws Exception {
request.setParameterMap(ImmutableMap.<String, Object>of(":form", "x", "hello", new String[] { "world", "mundo" }));
final Form form = formHelper.getForm("x", request, response);
assertThat(form.get("hello"), is(equalTo("world")));
}
use of com.adobe.acs.commons.forms.Form in project acs-aem-commons by Adobe-Consulting-Services.
the class PostRedirectGetFormHelperImplTest method shouldSerialiseFormInRedirectUrlParameter.
@Test
public void shouldSerialiseFormInRedirectUrlParameter() throws Exception {
request.setParameterMap(ImmutableMap.<String, Object>of(":form", "x", "hello", "world"));
final SlingHttpServletResponse spiedResponse = spy(response);
final Form form = formHelper.getForm("x", request, response);
form.setError("hello", "Error1");
formHelper.renderForm(form, requestResource, request, spiedResponse);
verify(spiedResponse).sendRedirect(redirectCaptor.capture());
String redirectLocation = redirectCaptor.getValue();
final String formString = decode(getFormParameter(redirectLocation));
final JSONObject formObject = toJSONObject(formString);
// form name
assertThat(formObject.getString(PostRedirectGetFormHelperImpl.KEY_FORM_NAME), is(equalTo("x")));
// errors
final JSONObject formErrors = formObject.getJSONObject(PostRedirectGetFormHelperImpl.KEY_ERRORS);
assertThat(formErrors.getString("hello"), is(equalTo("Error1")));
// form data
final JSONObject formData = formObject.getJSONObject(PostRedirectGetFormHelperImpl.KEY_FORM);
assertThat(formData.getString("hello"), is(equalTo("world")));
}
Aggregations