/** - 内容:sendInBackground(POST)が成功することを確認する - 結果:非同期でプッシュの送信が出来る事 */ @Test public void sendInBackground_post() throws Exception { Assert.assertFalse(callbackFlag); // post NCMBPush push = new NCMBPush(); push.setMessage("message"); push.setTitle("title"); push.sendInBackground( new DoneCallback() { @Override public void done(NCMBException e) { Assert.assertNull(e); callbackFlag = true; } }); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); Assert.assertTrue(callbackFlag); // check Assert.assertEquals("message", push.getMessage()); Assert.assertEquals("title", push.getTitle()); Assert.assertEquals("7FrmPTBKSNtVjajm", push.getObjectId()); DateFormat format = NCMBDateFormat.getIso8601(); Assert.assertEquals(format.parse("2014-06-03T11:28:30.348Z"), push.getCreateDate()); }
/** - 内容:send(POST)が成功することを確認する - 結果:同期でプッシュの送信が出来る事 */ @Test public void send_post() throws Exception { // post NCMBException error = null; NCMBPush push = new NCMBPush(); try { push.send(); } catch (NCMBException e) { error = e; } // check Assert.assertNull(error); Assert.assertEquals("7FrmPTBKSNtVjajm", push.getObjectId()); DateFormat format = NCMBDateFormat.getIso8601(); Assert.assertEquals(format.parse("2014-06-03T11:28:30.348Z"), push.getCreateDate()); }
/** - 内容:sendInBackground(callback無し)が成功することを確認する - 結果:非同期でプッシュの送信が出来る事 */ @Test public void sendInBackground_none_callback() throws Exception { // post NCMBPush push = new NCMBPush(); push.setMessage("message"); push.setTitle("title"); push.sendInBackground(); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); // check Assert.assertEquals("message", push.getMessage()); Assert.assertEquals("title", push.getTitle()); Assert.assertEquals("7FrmPTBKSNtVjajm", push.getObjectId()); DateFormat format = NCMBDateFormat.getIso8601(); Assert.assertEquals(format.parse("2014-06-03T11:28:30.348Z"), push.getCreateDate()); Assert.assertEquals(format.parse("2014-06-03T11:28:30.348Z"), push.getUpdateDate()); }
/** - 内容:setSearchConditionで設定してプッシュ送信が出来るか確認する - 結果:エラーが発生せずにsetSearchConditionの値が取得出来る事 */ @Test public void setSearchCondition() throws Exception { // post NCMBPush push = new NCMBPush(); NCMBQuery<NCMBInstallation> query = new NCMBQuery<>("installation"); query.whereGreaterThan("score", 80); push.setSearchCondition(query); NCMBException error = null; try { push.send(); } catch (NCMBException e) { error = e; } // check Assert.assertNull(error); Assert.assertEquals(80, push.getSearchCondition().getJSONObject("score").getInt("$gt")); DateFormat format = NCMBDateFormat.getIso8601(); Assert.assertEquals(format.parse("2014-06-03T11:28:30.348Z"), push.getCreateDate()); Assert.assertEquals(format.parse("2014-06-03T11:28:30.348Z"), push.getUpdateDate()); }
/** - 内容:send(PUT)が成功することを確認する - 結果:同期でプッシュの更新が出来る事 */ @Test public void send_put() throws Exception { NCMBException error = null; Date date = new Date(); date.setTime(date.getTime() + 60 * 60 * 24 * 1000); // post NCMBPush push = new NCMBPush(); try { push.setTitle("title"); push.setMessage("message"); push.setDeliveryTime(date); // 配信日時1日後 push.send(); } catch (NCMBException e) { error = e; } Assert.assertNull(error); Assert.assertEquals("title", push.getTitle()); Assert.assertEquals("message", push.getMessage()); Assert.assertEquals("7FrmPTBKSNtVjajm", push.getObjectId()); // put try { push.setTitle("title_update"); push.setMessage("message_update"); push.send(); } catch (NCMBException e) { error = e; } // check Assert.assertNull(error); Assert.assertEquals("title_update", push.getTitle()); Assert.assertEquals("message_update", push.getMessage()); DateFormat format = NCMBDateFormat.getIso8601(); Assert.assertEquals(format.parse("2014-06-04T11:28:30.348Z"), push.getUpdateDate()); }