Search in sources :

Example 1 with HeadlessSessionImpl

use of org.apache.karaf.shell.impl.console.HeadlessSessionImpl in project karaf by apache.

the class ParsingTest method testCommandLineParser.

@Test
public void testCommandLineParser() {
    SessionFactoryImpl sessionFactory = new SessionFactoryImpl(new ThreadIOImpl());
    ManagerImpl manager = new ManagerImpl(sessionFactory, sessionFactory);
    sessionFactory.getRegistry().register(new ActionCommand(manager, FooCommand.class));
    sessionFactory.getRegistry().register(new ActionCommand(manager, AnotherCommand.class));
    sessionFactory.getRegistry().register(new CustomParser());
    Session session = new HeadlessSessionImpl(sessionFactory, sessionFactory.getCommandProcessor(), new ByteArrayInputStream(new byte[0]), new PrintStream(new ByteArrayOutputStream()), new PrintStream(new ByteArrayOutputStream()));
    String parsed = CommandLineParser.parse(session, " foo bar (a + b); another   command with spaces ");
    assertEquals("foo bar (a + b) ; another \"command with spaces\"", parsed);
}
Also used : PrintStream(java.io.PrintStream) HeadlessSessionImpl(org.apache.karaf.shell.impl.console.HeadlessSessionImpl) ThreadIOImpl(org.apache.felix.gogo.runtime.threadio.ThreadIOImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ManagerImpl(org.apache.karaf.shell.impl.action.command.ManagerImpl) ActionCommand(org.apache.karaf.shell.impl.action.command.ActionCommand) SessionFactoryImpl(org.apache.karaf.shell.impl.console.SessionFactoryImpl) Session(org.apache.karaf.shell.api.console.Session) Test(org.junit.Test)

Example 2 with HeadlessSessionImpl

use of org.apache.karaf.shell.impl.console.HeadlessSessionImpl in project karaf by apache.

the class ParsingTest method testCommandLineParserMultiLine.

@Test
public void testCommandLineParserMultiLine() {
    SessionFactoryImpl sessionFactory = new SessionFactoryImpl(new ThreadIOImpl());
    ManagerImpl manager = new ManagerImpl(sessionFactory, sessionFactory);
    sessionFactory.getRegistry().register(new ActionCommand(manager, FooCommand.class));
    sessionFactory.getRegistry().register(new ActionCommand(manager, AnotherCommand.class));
    sessionFactory.getRegistry().register(new CustomParser());
    Session session = new HeadlessSessionImpl(sessionFactory, sessionFactory.getCommandProcessor(), new ByteArrayInputStream(new byte[0]), new PrintStream(new ByteArrayOutputStream()), new PrintStream(new ByteArrayOutputStream()));
    String parsed = CommandLineParser.parse(session, "echo a\necho b");
    assertEquals("echo a\necho b", parsed);
}
Also used : PrintStream(java.io.PrintStream) HeadlessSessionImpl(org.apache.karaf.shell.impl.console.HeadlessSessionImpl) ThreadIOImpl(org.apache.felix.gogo.runtime.threadio.ThreadIOImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ManagerImpl(org.apache.karaf.shell.impl.action.command.ManagerImpl) ActionCommand(org.apache.karaf.shell.impl.action.command.ActionCommand) SessionFactoryImpl(org.apache.karaf.shell.impl.console.SessionFactoryImpl) Session(org.apache.karaf.shell.api.console.Session) Test(org.junit.Test)

Example 3 with HeadlessSessionImpl

use of org.apache.karaf.shell.impl.console.HeadlessSessionImpl in project karaf by apache.

the class ActionMaskingCallbackTest method setUp.

@Before
public void setUp() {
    ThreadIO tio = new ThreadIOImpl();
    CommandProcessor cp = new CommandProcessorImpl(tio);
    SessionFactory sf = new SessionFactoryImpl(tio);
    InputStream is = new ByteArrayInputStream(new byte[0]);
    PrintStream os = new PrintStream(new ByteArrayOutputStream());
    Session session = new HeadlessSessionImpl(sf, cp, is, os, os);
    parser = new KarafParser(session);
    ActionCommand cmd = new ActionCommand(null, UserAddCommand.class);
    cb = ActionMaskingCallback.build(cmd);
}
Also used : ThreadIO(org.apache.felix.service.threadio.ThreadIO) SessionFactory(org.apache.karaf.shell.api.console.SessionFactory) PrintStream(java.io.PrintStream) HeadlessSessionImpl(org.apache.karaf.shell.impl.console.HeadlessSessionImpl) ThreadIOImpl(org.apache.felix.gogo.runtime.threadio.ThreadIOImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CommandProcessorImpl(org.apache.felix.gogo.runtime.CommandProcessorImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KarafParser(org.apache.karaf.shell.impl.console.parsing.KarafParser) ByteArrayInputStream(java.io.ByteArrayInputStream) CommandProcessor(org.apache.felix.service.command.CommandProcessor) SessionFactoryImpl(org.apache.karaf.shell.impl.console.SessionFactoryImpl) Session(org.apache.karaf.shell.api.console.Session) Before(org.junit.Before)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 ThreadIOImpl (org.apache.felix.gogo.runtime.threadio.ThreadIOImpl)3 Session (org.apache.karaf.shell.api.console.Session)3 HeadlessSessionImpl (org.apache.karaf.shell.impl.console.HeadlessSessionImpl)3 SessionFactoryImpl (org.apache.karaf.shell.impl.console.SessionFactoryImpl)3 ActionCommand (org.apache.karaf.shell.impl.action.command.ActionCommand)2 ManagerImpl (org.apache.karaf.shell.impl.action.command.ManagerImpl)2 Test (org.junit.Test)2 InputStream (java.io.InputStream)1 CommandProcessorImpl (org.apache.felix.gogo.runtime.CommandProcessorImpl)1 CommandProcessor (org.apache.felix.service.command.CommandProcessor)1 ThreadIO (org.apache.felix.service.threadio.ThreadIO)1 SessionFactory (org.apache.karaf.shell.api.console.SessionFactory)1 KarafParser (org.apache.karaf.shell.impl.console.parsing.KarafParser)1 Before (org.junit.Before)1