26
26
27
27
import com .beust .jcommander .JCommander ;
28
28
29
+ import org .junit .Assume ;
29
30
import org .junit .Test ;
30
31
import org .openqa .grid .common .exception .GridConfigurationException ;
31
32
import org .openqa .grid .internal .utils .configuration .GridNodeConfiguration ;
@@ -268,7 +269,7 @@ public void testConstructorDoesNotPruneCapabilitiesWithUnknownPlatform() {
268
269
}
269
270
270
271
@ Test
271
- public void testBuilderPrunesCapabilitiesWithUnknownPlatform () {
272
+ public void testBuilderPrunesCapabilitiesWithUnknownPlatformName () {
272
273
GridNodeConfiguration config = new GridNodeConfiguration ();
273
274
MutableCapabilities capabilities = new MutableCapabilities ();
274
275
capabilities .setCapability ("browserName" , "firefox" );
@@ -278,6 +279,86 @@ public void testBuilderPrunesCapabilitiesWithUnknownPlatform() {
278
279
assertEquals (req .getConfiguration ().capabilities .size (), 0 );
279
280
}
280
281
282
+ @ Test
283
+ public void testBuilderPrunesCapabilitiesWithUnknownPlatform () {
284
+ GridNodeConfiguration config = new GridNodeConfiguration ();
285
+ MutableCapabilities capabilities = new MutableCapabilities ();
286
+ capabilities .setCapability ("browserName" , "firefox" );
287
+ capabilities .setCapability ("platform" , "cheese" );
288
+ config .capabilities = Arrays .asList (capabilities );
289
+ RegistrationRequest req = RegistrationRequest .build (config );
290
+ assertEquals (req .getConfiguration ().capabilities .size (), 0 );
291
+ }
292
+
293
+ @ Test
294
+ public void testBuilderPrunesCapabilitiesWithPlatformThatDoesNotMatchCurrent () {
295
+ Platform current = Platform .getCurrent ().family ();
296
+ Platform platform = Arrays .stream (Platform .values ())
297
+ .filter (p -> ! p .is (current )).findFirst ().get ();
298
+ GridNodeConfiguration config = new GridNodeConfiguration ();
299
+ MutableCapabilities capabilities = new MutableCapabilities ();
300
+ capabilities .setCapability ("browserName" , "firefox" );
301
+ capabilities .setCapability ("platform" , platform );
302
+ config .capabilities = Arrays .asList (capabilities );
303
+ RegistrationRequest req = RegistrationRequest .build (config );
304
+ assertEquals (req .getConfiguration ().capabilities .size (), 0 );
305
+ }
306
+
307
+ @ Test
308
+ public void testBuilderDoesNotPruneCapabilitiesWithPlatformThatIsEqualToCurrentFamily () {
309
+ Platform platform = Platform .getCurrent ().family ();
310
+ GridNodeConfiguration config = new GridNodeConfiguration ();
311
+ MutableCapabilities capabilities = new MutableCapabilities ();
312
+ capabilities .setCapability ("browserName" , "firefox" );
313
+ capabilities .setCapability ("platform" , platform );
314
+ config .capabilities = Arrays .asList (capabilities );
315
+ RegistrationRequest req = RegistrationRequest .build (config );
316
+ assertEquals (req .getConfiguration ().capabilities .size (), 1 );
317
+ }
318
+
319
+ @ Test
320
+ public void testBuilderDoesNotPruneCapabilitiesWithPlatformThatBelongsToCurrentFamily () {
321
+ Platform current = Platform .getCurrent ().family ();
322
+ Platform platform = Arrays .stream (Platform .values ())
323
+ .filter (p -> p .is (current ) && p != current ).findFirst ().orElse (null );
324
+ Assume .assumeTrue (platform != null );
325
+ GridNodeConfiguration config = new GridNodeConfiguration ();
326
+ MutableCapabilities capabilities = new MutableCapabilities ();
327
+ capabilities .setCapability ("browserName" , "firefox" );
328
+ capabilities .setCapability ("platform" , platform );
329
+ config .capabilities = Arrays .asList (capabilities );
330
+ RegistrationRequest req = RegistrationRequest .build (config );
331
+ assertEquals (req .getConfiguration ().capabilities .size (), 1 );
332
+ }
333
+
334
+ @ Test
335
+ public void testBuilderFixesUpPlatform () {
336
+ Platform platform = Platform .getCurrent ();
337
+ GridNodeConfiguration config = new GridNodeConfiguration ();
338
+ MutableCapabilities capabilities = new MutableCapabilities ();
339
+ capabilities .setCapability ("browserName" , "firefox" );
340
+ capabilities .setCapability ("platformName" , platform );
341
+ config .capabilities = Arrays .asList (capabilities );
342
+ RegistrationRequest req = RegistrationRequest .build (config );
343
+ assertEquals (req .getConfiguration ().capabilities .size (), 1 );
344
+ assertEquals (req .getConfiguration ().capabilities .get (0 ).getCapability ("platform" ), platform );
345
+ assertEquals (req .getConfiguration ().capabilities .get (0 ).getCapability ("platformName" ), platform );
346
+ }
347
+
348
+ @ Test
349
+ public void testBuilderFixesUpPlatformName () {
350
+ Platform platform = Platform .getCurrent ();
351
+ GridNodeConfiguration config = new GridNodeConfiguration ();
352
+ MutableCapabilities capabilities = new MutableCapabilities ();
353
+ capabilities .setCapability ("browserName" , "firefox" );
354
+ capabilities .setCapability ("platform" , platform );
355
+ config .capabilities = Arrays .asList (capabilities );
356
+ RegistrationRequest req = RegistrationRequest .build (config );
357
+ assertEquals (req .getConfiguration ().capabilities .size (), 1 );
358
+ assertEquals (req .getConfiguration ().capabilities .get (0 ).getCapability ("platform" ), platform );
359
+ assertEquals (req .getConfiguration ().capabilities .get (0 ).getCapability ("platformName" ), platform );
360
+ }
361
+
281
362
private void assertConstruction (RegistrationRequest req ) {
282
363
assertNotNull (req );
283
364
assertNotNull (req .getConfiguration ());
0 commit comments