NCMBInstallationService extends NCMBService { public JSONObject updateInstallation(String objectId, JSONObject params) throws NCMBException { try { params = argumentNullCheckForPUT(objectId, params); try { setInstallationBasicData(params); } catch (JSONException e) { throw new NCMBException(NCMBException.INVALID_JSON, "Invalid json format."); } catch (PackageManager.NameNotFoundException e) { throw new NCMBException(NCMBException.DATA_NOT_FOUND, "PackageManager not found."); } RequestParams request = createRequestParams(objectId, params, null, NCMBRequest.HTTP_METHOD_PUT); NCMBResponse response = sendRequest(request); if (response.statusCode != HTTP_STATUS_INSTALLATION_UPDATED) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, "Updated failed."); } writeCurrentInstallation(params, response.responseData); return response.responseData; } catch (NCMBException error) { checkDataNotFound(objectId, error.getCode()); throw error; } } NCMBInstallationService(NCMBContext context); JSONObject createInstallation(String registrationId, JSONObject params); void createInstallationInBackground(String registrationId, JSONObject params, final ExecuteServiceCallback callback); JSONObject updateInstallation(String objectId, JSONObject params); void updateInstallationInBackground(final String objectId, JSONObject params, final ExecuteServiceCallback callback); void deleteInstallation(String objectId); void deleteInstallationInBackground(final String objectId, DoneCallback callback); NCMBInstallation fetchInstallation(String objectId); void fetchInstallationInBackground(String objectId, final FetchCallback callback); List searchInstallation(JSONObject conditions); void searchInstallationInBackground(JSONObject conditions, final SearchInstallationCallback callback); static final String SERVICE_PATH; static final int HTTP_STATUS_INSTALLATION_CREATED; static final int HTTP_STATUS_INSTALLATION_UPDATED; static final int HTTP_STATUS_INSTALLATION_DELETED; static final int HTTP_STATUS_INSTALLATION_GOTTEN; }
@Test public void updateInstallation() throws Exception { Exception error = null; JSONObject json = null; try { NCMBInstallationService installationService = (NCMBInstallationService) NCMB.factory(NCMB.ServiceType.INSTALLATION); JSONObject updateData = new JSONObject(); updateData.put("key", "value_update"); json = installationService.updateInstallation("7FrmPTBKSNtVjajm", updateData); } catch (Exception e) { error = e; } Assert.assertNull(error); Assert.assertEquals("2014-06-04T11:28:30.348Z", json.getString("updateDate")); }
@Test public void currentInstallation_v1_From_v2() throws Exception { JSONObject localFileData = new JSONObject(); localFileData.put("appVersion", "1.0"); localFileData.put("deviceToken", "dummyDeviceToken"); localFileData.put("objectId", "non-update-value-id"); localFileData.put("key", "value"); localFileData.put("applicationName", "AndroidSDK_v1"); localFileData.put("classname", "installation"); localFileData.put("channels", new JSONArray("[Ch2]")); localFileData.put("timeZone", "Asia\\/Tokyo"); localFileData.put("createDate", "2015-09-10T02:24:03.597Z"); localFileData.put("updateDate", "2015-09-11T02:24:03.597Z"); localFileData.put("sdkVersion", "1.5.0"); File localFile = new File(NCMB.getCurrentContext().context.getDir("NCMB", Context.MODE_PRIVATE), "currentInstallation"); try { FileOutputStream out = new FileOutputStream(localFile); out.write(localFileData.toString().getBytes("UTF-8")); out.close(); } catch (IOException e) { throw new RuntimeException(e); } NCMBInstallation currentInstallation = NCMBInstallation.getCurrentInstallation(); Assert.assertEquals("1.5.0", currentInstallation.getSDKVersion()); Assert.assertEquals("non-update-value-id", currentInstallation.getObjectId()); Assert.assertEquals("value", currentInstallation.getString("key")); Assert.assertEquals("dummyDeviceToken", currentInstallation.getLocalDeviceToken()); Assert.assertEquals("1.0", currentInstallation.getAppVersion()); Assert.assertEquals("AndroidSDK_v1", currentInstallation.getApplicationName()); Assert.assertEquals(new JSONArray("[Ch2]"), currentInstallation.getChannels()); Assert.assertEquals("Asia\\/Tokyo", currentInstallation.getTimeZone()); DateFormat format = NCMBDateFormat.getIso8601(); Date resultCreateDate = format.parse("2015-09-10T02:24:03.597Z"); Assert.assertEquals(resultCreateDate, currentInstallation.getCreateDate()); Date resultUpdateDate = format.parse("2015-09-11T02:24:03.597Z"); Assert.assertEquals(resultUpdateDate, currentInstallation.getUpdateDate()); NCMBInstallationService installationService = (NCMBInstallationService) NCMB.factory(NCMB.ServiceType.INSTALLATION); JSONObject updateJson = installationService.updateInstallation(currentInstallation.getObjectId(), null); Assert.assertEquals("2014-06-04T11:28:30.348Z", updateJson.getString("updateDate")); currentInstallation = NCMBInstallation.getCurrentInstallation(); Assert.assertEquals("3.0.4", currentInstallation.getSDKVersion()); }