Clover Coverage Report - Atlassian Mail
Coverage timestamp: Mon Sep 29 2008 21:26:36 CDT
127   213   14   9.77
2   187   0.11   13
13     1.08  
1    
 
 
  TestMailServerManager       Line # 30 127 14 98.6% 0.9859155
 
  (11)
 
1    /*
2    * Created by IntelliJ IDEA.
3    * User: owen
4    * Date: Nov 25, 2002
5    * Time: 10:44:50 AM
6    * CVS Revision: $Revision: 1.11 $
7    * Last CVS Commit: $Date: 2005/05/10 07:01:16 $
8    * Author of last CVS Commit: $Author: schang $
9    * To change this template use Options | File Templates.
10    */
11    package test.atlassian.mail.server;
12   
13    import com.atlassian.core.ofbiz.CoreFactory;
14    import com.atlassian.core.ofbiz.test.AbstractOFBizTestCase;
15    import com.atlassian.core.ofbiz.test.AbstractOFBizTestCase;
16    import com.atlassian.core.ofbiz.test.UtilsForTests;
17    import com.atlassian.core.ofbiz.test.UtilsForTests;
18    import com.atlassian.core.ofbiz.CoreFactory;
19    import com.atlassian.mail.server.MailServer;
20    import com.atlassian.mail.server.impl.PopMailServerImpl;
21    import com.atlassian.mail.server.impl.SMTPMailServerImpl;
22    import com.atlassian.mail.server.managers.OFBizMailServerManager;
23    import org.ofbiz.core.entity.GenericValue;
24    import org.ofbiz.core.util.UtilMisc;
25    import test.mock.mail.server.MockMailServerManager;
26   
27    import java.util.HashMap;
28    import java.util.Map;
29   
 
