1 package org.itracker.selenium;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.itracker.model.User;
6 import org.itracker.persistence.dao.UserDAO;
7 import org.junit.Test;
8 import org.openqa.selenium.By;
9 import org.subethamail.wiser.WiserMessage;
10
11 import static org.itracker.Assert.assertEquals;
12 import static org.itracker.Assert.assertTrue;
13
14
15
16
17
18
19 public class CreateIssueSeleniumIT extends AbstractSeleniumTestCase {
20
21 private static final Logger log = Logger.getLogger(CreateIssueSeleniumIT.class);
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 @Test
37 public void testCreateUnassignedIssue() throws Exception {
38 log.info(" running testCreateUnassignedIssue");
39 closeSession();
40
41 final String descriptionValue = "Issue to be unassigned.";
42 final String historyValue = "Issue to be unassigned history.";
43
44 driver.get(applicationURL);
45
46 login("admin_test1", "admin_test1");
47
48
49 assertElementPresent(By.name("listprojects")).click();
50 waitForPageToLoad();
51
52
53 assertElementPresent(By.xpath("//tr[starts-with(@id, 'project.')]" +
54 "/td[normalize-space(text())='test_name']/.." +
55 "/td//a[2]"))
56 .click();
57 waitForPageToLoad();
58
59 assertElementPresent(By.name("description"));
60 assertElementPresent(By.name("ownerId"));
61 assertElementPresent(By.name("creatorId"));
62 assertElementPresent(By.name("severity"));
63 assertElementPresent(By.name("versions"));
64
65 assertElementPresent(By.name("description"))
66 .sendKeys(descriptionValue);
67 assertElementPresent(By.name("history"))
68 .sendKeys(historyValue);
69
70 log.debug(driver.getPageSource());
71
72 assertElementPresent(By.cssSelector("select[name='ownerId'] option[value='-1']")).click();
73 final UserDAO userDao = (UserDAO) applicationContext.getBean("userDAO");
74 final User user = userDao.findByLogin("admin_test1");
75 assertTrue(null != user);
76 final long userId = user.getId();
77 assertElementPresent(By.cssSelector("select[name='creatorId'] option[value='" + userId + "']"))
78 .click();
79
80 int received = wiser.getMessages().size();
81
82 assertElementPresent(By.cssSelector("input[type='submit']"))
83 .click();
84 waitForPageToLoad();
85
86 assertEquals("wiser.receivedEmailSize", received + 1, wiser.getMessages().size());
87 final WiserMessage smtpMessage = wiser.getMessages().get(received);
88 final String smtpMessageBody = (String) smtpMessage.getMimeMessage().getContent();
89
90
91 log.debug("testCreateUnassignedIssue, received:\n" + smtpMessageBody);
92
93
94 assertTrue("System URL in Message body, " + applicationURL + ", " + smtpMessageBody,
95 StringUtils.containsIgnoreCase(smtpMessageBody, applicationURL));
96
97 assertTrue("Description not contained in Message body, " + descriptionValue,
98 smtpMessageBody.contains(descriptionValue));
99 assertTrue("History not contained in Message body," + historyValue,
100 smtpMessageBody.contains(historyValue));
101
102
103 assertElementPresent(By.id("issues"));
104 assertElementCountEquals(5, By.xpath("//*[starts-with(@id, 'issue.')]"));
105
106 assertElementPresent(By.xpath("//tr[starts-with(@id, 'issue.')]" +
107 "/td[normalize-space(text())=normalize-space('" + descriptionValue + "')]"));
108
109 driver.get(applicationURL + "/portalhome.do");
110
111
112 assertElementPresent(By.xpath("//tr[starts-with(@id,'unassignedIssue.')]" +
113 "/td[normalize-space(text())='test_name']/.." +
114 "/td[normalize-space(text())=normalize-space('" + descriptionValue + "')]"));
115
116
117 assertElementPresent(By.xpath("//tr[starts-with(@id,'createdIssue.')]" +
118 "/td[normalize-space(text())='test_name']/.." +
119 "/td[normalize-space(text())=normalize-space('" + descriptionValue + "')]"));
120
121
122 assertElementNotPresent(By.xpath("//*[starts-with(@id, 'watchedIssue.')]"));
123 }
124
125
126
127
128 @Test
129 public void testCreateAssignedIssue() throws Exception {
130
131 final String descriptionValue = "Issue to be assigned.";
132 final String historyValue = "Issue to be assigned history.";
133
134 log.info(" running testCreateAssignedIssue");
135 closeSession();
136
137 driver.get(applicationURL);
138
139 login("admin_test1", "admin_test1");
140
141
142 assertElementPresent(By.name("listprojects"))
143 .click();
144 waitForPageToLoad();
145
146
147 assertElementPresent(By.xpath("//tr[starts-with(@id, 'project.')]" +
148 "/td[normalize-space(text())='test_name']/.." +
149 "/td//a[2]"))
150 .click();
151 waitForPageToLoad();
152
153 assertElementPresent(By.name("description"))
154 .sendKeys(descriptionValue);
155 assertElementPresent(By.name("ownerId"));
156 assertElementPresent(By.name("creatorId"));
157 assertElementPresent(By.name("severity"));
158 assertElementPresent(By.name("versions"));
159 assertElementPresent(By.name("history"))
160 .sendKeys(historyValue);
161
162 final UserDAO userDao = (UserDAO) applicationContext.getBean("userDAO");
163 final User user = userDao.findByLogin("admin_test1");
164 assertTrue("user #admin_test1", null != user);
165 final long userId = user.getId();
166 assertElementPresent(By.cssSelector("select[name='ownerId'] option[value='" + userId + "']"))
167 .click();
168 assertElementPresent(By.cssSelector("select[name='creatorId'] option[value='" + userId + "']"))
169 .click();
170
171 int received = wiser.getMessages().size();
172 assertElementPresent(By.cssSelector("input[type='submit']"))
173 .click();
174 waitForPageToLoad();
175
176 assertEquals("wiser.receivedEmailSize", received + 2, wiser.getMessages().size());
177 final WiserMessage smtpMessage1 = wiser.getMessages().get(received);
178 final WiserMessage smtpMessage2 = wiser.getMessages().get(received + 1);
179
180 final String smtpMessageBody1 = (String) smtpMessage1.getMimeMessage().getContent();
181 final String smtpMessageBody2 = (String) smtpMessage2.getMimeMessage().getContent();
182
183
184 log.debug("testCreateAssignedIssue, received:\n " + smtpMessageBody1);
185 assertTrue(smtpMessageBody1.contains(descriptionValue));
186 assertTrue(smtpMessageBody1.contains(historyValue));
187
188
189 log.debug("testCreateAssignedIssue, received2:\n " + smtpMessageBody2);
190 assertTrue(smtpMessageBody2.contains(descriptionValue));
191 assertTrue(smtpMessageBody2.contains(historyValue));
192
193
194 assertElementPresent(By.id("issues"));
195 assertElementCountEquals(5, By.xpath("//*[starts-with(@id, 'issue.')]"));
196
197 assertElementPresent(By.xpath("//*[starts-with(@id, 'issue.')]" +
198 "/td[normalize-space(text())=normalize-space('" + descriptionValue + "')]"));
199
200 driver.get(applicationURL + "/portalhome.do");
201
202
203 assertElementNotPresent(By.xpath("//tr[starts-with(@id,'unassignedIssue.')]" +
204 "/td[normalize-space(text())='test_name']/.." +
205 "/td[normalize-space(text())=normalize-space('" + descriptionValue + "')]"));
206
207
208 assertElementPresent(By.xpath("//tr[starts-with(@id,'createdIssue.')]" +
209 "/td[normalize-space(text())='test_name']/.." +
210 "/td[normalize-space(text())=normalize-space('" + descriptionValue + "')]"));
211
212
213 assertElementNotPresent(By.xpath("//*[starts-with(@id, 'watchedIssue.')]"));
214 }
215
216 @Override
217 protected String[] getDataSetFiles() {
218 return new String[]{
219 "dataset/languagebean_init_dataset.xml",
220 "dataset/languagebean_dataset.xml",
221 "dataset/userpreferencesbean_dataset.xml",
222 "dataset/userbean_dataset.xml",
223 "dataset/projectbean_dataset.xml",
224 "dataset/permissionbean_dataset.xml",
225 "dataset/versionbean_dataset.xml",
226 "dataset/issuebean_dataset.xml",
227 "dataset/issueversionrel_dataset.xml",
228 "dataset/issueactivitybean_dataset.xml",
229 "dataset/issuehistorybean_dataset.xml"
230 };
231 }
232
233
234 }