Skip to content
Permalink
Browse files

switching from json-simple to gson [oh the pain :( ]

  • Loading branch information...
nicegraham committed Jul 4, 2013
1 parent 1605d6e commit 4d9bada8aeab5b09e7a27926fc9ecab8bb5a1b51
Showing with 230 additions and 338 deletions.
  1. +5 −17 SeleniumGridExtras/pom.xml
  2. +6 −3 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/ApiDocumentation.java
  3. +75 −77 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/DefaultConfig.java
  4. +2 −1 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/ExtrasEndPoint.java
  5. +19 −20 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/FirstTimeRunConfig.java
  6. +0 −69 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/JsonArrayBuilder.java
  7. +38 −31 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/JsonResponseBuilder.java
  8. +4 −35 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/JsonWrapper.java
  9. +22 −19 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/RuntimeConfig.java
  10. +13 −16 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/grid/GridWrapper.java
  11. +21 −26 ...dExtras/src/main/java/com/groupon/seleniumgridextras/grid/servlets/SeleniumGridExtrasServlet.java
  12. +1 −5 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/GetConfig.java
  13. +0 −1 SeleniumGridExtras/src/main/java/com/groupon/seleniumgridextras/tasks/KillAllIE.java
  14. +1 −1 SeleniumGridExtras/src/main/resources/www/js_partial.html
  15. +4 −2 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/DownloadWebdriverTest.java
  16. +4 −3 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/ExposeDirectoryTest.java
  17. +1 −1 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/GetProcessesTest.java
  18. +1 −1 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/KillAllByNameTest.java
  19. +1 −1 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/ScreenshotTest.java
  20. +3 −2 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/UpgradeWebdriverTest.java
  21. +5 −3 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/grid/GridWrapperTest.java
  22. +1 −1 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/tasks/GetInfoForPortTest.java
  23. +1 −1 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/tasks/GridStatusTest.java
  24. +1 −1 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/tasks/SetupTest.java
  25. +1 −1 SeleniumGridExtras/src/test/java/com/groupon/seleniumgridextras/tasks/TeardownTest.java
@@ -34,11 +34,11 @@
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<!--<dependency>-->
<!--<groupId>com.googlecode.json-simple</groupId>-->
<!--<artifactId>json-simple</artifactId>-->
<!--<version>1.1.1</version>-->
<!--</dependency>-->
</dependencies>

<build>
@@ -67,18 +67,6 @@
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<groupId>org.codehaus.mojo</groupId>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>test</id>-->
<!--<phase>test</phase>-->
<!--<goals>-->
<!--<goal>spec</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
</plugins>
</build>
</project>
@@ -36,16 +36,19 @@
*/
package com.groupon.seleniumgridextras;

import org.json.simple.JSONArray;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.util.Map;

public class ApiDocumentation {

private static JSONArray apiSpec = new JSONArray();
private static JsonArray apiSpec = new JsonArray();

public static void registerApiEndPoint(Map endPoint){
apiSpec.add(endPoint);
JsonObject o = new JsonParser().parse(String.valueOf(endPoint)).getAsJsonObject();
apiSpec.add(o);
}

public static String getApiDocumentation(){
@@ -34,35 +34,35 @@
* Date: 5/10/13
* Time: 4:06 PM
*/

package com.groupon.seleniumgridextras;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;

public class DefaultConfig {

private static JSONObject defaultConfig;
private static JSONArray enabledPlugins;
private static JSONArray disabledPlugins;
private static JSONArray setupTask;
private static JSONArray teardownTask;
private static JSONObject gridConfig;
private static JSONObject webdriverConfig;
private static JsonObject defaultConfig;
private static JsonArray enabledPlugins;
private static JsonArray disabledPlugins;
private static JsonArray setupTask;
private static JsonArray teardownTask;
private static JsonObject gridConfig;
private static JsonObject webdriverConfig;


public static String toJsonString(){
return getDefaultConfig().toJSONString();
return getDefaultConfig().toString();
}

public static JSONObject getDefaultConfig() {
defaultConfig = new JSONObject();
enabledPlugins = new JSONArray();
disabledPlugins = new JSONArray();
setupTask = new JSONArray();
teardownTask = new JSONArray();
gridConfig = new JSONObject();
webdriverConfig = new JSONObject();
public static JsonObject getDefaultConfig() {
defaultConfig = new JsonObject();
enabledPlugins = new JsonArray();
disabledPlugins = new JsonArray();
setupTask = new JsonArray();
teardownTask = new JsonArray();
gridConfig = new JsonObject();
webdriverConfig = new JsonObject();


loadDisabledPlugins();
@@ -78,104 +78,102 @@ public static JSONObject getDefaultConfig() {
}

public static void loadConfigVersion(){
defaultConfig.put("config_version", "1.0");
defaultConfig.addProperty("config_version", "1.0");
}

private static void loadSetupConfig() {
setupTask.add("com.groupon.seleniumgridextras.tasks.KillAllIE");
setupTask.add("com.groupon.seleniumgridextras.tasks.MoveMouse");
defaultConfig.put("setup", setupTask);
setupTask.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.KillAllIE"));
setupTask.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.MoveMouse"));
defaultConfig.add("setup", setupTask);
}

private static void loadTeardownConfig() {
teardownTask.add("com.groupon.seleniumgridextras.tasks.KillAllIE");
teardownTask.add("com.groupon.seleniumgridextras.tasks.MoveMouse");
defaultConfig.put("teardown", teardownTask);
teardownTask.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.KillAllIE"));
teardownTask.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.MoveMouse"));
defaultConfig.add("teardown", teardownTask);
}


private static void loadWebDriverInfo() {
webdriverConfig.put("directory", "webdriver");
webdriverConfig.put("version", "2.33.0");
defaultConfig.put("webdriver", webdriverConfig);
webdriverConfig.addProperty("directory", "webdriver");
webdriverConfig.addProperty("version", "2.33.0");
defaultConfig.add("webdriver", webdriverConfig);
}

private static void loadEnabledPlugins() {
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.DownloadWebdriver");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.UpgradeWebdriver");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.Setup");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.Teardown");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.MoveMouse");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.RebootNode");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.KillAllIE");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.KillAllFirefox");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.KillAllChrome");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.GetProcesses");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.KillPid");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.Netstat");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.Screenshot");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.ExposeDirectory");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.StartGrid");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.GetInfoForPort");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.GridStatus");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.KillAllByName");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.StopGrid");
enabledPlugins.add("com.groupon.seleniumgridextras.tasks.GetConfig");

