Java tutorial
/* FailFileDescriptorProfileTestCase.java Copyright (c) 2014 NTT DOCOMO,INC. Released under the MIT license http://opensource.org/licenses/mit-license.php */ package org.deviceconnect.android.profile.restful.test; import java.io.UnsupportedEncodingException; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.StringBody; import org.deviceconnect.android.test.plugin.profile.TestFileDescriptorProfileConstants; import org.deviceconnect.message.DConnectMessage; import org.deviceconnect.message.DConnectMessage.ErrorCode; import org.deviceconnect.profile.AuthorizationProfileConstants; import org.deviceconnect.profile.DConnectProfileConstants; import org.deviceconnect.profile.FileDescriptorProfileConstants; import org.deviceconnect.utils.URIBuilder; import org.json.JSONException; import org.json.JSONObject; /** * FileDescriptor?. * @author NTT DOCOMO, INC. */ public class FailFileDescriptorProfileTestCase extends RESTfulDConnectTestCase { /** * . * * @param tag */ public FailFileDescriptorProfileTestCase(final String tag) { super(tag); } /** * deviceId?????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/open?mediaId=xxxx&flag=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetOpenNoDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_OPEN); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(FileDescriptorProfileConstants.PARAM_FLAG, "r"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.EMPTY_DEVICE_ID.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/open?deviceId=&mediaId=xxxx&flag=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetOpenEmptyDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_OPEN); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, ""); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(FileDescriptorProfileConstants.PARAM_FLAG, "r"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ???deviceId???. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/open?deviceId=123456789&mediaId=xxxx&flag=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetOpenInvalidDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_OPEN); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(FileDescriptorProfileConstants.PARAM_FLAG, "r"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ???????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/open?deviceId=xxxxx&mediaId=xxxx&flag=xxxx&abc=abc * </pre> * <pre> * ?? * ??????? * result?0??????? * </pre> */ public void testGetOpenUndefinedAttribute() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_OPEN); builder.addParameter("abc", "abc"); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(FileDescriptorProfileConstants.PARAM_FLAG, "r"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultOK(root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId2??????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/open?deviceId=123456789&deviceId=xxx&mediaId=xxxx&flag=xxxx * </pre> * <pre> * ?? * ??????? * result?1??????? * </pre> */ public void testGetOpenDuplicatedDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_OPEN); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(FileDescriptorProfileConstants.PARAM_FLAG, "r"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * mediaId?????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/open?deviceId=xxxx&flag=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetOpenNoPath() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_OPEN); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_FLAG, "r"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.INVALID_REQUEST_PARAMETER.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * flag?????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/open?deviceId=xxxx&mediaId=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetOpenNoFlag() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_OPEN); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.INVALID_REQUEST_PARAMETER.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?POST????. * <pre> * ?HTTP * Method: POST * Path: /file_descriptor/open?deviceId=xxxx&mediaId=xxxx&flag=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetOpenInvalidMethodPost() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_OPEN); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(FileDescriptorProfileConstants.PARAM_FLAG, "r"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPost(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_SUPPORT_ACTION.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?PUT????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/open?deviceId=xxxx&mediaId=xxxx&flag=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetOpenInvalidMethodPut() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_OPEN); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(FileDescriptorProfileConstants.PARAM_FLAG, "r"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.UNKNOWN_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?DELETE????. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/open?deviceId=xxxx&mediaId=xxxx&flag=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetOpenInvalidMethodDelete() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_OPEN); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(FileDescriptorProfileConstants.PARAM_FLAG, "r"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.UNKNOWN_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId?????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/close?mediaId=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutCloseNoDeviceID() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_CLOSE); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.EMPTY_DEVICE_ID.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/close?deviceId=&mediaId=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutCloseEmptyDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_CLOSE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, ""); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ???deviceId???. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/close?deviceId=123456789&mediaId=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutCloseInvalidDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_CLOSE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ???????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/close?deviceId=xxxxx&mediaId=xxxx&abc=abc * </pre> * <pre> * ?? * ??????? * result?0??????? * </pre> */ public void testPutCloseUndefinedAttribute() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_CLOSE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter("abc", "abc"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultOK(root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId2??????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/close?deviceId=123456789&deviceId=xxx&mediaId=xxxx * </pre> * <pre> * ?? * ??????? * result?1??????? * </pre> */ public void testPutCloseDuplicatedDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_CLOSE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?GET????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/close?deviceId=xxxx&mediaId=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutCloseInvalidMethodGet() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_CLOSE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.UNKNOWN_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?POST????. * <pre> * ?HTTP * Method: POST * Path: /file_descriptor/close?deviceId=xxxx&mediaId=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutCloseInvalidMethodPost() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_CLOSE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPost(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_SUPPORT_ACTION.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?DELETE????. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/close?deviceId=xxxx&mediaId=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutCloseInvalidMethodDelete() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_CLOSE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.UNKNOWN_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId??????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/read?mediaId=xxxx&length=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetReadNoDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_READ); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.EMPTY_DEVICE_ID.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId?????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/read?deviceId=&mediaId=xxxx&length=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetReadEmptyDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_READ); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, ""); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ???deviceId????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/read?deviceId=123456789&mediaId=xxxx&length=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetReadInvalidDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_READ); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ????????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/read?deviceId=xxxxx&mediaId=xxxx&length=xxxx&abc=abc * </pre> * <pre> * ?? * ??????? * result?0??????? * </pre> */ public void testGetReadUndefinedAttribute() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_READ); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(FileDescriptorProfileConstants.PARAM_LENGTH, "1"); builder.addParameter("abc", "abc"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultOK(root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId2???????. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/read?deviceId=123456789&deviceId=xxx&mediaId=xxxx&length=xxxx * </pre> * <pre> * ?? * ??????? * result?1??????? * </pre> */ public void testGetReadDuplicatedDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_READ); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * mediaId??????. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/read?deviceId=xxxx&length=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetReadNoPath() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_READ); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_LENGTH, String.valueOf(TestFileDescriptorProfileConstants.BYTE)); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.INVALID_REQUEST_PARAMETER.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * length??????. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/read?deviceId=xxxx&mediaId=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetReadNoLength() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_READ); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.INVALID_REQUEST_PARAMETER.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?POST?????. * <pre> * ?HTTP * Method: POST * Path: /file_descriptor/read?deviceId=xxxx&mediaId=xxxx&length=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetReadInvalidMethodPost() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_READ); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPost(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_SUPPORT_ACTION.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?PUT?????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/read?deviceId=xxxx&mediaId=xxxx&length=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetReadInvalidMethodPut() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_READ); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.UNKNOWN_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?DELETE?????. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/read?deviceId=xxxx&mediaId=xxxx&length=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testGetReadInvalidMethodDelete() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_READ); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.UNKNOWN_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId???????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/write?mediaId=xxxx * Multipart: media * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutWriteNoDeviceID() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_WRITE); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.EMPTY_DEVICE_ID.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId??????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/write?deviceId=&mediaId=xxxx * Multipart: media * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutWriteEmptyDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_WRITE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, ""); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ???deviceId?????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/write?deviceId=123456789&mediId=xxxx * Multipart: media * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutWriteInvalidDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_WRITE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?????????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/write?deviceId=xxxxx&mediaId=xxxx&abc=abc * Multipart: media * </pre> * <pre> * ?? * ??????? * result?0??????? * </pre> */ public void testPutWriteUndefinedAttribute() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_WRITE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter("abc", "abc"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { MultipartEntity entity = new MultipartEntity(); entity.addPart("media", new StringBody("test")); HttpPut request = new HttpPut(builder.toString()); request.addHeader("Content-Disposition", "form-data; name=\"media\"; filename=\"test.txt\""); request.setEntity(entity); JSONObject root = sendRequest(request); assertResultOK(root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } catch (UnsupportedEncodingException e) { fail("Exception in StringBody." + e.getMessage()); } } /** * deviceId2????????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/write?deviceId=123456789&deviceId=xxx&mediaId=xxxx * Multipart: media * </pre> * <pre> * ?? * ??????? * result?1??????? * </pre> */ public void testPutWriteDuplicatedDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_WRITE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?GET??????. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/write?deviceId=xxxx&mediaId=xxxx * Multipart: media * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutWriteInvalidMethodGet() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_WRITE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.UNKNOWN_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?POST??????. * <pre> * ?HTTP * Method: POST * Path: /file_descriptor/write?deviceId=xxxx&mediaId=xxxx * Multipart: media * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutWriteInvalidMethodPost() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_WRITE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPost(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_SUPPORT_ACTION.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?DELETE??????. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/write?deviceId=xxxx&mediaId=xxxx * Multipart: media * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutWriteInvalidMethodDelete() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_WRITE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(FileDescriptorProfileConstants.PARAM_PATH, TestFileDescriptorProfileConstants.PATH); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.UNKNOWN_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId???onwatchfile???. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/onwatchfile?sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutOnWatchFileNoDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.EMPTY_DEVICE_ID.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId??onwatchfile???. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/onwatchfile?deviceId=&sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutOnWatchFileEmptyDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, ""); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ???deviceId?onwatchfile???. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/onwatchfile?deviceId=123456789&sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutOnWatchFileInvalidDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?????onwatchfile???. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/onwatchfile?devicdId=xxxxx&sessionKey=xxxx&abc=abc * </pre> * <pre> * ?? * ??????? * result?0??????? * charging?false??????? * </pre> */ public void testPutOnWatchFileUndefinedAttribute() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter("abc", "abc"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultOK(root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId2????onwatchfile???. * <pre> * ?HTTP * Method: PUT * Path: /file_descriptor/onwatchfile?deviceId=123456789&deviceId=xxx&sessionKey=xxxx * </pre> * <pre> * ?? * ??????? * result?1??????? * </pre> */ public void testPutOnWatchFileDuplicatedDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?GET??onwatchfile??. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/onwatchfile?deviceId=xxxx&sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutOnWatchFileInvalidMethodGet() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(DConnectProfileConstants.PARAM_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.UNKNOWN_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?POST??onwatchfile??. * <pre> * ?HTTP * Method: POST * Path: /file_descriptor/onwatchfile?deviceId=xxxx&sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testPutOnWatchFileInvalidMethodPost() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(DConnectProfileConstants.PARAM_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPost(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_SUPPORT_ACTION.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId???onwatchfile???. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/onwatchfile?sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testDeleteOnWatchFileNoDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.EMPTY_DEVICE_ID.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId??onwatchfile???. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/onwatchfile?deviceId=&sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testDeleteOnWatchFileEmptyDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, ""); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ???deviceId?onwatchfile???. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/onwatchfile?deviceId=123456789&sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testDeleteOnWatchFileInvalidDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?????onwatchfile???. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/onwatchfile?devicdId=xxxxx&sessionKey=xxxx&abc=abc * </pre> * <pre> * ?? * ??????? * result?0??????? * charging?false??????? * </pre> */ public void testDeleteOnWatchFileUndefinedAttribute() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter("abc", "abc"); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultOK(root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * deviceId2????onwatchfile???. * <pre> * ?HTTP * Method: DELETE * Path: /file_descriptor/onwatchfile?deviceId=123456789&deviceId=xxx&sessionKey=xxxx * </pre> * <pre> * ?? * ??????? * result?1??????? * </pre> */ public void testDeleteOnWatchFileDuplicatedDeviceId() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, "123456789"); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(DConnectMessage.EXTRA_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_FOUND_DEVICE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?GET??onwatchfile??. * <pre> * ?HTTP * Method: GET * Path: /file_descriptor/onwatchfile?deviceId=xxxx&sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testDeleteOnWatchFileInvalidMethodGet() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(DConnectProfileConstants.PARAM_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.UNKNOWN_ATTRIBUTE.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } /** * ?POST??onwatchfile??. * <pre> * ?HTTP * Method: POST * Path: /file_descriptor/onwatchfile?deviceId=xxxx&sessionKey=xxxx * </pre> * <pre> * ?? * result?1??????? * </pre> */ public void testDeleteOnWatchFileInvalidMethodPost() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(FileDescriptorProfileConstants.PROFILE_NAME); builder.setAttribute(FileDescriptorProfileConstants.ATTRIBUTE_ON_WATCH_FILE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(DConnectProfileConstants.PARAM_SESSION_KEY, TEST_SESSION_KEY); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPost(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_SUPPORT_ACTION.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } }