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

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


        }
    }

    @Test
    public void clone_builder_empty() {
        MailBuilder copy = (MailBuilder) 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 = (MailBuilder) 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

    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

    }

    @Test
    public void build() throws Exception {
        builder = createVeryComplexMail();
        MailBuilder copy = builder.clone();

        // ���content tree�Ƿ�Ϊ������ͬ��ʵ����ͬ
        Object[] tree1 = getMailBuilderTree(builder);
        Object[] tree2 = getMailBuilderTree(copy);
View Full Code Here

        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

    protected final <T> T getService(Class<T> serviceType, String defaultId, T defaultInstance) {
        if (defaultInstance != null) {
            return defaultInstance;
        }

        MailBuilder builder = getMailBuilder(false);

        if (builder != null) {
            MailService mailService = builder.getMailService();

            if (mailService != null) {
                return mailService.getService(serviceType, defaultId);
            }
        }
View Full Code Here

            if (mailService == null) {
                throw new MailBuilderException("Could not find mail \"" + mailRef + "\": no MailService");
            }

            MailBuilder mailBuilder;

            try {
                mailBuilder = mailService.getMailBuilder(mailRef);
            } catch (MailNotFoundException e) {
                throw new MailBuilderException("Could not find mail \"" + mailRef + "\"", e);
            }

            Message mail = mailBuilder.getMessage(getMailBuilder().getSession());

            render(mailPart, mail);
        }
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

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.