diff --git a/src/main/java/com/smartcar/sdk/Vehicle.java b/src/main/java/com/smartcar/sdk/Vehicle.java index 1c243105..80de272c 100644 --- a/src/main/java/com/smartcar/sdk/Vehicle.java +++ b/src/main/java/com/smartcar/sdk/Vehicle.java @@ -362,7 +362,7 @@ public ActionResponse stopCharge() throws SmartcarException { /** * Send request to the /security endpoint to get the vehicle's lock status * - * @return VehicleLock + * @return VehicleLockStatus * @throws SmartcarException */ public VehicleLockStatus lockStatus() throws SmartcarException { diff --git a/src/main/java/com/smartcar/sdk/data/BatchResponse.java b/src/main/java/com/smartcar/sdk/data/BatchResponse.java index 3e883ad4..47cc904e 100644 --- a/src/main/java/com/smartcar/sdk/data/BatchResponse.java +++ b/src/main/java/com/smartcar/sdk/data/BatchResponse.java @@ -200,6 +200,17 @@ public VehicleChargeLimit chargeLimit() return get("/charge/limit", VehicleChargeLimit.class); } + /** + * Get response from the /security endpoint + * + * @return the lock status of the vehicle + * @throws SmartcarException if the request for this endpoint returned an HTTP error code + */ + public VehicleLockStatus lockStatus() + throws SmartcarException { + return get("/security", VehicleLockStatus.class); + } + /** @return a stringified representation of BatchResponse */ @Override public String toString() { diff --git a/src/test/java/com/smartcar/sdk/VehicleTest.java b/src/test/java/com/smartcar/sdk/VehicleTest.java index d34a42e9..cdf2182a 100644 --- a/src/test/java/com/smartcar/sdk/VehicleTest.java +++ b/src/test/java/com/smartcar/sdk/VehicleTest.java @@ -424,6 +424,42 @@ public void testRequestBatch() throws Exception { Assert.assertEquals(odometer.getMeta().getUnitSystem(), "metric"); } + @Test + public void testLockStatusBatch() throws Exception { + loadAndEnqueueResponse("BatchLockStatusResponseSuccess"); + + String[] paths = new String[]{"/security"}; + JsonArrayBuilder endpoints = Json.createArrayBuilder(); + for (String path : paths) { + endpoints.add(Json.createObjectBuilder().add("path", path)); + } + javax.json.JsonArray requests = endpoints.build(); + + SmartcarVehicleRequest request = new SmartcarVehicleRequest.Builder() + .method("POST") + .path("batch") + .addBodyParameter("requests", requests) + .build(); + + VehicleResponse batchResponse = this.subject.request(request); + Assert.assertEquals(batchResponse.getMeta().getRequestId(), "67127d3a-a08a-41f0-8211-f96da36b2d6e"); + + JsonArray responsesArray = batchResponse.getBody().get("responses").getAsJsonArray(); + + BatchResponse response = new BatchResponse(responsesArray); + + Assert.assertEquals(responsesArray.size(), 1); + + VehicleLockStatus lockStatus = response.lockStatus(); + + Assert.assertTrue(lockStatus.isLocked()); + Assert.assertEquals(lockStatus.getDoors().length, 4); + Assert.assertEquals(lockStatus.getWindows().length, 4); + Assert.assertEquals(lockStatus.getSunroof().length, 1); + Assert.assertEquals(lockStatus.getStorage().length, 2); + Assert.assertEquals(lockStatus.getChargingPort().length, 1); + } + @Test public void testV1PermissionError() throws FileNotFoundException { loadAndEnqueueErrorResponse("ErrorPermissionV1", 403); diff --git a/src/test/resources/BatchLockStatusResponseSuccess.json b/src/test/resources/BatchLockStatusResponseSuccess.json new file mode 100644 index 00000000..b593aef7 --- /dev/null +++ b/src/test/resources/BatchLockStatusResponseSuccess.json @@ -0,0 +1,73 @@ +{ + "responses": + [ + { + "headers": { + }, + "path": "/security", + "code": 200, + "body": { + "isLocked": true, + "doors": [ + { + "type": "frontLeft", + "status": "LOCKED" + }, + { + "type": "frontRight", + "status": "LOCKED" + }, + { + "type": "backLeft", + "status": "LOCKED" + }, + { + "type": "backRight", + "status": "LOCKED" + } + ], + "windows": [ + { + "type": "frontLeft", + "status": "CLOSED" + }, + { + "type": "frontRight", + "status": "CLOSED" + }, + { + "type": "backLeft", + "status": "CLOSED" + }, + { + "type": "backRight", + "status": "CLOSED" + } + ], + "sunroof": [ + { + "type": "sunroof", + "status": "CLOSED" + } + ], + "storage": [ + { + "type": "rear", + "status": "CLOSED" + }, + { + "type": "front", + "status": "CLOSED" + } + ], + "chargingPort": [ + { + "type": "chargingPort", + "status": "CLOSED" + } + ] + + } + } + ] +} \ No newline at end of file