|
22 | 22 | import static org.junit.Assert.assertNotNull;
|
23 | 23 | import static org.junit.Assert.assertNull;
|
24 | 24 | import static org.junit.Assert.assertSame;
|
| 25 | +import static org.junit.Assert.assertThat; |
25 | 26 | import static org.junit.Assert.assertTrue;
|
26 | 27 |
|
27 | 28 | import com.google.common.collect.ImmutableMap;
|
|
30 | 31 |
|
31 | 32 | import com.beust.jcommander.JCommander;
|
32 | 33 |
|
| 34 | +import org.hamcrest.CoreMatchers; |
33 | 35 | import org.junit.Test;
|
34 | 36 | import org.openqa.grid.common.exception.GridConfigurationException;
|
35 | 37 | import org.openqa.selenium.Platform;
|
36 | 38 | import org.openqa.selenium.remote.DesiredCapabilities;
|
| 39 | +import org.openqa.selenium.testing.TestUtilities; |
37 | 40 |
|
38 | 41 | import java.util.Arrays;
|
39 | 42 |
|
@@ -146,7 +149,6 @@ public void testConstructorEqualsDefaultConfig() {
|
146 | 149 | assertEquals(expected.nodeConfigFile, actual.nodeConfigFile);
|
147 | 150 | assertEquals(expected.unregisterIfStillDownAfter, actual.unregisterIfStillDownAfter);
|
148 | 151 |
|
149 |
| - |
150 | 152 | assertEquals(expected.cleanUpCycle, actual.cleanUpCycle);
|
151 | 153 | assertEquals(expected.host, actual.host);
|
152 | 154 | assertEquals(expected.maxSession, actual.maxSession);
|
@@ -217,16 +219,74 @@ public void testWithCapabilitiesArgsWithExtraSpacing() {
|
217 | 219 |
|
218 | 220 | @Test
|
219 | 221 | public void testGetHubHost() {
|
| 222 | + final String[] args = new String[]{"-hubHost", "dummyhost", "-hubPort", "1234"}; |
220 | 223 | GridNodeConfiguration gnc = new GridNodeConfiguration();
|
221 |
| - gnc.hub = "http://dummyhost:4444/wd/hub"; |
| 224 | + new JCommander(gnc, args); |
222 | 225 | assertEquals("dummyhost", gnc.getHubHost());
|
223 | 226 | }
|
224 | 227 |
|
| 228 | + @Test |
| 229 | + public void testGetHubHostFromHubOption() { |
| 230 | + final String[] args = new String[]{"-hub", "http://dummyhost:1234/wd/hub"}; |
| 231 | + GridNodeConfiguration gnc = new GridNodeConfiguration(); |
| 232 | + new JCommander(gnc, args); |
| 233 | + assertEquals("dummyhost", gnc.getHubHost()); |
| 234 | + } |
| 235 | + |
| 236 | + @Test |
| 237 | + public void testOneOfHubOrHubHostShouldBePresent() { |
| 238 | + final String[] args = new String[]{"-hubPort", "1234"}; |
| 239 | + GridNodeConfiguration gnc = new GridNodeConfiguration(); |
| 240 | + new JCommander(gnc, args); |
| 241 | + Throwable t = TestUtilities.catchThrowable(gnc::getHubHost); |
| 242 | + assertThat(t, CoreMatchers.instanceOf(RuntimeException.class)); |
| 243 | + t = TestUtilities.catchThrowable(gnc::getHubPort); |
| 244 | + assertThat(t, CoreMatchers.instanceOf(RuntimeException.class)); |
| 245 | + } |
| 246 | + |
| 247 | + @Test |
| 248 | + public void testHubOptionHasPrecedenceOverHubHost() { |
| 249 | + final String[] args = new String[]{"-hub", "http://smarthost:4321/wd/hub", |
| 250 | + "-hubHost", "dummyhost", "-hubPort", "1234"}; |
| 251 | + GridNodeConfiguration gnc = new GridNodeConfiguration(); |
| 252 | + new JCommander(gnc, args); |
| 253 | + assertEquals("smarthost", gnc.getHubHost()); |
| 254 | + } |
| 255 | + |
225 | 256 | @Test
|
226 | 257 | public void testGetHubPort() {
|
| 258 | + final String[] args = new String[]{"-hubHost", "dummyhost", "-hubPort", "1234"}; |
227 | 259 | GridNodeConfiguration gnc = new GridNodeConfiguration();
|
228 |
| - gnc.hub = "http://dummyhost:4444/wd/hub"; |
229 |
| - assertEquals(4444, gnc.getHubPort().intValue()); |
| 260 | + new JCommander(gnc, args); |
| 261 | + assertEquals(1234, gnc.getHubPort().intValue()); |
| 262 | + } |
| 263 | + |
| 264 | + @Test |
| 265 | + public void testGetHubPortFromHubOption() { |
| 266 | + final String[] args = new String[]{"-hub", "http://dummyhost:1234/wd/hub"}; |
| 267 | + GridNodeConfiguration gnc = new GridNodeConfiguration(); |
| 268 | + new JCommander(gnc, args); |
| 269 | + assertEquals(1234, gnc.getHubPort().intValue()); |
| 270 | + } |
| 271 | + |
| 272 | + @Test |
| 273 | + public void testOneOfHubOrHubPortShouldBePresent() { |
| 274 | + final String[] args = new String[]{"-hubHost", "dummyhost"}; |
| 275 | + GridNodeConfiguration gnc = new GridNodeConfiguration(); |
| 276 | + new JCommander(gnc, args); |
| 277 | + Throwable t = TestUtilities.catchThrowable(gnc::getHubHost); |
| 278 | + assertThat(t, CoreMatchers.instanceOf(RuntimeException.class)); |
| 279 | + t = TestUtilities.catchThrowable(gnc::getHubPort); |
| 280 | + assertThat(t, CoreMatchers.instanceOf(RuntimeException.class)); |
| 281 | + } |
| 282 | + |
| 283 | + @Test |
| 284 | + public void testHubOptionHasPrecedenceOverHubPort() { |
| 285 | + final String[] args = new String[]{"-hub", "http://smarthost:4321/wd/hub", |
| 286 | + "-hubHost", "dummyhost", "-hubPort", "1234"}; |
| 287 | + GridNodeConfiguration gnc = new GridNodeConfiguration(); |
| 288 | + new JCommander(gnc, args); |
| 289 | + assertEquals(4321, gnc.getHubPort().intValue()); |
230 | 290 | }
|
231 | 291 |
|
232 | 292 | @Test
|
|
0 commit comments