Search in sources :

Example 56 with Resource

use of org.apache.sling.api.resource.Resource in project sling by apache.

the class MockedResourceResolverImplTest method buildMappingResource.

@SuppressWarnings("unchecked")
private Resource buildMappingResource(String path, ResourceProvider<?> provider, ResourceResolver resourceResolver) {
    List<Resource> localHostAnyList = new ArrayList<Resource>();
    localHostAnyList.add(buildResource(path + "/http/example.com.80/cgi-bin", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:internalRedirect", "/scripts"));
    localHostAnyList.add(buildResource(path + "/http/example.com.80/gateway", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:internalRedirect", "http://gbiv.com"));
    localHostAnyList.add(buildResource(path + "/http/example.com.80/stories", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:internalRedirect", "/anecdotes/$1"));
    List<Resource> mappingChildren = new ArrayList<Resource>();
    mappingChildren.add(buildResource(path + "/http/example.com.80", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:redirect", "http://www.example.com/"));
    mappingChildren.add(buildResource(path + "/http/www.example.com.80", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:internalRedirect", "/example"));
    mappingChildren.add(buildResource(path + "/http/any_example.com.80", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:match", ".+\\.example\\.com\\.80", "sling:redirect", "http://www.example.com/"));
    mappingChildren.add(buildResource(path + "/http/localhost_any", localHostAnyList, resourceResolver, provider, "sling:match", "localhost\\.\\d*", "sling:internalRedirect", "/content"));
    Resource etcMapResource = buildResource(path + "/http", mappingChildren);
    Mockito.when(provider.getResource(Mockito.any(ResolveContext.class), Mockito.eq(path), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(etcMapResource);
    return etcMapResource;
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) ResourceContext(org.apache.sling.spi.resource.provider.ResourceContext) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource)

Example 57 with Resource

use of org.apache.sling.api.resource.Resource in project sling by apache.

the class MockedResourceResolverImplTest method testRelativeResource.

/**
     * Test search paths
     * @throws LoginException
     */
@Test
public void testRelativeResource() throws LoginException {
    ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(null);
    Assert.assertNotNull(resourceResolver);
    Resource appResource = buildResource("/apps/store/inventory", EMPTY_RESOURCE_LIST, resourceResolver, appsResourceProvider);
    Resource libResource = buildResource("/libs/store/catalog", EMPTY_RESOURCE_LIST, resourceResolver, appsResourceProvider);
    Resource testResource = resourceResolver.getResource("store/inventory");
    Assert.assertEquals(appResource, testResource);
    testResource = resourceResolver.getResource("store/catalog");
    Assert.assertEquals(libResource, testResource);
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 58 with Resource

use of org.apache.sling.api.resource.Resource in project sling by apache.

the class ResourceDecorationTest method NonExistentIsDecorated.

@Test
public void NonExistentIsDecorated() {
    final Resource r = resolver.resolve("/foo");
    assertDecorated(r);
    assertExistent(r, false);
}
Also used : Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 59 with Resource

use of org.apache.sling.api.resource.Resource in project sling by apache.

the class ResourceDecorationTest method listChildrenDecorates.

@Test
public void listChildrenDecorates() {
    final Resource testVar = resolver.resolve("/var");
    assertDecorated(resolver.listChildren(testVar), 3);
}
Also used : Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 60 with Resource

use of org.apache.sling.api.resource.Resource in project sling by apache.

the class AuthenticatedResourceProviderTest method testGetParent.

@Test
public void testGetParent() {
    final Resource child = mock(Resource.class);
    when(child.getPath()).thenReturn("/parent/child");
    final Resource parent = mock(Resource.class);
    when(parent.getPath()).thenReturn("/parent");
    when(this.resourceProvider.getParent(this.resolveContext, child)).thenReturn(parent);
    assertEquals("/parent", this.src.getParent(child).getPath());
}
Also used : Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Aggregations

Resource (org.apache.sling.api.resource.Resource)1151 Test (org.junit.Test)633 ValueMap (org.apache.sling.api.resource.ValueMap)263 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)164 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)159 Node (javax.jcr.Node)116 HashMap (java.util.HashMap)104 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)99 PersistenceException (org.apache.sling.api.resource.PersistenceException)94 ArrayList (java.util.ArrayList)70 HttpServletRequest (javax.servlet.http.HttpServletRequest)62 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)60 FakeSlingHttpServletRequest (org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest)59 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)55 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)43 Map (java.util.Map)41 InputStream (java.io.InputStream)38 LoginException (org.apache.sling.api.resource.LoginException)37 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)36 Iterator (java.util.Iterator)33