Skip to content

Commit

Permalink
Move support classes required for Grid TNG somewhere safe
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Aug 19, 2018
1 parent 8888d4b commit dbf0de8
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 47 deletions.
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;
package org.openqa.selenium.grid.session.remote;

import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.grid.session.ActiveSession;
Expand All @@ -29,7 +29,7 @@
import java.io.IOException;
import java.util.Objects;

public class ActiveSessionCommandExecutor implements CommandExecutor {
class ActiveSessionCommandExecutor implements CommandExecutor {

private final ActiveSession session;
private boolean active;
Expand Down
17 changes: 17 additions & 0 deletions java/server/src/org/openqa/selenium/grid/session/remote/BUCK
@@ -0,0 +1,17 @@
# BUILD FILE SYNTAX: SKYLARK

java_library(
name = "remote",
srcs = glob(["*.java"]),
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//java/server/src/org/openqa/selenium/grid/session:session",
"//java/server/src/org/openqa/selenium/grid/web:web",
"//java/server/src/org/openqa/selenium/remote/server/jmx:jmx",
"//third_party/java/guava:guava",
],
visibility = [
"//java/server/src/org/openqa/selenium/...",
"//java/server/test/org/openqa/selenium/grid/session/remote:remote",
],
)
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;
package org.openqa.selenium.grid.session.remote;

import static com.google.common.net.MediaType.JSON_UTF_8;
import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;
package org.openqa.selenium.grid.session.remote;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
Expand Down
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;
package org.openqa.selenium.grid.session.remote;

import static org.openqa.selenium.remote.Dialect.OSS;

Expand Down
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;
package org.openqa.selenium.grid.session.remote;


import static java.util.concurrent.TimeUnit.SECONDS;
Expand Down
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;
package org.openqa.selenium.grid.session.remote;

import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
Expand Down
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;
package org.openqa.selenium.grid.session.remote;

import java.io.IOException;
import java.io.Reader;
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.grid.session.ActiveSession;
import org.openqa.selenium.grid.session.SessionFactory;
import org.openqa.selenium.grid.session.remote.ServicedSession;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.Dialect;

Expand Down
8 changes: 1 addition & 7 deletions java/server/src/org/openqa/selenium/remote/server/BUCK
Expand Up @@ -64,27 +64,21 @@ java_library(name = 'server',
java_library(
name = 'webdriver-servlet',
srcs = [
'ActiveSessionCommandExecutor.java',
'ActiveSessionFactory.java',
'ActiveSessionListener.java',
'ActiveSessions.java',
'AllHandlers.java',
'DefaultPipeline.java',
'InMemorySession.java',
'NewSessionPipeline.java',
'Passthrough.java',
'ProtocolConverter.java',
'RemoteSession.java',
'ServicedSession.java',
'SessionCodec.java',
'TeeReader.java',
'WebDriverServlet.java',
] + glob(['commandhandler/*.java']),
provided_deps = [
'//third_party/java/servlet:javax.servlet-api',
],
exported_deps = [
'//java/server/src/org/openqa/selenium/grid/session:session',
'//java/server/src/org/openqa/selenium/grid/session/remote:remote',
'//java/server/src/org/openqa/selenium/grid/web:web',
],
deps = [
Expand Down
15 changes: 15 additions & 0 deletions java/server/test/org/openqa/selenium/grid/session/remote/BUCK
@@ -0,0 +1,15 @@
# BUILD FILE SYNTAX: SKYLARK

java_test(
name = "remote",
srcs = glob(["*.java"]),
labels = [
"small",
],
deps = [
"//java/client/src/org/openqa/selenium/remote:remote",
"//java/server/src/org/openqa/selenium/grid/session/remote:remote",
"//third_party/java/guava:guava",
"//third_party/java/junit:junit",
],
)
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;
package org.openqa.selenium.grid.session.remote;

import static java.net.HttpURLConnection.HTTP_OK;
import static java.nio.charset.StandardCharsets.UTF_8;
Expand Down
Expand Up @@ -15,25 +15,21 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;
package org.openqa.selenium.grid.session.remote;


import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.openqa.selenium.json.Json.MAP_TYPE;
import static org.openqa.selenium.remote.Dialect.W3C;
import static org.openqa.selenium.remote.ErrorCodes.UNHANDLED_ERROR;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;

import org.junit.Test;
import org.openqa.selenium.WebDriverException;
Expand All @@ -51,12 +47,12 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class ProtocolConverterTest {

private final static TypeToken<Map<String, Object>> MAP_TYPE = new TypeToken<Map<String, Object>>() {};
private final static Gson gson = new GsonBuilder().serializeNulls().create();
private final Json json = new Json();

@Test
public void shouldRoundTripASimpleCommand() throws IOException {
Expand All @@ -75,11 +71,11 @@ protected HttpResponse makeRequest(HttpRequest request) {
response.setHeader("Content-Type", MediaType.JSON_UTF_8.toString());
response.setHeader("Cache-Control", "none");

JsonObject obj = new JsonObject();
obj.addProperty("sessionId", sessionId.toString());
obj.addProperty("status", 0);
obj.add("value", JsonNull.INSTANCE);
String payload = gson.toJson(obj);
Map<String, Object> obj = new HashMap<>();
obj.put("sessionId", sessionId.toString());
obj.put("status", 0);
obj.put("value", null);
String payload = json.toJson(obj);
response.setContent(payload.getBytes(UTF_8));

return response;
Expand All @@ -99,7 +95,7 @@ protected HttpResponse makeRequest(HttpRequest request) {
assertEquals(MediaType.JSON_UTF_8, MediaType.parse(resp.getHeader("Content-type")));
assertEquals(HttpURLConnection.HTTP_OK, resp.getStatus());

Map<String, Object> parsed = new Gson().fromJson(resp.getContentString(), MAP_TYPE.getType());
Map<String, Object> parsed = json.toType(resp.getContentString(), MAP_TYPE);
assertNull(parsed.toString(), parsed.get("sessionId"));
assertTrue(parsed.toString(), parsed.containsKey("value"));
assertNull(parsed.toString(), parsed.get("value"));
Expand All @@ -120,7 +116,7 @@ public void shouldAliasAComplexCommand() throws IOException {
@Override
protected HttpResponse makeRequest(HttpRequest request) {
assertEquals(String.format("/session/%s/execute/sync", sessionId), request.getUri());
Map<String, Object> params = gson.fromJson(request.getContentString(), MAP_TYPE.getType());
Map<String, Object> params = json.toType(request.getContentString(), MAP_TYPE);

assertEquals(
ImmutableList.of(
Expand All @@ -132,11 +128,11 @@ protected HttpResponse makeRequest(HttpRequest request) {
response.setHeader("Content-Type", MediaType.JSON_UTF_8.toString());
response.setHeader("Cache-Control", "none");

JsonObject obj = new JsonObject();
obj.addProperty("sessionId", sessionId.toString());
obj.addProperty("status", 0);
obj.addProperty("value", true);
String payload = gson.toJson(obj);
Map<String, Object> obj = ImmutableMap.of(
"sessionId", sessionId.toString(),
"status", 0,
"value", true);
String payload = json.toJson(obj);
response.setContent(payload.getBytes(UTF_8));

return response;
Expand All @@ -156,7 +152,7 @@ protected HttpResponse makeRequest(HttpRequest request) {
assertEquals(MediaType.JSON_UTF_8, MediaType.parse(resp.getHeader("Content-type")));
assertEquals(HttpURLConnection.HTTP_OK, resp.getStatus());

Map<String, Object> parsed = new Gson().fromJson(resp.getContentString(), MAP_TYPE.getType());
Map<String, Object> parsed = json.toType(resp.getContentString(), MAP_TYPE);
assertNull(parsed.get("sessionId"));
assertTrue(parsed.containsKey("value"));
assertEquals(true, parsed.get("value"));
Expand Down Expand Up @@ -205,7 +201,7 @@ protected HttpResponse makeRequest(HttpRequest request) {
assertEquals(MediaType.JSON_UTF_8, MediaType.parse(resp.getHeader("Content-type")));
assertEquals(HTTP_INTERNAL_ERROR, resp.getStatus());

Map<String, Object> parsed = new Gson().fromJson(resp.getContentString(), MAP_TYPE.getType());
Map<String, Object> parsed = json.toType(resp.getContentString(), MAP_TYPE);
assertNull(parsed.get("sessionId"));
assertTrue(parsed.containsKey("value"));
@SuppressWarnings("unchecked") Map<String, Object> value =
Expand Down
Expand Up @@ -15,15 +15,14 @@
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.remote.server;
package org.openqa.selenium.grid.session.remote;

import static org.junit.Assert.assertEquals;

import com.google.gson.stream.JsonReader;

import org.junit.Test;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonInput;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
Expand All @@ -32,15 +31,15 @@
public class TeeReaderTest {

@Test
public void shouldDuplicateStreams() throws IOException {
public void shouldDuplicateStreams() {
String expected = "{\"key\": \"value\"}";
Reader source = new StringReader(expected);

StringWriter writer = new StringWriter();

Reader tee = new TeeReader(source, writer);

try (JsonReader reader = new JsonReader(tee)) {
try (JsonInput reader = new Json().newInput(tee)) {

reader.beginObject();
assertEquals("key", reader.nextName());
Expand Down
Expand Up @@ -38,14 +38,11 @@
DriverFactoryTest.class,
NewSessionPayloadTest.class,
NewSessionPipelineTest.class,
PassthroughTest.class,
ProtocolConverterTest.class,
ResponsesTest.class,
ResultConfigTest.class,
SendKeyToActiveElementTest.class,
SessionLogsTest.class,
SyntheticNewSessionPayloadTest.class,
TeeReaderTest.class,
UploadFileTest.class,
org.openqa.selenium.remote.server.commandhandler.UploadFileTest.class,
UtilsTest.class,
Expand Down

0 comments on commit dbf0de8

Please sign in to comment.