@Test public void testCollectAttachments() throws Exception { final CacheManager cacheManager = mockery.mock(CacheManager.class); final Cache cache = mockery.mock(Cache.class); mockery.checking(new Expectations() {{ allowing(cacheManager).getCache("contentService-templateSupport"); will(returnValue(cache)); allowing(cache).get("<% \n %>${name} is awesome!"); will(returnValue(null)); allowing(cache).put(with(equal("<% \n %>${name} is awesome!")), with(any(Object.class))); }}); final TemplateProcessor templates = new MailComposerTemplateSupportGroovyImpl(new GroovyGStringTemplateSupportImpl(cacheManager)); final MailComposerImpl composer = new MailComposerImpl(null, templates); final Map<String, Object> model = createModelWithAttach(); final Map<String, byte[]> attach = composer.collectAttachments(model); assertNotNull(attach); assertFalse(attach.size() == model.size()); assertEquals(1, attach.size()); assertTrue(attach.entrySet().iterator().next().getKey().startsWith("attachment:")); mockery.assertIsSatisfied(); }
Map<String, byte[]> collectAttachments(final Map<String, Object> model) { final Map<String, byte[]> attachments = new HashMap<>(); for (final String key : model.keySet()) { if (key.startsWith(ATTACHMENT_PREFIX)) { final Object attachment = model.get(key); if (attachment instanceof byte[]) { attachments.put(key, (byte[]) attachment); } else { LOG.error("Invalid attachment in model. Attachments must be of type 'byte[]'"); } } } return attachments; }
MailComposerImpl implements MailComposer { Map<String, byte[]> collectAttachments(final Map<String, Object> model) { final Map<String, byte[]> attachments = new HashMap<>(); for (final String key : model.keySet()) { if (key.startsWith(ATTACHMENT_PREFIX)) { final Object attachment = model.get(key); if (attachment instanceof byte[]) { attachments.put(key, (byte[]) attachment); } else { LOG.error("Invalid attachment in model. Attachments must be of type 'byte[]'"); } } } return attachments; } }
MailComposerImpl implements MailComposer { Map<String, byte[]> collectAttachments(final Map<String, Object> model) { final Map<String, byte[]> attachments = new HashMap<>(); for (final String key : model.keySet()) { if (key.startsWith(ATTACHMENT_PREFIX)) { final Object attachment = model.get(key); if (attachment instanceof byte[]) { attachments.put(key, (byte[]) attachment); } else { LOG.error("Invalid attachment in model. Attachments must be of type 'byte[]'"); } } } return attachments; } MailComposerImpl(final MailTemplateResourcesProvider mailTemplateResourcesProvider,
                            final TemplateProcessor templateSupport); }
MailComposerImpl implements MailComposer { Map<String, byte[]> collectAttachments(final Map<String, Object> model) { final Map<String, byte[]> attachments = new HashMap<>(); for (final String key : model.keySet()) { if (key.startsWith(ATTACHMENT_PREFIX)) { final Object attachment = model.get(key); if (attachment instanceof byte[]) { attachments.put(key, (byte[]) attachment); } else { LOG.error("Invalid attachment in model. Attachments must be of type 'byte[]'"); } } } return attachments; } MailComposerImpl(final MailTemplateResourcesProvider mailTemplateResourcesProvider,
                            final TemplateProcessor templateSupport); String getResourceExpression(); void setResourceExpression(final String resourceExpression); @Override void composeMessage(final Mail mail,
                               final String shopCode,
                               final String locale,
                               final List<String> mailTemplateChain,
                               final String templateName,
                               final String from,
                               final String toEmail,
                               final String ccEmail,
                               final String bccEmail,
                               final Map<String, Object> model); @Override void convertMessage(final Mail mail, final MimeMessage mimeMessage); @Override String convertMessageToTXT(final Mail mail); @Override String convertMessageToHTML(final Mail mail); }
MailComposerImpl implements MailComposer { Map<String, byte[]> collectAttachments(final Map<String, Object> model) { final Map<String, byte[]> attachments = new HashMap<>(); for (final String key : model.keySet()) { if (key.startsWith(ATTACHMENT_PREFIX)) { final Object attachment = model.get(key); if (attachment instanceof byte[]) { attachments.put(key, (byte[]) attachment); } else { LOG.error("Invalid attachment in model. Attachments must be of type 'byte[]'"); } } } return attachments; } MailComposerImpl(final MailTemplateResourcesProvider mailTemplateResourcesProvider,
                            final TemplateProcessor templateSupport); String getResourceExpression(); void setResourceExpression(final String resourceExpression); @Override void composeMessage(final Mail mail,
                               final String shopCode,
                               final String locale,
                               final List<String> mailTemplateChain,
                               final String templateName,
                               final String from,
                               final String toEmail,
                               final String ccEmail,
                               final String bccEmail,
                               final Map<String, Object> model); @Override void convertMessage(final Mail mail, final MimeMessage mimeMessage); @Override String convertMessageToTXT(final Mail mail); @Override String convertMessageToHTML(final Mail mail);  }