@Test
  public void testRateDown() {
    User author = new User("test1", "qaz123").save();
    Message message = new Message("test content", author).save();

    assertEquals(-1, message.rateDown().rating);
    assertEquals(-2, message.rateDown().rating);
  }
  @Test
  public void createAndRetrieveMessage() {
    User author = new User("test1", "qaz123").save();
    new Message("test content", author).save();
    Message message = Message.find("byAuthor", author).first();

    assertNotNull(message);
    assertEquals(author, message.author);
    assertEquals("test content", message.content);
  }
  @Test
  public void testGetAllOrderedByPostedDate() {
    User author = new User("test1", "qaz123").save();
    Message firstMessage = new Message("test1 content", author).save();
    Message secondMessage = new Message("test2 content", author).save();
    List<Message> messages = Message.getAllOrderedByPostedDate();

    assertEquals(secondMessage, messages.get(0));
    assertEquals(firstMessage, messages.get(1));
  }
  @Test
  public void encryptDecodeWrongBasis() throws CoseException {
    CBORObject obj = CBORObject.NewMap();

    thrown.expect(CoseException.class);
    thrown.expectMessage("Message is not a COSE security Message");

    byte[] rgb = obj.EncodeToBytes();
    Message msg = Message.DecodeFromBytes(rgb, MessageTag.Encrypt);
  }
  @Test
  public void encryptDecodeWrongCount() throws CoseException {
    CBORObject obj = CBORObject.NewArray();
    obj.Add(CBORObject.False);

    thrown.expect(CoseException.class);
    thrown.expectMessage("Invalid Encrypt structure");

    byte[] rgb = obj.EncodeToBytes();
    Message msg = Message.DecodeFromBytes(rgb, MessageTag.Encrypt);
  }
    @Override
    public void onMessage(Message message) {

      String value = new String(message.getData());

      logger.trace("NATS Subscriber ({}):  Received message: {}", id, value);

      if (checkPayload) {
        org.junit.Assert.assertTrue(REDIS_PAYLOAD.equals(value));
      }

      if (tallyMessage() == testCount) {
        logger.debug("NATS Subscriber ({}) Received {} messages.  Completed.", id, testCount);
        setComplete();
      }
    }
  /** Test of Decrypt method, of class Encrypt0Message. */
  @Test
  public void testRoundTrip() throws Exception {
    System.out.println("Round Trip");
    EncryptMessage msg = new EncryptMessage();
    msg.addAttribute(HeaderKeys.Algorithm, AlgorithmID.AES_GCM_128.AsCBOR(), Attribute.PROTECTED);
    msg.addAttribute(HeaderKeys.IV, CBORObject.FromObject(rgbIV96), Attribute.PROTECTED);
    msg.SetContent(rgbContent);
    msg.addRecipient(recipient128);
    msg.encrypt();

    List<Recipient> rList = msg.getRecipientList();
    assertEquals(rList.size(), 1);

    byte[] rgbMsg = msg.EncodeToBytes();

    msg = (EncryptMessage) Message.DecodeFromBytes(rgbMsg, MessageTag.Encrypt);
    Recipient r = msg.getRecipient(0);
    r.SetKey(cnKey128);
    byte[] contentNew = msg.decrypt(r);

    assertArrayEquals(rgbContent, contentNew);
  }
 @Test
 public void logSend() {
   Message message = new Message(1, new Card(2), 3, 4, 5, new Money(6));
   log.logSend(message);
   assertTrue(mock_simulator.getLastLog().equals("Message:   " + message.toString()));
 }