Search in sources :

Example 16 with RequestPathInfo

use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.

the class SlingRequestPathInfoTest method testMerge.

public void testMerge() {
    SlingRequestPathInfo p = new SlingRequestPathInfo(new MockResource("/some/path", ".s1.s2.ext"));
    assertEquals("s1.s2", p.getSelectorString());
    assertEquals("ext", p.getExtension());
    // test to replace selectors with a new one
    RequestDispatcherOptions o = new RequestDispatcherOptions();
    o.setReplaceSelectors("a");
    RequestPathInfo result = p.merge(o);
    assertEquals("a", result.getSelectorString());
    assertEquals("ext", result.getExtension());
    // test to replace selector with the empty string
    o.setReplaceSelectors("");
    result = p.merge(o);
    assertEquals(null, result.getSelectorString());
    assertEquals("ext", result.getExtension());
    // now add a selector
    o.setAddSelectors("b");
    result = p.merge(o);
    assertEquals("b", result.getSelectorString());
    assertEquals("ext", result.getExtension());
    // replace ext
    o.setReplaceSuffix("html");
    result = p.merge(o);
    assertEquals("b", result.getSelectorString());
    assertEquals("html", result.getSuffix());
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo) RequestDispatcherOptions(org.apache.sling.api.request.RequestDispatcherOptions)

Example 17 with RequestPathInfo

use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.

the class SlingRequestPathInfoTest method testPathOnly.

public void testPathOnly() {
    RequestPathInfo p = new SlingRequestPathInfo(new MockResource("/some/path/here", ""));
    assertEquals("/some/path/here", p.getResourcePath());
    assertNull("Selectors are null", p.getSelectorString());
    assertEquals(0, p.getSelectors().length);
    assertNull("Extension is null", p.getExtension());
    assertNull("Suffix is null", p.getSuffix());
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo)

Example 18 with RequestPathInfo

use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.

the class SlingRequestPathInfoTest method testAllOptions.

public void testAllOptions() {
    RequestPathInfo p = new SlingRequestPathInfo(new MockResource("/some/path", ".print.a4.html/some/suffix"));
    assertEquals("/some/path", p.getResourcePath());
    assertEquals("print.a4", p.getSelectorString());
    assertEquals(2, p.getSelectors().length);
    assertEquals("print", p.getSelectors()[0]);
    assertEquals("a4", p.getSelectors()[1]);
    assertEquals("html", p.getExtension());
    assertEquals("/some/suffix", p.getSuffix());
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo)

Example 19 with RequestPathInfo

use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.

the class SlingRequestPathInfoTest method testTrailingDotDotDot.

public void testTrailingDotDotDot() {
    RequestPathInfo p = new SlingRequestPathInfo(new MockResource("/some/path", "..."));
    assertEquals("/some/path", p.getResourcePath());
    assertNull("Selectors are null", p.getSelectorString());
    assertEquals(0, p.getSelectors().length);
    assertNull("Extension is null", p.getExtension());
    assertNull("Suffix is null", p.getSuffix());
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo)

Example 20 with RequestPathInfo

use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.

the class SlingRequestPathInfoTest method testTrailingDotDot.

public void testTrailingDotDot() {
    RequestPathInfo p = new SlingRequestPathInfo(new MockResource("/some/path", ".."));
    assertEquals("/some/path", p.getResourcePath());
    assertNull("Selectors are null", p.getSelectorString());
    assertEquals(0, p.getSelectors().length);
    assertNull("Extension is null", p.getExtension());
    assertNull("Suffix is null", p.getSuffix());
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo)

Aggregations

RequestPathInfo (org.apache.sling.api.request.RequestPathInfo)33 Resource (org.apache.sling.api.resource.Resource)4 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 Servlet (javax.servlet.Servlet)1 RequestDispatcherOptions (org.apache.sling.api.request.RequestDispatcherOptions)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 SlingMainServlet (org.apache.sling.engine.impl.SlingMainServlet)1 VersioningConfiguration (org.apache.sling.servlets.post.VersioningConfiguration)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1