You can directly leverage KarafTestSupport.

It basically does:

protected String executeCommand(final String command, final Long timeout, final Boolean silent, final Principal ... principals) {
        waitForCommandService(command);

        String response;
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final PrintStream printStream = new PrintStream(byteArrayOutputStream);

        final Callable<String> commandCallable = new Callable<String>() {
            @Override
            public String call() throws Exception {
                try {
                    if (!silent) {
                        System.err.println(command);
                    }
final CommandProcessor commandProcessor = getOsgiService(CommandProcessor.class); final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err);
                    commandSession.execute(command);
                } catch (Exception e) {
                    throw new RuntimeException(e.getMessage(), e);
                }
                printStream.flush();
                return byteArrayOutputStream.toString();
            }
        };

        FutureTask<String> commandFuture;
        if (principals.length == 0) {
            commandFuture = new FutureTask<String>(commandCallable);
        } else {
// If principals are defined, run the command callable via Subject.doAs()
            commandFuture = new FutureTask<String>(new Callable<String>() {
                @Override
                public String call() throws Exception {
                    Subject subject = new Subject();

subject.getPrincipals().addAll(Arrays.asList(principals));
return Subject.doAs(subject, new PrivilegedExceptionAction<String>() {
                        @Override
                        public String run() throws Exception {
                            return commandCallable.call();
                        }
                    });
                }
            });
        }

        try {
            executor.submit(commandFuture);
            response = commandFuture.get(timeout, TimeUnit.MILLISECONDS);
        } catch (TimeoutException e) {
            e.printStackTrace(System.err);
            response = "SHELL COMMAND TIMED OUT: ";
        } catch (ExecutionException e) {
            Throwable cause = e.getCause().getCause();
            throw new RuntimeException(cause.getMessage(), cause);
        } catch (InterruptedException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        return response;
    }

Providing your principals.

Regards
JB

On 04/26/2016 08:29 PM, Alex Soto wrote:
session execute:

final Session session = sessionFactory.create(System.in, printStream,
System.err);
session.execute(command);

with some future, callable, etc. as the done in Karaf’s own ITs
Best regards,

Alex soto




On Apr 26, 2016, at 1:50 PM, Jean-Baptiste Onofré <j...@nanthrax.net
<mailto:j...@nanthrax.net>> wrote:

I bet the ACL files are missing in the etc folder (probably custom
distribution).

Can you check this ?

Regards
JB

On 04/26/2016 06:55 PM, Alex Soto wrote:
Hello,

Running Karaf 4.0.3, and pax-exam 4.7.0.
From my pax-exam integration test I have no problem running command
“bundle:list”, however, on the next line, I try to run “bundle:restart”
and get exception:

org.apache.felix.gogo.runtime.CommandNotFoundException: Command not
found: bundle:restart

I assume that all bundle commands are deployed by the same feature, so
why is /list/ is available and not /restart/?
Is there something else I need to do to get access to the /restart
/command?

Best regards,
Alex soto




--
Jean-Baptiste Onofré
jbono...@apache.org <mailto:jbono...@apache.org>
http://blog.nanthrax.net
Talend - http://www.talend.com


--
Jean-Baptiste Onofré
jbono...@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Reply via email to