Skip to content

Commit

Permalink
Added support for lock status batch
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Garcia committed Aug 25, 2023
1 parent e102fd7 commit 2dc1a72
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/smartcar/sdk/Vehicle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/smartcar/sdk/data/BatchResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/com/smartcar/sdk/VehicleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
73 changes: 73 additions & 0 deletions src/test/resources/BatchLockStatusResponseSuccess.json
Original file line number Diff line number Diff line change
@@ -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"
}
]

}
}
]
}

0 comments on commit 2dc1a72

Please sign in to comment.