Package org.apache.sling.commons.testing.jcr

Examples of org.apache.sling.commons.testing.jcr.MockNode


            }
        };
       
        final String path = "/foo/node";
       
        final MockNode mn = new MockNode(path);
        try {
            mn.setProperty("title", "test.title");
            mn.setProperty("desc", "test.desc");
        } catch(RepositoryException ignored) {
            // ignore, cannot happen with this mock class
        }
       
        final MockResource mr = new MockResource(null, path, null) {
View Full Code Here


        assertTrue("At least " + expectedTests + " have been run", counter >= expectedTests);
    }
   
    public void testTitleBuilding() throws RepositoryException {
        final String path = "/foo/title";
        final MockNode n = new MockNode(path);
        final MockResource r = new MockResource(null, path, null);
       
        assertEquals("foo/title", generator.getTitle(r, n));
       
        n.setProperty("description", "the description");
        assertEquals("the description", generator.getTitle(r, n));
       
        n.setProperty("name", "the name");
        assertEquals("the name", generator.getTitle(r, n));
       
        n.setProperty("title", "the title");
        assertEquals("the title", generator.getTitle(r, n));
    }
View Full Code Here

        writer.dump(n, sw, 0);
        return sw.toString();
    }
   
    public void testBasicJson() throws RepositoryException, JSONException {
        final Node n = new MockNode("/test");
        n.setProperty("testprop", "1234");
        assertEquals("{\"testprop\":\"1234\"}",getJson(n, 0));
    }
View Full Code Here

        n.setProperty("testprop", "1234");
        assertEquals("{\"testprop\":\"1234\"}",getJson(n, 0));
    }
   
    public void testMultivalued() throws RepositoryException, JSONException {
        final Node n = new MockNode("/test");
        final String [] values = { "1234", "yes" };
        n.setProperty("testprop", values);
        assertEquals("{\"testprop\":[\"1234\",\"yes\"]}",getJson(n, 0));
    }
View Full Code Here

        }
    }

    public void testSingle() throws RepositoryException {
        String path = "/parent/path/node";
        Node node = new MockNode(path);
        NodeIterator ni = new MockNodeIterator(new Node[] { node });
        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null);

        assertTrue(ri.hasNext());
        Resource res = ri.next();
        assertEquals(path, res.getPath());
        assertEquals(node.getPrimaryNodeType().getName(), res.getResourceType());

        assertFalse(ri.hasNext());

        try {
            ri.next();
View Full Code Here

    public void testMulti() throws RepositoryException {
        int numNodes = 10;
        String pathBase = "/parent/path/node/";
        Node[] nodes = new Node[numNodes];
        for (int i=0; i < nodes.length; i++) {
            nodes[i] = new MockNode(pathBase + i, "some:type" + i);
        }
        NodeIterator ni = new MockNodeIterator(nodes);
        JcrNodeResourceIterator ri = new JcrNodeResourceIterator(null, ni, null);

        for (int i=0; i < nodes.length; i++) {
View Full Code Here

        writer.dump(n, sw, 0);
        return sw.toString();
    }
   
    public void testBasicJson() throws RepositoryException, JSONException {
        final Node n = new MockNode("/test");
        n.setProperty("testprop", "1234");
        assertEquals("{\"testprop\":\"1234\"}",getJson(n, 0));
    }
View Full Code Here

        n.setProperty("testprop", "1234");
        assertEquals("{\"testprop\":\"1234\"}",getJson(n, 0));
    }
   
    public void testMultivalued() throws RepositoryException, JSONException {
        final Node n = new MockNode("/test");
        final String [] values = { "1234", "yes" };
        n.setProperty("testprop", values);
        assertEquals("{\"testprop\":[\"1234\",\"yes\"]}",getJson(n, 0));
    }
View Full Code Here

    /**
     * See <a href="https://issues.apache.org/jira/browse/SLING-924">SLING-924</a>
     */
    public void testOutputIterator() throws JSONException, RepositoryException {
        MockNode node1 = new MockNode("/node1");
        MockNode node2 = new MockNode("/node2");
        node1.addNode("node3");
        node1.setProperty("name", "node1");
        node2.setProperty("name", "node2");
        final NodeIterator it = new MockNodeIterator(new Node[]{node1, node2});
        final StringWriter sw = new StringWriter();
        writer.dump(it, sw);
        Pattern testPattern = Pattern.compile("\\{(.[^\\}]*)\\}"); // Pattern to look for a {...}
        Matcher matcher = testPattern.matcher(sw.toString());
View Full Code Here

* @since Apr 17, 2009 6:57:04 PM
*/
public class JsonJcrNodeTest extends TestCase {

    public void testJcrJsonObject() throws RepositoryException, JSONException {
        MockNode node = new MockNode("/node1");
        node.setProperty("prop1", "value1");
        node.setProperty("prop2", "value2");
        Set<String> ignoredProperties = new HashSet<String>();
        ignoredProperties.add("prop2");
        JsonJcrNode json = new JsonJcrNode(node, ignoredProperties);
        assertTrue("Did not create property", json.has("prop1"));
        assertFalse("Created ignored property", json.has("prop2"));
View Full Code Here

TOP

Related Classes of org.apache.sling.commons.testing.jcr.MockNode

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.