NCMBObjectService extends NCMBService { public void searchObjectInBackground(final String className, JSONObject conditions, SearchObjectCallback callback) { if (!validateClassName(className)){ callback.done(null, new NCMBException(NCMBException.REQUIRED, "className is must not be null or empty")); } String url = mContext.baseUrl + mServicePath + className; String type = NCMBRequest.HTTP_METHOD_GET; RequestParams reqParams = new RequestParams(); reqParams.url = url; reqParams.type = type; reqParams.query = conditions; try { sendRequestAsync(reqParams, new ObjectServiceCallback(this, callback){ @Override public void handleResponse(NCMBResponse response) { SearchObjectCallback callback = (SearchObjectCallback) mCallback; if (callback != null) { try { callback.done(createSearchResults(className, response.responseData), null); } catch (NCMBException callbackException) { callback.done(null, callbackException); } } } @Override public void handleError(NCMBException e) { SearchObjectCallback callback = (SearchObjectCallback) 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 searchObjectInBackground_valid_class() throws Exception { Assert.assertFalse(callbackFlag); NCMBObjectService objServ = (NCMBObjectService) NCMB.factory(NCMB.ServiceType.OBJECT); JSONObject conditions = new JSONObject("{\"where\":{\"key\":\"value\"},\"limit\":1}"); objServ.searchObjectInBackground("TestClass", conditions, new SearchObjectCallback() { @Override public void done(List result, NCMBException e) { searchResult = (ArrayList<NCMBObject>) result; callbackFlag = true; } }); Robolectric.flushBackgroundThreadScheduler(); ShadowLooper.runUiThreadTasks(); Assert.assertTrue(callbackFlag); Assert.assertEquals("8FgKqFlH8dZRDrBJ", searchResult.get(0).getObjectId()); }