Package org.jboss.dna.graph

Examples of org.jboss.dna.graph.Node


        return Location.create(uuid);
    }

    protected UUID getRootNodeUuid() {
        if (rootUuid == null) {
            Node root = graph.getNodeAt("/");
            rootLocation = root.getLocation();
            rootUuid = rootLocation.getUuid();
            if (rootUuid == null) {
                Property uuid = root.getProperty(DnaLexicon.UUID);
                if (uuid != null) {
                    rootUuid = context.getValueFactories().getUuidFactory().create(uuid.getFirstValue());
                }
            }
            if (rootUuid == null) {
                Property uuid = root.getProperty(JcrLexicon.UUID);
                if (uuid != null) {
                    rootUuid = context.getValueFactories().getUuidFactory().create(uuid.getFirstValue());
                }
            }
        }
View Full Code Here


     * @param location the location; may not be null
     * @return the node that was read
     */
    public Node readNodeThoroughly( Location location ) {
        assertThat(location, is(notNullValue()));
        Node result = null;
        if (location.hasPath() && location.hasIdProperties()) {
            // Read the node by the full location ...
            result = graph.getNodeAt(location);

            // Read the node by the path ...
            Node resultByPath = graph.getNodeAt(location.getPath());
            assertSameNode(resultByPath, result);

            // Read the node by identification properties ...
            if (location.hasIdProperties()) {
                Node resultByIdProps = graph.getNodeAt(location.getIdProperties());
                assertSameNode(resultByIdProps, result);
            }

            // Check the result has the correct location ...
            assertThat("The node that was read doesn't have the expected location", result.getLocation(), is(location));
View Full Code Here

        // Iterate over each subgraph. Note that because each location should have a path, the path can be used
        // to ensure the structure matches.
        Iterator<SubgraphNode> iter1 = subgraph1.iterator();
        Iterator<SubgraphNode> iter2 = subgraph2.iterator();
        while (iter1.hasNext() && iter2.hasNext()) {
            Node node1 = iter1.next();
            Node node2 = iter2.next();

            assertThat(node1, is(notNullValue()));
            assertThat(node2, is(notNullValue()));

            // Each node should have equivalent paths ..
            assertThat(node1.getLocation().hasPath(), is(true));
            assertThat(node2.getLocation().hasPath(), is(true));
            if (pathsShouldMatch) {
                assertThat(node1.getLocation().getPath(), is(node2.getLocation().getPath()));
            } else {
                Path relativeNode1 = node1.getLocation().getPath().relativeTo(rootPath1);
                Path relativeNode2 = node2.getLocation().getPath().relativeTo(rootPath2);
                assertThat(relativeNode1, is(relativeNode2));
            }

            // Each node should have the same Identification properties ...
            if (idPropertiesShouldMatch) {
                assertThat(node1.getLocation().getIdProperties(), is(node2.getLocation().getIdProperties()));
            }

            // Do not compare the workspace name.

            // Each node should have the same properties (excluding any identification properties) ...
            Map<Name, Property> properties1 = new HashMap<Name, Property>(node1.getPropertiesByName());
            Map<Name, Property> properties2 = new HashMap<Name, Property>(node2.getPropertiesByName());
            if (!idPropertiesShouldMatch) {
                for (Property idProperty : node1.getLocation().getIdProperties()) {
                    properties1.remove(idProperty.getName());
                }
                for (Property idProperty : node2.getLocation().getIdProperties()) {
                    properties2.remove(idProperty.getName());
                }
            }
            assertThat(properties1, is(properties2));

            // Each node should have the same children. We can check this, tho this will be enforced when comparing paths ...
            assertThat(node1.getChildrenSegments(), is(node2.getChildrenSegments()));
        }

        // There should be no more nodes in either iterator ...
        assertThat(iter1.hasNext(), is(false));
        assertThat(iter2.hasNext(), is(false));
View Full Code Here

    @Test
    public void shouldSetPropertyOnRootNode() {
        graph.set("propA").to("valueA").on("/");
        // Now look up the node ...
        Node root = graph.getNodeAt("/");
        assertThat(root, is(notNullValue()));
        assertThat(root, hasProperty(DnaLexicon.UUID, getRootNodeUuid()));
        assertThat(root, hasProperty("propA", "valueA"));
    }
View Full Code Here

    @Test
    public void shouldAddChildUnderRootNode() {
        graph.batch().create("/a").with("propB", "valueB").and("propC", "valueC").and().execute();
        // Now look up the root node ...
        Node root = graph.getNodeAt("/");
        assertThat(root, is(notNullValue()));
        assertThat(root, hasProperty(DnaLexicon.UUID, getRootNodeUuid()));
        assertThat(root.getChildren(), hasChild(segment("a")));

        // Now look up node A ...
        Node nodeA = graph.getNodeAt("/a");
        assertThat(nodeA, is(notNullValue()));
        assertThat(nodeA, hasProperty("propB", "valueB"));
        assertThat(nodeA, hasProperty("propC", "valueC"));
        assertThat(nodeA.getChildren(), isEmpty());
    }
View Full Code Here

             .with("propD", "valueD")
             .and("propE", "valueE")
             .and()
             .execute();
        // Now look up the root node ...
        Node root = graph.getNodeAt("/");
        assertThat(root, is(notNullValue()));
        assertThat(root, hasProperty(DnaLexicon.UUID, getRootNodeUuid()));
        assertThat(root, hasProperty("propA", "valueA"));
        assertThat(root.getChildren(), hasChildren(segment("a"), segment("b")));

        // Now look up node A ...
        Node nodeA = graph.getNodeAt("/a");
        assertThat(nodeA, is(notNullValue()));
        assertThat(nodeA, hasProperty("propB", "valueB"));
        assertThat(nodeA, hasProperty("propC", "valueC"));
        assertThat(nodeA.getChildren(), isEmpty());

        // Now look up node B ...
        Node nodeB = graph.getNodeAt("/b");
        assertThat(nodeB, is(notNullValue()));
        assertThat(nodeB, hasProperty("propD", "valueD"));
        assertThat(nodeB, hasProperty("propE", "valueE"));
        assertThat(nodeB.getChildren(), isEmpty());

        // Get the subgraph ...
        Subgraph subgraph = graph.getSubgraphOfDepth(3).at("/");
        assertThat(subgraph, is(notNullValue()));
        assertThat(subgraph.getNode("."), hasProperty(DnaLexicon.UUID, getRootNodeUuid()));
View Full Code Here

        for (int i = 0; i != 100; ++i) {
            create = create.with("property" + i, "value" + i);
        }
        create.and().execute();
        // Now look up all the properties ...
        Node nodeA = graph.getNodeAt("/a");
        assertThat(nodeA, is(notNullValue()));
        for (int i = 0; i != 100; ++i) {
            assertThat(nodeA, hasProperty("property" + i, "value" + i));
        }
        assertThat(nodeA.getChildren(), isEmpty());
    }
View Full Code Here

            create = create.with("property" + i, "value" + i);
        }
        create.and().execute();

        // Now look up all the properties ...
        Node nodeA = graph.getNodeAt("/a");
        assertThat(nodeA, is(notNullValue()));
        for (int i = 0; i != 10; ++i) {
            assertThat(nodeA, hasProperty("property" + i, "value" + i));
        }
        assertThat(nodeA.getChildren(), isEmpty());

        // Now, remove some of the properties and add some others ...
        Graph.Batch batch = graph.batch();
        batch.remove("property0", "property1").on("/a");
        batch.set("property6").to("new valid 6").on("/a");
        batch.execute();

        // Re-read the properties ...
        nodeA = graph.getNodeAt("/a");
        assertThat(nodeA, is(notNullValue()));
        for (int i = 0; i != 10; ++i) {
            if (i == 0 || i == 1) {
                continue;
            } else if (i == 6) {
                assertThat(nodeA, hasProperty("property" + i, "new valid 6"));
            } else {
                assertThat(nodeA, hasProperty("property" + i, "value" + i));
            }
        }
        assertThat(nodeA.getChildren(), isEmpty());

    }
View Full Code Here

        create = create.with("largeProperty1", validLargeValues[0]);
        create = create.with("largeProperty2", validLargeValues[1]);
        create.and().execute();

        // Now look up all the properties ...
        Node nodeA = graph.getNodeAt("/a");
        assertThat(nodeA, is(notNullValue()));
        for (int i = 0; i != 100; ++i) {
            assertThat(nodeA, hasProperty("property" + i, "value" + i));
        }
        assertThat(nodeA, hasProperty("largeProperty1", validLargeValues[0]));
        assertThat(nodeA, hasProperty("largeProperty2", validLargeValues[1]));
        assertThat(nodeA.getChildren(), isEmpty());

        // Now, remove some of the properties and add some others ...
        Graph.Batch batch = graph.batch();
        batch.remove("largeProperty1", "property0", "property1").on("/a");
        batch.set("property50").to("new valid 50").on("/a");
        batch.set("largeProperty3").to(validLargeValues[2]).on("/a");
        batch.execute();

        // Re-read the properties ...
        nodeA = graph.getNodeAt("/a");
        assertThat(nodeA, is(notNullValue()));
        for (int i = 0; i != 100; ++i) {
            if (i == 0 || i == 1) {
                continue;
            } else if (i == 50) {
                assertThat(nodeA, hasProperty("property" + i, "new valid 50"));
            } else {
                assertThat(nodeA, hasProperty("property" + i, "value" + i));
            }
        }
        assertThat(nodeA, hasProperty("largeProperty2", validLargeValues[1]));
        assertThat(nodeA, hasProperty("largeProperty3", validLargeValues[2]));
        assertThat(nodeA.getChildren(), isEmpty());

    }
View Full Code Here

    @Test
    public void shouldReturnRootNodeInMirrorProjection() {
        // Get the root node of the mirror projection using the actual graph ...
        Graph mirrorGraph = graphFor(mirrorSourceName, mirrorWorkspaceName);
        Node mirrorRoot = mirrorGraph.getNodeAt("/");
        Location mirrorRootLocation = mirrorRoot.getLocation();
        assertThat(mirrorRootLocation.hasIdProperties(), is(true));
        assertThat(mirrorRootLocation.getUuid(), is(notNullValue()));

        // Get the same node through the federation source ...
        Node fedRoot = federated.getNodeAt("/");
        Location fedRootLocation = fedRoot.getLocation();
        assertThat(fedRootLocation.hasIdProperties(), is(true));
        assertThat(fedRootLocation.getUuid(), is(notNullValue()));

        // The UUIDs of the nodes must be the same ...
        assertThat(fedRootLocation.getUuid(), is(mirrorRootLocation.getUuid()));
View Full Code Here

TOP

Related Classes of org.jboss.dna.graph.Node

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.