Author: tchemit Date: 2012-08-26 13:19:25 +0200 (Sun, 26 Aug 2012) New Revision: 3629 Url: http://chorem.org/repositories/revision/pollen/3629 Log: refs #606: Add some ITs to prevent regression (ok, layout is ok, now just have to write tests\!) Added: trunk/pollen-ui-struts2/src/it/pollVoteVisibility/src/test/java/org/chorem/poll/ui/it/AnonymousFreePollByAnonymousIT.java trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/AbstractPollIT.java trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/PollenUrlFixtures.java trunk/pollen-ui-struts2/src/test/resources/pollen-it.properties Removed: trunk/pollen-ui-struts2/src/it/pollen-ui-it/src/config/ Modified: trunk/pollen-ui-struts2/src/it/pollVoteVisibility/ trunk/pollen-ui-struts2/src/it/pollen-ui-it/ trunk/pollen-ui-struts2/src/it/pollen-ui-it/pom.xml trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/WebDriverResources.java Property changes on: trunk/pollen-ui-struts2/src/it/pollVoteVisibility ___________________________________________________________________ Added: svn:ignore + *.ipr *.iws *.iml Added: trunk/pollen-ui-struts2/src/it/pollVoteVisibility/src/test/java/org/chorem/poll/ui/it/AnonymousFreePollByAnonymousIT.java =================================================================== --- trunk/pollen-ui-struts2/src/it/pollVoteVisibility/src/test/java/org/chorem/poll/ui/it/AnonymousFreePollByAnonymousIT.java (rev 0) +++ trunk/pollen-ui-struts2/src/it/pollVoteVisibility/src/test/java/org/chorem/poll/ui/it/AnonymousFreePollByAnonymousIT.java 2012-08-26 11:19:25 UTC (rev 3629) @@ -0,0 +1,39 @@ +package org.chorem.poll.ui.it; + +import org.chorem.pollen.ui.it.AbstractPollIT; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebDriver; + +/** + * Test a anonymous free poll created by a anonymous user. + * <p/> + * For that poll nobody can see votes. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4.5 + */ +public class AnonymousFreePollByAnonymousIT extends AbstractPollIT { + + public AnonymousFreePollByAnonymousIT(Class<? extends WebDriver> driverType) { + super(driverType, + "cacb52f4d49047b7a7aa24ec528fcc87", + "e814ba6e25174d5983ad796c400520f5"); + } + + @Test + public void checkSummaryPollPage() { + + // can not access to summary page with no pollId + gotoUrl(urlFixtures.summaryPoll(), urlFixtures.poll_required(), false); + + // can not access to summary page with no creatorId + gotoUrl(urlFixtures.summaryPoll(), urlFixtures.poll_creator_required(), false); + + // access to summary page + gotoUrl(urlFixtures.summaryPoll(adminPollUri), true); + + // check can vote + Assert.assertTrue(true); + } +} Property changes on: trunk/pollen-ui-struts2/src/it/pollVoteVisibility/src/test/java/org/chorem/poll/ui/it/AnonymousFreePollByAnonymousIT.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Property changes on: trunk/pollen-ui-struts2/src/it/pollen-ui-it ___________________________________________________________________ Added: svn:ignore + *.iml *.ipr *.iws .idea Modified: trunk/pollen-ui-struts2/src/it/pollen-ui-it/pom.xml =================================================================== --- trunk/pollen-ui-struts2/src/it/pollen-ui-it/pom.xml 2012-08-25 18:51:42 UTC (rev 3628) +++ trunk/pollen-ui-struts2/src/it/pollen-ui-it/pom.xml 2012-08-26 11:19:25 UTC (rev 3629) @@ -23,6 +23,8 @@ <defaultLogDir>${basedir}/target</defaultLogDir> <explodedWarPath>../pollen-ui-it/target/war</explodedWarPath> + <pollenConfigurationFile>pollen-it.properties</pollenConfigurationFile> + <pollenDataDirectory>${project.build.testOutputDirectory}/data</pollenDataDirectory> </properties> <dependencies> @@ -91,29 +93,6 @@ <plugins> <plugin> - <artifactId>maven-antrun-plugin</artifactId> - <inherited>false</inherited> - <executions> - <execution> - <phase>generate-test-resources</phase> - <configuration> - <tasks> - <copy failonerror="false" overwrite="true" - todir="${project.build.directory}/war/WEB-INF/classes"> - <fileset dir="${basedir}/config/"> - <include name="**/*" /> - </fileset> - </copy> - </tasks> - </configuration> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> <artifactId>maven-dependency-plugin</artifactId> <inherited>false</inherited> <executions> @@ -166,7 +145,7 @@ </systemProperty> <systemProperty> <name>pollenConfigurationFile</name> - <value>pollen-it.properties</value> + <value>${pollenConfigurationFile}</value> </systemProperty> <systemProperty> <name>jetty.port</name> @@ -178,12 +157,28 @@ </systemProperty> <systemProperty> <name>pollenDataDirectory</name> - <value>${project.build.directory}/test-classes/data</value> + <value>${pollenDataDirectory}</value> </systemProperty> </systemProperties> </configuration> </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + + <execution> + <id>default-test</id> + <goals> + <goal>test</goal> + </goals> + <configuration> + <skip>true</skip> + </configuration> + </execution> + </executions> + </plugin> + </plugins> </pluginManagement> </build> @@ -209,7 +204,7 @@ <goal>run</goal> </goals> <configuration> - <daemon>false</daemon> + <daemon>true</daemon> <webAppSourceDirectory> ${explodedWarPath} </webAppSourceDirectory> @@ -221,7 +216,7 @@ <classesDirectory> ${explodedWarPath}/WEB-INF/classes </classesDirectory> - <!--useTestScope>true</useTestScope--> + <useTestScope>true</useTestScope> </configuration> </execution> @@ -250,6 +245,12 @@ </includes> <systemPropertyVariables> <pollenServerPort>${pollenServerPort}</pollenServerPort> + <pollenConfigurationFile> + ${pollenConfigurationFile} + </pollenConfigurationFile> + <pollenDataDirectory> + ${pollenDataDirectory} + </pollenDataDirectory> </systemPropertyVariables> </configuration> </execution> Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/AbstractPollIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/AbstractPollIT.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/AbstractPollIT.java 2012-08-26 11:19:25 UTC (rev 3629) @@ -0,0 +1,224 @@ +package org.chorem.pollen.ui.it; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.bean.PollUri; +import org.chorem.pollen.business.persistence.Poll; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +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; + +/** + * Base class test for a it on a specific poll. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4.5 + */ +@RunWith(value = Parameterized.class) +public class AbstractPollIT { + + /** Logger. */ + protected final Log log = LogFactory.getLog(getClass()); + + @Parameterized.Parameters + public static Collection<Object[]> driverTypes() { + return WebDriverResources.driverTypes(); + } + + /** Selenium driver to use for all tests of this class. */ + @ClassRule + public static final WebDriverResources seleniumServer = new WebDriverResources(); + + /** URL fixtures. */ + protected static final PollenUrlFixtures urlFixtures = new PollenUrlFixtures(); + + /** Type of driver used by currenttest. */ + protected final Class<? extends WebDriver> driverType; + + /** {@link Poll#getPollId()}. */ + protected final String pollId; + + /** {@link Poll#getCreator()#accountId} */ + protected final String accountId; + + /** {@link PollUri} of the poll (with no accountId) */ + protected final PollUri pollUri; + + /** {@link PollUri} of the poll (with admin accountId ) */ + protected final PollUri adminPollUri; + + /** Driver used by current test. */ + protected WebDriver driver; + + protected AbstractPollIT(Class<? extends WebDriver> driverType, + String pollId, String accountId) { + this.pollId = pollId; + this.accountId = accountId; + this.driverType = driverType; + + pollUri = PollUri.newPollUri(pollId); + adminPollUri = PollUri.newPollUri(pollId, accountId); + } + + @Before + public void setUp() throws Exception { + driver = seleniumServer.getDriver(driverType); + } + + @After + public void after() { + + // make sure driver came back in original state: + // go back to home page and logout if was loggued in + logout(); + } + + protected PollUri newPollUri(String accountId) { + return PollUri.newPollUri(pollId, accountId); + } + + protected void logout() { + gotoUrl(urlFixtures.logout(), urlFixtures.home(), true); + } + + 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; + } + checkCurrentUrl(expectedUrl, strict); + } + + /** + * Check that the current URL is the expected one. + * If it is a strict comparison, the URL should be the same that the wanted. + * If not, it only checks that the current URL start with the wanted url. + */ + protected void checkCurrentUrl(String expectedUrl, boolean strict) { + if (strict) { + Assert.assertEquals("Current url [" + driver.getCurrentUrl() + "] should be " + expectedUrl, expectedUrl, driver.getCurrentUrl()); + } else { + Assert.assertTrue("Current url [" + driver.getCurrentUrl() + "] should starts with " + expectedUrl, 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(); + } + + /** + * Set a value for a WebElement. + * <p/> + * This operations does 3 steps : + * <ul> + * <li>Get the WebElement thanks to its id (given in parameter)</li> + * <li>check the element is an input</li> + * <li>check the element is displayed</li> + * <li>clear the element</li> + * <li>send the wanted keys</li> + * </ul> + */ + protected void sendKeysById(String webElementId, String value) { + sendKeysBy(By.id(webElementId), value); + } + + /** + * Set a value for a WebElement. + * <p/> + * This operations does 3 steps : + * <ul> + * <li>Get the WebElement thanks to its name (given in parameter)</li> + * <li>check the element is an input</li> + * <li>check the element is displayed</li> + * <li>clear the element</li> + * <li>send the wanted keys</li> + * </ul> + */ + protected void sendKeysByName(String webElementName, String value) { + By byName = By.name(webElementName); + sendKeysBy(byName, value); + } + + /** + * Set a value for a WebElement. + * <p/> + * This operations does 3 steps : + * <ul> + * <li>Get the WebElement thanks to a {@link By} locator</li> + * <li>check the element is an input</li> + * <li>check the element is displayed</li> + * <li>clear the element</li> + * <li>send the wanted keys</li> + * </ul> + */ + protected void sendKeysBy(By by, String value) { + WebElement webElement = findElement(by); + Assert.assertEquals("input", webElement.getTagName()); + Assert.assertTrue(webElement.isDisplayed()); + webElement.sendKeys(value); + Assert.assertEquals(value, webElement.getAttribute("value")); + } + + /** + * Get a WebElement with a {@link By} locator, and check it is an input + * and that is value is the one expected. + */ + protected void checkWebElementValue(By by, String expectedValue) { + WebElement webElement = findElement(by); + Assert.assertEquals("input", webElement.getTagName()); + Assert.assertTrue(webElement.isDisplayed()); + Assert.assertEquals(expectedValue, webElement.getAttribute("value")); + } +} Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/AbstractPollIT.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/PollenUrlFixtures.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/PollenUrlFixtures.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/PollenUrlFixtures.java 2012-08-26 11:19:25 UTC (rev 3629) @@ -0,0 +1,193 @@ +package org.chorem.pollen.ui.it; + +import com.google.common.base.Preconditions; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.PollenConfiguration; +import org.chorem.pollen.bean.PollUri; + +/** + * All urls useables by a test. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4.5 + */ +public class PollenUrlFixtures { + + /** Logger. */ + private static final Log log = LogFactory.getLog(PollenUrlFixtures.class); + + /** + * Define all urls useables in tests (and in application). + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4.5 + */ + private static enum POLLEN_URL { + + poll_creator_required("security/illegal_access"), + poll_access_required("security/illegal_access"), + poll_required("security/illegal_access"), + admin_required("security/illegal_access"), + connected_required("security/illegal_access"), + + home("home"), + createdList("user/createdList"), + invitedList("user/invitedList"), + participatedList("user/participatedList"), + favoriteLists("user/favoriteLists"), + logout("user/logout"), + + pollsList("admin/pollsList"), + usersList("admin/usersList"), + + createPoll("poll/create"), + editPoll("poll/edit", "!input"), + voteforPoll("poll/votefor"), + summaryPoll("poll/summary"); + + private final String path; + + private final String suffix; + + POLLEN_URL(String path, String suffix) { + this.path = path; + this.suffix = suffix; + } + + POLLEN_URL(String path) { + this(path, null); + } + + public String getPath() { + return path; + } + + public String toURL(PollenUrlFixtures fixtures) { + String result = toURL(fixtures, null); + return result; + } + + public String toURL(PollenUrlFixtures fixtures, PollUri pollUri) { + String result = fixtures.baseUrl() + getPath(); + if (pollUri != null) { + result += "/" + pollUri.toString(); + if (suffix != null) { + result += suffix; + } + } + return result; + } + } + + /** + * The base url of the application. + * <p/> + * This url contains also the web context. This url is obtain from + * the configuration. + * <p/> + * Example: + * <p/> + * <pre>http://localhost:8765/pollen</pre> + * + * @see PollenConfiguration#getApplicationUrl() + */ + protected final String baseUrl; + + /** Configuration of Pollen. */ + protected final PollenConfiguration configuration; + + public PollenUrlFixtures() { + String configurationFile = System.getProperty("pollenConfigurationFile"); + Preconditions.checkNotNull(configurationFile); + // load configuration + configuration = new PollenConfiguration(configurationFile, null); + + // load baseurl + String url = configuration.getApplicationUrl().toString(); + if (!url.endsWith("/")) { + url += "/"; + } + this.baseUrl = url; + + if (log.isInfoEnabled()) { + log.info("Base url = " + url); + } + } + + protected String baseUrl() { + return baseUrl; + } + + public String home() { + return POLLEN_URL.home.toURL(this); + } + + public String createdList() { + return POLLEN_URL.createdList.toURL(this); + } + + public String invitedList() { + return POLLEN_URL.createdList.toURL(this); + } + + public String participatedList() { + return POLLEN_URL.participatedList.toURL(this); + } + + public String favoriteLists() { + return POLLEN_URL.favoriteLists.toURL(this); + } + + public String pollsList() { + return POLLEN_URL.pollsList.toURL(this); + } + + public String usersList() { + return POLLEN_URL.usersList.toURL(this); + } + + public String connected_required() { + return POLLEN_URL.connected_required.toURL(this); + } + + public String admin_required() { + return POLLEN_URL.admin_required.toURL(this); + } + + public String poll_required() { + return POLLEN_URL.poll_required.toURL(this); + } + + public String poll_access_required() { + return POLLEN_URL.poll_access_required.toURL(this); + } + + public String poll_creator_required() { + return POLLEN_URL.poll_creator_required.toURL(this); + } + + public String voteforPoll(PollUri pollUri) { + return POLLEN_URL.voteforPoll.toURL(this, pollUri); + } + + public String createPoll() { + return POLLEN_URL.createPoll.toURL(this); + } + + public String editPoll(PollUri pollUri) { + return POLLEN_URL.editPoll.toURL(this, pollUri); + } + + public String summaryPoll(PollUri pollUri) { + return POLLEN_URL.summaryPoll.toURL(this,pollUri); + } + + public String summaryPoll() { + return POLLEN_URL.summaryPoll.toURL(this); + } + + public String logout() { + return POLLEN_URL.logout.toURL(this); + } +} Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/PollenUrlFixtures.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/WebDriverResources.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/WebDriverResources.java 2012-08-25 18:51:42 UTC (rev 3628) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/it/WebDriverResources.java 2012-08-26 11:19:25 UTC (rev 3629) @@ -35,7 +35,7 @@ if (safeDrivers == null) { List<Class<? extends WebDriver>> allDrivers = Lists.newArrayList(); - allDrivers.add(HtmlUnitDriver.class); +// allDrivers.add(HtmlUnitDriver.class); allDrivers.add(FirefoxDriver.class); // allDrivers.add(ChromeDriver.class); // allDrivers.add(InternetExplorerDriver.class); Copied: trunk/pollen-ui-struts2/src/test/resources/pollen-it.properties (from rev 3628, trunk/pollen-ui-struts2/src/it/pollen-ui-it/src/config/pollen-it.properties) =================================================================== --- trunk/pollen-ui-struts2/src/test/resources/pollen-it.properties (rev 0) +++ trunk/pollen-ui-struts2/src/test/resources/pollen-it.properties 2012-08-26 11:19:25 UTC (rev 3629) @@ -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% +### + +# répertoire des données (injecté via jvm) +pollen.dataDirectory=${pollenDataDirectory} + +# url de l'application +siteUrl=http://localhost:${pollenServerPort}/pollen + +# Db configuration +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.connection.username=sa +hibernate.connection.password=sa +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:file:${pollen.dataDirectory}/db/pollendb +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} + Property changes on: trunk/pollen-ui-struts2/src/test/resources/pollen-it.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native