Package org.metagrid.gatekeeper.node

Examples of org.metagrid.gatekeeper.node.Node


                )
            );

        log.debug("----------");
        log.debug("URI [urn://orange/000]");
        Node node = reader.read(
            resources.get(
                new URI("urn://orange/000")
                ).reader()
            );
        //
        // Check the OrangeNode weight.
        assertEquals(
            "0",
            node.properties().get(
                OrangeNode.WEIGHT_PROPERTY_URI
                ).value()
            );

        //
        // Parse the next OrangeNode ...
        log.debug("----------");
        log.debug("URI [urn://orange/001]");
        node = reader.read(
            resources.get(
                new URI("urn://orange/001")
                ).reader()
            );
        //
        // Check the OrangeNode weight.
        assertEquals(
            "1",
            node.properties().get(
                OrangeNode.WEIGHT_PROPERTY_URI
                ).value()
            );

        //
        // Parse the first AppleBean ...
        log.debug("----------");
        log.debug("URI [urn://apple/000]");
        node = reader.read(
            resources.get(
                new URI("urn://apple/000")
                ).reader()
            );
        //
        // Check the AppleNode weight.
        assertEquals(
            "2",
            node.properties().get(
                AppleNode.WEIGHT_PROPERTY_URI
                ).value()
            );

        //
        // Parse the next AppleNode ...
        log.debug("----------");
        log.debug("URI [urn://apple/001]");
        node = reader.read(
            resources.get(
                new URI("urn://apple/001")
                ).reader()
            );
        //
        // Check the AppleNode weight.
        assertEquals(
            "3",
            node.properties().get(
                AppleNode.WEIGHT_PROPERTY_URI
                ).value()
            );
        //
        // Check we can set the modified date.
        node.properties().set(
            FruitNode.MODIFIED_PROPERTY_URI,
            "2008-11-29T06:25:50.379+0000"
            );

        //
        // Check we can't set the created date.