30    public class TestMailServerManager extends AbstractOFBizTestCase
31    {
 
32  11 toggle public TestMailServerManager(String s)
33    {
34  11 super(s);
35    }
36   
 
37  11 toggle protected void tearDown() throws Exception
38    {
39  11 UtilsForTests.cleanUsers();
40  11 super.tearDown();
41    }
42   
 
43  1 toggle public void testCreateSMTPAndGet() throws Exception
44    {
45  1 MockMailServerManager mmsm = new MockMailServerManager();
46  1 MailServer localMailServer = new SMTPMailServerImpl(new Long(1), "Name", "Description", "owen@atlassian.com", "[OWEN]", false, "mail.atlassian.com", "owen", "fellows");
47  1 Long id = mmsm.create(localMailServer);
48  1 assertNotNull(id);
49  1 MailServer mailServer = mmsm.getMailServer(id);
50  1 assertEquals(localMailServer, mailServer);
51    }
52   
 
53  1 toggle public void testUpdateSMTP() throws Exception
54    {
55  1 MockMailServerManager mmsm = new MockMailServerManager();
56  1 Long id = mmsm.create(new SMTPMailServerImpl(new Long(1), "Name", "Description", "owen@atlassian.com", "[OWEN]", false, "mail.atlassian.com", "owen", "fellows"));
57  1 MailServer mailServer = mmsm.getMailServer("Name");
58  1 if (OFBizMailServerManager.SERVER_TYPES[1].equals(mailServer.getType()))
59    {
60  1 SMTPMailServerImpl smtp = (SMTPMailServerImpl) mailServer;
61  1 smtp.setUsername(null);
62  1 smtp.setPassword(null);
63  1 smtp.setName("new name");
64  1 mmsm.update(smtp);
65  1 MailServer updatedMailServer = mmsm.getMailServer(id);
66  1 assertNull(updatedMailServer.getUsername());
67  1 assertNull(updatedMailServer.getPassword());
68  1 assertEquals("new name", updatedMailServer.getName());
69  1 assertEquals(mailServer, updatedMailServer);
70    }
71    else
72  0 fail("Mail Server returned is not an SMTP server");
73    }
74   
 
75  1 toggle public void testDeleteSMTP() throws Exception
76    {
77  1 MockMailServerManager mmsm = new MockMailServerManager();
78  1 Long id = mmsm.create(new SMTPMailServerImpl(new Long(1), "Name", "Description", "owen@atlassian.com", "[OWEN]", false, "mail.atlassian.com", "owen", "fellows"));
79  1 MailServer mailServer = mmsm.getMailServer(id);
80  1 mmsm.delete(mailServer.getId());
81  1 assertNull(mmsm.getMailServer(id));
82    }
83   
 
84  1 toggle public void testGetMailServerGV() throws Exception
85    {
86  1 MockMailServerManager mmsm = new MockMailServerManager();
87  1 Map params = UtilMisc.toMap("id", new Long(1));
88  1 params.put("name", "Name");
89  1 params.put("description", "Description");
90  1 params.put("from", "owen@atlassian.com");
91  1 params.put("prefix", "[OWEN]");
92  1 params.put("smtpPort", "25");
93  1 params.put("servername", "mail.atlassian.com");
94  1 params.put("username", "owen");
95  1 params.put("password", "fellows");
96  1 params.put("type", OFBizMailServerManager.SERVER_TYPES[1]);
97  1 GenericValue gv = CoreFactory.getGenericDelegator().makeValue("MailServer", params);
98  1 Long id = mmsm.create(new SMTPMailServerImpl(new Long(1), "Name", "Description", "owen@atlassian.com", "[OWEN]", false, "mail.atlassian.com", "owen", "fellows"));
99  1 GenericValue mailServerGV = mmsm.getMailServerGV(id);
100  1 assertEquals(gv, mailServerGV);
101    }
102   
 
103  1 toggle public void testConstructMailServer1()
104    {
105  1 MockMailServerManager mmsm = new MockMailServerManager();
106  1 MailServer oldMailServer = new SMTPMailServerImpl(new Long(1), "Name", "Description", "owen@atlassian.com", "[OWEN]", false, "mail.atlassian.com", "owen", "fellows");
107  1 Map params = UtilMisc.toMap("id", new Long(1));
108  1 params.put("name", "Name");
109  1 params.put("description", "Description");
110  1 params.put("from", "owen@atlassian.com");
111  1 params.put("prefix", "[OWEN]");
112  1 params.put("servername", "mail.atlassian.com");
113  1 params.put("username", "owen");
114  1 params.put("password", "fellows");
115  1 params.put("type", OFBizMailServerManager.SERVER_TYPES[1]);
116  1 GenericValue gv = CoreFactory.getGenericDelegator().makeValue("MailServer", params);
117  1 MailServer newMailServer = mmsm.constructMailServer(gv);
118  1 assertEquals(oldMailServer, newMailServer);
119    }
120   
 
121  1 toggle public void testConstructMailServer2()
122    {
123  1 MockMailServerManager mmsm = new MockMailServerManager();
124  1 MailServer oldMailServer = new SMTPMailServerImpl(new Long(1), "Name", "Description", "owen@atlassian.com", "[OWEN]", true, "mail.atlassian.com", "owen", "fellows");
125  1 Map params = UtilMisc.toMap("id", new Long(1));
126  1 params.put("name", "Name");
127  1 params.put("description", "Description");
128  1 params.put("from", "owen@atlassian.com");
129  1 params.put("prefix", "[OWEN]");
130  1 params.put("jndilocation", "mail.atlassian.com");
131  1 params.put("username", "owen");
132  1 params.put("password", "fellows");
133  1 params.put("type", OFBizMailServerManager.SERVER_TYPES[1]);
134  1 GenericValue gv = CoreFactory.getGenericDelegator().makeValue("MailServer", params);
135  1 MailServer newMailServer = mmsm.constructMailServer(gv);
136  1 assertEquals(oldMailServer, newMailServer);
137    }
138   
 
139  1 toggle public void testConstructMailServer3()
140    {
141  1 MockMailServerManager mmsm = new MockMailServerManager();
142  1 MailServer oldMailServer = new PopMailServerImpl(new Long(1), "Name", "Description", "mail.atlassian.com", "owen", "fellows");
143  1 Map params = UtilMisc.toMap("id", new Long(1));
144  1 params.put("name", "Name");
145  1 params.put("description", "Description");
146  1 params.put("servername", "mail.atlassian.com");
147  1 params.put("username", "owen");
148  1 params.put("password", "fellows");
149  1 params.put("type", OFBizMailServerManager.SERVER_TYPES[0]);
150  1 GenericValue gv = CoreFactory.getGenericDelegator().makeValue("MailServer", params);
151  1 MailServer newMailServer = mmsm.constructMailServer(gv);
152  1 assertEquals(oldMailServer, newMailServer);
153    }
154   
 
155  1 toggle public void testConstructMailServer4()
156    {
157  1 MockMailServerManager mmsm = new MockMailServerManager();
158  1 Map params = UtilMisc.toMap("type", "notype");
159  1 GenericValue gv = CoreFactory.getGenericDelegator().makeValue("MailServer", params);
160  1 MailServer newMailServer = mmsm.constructMailServer(gv);
161  1 assertEquals(null, newMailServer);
162    }
163   
 
164  1 toggle public void testGetMapFromColumns1() throws Exception
165    {
166  1 MockMailServerManager mmsm = new MockMailServerManager();
167  1 MailServer oldMailServer = new SMTPMailServerImpl(new Long(1), "Name", "Description", "owen@atlassian.com", "[OWEN]", false, "mail.atlassian.com", "owen", "fellows");
168  1 Map oldMap = mmsm.getMapFromColumns(oldMailServer);
169  1 Map params = UtilMisc.toMap("name", "Name");
170  1 params.put("description", "Description");
171  1 params.put("from", "owen@atlassian.com");
172  1 params.put("prefix", "[OWEN]");
173  1 params.put("smtpPort", "25");
174  1 params.put("servername", "mail.atlassian.com");
175  1 params.put("username", "owen");
176  1 params.put("password", "fellows");
177  1 params.put("type", OFBizMailServerManager.SERVER_TYPES[1]);
178  1 assertEquals(oldMap, params);
179    }
180   
 
181  1 toggle public void testGetMapFromColumns2() throws Exception
182    {
183  1 MockMailServerManager mmsm = new MockMailServerManager();
184  1 MailServer oldMailServer = new SMTPMailServerImpl(new Long(1), "Name", "Description", "owen@atlassian.com", "[OWEN]", true, "mail.atlassian.com", null, null);
185  1 Map oldMap = mmsm.getMapFromColumns(oldMailServer);
186  1 Map params = new HashMap();
187  1 params.put("name", "Name");
188  1 params.put("description", "Description");
189  1 params.put("from", "owen@atlassian.com");
190  1 params.put("prefix", "[OWEN]");
191  1 params.put("smtpPort", "25");
192  1 params.put("servername", null);
193  1 params.put("jndilocation", "mail.atlassian.com");
194  1 params.put("type", OFBizMailServerManager.SERVER_TYPES[1]);
195  1 params.put("username", null);
196  1 params.put("password", null);
197  1 assertEquals(oldMap, params);
198    }
199   
 
200  1 toggle public void testGetMapFromColumns3() throws Exception
201    {
202  1 MockMailServerManager mmsm = new MockMailServerManager();
203  1 MailServer oldMailServer = new PopMailServerImpl(new Long(1), "Name", "Description", "mail.atlassian.com", "owen", "fellows");
204  1 Map oldMap = mmsm.getMapFromColumns(oldMailServer);
205  1 Map params = UtilMisc.toMap("name", "Name");
206  1 params.put("description", "Description");
207  1 params.put("username", "owen");
208  1 params.put("password", "fellows");
209  1 params.put("type", OFBizMailServerManager.SERVER_TYPES[0]);
210  1 params.put("servername", "mail.atlassian.com");
211  1 assertEquals(oldMap, params);
212    }
213    }