Search in sources :

Example 21 with RequestProperty

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]);
}
Also used : RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) Test(org.junit.Test)

Example 22 with RequestProperty

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]);
}
Also used : RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) Test(org.junit.Test)

Example 23 with RequestProperty

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;
}
Also used : Expectations(org.jmock.Expectations) HtmlResponse(org.apache.sling.servlets.post.HtmlResponse) Set(java.util.Set) RequestParameter(org.apache.sling.api.request.RequestParameter) ArrayList(java.util.ArrayList) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) RequestParameterMap(org.apache.sling.api.request.RequestParameterMap) RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) ModifyOperation(org.apache.sling.servlets.post.impl.operations.ModifyOperation) RequestParameterMap(org.apache.sling.api.request.RequestParameterMap) Map(java.util.Map) Vector(java.util.Vector)

Example 24 with RequestProperty

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());
}
Also used : RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) Test(org.junit.Test)

Example 25 with RequestProperty

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]);
}
Also used : RequestProperty(org.apache.sling.servlets.post.impl.helper.RequestProperty) Test(org.junit.Test)

Aggregations

RequestProperty (org.apache.sling.servlets.post.impl.helper.RequestProperty)26 Test (org.junit.Test)12 RepositoryException (javax.jcr.RepositoryException)5 Resource (org.apache.sling.api.resource.Resource)5 HashMap (java.util.HashMap)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4 UserManager (org.apache.jackrabbit.api.security.user.UserManager)4 RequestParameter (org.apache.sling.api.request.RequestParameter)4 Map (java.util.Map)3 Group (org.apache.jackrabbit.api.security.user.Group)3 Session (javax.jcr.Session)2 User (org.apache.jackrabbit.api.security.user.User)2 RequestParameterMap (org.apache.sling.api.request.RequestParameterMap)2 LoginException (org.apache.sling.api.resource.LoginException)2 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)2 PersistenceException (org.apache.sling.api.resource.PersistenceException)2 ResourceNotFoundException (org.apache.sling.api.resource.ResourceNotFoundException)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 VersioningConfiguration (org.apache.sling.servlets.post.VersioningConfiguration)2 IOException (java.io.IOException)1