// This is the only test for ReadOnlyProperty at the moment.
        final Node frog = node ;
        assertThrows(
            PropertyException.class,
            new TestBlock()
                {
                public void run()
                    {
                    frog.properties().set(
                        FruitNode.CREATED_PROPERTY_URI,
                        "2008-11-29T06:25:50.379+0000"
                        );
                    }
                }
View Full Code Here


        NodeService<Node> client = new HttpConnectionClientImpl<Node>(
            reader,
            writer
            );
       
        Node selected = client.select(
            new URI(
                "http://data.metagrid.co.uk/test/0001"
                )
            );
View Full Code Here

    throws Exception
        {

        //
        // Create our node.
        final Node inner = new SimpleNode(
            new URI("urn:node.000"),
            new URI("urn:type.000")
            );

        //
        // Check we can set the secret property.
        assertEquals(
            "egertvsg",
            inner.properties().set(
                new URI("urn:test.secret"),
                "egertvsg"
                ).value()
            );

        //
        // Check we can get the secret property.
        assertEquals(
            "egertvsg",
            inner.properties().get(
                new URI("urn:test.secret")
                ).value()
            );

        //
        // Check we can set the test properties.
        assertEquals(
            "green",
            inner.properties().set(
                new URI("urn:test.frog"),
                "green"
                ).value()
            );

        //
        // Check we can get the test property.
        assertEquals(
            "green",
            inner.properties().get(
                new URI("urn:test.frog")
                ).value()
            );

        //
        // Create our protector.
        SimpleProtector protector = new SimpleProtector(
            inner.ident()
            );

        //
        // Protect the node.
        final Node outer = ProtectedNode.wrap(
            protector,
            inner
            );

        //
        // Check we can't get the test properties.
        assertThrows(
            ProtectedException.class,
            new TestBlock()
                {
                public void run()
                    throws Exception
                    {
                    outer.properties().get(
                        new URI("urn:test.frog")
                        );
                    }
                }
            );

        assertThrows(
            ProtectedException.class,
            new TestBlock()
                {
                public void run()
                    throws Exception
                    {
                    outer.properties().get(
                        new URI("urn:test.toad")
                        );
                    }
                }
            );

        //
        // Allow select on frog.
        protector.add(
            new URI("urn:test.frog"),
            ProtectedProperty.SELECT_PROPERTY_ACTION,
            SimpleProtector.Permission.ALLOW
            );

        //
        // Check we can get the frog property.
        assertEquals(
            "green",
            outer.properties().get(
                new URI("urn:test.frog")
                ).value()
            );

        //
        // Check we still can't get the other property.
        assertThrows(
            ProtectedException.class,
            new TestBlock()
                {
                public void run()
                    throws Exception
                    {
                    try {
                        outer.properties().get(
                            new URI("urn:test.toad")
                            );
                        }
                    catch (ProtectedException ouch)
                        {
                        assertEquals(
                            new URI("urn:test.toad"),
                            ouch.protector().target()
                            );
                        assertEquals(
                            outer.ident(),
                            ouch.protector().parent().target()
                            );
                        throw ouch ;
                        }
                    }
                }
            );

        //
        // Allow select and update on toad.
        protector.add(
            new URI("urn:test.toad"),
            ProtectedProperty.SELECT_PROPERTY_ACTION,
            SimpleProtector.Permission.ALLOW
            );
        protector.add(
            new URI("urn:test.toad"),
            ProtectedProperty.MODIFY_PROPERTY_ACTION,
            SimpleProtector.Permission.ALLOW
            );

        //
        // Check we can set the toad property.
        assertEquals(
            "brown",
            outer.properties().set(
                new URI("urn:test.toad"),
                "brown"
                ).value()
            );

//
// Count the inner properties.
for (Property p : inner.properties())
    {
    log.debug("Inner [" + p.type() + "][" + p.value() + "]");
    }

//
// Count the outer properties.
for (Property p : outer.properties())
    {
    log.debug("Outer [" + p.type() + "][" + p.value() + "]");
    }

        //
        // Check we get a null property.
        assertNull(
            inner.properties().get(
                new URI("urn:test.newt")
                )
            );

        //
        // Check we can't an unknown property.
        assertThrows(
            ProtectedException.class,
            new TestBlock()
                {
                public void run()
                    throws Exception
                    {
                    try {
                        assertNull(
                            outer.properties().get(
                                new URI("urn:test.newt")
                                )
                            );
                        }
                    catch (ProtectedException ouch)
                        {
                        assertEquals(
                            new URI("urn:test.newt"),
                            ouch.protector().target()
                            );
                        assertEquals(
                            outer.ident(),
                            ouch.protector().parent().target()
                            );
                        throw ouch ;
                        }
                    }
                }
            );

        //
        // Allow select on newt.
        protector.add(
            new URI("urn:test.newt"),
            ProtectedProperty.SELECT_PROPERTY_ACTION,
            SimpleProtector.Permission.ALLOW
            );

        //
        // Check we get a null property.
        assertNull(
            outer.properties().get(
                new URI("urn:test.newt")
                )
            );

/*
 
View Full Code Here

        final XMLNodeReader<Node> reader = new XMLNodeReaderImpl<Node>(
            new SimpleNodeFactory()
            );
        //
        // Check we can parse the node XML.
        Node node = reader.read(
            new StringResource(
                "<node xmlns='urn:metagrid' ident='urn:node/001' type='urn:metagrid/node/type/node'>"
              + "  <properties>"
              + "    <property type='urn:metagrid/property/type/frog'>property.frog</property>"
              + "    <property type='urn:metagrid/property/type/toad'>property.toad</property>"
              + "  </properties>"
              + "</node>"
                ).reader()
            );
        //
        // Check the node properties.
        assertEquals(
            "property.frog",
            node.properties().get(
                new URI(
                    "urn:metagrid/property/type/frog"
                    )
                ).value()
            );
        assertEquals(
            "property.toad",
            node.properties().get(
                new URI(
                    "urn:metagrid/property/type/toad"
                    )
                ).value()
            );
View Full Code Here

        // Create our outer node reader.
        XMLNodeReader<ComplexNodeOne> outerreader = new ComplexNodeOneReader(
            new ComplexNodeOne.Factory()
        );

        Node outernode = outerreader.read(
        resources.get(
        URI.create(
          "urn://test/000"
          )
        ).reader()
View Full Code Here

        //
        // Create our outer node reader.
        XMLNodeReader<ComplexNodeTwo> reader = new ComplexNodeTwoReader();

        Node complex = reader.read(
            new ComplexNodeTwo.Factory(),
            resources.get(
                URI.create(
                    "urn://test/000"
                    )
View Full Code Here

            writer
            );

        //
        // Create our node.
        Node created = client.create(
            URI.create(
                "urn://apples/001"
                ),
            URI.create(
                "urn:metagrid.apple"
                )
            );

        //
        // Check the created node properties.
        assertEquals(
            "27",
            created.properties().get(
                AppleNode.WEIGHT_PROPERTY_URI
                ).value()
            );

        //
        // Select our node.
        Node selected = client.select(
            URI.create(
                "urn://apples/001"
                )
            );

        //
        // Check the selected node properties.
        assertEquals(
            "28",
            selected.properties().get(
                AppleNode.WEIGHT_PROPERTY_URI
                ).value()
            );
        }
View Full Code Here

                log.debug("TestConnectionHandler.handle(TestConnection)");
                log.debug("  Target [" + connection.target() + "]");
                log.debug("  Action [" + connection.action() + "]");


                Node node = null ;

                //
                // Check the action.
                switch(connection.action())
                    {
                    case CREATE :

                        node = creator.read(
                            connection.request().reader()
                            );

                        break ;
                   
                    case UPDATE :

                        node = updator.read(
                            connection.request().reader()
                            );

                        break ;

                    case SELECT :

                        node = selector.node(
                            connection.target()
                            );

                        break ;

                    }

//
// Commit the changes ...
//

                Writer writer = connection.response().writer();

                //
                // Write the response.
                xmlwriter.write(
                    writer,
                    node
                    );

                //
                // Close the response.
                try {
                    writer.close();
                    }
                catch(Exception ouch)
                    {
                    log.error("Failed to close response message [" + ouch + "]");
                    throw new TestConnectionException(
                        ouch
                        );
                    }

                }
            };

        //
        // Create our test connector.
        TestConnector connector = new TestConnectorImpl(
            handler
            );

        //
        // Create our (client) Node factory.
        NodeFactory<Node> factory = new SimpleNodeFactory();

        //
        // Create our (client) NodeReader.
        NodeReader<Node> reader = new XMLNodeReaderImpl<Node>(
            factory
            );

        //
        // Create our (client) NodeWriter.
        NodeWriter<Node> writer = new XMLNodeWriterImpl<Node>();

        //
        // Create our test client.
        NodeService<Node> client = new TestConnectionClientImpl<Node>(
            connector,
            reader,
            writer
            );

log.debug("");
log.debug("--------------");
log.debug("");

        //
        // Create our node.
        Node created = client.create(
            URI.create(
                "urn://test/001"
                ),
            URI.create(
                "urn:metagrid.test"
                )
            );

        //
        // Check the created node properties.
        assertEquals(
            "0",
            created.properties().get(
                CountedNodeServer.SERIAL_PROPERTY_URI
                ).value()
            );

log.debug("");
log.debug("--------------");
log.debug("");

        //
        // Select our node.
        Node selected = client.select(
            URI.create(
                "urn://apples/001"
                )
            );

        //
        // Check the selected node properties.
        assertEquals(
            "1",
            selected.properties().get(
                CountedNodeServer.SERIAL_PROPERTY_URI
                ).value()
            );

        }
View Full Code Here

    public void create(final ServiceRequest request)
        {
        log.debug("ServiceRequestHandlerImpl.create()");
        log.debug("URI [" + request.uri() + "]");
        try {
            Node node = this.creator.read(
                request.reader(),
                new URIHandler()
                    {
                    public URI uri(URI ident)
                        {
View Full Code Here

    public void select(final ServiceRequest request)
        {
        log.debug("ServiceRequestHandlerImpl.select()");
        log.debug("URI [" + request.uri() + "]");
        try {
            Node node = this.selector.node(
                request.uri()
                );
            this.write(
                request,
                node
View Full Code Here

TOP

Related Classes of org.metagrid.gatekeeper.node.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.