1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.remote
.core
.tests
.shell
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
16 import static org
.junit
.Assume
.assumeTrue
;
17 import static org
.junit
.Assert
.assertEquals
;
18 import static org
.junit
.Assert
.assertTrue
;
20 import java
.util
.Arrays
;
22 import org
.eclipse
.core
.commands
.ExecutionException
;
23 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
24 import org
.eclipse
.core
.runtime
.Platform
;
25 import org
.eclipse
.jdt
.annotation
.NonNull
;
26 import org
.eclipse
.remote
.core
.IRemoteConnection
;
27 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.core
.shell
.CommandShell
;
28 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.RemoteSystemProxy
;
29 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
30 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandInput
;
31 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandResult
;
32 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.shell
.ICommandShell
;
33 import org
.junit
.Test
;
36 * Test suite for the {@link CommandShell} class
38 public class CommandShellTest
{
40 private static final boolean IS_UNIX
= !Platform
.getOS().equals(Platform
.OS_WIN32
);
42 private static final @NonNull String
@NonNull [] CMD_INPUT_UNIX
= { "ls", "-l" };
43 private static final @NonNull String
@NonNull [] CMD_ERROR_INPUT_UNIX
= { "ls", "blablablabla" };
44 private static final @NonNull String
@NonNull [] CMD_UNKNOWN_COMMAND_UNIX
= { "blablablabla" };
46 private static final IRemoteConnection LOCAL_CONNECTION
= TmfRemoteConnectionFactory
.getLocalConnection();
47 private static final RemoteSystemProxy LOCAL_PROXY
= new RemoteSystemProxy(checkNotNull(LOCAL_CONNECTION
));
50 * Test suite for the {@link CommandShell#executeCommand} method
51 * @throws ExecutionException
55 public void testExecuteSuccess() throws ExecutionException
{
57 LOCAL_PROXY
.connect(new NullProgressMonitor());
58 ICommandShell shell
= LOCAL_PROXY
.createCommandShell();
60 ICommandInput command
= shell
.createCommand();
61 command
.addAll(checkNotNull(Arrays
.asList(CMD_INPUT_UNIX
)));
62 ICommandResult result
= shell
.executeCommand(command
, new NullProgressMonitor());
63 assertEquals(0, result
.getResult());
67 * Test suite for the {@link CommandShell#executeCommand} method (non-null result value)
68 * @throws ExecutionException
72 public void testExecuteError() throws ExecutionException
{
75 LOCAL_PROXY
.connect(new NullProgressMonitor());
76 ICommandShell shell
= LOCAL_PROXY
.createCommandShell();
78 ICommandInput command
= shell
.createCommand();
79 command
.addAll(checkNotNull(Arrays
.asList(CMD_ERROR_INPUT_UNIX
)));
80 ICommandResult result
= shell
.executeCommand(command
, new NullProgressMonitor());
81 assertTrue(result
.getResult() > 0);
85 * Test suite for the {@link CommandShell#executeCommand} method (with exception)
86 * @throws ExecutionException
89 @Test (expected
=ExecutionException
.class)
90 public void testExecuteException() throws ExecutionException
{
92 throw new ExecutionException("");
94 LOCAL_PROXY
.connect(new NullProgressMonitor());
95 ICommandShell shell
= LOCAL_PROXY
.createCommandShell();
97 ICommandInput command
= shell
.createCommand();
98 command
.addAll(checkNotNull(Arrays
.asList(CMD_UNKNOWN_COMMAND_UNIX
)));
99 ICommandResult result
= shell
.executeCommand(command
, new NullProgressMonitor());
100 assertTrue(result
.getResult() > 0);