use of org.apache.sling.servlets.post.impl.helper.RequestProperty in project sling by apache.
the class RequestPropertyTest method testMultiValue.
@Test
public void testMultiValue() throws Throwable {
Map<String, RequestProperty> props = collectContent(p("./param", "true", "false"));
assertEquals(1, props.size());
RequestProperty prop = props.get("/test/path/param");
assertTrue(prop.hasValues());
assertTrue(prop.providesValue());
assertEquals(2, prop.getStringValues().length);
assertEquals("true", prop.getStringValues()[0]);
assertEquals("false", prop.getStringValues()[1]);
}
use of org.apache.sling.servlets.post.impl.helper.RequestProperty in project sling by apache.
the class RequestPropertyTest method testMultiValueWithBlanks.
@Test
public void testMultiValueWithBlanks() throws Throwable {
Map<String, RequestProperty> props = collectContent(p("./param", "true", "", ""));
assertEquals(1, props.size());
RequestProperty prop = props.get("/test/path/param");
assertTrue(prop.hasValues());
assertTrue(prop.providesValue());
assertEquals(3, prop.getStringValues().length);
assertEquals("true", prop.getStringValues()[0]);
assertEquals("", prop.getStringValues()[1]);
assertEquals("", prop.getStringValues()[2]);
}
use of org.apache.sling.servlets.post.impl.helper.RequestProperty in project sling by apache.
the class RequestPropertyTest method collectContent.
@SuppressWarnings("unchecked")
private Map<String, RequestProperty> collectContent(Param... kvs) throws Throwable {
final List<Map.Entry<String, RequestParameter>> params = new ArrayList<Map.Entry<String, RequestParameter>>();
for (int i = 0; i < kvs.length; i++) {
final Param kv = kvs[i];
final RequestParameter[] param = new RequestParameter[kv.value.length];
for (int j = 0; j < kv.value.length; j++) {
final String strValue = kv.value[j];
final RequestParameter aparam = context.mock(RequestParameter.class, "requestParameter" + i + "#" + j);
context.checking(new Expectations() {
{
allowing(aparam).getString();
will(returnValue(strValue));
}
});
param[j] = aparam;
}
final Map.Entry<String, RequestParameter> entry = context.mock(Map.Entry.class, "entry" + i);
context.checking(new Expectations() {
{
allowing(entry).getKey();
will(returnValue(kv.key));
allowing(entry).getValue();
will(returnValue(param));
}
});
params.add(entry);
}
final Set set = context.mock(Set.class);
context.checking(new Expectations() {
{
one(set).iterator();
will(returnValue(params.iterator()));
}
});
final RequestParameterMap map = context.mock(RequestParameterMap.class);
context.checking(new Expectations() {
{
one(map).entrySet();
will(returnValue(set));
}
});
final SlingHttpServletRequest request = context.mock(SlingHttpServletRequest.class);
context.checking(new Expectations() {
{
Vector names = new Vector();
names.add("./param");
one(request).getParameterNames();
will(returnValue(names.elements()));
one(request).getRequestParameterMap();
will(returnValue(map));
}
});
final HtmlResponse response = new HtmlResponse();
response.setPath("/test/path");
Map<String, RequestProperty> props = (Map<String, RequestProperty>) PrivateAccessor.invoke(new ModifyOperation(), "collectContent", COLLECT_CLASSES, new Object[] { request, response });
return props;
}
use of org.apache.sling.servlets.post.impl.helper.RequestProperty in project sling by apache.
the class RequestPropertyTest method testMultiValueWithAllBlanksIgnoringBlanks.
@Test
public void testMultiValueWithAllBlanksIgnoringBlanks() throws Throwable {
Map<String, RequestProperty> props = collectContent(p("./param", "", "", ""), p("./param@IgnoreBlanks", "true"));
assertEquals(1, props.size());
RequestProperty prop = props.get("/test/path/param");
assertFalse(prop.hasValues());
}
use of org.apache.sling.servlets.post.impl.helper.RequestProperty in project sling by apache.
the class RequestPropertyTest method testSingleValueWithBlank.
@Test
public void testSingleValueWithBlank() throws Throwable {
Map<String, RequestProperty> props = collectContent(p("./param", ""));
assertEquals(1, props.size());
RequestProperty prop = props.get("/test/path/param");
assertTrue(prop.hasValues());
assertFalse(prop.providesValue());
assertEquals(1, prop.getStringValues().length);
assertEquals("", prop.getStringValues()[0]);
}
Aggregations