defaultConfig.put("activated_modules", enabledPlugins);
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.DownloadWebdriver"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.UpgradeWebdriver"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.Setup"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.Teardown"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.MoveMouse"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.RebootNode"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.KillAllIE"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.KillAllFirefox"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.KillAllChrome"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.GetProcesses"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.KillPid"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.Netstat"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.Screenshot"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.ExposeDirectory"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.StartGrid"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.GetInfoForPort"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.GridStatus"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.KillAllByName"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.StopGrid"));
enabledPlugins.add(new JsonPrimitive("com.groupon.seleniumgridextras.tasks.GetConfig"));

defaultConfig.add("activated_modules", enabledPlugins);
}

private static void loadDisabledPlugins() {
disabledPlugins.add("com.groupon.GetFile");
defaultConfig.put("disabled_modules", disabledPlugins);
disabledPlugins.add(new JsonPrimitive("com.groupon.GetFile"));
defaultConfig.add("disabled_modules", disabledPlugins);
}

private static void loadGridConfig() {
gridConfig.put("default_role", "hub");
gridConfig.put("auto_start_hub", "0");
gridConfig.put("auto_start_node", "1");
gridConfig.put("hub", getGridHubConfig());
gridConfig.put("node", getGridNodeConfig());
gridConfig.addProperty("default_role", "hub");
gridConfig.addProperty("auto_start_hub", "0");
gridConfig.addProperty("auto_start_node", "1");
gridConfig.add("hub", getGridHubConfig());
gridConfig.add("node", getGridNodeConfig());

defaultConfig.put("grid", gridConfig);
defaultConfig.add("grid", gridConfig);
}

