r3456 - in trunk: . pollen-ui-struts2 pollen-ui-struts2/src/main/java/org/chorem/pollen/ui pollen-ui-struts2/src/test/java/org/chorem/pollen/ui pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security pollen-ui-struts2/src/test/resources pollen-ui-struts2-test pollen-ui-struts2-test/src/main/resources pollen-ui-struts2-test/src/main/webapp/WEB-INF pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security pollen-ui-strut
Author: tchemit Date: 2012-06-12 18:45:52 +0200 (Tue, 12 Jun 2012) New Revision: 3456 Url: http://chorem.org/repositories/revision/pollen/3456 Log: refs #606: Add some ITs to prevent regression (finally use same module with jetty (tomcat plugin must be improved :()) Added: trunk/pollen-ui-struts2-test/src/test/resources/web-test.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/PollenTestApplicationListener.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/ 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/log4j.properties trunk/pollen-ui-struts2/src/test/resources/pollen-test.properties trunk/pollen-ui-struts2/src/test/resources/pollendb.h2.db trunk/pollen-ui-struts2/src/test/resources/web-test.xml Removed: trunk/pollen-ui-struts2-test/src/main/resources/log4j.properties trunk/pollen-ui-struts2-test/src/main/resources/pollen-test.properties trunk/pollen-ui-struts2-test/src/main/webapp/WEB-INF/web.xml trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/WebDriverResource.java trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java trunk/pollen-ui-struts2-test/src/test/resources/pollendb.h2.db trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTestApplicationListener.java Modified: trunk/pollen-ui-struts2-test/pom.xml trunk/pollen-ui-struts2/pom.xml trunk/pom.xml Modified: trunk/pollen-ui-struts2/pom.xml =================================================================== --- trunk/pollen-ui-struts2/pom.xml 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pollen-ui-struts2/pom.xml 2012-06-12 16:45:52 UTC (rev 3456) @@ -186,6 +186,39 @@ <artifactId>junit</artifactId> </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-java</artifactId> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-api</artifactId> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-support</artifactId> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-chrome-driver</artifactId> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-firefox-driver</artifactId> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-htmlunit-driver</artifactId> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-ie-driver</artifactId> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-safari-driver</artifactId> + </dependency> + </dependencies> <!-- ************************************************************* --> @@ -398,7 +431,7 @@ <goal>war</goal> </goals> <configuration> - <primaryArtifact>true</primaryArtifact> + <primaryArtifact>false</primaryArtifact> <webappDirectory> target/pollen-embedded-${project.version} </webappDirectory> @@ -441,6 +474,29 @@ </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> @@ -502,6 +558,92 @@ </profile> + <profile> + <id>selenium</id> + <activation> + <property> + <name>maven.test.skip</name> + <value>!false</value> + </property> + + </activation> + <build> + <defaultGoal>post-integration-test</defaultGoal> + <plugins> + <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> + </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> + + <execution> + <id>stop-pollen</id> + <phase>post-integration-test</phase> + <goals> + <goal>stop</goal> + </goals> + </execution> + </executions> + </plugin> + + <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> + <phase>integration-test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <skip>false</skip> + <includes> + <include>**/*SIT.java</include> + </includes> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + </build> + </profile> + </profiles> </project> Deleted: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTestApplicationListener.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTestApplicationListener.java 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTestApplicationListener.java 2012-06-12 16:45:52 UTC (rev 3456) @@ -1,94 +0,0 @@ -/* - * #%L - * Pollen :: UI (struts2) - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package org.chorem.pollen.ui; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.pollen.PollenConfiguration; -import org.chorem.pollen.PollenConfigurationOption; - -import java.io.File; -import java.io.IOException; -import java.util.Properties; - -/** - * Pollen application listener used for test purposes. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class PollenTestApplicationListener extends PollenApplicationListener { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(PollenTestApplicationListener.class); - - @Override - protected PollenConfiguration prepareConfiguration() { - PollenConfiguration configuration; - - configuration = new PollenConfiguration("pollen-test.properties", - null) { - - @Override - protected void loadApplicationConfig(String file, - Properties defaultOptions) { - super.loadApplicationConfig(file, defaultOptions); - - // let's add a suffix (to isolate this data dir) - File dataDirectory = new File(getDataDirectory(), - String.valueOf(System.nanoTime())); - if (log.isInfoEnabled()) { - log.info("Data directory = " + dataDirectory); - } - setOption(PollenConfigurationOption.DATA_DIR.getKey(), - dataDirectory.getAbsolutePath()); - - - File incomingDatabase = getOptionAsFile("incomingDatabase"); - - if (log.isInfoEnabled()) { - log.info("Incoming db = " + incomingDatabase); - } - // copy db to correct path - File dbDirectory = new File(dataDirectory, "db"); - - try { - if (log.isInfoEnabled()) { - log.info("Copy incoming db [" + incomingDatabase + - "] to [" + dbDirectory + "]"); - } - FileUtils.copyFileToDirectory( - incomingDatabase, dbDirectory); - } catch (IOException e) { - throw new IllegalStateException( - "Could not copy db to " + dbDirectory); - } - - } - }; - - return configuration; - } -} Copied: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java (from rev 3452, trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java) =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java 2012-06-12 16:45:52 UTC (rev 3456) @@ -0,0 +1,63 @@ +/* + * #%L + * T3 :: Web + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package org.chorem.pollen.ui; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Rule; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.openqa.selenium.WebDriver; + +import java.util.Collection; + +/** + * Test base class for ui tests. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +@RunWith(value = Parameterized.class) +public abstract class PollenBaseWebDriverIT { + + /** Logger. */ + protected final Log log = LogFactory.getLog(getClass()); + + @Parameterized.Parameters + public static Collection<Object[]> driverTypes() { + return WebDriverResource.driverTypes(); + } + + @Rule + public WebDriverResource seleniumServer; + + protected PollenBaseWebDriverIT(Class<? extends WebDriver> driverType) { + seleniumServer = new WebDriverResource(getClass(), driverType); + } + + public WebDriver getDriver() { + return seleniumServer.getDriver(); + } + +} Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenTestApplicationListener.java (from rev 3454, trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenTestApplicationListener.java) =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenTestApplicationListener.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenTestApplicationListener.java 2012-06-12 16:45:52 UTC (rev 3456) @@ -0,0 +1,94 @@ +/* + * #%L + * Pollen :: UI (struts2) + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package org.chorem.pollen.ui; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.PollenConfiguration; +import org.chorem.pollen.PollenConfigurationOption; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +/** + * Pollen application listener used for test purposes. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class PollenTestApplicationListener extends PollenApplicationListener { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(PollenTestApplicationListener.class); + + @Override + protected PollenConfiguration prepareConfiguration() { + PollenConfiguration configuration; + + configuration = new PollenConfiguration("pollen-test.properties", + null) { + + @Override + protected void loadApplicationConfig(String file, + Properties defaultOptions) { + super.loadApplicationConfig(file, defaultOptions); + + // let's add a suffix (to isolate this data dir) + File dataDirectory = new File(getDataDirectory(), + String.valueOf(System.nanoTime())); + if (log.isInfoEnabled()) { + log.info("Data directory = " + dataDirectory); + } + setOption(PollenConfigurationOption.DATA_DIR.getKey(), + dataDirectory.getAbsolutePath()); + + + File incomingDatabase = getOptionAsFile("incomingDatabase"); + + if (log.isInfoEnabled()) { + log.info("Incoming db = " + incomingDatabase); + } + // copy db to correct path + File dbDirectory = new File(dataDirectory, "db"); + + try { + if (log.isInfoEnabled()) { + log.info("Copy incoming db [" + incomingDatabase + + "] to [" + dbDirectory + "]"); + } + FileUtils.copyFileToDirectory( + incomingDatabase, dbDirectory); + } catch (IOException e) { + throw new IllegalStateException( + "Could not copy db to " + dbDirectory); + } + + } + }; + + return configuration; + } +} Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenTestApplicationListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java (from rev 3452, trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/WebDriverResource.java) =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java 2012-06-12 16:45:52 UTC (rev 3456) @@ -0,0 +1,154 @@ +/* + * #%L + * T3 :: Web + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package org.chorem.pollen.ui; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.rules.ExternalResource; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeDriverService; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +/** + * Web driver resource. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class WebDriverResource extends ExternalResource { + + /** 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<?>> checkedDrivers = new ArrayList<Class<?>>(); + for (Class<? extends WebDriver> driver : allDrivers) { + boolean ok = checkDriver(driver); + if (ok) { + checkedDrivers.add(driver); + } + } + //{{ChromeDriver.class}, {FirefoxDriver.class}, {HtmlUnitDriver.class}} + Object[][] data = new Object[checkedDrivers.size()][1]; + int i = 0; + for (Class<?> checkedDriver : checkedDrivers) { + data[i++][0] = checkedDriver; + } + safeDrivers = Arrays.asList(data); + } + + return safeDrivers; + } + + private static boolean checkDriver(Class<? extends WebDriver> driverType) { + + WebDriver driver = null; + boolean result = false; + try { + driver = driverType.getConstructor().newInstance(); + result = true; + } catch (Exception e) { + + // can not use this driver + 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; + + protected WebDriver driver; + + public WebDriverResource(Class<?> testClass, + Class<? extends WebDriver> driverType) { + this.testClass = testClass; + this.driverType = driverType; + } + + public WebDriver getDriver() { + return driver; + } + + @Override + protected void before() throws Throwable { + if (log.isInfoEnabled()) { + log.info("Start test [" + testClass.getName() + "] with driver of type " + driverType.getName()); + } + if (ChromeDriver.class == driverType) { + + service = new ChromeDriverService.Builder() + .usingChromeDriverExecutable(new File("/usr/bin/chromium-browser")) + .usingAnyFreePort() + .build(); + service.start(); + + driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); + + } else { + driver = driverType.getConstructor().newInstance(); + } + } + + @Override + protected void after() { + if (ChromeDriver.class == driverType) { + service.stop(); + } + driver.quit(); + } +} Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java (from rev 3452, trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java) =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java 2012-06-12 16:45:52 UTC (rev 3456) @@ -0,0 +1,153 @@ +/* + * #%L + * T3 :: Web + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package org.chorem.pollen.ui.security; + +import junit.framework.Assert; +import org.chorem.pollen.ui.PollenBaseWebDriverIT; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.List; + +/** + * Test the login action. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ +public class LoginSIT extends PollenBaseWebDriverIT { + + public LoginSIT(Class<? extends WebDriver> driverType) { + super(driverType); + } + + @Test + public void loginAdmin() throws Exception { + + WebDriver driver = getDriver(); + + driver.get("http://localhost:8080/pollen/home"); + + 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")); + + // check there is a admin menu (so 4 menus) + List<WebElement> menus = driver.findElements(By.className("menu_elt")); + Assert.assertEquals(4, menus.size()); + } + + @Test + public void loginUser() throws Exception { + + WebDriver driver = getDriver(); + + driver.get("http://localhost:8080/pollen/home"); + + 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")); + + // check there is not a admin menu (so 2 menus) + List<WebElement> menus = driver.findElements(By.className("menu_elt")); + Assert.assertEquals(3, menus.size()); + } + + @Test + public void badLogin() throws Exception { + + WebDriver driver = getDriver(); + + driver.get("http://localhost:8080/pollen/home"); + + 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")); + } +} Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java (from rev 3455, trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java) =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java 2012-06-12 16:45:52 UTC (rev 3456) @@ -0,0 +1,303 @@ +package org.chorem.pollen.ui.security; + +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 : + * + * <ul> + * <li>Access to "connected pages" when connected (OK)</li> + * <li>Access to "connected pages" when not connected (KO)</li> + * <li>Access to "admin pages" when not connected (KO)</li> + * <li>Access to "admin pages" when not connected as admin (KO)</li> + * <li>Access to "admin pages" when connected as admin (OK)</li> + * </ul> + * + * TODO ymartel 2012/06/12 + * Should check those security access to : + * <ul> + * <li>Access to "poll page" with a good pollId (OK)</li> + * <li>Access to "poll page" with a bad pollId (KO)</li> + * <li>Access to "restricted poll page" with a good accountId (OK)</li> + * <li>Access to "restricted poll page" with a bad accountId (KO)</li> + * </ul> + * + * @author ymartel <martel@codelutin.com> + */ +public class SecurityAccessSIT extends PollenBaseWebDriverIT { + + public SecurityAccessSIT(Class<? extends WebDriver> driverType) { + 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> + * <li>Connect the user "user"</li> + * <li>Try to access to createdList page</li> + * <li>Try to access to invitedList page</li> + * <li>Try to access to participatedList page</li> + * <li>Try to access to favoriteLists page</li> + * </ol> + * + * All the page should be accessed. + * + * @throws Exception + */ + @Test + public void accessConnectedPageAsUser() throws Exception { + + WebDriver driver = getDriver(); + + if (log.isInfoEnabled()) { + log.info("Login url : " + driver.getCurrentUrl()); + } + // login as user + connect(driver, "user", "user"); + + // try to access to createdList page, current url should be good one + driver.get(CREATEDLIST_URL); + Assert.assertEquals(CREATEDLIST_URL, driver.getCurrentUrl()); + + // try to access to participatedList page, current url should be good one + driver.get(PARTICIPATEDLIST_URL); + Assert.assertEquals(PARTICIPATEDLIST_URL, driver.getCurrentUrl()); + + // try to access to invitedList page, current url should be good one + driver.get(INVITEDLIST_URL); + Assert.assertEquals(INVITEDLIST_URL, driver.getCurrentUrl()); + + // try to access to favoriteLists page, current url should be good one + driver.get(FAVORITELIST_URL); + Assert.assertEquals(FAVORITELIST_URL, driver.getCurrentUrl()); + + } + + /** + * This test : + * <ol> + * <li>Don't login</li> + * <li>Try to access to createdList page</li> + * <li>Try to access to invitedList page</li> + * <li>Try to access to participatedList page</li> + * <li>Try to access to favoriteLists page</li> + * </ol> + * + * All the page should be redirected to connected_required page. + * + * @throws Exception + */ + @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)); + + // 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)); + + // 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)); + + // 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)); + + } + + /** + * This test : + * <ol> + * <li>Don't login</li> + * <li>Try to access to admin polls list page</li> + * <li>Try to access to admin users list page</li> + * </ol> + * + * All the page should be redirected to connected_required page. + * + * @throws Exception + */ + @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)); + + // 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)); + + } + + /** + * This test : + * <ol> + * <li>Login as lambda user</li> + * <li>Try to access to admin polls list page</li> + * <li>Try to access to admin users list page</li> + * </ol> + * + * All the page should be redirected to admin_required page. + * + * @throws Exception + */ + @Test + public void accessAdminPageAsUser() throws Exception { + + WebDriver driver = getDriver(); + + // login as user + connect(driver, "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)); + + // 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)); + + } + + /** + * This test : + * <ol> + * <li>Login as admin</li> + * <li>Try to access to admin polls list page</li> + * <li>Try to access to admin users list page</li> + * </ol> + * + * All the page should be accessed. + * + * @throws Exception + */ + @Test + public void accessAdminPageAsAdmin() throws Exception { + + WebDriver driver = getDriver(); + + // login as user + connect(driver, "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()); + + // 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()); + + } + + /** + * This test : + * <ol> + * <li>Try to access to normal poll with good pollId</li> + * <li>Try to access to normal poll with bad pollId (should be redirected)</li> + * <li>Try to access to moderation page for normal poll with good pollId & good tokenId</li> + * <li>Try to access to moderation page for normal poll with good pollId & bad tokenId (should be redirected)</li> + * <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> + * + * All the page should be accessed. + * + * @throws Exception + */ + @Test + public void accessNormalPoolActionsAsAnonymous() throws Exception { + + WebDriver driver = getDriver(); + + // 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()); + + // 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)); + + // 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()); + + // 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)); + + // 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()); + + // 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)); + + } + + /** + * 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(); + } + +} Copied: trunk/pollen-ui-struts2/src/test/resources/log4j.properties (from rev 3451, trunk/pollen-ui-struts2-test/src/main/resources/log4j.properties) =================================================================== --- trunk/pollen-ui-struts2/src/test/resources/log4j.properties (rev 0) +++ trunk/pollen-ui-struts2/src/test/resources/log4j.properties 2012-06-12 16:45:52 UTC (rev 3456) @@ -0,0 +1,39 @@ +### +# #%L +# Pollen :: UI (struts2) +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# #L% +### +log4j.rootCategory=ERROR, console, file + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d [%p] %c %m%n + +log4j.logger.org.chorem.pollen=INFO +log4j.logger.org.chorem.pollen.ui.PollenShiroIsAdministratorFilter=DEBUG +log4j.logger.org.nuiton=INFO + +# FileAppender : need to have pollen.log.dir in system properties at application startup +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.File=${basedir}/target/pollen.log +log4j.appender.file.MaxFileSize=10MB +log4j.appender.file.MaxBackupIndex=4 +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{yyyy/MM/dd hh:mm:ss} %5p (%F:%L) %m%n Property changes on: trunk/pollen-ui-struts2/src/test/resources/log4j.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/test/resources/pollen-test.properties (from rev 3454, trunk/pollen-ui-struts2-test/src/main/resources/pollen-test.properties) =================================================================== --- trunk/pollen-ui-struts2/src/test/resources/pollen-test.properties (rev 0) +++ trunk/pollen-ui-struts2/src/test/resources/pollen-test.properties 2012-06-12 16:45:52 UTC (rev 3456) @@ -0,0 +1,46 @@ +### +# #%L +# Pollen :: UI (struts2) Test +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2009 - 2012 CodeLutin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# #L% +### + +# Db configuration +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.connection.username=sa +hibernate.connection.password=sa +hibernate.connection.driver_class=org.h2.Driver +hibernate.show_sql=false +hibernate.hbm2ddl.auto=update + +# Database migration configuration +topia.service.migration=org.nuiton.topia.migration.TopiaMigrationEngine +topia.service.migration.callback=org.chorem.pollen.entities.migration.PollenMigrationCallback +topia.service.migration.showSql=false + +# Version de l'application +pollen.version=${project.version} + +# url de l'application +siteUrl=http://localhost:8080/pollen + +# répertoire des données (chaque execution utilisera un sous répertoire) +pollen.dataDirectory=${basedir}/target/surefire-workdir/pollen-data + +incomingDatabase=${basedir}/target/test-classes/pollendb.h2.db \ No newline at end of file Property changes on: trunk/pollen-ui-struts2/src/test/resources/pollen-test.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/pollen-ui-struts2/src/test/resources/pollendb.h2.db (from rev 3454, trunk/pollen-ui-struts2-test/src/test/resources/pollendb.h2.db) =================================================================== (Binary files differ) Property changes on: trunk/pollen-ui-struts2/src/test/resources/pollendb.h2.db ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: svn:keywords + Author Date Id Revision HeadURL Added: trunk/pollen-ui-struts2/src/test/resources/web-test.xml =================================================================== --- trunk/pollen-ui-struts2/src/test/resources/web-test.xml (rev 0) +++ trunk/pollen-ui-struts2/src/test/resources/web-test.xml 2012-06-12 16:45:52 UTC (rev 3456) @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + Pollen :: UI (struts2) + $Id: web.xml 3451 2012-06-12 12:07:38Z tchemit $ + $HeadURL: http://svn.chorem.org/svn/pollen/trunk/pollen-ui-struts2-test/src/main/webap... $ + %% + Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --> + +<web-app id="Pollen" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> + + <display-name>Pollen</display-name> + + <filter> + <filter-name>topiaTransaction</filter-name> + <filter-class>org.chorem.pollen.ui.PollenTopiaTransactionFilter</filter-class> + </filter> + + <filter> + <filter-name>struts-prepare</filter-name> + <filter-class> + org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter + </filter-class> + </filter> + <filter> + <filter-name>ShiroFilter</filter-name> + <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class> + </filter> + + <filter> + <filter-name>sitemesh</filter-name> + <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> + </filter> + + <filter> + <filter-name>struts-execute</filter-name> + <filter-class> + org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter + </filter-class> + </filter> + + <filter-mapping> + <filter-name>topiaTransaction</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <filter-mapping> + <filter-name>ShiroFilter</filter-name> + <url-pattern>/*</url-pattern> + <dispatcher>REQUEST</dispatcher> + <dispatcher>FORWARD</dispatcher> + <dispatcher>INCLUDE</dispatcher> + <dispatcher>ERROR</dispatcher> + </filter-mapping> + + <filter-mapping> + <filter-name>struts-prepare</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <filter-mapping> + <filter-name>sitemesh</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <filter-mapping> + <filter-name>struts-execute</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <listener> + <description>Init</description> + <listener-class>org.chorem.pollen.ui.PollenTestApplicationListener</listener-class> + </listener> + + <listener> + <description>Shiro security layer</description> + <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class> + </listener> + + <welcome-file-list> + <welcome-file>/</welcome-file> + <welcome-file>index.jsp</welcome-file> + <welcome-file>home</welcome-file> + </welcome-file-list> +</web-app> Modified: trunk/pollen-ui-struts2-test/pom.xml =================================================================== --- trunk/pollen-ui-struts2-test/pom.xml 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pollen-ui-struts2-test/pom.xml 2012-06-12 16:45:52 UTC (rev 3456) @@ -25,6 +25,7 @@ <artifactId>pollen-ui-struts2</artifactId> <version>${project.version}</version> <type>war</type> + <classifier>embedded</classifier> </dependency> <dependency> @@ -121,30 +122,45 @@ <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <configuration> - <daemon>true</daemon> <stopKey>A</stopKey> <stopPort>1269</stopPort> - <webAppConfig> - <contextPath>/pollen</contextPath> - </webAppConfig> - <systemProperties> - <systemProperty> - <name>siteUrl</name> - <value>http://localhost:8080/pollen</value> - </systemProperty> - <systemProperty> - <name>pollen.log.dir</name> - <value>target</value> - </systemProperty> - </systemProperties> </configuration> <executions> + <execution> + <id>start-pollen</id> + <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> - <phase>pre-integration-test</phase> + <configuration> + <daemon>true</daemon> + <stopKey>A</stopKey> + <stopPort>1269</stopPort> + <webAppConfig> + <descriptor>src/test/resources/web-test.xml</descriptor> + <contextPath>/pollen</contextPath> + </webAppConfig> + <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> + + <execution> + <id>stop-pollen</id> + <phase>post-integration-test</phase> + <goals> + <goal>stop</goal> + </goals> + </execution> </executions> </plugin> Deleted: trunk/pollen-ui-struts2-test/src/main/resources/log4j.properties =================================================================== --- trunk/pollen-ui-struts2-test/src/main/resources/log4j.properties 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pollen-ui-struts2-test/src/main/resources/log4j.properties 2012-06-12 16:45:52 UTC (rev 3456) @@ -1,39 +0,0 @@ -### -# #%L -# Pollen :: UI (struts2) -# $Id$ -# $HeadURL$ -# %% -# Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# #L% -### -log4j.rootCategory=ERROR, console, file - -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d [%p] %c %m%n - -log4j.logger.org.chorem.pollen=INFO -log4j.logger.org.chorem.pollen.ui.PollenShiroIsAdministratorFilter=DEBUG -log4j.logger.org.nuiton=INFO - -# FileAppender : need to have pollen.log.dir in system properties at application startup -log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=${basedir}/target/pollen.log -log4j.appender.file.MaxFileSize=10MB -log4j.appender.file.MaxBackupIndex=4 -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{yyyy/MM/dd hh:mm:ss} %5p (%F:%L) %m%n Deleted: trunk/pollen-ui-struts2-test/src/main/resources/pollen-test.properties =================================================================== --- trunk/pollen-ui-struts2-test/src/main/resources/pollen-test.properties 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pollen-ui-struts2-test/src/main/resources/pollen-test.properties 2012-06-12 16:45:52 UTC (rev 3456) @@ -1,46 +0,0 @@ -### -# #%L -# Pollen :: UI (struts2) Test -# $Id$ -# $HeadURL$ -# %% -# Copyright (C) 2009 - 2012 CodeLutin -# %% -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# #L% -### - -# Db configuration -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.connection.username=sa -hibernate.connection.password=sa -hibernate.connection.driver_class=org.h2.Driver -hibernate.show_sql=false -hibernate.hbm2ddl.auto=update - -# Database migration configuration -topia.service.migration=org.nuiton.topia.migration.TopiaMigrationEngine -topia.service.migration.callback=org.chorem.pollen.entities.migration.PollenMigrationCallback -topia.service.migration.showSql=false - -# Version de l'application -pollen.version=${project.version} - -# url de l'application -siteUrl=http://localhost:8080/pollen - -# répertoire des données (chaque execution utilisera un sous répertoire) -pollen.dataDirectory=${basedir}/target/surefire-workdir/pollen-data - -incomingDatabase=${basedir}/target/test-classes/pollendb.h2.db \ No newline at end of file Deleted: trunk/pollen-ui-struts2-test/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/pollen-ui-struts2-test/src/main/webapp/WEB-INF/web.xml 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pollen-ui-struts2-test/src/main/webapp/WEB-INF/web.xml 2012-06-12 16:45:52 UTC (rev 3456) @@ -1,103 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - #%L - Pollen :: UI (struts2) - $Id$ - $HeadURL$ - %% - Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit - %% - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - #L% - --> - -<web-app id="Pollen" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> - - <display-name>Pollen</display-name> - - <filter> - <filter-name>topiaTransaction</filter-name> - <filter-class>org.chorem.pollen.ui.PollenTopiaTransactionFilter</filter-class> - </filter> - - <filter> - <filter-name>struts-prepare</filter-name> - <filter-class> - org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter - </filter-class> - </filter> - <filter> - <filter-name>ShiroFilter</filter-name> - <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class> - </filter> - - <filter> - <filter-name>sitemesh</filter-name> - <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> - </filter> - - <filter> - <filter-name>struts-execute</filter-name> - <filter-class> - org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter - </filter-class> - </filter> - - <filter-mapping> - <filter-name>topiaTransaction</filter-name> - <url-pattern>/*</url-pattern> - </filter-mapping> - - <filter-mapping> - <filter-name>ShiroFilter</filter-name> - <url-pattern>/*</url-pattern> - <dispatcher>REQUEST</dispatcher> - <dispatcher>FORWARD</dispatcher> - <dispatcher>INCLUDE</dispatcher> - <dispatcher>ERROR</dispatcher> - </filter-mapping> - - <filter-mapping> - <filter-name>struts-prepare</filter-name> - <url-pattern>/*</url-pattern> - </filter-mapping> - - <filter-mapping> - <filter-name>sitemesh</filter-name> - <url-pattern>/*</url-pattern> - </filter-mapping> - - <filter-mapping> - <filter-name>struts-execute</filter-name> - <url-pattern>/*</url-pattern> - </filter-mapping> - - <listener> - <description>Init</description> - <listener-class>org.chorem.pollen.ui.PollenTestApplicationListener</listener-class> - </listener> - - <listener> - <description>Shiro security layer</description> - <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class> - </listener> - - <welcome-file-list> - <welcome-file>/</welcome-file> - <welcome-file>index.jsp</welcome-file> - <welcome-file>home</welcome-file> - </welcome-file-list> -</web-app> Deleted: trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java =================================================================== --- trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java 2012-06-12 16:45:52 UTC (rev 3456) @@ -1,63 +0,0 @@ -/* - * #%L - * T3 :: Web - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package org.chorem.pollen.ui; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Rule; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.openqa.selenium.WebDriver; - -import java.util.Collection; - -/** - * Test base class for ui tests. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -@RunWith(value = Parameterized.class) -public abstract class PollenBaseWebDriverIT { - - /** Logger. */ - protected final Log log = LogFactory.getLog(getClass()); - - @Parameterized.Parameters - public static Collection<Object[]> driverTypes() { - return WebDriverResource.driverTypes(); - } - - @Rule - public WebDriverResource seleniumServer; - - protected PollenBaseWebDriverIT(Class<? extends WebDriver> driverType) { - seleniumServer = new WebDriverResource(getClass(), driverType); - } - - public WebDriver getDriver() { - return seleniumServer.getDriver(); - } - -} Deleted: trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/WebDriverResource.java =================================================================== --- trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/WebDriverResource.java 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/WebDriverResource.java 2012-06-12 16:45:52 UTC (rev 3456) @@ -1,154 +0,0 @@ -/* - * #%L - * T3 :: Web - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package org.chorem.pollen.ui; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.rules.ExternalResource; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeDriverService; -import org.openqa.selenium.firefox.FirefoxDriver; -import org.openqa.selenium.htmlunit.HtmlUnitDriver; -import org.openqa.selenium.remote.DesiredCapabilities; -import org.openqa.selenium.remote.RemoteWebDriver; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -/** - * Web driver resource. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class WebDriverResource extends ExternalResource { - - /** 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<?>> checkedDrivers = new ArrayList<Class<?>>(); - for (Class<? extends WebDriver> driver : allDrivers) { - boolean ok = checkDriver(driver); - if (ok) { - checkedDrivers.add(driver); - } - } - //{{ChromeDriver.class}, {FirefoxDriver.class}, {HtmlUnitDriver.class}} - Object[][] data = new Object[checkedDrivers.size()][1]; - int i = 0; - for (Class<?> checkedDriver : checkedDrivers) { - data[i++][0] = checkedDriver; - } - safeDrivers = Arrays.asList(data); - } - - return safeDrivers; - } - - private static boolean checkDriver(Class<? extends WebDriver> driverType) { - - WebDriver driver = null; - boolean result = false; - try { - driver = driverType.getConstructor().newInstance(); - result = true; - } catch (Exception e) { - - // can not use this driver - 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; - - protected WebDriver driver; - - public WebDriverResource(Class<?> testClass, - Class<? extends WebDriver> driverType) { - this.testClass = testClass; - this.driverType = driverType; - } - - public WebDriver getDriver() { - return driver; - } - - @Override - protected void before() throws Throwable { - if (log.isInfoEnabled()) { - log.info("Start test [" + testClass.getName() + "] with driver of type " + driverType.getName()); - } - if (ChromeDriver.class == driverType) { - - service = new ChromeDriverService.Builder() - .usingChromeDriverExecutable(new File("/usr/bin/chromium-browser")) - .usingAnyFreePort() - .build(); - service.start(); - - driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); - - } else { - driver = driverType.getConstructor().newInstance(); - } - } - - @Override - protected void after() { - if (ChromeDriver.class == driverType) { - service.stop(); - } - driver.quit(); - } -} Deleted: trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java =================================================================== --- trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java 2012-06-12 16:45:52 UTC (rev 3456) @@ -1,153 +0,0 @@ -/* - * #%L - * T3 :: Web - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 - 2011 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package org.chorem.pollen.ui.security; - -import junit.framework.Assert; -import org.chorem.pollen.ui.PollenBaseWebDriverIT; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; - -import java.util.List; - -/** - * Test the login action. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.4 - */ -public class LoginSIT extends PollenBaseWebDriverIT { - - public LoginSIT(Class<? extends WebDriver> driverType) { - super(driverType); - } - - @Test - public void loginAdmin() throws Exception { - - WebDriver driver = getDriver(); - - driver.get("http://localhost:8080/pollen/home"); - - 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")); - - // check there is a admin menu (so 4 menus) - List<WebElement> menus = driver.findElements(By.className("menu_elt")); - Assert.assertEquals(4, menus.size()); - } - - @Test - public void loginUser() throws Exception { - - WebDriver driver = getDriver(); - - driver.get("http://localhost:8080/pollen/home"); - - 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")); - - // check there is not a admin menu (so 2 menus) - List<WebElement> menus = driver.findElements(By.className("menu_elt")); - Assert.assertEquals(3, menus.size()); - } - - @Test - public void badLogin() throws Exception { - - WebDriver driver = getDriver(); - - driver.get("http://localhost:8080/pollen/home"); - - 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")); - } -} Deleted: trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java =================================================================== --- trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pollen-ui-struts2-test/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java 2012-06-12 16:45:52 UTC (rev 3456) @@ -1,303 +0,0 @@ -package org.chorem.pollen.ui.security; - -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 : - * - * <ul> - * <li>Access to "connected pages" when connected (OK)</li> - * <li>Access to "connected pages" when not connected (KO)</li> - * <li>Access to "admin pages" when not connected (KO)</li> - * <li>Access to "admin pages" when not connected as admin (KO)</li> - * <li>Access to "admin pages" when connected as admin (OK)</li> - * </ul> - * - * TODO ymartel 2012/06/12 - * Should check those security access to : - * <ul> - * <li>Access to "poll page" with a good pollId (OK)</li> - * <li>Access to "poll page" with a bad pollId (KO)</li> - * <li>Access to "restricted poll page" with a good accountId (OK)</li> - * <li>Access to "restricted poll page" with a bad accountId (KO)</li> - * </ul> - * - * @author ymartel <martel@codelutin.com> - */ -public class SecurityAccessSIT extends PollenBaseWebDriverIT { - - public SecurityAccessSIT(Class<? extends WebDriver> driverType) { - 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> - * <li>Connect the user "user"</li> - * <li>Try to access to createdList page</li> - * <li>Try to access to invitedList page</li> - * <li>Try to access to participatedList page</li> - * <li>Try to access to favoriteLists page</li> - * </ol> - * - * All the page should be accessed. - * - * @throws Exception - */ - @Test - public void accessConnectedPageAsUser() throws Exception { - - WebDriver driver = getDriver(); - - if (log.isInfoEnabled()) { - log.info("Login url : " + driver.getCurrentUrl()); - } - // login as user - connect(driver, "user", "user"); - - // try to access to createdList page, current url should be good one - driver.get(CREATEDLIST_URL); - Assert.assertEquals(CREATEDLIST_URL, driver.getCurrentUrl()); - - // try to access to participatedList page, current url should be good one - driver.get(PARTICIPATEDLIST_URL); - Assert.assertEquals(PARTICIPATEDLIST_URL, driver.getCurrentUrl()); - - // try to access to invitedList page, current url should be good one - driver.get(INVITEDLIST_URL); - Assert.assertEquals(INVITEDLIST_URL, driver.getCurrentUrl()); - - // try to access to favoriteLists page, current url should be good one - driver.get(FAVORITELIST_URL); - Assert.assertEquals(FAVORITELIST_URL, driver.getCurrentUrl()); - - } - - /** - * This test : - * <ol> - * <li>Don't login</li> - * <li>Try to access to createdList page</li> - * <li>Try to access to invitedList page</li> - * <li>Try to access to participatedList page</li> - * <li>Try to access to favoriteLists page</li> - * </ol> - * - * All the page should be redirected to connected_required page. - * - * @throws Exception - */ - @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)); - - // 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)); - - // 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)); - - // 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)); - - } - - /** - * This test : - * <ol> - * <li>Don't login</li> - * <li>Try to access to admin polls list page</li> - * <li>Try to access to admin users list page</li> - * </ol> - * - * All the page should be redirected to connected_required page. - * - * @throws Exception - */ - @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)); - - // 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)); - - } - - /** - * This test : - * <ol> - * <li>Login as lambda user</li> - * <li>Try to access to admin polls list page</li> - * <li>Try to access to admin users list page</li> - * </ol> - * - * All the page should be redirected to admin_required page. - * - * @throws Exception - */ - @Test - public void accessAdminPageAsUser() throws Exception { - - WebDriver driver = getDriver(); - - // login as user - connect(driver, "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)); - - // 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)); - - } - - /** - * This test : - * <ol> - * <li>Login as admin</li> - * <li>Try to access to admin polls list page</li> - * <li>Try to access to admin users list page</li> - * </ol> - * - * All the page should be accessed. - * - * @throws Exception - */ - @Test - public void accessAdminPageAsAdmin() throws Exception { - - WebDriver driver = getDriver(); - - // login as user - connect(driver, "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()); - - // 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()); - - } - - /** - * This test : - * <ol> - * <li>Try to access to normal poll with good pollId</li> - * <li>Try to access to normal poll with bad pollId (should be redirected)</li> - * <li>Try to access to moderation page for normal poll with good pollId & good tokenId</li> - * <li>Try to access to moderation page for normal poll with good pollId & bad tokenId (should be redirected)</li> - * <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> - * - * All the page should be accessed. - * - * @throws Exception - */ - @Test - public void accessNormalPoolActionsAsAnonymous() throws Exception { - - WebDriver driver = getDriver(); - - // 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()); - - // 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)); - - // 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()); - - // 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)); - - // 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()); - - // 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)); - - } - - /** - * 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(); - } - -} Deleted: trunk/pollen-ui-struts2-test/src/test/resources/pollendb.h2.db =================================================================== (Binary files differ) Copied: trunk/pollen-ui-struts2-test/src/test/resources/web-test.xml (from rev 3451, trunk/pollen-ui-struts2-test/src/main/webapp/WEB-INF/web.xml) =================================================================== --- trunk/pollen-ui-struts2-test/src/test/resources/web-test.xml (rev 0) +++ trunk/pollen-ui-struts2-test/src/test/resources/web-test.xml 2012-06-12 16:45:52 UTC (rev 3456) @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + Pollen :: UI (struts2) + $Id$ + $HeadURL$ + %% + Copyright (C) 2009 - 2012 CodeLutin, Tony Chemit + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --> + +<web-app id="Pollen" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> + + <display-name>Pollen</display-name> + + <filter> + <filter-name>topiaTransaction</filter-name> + <filter-class>org.chorem.pollen.ui.PollenTopiaTransactionFilter</filter-class> + </filter> + + <filter> + <filter-name>struts-prepare</filter-name> + <filter-class> + org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter + </filter-class> + </filter> + <filter> + <filter-name>ShiroFilter</filter-name> + <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class> + </filter> + + <filter> + <filter-name>sitemesh</filter-name> + <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class> + </filter> + + <filter> + <filter-name>struts-execute</filter-name> + <filter-class> + org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter + </filter-class> + </filter> + + <filter-mapping> + <filter-name>topiaTransaction</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <filter-mapping> + <filter-name>ShiroFilter</filter-name> + <url-pattern>/*</url-pattern> + <dispatcher>REQUEST</dispatcher> + <dispatcher>FORWARD</dispatcher> + <dispatcher>INCLUDE</dispatcher> + <dispatcher>ERROR</dispatcher> + </filter-mapping> + + <filter-mapping> + <filter-name>struts-prepare</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <filter-mapping> + <filter-name>sitemesh</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <filter-mapping> + <filter-name>struts-execute</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <listener> + <description>Init</description> + <listener-class>org.chorem.pollen.ui.PollenTestApplicationListener</listener-class> + </listener> + + <listener> + <description>Shiro security layer</description> + <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class> + </listener> + + <welcome-file-list> + <welcome-file>/</welcome-file> + <welcome-file>index.jsp</welcome-file> + <welcome-file>home</welcome-file> + </welcome-file-list> +</web-app> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-06-12 16:23:53 UTC (rev 3455) +++ trunk/pom.xml 2012-06-12 16:45:52 UTC (rev 3456) @@ -24,7 +24,6 @@ <module>pollen-persistence</module> <module>pollen-services</module> <module>pollen-ui-struts2</module> - <module>pollen-ui-struts2-test</module> </modules> <name>Pollen</name>
participants (1)
-
tchemit@users.chorem.org