|
51 | 51 | import static org.hamcrest.Matchers.not;
|
52 | 52 | import static org.junit.Assert.assertEquals;
|
53 | 53 | import static org.junit.Assert.assertFalse;
|
| 54 | +import static org.junit.Assert.assertNotNull; |
54 | 55 | import static org.junit.Assert.assertThat;
|
55 | 56 | import static org.junit.Assert.assertTrue;
|
56 | 57 | import static org.junit.Assert.fail;
|
@@ -402,6 +403,31 @@ public void testConvertLogEntriesToJson() throws JSONException {
|
402 | 403 | assertEquals("entry2", obj2.get("message"));
|
403 | 404 | }
|
404 | 405 |
|
| 406 | + @Test |
| 407 | + public void testShouldBeAbleToConvertACommand() throws JSONException { |
| 408 | + SessionId sessionId = new SessionId("some id"); |
| 409 | + String commandName = "some command"; |
| 410 | + Map<String, Object> parameters = new HashMap<String, Object>(); |
| 411 | + parameters.put("param1", "value1"); |
| 412 | + parameters.put("param2", "value2"); |
| 413 | + Command command = new Command(sessionId, commandName, parameters); |
| 414 | + |
| 415 | + System.out.println(new BeanToJsonConverter().convert(command)); |
| 416 | + JSONObject json = new JSONObject(new BeanToJsonConverter().convert(command)); |
| 417 | + |
| 418 | + assertNotNull(json.get("sessionId")); |
| 419 | + JSONObject sid = (JSONObject) json.get("sessionId"); |
| 420 | + assertEquals(sid.getString("value"), sessionId.toString()); |
| 421 | + |
| 422 | + assertEquals(json.getString("name"), commandName); |
| 423 | + |
| 424 | + assertNotNull(json.get("parameters")); |
| 425 | + JSONObject pars = (JSONObject) json.get("parameters"); |
| 426 | + assertEquals(pars.length(), 2); |
| 427 | + assertEquals(pars.getString("param1"), parameters.get("param1")); |
| 428 | + assertEquals(pars.getString("param2"), parameters.get("param2")); |
| 429 | + } |
| 430 | + |
405 | 431 | @SuppressWarnings("unused")
|
406 | 432 | private static class SimpleBean {
|
407 | 433 |
|
|
0 commit comments