Package org.jvnet.mock_javamail

Examples of org.jvnet.mock_javamail.Mailbox


        assertMailboxReceivedMessages("route-test-copy@localhost");
    }

    protected void assertMailboxReceivedMessages(String name) throws Exception {
        Mailbox mailbox = Mailbox.get(name);
        assertEquals(name + " should have received 1 mail", 1, mailbox.size());

        Message message = mailbox.get(0);
        assertNotNull(name + " should have received at least one mail!", message);
        Object content = message.getContent();
        assertNotNull("The content should not be null!", content);
        if (content instanceof InputStream) {
            assertEquals("hello world!", IOConverter.toString((InputStream)content, null));
View Full Code Here


        String body = "Hello Claus.\nYes it does.\n\nRegards James.";
        template.sendBodyAndHeaders("smtp://davsclaus@apache.org", body, map);
        // END SNIPPET: e1

        Mailbox box = Mailbox.get("davsclaus@apache.org");
        Message msg = box.get(0);
        assertEquals("davsclaus@apache.org", msg.getRecipients(Message.RecipientType.TO)[0].toString());
        assertEquals("jstrachan@apache.org", msg.getFrom()[0].toString());
        assertEquals("Camel rocks", msg.getSubject());
    }
View Full Code Here

        template.sendBodyAndHeader("file://target/mailtext", "Hi how are you", Exchange.FILE_NAME, "mail.txt");

        assertMockEndpointsSatisfied();

        Mailbox mailbox = Mailbox.get("james@localhost");
        assertEquals(1, mailbox.size());
        Object body = mailbox.get(0).getContent();
        assertEquals("Hi how are you", body);
        Object subject = mailbox.get(0).getSubject();
        assertEquals("Hello World", subject);
    }
View Full Code Here

            });
        }

        assertMockEndpointsSatisfied();

        Mailbox box = Mailbox.get("someone@localhost");
        assertEquals(files, box.size());

        // as we use concurrent producers the mails can arrive out of order
        Set<Object> bodies = new HashSet<Object>();
        for (int i = 0; i < files; i++) {
            bodies.add(box.get(i).getContent());
        }

        assertEquals("There should be " + files + " unique mails", files, bodies.size());
    }
View Full Code Here

    public void testRendportIncident() throws Exception {
        // start camel
        startCamel();

        // assert mailbox is empty before starting
        Mailbox inbox = Mailbox.get("incident@mycompany.com");
        inbox.clear();
        assertEquals("Should not have mails", 0, inbox.size());

        // create input parameter
        InputReportIncident input = new InputReportIncident();
        input.setIncidentId("123");
        input.setIncidentDate("2008-08-18");
        input.setGivenName("Claus");
        input.setFamilyName("Ibsen");
        input.setSummary("Bla");
        input.setDetails("Bla bla");
        input.setEmail("davsclaus@apache.org");
        input.setPhone("0045 2962 7576");

        // create the webservice client and send the request
        ReportIncidentEndpoint client = createCXFClient();
        OutputReportIncident out = client.reportIncident(input);

        // assert we got a OK back
        assertEquals("0", out.getCode());

        // let some time pass to allow Camel to pickup the file and send it as an email
        Thread.sleep(3000);

        // assert mail box
        assertEquals("Should have got 1 mail", 1, inbox.size());

        // stop camel
        stopCamel();
    }
View Full Code Here

        assertMailboxReceivedMessages("route-test-copy@localhost");
    }

    protected void assertMailboxReceivedMessages(String name) throws Exception {
        Mailbox mailbox = Mailbox.get(name);
        assertEquals(name + " should have received 1 mail", 1, mailbox.size());

        Message message = mailbox.get(0);
        assertNotNull(name + " should have received at least one mail!", message);
        Object content = message.getContent();
        assertNotNull("The content should not be null!", content);
        if (content instanceof InputStream) {
            assertEquals("hello world!", IOConverter.toString((InputStream)content));
View Full Code Here

        for (Address addr : addresses) {
            if (addr instanceof InternetAddress) {
                addr = new InternetAddress(((InternetAddress) addr).getAddress());
            }

            Mailbox mailbox = Mailbox.get(addr);

            if (mailbox.isError()) {
                throw new MessagingException("Simulated error sending message to " + addr);
            }

            mailbox.add(new MimeMessage((MimeMessage) msg));
        }
    }
View Full Code Here

        return builder;
    }

    protected void setError(String targetAddress, boolean err) throws Exception {
        Mailbox inbox = Mailbox.get(targetAddress);
        inbox.setError(err);
    }
View Full Code Here

    private Message receiveMail(String targetAddress) throws Exception {
        return receiveMails(targetAddress, 1)[0];
    }

    private Message[] receiveMails(String targetAddress, int count) throws Exception {
        Mailbox mailbox = Mailbox.get(targetAddress);
        assertEquals(count, mailbox.size());

        Message[] msgs = mailbox.toArray(new Message[mailbox.size()]);

        Arrays.sort(msgs, new Comparator<Message>() {
            public int compare(Message o1, Message o2) {
                try {
                    return o1.getSubject().compareTo(o2.getSubject());
View Full Code Here

        super.setUp();
    }

    @Test
    public void testFetchSize() throws Exception {
        Mailbox mailbox = Mailbox.get("jones@localhost");
        assertEquals(5, mailbox.size());

        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(2);
        mock.expectedBodiesReceived("Message 0", "Message 1");
        // should be done within 2 seconds as no delay when started
        mock.setResultWaitTime(2000L);
        mock.assertIsSatisfied();

        Thread.sleep(500);
        assertEquals(3, mailbox.size());

        // reset mock to assert the next batch of 2 messages polled
        mock.reset();
        mock.expectedMessageCount(2);
        mock.expectedBodiesReceived("Message 2", "Message 3");
        // should be done within 5 (delay) + 1 seconds (polling)
        mock.setResultWaitTime(7000L);
        mock.assertIsSatisfied();

        Thread.sleep(500);
        assertEquals(1, mailbox.size());

        // reset mock to assert the last message polled
        mock.reset();
        mock.expectedMessageCount(1);
        mock.expectedBodiesReceived("Message 4");
View Full Code Here

TOP

Related Classes of org.jvnet.mock_javamail.Mailbox

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.