Package org.metagrid.gatekeeper.node

Examples of org.metagrid.gatekeeper.node.SimpleNode


    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")
                )
            );

        //
View Full Code Here

TOP

Related Classes of org.metagrid.gatekeeper.node.SimpleNode

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.