NCMBObjectService extends NCMBService { public void updateObjectInBackground(String className, String objectId, JSONObject params, ExecuteServiceCallback callback) { if (!validateClassName(className) || !validateObjectId(objectId)){ callback.done(null, new NCMBException(NCMBException.REQUIRED, "className / objectId is must not be null or empty")); } else { String url = mContext.baseUrl + mServicePath + className + "/" + objectId; String type = NCMBRequest.HTTP_METHOD_PUT; try { sendRequestAsync(url, type, params.toString(), null, new ObjectServiceCallback(this, callback) { @Override public void handleResponse(NCMBResponse response) { ExecuteServiceCallback callback = (ExecuteServiceCallback) mCallback; if (callback != null) { callback.done(response.responseData, null); } } @Override public void handleError(NCMBException e) { ExecuteServiceCallback callback = (ExecuteServiceCallback) mCallback; if (callback != null) { callback.done(null, e); } } }); } catch (NCMBException e) { if (callback != null) { callback.done(null, e); } } } } NCMBObjectService(NCMBContext context); JSONObject saveObject(String className, JSONObject params); void saveObjectInBackground(String className, JSONObject params, ExecuteServiceCallback callback); NCMBObject fetchObject(String className,String objectId); void fetchObjectInBackground(final String className, String objectId, final FetchCallback callback); JSONObject updateObject(String className, String objectId, JSONObject params); void updateObjectInBackground(String className, String objectId, JSONObject params, ExecuteServiceCallback callback); JSONObject deleteObject(String className,String objectId); void deleteObjectInBackground(String className, String objectId, ExecuteServiceCallback callback); List searchObject(String className, JSONObject conditions); void searchObjectInBackground(final String className, JSONObject conditions, SearchObjectCallback callback); int countObject(String className, JSONObject conditions); void countObjectInBackground(final String className, JSONObject conditions, CountCallback callback); static final String SERVICE_PATH; }
@Test public void updateObjectInBackground_valid_class() throws Exception { Assert.assertFalse(callbackFlag); NCMBObjectService objServ = (NCMBObjectService) NCMB.factory(NCMB.ServiceType.OBJECT); objServ.updateObjectInBackground( "TestClass", "updateTestObjectId", new JSONObject("{\"updateKey\":\"updateValue\"}"), new ExecuteServiceCallback() { @Override public void done(JSONObject json, NCMBException e) { response = json; callbackFlag = true; } } ); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); Assert.assertTrue(callbackFlag); Assert.assertEquals("2014-06-04T11:28:30.348Z", response.getString("updateDate")); }