Search in sources :

Example 6 with MockServiceReference

use of org.apache.sling.commons.testing.osgi.MockServiceReference in project sling by apache.

the class ServletResourceProviderCreateTest method testCreateMethodsAll.

public void testCreateMethodsAll() {
    MockServiceReference msr = new MockServiceReference(null);
    msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES, RES_TYPE);
    msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS, "*");
    ServletResourceProvider srp = factory.create(msr, TEST_SERVLET);
    assertNotNull(srp);
    String[] paths = srp.getServletPaths();
    assertNotNull(paths);
    assertEquals(1, paths.length);
    Set<String> checkerSet = new HashSet<>();
    checkerSet.add(ROOT + RES_TYPE_PATH + ServletResourceProviderFactory.SERVLET_PATH_EXTENSION);
    for (String path : paths) {
        assertTrue(path + " not expected", checkerSet.remove(path));
    }
    assertTrue(checkerSet.isEmpty());
}
Also used : MockServiceReference(org.apache.sling.commons.testing.osgi.MockServiceReference) HashSet(java.util.HashSet)

Example 7 with MockServiceReference

use of org.apache.sling.commons.testing.osgi.MockServiceReference in project sling by apache.

the class ServletResourceProviderCreateTest method testCreateMethodsSingle.

public void testCreateMethodsSingle() {
    MockServiceReference msr = new MockServiceReference(null);
    msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES, RES_TYPE);
    msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS, "GET");
    ServletResourceProvider srp = factory.create(msr, TEST_SERVLET);
    assertNotNull(srp);
    String[] paths = srp.getServletPaths();
    assertNotNull(paths);
    assertEquals(1, paths.length);
    Set<String> checkerSet = new HashSet<>();
    checkerSet.add(ROOT + RES_TYPE_PATH + "/" + HttpConstants.METHOD_GET + ServletResourceProviderFactory.SERVLET_PATH_EXTENSION);
    for (String path : paths) {
        assertTrue(path + " not expected", checkerSet.remove(path));
    }
    assertTrue(checkerSet.isEmpty());
}
Also used : MockServiceReference(org.apache.sling.commons.testing.osgi.MockServiceReference) HashSet(java.util.HashSet)

Example 8 with MockServiceReference

use of org.apache.sling.commons.testing.osgi.MockServiceReference in project sling by apache.

the class ServletResourceProviderCreateTest method testCreateMethodsDefault.

public void testCreateMethodsDefault() {
    MockServiceReference msr = new MockServiceReference(null);
    msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES, RES_TYPE);
    // msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS, "*");
    ServletResourceProvider srp = factory.create(msr, TEST_SERVLET);
    assertNotNull(srp);
    String[] paths = srp.getServletPaths();
    assertNotNull(paths);
    assertEquals(2, paths.length);
    Set<String> checkerSet = new HashSet<>();
    checkerSet.add(ROOT + RES_TYPE_PATH + "/" + HttpConstants.METHOD_GET + ServletResourceProviderFactory.SERVLET_PATH_EXTENSION);
    checkerSet.add(ROOT + RES_TYPE_PATH + "/" + HttpConstants.METHOD_HEAD + ServletResourceProviderFactory.SERVLET_PATH_EXTENSION);
    for (String path : paths) {
        assertTrue(path + " not expected", checkerSet.remove(path));
    }
    assertTrue(checkerSet.isEmpty());
}
Also used : MockServiceReference(org.apache.sling.commons.testing.osgi.MockServiceReference) HashSet(java.util.HashSet)

Aggregations

MockServiceReference (org.apache.sling.commons.testing.osgi.MockServiceReference)8 HashSet (java.util.HashSet)6 Field (java.lang.reflect.Field)2 Dictionary (java.util.Dictionary)2 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 LoginException (org.apache.sling.api.resource.LoginException)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 ResourceResolverFactory (org.apache.sling.api.resource.ResourceResolverFactory)1 MockBundle (org.apache.sling.commons.testing.osgi.MockBundle)1 MockBundleContext (org.apache.sling.commons.testing.osgi.MockBundleContext)1 MockResource (org.apache.sling.commons.testing.sling.MockResource)1 MockResourceResolver (org.apache.sling.commons.testing.sling.MockResourceResolver)1 MockServletResource (org.apache.sling.servlets.resolver.internal.resource.MockServletResource)1 ServletResourceProvider (org.apache.sling.servlets.resolver.internal.resource.ServletResourceProvider)1 ServletResourceProviderFactory (org.apache.sling.servlets.resolver.internal.resource.ServletResourceProviderFactory)1 Before (org.junit.Before)1