|
| 1 | +package org.testar.cli; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | +import java.util.Properties; |
| 5 | + |
| 6 | +import org.junit.Assert; |
| 7 | +import org.junit.Test; |
| 8 | +import org.testar.config.ConfigTags; |
| 9 | +import org.testar.config.settings.Settings; |
| 10 | +import org.testar.config.settings.SettingsDefaults; |
| 11 | +import org.testar.plugin.OperatingSystems; |
| 12 | +import org.testar.plugin.PlatformSessionSpec; |
| 13 | + |
| 14 | +public class CliDaemonServerTest { |
| 15 | + |
| 16 | + @Test |
| 17 | + public void buildSessionSpecForAndroidCopiesApkArgumentIntoSettings() { |
| 18 | + CliDaemonServer server = new CliDaemonServer(); |
| 19 | + Settings settings = defaultSettings(); |
| 20 | + |
| 21 | + PlatformSessionSpec sessionSpec = server.buildSessionSpec( |
| 22 | + CliRequest.of(CliCommand.START_SESSION, List.of("android", "/tmp/example.apk")), |
| 23 | + settings |
| 24 | + ); |
| 25 | + |
| 26 | + Assert.assertEquals(OperatingSystems.ANDROID, sessionSpec.getOperatingSystem()); |
| 27 | + Assert.assertEquals(PlatformSessionSpec.TargetType.EXECUTABLE, sessionSpec.getTargetType()); |
| 28 | + Assert.assertEquals("/tmp/example.apk", sessionSpec.getTarget()); |
| 29 | + Assert.assertFalse(settings.get(ConfigTags.AppiumIsApkInstalled)); |
| 30 | + Assert.assertEquals("/tmp/example.apk", settings.get(ConfigTags.AppiumApp)); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void buildSessionSpecForWebdriverCopiesTargetIntoSettings() { |
| 35 | + CliDaemonServer server = new CliDaemonServer(); |
| 36 | + Settings settings = defaultSettings(); |
| 37 | + |
| 38 | + PlatformSessionSpec sessionSpec = server.buildSessionSpec( |
| 39 | + CliRequest.of(CliCommand.START_SESSION, List.of("webdriver", "https://example.org")), |
| 40 | + settings |
| 41 | + ); |
| 42 | + |
| 43 | + Assert.assertEquals(OperatingSystems.WEBDRIVER, sessionSpec.getOperatingSystem()); |
| 44 | + Assert.assertEquals("https://example.org", sessionSpec.getTarget()); |
| 45 | + Assert.assertEquals("https://example.org", settings.get(ConfigTags.SUTConnectorValue)); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void buildSessionSpecForWindowsKeepsTargetInSessionSpec() { |
| 50 | + CliDaemonServer server = new CliDaemonServer(); |
| 51 | + Settings settings = defaultSettings(); |
| 52 | + |
| 53 | + PlatformSessionSpec sessionSpec = server.buildSessionSpec( |
| 54 | + CliRequest.of(CliCommand.START_SESSION, List.of("windows", "notepad.exe")), |
| 55 | + settings |
| 56 | + ); |
| 57 | + |
| 58 | + Assert.assertEquals(OperatingSystems.WINDOWS, sessionSpec.getOperatingSystem()); |
| 59 | + Assert.assertEquals("notepad.exe", sessionSpec.getTarget()); |
| 60 | + } |
| 61 | + |
| 62 | + private static Settings defaultSettings() { |
| 63 | + return new Settings(SettingsDefaults.getSettingsDefaults(), new Properties()); |
| 64 | + } |
| 65 | +} |
0 commit comments