mirror of
https://github.com/status-im/react-native.git
synced 2025-01-15 20:15:11 +00:00
break dependency between JSPackagerClient.RequestHandler and WebSocketListener
Reviewed By: amnn Differential Revision: D4810406 fbshipit-source-id: a447bc15c6619921edd7adf0b3d1d93ae04e2e43
This commit is contained in:
parent
ec68c97d72
commit
175e77d004
@ -23,7 +23,6 @@ import java.util.regex.Pattern;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.facebook.common.logging.FLog;
|
import com.facebook.common.logging.FLog;
|
||||||
import com.facebook.infer.annotation.Assertions;
|
import com.facebook.infer.annotation.Assertions;
|
||||||
@ -34,6 +33,10 @@ import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
|
|||||||
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;
|
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;
|
||||||
import com.facebook.react.packagerconnection.FileIoHandler;
|
import com.facebook.react.packagerconnection.FileIoHandler;
|
||||||
import com.facebook.react.packagerconnection.JSPackagerClient;
|
import com.facebook.react.packagerconnection.JSPackagerClient;
|
||||||
|
import com.facebook.react.packagerconnection.RequestHandler;
|
||||||
|
import com.facebook.react.packagerconnection.NotificationOnlyHandler;
|
||||||
|
import com.facebook.react.packagerconnection.RequestOnlyHandler;
|
||||||
|
import com.facebook.react.packagerconnection.Responder;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -95,8 +98,8 @@ public class DevServerHelper {
|
|||||||
|
|
||||||
public interface PackagerCommandListener {
|
public interface PackagerCommandListener {
|
||||||
void onPackagerReloadCommand();
|
void onPackagerReloadCommand();
|
||||||
void onCaptureHeapCommand(@Nullable final JSPackagerClient.Responder responder);
|
void onCaptureHeapCommand(@Nullable final Responder responder);
|
||||||
void onPokeSamplingProfilerCommand(@Nullable final JSPackagerClient.Responder responder);
|
void onPokeSamplingProfilerCommand(@Nullable final Responder responder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final DevInternalSettings mSettings;
|
private final DevInternalSettings mSettings;
|
||||||
@ -129,23 +132,23 @@ public class DevServerHelper {
|
|||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... backgroundParams) {
|
protected Void doInBackground(Void... backgroundParams) {
|
||||||
Map<String, JSPackagerClient.RequestHandler> handlers =
|
Map<String, RequestHandler> handlers =
|
||||||
new HashMap<String, JSPackagerClient.RequestHandler>();
|
new HashMap<String, RequestHandler>();
|
||||||
handlers.put("reload", new JSPackagerClient.NotificationOnlyHandler() {
|
handlers.put("reload", new NotificationOnlyHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onNotification(@Nullable Object params) {
|
public void onNotification(@Nullable Object params) {
|
||||||
commandListener.onPackagerReloadCommand();
|
commandListener.onPackagerReloadCommand();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
handlers.put("captureHeap", new JSPackagerClient.RequestOnlyHandler() {
|
handlers.put("captureHeap", new RequestOnlyHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onRequest(@Nullable Object params, JSPackagerClient.Responder responder) {
|
public void onRequest(@Nullable Object params, Responder responder) {
|
||||||
commandListener.onCaptureHeapCommand(responder);
|
commandListener.onCaptureHeapCommand(responder);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
handlers.put("pokeSamplingProfiler", new JSPackagerClient.RequestOnlyHandler() {
|
handlers.put("pokeSamplingProfiler", new RequestOnlyHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onRequest(@Nullable Object params, JSPackagerClient.Responder responder) {
|
public void onRequest(@Nullable Object params, Responder responder) {
|
||||||
commandListener.onPokeSamplingProfilerCommand(responder);
|
commandListener.onPokeSamplingProfilerCommand(responder);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -44,6 +44,7 @@ import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
|
|||||||
import com.facebook.react.devsupport.interfaces.StackFrame;
|
import com.facebook.react.devsupport.interfaces.StackFrame;
|
||||||
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
|
import com.facebook.react.modules.debug.interfaces.DeveloperSettings;
|
||||||
import com.facebook.react.packagerconnection.JSPackagerClient;
|
import com.facebook.react.packagerconnection.JSPackagerClient;
|
||||||
|
import com.facebook.react.packagerconnection.Responder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -674,7 +675,7 @@ public class DevSupportManagerImpl implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCaptureHeapCommand(final JSPackagerClient.Responder responder) {
|
public void onCaptureHeapCommand(final Responder responder) {
|
||||||
UiThreadUtil.runOnUiThread(new Runnable() {
|
UiThreadUtil.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -684,7 +685,7 @@ public class DevSupportManagerImpl implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPokeSamplingProfilerCommand(@Nullable final JSPackagerClient.Responder responder) {
|
public void onPokeSamplingProfilerCommand(@Nullable final Responder responder) {
|
||||||
UiThreadUtil.runOnUiThread(new Runnable() {
|
UiThreadUtil.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -693,7 +694,7 @@ public class DevSupportManagerImpl implements
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleCaptureHeap(final JSPackagerClient.Responder responder) {
|
private void handleCaptureHeap(final Responder responder) {
|
||||||
if (mCurrentContext == null) {
|
if (mCurrentContext == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -713,7 +714,7 @@ public class DevSupportManagerImpl implements
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePokeSamplingProfiler(@Nullable final JSPackagerClient.Responder responder) {
|
private void handlePokeSamplingProfiler(@Nullable final Responder responder) {
|
||||||
try {
|
try {
|
||||||
List<String> pokeResults = JSCSamplingProfiler.poke(60000);
|
List<String> pokeResults = JSCSamplingProfiler.poke(60000);
|
||||||
for (String result : pokeResults) {
|
for (String result : pokeResults) {
|
||||||
|
@ -62,17 +62,17 @@ public class FileIoHandler implements Runnable {
|
|||||||
private int mNextHandle;
|
private int mNextHandle;
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
private final Map<Integer, TtlFileInputStream> mOpenFiles;
|
private final Map<Integer, TtlFileInputStream> mOpenFiles;
|
||||||
private final Map<String, JSPackagerClient.RequestHandler> mRequestHandlers;
|
private final Map<String, RequestHandler> mRequestHandlers;
|
||||||
|
|
||||||
public FileIoHandler() {
|
public FileIoHandler() {
|
||||||
mNextHandle = 1;
|
mNextHandle = 1;
|
||||||
mHandler = new Handler(Looper.getMainLooper());
|
mHandler = new Handler(Looper.getMainLooper());
|
||||||
mOpenFiles = new HashMap<>();
|
mOpenFiles = new HashMap<>();
|
||||||
mRequestHandlers = new HashMap<>();
|
mRequestHandlers = new HashMap<>();
|
||||||
mRequestHandlers.put("fopen", new JSPackagerClient.RequestOnlyHandler() {
|
mRequestHandlers.put("fopen", new RequestOnlyHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onRequest(
|
public void onRequest(
|
||||||
@Nullable Object params, JSPackagerClient.Responder responder) {
|
@Nullable Object params, Responder responder) {
|
||||||
synchronized (mOpenFiles) {
|
synchronized (mOpenFiles) {
|
||||||
try {
|
try {
|
||||||
JSONObject paramsObj = (JSONObject)params;
|
JSONObject paramsObj = (JSONObject)params;
|
||||||
@ -98,10 +98,10 @@ public class FileIoHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mRequestHandlers.put("fclose", new JSPackagerClient.RequestOnlyHandler() {
|
mRequestHandlers.put("fclose", new RequestOnlyHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onRequest(
|
public void onRequest(
|
||||||
@Nullable Object params, JSPackagerClient.Responder responder) {
|
@Nullable Object params, Responder responder) {
|
||||||
synchronized (mOpenFiles) {
|
synchronized (mOpenFiles) {
|
||||||
try {
|
try {
|
||||||
if (!(params instanceof Number)) {
|
if (!(params instanceof Number)) {
|
||||||
@ -121,10 +121,10 @@ public class FileIoHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mRequestHandlers.put("fread", new JSPackagerClient.RequestOnlyHandler() {
|
mRequestHandlers.put("fread", new RequestOnlyHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onRequest(
|
public void onRequest(
|
||||||
@Nullable Object params, JSPackagerClient.Responder responder) {
|
@Nullable Object params, Responder responder) {
|
||||||
synchronized (mOpenFiles) {
|
synchronized (mOpenFiles) {
|
||||||
try {
|
try {
|
||||||
JSONObject paramsObj = (JSONObject)params;
|
JSONObject paramsObj = (JSONObject)params;
|
||||||
@ -153,7 +153,7 @@ public class FileIoHandler implements Runnable {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, JSPackagerClient.RequestHandler> handlers() {
|
public Map<String, RequestHandler> handlers() {
|
||||||
return mRequestHandlers;
|
return mRequestHandlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,9 +8,6 @@
|
|||||||
|
|
||||||
package com.facebook.react.packagerconnection;
|
package com.facebook.react.packagerconnection;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -32,10 +29,10 @@ final public class JSPackagerClient implements ReconnectingWebSocket.MessageCall
|
|||||||
private static final String PACKAGER_CONNECTION_URL_FORMAT = "ws://%s/message?device=%s&app=%s&context=%s";
|
private static final String PACKAGER_CONNECTION_URL_FORMAT = "ws://%s/message?device=%s&app=%s&context=%s";
|
||||||
private static final int PROTOCOL_VERSION = 2;
|
private static final int PROTOCOL_VERSION = 2;
|
||||||
|
|
||||||
public class Responder {
|
private class ResponderImpl implements Responder {
|
||||||
private Object mId;
|
private Object mId;
|
||||||
|
|
||||||
public Responder(Object id) {
|
public ResponderImpl(Object id) {
|
||||||
mId = id;
|
mId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,26 +61,6 @@ final public class JSPackagerClient implements ReconnectingWebSocket.MessageCall
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface RequestHandler {
|
|
||||||
public void onRequest(@Nullable Object params, Responder responder);
|
|
||||||
public void onNotification(@Nullable Object params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static abstract class NotificationOnlyHandler implements RequestHandler {
|
|
||||||
final public void onRequest(@Nullable Object params, Responder responder) {
|
|
||||||
responder.error("Request is not supported");
|
|
||||||
FLog.e(TAG, "Request is not supported");
|
|
||||||
}
|
|
||||||
abstract public void onNotification(@Nullable Object params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static abstract class RequestOnlyHandler implements RequestHandler {
|
|
||||||
abstract public void onRequest(@Nullable Object params, Responder responder);
|
|
||||||
final public void onNotification(@Nullable Object params) {
|
|
||||||
FLog.e(TAG, "Notification is not supported");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ReconnectingWebSocket mWebSocket;
|
private ReconnectingWebSocket mWebSocket;
|
||||||
private Map<String, RequestHandler> mRequestHandlers;
|
private Map<String, RequestHandler> mRequestHandlers;
|
||||||
|
|
||||||
@ -149,7 +126,7 @@ final public class JSPackagerClient implements ReconnectingWebSocket.MessageCall
|
|||||||
if (id == null) {
|
if (id == null) {
|
||||||
handler.onNotification(params);
|
handler.onNotification(params);
|
||||||
} else {
|
} else {
|
||||||
handler.onRequest(params, new Responder(id));
|
handler.onRequest(params, new ResponderImpl(id));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
FLog.e(TAG, "Handling the message failed", e);
|
FLog.e(TAG, "Handling the message failed", e);
|
||||||
@ -160,7 +137,7 @@ final public class JSPackagerClient implements ReconnectingWebSocket.MessageCall
|
|||||||
|
|
||||||
private void abortOnMessage(Object id, String reason) {
|
private void abortOnMessage(Object id, String reason) {
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
(new Responder(id)).error(reason);
|
(new ResponderImpl(id)).error(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
FLog.e(TAG, "Handling the message failed with reason: " + reason);
|
FLog.e(TAG, "Handling the message failed with reason: " + reason);
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the LICENSE file in the root
|
||||||
|
* directory of this source tree. An additional grant of patent rights can be found in the PATENTS
|
||||||
|
* file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.facebook.react.packagerconnection;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.facebook.common.logging.FLog;
|
||||||
|
|
||||||
|
public abstract class NotificationOnlyHandler implements RequestHandler {
|
||||||
|
private static final String TAG = JSPackagerClient.class.getSimpleName();
|
||||||
|
|
||||||
|
final public void onRequest(@Nullable Object params, Responder responder) {
|
||||||
|
responder.error("Request is not supported");
|
||||||
|
FLog.e(TAG, "Request is not supported");
|
||||||
|
}
|
||||||
|
abstract public void onNotification(@Nullable Object params);
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the LICENSE file in the root
|
||||||
|
* directory of this source tree. An additional grant of patent rights can be found in the PATENTS
|
||||||
|
* file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.facebook.react.packagerconnection;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public interface RequestHandler {
|
||||||
|
void onRequest(@Nullable Object params, Responder responder);
|
||||||
|
void onNotification(@Nullable Object params);
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the LICENSE file in the root
|
||||||
|
* directory of this source tree. An additional grant of patent rights can be found in the PATENTS
|
||||||
|
* file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.facebook.react.packagerconnection;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.facebook.common.logging.FLog;
|
||||||
|
|
||||||
|
public abstract class RequestOnlyHandler implements RequestHandler {
|
||||||
|
private static final String TAG = JSPackagerClient.class.getSimpleName();
|
||||||
|
|
||||||
|
abstract public void onRequest(@Nullable Object params, Responder responder);
|
||||||
|
final public void onNotification(@Nullable Object params) {
|
||||||
|
FLog.e(TAG, "Notification is not supported");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015-present, Facebook, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the LICENSE file in the root
|
||||||
|
* directory of this source tree. An additional grant of patent rights can be found in the PATENTS
|
||||||
|
* file in the same directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.facebook.react.packagerconnection;
|
||||||
|
|
||||||
|
public interface Responder {
|
||||||
|
void respond(Object result);
|
||||||
|
void error(Object error);
|
||||||
|
}
|
@ -25,10 +25,10 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class JSPackagerClientTest {
|
public class JSPackagerClientTest {
|
||||||
private static Map<String, JSPackagerClient.RequestHandler> createRH(
|
private static Map<String, RequestHandler> createRH(
|
||||||
String action, JSPackagerClient.RequestHandler handler) {
|
String action, RequestHandler handler) {
|
||||||
Map<String, JSPackagerClient.RequestHandler> m =
|
Map<String, RequestHandler> m =
|
||||||
new HashMap<String, JSPackagerClient.RequestHandler>();
|
new HashMap<String, RequestHandler>();
|
||||||
m.put(action, handler);
|
m.put(action, handler);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ public class JSPackagerClientTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_onMessage_ShouldTriggerNotification() throws IOException {
|
public void test_onMessage_ShouldTriggerNotification() throws IOException {
|
||||||
JSPackagerClient.RequestHandler handler = mock(JSPackagerClient.RequestHandler.class);
|
RequestHandler handler = mock(RequestHandler.class);
|
||||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||||
|
|
||||||
client.onMessage(
|
client.onMessage(
|
||||||
@ -52,12 +52,12 @@ public class JSPackagerClientTest {
|
|||||||
WebSocket.TEXT,
|
WebSocket.TEXT,
|
||||||
"{\"version\": 2, \"method\": \"methodValue\", \"params\": \"paramsValue\"}"));
|
"{\"version\": 2, \"method\": \"methodValue\", \"params\": \"paramsValue\"}"));
|
||||||
verify(handler).onNotification(eq("paramsValue"));
|
verify(handler).onNotification(eq("paramsValue"));
|
||||||
verify(handler, never()).onRequest(any(), any(JSPackagerClient.Responder.class));
|
verify(handler, never()).onRequest(any(), any(Responder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_onMessage_ShouldTriggerRequest() throws IOException {
|
public void test_onMessage_ShouldTriggerRequest() throws IOException {
|
||||||
JSPackagerClient.RequestHandler handler = mock(JSPackagerClient.RequestHandler.class);
|
RequestHandler handler = mock(RequestHandler.class);
|
||||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||||
|
|
||||||
client.onMessage(
|
client.onMessage(
|
||||||
@ -65,12 +65,12 @@ public class JSPackagerClientTest {
|
|||||||
WebSocket.TEXT,
|
WebSocket.TEXT,
|
||||||
"{\"version\": 2, \"id\": \"idValue\", \"method\": \"methodValue\", \"params\": \"paramsValue\"}"));
|
"{\"version\": 2, \"id\": \"idValue\", \"method\": \"methodValue\", \"params\": \"paramsValue\"}"));
|
||||||
verify(handler, never()).onNotification(any());
|
verify(handler, never()).onNotification(any());
|
||||||
verify(handler).onRequest(eq("paramsValue"), any(JSPackagerClient.Responder.class));
|
verify(handler).onRequest(eq("paramsValue"), any(Responder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_onMessage_WithoutParams_ShouldTriggerNotification() throws IOException {
|
public void test_onMessage_WithoutParams_ShouldTriggerNotification() throws IOException {
|
||||||
JSPackagerClient.RequestHandler handler = mock(JSPackagerClient.RequestHandler.class);
|
RequestHandler handler = mock(RequestHandler.class);
|
||||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||||
|
|
||||||
client.onMessage(
|
client.onMessage(
|
||||||
@ -78,12 +78,12 @@ public class JSPackagerClientTest {
|
|||||||
WebSocket.TEXT,
|
WebSocket.TEXT,
|
||||||
"{\"version\": 2, \"method\": \"methodValue\"}"));
|
"{\"version\": 2, \"method\": \"methodValue\"}"));
|
||||||
verify(handler).onNotification(eq(null));
|
verify(handler).onNotification(eq(null));
|
||||||
verify(handler, never()).onRequest(any(), any(JSPackagerClient.Responder.class));
|
verify(handler, never()).onRequest(any(), any(Responder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_onMessage_WithInvalidContentType_ShouldNotTriggerCallback() throws IOException {
|
public void test_onMessage_WithInvalidContentType_ShouldNotTriggerCallback() throws IOException {
|
||||||
JSPackagerClient.RequestHandler handler = mock(JSPackagerClient.RequestHandler.class);
|
RequestHandler handler = mock(RequestHandler.class);
|
||||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||||
|
|
||||||
client.onMessage(
|
client.onMessage(
|
||||||
@ -91,12 +91,12 @@ public class JSPackagerClientTest {
|
|||||||
WebSocket.BINARY,
|
WebSocket.BINARY,
|
||||||
"{\"version\": 2, \"method\": \"methodValue\"}"));
|
"{\"version\": 2, \"method\": \"methodValue\"}"));
|
||||||
verify(handler, never()).onNotification(any());
|
verify(handler, never()).onNotification(any());
|
||||||
verify(handler, never()).onRequest(any(), any(JSPackagerClient.Responder.class));
|
verify(handler, never()).onRequest(any(), any(Responder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_onMessage_WithoutMethod_ShouldNotTriggerCallback() throws IOException {
|
public void test_onMessage_WithoutMethod_ShouldNotTriggerCallback() throws IOException {
|
||||||
JSPackagerClient.RequestHandler handler = mock(JSPackagerClient.RequestHandler.class);
|
RequestHandler handler = mock(RequestHandler.class);
|
||||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||||
|
|
||||||
client.onMessage(
|
client.onMessage(
|
||||||
@ -104,12 +104,12 @@ public class JSPackagerClientTest {
|
|||||||
WebSocket.TEXT,
|
WebSocket.TEXT,
|
||||||
"{\"version\": 2}"));
|
"{\"version\": 2}"));
|
||||||
verify(handler, never()).onNotification(any());
|
verify(handler, never()).onNotification(any());
|
||||||
verify(handler, never()).onRequest(any(), any(JSPackagerClient.Responder.class));
|
verify(handler, never()).onRequest(any(), any(Responder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_onMessage_With_Null_Action_ShouldNotTriggerCallback() throws IOException {
|
public void test_onMessage_With_Null_Action_ShouldNotTriggerCallback() throws IOException {
|
||||||
JSPackagerClient.RequestHandler handler = mock(JSPackagerClient.RequestHandler.class);
|
RequestHandler handler = mock(RequestHandler.class);
|
||||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||||
|
|
||||||
client.onMessage(
|
client.onMessage(
|
||||||
@ -117,12 +117,12 @@ public class JSPackagerClientTest {
|
|||||||
WebSocket.TEXT,
|
WebSocket.TEXT,
|
||||||
"{\"version\": 2, \"method\": null}"));
|
"{\"version\": 2, \"method\": null}"));
|
||||||
verify(handler, never()).onNotification(any());
|
verify(handler, never()).onNotification(any());
|
||||||
verify(handler, never()).onRequest(any(), any(JSPackagerClient.Responder.class));
|
verify(handler, never()).onRequest(any(), any(Responder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_onMessage_WithInvalidMethod_ShouldNotTriggerCallback() throws IOException {
|
public void test_onMessage_WithInvalidMethod_ShouldNotTriggerCallback() throws IOException {
|
||||||
JSPackagerClient.RequestHandler handler = mock(JSPackagerClient.RequestHandler.class);
|
RequestHandler handler = mock(RequestHandler.class);
|
||||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||||
|
|
||||||
client.onMessage(
|
client.onMessage(
|
||||||
@ -130,12 +130,12 @@ public class JSPackagerClientTest {
|
|||||||
WebSocket.BINARY,
|
WebSocket.BINARY,
|
||||||
"{\"version\": 2, \"method\": \"methodValue2\"}"));
|
"{\"version\": 2, \"method\": \"methodValue2\"}"));
|
||||||
verify(handler, never()).onNotification(any());
|
verify(handler, never()).onNotification(any());
|
||||||
verify(handler, never()).onRequest(any(), any(JSPackagerClient.Responder.class));
|
verify(handler, never()).onRequest(any(), any(Responder.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_onMessage_WrongVersion_ShouldNotTriggerCallback() throws IOException {
|
public void test_onMessage_WrongVersion_ShouldNotTriggerCallback() throws IOException {
|
||||||
JSPackagerClient.RequestHandler handler = mock(JSPackagerClient.RequestHandler.class);
|
RequestHandler handler = mock(RequestHandler.class);
|
||||||
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
final JSPackagerClient client = new JSPackagerClient("test_client", mSettings, createRH("methodValue", handler));
|
||||||
|
|
||||||
client.onMessage(
|
client.onMessage(
|
||||||
@ -143,6 +143,6 @@ public class JSPackagerClientTest {
|
|||||||
WebSocket.TEXT,
|
WebSocket.TEXT,
|
||||||
"{\"version\": 1, \"method\": \"methodValue\"}"));
|
"{\"version\": 1, \"method\": \"methodValue\"}"));
|
||||||
verify(handler, never()).onNotification(any());
|
verify(handler, never()).onNotification(any());
|
||||||
verify(handler, never()).onRequest(any(), any(JSPackagerClient.Responder.class));
|
verify(handler, never()).onRequest(any(), any(Responder.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user