Java tutorial
/* FailAvailabilityProfileTestCase.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 android.support.test.runner.AndroidJUnit4; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpUriRequest; import org.deviceconnect.message.DConnectMessage.ErrorCode; import org.deviceconnect.profile.AvailabilityProfileConstants; import org.deviceconnect.utils.URIBuilder; import org.json.JSONException; import org.json.JSONObject; import org.junit.Test; import org.junit.runner.RunWith; /** * Availability?. * @author NTT DOCOMO, INC. */ @RunWith(AndroidJUnit4.class) public class FailAvailabilityProfileTestCase extends RESTfulDConnectTestCase { @Override protected boolean isLocalOAuth() { return false; } @Override protected boolean isSearchDevices() { return false; } /** * ?POST?????. * <pre> * ?HTTP * Method: POST * Path: /availability * </pre> * <pre> * ?? * result?1??????? * </pre> */ @Test public void testGetAvailabilityInvalidMethodPost() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(AvailabilityProfileConstants.PROFILE_NAME); 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: /availability * </pre> * <pre> * ?? * result?1??????? * </pre> */ @Test public void testGetAvailabilityInvalidMethodPut() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(AvailabilityProfileConstants.PROFILE_NAME); try { HttpUriRequest request = new HttpPut(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: /availability * </pre> * <pre> * ?? * result?1??????? * </pre> */ @Test public void testGetAvailabilityInvalidMethodDelete() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(AvailabilityProfileConstants.PROFILE_NAME); try { HttpUriRequest request = new HttpDelete(builder.toString()); JSONObject root = sendRequest(request); assertResultError(ErrorCode.NOT_SUPPORT_ACTION.getCode(), root); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } } }