Package org.jboss.dna.graph.request

Examples of org.jboss.dna.graph.request.CreateNodeRequest


                return and(name, values);
            }

            public Location getLocation() {
                Location parentLoc = Location.create(parent);
                CreateNodeRequest request = requests.createNode(parentLoc, workspaceName, childName, this.properties.iterator());
                return request.getActualLocationOfNode();
            }

            public Node getNode() {
                Location parentLoc = Location.create(parent);
                CreateNodeRequest request = requests.createNode(parentLoc, workspaceName, childName, this.properties.iterator());
                return getNodeAt(request.getActualLocationOfNode());
            }

            public Graph and() {
                requests.createNode(Location.create(parent), workspaceName, childName, this.properties.iterator());
                return Graph.this;
View Full Code Here


    public void assertCreateNode( Iterator<Request> iterator,
                                  String path,
                                  String... properties ) {
        Request nextCommand = iterator.next();
        assertThat(nextCommand, is(instanceOf(CreateNodeRequest.class)));
        CreateNodeRequest createNode = (CreateNodeRequest)nextCommand;
        Path expectedPath = context.getValueFactories().getPathFactory().create(path);
        Path parentPath = createNode.under().getPath();
        assertThat(parentPath, is(expectedPath.getParent()));
        assertThat(createNode.named(), is(expectedPath.getLastSegment().getName()));

        if (properties.length > 0) {
            Map<Name, Property> propertiesByName = new HashMap<Name, Property>();
            for (Property prop : createNode.properties()) {
                propertiesByName.put(prop.getName(), prop);
            }
            for (String propertyStr : properties) {
                if (propertyStr == "any properties") {
                    propertiesByName.clear();
View Full Code Here

                               String... properties ) {
        // Create the expected path ...
        PathFactory factory = context.getValueFactories().getPathFactory();
        Path expectedPath = parentPath != null ? factory.create(parentPath, path) : factory.create("/" + path);
        // Now get the next request and compare the expected and actual ...
        CreateNodeRequest request = requests.remove();
        Path parentPath = request.under().getPath();
        assertThat(parentPath, is(expectedPath.getParent()));
        assertThat(request.named(), is(expectedPath.getLastSegment().getName()));

        if (properties.length != 0) {
            // Create the list of properties ...
            Map<Name, Property> expectedProperties = new HashMap<Name, Property>();
            for (String propertyString : properties) {
                String[] strings = propertyString.split("=");
                if (strings.length < 2) continue;
                Name name = context.getValueFactories().getNameFactory().create(strings[0]);
                Object[] values = new Object[strings.length - 1];
                for (int i = 1; i != strings.length; ++i) {
                    values[i - 1] = strings[i];
                }
                Property property = context.getPropertyFactory().create(name, values);
                expectedProperties.put(name, property);
            }

            for (Property actual : request.properties()) {
                Property expected = expectedProperties.remove(actual.getName());
                assertThat("unexpected property: " + actual, expected, is(notNullValue()));
                assertThat(actual, is(expected));
            }
            if (!expectedProperties.isEmpty()) {
                StringBuilder msg = new StringBuilder("missing actual properties: ");
                boolean isFirst = true;
                for (Property expected : expectedProperties.values()) {
                    if (!isFirst) msg.append(", ");
                    else isFirst = false;
                    msg.append(expected.getName());
                }
                msg.append(" on node ").append(request.under());
                System.out.println("Found properties: " + request.properties());
                assertThat(msg.toString(), expectedProperties.isEmpty(), is(true));
            }
        }
    }
View Full Code Here

            }
            Property property = context.getPropertyFactory().create(name, values);
            expectedProperties.put(name, property);
        }

        CreateNodeRequest propertyRequest = requests.remove();
        Path parentPath = propertyRequest.under().getPath();
        assertThat(parentPath, is(expectedPath.getParent()));
        assertThat(propertyRequest.named(), is(expectedPath.getLastSegment().getName()));

        for (Property actual : propertyRequest.properties()) {
            Property expected = expectedProperties.remove(actual.getName());
            assertThat("unexpected property: " + actual, expected, is(notNullValue()));
            assertThat(actual, is(expected));
        }
        if (!expectedProperties.isEmpty()) {
            StringBuilder msg = new StringBuilder("missing actual properties: ");
            boolean isFirst = true;
            for (Property expected : expectedProperties.values()) {
                if (!isFirst) msg.append(", ");
                else isFirst = false;
                msg.append(expected.getName());
            }
            msg.append(" on node ").append(propertyRequest.under());
            System.out.println("Found properties: " + propertyRequest.properties());
            assertThat(msg.toString(), expectedProperties.isEmpty(), is(true));
        }
    }
View Full Code Here

        public void create( Path path,
                            List<Property> properties ) {
            assert path != null;
            Path parent = path.getParent();
            Name child = path.getLastSegment().getName();
            requests.add(new CreateNodeRequest(Location.create(parent), workspace, child, properties));
        }
View Full Code Here

                            final Property... additionalProperties ) {
            Path parent = path.getParent();
            Name child = path.getLastSegment().getName();
            Location location = Location.create(parent);
            if (firstProperty == null) {
                requests.add(new CreateNodeRequest(location, workspace, child));
            } else {
                if (additionalProperties == null || additionalProperties.length == 0) {
                    requests.add(new CreateNodeRequest(location, workspace, child, firstProperty));
                } else {
                    Iterator<Property> iter = new Iterator<Property>() {
                        private int index = -1;

                        public boolean hasNext() {
                            return index < additionalProperties.length;
                        }

                        public Property next() {
                            if (index == -1) {
                                ++index;
                                return firstProperty;
                            }
                            return additionalProperties[index++];
                        }

                        public void remove() {
                            throw new UnsupportedOperationException();
                        }
                    };
                    requests.add(new CreateNodeRequest(location, workspace, child, iter));
                }
            }
        }
View Full Code Here

                                              String child,
                                              Property... properties ) {
        Name name = context.getValueFactories().getNameFactory().create(child);
        Request request = executedRequests.poll();
        assertThat(request, is(instanceOf(CreateNodeRequest.class)));
        CreateNodeRequest create = (CreateNodeRequest)request;
        assertThat(create.under(), is(parent));
        assertThat(create.named(), is(name));
        assertThat(create.properties(), hasItems(properties));
    }
View Full Code Here

TOP

Related Classes of org.jboss.dna.graph.request.CreateNodeRequest

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.