@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()); }
@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"); }
@Test public void testOnMessage() throws Exception { Message message = MailingListServicesProvider.getFactory().getMessageService().getMessage("700"); message.setContentType("text/plain; charset=\"UTF-8\""); MessageEvent event = new MessageEvent(); event.addMessage(message); component.onMessage(event); /*List<TextMessage> jmsMessages = MockObjectFactory.getMessages(JNDINames.JMS_QUEUE); assertNotNull(jmsMessages); assertEquals(3, 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)); assertEquals(message.getSummary() + TECHNICAL_CONTENT, data.getMessage()); String url = (String) data.getTargetParam().get("URL"); assertNotNull(url); assertEquals("http://*****:*****@silverpeas.com", source); }*/ checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); message = MailingListServicesProvider.getFactory().getMessageService().getMessage(message.getId()); message.setModerated(true); event = new MessageEvent(); event.addMessage(message); component.onMessage(event); /*jmsMessages = MockObjectFactory.getMessages(JNDINames.JMS_QUEUE); assertNotNull(jmsMessages); assertEquals(6, 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)); assertEquals(message.getSummary() + TECHNICAL_CONTENT, data.getMessage()); String url = (String) data.getTargetParam().get("URL"); assertNotNull(url); assertEquals( "http://*****:*****@silverpeas.com", source); }*/ checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); checkNoMessage("*****@*****.**"); }