Author: tchemit Date: 2012-06-12 23:28:29 +0200 (Tue, 12 Jun 2012) New Revision: 3458 Url: http://chorem.org/repositories/revision/pollen/3458 Log: refs #606: Add some ITs to prevent regression - improve its (we should hide the driver from tests - improve jetty configuration Added: trunk/pollen-ui-struts2/src/jetty/ trunk/pollen-ui-struts2/src/jetty/jetty-context.xml trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java Removed: trunk/pollen-ui-struts2-test/ Modified: trunk/pollen-ui-struts2/pom.xml trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java trunk/pollen-ui-struts2/src/test/resources/pollendb.h2.db Modified: trunk/pollen-ui-struts2/pom.xml =================================================================== --- trunk/pollen-ui-struts2/pom.xml 2012-06-12 16:46:42 UTC (rev 3457) +++ trunk/pollen-ui-struts2/pom.xml 2012-06-12 21:28:29 UTC (rev 3458) @@ -295,6 +295,7 @@ <configuration> <stopKey>A</stopKey> <stopPort>1269</stopPort> + <contextXml>${basedir}/src/jetty/jetty-context.xml</contextXml> <webAppConfig> <contextPath>/pollen</contextPath> </webAppConfig> @@ -393,6 +394,7 @@ target/pollen-embedded-temp-${project.version}/WEB-INF/webfrag.xml </webXmlFragment> <packageRoot>org.apache.jsp</packageRoot> + </configuration> </execution> </executions> @@ -474,29 +476,6 @@ </executions> </plugin> - <plugin> - - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>1.7</version> - <executions> - <execution> - <goals> - <goal>attach-artifact</goal> - </goals> - <configuration> - <artifacts> - <artifact> - <file>target/pollen-${project.version}-embedded.war</file> - <type>war</type> - <classifier>embedded</classifier> - </artifact> - </artifacts> - </configuration> - </execution> - </executions> - </plugin> - <!-- Build embedded zip --> <plugin> @@ -563,9 +542,8 @@ <activation> <property> <name>maven.test.skip</name> - <value>!false</value> + <value>!true</value> </property> - </activation> <build> <defaultGoal>post-integration-test</defaultGoal> @@ -573,37 +551,21 @@ <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> - <configuration> - <stopKey>A</stopKey> - <stopPort>1269</stopPort> - </configuration> <executions> <execution> <id>start-pollen</id> <phase>pre-integration-test</phase> <goals> - <goal>run</goal> + <goal>start</goal> </goals> <configuration> <daemon>true</daemon> - <stopKey>A</stopKey> - <stopPort>1269</stopPort> <webAppConfig> <descriptor>src/test/resources/web-test.xml</descriptor> <contextPath>/pollen</contextPath> </webAppConfig> <useTestClasspath>true</useTestClasspath> - <systemProperties> - <systemProperty> - <name>siteUrl</name> - <value>http://localhost:8080/pollen</value> - </systemProperty> - <systemProperty> - <name>pollen.log.dir</name> - <value>target</value> - </systemProperty> - </systemProperties> </configuration> </execution> @@ -619,10 +581,6 @@ <plugin> <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <!-- Skip the normal tests, we'll run them in the integration-test phase --> - <skip>true</skip> - </configuration> <executions> <execution> @@ -631,7 +589,6 @@ <goal>test</goal> </goals> <configuration> - <skip>false</skip> <includes> <include>**/*SIT.java</include> </includes> Added: trunk/pollen-ui-struts2/src/jetty/jetty-context.xml =================================================================== --- trunk/pollen-ui-struts2/src/jetty/jetty-context.xml (rev 0) +++ trunk/pollen-ui-struts2/src/jetty/jetty-context.xml 2012-06-12 21:28:29 UTC (rev 3458) @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> + +<Configure class="org.eclipse.jetty.webapp.WebAppContext"> + <Call name="setAttribute"> + <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg> + <Arg>.*/.*jsp-api-[^/]\.jar$|./.*jsp-[^/]\.jar$|./.*taglibs[^/]*\.jar$</Arg> + </Call> +</Configure> \ No newline at end of file Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java 2012-06-12 16:46:42 UTC (rev 3457) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java 2012-06-12 21:28:29 UTC (rev 3458) @@ -25,12 +25,18 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; import org.junit.Rule; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; import java.util.Collection; +import java.util.List; /** * Test base class for ui tests. @@ -52,12 +58,83 @@ @Rule public WebDriverResource seleniumServer; + protected PollenFixtures fixtures ; + + protected WebDriver driver; + + @Before + public void setUp() throws Exception { + driver = seleniumServer.getDriver(); + fixtures = seleniumServer.getFixtures(); + } + + @AfterClass + public static void afterClass() { + WebDriverResource.afterClass(); + + } + protected PollenBaseWebDriverIT(Class<? extends WebDriver> driverType) { - seleniumServer = new WebDriverResource(getClass(), driverType); + seleniumServer = new WebDriverResource(driverType); } - public WebDriver getDriver() { - return seleniumServer.getDriver(); + protected void gotoUrl(String url, boolean strict) { + gotoUrl(url, null, strict); } + protected void gotoUrl(String url) { + gotoUrl(url, null, true); + } + + protected void gotoUrl(String url, String fallBackUrl) { + gotoUrl(url, fallBackUrl, true); + } + + protected void gotoUrl(String url, String fallBackUrl, boolean strict) { + driver.get(url); + String expectedUrl; + if (fallBackUrl == null) { + expectedUrl = url; + } else { + expectedUrl = fallBackUrl; + } + + if (strict) { + Assert.assertEquals(expectedUrl, driver.getCurrentUrl()); + } else { + Assert.assertTrue(driver.getCurrentUrl().startsWith(expectedUrl)); + } + } + + protected WebElement findElement(By by) { + WebElement element = driver.findElement(by); + return element; + } + + protected List<WebElement> findElements(By by) { + List<WebElement> result = driver.findElements(by); + return result; + } + + /** Try to log in using the given {@code username} and {@code password}. */ + protected void connect(String username, String password) { + + // click on tologin element (display the login form) + WebElement loginClick = driver.findElement(By.id("tologin")); + loginClick.click(); + + // Find the text input element by its name + WebElement loginElement = driver.findElement(By.name("login")); + Assert.assertEquals("input", loginElement.getTagName()); + Assert.assertTrue(loginElement.isDisplayed()); + loginElement.sendKeys(username); + + WebElement passwordElement = driver.findElement(By.name("password")); + Assert.assertTrue(passwordElement.isDisplayed()); + Assert.assertEquals("input", passwordElement.getTagName()); + passwordElement.sendKeys(password); + + WebElement submit = driver.findElement(By.name("action:login")); + submit.click(); + } } Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenFixtures.java 2012-06-12 21:28:29 UTC (rev 3458) @@ -0,0 +1,86 @@ +package org.chorem.pollen.ui; + +import org.chorem.pollen.bean.PollUri; + +/** + * Some fixtures for tests. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class PollenFixtures { + + public static final String PREFIX_URL = "http://localhost:8080/pollen/"; + + public String normalPollId() { + return "c7082f9752844b83a1859abcae3b681c"; + } + + public String normalPollCreatorId() { + return "b9b434acd58d42fca083d473ee021fce"; + } + + public String homeURL() { + return PREFIX_URL + "home"; + } + + public String createdListURL() { + return PREFIX_URL + "user/createdList"; + } + + public String invitedListURL() { + return PREFIX_URL + "user/invitedList"; + } + + public String participatedListURL() { + return PREFIX_URL + "user/participatedList"; + } + + public String favoriteListsURL() { + return PREFIX_URL + "user/favoriteLists"; + } + + public String pollsListURL() { + return PREFIX_URL + "admin/pollsList"; + } + + public String usersListURL() { + return PREFIX_URL + "admin/usersList"; + } + + public String connected_requiredURL() { + return PREFIX_URL + "security/connected_required"; + } + + public String admin_requiredURL() { + return PREFIX_URL + "security/admin_required"; + } + + public String voteforURL() { + return PREFIX_URL + "poll/votefor/"; + } + + public String voteforURL(PollUri pollUri) { + return voteforURL() + pollUri.toString(); + } + + public String modificationURL(PollUri pollUri) { + return modificationURL() + pollUri.toString(); + } + + public String modificationURL() { + return PREFIX_URL + "poll/modification/"; + } + + public String poll_requiredURL() { + return PREFIX_URL + "security/poll_required"; + } + + public String poll_access_requiredURL() { + return PREFIX_URL + "security/poll_access_required"; + } + + public String poll_creator_requiredURL() { + return PREFIX_URL + "security/poll_creator_required"; + } +} Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java 2012-06-12 16:46:42 UTC (rev 3457) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java 2012-06-12 21:28:29 UTC (rev 3458) @@ -23,9 +23,11 @@ */ package org.chorem.pollen.ui; +import com.google.common.collect.Lists; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.rules.ExternalResource; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeDriverService; @@ -46,27 +48,25 @@ * @author tchemit <chemit@codelutin.com> * @since 1.4 */ -public class WebDriverResource extends ExternalResource { +public class WebDriverResource extends TestWatcher { /** Logger. */ private static final Log log = LogFactory.getLog(WebDriverResource.class); private static ChromeDriverService service; - protected static final Class<? extends WebDriver>[] allDrivers = new Class[]{ -// ChromeDriver.class, -// InternetExplorerDriver.class, -// SafariDriver.class, - FirefoxDriver.class, - HtmlUnitDriver.class - }; - protected static Collection<Object[]> safeDrivers; public static Collection<Object[]> driverTypes() { if (safeDrivers == null) { - //System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome"); + List<Class<? extends WebDriver>> allDrivers = Lists.newArrayList(); + allDrivers.add(HtmlUnitDriver.class); + allDrivers.add(FirefoxDriver.class); +// allDrivers.add(ChromeDriver.class); +// allDrivers.add(InternetExplorerDriver.class); +// allDrivers.add(SafariDriver.class); + List<Class<?>> checkedDrivers = new ArrayList<Class<?>>(); for (Class<? extends WebDriver> driver : allDrivers) { boolean ok = checkDriver(driver); @@ -74,7 +74,6 @@ checkedDrivers.add(driver); } } - //{{ChromeDriver.class}, {FirefoxDriver.class}, {HtmlUnitDriver.class}} Object[][] data = new Object[checkedDrivers.size()][1]; int i = 0; for (Class<?> checkedDriver : checkedDrivers) { @@ -88,10 +87,9 @@ private static boolean checkDriver(Class<? extends WebDriver> driverType) { - WebDriver driver = null; boolean result = false; try { - driver = driverType.getConstructor().newInstance(); + createDriver(driverType, true); result = true; } catch (Exception e) { @@ -99,36 +97,63 @@ if (log.isInfoEnabled()) { log.info("Can not use driver " + driverType.getName(), e); } - } finally { - if (driver != null) { - driver.quit(); - } } return result; } - private final Class<?> testClass; - private final Class<? extends WebDriver> driverType; + private final PollenFixtures fixtures; + protected WebDriver driver; - public WebDriverResource(Class<?> testClass, - Class<? extends WebDriver> driverType) { - this.testClass = testClass; + public WebDriverResource(Class<? extends WebDriver> driverType) { this.driverType = driverType; + fixtures = new PollenFixtures(); } public WebDriver getDriver() { return driver; } + public PollenFixtures getFixtures() { + return fixtures; + } + @Override - protected void before() throws Throwable { + protected void starting(Description description) { + String testName = description.getClassName() + "#" + description.getMethodName() + " on [" + driverType.getName() + "]"; + if (log.isInfoEnabled()) { - log.info("Start test [" + testClass.getName() + "] with driver of type " + driverType.getName()); + log.info("Start test " + testName); } + + try { + driver = createDriver(driverType, false); + + } catch (Exception e) { + throw new IllegalStateException("Could not begin test " + testName); + } + } + + @Override + protected void finished(Description description) { + + // close current driver + driver.quit(); + } + + public static void afterClass() { + + if (service != null) { + service.stop(); + } + } + + protected static WebDriver createDriver(Class<? extends WebDriver> driverType, boolean clear) throws Exception { + WebDriver result; + if (ChromeDriver.class == driverType) { service = new ChromeDriverService.Builder() @@ -137,18 +162,23 @@ .build(); service.start(); - driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); + result = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); } else { - driver = driverType.getConstructor().newInstance(); + result = driverType.getConstructor().newInstance(); } - } - @Override - protected void after() { - if (ChromeDriver.class == driverType) { - service.stop(); + if (clear) { + + if (result != null) { + result.close(); + } + + if (service != null) { + service.stop(); + } + } - driver.quit(); + return result; } } Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java 2012-06-12 16:46:42 UTC (rev 3457) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java 2012-06-12 21:28:29 UTC (rev 3458) @@ -23,8 +23,8 @@ */ package org.chorem.pollen.ui.security; -import junit.framework.Assert; import org.chorem.pollen.ui.PollenBaseWebDriverIT; +import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; @@ -47,107 +47,40 @@ @Test public void loginAdmin() throws Exception { - WebDriver driver = getDriver(); + gotoUrl(fixtures.homeURL()); - driver.get("http://localhost:8080/pollen/home"); + connect("admin", "admin"); - if (log.isInfoEnabled()) { - log.info("Login url : " + driver.getCurrentUrl()); - } - - // click on tologin element (display the login form) - WebElement loginClick = driver.findElement(By.id("tologin")); - loginClick.click(); - - // Find the text input element by its name - WebElement login = driver.findElement(By.name("login")); - Assert.assertEquals("input", login.getTagName()); - Assert.assertTrue(login.isDisplayed()); - login.sendKeys("admin"); - - WebElement password = driver.findElement(By.name("password")); - Assert.assertTrue(password.isDisplayed()); - Assert.assertEquals("input", password.getTagName()); - password.sendKeys("admin"); - - WebElement submit = driver.findElement(By.name("action:login")); - Assert.assertNotNull(submit); - submit.click(); - // check info_success is on - driver.findElement(By.className("info_success")); + findElement(By.className("info_success")); // check there is a admin menu (so 4 menus) - List<WebElement> menus = driver.findElements(By.className("menu_elt")); + List<WebElement> menus = findElements(By.className("menu_elt")); Assert.assertEquals(4, menus.size()); } @Test public void loginUser() throws Exception { - WebDriver driver = getDriver(); + gotoUrl(fixtures.homeURL()); - driver.get("http://localhost:8080/pollen/home"); + connect("user", "user"); - if (log.isInfoEnabled()) { - log.info("Login url : " + driver.getCurrentUrl()); - } - - // click on tologin element (display the login form) - WebElement loginClick = driver.findElement(By.id("tologin")); - Assert.assertNotNull(loginClick); - loginClick.click(); - - // Find the text input element by its name - WebElement login = driver.findElement(By.name("login")); - Assert.assertEquals("input", login.getTagName()); - Assert.assertTrue(login.isDisplayed()); - login.sendKeys("user"); - - WebElement password = driver.findElement(By.name("password")); - Assert.assertTrue(password.isDisplayed()); - Assert.assertEquals("input", password.getTagName()); - password.sendKeys("user"); - - WebElement submit = driver.findElement(By.name("action:login")); - submit.click(); - // check info_success is on - driver.findElement(By.className("info_success")); + findElement(By.className("info_success")); - // check there is not a admin menu (so 2 menus) - List<WebElement> menus = driver.findElements(By.className("menu_elt")); + // check there is not a admin menu (so 3 menus) + List<WebElement> menus = findElements(By.className("menu_elt")); Assert.assertEquals(3, menus.size()); } @Test public void badLogin() throws Exception { - WebDriver driver = getDriver(); + gotoUrl(fixtures.homeURL()); - driver.get("http://localhost:8080/pollen/home"); + connect("admin", "admin" + System.currentTimeMillis()); - if (log.isInfoEnabled()) { - log.info("Login url : " + driver.getCurrentUrl()); - } - - // click on tologin element (display the login form) - WebElement loginClick = driver.findElement(By.id("tologin")); - Assert.assertNotNull(loginClick); - loginClick.click(); - - // Find the text input element by its name - WebElement login = driver.findElement(By.name("login")); - Assert.assertTrue(login.isDisplayed()); - login.sendKeys("admin"); - - WebElement password = driver.findElement(By.name("password")); - Assert.assertTrue(password.isDisplayed()); - password.sendKeys("admin" + System.currentTimeMillis()); - - WebElement submit = driver.findElement(By.name("action:login")); - submit.click(); - - driver.findElement(By.className("info_error")); + findElement(By.className("info_error")); } } Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java 2012-06-12 16:46:42 UTC (rev 3457) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java 2012-06-12 21:28:29 UTC (rev 3458) @@ -1,15 +1,13 @@ package org.chorem.pollen.ui.security; +import org.chorem.pollen.bean.PollUri; import org.chorem.pollen.ui.PollenBaseWebDriverIT; -import org.junit.Assert; import org.junit.Test; -import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; /** * Test the security on some restricted pages : - * + * <p/> * <ul> * <li>Access to "connected pages" when connected (OK)</li> * <li>Access to "connected pages" when not connected (KO)</li> @@ -17,7 +15,7 @@ * <li>Access to "admin pages" when not connected as admin (KO)</li> * <li>Access to "admin pages" when connected as admin (OK)</li> * </ul> - * + * <p/> * TODO ymartel 2012/06/12 * Should check those security access to : * <ul> @@ -35,22 +33,6 @@ super(driverType); } - protected final String CREATEDLIST_URL = "http://localhost:8080/pollen/user/createdList"; - protected final String INVITEDLIST_URL = "http://localhost:8080/pollen/user/invitedList"; - protected final String PARTICIPATEDLIST_URL = "http://localhost:8080/pollen/user/participatedList"; - protected final String FAVORITELIST_URL = "http://localhost:8080/pollen/user/favoriteLists"; - protected final String ADMIN_POLLSLIST_URL = "http://localhost:8080/pollen/admin/pollsList"; - protected final String ADMIN_USERSLIST_URL = "http://localhost:8080/pollen/admin/usersList"; - protected final String CONNECTEDREQUIRED_URL = "http://localhost:8080/pollen/security/connected_required"; - protected final String ADMINREQUIRED_URL = "http://localhost:8080/pollen/security/admin_required"; - protected final String POLL_BASE_URL = "http://localhost:8080/pollen/poll/votefor/"; - protected final String POLL_MODIFICATION_BASE_URL = "http://localhost:8080/pollen/poll/modification/"; - protected final String NORMALPOLL_ID = "c7082f9752844b83a1859abcae3b681c"; - protected final String NORMALPOLL_ADMINTOKEN = "b9b434acd58d42fca083d473ee021fce"; - protected final String POLLREQUIRED_URL = "http://localhost:8080/pollen/security/poll_required"; - protected final String POLLACCESSREQUIRED_URL = "http://localhost:8080/pollen/security/poll_access_required"; - protected final String POLLCREATORREQUIRED_URL = "http://localhost:8080/pollen/security/poll_creator_required"; - /** * This test : * <ol> @@ -60,7 +42,7 @@ * <li>Try to access to participatedList page</li> * <li>Try to access to favoriteLists page</li> * </ol> - * + * <p/> * All the page should be accessed. * * @throws Exception @@ -68,30 +50,23 @@ @Test public void accessConnectedPageAsUser() throws Exception { - WebDriver driver = getDriver(); + // Go on home page + gotoUrl(fixtures.homeURL()); - if (log.isInfoEnabled()) { - log.info("Login url : " + driver.getCurrentUrl()); - } // login as user - connect(driver, "user", "user"); + connect("user", "user"); // try to access to createdList page, current url should be good one - driver.get(CREATEDLIST_URL); - Assert.assertEquals(CREATEDLIST_URL, driver.getCurrentUrl()); + gotoUrl(fixtures.createdListURL()); // try to access to participatedList page, current url should be good one - driver.get(PARTICIPATEDLIST_URL); - Assert.assertEquals(PARTICIPATEDLIST_URL, driver.getCurrentUrl()); + gotoUrl(fixtures.participatedListURL()); // try to access to invitedList page, current url should be good one - driver.get(INVITEDLIST_URL); - Assert.assertEquals(INVITEDLIST_URL, driver.getCurrentUrl()); + gotoUrl(fixtures.invitedListURL()); // try to access to favoriteLists page, current url should be good one - driver.get(FAVORITELIST_URL); - Assert.assertEquals(FAVORITELIST_URL, driver.getCurrentUrl()); - + gotoUrl(fixtures.favoriteListsURL()); } /** @@ -103,7 +78,7 @@ * <li>Try to access to participatedList page</li> * <li>Try to access to favoriteLists page</li> * </ol> - * + * <p/> * All the page should be redirected to connected_required page. * * @throws Exception @@ -111,24 +86,17 @@ @Test public void accessConnectedPageAsAnonymous() throws Exception { - WebDriver driver = getDriver(); - // try to access to createdList page, current url should be the connected_required one - driver.get(CREATEDLIST_URL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(CONNECTEDREQUIRED_URL)); + gotoUrl(fixtures.createdListURL(), fixtures.connected_requiredURL(), false); // try to access to participatedList page, current url should be the connected_required one - driver.get(PARTICIPATEDLIST_URL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(CONNECTEDREQUIRED_URL)); + gotoUrl(fixtures.participatedListURL(), fixtures.connected_requiredURL(), false); // try to access to invitedList page, current url should be the connected_required one - driver.get(INVITEDLIST_URL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(CONNECTEDREQUIRED_URL)); + gotoUrl(fixtures.invitedListURL(), fixtures.connected_requiredURL(), false); // try to access to favoriteLists page, current url should be the connected_required one - driver.get(FAVORITELIST_URL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(CONNECTEDREQUIRED_URL)); - + gotoUrl(fixtures.favoriteListsURL(), fixtures.connected_requiredURL(), false); } /** @@ -138,7 +106,7 @@ * <li>Try to access to admin polls list page</li> * <li>Try to access to admin users list page</li> * </ol> - * + * <p/> * All the page should be redirected to connected_required page. * * @throws Exception @@ -146,16 +114,11 @@ @Test public void accessAdminPageAsAnonymous() throws Exception { - WebDriver driver = getDriver(); - // try to access to admin polls list page, current url should be the connected_required one - driver.get(ADMIN_POLLSLIST_URL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(CONNECTEDREQUIRED_URL)); + gotoUrl(fixtures.pollsListURL(), fixtures.connected_requiredURL(), false); // try to access to admin users list page, current url should be the connected_required one - driver.get(ADMIN_USERSLIST_URL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(CONNECTEDREQUIRED_URL)); - + gotoUrl(fixtures.usersListURL(), fixtures.connected_requiredURL(), false); } /** @@ -165,7 +128,7 @@ * <li>Try to access to admin polls list page</li> * <li>Try to access to admin users list page</li> * </ol> - * + * <p/> * All the page should be redirected to admin_required page. * * @throws Exception @@ -173,19 +136,17 @@ @Test public void accessAdminPageAsUser() throws Exception { - WebDriver driver = getDriver(); + // Go on home page + gotoUrl(fixtures.homeURL()); // login as user - connect(driver, "user", "user"); + connect("user", "user"); // try to access to admin polls list page, current url should be the admin_required one - driver.get(ADMIN_POLLSLIST_URL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(ADMINREQUIRED_URL)); + gotoUrl(fixtures.pollsListURL(), fixtures.admin_requiredURL(), false); // try to access to admin users list page, current url should be the admin_required one - driver.get(ADMIN_USERSLIST_URL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(ADMINREQUIRED_URL)); - + gotoUrl(fixtures.usersListURL(), fixtures.admin_requiredURL(), false); } /** @@ -195,7 +156,7 @@ * <li>Try to access to admin polls list page</li> * <li>Try to access to admin users list page</li> * </ol> - * + * <p/> * All the page should be accessed. * * @throws Exception @@ -203,19 +164,17 @@ @Test public void accessAdminPageAsAdmin() throws Exception { - WebDriver driver = getDriver(); + // Go on home page + gotoUrl(fixtures.homeURL()); // login as user - connect(driver, "admin", "admin"); + connect("admin", "admin"); // try to access to admin polls list page, current url should be good one - driver.get(ADMIN_POLLSLIST_URL); - Assert.assertEquals(ADMIN_POLLSLIST_URL, driver.getCurrentUrl()); + gotoUrl(fixtures.pollsListURL()); // try to access to admin users list page, current url should be good one - driver.get(ADMIN_USERSLIST_URL); - Assert.assertEquals(ADMIN_USERSLIST_URL, driver.getCurrentUrl()); - + gotoUrl(fixtures.usersListURL()); } /** @@ -228,7 +187,7 @@ * <li>Try to access to admin page for normal poll with good pollId & good tokenId</li> * <li>Try to access to admin page for normal poll with good pollId & bad tokenId (should be redirected)</li> * </ol> - * + * <p/> * All the page should be accessed. * * @throws Exception @@ -236,68 +195,31 @@ @Test public void accessNormalPoolActionsAsAnonymous() throws Exception { - WebDriver driver = getDriver(); + String pollId = fixtures.normalPollId(); + String badPollId = pollId + System.nanoTime(); + String creatorId = fixtures.normalPollCreatorId(); + String badCreatorId = creatorId + System.nanoTime(); // try to access to poll page, current url should be good one - String normalPollURL = POLL_BASE_URL + NORMALPOLL_ID; - driver.get(normalPollURL); - Assert.assertEquals(normalPollURL, driver.getCurrentUrl()); + String normalPollURL = fixtures.voteforURL(PollUri.newPollUri(pollId)); + gotoUrl(normalPollURL); // try to access to poll page with bad pollId, current url should be the poll_required one - String badPollURL = POLL_BASE_URL + NORMALPOLL_ID.substring(0, 5); - driver.get(badPollURL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(POLLREQUIRED_URL)); + gotoUrl(fixtures.voteforURL(PollUri.newPollUri(badPollId)), fixtures.poll_requiredURL(), false); // try to access to poll moderation page, current url should be good one - String moderationURL = normalPollURL + ":" + NORMALPOLL_ADMINTOKEN; - driver.get(moderationURL); - Assert.assertEquals(moderationURL, driver.getCurrentUrl()); + String moderationURL = fixtures.voteforURL(PollUri.newPollUri(pollId, creatorId)); + gotoUrl(moderationURL); // try to access to poll page with bad pollId, current url should be the poll_required one - String badModerationURL = normalPollURL + ":" + NORMALPOLL_ADMINTOKEN.substring(0, 5); - driver.get(badModerationURL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(POLLACCESSREQUIRED_URL)); + gotoUrl(fixtures.voteforURL(PollUri.newPollUri(pollId, badCreatorId)), fixtures.poll_access_requiredURL(), false); // try to access to poll moderation page, current url should be good one - String normalPollAdminURL = POLL_MODIFICATION_BASE_URL + NORMALPOLL_ID + ":" + NORMALPOLL_ADMINTOKEN; - driver.get(normalPollAdminURL); - Assert.assertEquals(normalPollAdminURL, driver.getCurrentUrl()); + String normalPollAdminURL = fixtures.modificationURL(PollUri.newPollUri(pollId, creatorId)); + gotoUrl(normalPollAdminURL); // try to access to poll page with bad pollId, current url should be the poll_required one - String badNormalPollAdminURL = POLL_MODIFICATION_BASE_URL + NORMALPOLL_ID + ":" + NORMALPOLL_ADMINTOKEN.substring(0, 2); - driver.get(badNormalPollAdminURL); - Assert.assertTrue(driver.getCurrentUrl().startsWith(POLLCREATORREQUIRED_URL)); - + gotoUrl(fixtures.modificationURL(PollUri.newPollUri(pollId, badCreatorId)), fixtures.poll_creator_requiredURL(), false); } - /** - * Connect as the user named "user" - * - * @param driver : the {@link WebDriver} of the current test - */ - protected void connect(WebDriver driver, String username, String pwd) { - - // Go on home page - driver.get("http://localhost:8080/pollen/home"); - - // click on tologin element (display the login form) - WebElement loginClick = driver.findElement(By.id("tologin")); - Assert.assertNotNull(loginClick); - loginClick.click(); - - // Find the text input element by its name - WebElement login = driver.findElement(By.name("login")); - Assert.assertEquals("input", login.getTagName()); - Assert.assertTrue(login.isDisplayed()); - login.sendKeys(username); - - WebElement password = driver.findElement(By.name("password")); - Assert.assertTrue(password.isDisplayed()); - Assert.assertEquals("input", password.getTagName()); - password.sendKeys(pwd); - - WebElement submit = driver.findElement(By.name("action:login")); - submit.click(); - } - } Modified: trunk/pollen-ui-struts2/src/test/resources/pollendb.h2.db =================================================================== (Binary files differ)