@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 getElementTitle(Message message, String userId) { return message.getTitle(); }