Skip to content

Commit

Permalink
Merge pull request #1583 from LuxoftSDL/feature/0255_enchance_body_in…
Browse files Browse the repository at this point in the history
…formation

[0255] Enchance body information
  • Loading branch information
bilal-alsharifi authored Jan 26, 2021
2 parents 3c4c404 + 3ea6c35 commit c2ad479
Show file tree
Hide file tree
Showing 12 changed files with 1,140 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
import com.smartdevicelink.proxy.rpc.WindowState;
import com.smartdevicelink.proxy.rpc.WindowStatus;
import com.smartdevicelink.proxy.rpc.WindowTypeCapabilities;
import com.smartdevicelink.proxy.rpc.DoorStatus;
import com.smartdevicelink.proxy.rpc.GateStatus;
import com.smartdevicelink.proxy.rpc.RoofStatus;
import com.smartdevicelink.proxy.rpc.enums.AmbientLightStatus;
import com.smartdevicelink.proxy.rpc.enums.AppHMIType;
import com.smartdevicelink.proxy.rpc.enums.AppInterfaceUnregisteredReason;
Expand All @@ -137,6 +140,7 @@
import com.smartdevicelink.proxy.rpc.enums.DisplayMode;
import com.smartdevicelink.proxy.rpc.enums.DisplayType;
import com.smartdevicelink.proxy.rpc.enums.DistanceUnit;
import com.smartdevicelink.proxy.rpc.enums.DoorStatusType;
import com.smartdevicelink.proxy.rpc.enums.DriverDistractionState;
import com.smartdevicelink.proxy.rpc.enums.ECallConfirmationStatus;
import com.smartdevicelink.proxy.rpc.enums.EmergencyEventType;
Expand Down Expand Up @@ -427,6 +431,15 @@ public class TestValues {
public static final DynamicUpdateCapabilities GENERAL_DYNAMICUPDATECAPABILITIES = new DynamicUpdateCapabilities();
public static final WindowState GENERAL_WINDOWSTATE = new WindowState();

public static final DoorStatusType GENERAL_DOOR_STATUS_TYPE = DoorStatusType.REMOVED;

public static final DoorStatus GENERAL_DOOR_STATUS = new DoorStatus();
public static final GateStatus GENERAL_GATE_STATUS = new GateStatus();
public static final RoofStatus GENERAL_ROOF_STATUS = new RoofStatus();

public static final ArrayList<DoorStatus> GENERAL_DOOR_STATUS_LIST = new ArrayList<>(1);
public static final ArrayList<GateStatus> GENERAL_GATE_STATUS_LIST = new ArrayList<>(1);
public static final ArrayList<RoofStatus> GENERAL_ROOF_STATUS_LIST = new ArrayList<>(1);

public static final VehicleDataResult GENERAL_OEM_CUSTOM_VEHICLE_DATA = new VehicleDataResult();
public static final TemplateConfiguration GENERAL_TEMPLATE_CONFIGURATION = new TemplateConfiguration();
Expand Down Expand Up @@ -591,6 +604,12 @@ public void onVoiceCommandSelected() {
public static final JSONObject JSON_DISPLAYCAPABILITY = new JSONObject();
public static final JSONArray JSON_DISPLAYCAPABILITY_LIST = new JSONArray();
public static final JSONObject JSON_DYNAMICUPDATECAPABILITIES = new JSONObject();
public static final JSONArray JSON_ROOF_STATUSES = new JSONArray();
public static final JSONArray JSON_DOOR_STATUSES = new JSONArray();
public static final JSONArray JSON_GATE_STATUSES = new JSONArray();
public static final JSONObject JSON_ROOF_STATUS = new JSONObject();
public static final JSONObject JSON_DOOR_STATUS = new JSONObject();
public static final JSONObject JSON_GATE_STATUS = new JSONObject();

static {
GENERAL_TOUCHEVENTCAPABILITIES.setDoublePressAvailable(GENERAL_BOOLEAN);
Expand Down Expand Up @@ -1154,6 +1173,19 @@ public void onVoiceCommandSelected() {
GENERAL_STABILITY_CONTROL_STATUS.setEscSystem(GENERAL_ESC_SYSTEM);
GENERAL_STABILITY_CONTROL_STATUS.setTrailerSwayControl(GENERAL_S_WAY_CONTROL);

GENERAL_ROOF_STATUS.setLocation(GENERAL_GRID);
GENERAL_ROOF_STATUS.setState(GENERAL_WINDOW_STATE);
GENERAL_ROOF_STATUS.setStatus(GENERAL_DOOR_STATUS_TYPE);
GENERAL_ROOF_STATUS_LIST.add(GENERAL_ROOF_STATUS);

GENERAL_GATE_STATUS.setLocation(GENERAL_GRID);
GENERAL_GATE_STATUS.setStatus(GENERAL_DOOR_STATUS_TYPE);
GENERAL_GATE_STATUS_LIST.add(GENERAL_GATE_STATUS);

GENERAL_DOOR_STATUS.setLocation(GENERAL_GRID);
GENERAL_DOOR_STATUS.setStatus(GENERAL_DOOR_STATUS_TYPE);
GENERAL_DOOR_STATUS_LIST.add(GENERAL_DOOR_STATUS);

try {
JSON_HMIPERMISSIONS.put(HMIPermissions.KEY_ALLOWED, GENERAL_HMILEVEL_LIST);
JSON_HMIPERMISSIONS.put(HMIPermissions.KEY_USER_DISALLOWED, GENERAL_HMILEVEL_LIST);
Expand Down Expand Up @@ -1391,6 +1423,19 @@ public void onVoiceCommandSelected() {
JSON_MODULE_INFO.put(ModuleInfo.KEY_MODULE_SERVICE_AREA, TestValues.JSON_GRID);
JSON_MODULE_INFO.put(ModuleInfo.KEY_MULTIPLE_ACCESS_ALLOWED, TestValues.GENERAL_BOOLEAN);

JSON_ROOF_STATUS.put(RoofStatus.KEY_STATUS, GENERAL_DOOR_STATUS_TYPE);
JSON_ROOF_STATUS.put(RoofStatus.KEY_LOCATION, JSON_GRID);
JSON_ROOF_STATUS.put(RoofStatus.KEY_STATE, GENERAL_WINDOW_STATE.serializeJSON());

JSON_DOOR_STATUS.put(DoorStatus.KEY_STATUS, GENERAL_DOOR_STATUS_TYPE);
JSON_DOOR_STATUS.put(DoorStatus.KEY_LOCATION, JSON_GRID);

JSON_GATE_STATUS.put(GateStatus.KEY_STATUS, GENERAL_DOOR_STATUS_TYPE);
JSON_GATE_STATUS.put(GateStatus.KEY_LOCATION, JSON_GRID);

JSON_ROOF_STATUSES.put(JSON_ROOF_STATUS);
JSON_DOOR_STATUSES.put(JSON_DOOR_STATUS);
JSON_GATE_STATUSES.put(JSON_GATE_STATUS);

} catch (JSONException e) {
Log.e("Test", "Static Json Construction Failed.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3929,4 +3929,37 @@ public static boolean validateStabilityControlStatus(VehicleDataResult status1,
}
return status1.getDataType().equals(status2.getDataType()) && status1.getResultCode().equals(status2.getResultCode());
}

public static boolean validateDoorStatus(DoorStatus status1, DoorStatus status2) {
if (status1 == null) {
return (status2 == null);
}
if (status2 == null) {
return (status2 == null);
}
boolean gridValidated = validateGrid(status1.getLocation(), status2.getLocation());
return gridValidated && status1.getStatus().equals(status2.getStatus());
}

public static boolean validateGateStatus(GateStatus status1, GateStatus status2) {
if (status1 == null) {
return (status2 == null);
}
if (status2 == null) {
return (status2 == null);
}
boolean gridValidated = validateGrid(status1.getLocation(), status2.getLocation());
return gridValidated && status1.getStatus().equals(status2.getStatus());
}

public static boolean validateRoofStatus(RoofStatus status1, RoofStatus status2) {
if (status1 == null) {
return (status2 == null);
}
if (status2 == null) {
return (status2 == null);
}
boolean gridValidated = validateGrid(status1.getLocation(), status2.getLocation());
return gridValidated && status1.getStatus().equals(status2.getStatus()) && validateWindowStates(status1.getState(), status2.getState());
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package com.smartdevicelink.test.rpc.datatypes;

import com.smartdevicelink.marshal.JsonRPCMarshaller;
import com.smartdevicelink.proxy.rpc.BodyInformation;
import com.smartdevicelink.proxy.rpc.DoorStatus;
import com.smartdevicelink.proxy.rpc.GateStatus;
import com.smartdevicelink.proxy.rpc.RoofStatus;
import com.smartdevicelink.proxy.rpc.enums.IgnitionStableStatus;
import com.smartdevicelink.proxy.rpc.enums.IgnitionStatus;
import com.smartdevicelink.test.JsonUtils;
import com.smartdevicelink.test.TestValues;
import com.smartdevicelink.test.Validator;

import junit.framework.TestCase;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Hashtable;
import java.util.Iterator;

import static com.smartdevicelink.proxy.rpc.BodyInformation.KEY_DOOR_STATUSES;
import static com.smartdevicelink.proxy.rpc.BodyInformation.KEY_GATE_STATUSES;
import static com.smartdevicelink.proxy.rpc.BodyInformation.KEY_ROOF_STATUSES;

/**
* This is a unit test class for the SmartDeviceLink library project class :
* {@link com.smartdevicelink.proxy.rpc.BodyInformation}
Expand All @@ -32,6 +43,10 @@ public void setUp() {
msg.setPassengerDoorAjar(TestValues.GENERAL_BOOLEAN);
msg.setRearLeftDoorAjar(TestValues.GENERAL_BOOLEAN);
msg.setRearRightDoorAjar(TestValues.GENERAL_BOOLEAN);

msg.setDoorStatuses(TestValues.GENERAL_DOOR_STATUS_LIST);
msg.setGateStatuses(TestValues.GENERAL_GATE_STATUS_LIST);
msg.setRoofStatuses(TestValues.GENERAL_ROOF_STATUS_LIST);
}

/**
Expand All @@ -52,6 +67,9 @@ public void testRpcValues() {
assertEquals(TestValues.MATCH, TestValues.GENERAL_BOOLEAN, (boolean) msg.getPassengerDoorAjar());
assertEquals(TestValues.MATCH, TestValues.GENERAL_BOOLEAN, (boolean) msg.getRearLeftDoorAjar());
assertEquals(TestValues.MATCH, TestValues.GENERAL_BOOLEAN, (boolean) msg.getRearRightDoorAjar());
assertEquals(TestValues.MATCH, TestValues.GENERAL_GATE_STATUS_LIST, msg.getGateStatuses());
assertEquals(TestValues.MATCH, TestValues.GENERAL_ROOF_STATUS_LIST, msg.getRoofStatuses());
assertEquals(TestValues.MATCH, TestValues.GENERAL_DOOR_STATUS_LIST, msg.getDoorStatuses());

// Invalid/Null Tests
BodyInformation msg = new BodyInformation();
Expand All @@ -64,6 +82,9 @@ public void testRpcValues() {
assertNull(TestValues.NULL, msg.getPassengerDoorAjar());
assertNull(TestValues.NULL, msg.getRearLeftDoorAjar());
assertNull(TestValues.NULL, msg.getRearRightDoorAjar());
assertNull(TestValues.NULL, msg.getGateStatuses());
assertNull(TestValues.NULL, msg.getRoofStatuses());
assertNull(TestValues.NULL, msg.getDoorStatuses());
}

public void testJson() {
Expand All @@ -77,14 +98,49 @@ public void testJson() {
reference.put(BodyInformation.KEY_PASSENGER_DOOR_AJAR, TestValues.GENERAL_BOOLEAN);
reference.put(BodyInformation.KEY_REAR_LEFT_DOOR_AJAR, TestValues.GENERAL_BOOLEAN);
reference.put(BodyInformation.KEY_REAR_RIGHT_DOOR_AJAR, TestValues.GENERAL_BOOLEAN);
reference.put(KEY_DOOR_STATUSES, TestValues.JSON_DOOR_STATUSES);
reference.put(KEY_GATE_STATUSES, TestValues.JSON_GATE_STATUSES);
reference.put(KEY_ROOF_STATUSES, TestValues.JSON_ROOF_STATUSES);

JSONObject underTest = msg.serializeJSON();
assertEquals(TestValues.MATCH, reference.length(), underTest.length());

Iterator<?> iterator = reference.keys();
while (iterator.hasNext()) {
String key = (String) iterator.next();
assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
if (key.equals(KEY_DOOR_STATUSES)) {

JSONArray array1 = JsonUtils.readJsonArrayFromJsonObject(reference, key);
JSONArray array2 = JsonUtils.readJsonArrayFromJsonObject(underTest, key);

for (int i = 0; i < array1.length(); i++) {
Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(array1.getJSONObject(i));
Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(array2.getJSONObject(i));
assertTrue(Validator.validateDoorStatus(new DoorStatus(h1), new DoorStatus(h2)));

}
} else if (key.equals(KEY_GATE_STATUSES)) {

JSONArray array1 = JsonUtils.readJsonArrayFromJsonObject(reference, key);
JSONArray array2 = JsonUtils.readJsonArrayFromJsonObject(underTest, key);

for (int i = 0; i < array1.length(); i++) {
Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(array1.getJSONObject(i));
Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(array2.getJSONObject(i));
assertTrue(Validator.validateGateStatus(new GateStatus(h1), new GateStatus(h2)));
}
} else if (key.equals(KEY_ROOF_STATUSES)) {
JSONArray array1 = JsonUtils.readJsonArrayFromJsonObject(reference, key);
JSONArray array2 = JsonUtils.readJsonArrayFromJsonObject(underTest, key);

for (int i = 0; i < array1.length(); i++) {
Hashtable<String, Object> h1 = JsonRPCMarshaller.deserializeJSONObject(array1.getJSONObject(i));
Hashtable<String, Object> h2 = JsonRPCMarshaller.deserializeJSONObject(array2.getJSONObject(i));
assertTrue(Validator.validateRoofStatus(new RoofStatus(h1), new RoofStatus(h2)));
}
} else {
assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
}
}
} catch (JSONException e) {
fail(TestValues.JSON_FAIL);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.smartdevicelink.test.rpc.datatypes;

import com.smartdevicelink.marshal.JsonRPCMarshaller;
import com.smartdevicelink.proxy.rpc.DoorStatus;
import com.smartdevicelink.proxy.rpc.Grid;
import com.smartdevicelink.proxy.rpc.RoofStatus;
import com.smartdevicelink.proxy.rpc.enums.DoorStatusType;
import com.smartdevicelink.test.JsonUtils;
import com.smartdevicelink.test.TestValues;
import com.smartdevicelink.test.Validator;

import junit.framework.TestCase;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Hashtable;
import java.util.Iterator;

public class DoorStatusTests extends TestCase {
private DoorStatus msg;

@Override
public void setUp() {
msg = new DoorStatus(TestValues.GENERAL_GRID, TestValues.GENERAL_DOOR_STATUS_TYPE);
}

public void testRpcValues() {
// Test Values
Grid location = msg.getLocation();
DoorStatusType status = msg.getStatus();

// Valid Tests
assertEquals(TestValues.MATCH, TestValues.GENERAL_GRID, location);
assertEquals(TestValues.MATCH, TestValues.GENERAL_DOOR_STATUS_TYPE, status);
}

public void testJson() {
JSONObject reference = new JSONObject();

try {
reference.put(RoofStatus.KEY_STATUS, TestValues.GENERAL_DOOR_STATUS_TYPE);
reference.put(RoofStatus.KEY_LOCATION, TestValues.JSON_GRID);

JSONObject underTest = msg.serializeJSON();
assertEquals(TestValues.MATCH, reference.length(), underTest.length());

Iterator<?> iterator = reference.keys();
while (iterator.hasNext()) {
String key = (String) iterator.next();
if (key.equals(RoofStatus.KEY_LOCATION)) {
Hashtable<String, Object> hs1 = JsonRPCMarshaller.deserializeJSONObject((JSONObject) JsonUtils.readObjectFromJsonObject(reference, key));
Hashtable<String, Object> hs2 = JsonRPCMarshaller.deserializeJSONObject((JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key));

assertTrue(Validator.validateGrid(new Grid(hs1), new Grid(hs2)));

} else {
assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
}
}
} catch (JSONException e) {
fail(TestValues.JSON_FAIL);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.smartdevicelink.test.rpc.datatypes;

import com.smartdevicelink.marshal.JsonRPCMarshaller;
import com.smartdevicelink.proxy.rpc.GateStatus;
import com.smartdevicelink.proxy.rpc.Grid;
import com.smartdevicelink.proxy.rpc.RoofStatus;
import com.smartdevicelink.proxy.rpc.enums.DoorStatusType;
import com.smartdevicelink.test.JsonUtils;
import com.smartdevicelink.test.TestValues;
import com.smartdevicelink.test.Validator;

import junit.framework.TestCase;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Hashtable;
import java.util.Iterator;

public class GateStatusTests extends TestCase {
private GateStatus msg;

@Override
public void setUp() {
msg = new GateStatus(TestValues.GENERAL_GRID, TestValues.GENERAL_DOOR_STATUS_TYPE);
}

public void testRpcValues() {
// Test Values
Grid location = msg.getLocation();
DoorStatusType status = msg.getStatus();

// Valid Tests
assertEquals(TestValues.MATCH, TestValues.GENERAL_GRID, location);
assertEquals(TestValues.MATCH, TestValues.GENERAL_DOOR_STATUS_TYPE, status);
}

public void testJson() {
JSONObject reference = new JSONObject();

try {
reference.put(RoofStatus.KEY_STATUS, TestValues.GENERAL_DOOR_STATUS_TYPE);
reference.put(RoofStatus.KEY_LOCATION, TestValues.JSON_GRID);

JSONObject underTest = msg.serializeJSON();
assertEquals(TestValues.MATCH, reference.length(), underTest.length());

Iterator<?> iterator = reference.keys();
while (iterator.hasNext()) {
String key = (String) iterator.next();
if (key.equals(RoofStatus.KEY_LOCATION)) {
Hashtable<String, Object> hs1 = JsonRPCMarshaller.deserializeJSONObject((JSONObject) JsonUtils.readObjectFromJsonObject(reference, key));
Hashtable<String, Object> hs2 = JsonRPCMarshaller.deserializeJSONObject((JSONObject) JsonUtils.readObjectFromJsonObject(underTest, key));

assertTrue(Validator.validateGrid(new Grid(hs1), new Grid(hs2)));

} else {
assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
}
}
} catch (JSONException e) {
fail(TestValues.JSON_FAIL);
}
}
}
Loading

0 comments on commit c2ad479

Please sign in to comment.