private static JSONObject getGridHubConfig() {
JSONObject gridHubConfig = new JSONObject();
gridHubConfig.put("-role", "hub");
gridHubConfig.put("-servlets", "com.groupon.seleniumgridextras.grid.servlets.SeleniumGridExtrasServlet");
gridHubConfig.put("-port", "4444");
private static JsonObject getGridHubConfig() {
JsonObject gridHubConfig = new JsonObject();
gridHubConfig.addProperty("-role", "hub");
gridHubConfig.addProperty("-servlets", "com.groupon.seleniumgridextras.grid.servlets.SeleniumGridExtrasServlet");
gridHubConfig.addProperty("-port", "4444");

String hostIp = RuntimeConfig.getCurrentHostIP();
if (!hostIp.equals("")){
gridHubConfig.put("-host", hostIp);
gridHubConfig.addProperty("-host", hostIp);
}


return gridHubConfig;
}

private static JSONObject getGridNodeConfig() {
JSONObject gridNodeConfig = new JSONObject();
private static JsonObject getGridNodeConfig() {
JsonObject gridNodeConfig = new JsonObject();

gridNodeConfig.put("-role", "wd");
gridNodeConfig.put("-hub", "http://localhost:4444");
gridNodeConfig.put("-port", "4445");
gridNodeConfig.put("-nodeTimeout", "240");
gridNodeConfig.put("-maxSession", "1");
gridNodeConfig.addProperty("-role", "wd");
gridNodeConfig.addProperty("-hub", "http://localhost:4444");
gridNodeConfig.addProperty("-port", "4445");
gridNodeConfig.addProperty("-nodeTimeout", "240");
gridNodeConfig.addProperty("-maxSession", "1");

String hostIp = RuntimeConfig.getCurrentHostIP();
if (!hostIp.equals("")){
gridNodeConfig.put("-host", hostIp);
gridNodeConfig.addProperty("-host", hostIp);
}

gridNodeConfig.put("-proxy", "com.groupon.seleniumgridextras.grid.proxies.SetupTeardownProxy");
gridNodeConfig.addProperty("-proxy", "com.groupon.seleniumgridextras.grid.proxies.SetupTeardownProxy");

return gridNodeConfig;
}

private static void loadSharedDir() {
defaultConfig.put("expose_directory", "shared");
defaultConfig.addProperty("expose_directory", "shared");
}


@@ -1,5 +1,6 @@
package com.groupon.seleniumgridextras;

import com.google.gson.JsonObject;
import com.google.gson.annotations.SerializedName;

import java.util.HashMap;
@@ -44,7 +45,7 @@ public void setDescription(String description) {
this.description = description;
}

public Map<String, String> getResponseDescription() {
public JsonObject getResponseDescription() {
return getJsonResponse().getKeyDescriptions();
}

@@ -34,17 +34,16 @@
* Date: 5/10/13
* Time: 4:06 PM
*/

package com.groupon.seleniumgridextras;

import org.json.simple.JSONObject;
import com.google.gson.JsonObject;

import java.io.*;

public class FirstTimeRunConfig {


public static String toJsonString(JSONObject defaultConfig) {
public static String toJsonString(JsonObject defaultConfig) {
System.out.println(
"\n\n\n\nWe noticed this is a first time running, we will ask some configuration settings\n\n");

@@ -57,54 +56,54 @@ public static String toJsonString(JSONObject defaultConfig) {
System.out
.println("Than you, your answers were recorded to '" + RuntimeConfig.getConfigFile() + "'");
System.out.println("You can modify this file directly to tweak more options");
return defaultConfig.toJSONString();
return defaultConfig.toString();
}


private static JSONObject setGridHubAutostart(JSONObject defaultConfig) {
private static JsonObject setGridHubAutostart(JsonObject defaultConfig) {
String value = askQuestion("Do you want Grid Hub to be auto started? (1-yes/0-no)", "0");
JSONObject grid = (JSONObject) defaultConfig.get("grid");
grid.put("auto_start_hub", value);
JsonObject grid = (JsonObject) defaultConfig.get("grid");
grid.addProperty("auto_start_hub", value);
return defaultConfig;
}

private static JSONObject setGridNodeAutostart(JSONObject defaultConfig) {
private static JsonObject setGridNodeAutostart(JsonObject defaultConfig) {
String value = askQuestion("Do you want Grid Node to be auto started? (1-yes/0-no)", "1");
JSONObject grid = (JSONObject) defaultConfig.get("grid");
grid.put("auto_start_node", value);
JsonObject grid = (JsonObject) defaultConfig.get("grid");
grid.addProperty("auto_start_node", value);
return defaultConfig;
}

private static JSONObject setWebDriverVersion(JSONObject defaultConfig) {
JSONObject webdriver = (JSONObject) defaultConfig.get("webdriver");
private static JsonObject setWebDriverVersion(JsonObject defaultConfig) {
JsonObject webdriver = (JsonObject) defaultConfig.get("webdriver");
String currentVersion = webdriver.get("version").toString();

String newVersion = askQuestion("What version of webdriver JAR should we use?", currentVersion);

webdriver.put("version", newVersion);
webdriver.addProperty("version", newVersion);

return defaultConfig;
}

private static JSONObject setGridHubUrl(JSONObject defaultConfig) {
private static JsonObject setGridHubUrl(JsonObject defaultConfig) {

JSONObject grid = (JSONObject) defaultConfig.get("grid");
JSONObject nodeConfig = (JSONObject) grid.get("node");
JsonObject grid = (JsonObject) defaultConfig.get("grid");
JsonObject nodeConfig = (JsonObject) grid.get("node");

String url = askQuestion("What is the url for the Selenium Grid Hub?", "http://localhost:4444");

nodeConfig.put("-hub", url);
nodeConfig.addProperty("-hub", url);

return defaultConfig;
}


private static JSONObject setDefaultService(JSONObject defaultConfig) {
JSONObject grid = (JSONObject) defaultConfig.get("grid");
private static JsonObject setDefaultService(JsonObject defaultConfig) {
JsonObject grid = (JsonObject) defaultConfig.get("grid");

String role = askQuestion("What is the default Role of this computer? (hub|node)", "node");

grid.put("default_role", role);
grid.addProperty("default_role", role);

return defaultConfig;
}

0 comments on commit 4d9bada

Please sign in to comment.
You can’t perform that action at this time.