View Javadoc
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.itracker.services.ITrackerServices;
8   import org.itracker.web.util.ServletContextUtils;
9   import org.junit.Test;
10  import org.openqa.selenium.By;
11  import org.subethamail.wiser.WiserMessage;
12  
13  /**
14   * Verifies the functionality of new issue creation.
15   *
16   * @author Andrey Sergievskiy <seas@andreysergievskiy.com>
17   */
18  public class CreateIssueSeleniumIT extends AbstractSeleniumTestCase {
19  
20      private static final Logger log = Logger.getLogger(CreateIssueSeleniumIT.class);
21  
22      /**
23       * 1. Login into the system with some particular user
24       * (admin_test1 in our case, which already has 4 issues, 2 of them
25       * are unassigned).
26       * 2. Go to "Project List" page (by clicking "Project List" link).
27       * 3. Click "Create" link for selected project.
28       * 4. Fill issue fields with some data (we remember description
29       * in our case, to check if new issue has appeared).
30       * 5. After submitting new issue, we are at "View Issues" page and
31       * check if new issue has appeared.
32       * 6. Go to "Portal Home" page and check if new issue has appeared
33       * in "Unassigned" area and "Created" area.
34       */
35      @Test
36      public void testCreateUnassignedIssue() throws Exception {
37          log.info(" running testCreateUnassignedIssue");
38          closeSession();
39  
40          final String descriptionValue = "Issue to be unassigned.";
41          final String historyValue = "Issue to be unassigned history.";
42  
43          driver.get(applicationURL);
44  
45          login("admin_test1", "admin_test1");
46  
47          // Click "Projects List".
48          assertElementPresent(By.name("listprojects")).click();
49          waitForPageToLoad();
50  
51          // Click issue creation link (usually it's named "Create").
52          assertElementPresent(By.xpath("//*[starts-with(@id, 'project.')]" +
53                  "/*[3][text()='test_name']/../*[1]/a[2]"))
54          .click();
55          waitForPageToLoad();
56  
57          assertElementPresent(By.name("description"));
58          assertElementPresent(By.name("ownerId"));
59          assertElementPresent(By.name("creatorId"));
60          assertElementPresent(By.name("severity"));
61          assertElementPresent(By.name("versions"));
62  
63          assertElementPresent(By.id("description"))
64                  .findElement(By.tagName("input"))
65                  .sendKeys(descriptionValue);
66          assertElementPresent(By.name("history"))
67                  .sendKeys(historyValue);
68  
69          log.debug(driver.getPageSource());
70  
71          assertElementPresent(By.cssSelector("#ownerId select option[value='-1']"))
72                  .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("#creatorId select option[value='" + userId + "']"))
78          .click();
79  
80          int received = wiser.getMessages().size();
81  
82          assertElementPresent(By.cssSelector("#submit input"))
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          // as defined in jetty-env.xconf
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         // Check that the total number of issues is 5 now (4 from db + 1 our).
103         assertElementPresent(By.id("issues"));
104         assertElementCountEquals(5, By.xpath("//*[starts-with(@id, 'issue.')]"));
105         assertElementPresent(By.xpath("//*[starts-with(@id, 'issue.')]" +
106                 "/*[11][text()='" + descriptionValue + "']"));
107 
108         driver.get(applicationURL + "/portalhome.do");
109 
110         // Check that just created issue has appeared in "Unassigned" area.
111         assertElementPresent(By.xpath("//*[starts-with(@id,'unassignedIssue.')]" +
112                 "/*[5][text()='test_name']/../*[11][text()='" + descriptionValue + "']"));
113 
114         // Check that just created issue has appeared in "Created" area.
115         assertElementPresent(By.xpath("//*[starts-with(@id,'createdIssue.')]" +
116                 "/*[5][text()='test_name']/../*[11][text()='" + descriptionValue + "']"));
117 
118         // Check that number of watched items is 0.
119         assertElementNotPresent(By.xpath("//*[starts-with(@id, 'watchedIssue.')]"));
120     }
121 
122     /**
123      * TODO
124      */
125     @Test
126     public void testCreateAssignedIssue() throws Exception {
127 
128         final String descriptionValue = "Issue to be assigned.";
129         final String historyValue = "Issue to be assigned history.";
130 
131         log.info(" running testCreateAssignedIssue");
132         closeSession();
133 
134         driver.get(applicationURL);
135 
136         login("admin_test1", "admin_test1");
137 
138         // Clicking "Project List" link.
139         assertElementPresent(By.name("listprojects"))
140         .click();
141         waitForPageToLoad();
142 
143         // Click issue creation link (usually it's named "Create").
144         assertElementPresent(By.xpath("//*[starts-with(@id, 'project.')]" +
145                 "/*[3][text()='test_name']/../*[1]/a[2]"))
146         .click();
147         waitForPageToLoad();
148 
149         assertElementPresent(By.name("description"))
150         .sendKeys(descriptionValue);
151         assertElementPresent(By.name("ownerId"));
152         assertElementPresent(By.name("creatorId"));
153         assertElementPresent(By.name("severity"));
154         assertElementPresent(By.name("versions"));
155         assertElementPresent(By.name("history"))
156         .sendKeys(historyValue);
157 
158         final UserDAO userDao = (UserDAO) applicationContext.getBean("userDAO");
159         final User user = userDao.findByLogin("admin_test1");
160         assertTrue("user #admin_test1", null != user);
161         final long userId = user.getId();
162         assertElementPresent(By.cssSelector("#ownerId select option[value='" + userId + "']"))
163         .click();
164         assertElementPresent(By.cssSelector("#creatorId select option[value='" + userId + "']"))
165         .click();
166 
167         int received = wiser.getMessages().size();
168         assertElementPresent(By.cssSelector("#submit input"))
169         .click();
170         waitForPageToLoad();
171 
172         assertEquals("wiser.receivedEmailSize", received + 2, wiser.getMessages().size());
173         final WiserMessage smtpMessage1 = wiser.getMessages().get(received);
174         final WiserMessage smtpMessage2 = wiser.getMessages().get(received + 1);
175 
176         final String smtpMessageBody1 = (String) smtpMessage1.getMimeMessage().getContent();
177         final String smtpMessageBody2 = (String) smtpMessage2.getMimeMessage().getContent();
178 
179         // Checking email notification for creator.
180         log.debug("testCreateAssignedIssue, received:\n " + smtpMessageBody1);
181         assertTrue(smtpMessageBody1.contains(descriptionValue));
182         assertTrue(smtpMessageBody1.contains(historyValue));
183 
184         // Checking email notification for owner.
185         log.debug("testCreateAssignedIssue, received2:\n " + smtpMessageBody2);
186         assertTrue(smtpMessageBody2.contains(descriptionValue));
187         assertTrue(smtpMessageBody2.contains(historyValue));
188 //
189         // Checking that our new issue has appeared in "View Issues".
190         assertElementPresent(By.id("issues"));
191         assertElementCountEquals(5, By.xpath("//*[starts-with(@id, 'issue.')]"));
192         assertElementPresent(By.xpath("//*[starts-with(@id, 'issue.')]/*[11][text()='" + descriptionValue + "']"));
193 
194         driver.get(applicationURL + "/portalhome.do");
195 
196         // Checking that our new issue has not appeared in "Unassigned" area.
197         assertElementNotPresent(By.xpath("//*[starts-with(@id,'unassignedIssue.')]" +
198                         "/*[5][text()='test_name']/../*[11][text()='" + descriptionValue + "']"));
199         // Checking that our new issue has appeared in "Created" area.
200         assertElementPresent(By.xpath("//*[starts-with(@id,'createdIssue.')]" +
201                 "/*[5][text()='test_name']/../*[11][text()='" + descriptionValue + "']"));
202 
203         // Check that "Watched" area is still empty.
204         assertElementNotPresent(By.xpath("//*[starts-with(@id, 'watchedIssue.')]"));
205     }
206 
207     @Override
208     protected String[] getDataSetFiles() {
209         return new String[]{
210                 "dataset/languagebean_init_dataset.xml",
211                 "dataset/languagebean_dataset.xml",
212                 "dataset/userpreferencesbean_dataset.xml",
213                 "dataset/userbean_dataset.xml",
214                 "dataset/projectbean_dataset.xml",
215                 "dataset/permissionbean_dataset.xml",
216                 "dataset/versionbean_dataset.xml",
217                 "dataset/issuebean_dataset.xml",
218                 "dataset/issueversionrel_dataset.xml",
219                 "dataset/issueactivitybean_dataset.xml",
220                 "dataset/issuehistorybean_dataset.xml"
221         };
222     }
223 
224 
225 }