1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package com.smartdevicelink.test.rpc.datatypes;
import com.smartdevicelink.proxy.rpc.BodyInformation;
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 junit.framework.TestCase;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Iterator;
/**
* This is a unit test class for the SmartDeviceLink library project class :
* {@link com.smartdevicelink.proxy.rpc.BodyInformation}
*/
public class BodyInformationTests extends TestCase {
private BodyInformation msg;
@Override
public void setUp() {
msg = new BodyInformation();
msg.setParkBrakeActive(TestValues.GENERAL_BOOLEAN);
msg.setIgnitionStatus(TestValues.GENERAL_IGNITIONSTATUS);
msg.setIgnitionStableStatus(TestValues.GENERAL_IGNITIONSTABLESTATUS);
msg.setDriverDoorAjar(TestValues.GENERAL_BOOLEAN);
msg.setPassengerDoorAjar(TestValues.GENERAL_BOOLEAN);
msg.setRearLeftDoorAjar(TestValues.GENERAL_BOOLEAN);
msg.setRearRightDoorAjar(TestValues.GENERAL_BOOLEAN);
}
/**
* Tests the expected values of the RPC message.
*/
public void testRpcValues() {
// Test Values
boolean parkBrake = msg.getParkBrakeActive();
IgnitionStatus ignitionStatus = msg.getIgnitionStatus();
IgnitionStableStatus ignitionStable = msg.getIgnitionStableStatus();
// Valid Tests
assertEquals(TestValues.MATCH, TestValues.GENERAL_BOOLEAN, parkBrake);
assertEquals(TestValues.MATCH, TestValues.GENERAL_IGNITIONSTATUS, ignitionStatus);
assertEquals(TestValues.MATCH, TestValues.GENERAL_IGNITIONSTABLESTATUS, ignitionStable);
assertEquals(TestValues.MATCH, TestValues.GENERAL_BOOLEAN, (boolean) msg.getDriverDoorAjar());
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());
// Invalid/Null Tests
BodyInformation msg = new BodyInformation();
assertNotNull(TestValues.NOT_NULL, msg);
assertNull(TestValues.NULL, msg.getParkBrakeActive());
assertNull(TestValues.NULL, msg.getIgnitionStatus());
assertNull(TestValues.NULL, msg.getIgnitionStatus());
assertNull(TestValues.NULL, msg.getDriverDoorAjar());
assertNull(TestValues.NULL, msg.getPassengerDoorAjar());
assertNull(TestValues.NULL, msg.getRearLeftDoorAjar());
assertNull(TestValues.NULL, msg.getRearRightDoorAjar());
}
public void testJson() {
JSONObject reference = new JSONObject();
try {
reference.put(BodyInformation.KEY_PARK_BRAKE_ACTIVE, TestValues.GENERAL_BOOLEAN);
reference.put(BodyInformation.KEY_IGNITION_STATUS, TestValues.GENERAL_IGNITIONSTATUS);
reference.put(BodyInformation.KEY_IGNITION_STABLE_STATUS, TestValues.GENERAL_IGNITIONSTABLESTATUS);
reference.put(BodyInformation.KEY_DRIVER_DOOR_AJAR, TestValues.GENERAL_BOOLEAN);
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);
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));
}
} catch (JSONException e) {
fail(TestValues.JSON_FAIL);
}
}
}
|