Package org.apache.sling.api.resource

Examples of org.apache.sling.api.resource.Resource.adaptTo()


        final Resource firstGrandChild = mock(Resource.class);
        when(firstGrandChild.adaptTo(ValueMap.class)).thenReturn(firstGrandChildMap);
        when(firstGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel());

        final Resource secondGrandChild = mock(Resource.class);
        when(secondGrandChild.adaptTo(ValueMap.class)).thenReturn(secondGrandChildMap);
        when(secondGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel());

        Resource secondChild = mock(Resource.class);
        when(secondChild.listChildren()).thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator());
View Full Code Here


            throws RepositoryException {

        ApplyToIterator iterator = new ApplyToIterator(baseResource, paths);
        while (iterator.hasNext()) {
            Resource resource = iterator.next();
            Authorizable item = resource.adaptTo(Authorizable.class);
            if (item != null) {
                item.remove();
                changes.add(Modification.onDeleted(resource.getPath()));
            }
        }
View Full Code Here

        when(firstGrandChild.adaptTo(ValueMap.class)).thenReturn(firstGrandChildMap);
        when(firstGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel());

        final Resource secondGrandChild = mock(Resource.class);
        when(secondGrandChild.adaptTo(ValueMap.class)).thenReturn(secondGrandChildMap);
        when(secondGrandChild.adaptTo(ChildModel.class)).thenAnswer(new AdaptToChildModel());

        Resource secondChild = mock(Resource.class);
        when(secondChild.listChildren()).thenReturn(Arrays.asList(firstGrandChild, secondGrandChild).iterator());

        Resource emptyChild = mock(Resource.class);
View Full Code Here

            // if we can't find the members then it may be resolvable as a resource.
        }
        if ( memberAuthorizable == null ) {
            Resource res = resolver.getResource(baseResource, member);
            if (res != null) {
                memberAuthorizable = res.adaptTo(Authorizable.class);
            }
        }
        return memberAuthorizable;
    }
View Full Code Here

        createdNode.setProperty("testProperty", value);
        session.save();

        Resource resource = resolver.getResource(createdNode.getPath());

        SlingPropertyAnnotationTestModel model = resource.adaptTo(SlingPropertyAnnotationTestModel.class);

        assertNotNull("Model is null", model);
        assertEquals("Test Property is not set correctly", value, model.getTestProperty());
    } finally {
        if (createdNode != null) {
View Full Code Here

    @Test
    public void testNonModelClass() {
        Map<String, Object> emptyMap = Collections.<String, Object> emptyMap();

        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(emptyMap));

        assertNull(factory.getAdapter(res, NonModel.class));
    }

    @Test(expected = InvalidModelException.class)
View Full Code Here

    @Test(expected = InvalidModelException.class)
    public void testNonModelClassException() {
        Map<String, Object> emptyMap = Collections.<String, Object> emptyMap();

        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(emptyMap));

        assertNull(factory.createModel(res, NonModel.class));
    }

    @Test
View Full Code Here

    @Test
    public void testWrongAdaptableClass() {
        Map<String, Object> emptyMap = Collections.<String, Object> emptyMap();

        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(emptyMap));

        assertNull(factory.getAdapter(res, RequestModel.class));
    }

    @Test(expected = InvalidAdaptableException.class)
View Full Code Here

    @Test(expected = InvalidAdaptableException.class)
    public void testWrongAdaptableClassException() {
        Map<String, Object> emptyMap = Collections.<String, Object> emptyMap();

        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(emptyMap));

        assertNull(factory.createModel(res, RequestModel.class));
    }

    private class NonModel {
View Full Code Here

        map.put("first", "first-value");
        map.put("second", "second-value");
        ValueMap vm = new ValueMapDecorator(map);

        Resource res = mock(Resource.class);
        when(res.adaptTo(ValueMap.class)).thenReturn(vm);
        when(request.getResource()).thenReturn(res);

        InjectorSpecificAnnotationModel model = factory.getAdapter(request, InjectorSpecificAnnotationModel.class);
        assertNotNull("Could not instanciate model", model);
        assertEquals("first-value", model.getFirst());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.