1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package vogar.android; 18 19 import java.io.IOException; 20 import java.util.Arrays; 21 import java.util.List; 22 import org.junit.Test; 23 import org.junit.runner.RunWith; 24 import org.mockito.runners.MockitoJUnitRunner; 25 import vogar.Mode; 26 import vogar.ModeId; 27 import vogar.SshTarget; 28 import vogar.Target; 29 import vogar.Variant; 30 import vogar.commands.Command; 31 import vogar.commands.VmCommandBuilder; 32 33 import static org.junit.Assert.assertEquals; 34 35 /** 36 * Test the behaviour of the {@link DeviceRuntime} class when run with {@link SshTarget}. 37 */ 38 @RunWith(MockitoJUnitRunner.class) 39 public class DeviceRuntimeSshTargetTest extends AbstractModeTest { 40 41 @Override createTarget()42 protected Target createTarget() { 43 return new SshTarget(console, "host:99"); 44 } 45 46 @Test 47 @VogarArgs({"action"}) testSshTarget()48 public void testSshTarget() 49 throws IOException { 50 51 Mode deviceRuntime = new DeviceRuntime(run, ModeId.DEVICE, Variant.X32, 52 deviceUserNameSupplier); 53 54 VmCommandBuilder builder = newVmCommandBuilder(deviceRuntime) 55 .classpath(classpath) 56 .mainClass("mainclass") 57 .args("-x", "a b"); 58 Command command = builder.build(run.target); 59 List<String> args = command.getArgs(); 60 assertEquals(Arrays.asList( 61 "ssh", "-p", "99", "host", "-C", "" 62 + "cd /work" 63 + " &&" 64 + " ANDROID_DATA=runner" 65 + " dalvikvm32" 66 + " -classpath" 67 + " classes" 68 + " -Duser.home=runner/dir/user.home" 69 + " -Duser.name=fred" 70 + " -Duser.language=en" 71 + " -Duser.region=US" 72 + " -Xcheck:jni" 73 + " -Xjnigreflimit:2000" 74 + " mainclass" 75 + " -x a\\ b"), args); 76 } 77 } 78