Skip to content

Commit

Permalink
prevent json package depending on remote
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Jul 3, 2019
1 parent 593c17a commit 5263a2d
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 222 deletions.
1 change: 0 additions & 1 deletion java/client/src/org/openqa/selenium/json/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ java_library(
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium:core",
"//java/client/src/org/openqa/selenium/remote:api",
],
visibility = [
"//java/client/src/org/openqa/...",
Expand Down
1 change: 0 additions & 1 deletion java/client/src/org/openqa/selenium/json/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ java_library(
],
deps = [
"//java/client/src/org/openqa/selenium:core",
"//java/client/src/org/openqa/selenium/remote:api",
],
)
68 changes: 0 additions & 68 deletions java/client/src/org/openqa/selenium/json/CommandCoercer.java

This file was deleted.

2 changes: 0 additions & 2 deletions java/client/src/org/openqa/selenium/json/JsonOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.openqa.selenium.json;

import org.openqa.selenium.logging.LogLevelMapping;
import org.openqa.selenium.remote.SessionId;

import java.io.Closeable;
import java.io.File;
Expand Down Expand Up @@ -131,7 +130,6 @@ public class JsonOutput implements Closeable {
builder.put(URL.class::isAssignableFrom, (obj, depth) -> append(asString(((URL) obj).toExternalForm())));
builder.put(UUID.class::isAssignableFrom, (obj, depth) -> append(asString(((UUID) obj).toString())));
builder.put(Level.class::isAssignableFrom, (obj, depth) -> append(asString(LogLevelMapping.getName((Level) obj))));
builder.put(SessionId.class::isAssignableFrom, (obj, depth) -> append(asString(obj)));
builder.put(
GSON_ELEMENT,
(obj, depth) -> {
Expand Down
3 changes: 0 additions & 3 deletions java/client/src/org/openqa/selenium/json/JsonTypeCoercer.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ private JsonTypeCoercer(Stream<TypeCoercer<?>> coercers) {
Capabilities.class,
this,
Collector.of(MutableCapabilities::new, (caps, entry) -> caps.setCapability((String) entry.getKey(), entry.getValue()), MutableCapabilities::merge, UNORDERED)));
builder.add(new CommandCoercer());
builder.add(new ResponseCoercer(this));
builder.add(new SessionIdCoercer());

// Container types
//noinspection unchecked
Expand Down
87 changes: 0 additions & 87 deletions java/client/src/org/openqa/selenium/json/ResponseCoercer.java

This file was deleted.

57 changes: 0 additions & 57 deletions java/client/src/org/openqa/selenium/json/SessionIdCoercer.java

This file was deleted.

4 changes: 1 addition & 3 deletions java/client/src/org/openqa/selenium/remote/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ java_library(
],
deps = [
"//java/client/src/org/openqa/selenium:core",
"//third_party/java/guava:guava",
],
visibility = [
"//java/client/src/org/openqa/selenium/json:json",
"//third_party/java/guava:guava",
],
)

Expand Down
1 change: 1 addition & 0 deletions java/client/src/org/openqa/selenium/remote/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ java_library(
],
deps = [
"//java/client/src/org/openqa/selenium:core",
"//java/client/src/org/openqa/selenium/json",
"//third_party/java/guava",
],
)
Expand Down
36 changes: 36 additions & 0 deletions java/client/src/org/openqa/selenium/remote/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

package org.openqa.selenium.remote;

import org.openqa.selenium.json.JsonInput;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import static org.openqa.selenium.json.Json.MAP_TYPE;

public class Command {

private final SessionId sessionId;
Expand Down Expand Up @@ -72,4 +76,36 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(sessionId, getName(), getParameters());
}

private static Command fromJson(JsonInput input) {
input.beginObject();

SessionId sessionId = null;
String name = null;
Map<String, Object> parameters = null;

while (input.hasNext()) {
switch (input.nextName()) {
case "name":
name = input.nextString();
break;

case "parameters":
parameters = input.read(MAP_TYPE);
break;

case "sessionId":
sessionId = input.read(SessionId.class);
break;

default:
input.skipValue();
break;
}
}

input.endObject();

return new Command(sessionId, name, parameters);
}
}
41 changes: 41 additions & 0 deletions java/client/src/org/openqa/selenium/remote/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package org.openqa.selenium.remote;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

public class Response {

Expand Down Expand Up @@ -87,4 +89,43 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(value, sessionId, status, state);
}

private static Response fromJson(Map<String, Object> json) {
ErrorCodes errorCodes = new ErrorCodes();
Response response = new Response();

if (json.get("error") instanceof String) {
String state = (String) json.get("error");
response.setState(state);
response.setStatus(errorCodes.toStatus(state, Optional.empty()));
response.setValue(json.get("message"));
}

if (json.get("state") instanceof String) {
String state = (String) json.get("state");
response.setState(state);
response.setStatus(errorCodes.toStatus(state, Optional.empty()));
}

if (json.get("status") != null) {
Object status = json.get("status");
if (status instanceof String) {
String state = (String) status;
response.setState(state);
response.setStatus(errorCodes.toStatus(state, Optional.empty()));
} else {
int intStatus = ((Number) status).intValue();
response.setState(errorCodes.toState(intStatus));
response.setStatus(intStatus);
}
}

if (json.get("sessionId") instanceof String) {
response.setSessionId((String) json.get("sessionId"));
}

response.setValue(json.getOrDefault("value", json));

return response;
}
}

0 comments on commit 5263a2d

Please sign in to comment.