View Javadoc

1   package org.itracker.selenium;
2   
3   import com.dumbster.smtp.SimpleSmtpServer;
4   import com.dumbster.smtp.SmtpMessage;
5   
6   import java.io.IOException;
7   import java.util.Iterator;
8   
9   import org.junit.Test;
10  
11  /**
12   * Verifies the functionality of Edit Issue page.
13   *
14   * @author Andrey Sergievskiy <seas@andreysergievskiy.com>
15   */
16  public class EditIssueTest extends AbstractSeleniumTestCase {
17  
18      /**
19       * Editing one of tickets.
20       * 1. Enter the system with some particular user (admin_test1).
21       * 2. Goto Projects List page.
22       * 3. Click "View" link for some project (test_name).
23       * 4. Click "View" link for selected issue (no 1).
24       * 5. Click "Edit" link.
25       * 6. Update the description for this issue.
26       * 7. Submit the form.
27       * 8. Check if we got email notification about modifications.
28       * 9. Being at "View Issues" page, right after saving updated issues,
29       * check that no more issues with old description is here, but
30       * new description has appeared.
31       *
32       * @throws java.io.IOException
33       */
34      @Test
35      public void testEditIssue1FromViewIssue() throws Exception {
36          log.info("running testEditIssue1FromViewIssue");
37          closeSession();
38          selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
39                  + applicationPath);
40  
41          assertTrue(selenium.isElementPresent("//.[@name='login']"));
42          assertTrue(selenium.isElementPresent("//.[@name='password']"));
43          assertTrue(selenium.isElementPresent("//.[@value='Login']"));
44          selenium.type("//.[@name='login']", "admin_test1");
45          selenium.type("//.[@name='password']", "admin_test1");
46          selenium.click("//.[@value='Login']");
47          selenium.waitForPageToLoad(SE_TIMEOUT);
48  
49          selenium.click("listprojects");
50          selenium.waitForPageToLoad(SE_TIMEOUT);
51  
52          // Click view issue link (usually it's named "View").
53          assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'project.')]/td[3][text()='test_name']/../td[1]/a[1]"));
54          selenium.click("//tr[starts-with(@id, 'project.')]/td[3][text()='test_name']/../td[1]/a[1]");
55          selenium.waitForPageToLoad(SE_TIMEOUT);
56  
57          assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description']/../td[1]/a[1]"));
58          selenium.click("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description']/../td[1]/a[1]");
59          selenium.waitForPageToLoad(SE_TIMEOUT);
60  
61          assertTrue(selenium.isElementPresent("//td[@id='actions']/a[2]"));
62          selenium.click("//td[@id='actions']/a[2]");
63          selenium.waitForPageToLoad(SE_TIMEOUT);
64  
65          assertTrue(selenium.isElementPresent("description"));
66          assertTrue(selenium.isElementPresent("ownerId"));
67          assertTrue(selenium.isElementPresent("//input[@type='submit']"));
68  
69          selenium.type("description", "test_description (updated)");
70  
71  
72          startSMTP();
73          try {
74              selenium.click("//input[@type='submit']");
75              selenium.waitForPageToLoad(SE_TIMEOUT);
76  
77              assertEquals("smtpServer.receivedEmailSize", 1, smtpServer.getReceivedEmailSize());
78              final Iterator<SmtpMessage> iter =
79                      (Iterator<SmtpMessage>) smtpServer.getReceivedEmail();
80              // Checking email notification for creator.
81              final SmtpMessage smtpMessage = iter.next();
82              final String smtpMessageBody = smtpMessage.getBody();
83              assertTrue(smtpMessageBody.contains("test_description (updated)"));
84  
85          } finally {
86              stopSMTP();
87          }
88  
89  
90          assertTrue(selenium.isElementPresent("issues"));
91          assertEquals(4, selenium.getXpathCount("//tr[starts-with(@id, 'issue.')]"));
92          assertFalse(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description']/../td[13][contains(text(),'A. admin lastname')]"));
93          assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description (updated)']/../td[13][contains(text(),'A. admin lastname')]"));
94      }
95  
96      /**
97       * Editing one of tickets.
98       * 1. Enter the system with some particular user (admin_test1).
99       * 2. Goto Projects List page.
100      * 3. Click "View" link for some project (test_name).
101      * 4. Click "Edit" link for selected issue (no 1).
102      * 5. Update the description for this issue.
103      * 6. Submit the form.
104      * 7. Check if we got email notification about modifications.
105      * 8. Being at "View Issues" page, right after saving updated issues,
106      * check that no more issues with old description is here, but
107      * new description has appeared.
108      *
109      * @throws java.io.IOException
110      */
111     @Test
112     public void testEditIssue1FromIssueList() throws Exception {
113         log.info("running testEditIssue1FromIssueList");
114         closeSession();
115         selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
116                 + applicationPath);
117 
118         assertTrue(selenium.isElementPresent("//.[@name='login']"));
119         assertTrue(selenium.isElementPresent("//.[@name='password']"));
120         assertTrue(selenium.isElementPresent("//.[@value='Login']"));
121         selenium.type("//.[@name='login']", "admin_test1");
122         selenium.type("//.[@name='password']", "admin_test1");
123         selenium.click("//.[@value='Login']");
124         selenium.waitForPageToLoad(SE_TIMEOUT);
125 
126         selenium.click("listprojects");
127         selenium.waitForPageToLoad(SE_TIMEOUT);
128 
129         // Click view issue link (usually it's named "View").
130         assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'project.')]/td[3][text()='test_name']/../td[1]/a[1]"));
131         selenium.click("//tr[starts-with(@id, 'project.')]/td[3][text()='test_name']/../td[1]/a[1]");
132         selenium.waitForPageToLoad(SE_TIMEOUT);
133 
134         assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description']/../td[1]/a[2]"));
135         selenium.click("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description']/../td[1]/a[2]");
136         selenium.waitForPageToLoad(SE_TIMEOUT);
137 
138         assertTrue(selenium.isElementPresent("description"));
139         assertTrue(selenium.isElementPresent("ownerId"));
140         assertTrue(selenium.isElementPresent("//input[@type='submit']"));
141 
142         selenium.type("description", "test_description (updated)");
143 
144         startSMTP();
145         try {
146             selenium.click("//input[@type='submit']");
147             selenium.waitForPageToLoad(SE_TIMEOUT);
148 
149             assertEquals("smtpServer.receivedEmailSize", 1, smtpServer.getReceivedEmailSize());
150             final Iterator<SmtpMessage> iter =
151                     (Iterator<SmtpMessage>) smtpServer.getReceivedEmail();
152             // Checking email notification for creator.
153             final SmtpMessage smtpMessage = iter.next();
154             final String smtpMessageBody = smtpMessage.getBody();
155             assertTrue(smtpMessageBody.contains("test_description (updated)"));
156 
157         } finally {
158             stopSMTP();
159         }
160 
161 
162         assertTrue(selenium.isElementPresent("issues"));
163         assertEquals(4, selenium.getXpathCount("//tr[starts-with(@id, 'issue.')]"));
164         assertFalse(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description']/../td[13][contains(text(),'A. admin lastname')]"));
165         assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description (updated)']/../td[13][contains(text(),'A. admin lastname')]"));
166     }
167 
168     /**
169      * Move a ticket to another project.
170      * 1. Enter the system with some particular user (admin_test1).
171      * 2. Goto Projects List page.
172      * 3. Click "View" link for some project (test_name).
173      * 4. Click "View" link for selected issue (no 1).
174      * 5. Click "Move" link.
175      * 6. Select a project (test_name2) where we gonna move a ticket.
176      * 7. Since test_name2 was an empty project, and now we have a single
177      * item there, we check that it has appeared at "View Issues"
178      * page for test_name2 project.
179      *
180      * @throws java.io.IOException
181      */
182     @Test
183     public void testMoveIssue1() throws Exception {
184         log.info("running testMoveIssue1");
185         closeSession();
186         selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
187                 + applicationPath);
188 
189         assertTrue(selenium.isElementPresent("//.[@name='login']"));
190         assertTrue(selenium.isElementPresent("//.[@name='password']"));
191         assertTrue(selenium.isElementPresent("//.[@value='Login']"));
192         selenium.type("//.[@name='login']", "admin_test1");
193         selenium.type("//.[@name='password']", "admin_test1");
194         selenium.click("//.[@value='Login']");
195         selenium.waitForPageToLoad(SE_TIMEOUT);
196 
197         selenium.click("listprojects");
198         selenium.waitForPageToLoad(SE_TIMEOUT);
199 
200         // Click view issue link (usually it's named "View").
201         assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'project.')]/td[3][text()='test_name']/../td[1]/a[1]"));
202         selenium.click("//tr[starts-with(@id, 'project.')]/td[3][text()='test_name']/../td[1]/a[1]");
203         selenium.waitForPageToLoad(SE_TIMEOUT);
204 
205         assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description']/../td[1]/a[1]"));
206         selenium.click("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description']/../td[1]/a[1]");
207         selenium.waitForPageToLoad(SE_TIMEOUT);
208 
209         assertTrue(selenium.isElementPresent("//td[@id='actions']/a[3]"));
210         selenium.click("//td[@id='actions']/a[3]");
211         selenium.waitForPageToLoad(SE_TIMEOUT);
212 
213         assertTrue(selenium.isElementPresent("projectId"));
214         selenium.select("projectId", "label=test_name2");
215 
216 
217         startSMTP();
218         try {
219             selenium.click("//input[@type='submit']");
220             selenium.waitForPageToLoad(SE_TIMEOUT);
221 
222             assertEquals("smtpServer.getReceivedEmailSize :?", 0, smtpServer.getReceivedEmailSize()); // ? really no notification
223             //        final Iterator<SmtpMessage> iter =
224             //                (Iterator<SmtpMessage>)smtpServer.getReceivedEmail();
225             //        // Checking email notification for creator.
226             //        final SmtpMessage smtpMessage1 = iter.next();
227             //        final String smtpMessageBody1 = smtpMessage1.getBody();
228             //        assertTrue(smtpMessageBody1.contains("test_description (updated)"));
229 
230 
231             assertTrue(selenium.isElementPresent("//td[@id='actions']/a[1]"));
232             selenium.click("//td[@id='actions']/a[1]");
233             selenium.waitForPageToLoad(SE_TIMEOUT);
234         } finally {
235             stopSMTP();
236         }
237         assertTrue(selenium.isElementPresent("issues"));
238         assertEquals(1, selenium.getXpathCount("//tr[starts-with(@id, 'issue.')]"));
239         assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='1']/../td[11][text()='test_description']/../td[13][contains(text(),'A. admin lastname')]"));
240     }
241 
242     /**
243      * Editing one of tickets (another issues).
244      * 1. Enter the system with some particular user (admin_test1).
245      * 2. Goto Projects List page.
246      * 3. Click "View" link for some project (test_name).
247      * 4. Click "View" link for selected issue (no 2).
248      * 5. Click "Edit" link.
249      * 6. Update the description for this issue.
250      * 7. Submit the form.
251      * 8. Check if we got email notification about modifications.
252      * 9. Being at "View Issues" page, right after saving updated issues,
253      * check that no more issues with old description is here, but
254      * new description has appeared.
255      *
256      * @throws java.io.IOException
257      */
258     @Test
259     public void testEditIssue2FromViewIssue() throws Exception {
260         log.info("running testEditIssue2FromViewIssue");
261         closeSession();
262         selenium.open("http://" + applicationHost + ":" + applicationPort + "/"
263                 + applicationPath);
264 
265         assertTrue(selenium.isElementPresent("//.[@name='login']"));
266         assertTrue(selenium.isElementPresent("//.[@name='password']"));
267         assertTrue(selenium.isElementPresent("//.[@value='Login']"));
268         selenium.type("//.[@name='login']", "admin_test1");
269         selenium.type("//.[@name='password']", "admin_test1");
270         selenium.click("//.[@value='Login']");
271         selenium.waitForPageToLoad(SE_TIMEOUT);
272 
273         selenium.click("listprojects");
274         selenium.waitForPageToLoad(SE_TIMEOUT);
275 
276         // Click view issue link (usually it's named "View").
277         assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'project.')]/td[3][text()='test_name']/../td[1]/a[1]"));
278         selenium.click("//tr[starts-with(@id, 'project.')]/td[3][text()='test_name']/../td[1]/a[1]");
279         selenium.waitForPageToLoad(SE_TIMEOUT);
280 
281         assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='2']/../td[11][text()='test_description 2']/../td[1]/a[1]"));
282         selenium.click("//tr[starts-with(@id, 'issue.')]/td[3][text()='2']/../td[11][text()='test_description 2']/../td[1]/a[1]");
283         selenium.waitForPageToLoad(SE_TIMEOUT);
284 
285         assertEquals("test_description 2", selenium.getText("description"));
286         assertEquals("admin firstname admin lastname", selenium.getText("ownerName"));
287 
288         assertTrue(selenium.isElementPresent("//td[@id='actions']/a[2]"));
289         selenium.click("//td[@id='actions']/a[2]");
290         selenium.waitForPageToLoad(SE_TIMEOUT);
291 
292         assertTrue("no description", selenium.isElementPresent("description"));
293         assertTrue("no owner", selenium.isElementPresent("ownerId"));
294         assertTrue("no submit", selenium.isElementPresent("//input[@type='submit']"));
295 
296         selenium.type("description", "test_description 2 (updated)");
297 
298         startSMTP();
299         try {
300             selenium.click("//input[@type='submit']");
301             selenium.waitForPageToLoad(SE_TIMEOUT);
302             assertEquals("smtpServer.receivedEmailSize", 1, smtpServer.getReceivedEmailSize());
303             final Iterator<SmtpMessage> iter =
304                     (Iterator<SmtpMessage>) smtpServer.getReceivedEmail();
305             // Checking email notification for creator.
306             final SmtpMessage smtpMessage1 = iter.next();
307             final String smtpMessageBody1 = smtpMessage1.getBody();
308             assertTrue("smtpMessageBody1", smtpMessageBody1.contains("test_description 2 (updated)"));
309 
310 
311         } finally {
312             stopSMTP();
313         }
314 
315         assertTrue(selenium.isElementPresent("issues"));
316         assertEquals(4, selenium.getXpathCount("//tr[starts-with(@id, 'issue.')]"));
317         assertFalse(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='2']/../td[11][text()='test_description 2']/../td[13][contains(text(),'A. admin lastname')]"));
318         assertTrue(selenium.isElementPresent("//tr[starts-with(@id, 'issue.')]/td[3][text()='2']/../td[11][text()='test_description 2 (updated)']/../td[13][contains(text(),'A. admin lastname')]"));
319     }
320 
321     @Override
322     protected String[] getDataSetFiles
323             () {
324         return new String[]{
325                 "dataset/languagebean_init_dataset.xml",
326                 "dataset/languagebean_dataset.xml",
327                 "dataset/userpreferencesbean_dataset.xml",
328                 "dataset/userbean_dataset.xml",
329                 "dataset/projectbean_dataset.xml",
330                 "dataset/permissionbean_dataset.xml",
331                 "dataset/versionbean_dataset.xml",
332                 "dataset/issuebean_dataset.xml",
333                 "dataset/issueversionrel_dataset.xml",
334                 "dataset/issueactivitybean_dataset.xml",
335                 "dataset/issuehistorybean_dataset.xml"
336         };
337     }
338 
339     @Override
340     protected String[] getConfigLocations
341             () {
342         return new String[]{"application-context.xml"};
343     }
344 }