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
CommitLineData
1d6a2139
BH
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
13package org.eclipse.tracecompass.tmf.remote.core.tests.shell;
14
15import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
16import static org.junit.Assume.assumeTrue;
17import static org.junit.Assert.assertEquals;
18import static org.junit.Assert.assertTrue;
19
20import java.util.Arrays;
21
22import org.eclipse.core.commands.ExecutionException;
23import org.eclipse.core.runtime.NullProgressMonitor;
f530fffa 24import org.eclipse.core.runtime.Platform;
1d6a2139
BH
25import org.eclipse.jdt.annotation.NonNull;
26import org.eclipse.remote.core.IRemoteConnection;
27import org.eclipse.tracecompass.internal.tmf.remote.core.shell.CommandShell;
28import org.eclipse.tracecompass.tmf.remote.core.proxy.RemoteSystemProxy;
b6b4e8b4 29import org.eclipse.tracecompass.tmf.remote.core.proxy.TmfRemoteConnectionFactory;
1d6a2139
BH
30import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandInput;
31import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandResult;
32import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandShell;
33import org.junit.Test;
34
35/**
36 * Test suite for the {@link CommandShell} class
37 */
38public class CommandShellTest {
39
f530fffa 40 private static final boolean IS_UNIX = !Platform.getOS().equals(Platform.OS_WIN32);
1d6a2139 41
aa353506
AM
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" };
1d6a2139 45
b6b4e8b4 46 private static final IRemoteConnection LOCAL_CONNECTION = TmfRemoteConnectionFactory.getLocalConnection();
1d6a2139
BH
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 {
f530fffa 56 assumeTrue(IS_UNIX);
1d6a2139
BH
57 LOCAL_PROXY.connect(new NullProgressMonitor());
58 ICommandShell shell = LOCAL_PROXY.createCommandShell();
59
60 ICommandInput command = shell.createCommand();
f530fffa 61 command.addAll(checkNotNull(Arrays.asList(CMD_INPUT_UNIX)));
1d6a2139
BH
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 {
f530fffa 73 assumeTrue(IS_UNIX);
1d6a2139
BH
74
75 LOCAL_PROXY.connect(new NullProgressMonitor());
76 ICommandShell shell = LOCAL_PROXY.createCommandShell();
77
78 ICommandInput command = shell.createCommand();
f530fffa 79 command.addAll(checkNotNull(Arrays.asList(CMD_ERROR_INPUT_UNIX)));
1d6a2139
BH
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 {
f530fffa 91 if (!IS_UNIX) {
1d6a2139
BH
92 throw new ExecutionException("");
93 }
94 LOCAL_PROXY.connect(new NullProgressMonitor());
95 ICommandShell shell = LOCAL_PROXY.createCommandShell();
96
97 ICommandInput command = shell.createCommand();
f530fffa 98 command.addAll(checkNotNull(Arrays.asList(CMD_UNKNOWN_COMMAND_UNIX)));
1d6a2139
BH
99 ICommandResult result = shell.executeCommand(command, new NullProgressMonitor());
100 assertTrue(result.getResult() > 0);
101 }
102}
This page took 0.056861 seconds and 5 git commands to generate.