Package org.apache.sling.api.resource

Examples of org.apache.sling.api.resource.Resource


    @Before
    public final void setUp() throws IOException {
        this.resourceResolver = newResourceResolver();

        // prepare some test data using Sling CRUD API
        Resource rootNode = getTestRootResource();

        Map<String, Object> props = new HashMap<String, Object>();
        props.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
        props.put("stringProp", STRING_VALUE);
        props.put("stringArrayProp", STRING_ARRAY_VALUE);
        props.put("integerProp", INTEGER_VALUE);
        props.put("doubleProp", DOUBLE_VALUE);
        props.put("booleanProp", BOOLEAN_VALUE);
        props.put("dateProp", DATE_VALUE);
        props.put("calendarProp", CALENDAR_VALUE);
        props.put("binaryProp", new ByteArrayInputStream(BINARY_VALUE));
        Resource node1 = this.resourceResolver.create(rootNode, "node1", props);

        this.resourceResolver.create(node1, "node11", ValueMap.EMPTY);
        this.resourceResolver.create(node1, "node12", ValueMap.EMPTY);

        this.resourceResolver.commit();
View Full Code Here


     */
    private Resource getTestRootResource() throws PersistenceException {
        if (this.testRoot == null) {
            Map<String, Object> props = new HashMap<String, Object>();
            props.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
            final Resource root = this.resourceResolver.getResource("/");
            if (getResourceResolverType() == ResourceResolverType.JCR_JACKRABBIT) {
                final Resource classRoot = this.resourceResolver.create(root, getClass().getSimpleName(), props);
                this.testRoot = this.resourceResolver.create(classRoot, System.currentTimeMillis() + "_"
                        + (rootNodeCounter++), props);
            } else {
                this.testRoot = this.resourceResolver.create(root, "test", props);
            }
View Full Code Here

        return this.testRoot;
    }

    @Test
    public void testSimpleProperties() throws IOException {
        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
        assertNotNull(resource1);
        assertEquals("node1", resource1.getName());

        ValueMap props = ResourceUtil.getValueMap(resource1);
        assertEquals(STRING_VALUE, props.get("stringProp", String.class));
        assertArrayEquals(STRING_ARRAY_VALUE, props.get("stringArrayProp", String[].class));
        assertEquals((Integer) INTEGER_VALUE, props.get("integerProp", Integer.class));
View Full Code Here

        assertEquals(BOOLEAN_VALUE, props.get("booleanProp", Boolean.class));
    }

    @Test
    public void testDateProperty() throws IOException {
        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
        ValueMap props = ResourceUtil.getValueMap(resource1);
        // TODO: enable this test when JCR resource implementation supports
        // writing Date objects (SLING-3846)
        if (getResourceResolverType() != ResourceResolverType.JCR_MOCK
                && getResourceResolverType() != ResourceResolverType.JCR_JACKRABBIT) {
View Full Code Here

        }
    }

    @Test
    public void testDatePropertyToCalendar() throws IOException {
        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
        ValueMap props = ResourceUtil.getValueMap(resource1);
        // TODO: enable this test when JCR resource implementation supports
        // writing Date objects (SLING-3846)
        if (getResourceResolverType() != ResourceResolverType.JCR_MOCK
                && getResourceResolverType() != ResourceResolverType.JCR_JACKRABBIT) {
View Full Code Here

        }
    }

    @Test
    public void testCalendarProperty() throws IOException {
        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
        ValueMap props = ResourceUtil.getValueMap(resource1);
        assertEquals(CALENDAR_VALUE.getTime(), props.get("calendarProp", Calendar.class).getTime());
    }
View Full Code Here

        assertEquals(CALENDAR_VALUE.getTime(), props.get("calendarProp", Calendar.class).getTime());
    }

    @Test
    public void testCalendarPropertyToDate() throws IOException {
        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");
        ValueMap props = ResourceUtil.getValueMap(resource1);
        Date dateValue = props.get("calendarProp", Date.class);
        assertNotNull(dateValue);
        assertEquals(CALENDAR_VALUE.getTime(), dateValue);
    }
View Full Code Here

        assertEquals(CALENDAR_VALUE.getTime(), dateValue);
    }

    @Test
    public void testListChildren() throws IOException {
        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");

        List<Resource> children = ImmutableList.copyOf(resource1.listChildren());
        assertEquals(2, children.size());
        assertEquals("node11", children.get(0).getName());
        assertEquals("node12", children.get(1).getName());
    }
View Full Code Here

        assertEquals("node12", children.get(1).getName());
    }

    @Test
    public void testBinaryData() throws IOException {
        Resource resource1 = this.resourceResolver.getResource(getTestRootResource().getPath() + "/node1");

        Resource binaryPropResource = resource1.getChild("binaryProp");
        InputStream is = binaryPropResource.adaptTo(InputStream.class);
        byte[] dataFromResource = IOUtils.toByteArray(is);
        is.close();
        assertArrayEquals(BINARY_VALUE, dataFromResource);

        // read second time to ensure not the original input stream was returned
View Full Code Here

        assertArrayEquals(BINARY_VALUE, dataFromResource2);
    }

    @Test
    public void testPrimaryTypeResourceType() throws PersistenceException {
        Resource resource = this.resourceResolver.getResource(getTestRootResource().getPath());
        assertEquals(JcrConstants.NT_UNSTRUCTURED, resource.getResourceType());
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.api.resource.Resource

Copyright © 2018 www.massapicom. 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.