@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()); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Message other = (Message) obj; if (this.id != null && other.getId() != null && (!this.id.equals(other.id) || version != other.version)) { return false; } else if (messageId == null) { if (other.messageId != null) { return false; } } else if (!messageId.equals(other.messageId)) { return false; } else if (componentId == null) { if (other.componentId != null) { return false; } } else if (!componentId.equals(other.componentId)) { return false; } return true; }
@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()); }
@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("*****@*****.**"); }