ParsePushController { ParseRESTCommand buildRESTSendPushCommand(ParsePush.State state, String sessionToken) { return ParseRESTPushCommand.sendPushCommand(state.queryState(), state.channelSet(), state.expirationTime(), state.expirationTimeInterval(), state.pushTime(), state.data(), sessionToken); } ParsePushController(ParseHttpClient restClient); Task<Void> sendInBackground(ParsePush.State state, String sessionToken);  }
@Test public void testBuildRESTSendPushCommandWithChannelSet() throws Exception { ParseHttpClient restClient = mock(ParseHttpClient.class); ParsePushController controller = new ParsePushController(restClient); JSONObject data = new JSONObject(); data.put(ParsePush.KEY_DATA_MESSAGE, "hello world"); List<String> expectedChannelSet = new ArrayList<String>() {{ add("foo"); add("bar"); add("yarr"); }}; ParsePush.State state = new ParsePush.State.Builder() .data(data) .channelSet(expectedChannelSet) .build(); ParseRESTCommand pushCommand = controller.buildRESTSendPushCommand(state, "sessionToken"); JSONObject jsonParameters = pushCommand.jsonParameters; assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_PUSH_TIME)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_EXPIRATION_TIME)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_EXPIRATION_INTERVAL)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_WHERE)); assertEquals("hello world", jsonParameters.getJSONObject(ParseRESTPushCommand.KEY_DATA) .getString(ParsePush.KEY_DATA_MESSAGE)); JSONArray pushChannels = jsonParameters.getJSONArray(ParseRESTPushCommand.KEY_CHANNELS); assertEquals(new JSONArray(expectedChannelSet), pushChannels, JSONCompareMode.NON_EXTENSIBLE); }
@Test public void testBuildRESTSendPushCommandWithExpirationTime() throws Exception { ParseHttpClient restClient = mock(ParseHttpClient.class); ParsePushController controller = new ParsePushController(restClient); JSONObject data = new JSONObject(); data.put(ParsePush.KEY_DATA_MESSAGE, "hello world"); ParsePush.State state = new ParsePush.State.Builder() .data(data) .expirationTime((long) 1400000000) .build(); ParseRESTCommand pushCommand = controller.buildRESTSendPushCommand(state, "sessionToken"); JSONObject jsonParameters = pushCommand.jsonParameters; assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_PUSH_TIME)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_EXPIRATION_INTERVAL)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_CHANNELS)); assertEquals("{}", jsonParameters.get(ParseRESTPushCommand.KEY_WHERE).toString()); assertEquals("hello world", jsonParameters.getJSONObject(ParseRESTPushCommand.KEY_DATA) .getString(ParsePush.KEY_DATA_MESSAGE)); assertEquals(1400000000, jsonParameters.getLong(ParseRESTPushCommand.KEY_EXPIRATION_TIME)); }
@Test public void testBuildRESTSendPushCommandWithPushTime() throws Exception { ParseHttpClient restClient = mock(ParseHttpClient.class); ParsePushController controller = new ParsePushController(restClient); JSONObject data = new JSONObject(); data.put(ParsePush.KEY_DATA_MESSAGE, "hello world"); long pushTime = System.currentTimeMillis() / 1000 + 1000; ParsePush.State state = new ParsePush.State.Builder() .data(data) .pushTime(pushTime) .build(); ParseRESTCommand pushCommand = controller.buildRESTSendPushCommand(state, "sessionToken"); JSONObject jsonParameters = pushCommand.jsonParameters; assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_EXPIRATION_TIME)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_EXPIRATION_INTERVAL)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_CHANNELS)); assertEquals("{}", jsonParameters.get(ParseRESTPushCommand.KEY_WHERE).toString()); assertEquals("hello world", jsonParameters.getJSONObject(ParseRESTPushCommand.KEY_DATA) .getString(ParsePush.KEY_DATA_MESSAGE)); assertEquals(pushTime, jsonParameters.getLong(ParseRESTPushCommand.KEY_PUSH_TIME)); }
@Test public void testBuildRESTSendPushCommandWithExpirationTimeInterval() throws Exception { ParseHttpClient restClient = mock(ParseHttpClient.class); ParsePushController controller = new ParsePushController(restClient); JSONObject data = new JSONObject(); data.put(ParsePush.KEY_DATA_MESSAGE, "hello world"); ParsePush.State state = new ParsePush.State.Builder() .data(data) .expirationTimeInterval((long) 86400) .build(); ParseRESTCommand pushCommand = controller.buildRESTSendPushCommand(state, "sessionToken"); JSONObject jsonParameters = pushCommand.jsonParameters; assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_PUSH_TIME)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_EXPIRATION_TIME)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_CHANNELS)); assertEquals("{}", jsonParameters.get(ParseRESTPushCommand.KEY_WHERE).toString()); assertEquals("hello world", jsonParameters.getJSONObject(ParseRESTPushCommand.KEY_DATA) .getString(ParsePush.KEY_DATA_MESSAGE)); assertEquals(86400, jsonParameters.getLong(ParseRESTPushCommand.KEY_EXPIRATION_INTERVAL)); }
@Test public void testBuildRESTSendPushCommandWithQuery() throws Exception { ParseHttpClient restClient = mock(ParseHttpClient.class); ParsePushController controller = new ParsePushController(restClient); JSONObject data = new JSONObject(); data.put(ParsePush.KEY_DATA_MESSAGE, "hello world"); ParseQuery<ParseInstallation> query = ParseInstallation.getQuery(); query.whereEqualTo("language", "en/US"); query.whereLessThan("version", "1.2"); ParsePush.State state = new ParsePush.State.Builder() .data(data) .query(query) .build(); ParseRESTCommand pushCommand = controller.buildRESTSendPushCommand(state, "sessionToken"); JSONObject jsonParameters = pushCommand.jsonParameters; assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_PUSH_TIME)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_EXPIRATION_TIME)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_EXPIRATION_INTERVAL)); assertFalse(jsonParameters.getJSONObject(ParseRESTPushCommand.KEY_WHERE) .has(ParseRESTPushCommand.KEY_DEVICE_TYPE)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_CHANNELS)); assertEquals("hello world", jsonParameters .getJSONObject(ParseRESTPushCommand.KEY_DATA) .getString(ParsePush.KEY_DATA_MESSAGE)); JSONObject pushQuery = jsonParameters.getJSONObject(ParseRESTPushCommand.KEY_WHERE); assertEquals("en/US", pushQuery.getString("language")); JSONObject inequality = pushQuery.getJSONObject("version"); assertEquals("1.2", inequality.getString("$lt")); }
@Test public void testBuildRESTSendPushCommandWithPushToIOSAndAndroid() throws Exception { ParseHttpClient restClient = mock(ParseHttpClient.class); ParsePushController controller = new ParsePushController(restClient); JSONObject data = new JSONObject(); data.put(ParsePush.KEY_DATA_MESSAGE, "hello world"); ParsePush.State state = new ParsePush.State.Builder() .data(data) .build(); ParseRESTCommand pushCommand = controller.buildRESTSendPushCommand(state, "sessionToken"); JSONObject jsonParameters = pushCommand.jsonParameters; assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_PUSH_TIME)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_EXPIRATION_TIME)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_EXPIRATION_INTERVAL)); assertFalse(jsonParameters.has(ParseRESTPushCommand.KEY_CHANNELS)); assertEquals("hello world", jsonParameters.getJSONObject(ParseRESTPushCommand.KEY_DATA) .getString(ParsePush.KEY_DATA_MESSAGE)); assertFalse(jsonParameters.getJSONObject(ParseRESTPushCommand.KEY_WHERE) .has(ParseRESTPushCommand.KEY_DEVICE_TYPE)); }