1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
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 |
|
|
|
|
| 98.6% |
Uncovered Elements: 2 (142) |
Complexity: 14 |
Complexity Density: 0.11 |
|
30 |
|
public class TestMailServerManager extends AbstractOFBizTestCase |
31 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
32 |
11
|
public TestMailServerManager(String s)... |
33 |
|
{ |
34 |
11
|
super(s); |
35 |
|
} |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
37 |
11
|
protected void tearDown() throws Exception... |
38 |
|
{ |
39 |
11
|
UtilsForTests.cleanUsers(); |
40 |
11
|
super.tearDown(); |
41 |
|
} |
42 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
43 |
1
|
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 |
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 2 |
Complexity Density: 0.13 |
1
PASS
|
|
53 |
1
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1
PASS
|
|
75 |
1
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1
PASS
|
|
84 |
1
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1
PASS
|
|
103 |
1
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1
PASS
|
|
121 |
1
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
139 |
1
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1
PASS
|
|
155 |
1
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
164 |
1
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1
PASS
|
|
181 |
1
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
200 |
1
|
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 |
|
} |