NCMBObjectService extends NCMBService { public NCMBObject fetchObject(String className,String objectId) throws NCMBException { if (!validateClassName(className) || !validateObjectId(objectId)){ throw new NCMBException(NCMBException.REQUIRED, "className / objectId is must not be null or empty"); } String url = mContext.baseUrl + mServicePath + className + "/" + objectId; String type = NCMBRequest.HTTP_METHOD_GET; NCMBResponse response = sendRequest(url, type); if (response.statusCode != NCMBResponse.HTTP_STATUS_OK) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, "Invalid status code"); } return new NCMBObject(className, response.responseData); } 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 fetchObject_valid_class() throws Exception { NCMBObjectService objServ = (NCMBObjectService) NCMB.factory(NCMB.ServiceType.OBJECT); NCMBObject obj = objServ.fetchObject( "TestClass", "getTestObjectId" ); Assert.assertEquals("7FrmPTBKSNtVjajm", obj.getString("objectId")); Assert.assertEquals("2014-06-03T11:28:30.348Z", obj.getString("createDate")); Assert.assertEquals("2014-06-03T11:28:30.348Z", obj.getString("updateDate")); Assert.assertEquals("{}", obj.getString("acl")); }