/** - 内容:executeScriptInBackgroundが成功することを確認する - 結果:エラーが発生しないこと */ @Test public void executeScriptInBackground() throws Exception { NCMBScriptService scriptService = (NCMBScriptService) NCMB.factory(NCMB.ServiceType.SCRIPT); scriptService.executeScriptInBackground( "testScript.js", NCMBScript.MethodType.GET, null, null, null, mScriptUrl, new ExecuteScriptCallback() { @Override public void done(byte[] result, NCMBException e) { if (e != null) { Assert.fail(e.getMessage()); } else { try { Assert.assertEquals("hello", new String(result, "UTF-8")); } catch (UnsupportedEncodingException error) { Assert.fail(error.getMessage()); } } mCallbackFlag = true; } }); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); Assert.assertTrue(mCallbackFlag); }
/** - 内容:executeScriptが成功することを確認する - 結果:エラーが発生しないこと */ @Test public void executeScript() throws Exception { NCMBScriptService scriptService = (NCMBScriptService) NCMB.factory(NCMB.ServiceType.SCRIPT); byte[] result = scriptService.executeScript( "testScript.js", NCMBScript.MethodType.GET, null, null, null, mScriptUrl); Assert.assertEquals("hello", new String(result, "UTF-8")); }
/** - 内容:Instanceの値が正しく取得出来るかを確認する - 結果:値が正しく取得されていること */ @Test public void checkInstanceGet() throws Exception { // set Instance data NCMBPushService pushService = (NCMBPushService) NCMB.factory(NCMB.ServiceType.PUSH); NCMBPush fetchedPush = pushService.fetchPush("7FrmPTBKSNtVjajm"); NCMBPush push = new NCMBPush(fetchedPush.mFields); // check get checkGetResponse(push); }
@Before public void setup() throws Exception { ShadowLog.stream = System.out; mServer = new MockWebServer(); mServer.setDispatcher(NCMBDispatcher.dispatcher); mServer.start(); mScriptUrl = mServer.getUrl("/").toString() + "2015-09-01/script"; NCMB.initialize( RuntimeEnvironment.application.getApplicationContext(), "appKey", "cliKey", null, null); Robolectric.getBackgroundThreadScheduler().pause(); Robolectric.getForegroundThreadScheduler().pause(); mCallbackFlag = false; }
@Before public void setup() throws Exception { // create mocServer mServer = new MockWebServer(); mServer.setDispatcher(NCMBDispatcher.dispatcher); mServer.start(); // initialize NCMB.initialize( RuntimeEnvironment.application.getApplicationContext(), "appKey", "cliKey", mServer.getUrl("/").toString(), null); // log stream ShadowLog.stream = System.out; Robolectric.getBackgroundThreadScheduler().pause(); Robolectric.getForegroundThreadScheduler().pause(); callbackFlag = false; }