}
@Test
public void testInsertMessage() throws Exception {
final Message message = new Message();
message.setDirection(Direction.TO_CONNECTIONS);
message.setSource("test");
message.setStatus(Message.STATUS_CREATED);
message.setProperty("from", "1111");
message.setProperty("to", "2222");
message.setProperty("text", "text");
message.setProperty("other", "other value");
ConnectionsSmsHandler handler = new ConnectionsSmsHandler();
long id = handler.insertMessage(connection, message);
validateMessage(id, new MessageValidator() {
@Override
public void validate(ResultSet rs) throws SQLException {
Assert.assertEquals(rs.getString("source"), message.getSource());
Assert.assertEquals(rs.getByte("status"), message.getStatus());
Assert.assertEquals(rs.getString("smsc_from"), message.getProperty("from", String.class));
Assert.assertEquals(rs.getString("smsc_to"), message.getProperty("to", String.class));
Assert.assertEquals(rs.getString("smsc_text"), message.getProperty("text", String.class));
try {
Assert.assertEquals(rs.getString("other"), new JSONObject().put("other", "other value").toString());
} catch (JSONException e) {
Assert.fail("shouldn't had to throw exception", e);
}