Fix some null warnings
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.remote.core.tests / src / org / eclipse / tracecompass / tmf / remote / core / tests / shell / CommandShellTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.remote.core.tests.shell;
14
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;
19
20 import java.util.Arrays;
21
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;
34
35 /**
36 * Test suite for the {@link CommandShell} class
37 */
38 public class CommandShellTest {
39
40 private static final boolean IS_UNIX = !Platform.getOS().equals(Platform.OS_WIN32);
41
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" };
45
46 private static final IRemoteConnection LOCAL_CONNECTION = TmfRemoteConnectionFactory.getLocalConnection();
47 private static final RemoteSystemProxy LOCAL_PROXY = new RemoteSystemProxy(checkNotNull(LOCAL_CONNECTION));
48
49 /**
50 * Test suite for the {@link CommandShell#executeCommand} method
51 * @throws ExecutionException
52 * in case of an error
53 */
54 @Test
55 public void testExecuteSuccess() throws ExecutionException {
56 assumeTrue(IS_UNIX);
57 LOCAL_PROXY.connect(new NullProgressMonitor());
58 ICommandShell shell = LOCAL_PROXY.createCommandShell();
59
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());
64 }
65
66 /**
67 * Test suite for the {@link CommandShell#executeCommand} method (non-null result value)
68 * @throws ExecutionException
69 * in case of an error
70 */
71 @Test
72 public void testExecuteError() throws ExecutionException {
73 assumeTrue(IS_UNIX);
74
75 LOCAL_PROXY.connect(new NullProgressMonitor());
76 ICommandShell shell = LOCAL_PROXY.createCommandShell();
77
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);
82 }
83
84 /**
85 * Test suite for the {@link CommandShell#executeCommand} method (with exception)
86 * @throws ExecutionException
87 * in case of an error
88 */
89 @Test (expected=ExecutionException.class)
90 public void testExecuteException() throws ExecutionException {
91 if (!IS_UNIX) {
92 throw new ExecutionException("");
93 }
94 LOCAL_PROXY.connect(new NullProgressMonitor());
95 ICommandShell shell = LOCAL_PROXY.createCommandShell();
96
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);
101 }
102 }
This page took 0.033264 seconds and 5 git commands to generate.