Skip to content

Commit 06afc99

Browse files
mach6lukeis
authored andcommitted
Throw a friendly exception for old (selenium 2) nodeConfig.json files (#2838)
1 parent 4e28cd2 commit 06afc99

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

java/server/src/org/openqa/grid/internal/utils/configuration/GridNodeConfiguration.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public class GridNodeConfiguration extends GridConfiguration {
6868
@Expose( serialize = false )
6969
String remoteHost;
7070

71+
// used to read a Selenium 2.x nodeConfig.json file and throw a friendly exception
72+
@Expose( serialize = false )
73+
@Deprecated
74+
private Object configuration;
75+
7176
/*
7277
* config parameters which serialize and deserialize to/from json
7378
*/
@@ -293,6 +298,14 @@ public static GridNodeConfiguration loadFromJSON(JsonObject json) {
293298
GridNodeConfiguration config =
294299
builder.excludeFieldsWithoutExposeAnnotation().create().fromJson(json, GridNodeConfiguration.class);
295300

301+
if (config.configuration != null) {
302+
// caught below
303+
throw new GridConfigurationException("Deprecated -nodeConfig file encountered. Please update"
304+
+ " the file to work with Selenium 3. See https://github.com"
305+
+ "/SeleniumHQ/selenium/wiki/Grid2#configuring-the-nodes-by-json"
306+
+ " for more details.");
307+
}
308+
296309
return config;
297310
} catch (Throwable e) {
298311
throw new GridConfigurationException("Error with the JSON of the config : " + e.getMessage(),

java/server/test/org/openqa/grid/internal/utils/configuration/GridNodeConfigurationTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.beust.jcommander.JCommander;
3030

3131
import org.junit.Test;
32+
import org.openqa.grid.common.exception.GridConfigurationException;
3233
import org.openqa.selenium.remote.DesiredCapabilities;
3334

3435
import java.util.Arrays;
@@ -63,6 +64,20 @@ public void testLoadFromJson() {
6364
assertEquals(5L, gnc.capabilities.get(0).getCapability("maxInstances"));
6465
}
6566

67+
@Test(expected = GridConfigurationException.class)
68+
public void testLoadFromOldJson() {
69+
final String configJson = "{"
70+
+ "\"configuration\":"
71+
+ " {"
72+
+ "\"host\": \"dummyhost\","
73+
+ "\"maxSession\": 5,"
74+
+ "\"port\": 1234"
75+
+ " }"
76+
+ "}";
77+
JsonObject json = new JsonParser().parse(configJson).getAsJsonObject();
78+
GridNodeConfiguration gnc = GridNodeConfiguration.loadFromJSON(json);
79+
}
80+
6681
@Test
6782
public void testDefaults() {
6883
GridNodeConfiguration gnc = new GridNodeConfiguration();

0 commit comments

Comments
 (0)