@Test
 public void testGetMessage() {
   Message savedMessage = messageService.getMessage("1");
   assertNotNull(savedMessage);
   assertEquals(textEmailContent.replaceAll("\n", ""), savedMessage.getBody());
   assertEquals("componentId", savedMessage.getComponentId());
   assertEquals(true, savedMessage.isModerated());
   assertEquals(textEmailContent.substring(0, 200), savedMessage.getSummary());
   assertEquals("*****@*****.**", savedMessage.getSender());
   assertEquals("0000001747b40c8d", savedMessage.getMessageId());
   assertEquals(1204364055000l, savedMessage.getSentDate().getTime());
   assertEquals("Simple database message", savedMessage.getTitle());
   assertEquals("text/plain", savedMessage.getContentType());
   assertEquals(2008, savedMessage.getYear());
   assertEquals(Calendar.MARCH, savedMessage.getMonth());
   assertEquals("1", savedMessage.getId());
   assertEquals(1, savedMessage.getVersion());
   assertEquals(10000, savedMessage.getAttachmentsSize());
   assertNotNull(savedMessage.getAttachments());
   assertEquals(1, savedMessage.getAttachments().size());
   Attachment attached = savedMessage.getAttachments().iterator().next();
   assertNotNull(attached);
   assertEquals("1", attached.getId());
   assertEquals(1, attached.getVersion());
   assertEquals(10000, attached.getSize());
   assertEquals("lemonde.html", attached.getFileName());
   assertEquals("text/html", attached.getContentType());
   assertEquals(attachmentPath + "lemonde.html", attached.getPath());
 }
 @Test
 public void testModerateMessage() {
   Message savedMessage = messageService.getMessage("3");
   assertNotNull(savedMessage);
   assertEquals(textEmailContent.replaceAll("\n", ""), savedMessage.getBody());
   assertEquals("componentId", savedMessage.getComponentId());
   assertEquals(false, savedMessage.isModerated());
   assertEquals(textEmailContent.substring(0, 200), savedMessage.getSummary());
   assertEquals("*****@*****.**", savedMessage.getSender());
   assertEquals("0000001747b40c95", savedMessage.getMessageId());
   assertEquals(1204450455000l, savedMessage.getSentDate().getTime());
   assertEquals("Simple database message 3", savedMessage.getTitle());
   assertEquals("text/plain", savedMessage.getContentType());
   assertEquals(2008, savedMessage.getYear());
   assertEquals(Calendar.MARCH, savedMessage.getMonth());
   assertEquals("3", savedMessage.getId());
   assertEquals(1, savedMessage.getVersion());
   assertEquals(0, savedMessage.getAttachmentsSize());
   assertNotNull(savedMessage.getAttachments());
   messageService.moderateMessage("3");
   savedMessage = messageService.getMessage("3");
   assertNotNull(savedMessage);
   assertEquals(true, savedMessage.isModerated());
   assertEquals(textEmailContent.replaceAll("\n", ""), savedMessage.getBody());
   assertEquals("componentId", savedMessage.getComponentId());
   assertEquals(textEmailContent.substring(0, 200), savedMessage.getSummary());
   assertEquals("*****@*****.**", savedMessage.getSender());
   assertEquals("0000001747b40c95", savedMessage.getMessageId());
   assertEquals(1204450455000l, savedMessage.getSentDate().getTime());
   assertEquals("Simple database message 3", savedMessage.getTitle());
   assertEquals("text/plain", savedMessage.getContentType());
   assertEquals(2008, savedMessage.getYear());
   assertEquals(Calendar.MARCH, savedMessage.getMonth());
   assertEquals("3", savedMessage.getId());
   assertEquals(2, savedMessage.getVersion());
   assertEquals(0, savedMessage.getAttachmentsSize());
   assertNotNull(savedMessage.getAttachments());
 }
  @Test
  public void testSaveMessage() {
    Calendar sentDate = Calendar.getInstance();
    sentDate.set(Calendar.MILLISECOND, 0);
    Message message = new Message();
    message.setBody(textEmailContent);
    message.setComponentId("componentId");
    message.setModerated(true);
    message.setSummary(textEmailContent.substring(0, 200));
    message.setSender("*****@*****.**");
    message.setMessageId("0000001747b40c85");
    message.setSentDate(sentDate.getTime());
    message.setTitle("Simple text message");
    message.setContentType("text/plain");

    Attachment attachment = new Attachment();
    attachment.setPath(attachmentPath + "lemonde.html");
    attachment.setFileName("lemonde.html");
    attachment.setContentType("text/html");
    attachment.setSize(10000);
    message.getAttachments().add(attachment);
    String id = messageService.saveMessage(message);
    assertNotNull(id);
    Message savedMessage = messageService.getMessage(id);
    assertNotNull(savedMessage);
    assertEquals(textEmailContent, savedMessage.getBody());
    assertEquals("componentId", savedMessage.getComponentId());
    assertEquals(true, savedMessage.isModerated());
    assertEquals(textEmailContent.substring(0, 200), savedMessage.getSummary());
    assertEquals("*****@*****.**", savedMessage.getSender());
    assertEquals("0000001747b40c85", savedMessage.getMessageId());
    assertEquals(sentDate.getTime(), savedMessage.getSentDate());
    assertEquals("Simple text message", savedMessage.getTitle());
    assertEquals(sentDate.get(Calendar.YEAR), savedMessage.getYear());
    assertEquals(sentDate.get(Calendar.MONTH), savedMessage.getMonth());
    assertEquals(id, savedMessage.getId());
    assertEquals(0, savedMessage.getVersion());
    assertEquals(10000, savedMessage.getAttachmentsSize());
    assertNotNull(savedMessage.getAttachments());
    assertEquals(1, savedMessage.getAttachments().size());
    assertEquals("text/plain", savedMessage.getContentType());
    Attachment attached = savedMessage.getAttachments().iterator().next();
    assertNotNull(attached);
    assertEquals(0, attached.getVersion());
    assertNotNull(attached.getId());
    assertEquals(10000, attached.getSize());
    assertEquals("lemonde.html", attached.getFileName());
    assertEquals(attachmentPath + "lemonde.html", attached.getPath());
  }
 @Override
 public String getElementDescription(Message message, String userId) {
   return message.getSummary();
 }
 @Test
 public void testOnMessageNotModeratedNotify() throws Exception {
   MailingListComponent componentNotModerated = new MailingListComponent("101");
   MailingList list = ServicesFactory.getMailingListService().findMailingList("101");
   assertNotNull(list);
   assertNotNull(list.getModerators());
   assertEquals(3, list.getModerators().size());
   assertNotNull(list.getReaders());
   assertEquals(2, list.getReaders().size());
   assertFalse(list.isModerated());
   assertTrue(list.isNotify());
   Message message = ServicesFactory.getMessageService().getMessage("701");
   assertEquals(textEmailContent, message.getBody());
   message.setContentType("text/plain; charset=\"UTF-8\"");
   MessageEvent event = new MessageEvent();
   event.addMessage(message);
   componentNotModerated.onMessage(event);
   List<TextMessage> jmsMessages = MockObjectFactory.getMessages(JNDINames.JMS_QUEUE);
   assertNotNull(jmsMessages);
   assertEquals(5, jmsMessages.size());
   for (TextMessage alert : jmsMessages) {
     assertNotNull(alert.getText());
     NotificationData data = NotificationServerUtil.convertXMLToNotificationData(alert.getText());
     assertNotNull(data);
     String channel = data.getTargetChannel();
     assertEquals("SMTP", channel);
     String recipient = data.getTargetReceipt();
     assertNotNull(recipient);
     assertTrue(
         "Erreur destinataire " + recipient,
         "*****@*****.**".equals(recipient)
             || "*****@*****.**".equals(recipient)
             || "*****@*****.**".equals(recipient)
             || "*****@*****.**".equals(recipient)
             || "*****@*****.**".equals(recipient));
     assertEquals(message.getSummary(), data.getMessage());
     String url = (String) data.getTargetParam().get("URL");
     assertNotNull(url);
     assertEquals(
         "http://*****:*****@silverpeas.com", source);
   }
   checkSimpleEmail(
       "*****@*****.**",
       "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**",
       "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**", "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**",
       "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**", "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**", "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**",
       "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**", "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**",
       "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**",
       "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**",
       "[Liste de diffusion de test non modérée] : Simple Message");
   checkSimpleEmail(
       "*****@*****.**",
       "[Liste de diffusion de test non modérée] : Simple Message");
 }