Package com.alibaba.citrus.service.mail.builder

Examples of com.alibaba.citrus.service.mail.builder.MailBuilder


        assertEquals(1, StringUtil.countMatches(eml, "Content-Disposition: inline; filename=java.gif"));
        assertEquals(1, StringUtil.countMatches(eml, "Content-Disposition: inline; filename=bible.jpg"));
    }

    private MailBuilder createVeryComplexMail() {
        MailBuilder builder = new MailBuilder();

        // 创建所有contents。
        MultipartContent attachable = new MixedMultipartContent();
        attachable.setId("attachable");

        MultipartContent alternative = new AlternativeMultipartContent();
        alternative.setId("alternative");

        TextContent plainText = new TextContent("我爱北京敏感词", "text/plain");
        plainText.setId("plainText");

        TextContent htmlText = new TextContent("<爱北京敏感词>", "text/html");
        htmlText.setId("htmlText");

        TextTemplateContent plainTextTemplate = new TextTemplateContent("mail/mytemplate.vm", "text/plain");
        plainTextTemplate.setId("plainTextTemplate");

        AttachmentContent textAttachment = new AttachmentContent("testfile.txt");
        textAttachment.setId("textAttachment");

        HTMLTemplateContent htmlTemplate = new HTMLTemplateContent("mail/complexhtml.vm");
        htmlTemplate.setId("htmlTemplate");

        plainTextTemplate.setTemplateService(templateService);
        plainTextTemplate.setPullService(pullService);

        htmlTemplate.setTemplateService(templateService);
        htmlTemplate.setPullService(pullService);
        htmlTemplate.setResourceLoader(factory);
        htmlTemplate.addInlineResource("image", "/");

        textAttachment.setResourceLoader(factory);

        // 加入builder
        builder.setContent(attachable);
        {
            attachable.addContent(alternative);
            {
                alternative.addContent(plainText);
                alternative.addContent(htmlText);
            }

            attachable.addContent(plainTextTemplate);
            attachable.addContent(textAttachment);
            attachable.addContent(htmlTemplate);
        }

        // 检查getId()
        assertSame(attachable, builder.getContent("attachable"));
        assertSame(alternative, builder.getContent("alternative"));
        assertSame(plainText, builder.getContent("plainText"));
        assertSame(htmlText, builder.getContent("htmlText"));
        assertSame(plainTextTemplate, builder.getContent("plainTextTemplate"));
        assertSame(textAttachment, builder.getContent("textAttachment"));
        assertSame(htmlTemplate, builder.getContent("htmlTemplate"));

        return builder;
    }
