org.deviceconnect.android.profile.restful.test.NormalConnectProfileTestCase.java Source code

Java tutorial

Introduction

Here is the source code for org.deviceconnect.android.profile.restful.test.NormalConnectProfileTestCase.java

Source

/*
 NormalConnectProfileTestCase.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 junit.framework.Assert;

import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.deviceconnect.message.DConnectMessage;
import org.deviceconnect.profile.AuthorizationProfileConstants;
import org.deviceconnect.profile.ConnectProfileConstants;
import org.deviceconnect.profile.DConnectProfileConstants;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Connect?.
 * @author NTT DOCOMO, INC.
 */
public class NormalConnectProfileTestCase extends RESTfulDConnectTestCase {

    /**
     * .
     * @param tag 
     */
    public NormalConnectProfileTestCase(final String tag) {
        super(tag);
    }

    /**
     * WiFi(ON/OFF)??.
     * <pre>
     * ?HTTP
     * Method: GET
     * Path: /connect/wifi?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * power?true???????
     * </pre>
     */
    public void testGetWifi() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_WIFI);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpGet(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
            Assert.assertEquals("power is not equals.", true,
                    root.getBoolean(ConnectProfileConstants.PARAM_ENABLE));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * WiFi?.
     * <pre>
     * ?HTTP
     * Method: PUT
     * Path: /connect/wifi?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testPutWifi() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_WIFI);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpPut(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * WiFi?.
     * <pre>
     * ?HTTP
     * Method: DELETE
     * Path: /connect/wifi?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testDeleteWifi() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_WIFI);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpDelete(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * WiFi???.
     * <pre>
     * ?HTTP
     * Method: PUT
     * Path: /connect/wifichange?deviceid=xxxx&session_key=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testPutWifiChange() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_ON_WIFI_CHANGE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(DConnectProfileConstants.PARAM_SESSION_KEY + "=" + getClientId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpPut(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
            JSONObject event = waitForEvent();
            JSONObject connectStatus = event.getJSONObject(ConnectProfileConstants.PARAM_CONNECT_STATUS);
            Assert.assertNotNull(connectStatus);
            Assert.assertEquals(true, connectStatus.getBoolean(ConnectProfileConstants.PARAM_ENABLE));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * WiFi???.
     * <pre>
     * ?HTTP
     * Method: DELETE
     * Path: /connect/wifichange?deviceid=xxxx&session_key=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testDeleteWifiChange() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_ON_WIFI_CHANGE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(DConnectProfileConstants.PARAM_SESSION_KEY + "=" + getClientId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpDelete(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * Bluetooth(ON/OFF)??.
     * <pre>
     * ?HTTP
     * Method: GET
     * Path: /connect/bluetooth?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * power?true???????
     * </pre>
     */
    public void testGetBluetooth() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_BLUETOOTH);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpGet(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
            Assert.assertEquals("power is not equals.", true,
                    root.getBoolean(ConnectProfileConstants.PARAM_ENABLE));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * Bluetooth?.
     * <pre>
     * ?HTTP
     * Method: PUT
     * Path: /connect/bluetooth?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testPutBluetooth() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_BLUETOOTH);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpPut(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * Bluetooth?.
     * <pre>
     * ?HTTP
     * Method: DELETE
     * Path: /connect/bluetooth?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testDeleteBluetooth() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_BLUETOOTH);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpDelete(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * Bluetooth???.
     * <pre>
     * ?HTTP
     * Method: PUT
     * Path: /connect/bluetoothchange?deviceid=xxxx&session_key=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testPutBluetoothChange() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_ON_BLUETOOTH_CHANGE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(DConnectProfileConstants.PARAM_SESSION_KEY + "=" + getClientId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpPut(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
            JSONObject event = waitForEvent();
            JSONObject connectStatus = event.getJSONObject(ConnectProfileConstants.PARAM_CONNECT_STATUS);
            Assert.assertNotNull(connectStatus);
            Assert.assertEquals(true, connectStatus.getBoolean(ConnectProfileConstants.PARAM_ENABLE));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * Bluetooth???.
     * <pre>
     * ?HTTP
     * Method: DELETE
     * Path: /connect/bluetoothchange?deviceid=xxxx&session_key=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testDeleteBluetoothChange() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_ON_BLUETOOTH_CHANGE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(DConnectProfileConstants.PARAM_SESSION_KEY + "=" + getClientId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpDelete(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * Bluetooth????.
     * <pre>
     * ?HTTP
     * Method: PUT
     * Path: /connect/bluetooth/discoverable?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testPutBluetoothDiscoverable() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_BLUETOOTH);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_DISCOVERABLE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpPut(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * Bluetooth????.
     * <pre>
     * ?HTTP
     * Method: DELETE
     * Path: /connect/bluetooth/discoverable?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testDeleteBluetoothDiscoverable() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_BLUETOOTH);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_DISCOVERABLE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpDelete(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * NFC(ON/OFF)??.
     * <pre>
     * ?HTTP
     * Method: GET
     * Path: /connect/nfc?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * power?true???????
     * </pre>
     */
    public void testGetNFC() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_NFC);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpGet(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
            Assert.assertEquals("power is not equals.", true,
                    root.getBoolean(ConnectProfileConstants.PARAM_ENABLE));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * NFC?.
     * <pre>
     * ?HTTP
     * Method: PUT
     * Path: /connect/nfc?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testPutNFC() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_NFC);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpPut(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * NFC?.
     * <pre>
     * ?HTTP
     * Method: DELETE
     * Path: /connect/nfc?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testDeleteNFC() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_NFC);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpDelete(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * NFC???.
     * <pre>
     * ?HTTP
     * Method: PUT
     * Path: /connect/nfcchange?deviceid=xxxx&session_key=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testPutNFCChange() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_ON_NFC_CHANGE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(DConnectProfileConstants.PARAM_SESSION_KEY + "=" + getClientId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpPut(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
            JSONObject event = waitForEvent();
            JSONObject connectStatus = event.getJSONObject(ConnectProfileConstants.PARAM_CONNECT_STATUS);
            Assert.assertNotNull(connectStatus);
            Assert.assertEquals(true, connectStatus.getBoolean(ConnectProfileConstants.PARAM_ENABLE));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * NFC???.
     * <pre>
     * ?HTTP
     * Method: DELETE
     * Path: /connect/nfcchange?deviceid=xxxx&session_key=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testDeleteNFCChange() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_ON_NFC_CHANGE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(DConnectProfileConstants.PARAM_SESSION_KEY + "=" + getClientId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpDelete(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * BLE(ON/OFF)??.
     * <pre>
     * ?HTTP
     * Method: GET
     * Path: /connect/ble?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * power?true???????
     * </pre>
     */
    public void testGetBLE() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_BLE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpGet(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
            Assert.assertEquals("power is not equals.", true,
                    root.getBoolean(ConnectProfileConstants.PARAM_ENABLE));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * BLE?.
     * <pre>
     * ?HTTP
     * Method: PUT
     * Path: /connect/ble?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testPutBLE() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_BLE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpPut(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * BLE?.
     * <pre>
     * ?HTTP
     * Method: DELETE
     * Path: /connect/ble?deviceid=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testDeleteBLE() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_BLE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpDelete(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * BLE???.
     * <pre>
     * ?HTTP
     * Method: PUT
     * Path: /connect/blechange?deviceid=xxxx&session_key=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testPutBLEChange() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_ON_BLE_CHANGE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(DConnectProfileConstants.PARAM_SESSION_KEY + "=" + getClientId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpPut(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
            JSONObject event = waitForEvent();
            JSONObject connectStatus = event.getJSONObject(ConnectProfileConstants.PARAM_CONNECT_STATUS);
            Assert.assertNotNull(connectStatus);
            Assert.assertEquals(true, connectStatus.getBoolean(ConnectProfileConstants.PARAM_ENABLE));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }

    /**
     * BLE???.
     * <pre>
     * ?HTTP
     * Method: DELETE
     * Path: /connect/blechange?deviceid=xxxx&session_key=xxxx
     * </pre>
     * <pre>
     * ??
     * result?0???????
     * </pre>
     */
    public void testDeleteBLEChange() {
        StringBuilder builder = new StringBuilder();
        builder.append(DCONNECT_MANAGER_URI);
        builder.append("/" + ConnectProfileConstants.PROFILE_NAME);
        builder.append("/" + ConnectProfileConstants.ATTRIBUTE_ON_BLE_CHANGE);
        builder.append("?");
        builder.append(DConnectProfileConstants.PARAM_DEVICE_ID + "=" + getDeviceId());
        builder.append("&");
        builder.append(DConnectProfileConstants.PARAM_SESSION_KEY + "=" + getClientId());
        builder.append("&");
        builder.append(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN + "=" + getAccessToken());
        try {
            HttpUriRequest request = new HttpDelete(builder.toString());
            JSONObject root = sendRequest(request);
            Assert.assertNotNull("root is null.", root);
            Assert.assertEquals(DConnectMessage.RESULT_OK, root.getInt(DConnectMessage.EXTRA_RESULT));
        } catch (JSONException e) {
            fail("Exception in JSONObject." + e.getMessage());
        }
    }
}