Package org.apache.karaf.shell.commands

Examples of org.apache.karaf.shell.commands.Context


public class CompletionTest extends CompleterTestSupport {

    @Test
    public void testSubShellCompletion() throws Exception {
        Context context = new Context();
        context.set("SCOPE", "*");
        context.set(SessionProperties.COMPLETION_MODE, "subshell");
        CommandSessionHolder.setSession(context.getSession());

        context.addCommand("*", new SimpleSubShell("foo"), "foo");
        context.addCommand("*", new SimpleCommand(ExitAction.class), "exit");
        context.addCommand("foo", new SimpleCommand(MyAction.class), "my-action");
        context.addCommand("foo", new SimpleCommand(MyActionTwoArguments.class), "one-action");
        context.addCommand("bar", new SimpleCommand(MyAction.class), "one-action");
        context.addCommand("bar", new SimpleCommand(MyActionTwoArguments.class), "another");

        Completer comp = new CommandsCompleter(context.getSession());

        context.execute("foo");
        assertEquals(Arrays.asList("my-action "), complete(comp, "my"));
        assertEquals(Arrays.asList("exit ", "my-action ", "one-action "), complete(comp, ""));
        assertEquals(Arrays.asList(), complete(comp, "an"));
        assertEquals(Arrays.asList("--check", "--foo", "--help", "--integer", "--string"),
                     complete(comp, "my-action --"));
        assertEquals(Arrays.asList("--dummy", "--help"), complete(comp, "one-action --"));

        context.execute("exit");
        assertEquals(Arrays.asList(), complete(comp, "my"));
        assertEquals(Arrays.asList("exit ", "foo "), complete(comp, ""));
        assertEquals(Arrays.asList(), complete(comp, "an"));
    }
View Full Code Here


        assertEquals(Arrays.asList(), complete(comp, "an"));
    }

    @Test
    public void testFirstCompletion() throws Exception {
        Context context = new Context();
        context.set("SCOPE", "*");
        context.set(SessionProperties.COMPLETION_MODE, "first");
        CommandSessionHolder.setSession(context.getSession());

        context.addCommand("*", new SimpleSubShell("foo"), "foo");
        context.addCommand("*", new SimpleCommand(ExitAction.class), "exit");
        context.addCommand("foo", new SimpleCommand(MyAction.class), "my-action");
        context.addCommand("foo", new SimpleCommand(MyActionTwoArguments.class), "one-action");
        context.addCommand("bar", new SimpleCommand(MyAction.class), "one-action");
        context.addCommand("bar", new SimpleCommand(MyActionTwoArguments.class), "another");

        Completer comp = new CommandsCompleter(context.getSession());

        context.execute("foo");
        assertEquals(Arrays.asList("my-action "), complete(comp, "my"));
        assertEquals(Arrays.asList("my-action ", "one-action "), complete(comp, ""));
        assertEquals(Arrays.asList("another "), complete(comp, "an"));
        assertEquals(Arrays.asList("--check", "--foo", "--help", "--integer", "--string"),
                     complete(comp, "my-action --"));
        assertEquals(Arrays.asList("--dummy", "--help"), complete(comp, "one-action --"));

        context.execute("exit");
        assertEquals(Arrays.asList("my-action "), complete(comp, "my"));
        assertEquals(Arrays.asList("*:exit", "*:foo", "another", "bar:another",
                                   "bar:one-action", "exit", "foo",
                                   "foo:my-action", "foo:one-action", "my-action",
                                   "one-action", "one-action"), complete(comp, ""));
View Full Code Here

        assertEquals(Arrays.asList("another "), complete(comp, "an"));
    }

    @Test
    public void testGlobalCompletion() throws Exception {
        Context context = new Context();
        context.set("SCOPE", "*");
        context.set(SessionProperties.COMPLETION_MODE, "global");
        CommandSessionHolder.setSession(context.getSession());

        context.addCommand("*", new SimpleSubShell("foo"), "foo");
        context.addCommand("*", new SimpleCommand(ExitAction.class), "exit");
        context.addCommand("foo", new SimpleCommand(MyAction.class), "my-action");
        context.addCommand("foo", new SimpleCommand(MyActionTwoArguments.class), "one-action");
        context.addCommand("bar", new SimpleCommand(MyAction.class), "one-action");
        context.addCommand("bar", new SimpleCommand(MyActionTwoArguments.class), "another");

        Completer comp = new CommandsCompleter(context.getSession());

        context.execute("foo");
        assertEquals(Arrays.asList("my-action "), complete(comp, "my"));
        assertEquals(Arrays.asList("*:exit", "*:foo", "another", "bar:another",
                                    "bar:one-action", "exit", "foo",
                                   "foo:my-action", "foo:one-action", "my-action",
                                   "one-action", "one-action"), complete(comp, ""));
        assertEquals(Arrays.asList("another "), complete(comp, "an"));
        assertEquals(Arrays.asList("--check", "--foo", "--help", "--integer", "--string"),
                     complete(comp, "my-action --"));
        assertEquals(Arrays.asList("--dummy", "--help"), complete(comp, "one-action --"));

        context.execute("exit");
        assertEquals(Arrays.asList("my-action "), complete(comp, "my"));
        assertEquals(Arrays.asList("*:exit", "*:foo", "another", "bar:another",
                                   "bar:one-action", "exit", "foo",
                                   "foo:my-action", "foo:one-action", "my-action",
                                   "one-action", "one-action"), complete(comp, ""));
View Full Code Here

TOP

Related Classes of org.apache.karaf.shell.commands.Context

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.