Clover Coverage Report - Atlassian Mail
Coverage timestamp: Mon Sep 29 2008 21:26:36 CDT
138   243   16   9.2
2   205   0.12   15
15     1.07  
1    
 
 
  TestOFBizMailServerManager       Line # 30 138 16 98.7% 0.9870968
 
  (13)
 
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.5 $
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.managers;
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.CoreFactory;
17    import com.atlassian.mail.server.MailServer;
18    import com.atlassian.mail.server.PopMailServer;
19    import com.atlassian.mail.server.SMTPMailServer;
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 TestOFBizMailServerManager extends AbstractOFBizTestCase
31    {
32    private MockMailServerManager mmsm;
33   
 
34  13 toggle public TestOFBizMailServerManager(String s)
35    {
36  13 super(s);
37    }
38   
 
39  13 toggle protected void setUp() throws Exception
40    {
41  13 super.setUp();
42  13 mmsm = new MockMailServerManager();
43    }
44   
 
45  1 toggle public void testCreateSMTPAndGet() throws Exception
46    {
47  1 MailServer localMailServer = new SMTPMailServerImpl(new Long(1),"Name","Description","owen@atlassian.com","[OWEN]",false,"mail.atlassian.com","owen","fellows");
48  1 Long id = mmsm.create(localMailServer);
49  1 assertNotNull(id);
50  1 MailServer mailServer = mmsm.getMailServer(id);
51  1 assertEquals(localMailServer, mailServer);
52    }
53   
 
54  1 toggle public void testUpdateSMTP() throws Exception
55    {
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 SMTPMailServer smtp = (SMTPMailServer)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 Long id = mmsm.create(new SMTPMailServerImpl(new Long(1),"Name","Description","owen@atlassian.com","[OWEN]",false,"mail.atlassian.com","owen","fellows"));
78  1 MailServer mailServer = mmsm.getMailServer(id);
79  1 mmsm.delete(mailServer.getId());
80  1 assertNull(mmsm.getMailServer(id));
81    }
82   
 
83  1 toggle public void testGetMailServerGV() throws Exception
84    {
85  1 Map params = UtilMisc.toMap("id", new Long(1));
86  1 params.put("name","Name");
87  1 params.put("description","Description");
88  1 params.put("from","owen@atlassian.com");
89  1 params.put("prefix","[OWEN]");
90  1 params.put("servername","mail.atlassian.com");
91  1 params.put("smtpPort","25");
92  1 params.put("username","owen");
93  1 params.put("password","fellows");
94  1 params.put("type",OFBizMailServerManager.SERVER_TYPES[1]);
95  1 GenericValue gv = CoreFactory.getGenericDelegator().makeValue("MailServer", params);
96  1 Long id = mmsm.create(new SMTPMailServerImpl(new Long(1),"Name","Description","owen@atlassian.com","[OWEN]",false,"mail.atlassian.com","owen","fellows"));
97  1 GenericValue mailServerGV = mmsm.getMailServerGV(id);
98  1 assertEquals(gv, mailServerGV);
99    }
100   
 
101  1 toggle public void testConstructMailServer1()
102    {
103  1 MailServer oldMailServer = new SMTPMailServerImpl(new Long(1),"Name","Description","owen@atlassian.com","[OWEN]",false,"mail.atlassian.com","owen","fellows");
104  1 Map params = UtilMisc.toMap("id", new Long(1));
105  1 params.put("name","Name");
106  1 params.put("description","Description");
107  1 params.put("from","owen@atlassian.com");
108  1 params.put("prefix","[OWEN]");
109  1 params.put("servername","mail.atlassian.com");
110  1 params.put("username","owen");
111  1 params.put("password","fellows");
112  1 params.put("type",OFBizMailServerManager.SERVER_TYPES[1]);
113  1 GenericValue gv = CoreFactory.getGenericDelegator().makeValue("MailServer", params);
114  1 MailServer newMailServer = mmsm.constructMailServer(gv);
115  1 assertEquals(oldMailServer, newMailServer);
116    }
117   
 
118  1 toggle public void testConstructMailServer2()
119    {
120  1 MailServer oldMailServer = new SMTPMailServerImpl(new Long(1),"Name","Description","owen@atlassian.com","[OWEN]",true,"mail.atlassian.com",null,null);
121  1 Map params = UtilMisc.toMap("id", new Long(1));
122  1 params.put("name","Name");
123  1 params.put("description","Description");
124  1 params.put("from","owen@atlassian.com");
125  1 params.put("prefix","[OWEN]");
126  1 params.put("jndilocation","mail.atlassian.com");
127  1 params.put("username",null);
128  1 params.put("password",null);
129  1 params.put("type",OFBizMailServerManager.SERVER_TYPES[1]);
130  1 GenericValue gv = CoreFactory.getGenericDelegator().makeValue("MailServer", params);
131  1 MailServer newMailServer = mmsm.constructMailServer(gv);
132  1 assertEquals(oldMailServer, newMailServer);
133    }
134   
 
135  1 toggle public void testConstructMailServer3()
136    {
137  1 Map params = UtilMisc.toMap("id", new Long(1));
138  1 params.put("name","Name");
139  1 params.put("description","Description");
140  1 params.put("servername","mail.atlassian.com");
141  1 params.put("username","owen");
142  1 params.put("password","fellows");
143  1 params.put("type",OFBizMailServerManager.SERVER_TYPES[0]);
144  1 GenericValue gv = CoreFactory.getGenericDelegator().makeValue("MailServer", params);
145  1 MailServer newMailServer = mmsm.constructMailServer(gv);
146  1 PopMailServer expectedResult = new PopMailServerImpl(new Long(1), "Name", "Description", "mail.atlassian.com", "owen", "fellows");
147  1 assertEquals(expectedResult, newMailServer);
148    }
149   
 
150  1 toggle public void testConstructMailServer4()
151    {
152  1 Map params = UtilMisc.toMap("type","notype");
153  1 GenericValue gv = CoreFactory.getGenericDelegator().makeValue("MailServer", params);
154  1 MailServer newMailServer = mmsm.constructMailServer(gv);
155  1 assertEquals(null, newMailServer);
156    }
157   
 
158  1 toggle public void testGetMapFromColumns1() throws Exception
159    {
160  1 MailServer oldMailServer = new SMTPMailServerImpl(new Long(1),"Name","Description","owen@atlassian.com","[OWEN]",false,"mail.atlassian.com","owen","fellows");
161  1 Map oldMap = mmsm.getMapFromColumns(oldMailServer);
162  1 Map params = UtilMisc.toMap("name","Name");
163  1 params.put("description","Description");
164  1 params.put("from","owen@atlassian.com");
165  1 params.put("prefix","[OWEN]");
166  1 params.put("servername","mail.atlassian.com");
167  1 params.put("username","owen");
168  1 params.put("password","fellows");
169  1 params.put("smtpPort","25");
170  1 params.put("type",OFBizMailServerManager.SERVER_TYPES[1]);
171  1 assertEquals(oldMap, params);
172    }
173   
 
174  1 toggle public void testGetMapFromColumns2() throws Exception
175    {
176  1 MailServer oldMailServer = new SMTPMailServerImpl(new Long(1),"Name","Description","owen@atlassian.com","[OWEN]",true,"mail.atlassian.com",null,null);
177  1 Map oldMap = mmsm.getMapFromColumns(oldMailServer);
178  1 Map params = new HashMap();
179  1 params.put("name","Name");
180  1 params.put("description","Description");
181  1 params.put("from","owen@atlassian.com");
182  1 params.put("prefix","[OWEN]");
183  1 params.put("servername", null);
184  1 params.put("jndilocation", "mail.atlassian.com");
185  1 params.put("username",null);
186  1 params.put("password",null);
187  1 params.put("smtpPort","25");
188  1 params.put("type",OFBizMailServerManager.SERVER_TYPES[1]);
189  1 assertEquals(oldMap, params);
190    }
191   
 
192  1 toggle public void testGetMapFromColumns3() throws Exception
193    {
194  1 MailServer oldMailServer = new PopMailServerImpl(new Long(1),"Name","Description","mail.atlassian.com","owen","fellows");
195  1 Map oldMap = mmsm.getMapFromColumns(oldMailServer);
196  1 Map params = UtilMisc.toMap("name","Name");
197  1 params.put("description","Description");
198  1 params.put("username","owen");
199  1 params.put("password","fellows");
200  1 params.put("type",OFBizMailServerManager.SERVER_TYPES[0]);
201  1 params.put("servername","mail.atlassian.com");
202  1 assertEquals(oldMap, params);
203    }
204   
 
205  1 toggle public void testGetDefaultSMTPMailServer() throws Exception
206    {
207  1 SMTPMailServer server1 = new SMTPMailServerImpl(new Long(1), "Smtp Server Name1", "Description1", "test1@atlassian.com", "[OWEN]", false, "mail1.atlassian.com", "owen", "fellows");
208  1 SMTPMailServer server2 = new SMTPMailServerImpl(new Long(2), "Smtp Server Name", "Description2", "test2@atlassian.com", "[OWEN]", false, "mail2.atlassian.com", "owen", "fellows");
209  1 mmsm.create(server1);
210  1 mmsm.create(server2);
211   
212    // get it from the prefereneces-default.xml file
213  1 assertEquals(server2, mmsm.getDefaultSMTPMailServer());
214  1 assertEquals(server1, mmsm.getSmtpMailServers().get(0));
215   
216    // now get if from the first smtp server in servers
217  1 mmsm.delete(new Long(2));
218  1 assertEquals(server1, mmsm.getDefaultSMTPMailServer());
219  1 assertEquals(server1, mmsm.getSmtpMailServers().get(0));
220   
221    // cannot get any smtp servers, return null
222  1 mmsm.delete(new Long(1));
223  1 assertNull(mmsm.getDefaultSMTPMailServer());
224    }
225   
 
226  1 toggle public void testGetDefaultPopMailServer() throws Exception
227    {
228  1 PopMailServer server1 = new PopMailServerImpl(new Long(1), "Pop Server Name1", "Description1", "mail1.atlassian.com", "ownen", "fellows");
229  1 PopMailServer server2 = new PopMailServerImpl(new Long(2), "Pop Server Name", "Description2", "mail2.atlassian.com", "ownen", "fellows");
230  1 mmsm.create(server1);
231  1 mmsm.create(server2);
232   
233  1 assertEquals(server2, mmsm.getDefaultPopMailServer());
234  1 assertEquals(server1, mmsm.getPopMailServers().get(0));
235   
236  1 mmsm.delete(new Long(2));
237  1 assertEquals(server1, mmsm.getDefaultPopMailServer());
238  1 assertEquals(server1, mmsm.getPopMailServers().get(0));
239   
240  1 mmsm.delete(new Long(1));
241  1 assertNull(mmsm.getDefaultPopMailServer());
242    }
243    }