Search in sources :

Example 1 with RtmMessage

use of com.fitpay.android.webview.events.RtmMessage in project fitpay-android-sdk by fitpay.

the class RtmParserTest method testWebAppVersionSameWrongData.

@Test
public void testWebAppVersionSameWrongData() {
    String rtmMsgStr = "{\"callbackId\":\"0\",\"type\":\"version\"}";
    RtmMessage msg = Constants.getGson().fromJson(rtmMsgStr, RtmMessage.class);
    int webAppRtmVersion = RtmType.RTM_VERSION;
    String errorMsg = null;
    try {
        RtmParserImpl.parse(wvci, webAppRtmVersion, msg);
    } catch (IllegalStateException e) {
        errorMsg = e.getMessage();
    }
    assertEquals("missing required message data", errorMsg);
}
Also used : RtmMessage(com.fitpay.android.webview.events.RtmMessage) Test(org.junit.Test)

Example 2 with RtmMessage

use of com.fitpay.android.webview.events.RtmMessage in project fitpay-android-sdk by fitpay.

the class RtmParserTest method testWebAppVersionHigher.

@Test
public void testWebAppVersionHigher() {
    String rtmMsgStr = "{\"callbackId\":\"0\",\"data\":\"{\\\"version\\\":3}\",\"type\":\"version\"}";
    RtmMessage msg = Constants.getGson().fromJson(rtmMsgStr, RtmMessage.class);
    int webAppRtmVersion = RtmType.RTM_VERSION + 1;
    String errorMsg = null;
    try {
        RtmParserImpl.parse(wvci, webAppRtmVersion, msg);
    } catch (IllegalStateException e) {
        errorMsg = e.getMessage();
    }
    assertEquals("WebApp RTM version:" + webAppRtmVersion + " is not supported", errorMsg);
}
Also used : RtmMessage(com.fitpay.android.webview.events.RtmMessage) Test(org.junit.Test)

Example 3 with RtmMessage

use of com.fitpay.android.webview.events.RtmMessage in project fitpay-android-sdk by fitpay.

the class UnrecognizedMessageTest method testUnrecognizedRtmMessage.

@Test
public void testUnrecognizedRtmMessage() {
    String rtmMsgStr = "{\"callbackId\":\"10\",\"data\":\"{\\\"resource\\\":\\\"The Truth Is Out There\\\"}\",\"type\":\"somethingUnknown\"}";
    RtmMessage msg = Constants.getGson().fromJson(rtmMsgStr, RtmMessage.class);
    RxBus.getInstance().post(msg);
    try {
        FPLog.d("UnrecognizedMessageTest", "start:" + System.currentTimeMillis());
        latch.await(30, TimeUnit.SECONDS);
        FPLog.d("UnrecognizedMessageTest", "end:" + System.currentTimeMillis());
    } catch (InterruptedException e) {
        FPLog.d("UnrecognizedMessageTest", "exception:" + System.currentTimeMillis());
        e.printStackTrace();
    }
    assertNotNull("unrecognized message shouldn't be null", message);
    UnrecognizedRtmData data = Constants.getGson().fromJson(message.getJsonData(), UnrecognizedRtmData.class);
    assertEquals("unrecognized message data should be equal", "The Truth Is Out There", data.resource);
}
Also used : RtmMessage(com.fitpay.android.webview.events.RtmMessage) BearerTokenTest(com.fitpay.android.BearerTokenTest) Test(org.junit.Test)

Example 4 with RtmMessage

use of com.fitpay.android.webview.events.RtmMessage in project fitpay-android-sdk by fitpay.

the class RtmParserTest method testWebAppVersionLower.

@Test
public void testWebAppVersionLower() {
    String rtmMsgStr = "{\"callbackId\":\"0\",\"data\":\"{\\\"version\\\":3}\",\"type\":\"version\"}";
    RtmMessage msg = Constants.getGson().fromJson(rtmMsgStr, RtmMessage.class);
    int webAppRtmVersion = 2;
    String errorMsg = null;
    try {
        RtmParserImpl.parse(wvci, webAppRtmVersion, msg);
    } catch (IllegalStateException e) {
        errorMsg = e.getMessage();
    }
    Assert.assertNull(errorMsg);
}
Also used : RtmMessage(com.fitpay.android.webview.events.RtmMessage) Test(org.junit.Test)

Example 5 with RtmMessage

use of com.fitpay.android.webview.events.RtmMessage in project fitpay-android-sdk by fitpay.

the class RtmParserTest method testWebAppVersionSameNoMethod.

@Ignore("needs to be rewritten, we don't throw exceptions anymore... needs to listen to RxBus instead for the unrecognized message")
@Test
public void testWebAppVersionSameNoMethod() {
    String rtmMsgStr = "{\"callbackId\":\"9\",\"data\":\"{\\\"next\\\":\\\"\\\\/walletAccess\\\",\\\"previous\\\":\\\"\\\\/cards\\\"}\",\"type\":\"navigationStart\"}";
    RtmMessage msg = Constants.getGson().fromJson(rtmMsgStr, RtmMessage.class);
    int webAppRtmVersion = 3;
    String errorMsg = "";
    try {
        RtmParserImpl.parse(wvci, webAppRtmVersion, msg);
    } catch (IllegalStateException e) {
        errorMsg = e.getMessage();
    }
    assertEquals("unsupported action value navigationStart", errorMsg);
}
Also used : RtmMessage(com.fitpay.android.webview.events.RtmMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

RtmMessage (com.fitpay.android.webview.events.RtmMessage)7 Test (org.junit.Test)6 JavascriptInterface (android.webkit.JavascriptInterface)1 BearerTokenTest (com.fitpay.android.BearerTokenTest)1 JSONObject (org.json.JSONObject)1 Ignore (org.junit.Ignore)1