Search in sources :

Example 61 with Resource

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

the class ResourceDecorationTest method getRootIsDecorated.

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

Example 62 with Resource

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

the class ResourceDecoratorReturnsNullTest method testVarChildren.

@Test
public void testVarChildren() {
    final Resource var = resolver.resolve("/var");
    assertNotNull(var);
    assertResources(resolver.listChildren(var), "/var/one", "/var/two", "/var/three");
}
Also used : Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 63 with Resource

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

the class ResourceDecoratorReturnsNullTest method testRootChildren.

@Test
public void testRootChildren() {
    final Resource root = resolver.resolve("/");
    assertNotNull(root);
    assertResources(resolver.listChildren(root), "/tmp", "/var");
}
Also used : Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 64 with Resource

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

the class ResourceDecoratorTestBase method mockResource.

protected Resource mockResource(String path) {
    final Resource result = Mockito.mock(Resource.class);
    Mockito.when(result.getPath()).thenReturn(path);
    Mockito.when(result.getName()).thenReturn(ResourceUtil.getName(path));
    final ResourceMetadata m = new ResourceMetadata();
    Mockito.when(result.getResourceMetadata()).thenReturn(m);
    return result;
}
Also used : NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) ResourceMetadata(org.apache.sling.api.resource.ResourceMetadata)

Example 65 with Resource

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

the class ResourceProviderEntryTest method testRemoveTheOnlyProvider.

@Test
public void testRemoveTheOnlyProvider() throws LoginException {
    long counter = 1;
    providers.clear();
    for (String path : new String[] { "/foo", "/", "/foo/bar" }) {
        final ResourceResolver resolver = Mockito.mock(ResourceResolver.class);
        final ResourceProvider<?> p = Mockito.mock(ResourceProvider.class);
        Mockito.when(p.getResource(Mockito.any(ResolveContext.class), Mockito.startsWith(path), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(new TestResource(resolver));
        ++counter;
        ResourceProviderHandler h = createRPHandler(p, "rp" + counter, counter, path);
        providers.add(h);
        this.providersBasedResolver = null;
        {
            final Resource r = getResource(path);
            assertEqualsResolver(resolver, r);
            assertFalse(r instanceof SyntheticResource);
        }
        providers.remove(h);
        this.providersBasedResolver = null;
        {
            final Resource r = getResource(path);
            // If our provider is indeed gone, we should get one of the following conditions
            if (r == null) {
            //fine
            } else if (!p.equals(r.getResourceResolver())) {
            //fine
            } else {
                fail("Expecting inactive provider after removing it for " + path);
            }
        }
    }
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) ResourceContext(org.apache.sling.spi.resource.provider.ResourceContext) ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) AbstractResource(org.apache.sling.api.resource.AbstractResource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) 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