Exemple #1
0
  /**
   * test json fill bean
   *
   * @throws JSONException
   */
  @Test
  public void testJsonFillBean() throws JSONException {
    MessageInfo fromMsg = BaseTest.getMessageInfo();
    JSONObject jsonObject = JsonUtil.toJSONObjectFromBean(fromMsg);
    Assert.assertEquals(55555555555555L, jsonObject.get("messageId"));
    Assert.assertEquals("some msg", jsonObject.get("messageSubject"));
    Assert.assertEquals((short) 8, jsonObject.get("messageSubjectLength"));
    // Assert.assertEquals(new JSONObject(new Content(1, "哈哈噢噢,who am i?")),
    // jsonObject.get("messageContent"));
    Assert.assertEquals(true, jsonObject.get("success"));
    Assert.assertEquals((Long) 10L, jsonObject.get("messageSize"));
    Assert.assertEquals((Short) (short) 20, jsonObject.get("messageSize2"));

    jsonObject = JsonUtil.toJSONObject(jsonObject.toString());
    MessageInfo msg = new MessageInfo();
    JsonUtil.fillBeanFromJSONObject(msg, jsonObject, true);
    Assert.assertEquals(55555555555555L, msg.getMessageId());
    Assert.assertEquals("some msg", msg.getMessageSubject());
    Assert.assertEquals((short) 8, msg.getMessageSubjectLength());
    Assert.assertEquals(new Content(1, "哈哈噢噢,who am i?"), msg.getMessageContent());
    Assert.assertEquals(true, msg.getSuccess());
    Assert.assertEquals((Long) 10L, msg.getMessageSize());
    Assert.assertEquals((Short) (short) 20, msg.getMessageSize2());
    Assert.assertEquals(2, msg.getRecipientList().size());
    Assert.assertEquals(BaseTest.getRecipient(), msg.getRecipientList().get(0));
    Assert.assertEquals(BaseTest.getRecipient2(), msg.getRecipientList().get(1));
  }
Exemple #2
0
  /**
   * test to json
   *
   * @throws JSONException
   */
  @Test
  public void testToJson() throws JSONException {
    MessageInfo msg = BaseTest.getMessageInfo();
    JSONObject jsonObject = JsonUtil.toJSONObjectFromBean(msg);
    Assert.assertEquals(55555555555555L, jsonObject.get("messageId"));
    Assert.assertEquals("some msg", jsonObject.get("messageSubject"));
    Assert.assertEquals((short) 8, jsonObject.get("messageSubjectLength"));
    // Assert.assertEquals(new JSONObject(new Content(1, "哈哈噢噢,who am i?")),
    // jsonObject.get("messageContent"));
    Assert.assertEquals(true, jsonObject.get("success"));
    Assert.assertEquals((Long) 10L, jsonObject.get("messageSize"));
    Assert.assertEquals((Short) (short) 20, jsonObject.get("messageSize2"));

    jsonObject = JsonUtil.toJSONObject(jsonObject.toString());
    Assert.assertEquals(55555555555555L, jsonObject.get("messageId"));
    Assert.assertEquals("some msg", jsonObject.get("messageSubject"));
    Assert.assertEquals((byte) 8, jsonObject.get("messageSubjectLength"));
    // Assert.assertEquals(new JSONObject(new Content(1, "哈哈噢噢,who am i?")),
    // jsonObject.get("messageContent"));
    Assert.assertEquals(true, jsonObject.get("success"));
    Assert.assertEquals((Byte) (byte) 10, jsonObject.get("messageSize"));
    Assert.assertEquals((Byte) (byte) 20, jsonObject.get("messageSize2"));
  }