PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/server/mail/InvitationMailerTest.java

http://sigma-h.googlecode.com/
Java | 58 lines | 38 code | 16 blank | 4 comment | 0 complexity | 785913e08a0ad313301f5a2a116c1492 MD5 | raw file
 1/*
 2 * All Sigmah code is released under the GNU General Public License v3
 3 * See COPYRIGHT.txt and LICENSE.txt.
 4 */
 5
 6package org.sigmah.server.mail;
 7
 8import freemarker.template.Configuration;
 9import freemarker.template.TemplateException;
10import org.apache.commons.mail.EmailException;
11import org.junit.Test;
12import org.junit.runner.RunWith;
13import org.junit.runners.Parameterized;
14import org.sigmah.shared.domain.User;
15import org.sigmah.server.dao.hibernate.UserDAOImpl;
16import org.sigmah.server.util.TemplateModule;
17
18import java.io.IOException;
19import java.util.Arrays;
20import java.util.Collection;
21import java.util.Locale;
22
23import static junit.framework.Assert.assertTrue;
24
25@RunWith(Parameterized.class)
26public class InvitationMailerTest {
27
28    @Parameterized.Parameters
29    public static Collection<Object[]> locales() {
30        return Arrays.asList(new Object[][] { {Locale.ENGLISH}, { Locale.FRENCH }});
31    }
32
33    private Locale locale;
34
35    public InvitationMailerTest(Locale locale) {
36        this.locale = locale;
37    }
38
39    @Test
40    public void testExecutes() throws IOException, TemplateException, EmailException {
41    	
42    	
43        User newUser = UserDAOImpl.createNewUser("invitee@gmail.com", "Invitee", "en");
44        User invitingUser = UserDAOImpl.createNewUser("akbertram@gmail.com", "Inviter", "en");
45
46        Invitation invitation = new Invitation(newUser, invitingUser);
47
48        TemplateModule templateModule = new TemplateModule();
49        Configuration templateCfg = templateModule.provideConfiguration();
50
51        MockMailSender sender = new MockMailSender();
52        InvitationMailer mailer = new InvitationMailer(templateCfg, sender);
53
54        mailer.send(invitation, locale);
55
56        assertTrue(!sender.sentMail.isEmpty());
57    }
58}