View Full Code Here


        }
    }

    @Test
    public void send_single_builder() throws Exception {
        MailBuilder builder = createMailBuilder("", ALIREN_ALIBABA_COM);
        builder.setSentDate(new Date(0L)); // 1970s

        session.setDebug(true);

        assertFalse(session.isConnected());
        session.send(builder);
View Full Code Here

        assertFalse(session.isConnected());
    }

    @Test
    public void send_single_builder_handler() throws Exception {
        MailBuilder builder = createMailBuilder("", ALIREN_ALIBABA_COM);
        builder.setSentDate(new Date(0L)); // 1970s

        session.setDebug(true);
        assertFalse(session.isConnected());

        MyHandler handler = new MyHandler(builder);
View Full Code Here

    public void setMails() {
        MailServiceImpl mailService = new MailServiceImpl();

        // miss mail id
        Map<String, MailBuilder> mails = createHashMap();
        mails.put(null, new MailBuilder());

        try {
            mailService.setMails(mails);
            fail();
        } catch (IllegalArgumentException e) {
            assertThat(e, exception("mail id"));
        }

        // miss mail object
        mails = createHashMap();
        mails.put("id", null);

        try {
            mailService.setMails(mails);
            fail();
        } catch (IllegalArgumentException e) {
            assertThat(e, exception("mail builder"));
        }

        // set null
        mailService = new MailServiceImpl();
        mailService.setMails(null);

        // reset mails
        mails = createHashMap();
        mails.put("mail1", new MailBuilder());
        mails.put("mail2", new MailBuilder());
        mailService.setMails(mails);

        assertNotNull(mailService.getMailBuilder("mail1"));
        assertNotNull(mailService.getMailBuilder("mail2"));

        mails = createHashMap();
        mails.put("mail3", new MailBuilder());
        mails.put("mail4", new MailBuilder());
        mailService.setMails(mails);

        try {
            mailService.getMailBuilder("mail1");
            fail();
View Full Code Here

    protected abstract T createMailSession(MailService service);

    protected abstract T copyMailSession(T session, Properties overrideProps);

    protected Message createMessage(String subject, String addr) {
        MailBuilder builder = createMailBuilder(subject, addr);
        builder.setSentDate(new Date(0));
        return builder.getMessage(rawSession);
    }
View Full Code Here

        builder.setSentDate(new Date(0));
        return builder.getMessage(rawSession);
    }

    protected MailBuilder createMailBuilder(String subject, String addr) {
        MailBuilder builder = new MailBuilder();

        builder.setSubject(subject);
        builder.setContent(new TextContent());
        builder.setAddress(MailAddressType.TO, addr);

        return builder;
    }
View Full Code Here

        }
    }

    @Test
    public void clone_builder_empty() {
        MailBuilder copy = builder.clone();

        assertEquals(null, copy.getMailService());
        assertEquals(null, copy.getId());
        assertEquals("UTF-8", copy.getCharacterEncoding());

        for (MailAddressType addrType : MailAddressType.values()) {
            assertAddresses(copy, addrType);
        }

        assertEquals(0, copy.getAttributeKeys().size());

        assertEquals(null, copy.getSubject());

        Date sentDate = copy.getSentDate(); // lazy set current date

        assertNotNull(sentDate);
        assertTrue(sentDate.getTime() - System.currentTimeMillis() < 1000);

        assertSame(null, copy.getContent());
    }
View Full Code Here

        Date sentDate = new Date(0);

        initBuilder(builder, obj, sentDate);

        // clone
        MailBuilder copy = builder.clone();

        assertSame(mailService, copy.getMailService());
        assertEquals("myid", copy.getId());
        assertEquals("EUC_JP", copy.getCharacterEncoding());

        for (MailAddressType addrType : MailAddressType.values()) {
            assertAddresses(copy, addrType, "=?euc-jp?B?w+a58Q==?= <china@earth.com>");
        }

        assertEquals(1, copy.getAttributeKeys().size());
        assertSame(obj, copy.getAttribute("aaa"));

        assertEquals("my SUBJECT", copy.getSubject());

        assertSame(sentDate, copy.getSentDate());

        assertNotSame(builder.getContent(), copy.getContent());
        assertSame(obj, ((MyContent) copy.getContent()).object);
    }
View Full Code Here

        } catch (IllegalStateException e) {
            assertThat(e, exception("Attachment source already set: URL[", "testfile.txt]"));
        }

        try {
            content.setMail(new MailBuilder());
            fail();
        } catch (IllegalStateException e) {
            assertThat(e, exception("Attachment source already set: URL[", "testfile.txt]"));
        }

        try {
            content.setMail(new MailBuilder().getMessage(rawSession));
            fail();
        } catch (IllegalStateException e) {
            assertThat(e, exception("Attachment source already set: URL[", "testfile.txt]"));
        }
View Full Code Here

        } catch (IllegalArgumentException e) {
            assertThat(e, exception("mailBuilder"));
        }

        // mailBuilder
        MailBuilder attached = new MailBuilder();

        attached.setSubject("附件标题");
        attached.setContent(new TextContent("我爱北京敏感词", "text/plain"));

        content = new AttachmentContent(attached);
        builder.setContent(content);

        assert_Mail_我爱北京敏感词();
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.service.mail.builder.MailBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.