Package org.apache.karaf.shell.console.impl.jline.ConsoleImpl

Examples of org.apache.karaf.shell.console.impl.jline.ConsoleImpl.DelegateSession


        final ConsoleImpl console = new ConsoleImpl(null, new ThreadIOImpl(), System.in, System.out, System.err, null, "UTF-8", null, bc, true);
        assertTrue(console.session instanceof DelegateSession);

        console.session.put("foo", "bar");

        final DelegateSession ds = (DelegateSession) console.session;
        assertNull("Precondition", ds.delegate);

        Subject subject = new Subject();
        subject.getPrincipals().add(new RolePrincipal("myrole"));

        Subject.doAs(subject, new PrivilegedAction<Object>() {
            @Override
            public Object run() {
                SecuredCommandProcessorImpl secCP = console.createSecuredCommandProcessor();
                assertNotNull(ds.delegate);
                assertEquals("Attributes set before the delegate was set should have been transferred",
                        "bar", ds.get("foo"));
                assertEquals("Attributes set before the delegate was set should have been transferred",
                        "bar", ds.delegate.get("foo"));
                assertSame(System.out, ds.delegate.getConsole());
                assertSame(System.out, ds.getConsole());

                assertTrue(secCP.getCommands().contains("myscope:myfunction"));

                return null;
            }
View Full Code Here


        });
    }

    @Test
    public void testDelegateSession() throws Exception {
        DelegateSession ds = new DelegateSession();

        ds.put("a", "b");
        assertEquals("b", ds.get("a"));

        TestSession ts = new TestSession();

        assertNull("Precondition", ts.lastInvoked);

        ds.setDelegate(ts);
        assertEquals("put(a,b)", ts.lastInvoked);

        ds.put("c", "d");
        assertEquals("put(c,d)", ts.lastInvoked);

        ds.execute("hello 1234");
        assertEquals("execute(hello 1234)", ts.lastInvoked);

        ds.close();
        assertEquals("close", ts.lastInvoked);

        ds.getKeyboard();
        assertEquals("getKeyboard", ts.lastInvoked);

        ds.getConsole();
        assertEquals("getConsole", ts.lastInvoked);

        ds.get("xyz");
        assertEquals("get(xyz)", ts.lastInvoked);

        ds.format("foo", 12);
        assertEquals("format(foo,12)", ts.lastInvoked);

        ds.convert(TestSession.class, "a string");
        assertEquals("convert(TestSession,a string)", ts.lastInvoked);
    }
View Full Code Here

        });
    }

    @Test
    public void testDelegateSession() throws Exception {
        DelegateSession ds = new DelegateSession();

        ds.put("a", "b");
        assertEquals("b", ds.get("a"));

        TestSession ts = new TestSession();

        assertNull("Precondition", ts.lastInvoked);

        ds.setDelegate(ts);
        assertEquals("put(a,b)", ts.lastInvoked);

        ds.put("c", "d");
        assertEquals("put(c,d)", ts.lastInvoked);

        ds.execute("hello 1234");
        assertEquals("execute(hello 1234)", ts.lastInvoked);

        ds.close();
        assertEquals("close", ts.lastInvoked);

        ds.getKeyboard();
        assertEquals("getKeyboard", ts.lastInvoked);

        ds.getConsole();
        assertEquals("getConsole", ts.lastInvoked);

        ds.get("xyz");
        assertEquals("get(xyz)", ts.lastInvoked);

        ds.format("foo", 12);
        assertEquals("format(foo,12)", ts.lastInvoked);

        ds.convert(TestSession.class, "a string");
        assertEquals("convert(TestSession,a string)", ts.lastInvoked);
    }
View Full Code Here

        final ConsoleImpl console = new ConsoleImpl(null, new ThreadIOImpl(), System.in, System.out, System.err, null, "UTF-8", null, bc);
        assertTrue(console.session instanceof DelegateSession);

        console.session.put("foo", "bar");

        final DelegateSession ds = (DelegateSession) console.session;
        assertNull("Precondition", ds.delegate);

        Subject subject = new Subject();
        subject.getPrincipals().add(new RolePrincipal("myrole"));

        Subject.doAs(subject, new PrivilegedAction<Object>() {
            @Override
            public Object run() {
                SecuredCommandProcessorImpl secCP = console.createSecuredCommandProcessor();
                assertNotNull(ds.delegate);
                assertEquals("Attributes set before the delegate was set should have been transferred",
                        "bar", ds.get("foo"));
                assertEquals("Attributes set before the delegate was set should have been transferred",
                        "bar", ds.delegate.get("foo"));
                assertSame(System.out, ds.delegate.getConsole());
                assertSame(System.out, ds.getConsole());

                assertTrue(secCP.getCommands().contains("myscope:myfunction"));

                return null;
            }
View Full Code Here

TOP

Related Classes of org.apache.karaf.shell.console.impl.jline.ConsoleImpl.DelegateSession

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.