/** * バッテリー全属性取得テストを行う. * * <pre> * 【HTTP通信】 * Method: GET * Path: /battery?deviceid=xxxx * </pre> * * <pre> * 【期待する動作】 * ・resultに0が返ってくること。 * ・chargingがfalseで返ってくること。 * ・chargingtimeが50000で返ってくること。 * ・dischargingtimeが10000で返ってくること。 * ・levelが0.5で返ってくること。 * </pre> */ public void testGetBattery() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(BatteryProfileConstants.PROFILE_NAME); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpGet(builder.toString()); JSONObject root = sendRequest(request); assertResultOK(root); assertEquals( "charging is not equals.", TestBatteryProfileConstants.CHARGING, root.getBoolean(BatteryProfileConstants.ATTRIBUTE_CHARGING)); assertEquals( "chargingtime is not equals.", TestBatteryProfileConstants.CHARGING_TIME, root.getDouble(BatteryProfileConstants.ATTRIBUTE_CHARGING_TIME)); assertEquals( "dischargingtime is not equals.", TestBatteryProfileConstants.DISCHARGING_TIME, root.getDouble(BatteryProfileConstants.ATTRIBUTE_DISCHARGING_TIME)); assertEquals( "level is not equals.", TestBatteryProfileConstants.LEVEL, root.getDouble(BatteryProfileConstants.ATTRIBUTE_LEVEL)); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } }
/** * バッテリーonchargingchangeを解除するテストを行う. * * <pre> * 【HTTP通信】 * Method: DELETE * Path: /battery/onchargingchange?deviceid=xxxx&session_key=xxxx * </pre> * * <pre> * 【期待する動作】 * ・resultに0が返ってくること。 * </pre> */ public void testDeleteBatteryOnChargingChange() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(BatteryProfileConstants.PROFILE_NAME); builder.setAttribute(BatteryProfileConstants.ATTRIBUTE_ON_CHARGING_CHANGE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(DConnectProfileConstants.PARAM_SESSION_KEY, getClientId()); 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()); } }
/** * onbatterychange属性のコールバック登録テストを行う. * * <pre> * 【HTTP通信】 * Method: PUT * Path: /battery/onbatterychange?deviceid=xxxx&session_key=xxxx * </pre> * * <pre> * 【期待する動作】 * ・resultに0が返ってくること。 * </pre> */ public void testPutBatteryOnBatteryChange() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(BatteryProfileConstants.PROFILE_NAME); builder.setAttribute(BatteryProfileConstants.ATTRIBUTE_ON_BATTERY_CHANGE); builder.addParameter(DConnectProfileConstants.PARAM_DEVICE_ID, getDeviceId()); builder.addParameter(DConnectProfileConstants.PARAM_SESSION_KEY, getClientId()); builder.addParameter(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, getAccessToken()); try { HttpUriRequest request = new HttpPut(builder.toString()); JSONObject root = sendRequest(request); assertResultOK(root); // イベントメッセージを受け取る JSONObject resp = waitForEvent(); assertNotNull("response is null.", resp); assertEquals( BatteryProfileConstants.PROFILE_NAME, resp.getString(DConnectMessage.EXTRA_PROFILE)); assertEquals( BatteryProfileConstants.ATTRIBUTE_ON_BATTERY_CHANGE, resp.getString(DConnectMessage.EXTRA_ATTRIBUTE)); } catch (JSONException e) { fail("Exception in JSONObject." + e.getMessage()); } }