Author: ymartel Date: 2012-06-13 14:54:52 +0200 (Wed, 13 Jun 2012) New Revision: 3465 Url: http://chorem.org/repositories/revision/pollen/3465 Log: refs #606 : make only one simple package for ITs Added: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java Removed: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/ Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/LoginSIT.java trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/SecurityAccessSIT.java Modified: trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties =================================================================== --- trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-13 12:32:09 UTC (rev 3464) +++ trunk/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-06-13 12:54:52 UTC (rev 3465) @@ -209,9 +209,9 @@ pollen.error.vote.maxChoiceNb=Le nombre de choix maximal est de %d. pollen.error.vote.percentage=La somme des valeurs doit être égale à 100. pollen.fieldset.choice.options=Les choix -pollen.fieldset.creator.options=Vous pollen.fieldset.choice.options.help=Configurer les choix du sondage pollen.fieldset.connexionInformation=Information de connexion +pollen.fieldset.creator.options=Vous pollen.fieldset.creator.options.help=Renseigner les informations sur le créateur du sondage pollen.fieldset.login=Connexion pollen.fieldset.notification.options=Notifications Deleted: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java 2012-06-13 12:32:09 UTC (rev 3464) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java 2012-06-13 12:54:52 UTC (rev 3465) @@ -1,140 +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.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; - -import java.util.Collection; -import java.util.List; - -/** - * Test base class for ui tests. - * - * @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 PollenFixtures fixtures ; - - protected WebDriver driver; - - @Before - public void setUp() throws Exception { - driver = seleniumServer.getDriver(); - fixtures = seleniumServer.getFixtures(); - } - - @AfterClass - public static void afterClass() { - WebDriverResource.afterClass(); - - } - - protected PollenBaseWebDriverIT(Class<? extends WebDriver> driverType) { - seleniumServer = new WebDriverResource(driverType); - } - - protected void gotoUrl(String url, boolean strict) { - gotoUrl(url, null, strict); - } - - protected void gotoUrl(String url) { - gotoUrl(url, null, true); - } - - protected void gotoUrl(String url, String fallBackUrl) { - gotoUrl(url, fallBackUrl, true); - } - - protected void gotoUrl(String url, String fallBackUrl, boolean strict) { - driver.get(url); - String expectedUrl; - if (fallBackUrl == null) { - expectedUrl = url; - } else { - expectedUrl = fallBackUrl; - } - - if (strict) { - Assert.assertEquals(expectedUrl, driver.getCurrentUrl()); - } else { - Assert.assertTrue(driver.getCurrentUrl().startsWith(expectedUrl)); - } - } - - protected WebElement findElement(By by) { - WebElement element = driver.findElement(by); - return element; - } - - protected List<WebElement> findElements(By by) { - List<WebElement> result = driver.findElements(by); - return result; - } - - /** Try to log in using the given {@code username} and {@code password}. */ - protected void connect(String username, String password) { - - // click on tologin element (display the login form) - WebElement loginClick = driver.findElement(By.id("tologin")); - loginClick.click(); - - // Find the text input element by its name - WebElement loginElement = driver.findElement(By.name("login")); - Assert.assertEquals("input", loginElement.getTagName()); - Assert.assertTrue(loginElement.isDisplayed()); - loginElement.sendKeys(username); - - WebElement passwordElement = driver.findElement(By.name("password")); - Assert.assertTrue(passwordElement.isDisplayed()); - Assert.assertEquals("input", passwordElement.getTagName()); - passwordElement.sendKeys(password); - - WebElement submit = driver.findElement(By.name("action:login")); - submit.click(); - } -} Deleted: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java 2012-06-13 12:32:09 UTC (rev 3464) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/WebDriverResource.java 2012-06-13 12:54:52 UTC (rev 3465) @@ -1,184 +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 com.google.common.collect.Lists; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeDriverService; -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 TestWatcher { - - /** Logger. */ - private static final Log log = LogFactory.getLog(WebDriverResource.class); - - private static ChromeDriverService service; - - protected static Collection<Object[]> safeDrivers; - - public static Collection<Object[]> driverTypes() { - if (safeDrivers == null) { - - List<Class<? extends WebDriver>> allDrivers = Lists.newArrayList(); - allDrivers.add(HtmlUnitDriver.class); - allDrivers.add(FirefoxDriver.class); -// allDrivers.add(ChromeDriver.class); -// allDrivers.add(InternetExplorerDriver.class); -// allDrivers.add(SafariDriver.class); - - List<Class<?>> checkedDrivers = new ArrayList<Class<?>>(); - for (Class<? extends WebDriver> driver : allDrivers) { - boolean ok = checkDriver(driver); - if (ok) { - checkedDrivers.add(driver); - } - } - 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) { - - boolean result = false; - try { - createDriver(driverType, true); - result = true; - } catch (Exception e) { - - // can not use this driver - if (log.isInfoEnabled()) { - log.info("Can not use driver " + driverType.getName(), e); - } - } - - return result; - } - - private final Class<? extends WebDriver> driverType; - - private final PollenFixtures fixtures; - - protected WebDriver driver; - - public WebDriverResource(Class<? extends WebDriver> driverType) { - this.driverType = driverType; - fixtures = new PollenFixtures(); - } - - public WebDriver getDriver() { - return driver; - } - - public PollenFixtures getFixtures() { - return fixtures; - } - - @Override - protected void starting(Description description) { - String testName = description.getClassName() + "#" + description.getMethodName() + " on [" + driverType.getName() + "]"; - - if (log.isInfoEnabled()) { - log.info("Start test " + testName); - } - - try { - driver = createDriver(driverType, false); - - } catch (Exception e) { - throw new IllegalStateException("Could not begin test " + testName); - } - } - - @Override - protected void finished(Description description) { - - // close current driver - driver.quit(); - } - - public static void afterClass() { - - if (service != null) { - service.stop(); - } - } - - protected static WebDriver createDriver(Class<? extends WebDriver> driverType, boolean clear) throws Exception { - WebDriver result; - - if (ChromeDriver.class == driverType) { - - service = new ChromeDriverService.Builder() - .usingChromeDriverExecutable(new File("/usr/bin/chromium-browser")) - .usingAnyFreePort() - .build(); - service.start(); - - result = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); - - } else { - result = driverType.getConstructor().newInstance(); - } - - if (clear) { - - if (result != null) { - result.close(); - } - - if (service != null) { - service.stop(); - } - - } - return result; - } -} Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/LoginSIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/LoginSIT.java 2012-06-13 12:32:09 UTC (rev 3464) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/LoginSIT.java 2012-06-13 12:54:52 UTC (rev 3465) @@ -21,9 +21,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -package org.chorem.pollen.ui.security; +package org.chorem.pollen.ui.its; -import org.chorem.pollen.ui.PollenBaseWebDriverIT; import org.junit.Assert; import org.junit.Test; import org.openqa.selenium.By; Copied: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java (from rev 3464, trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/PollenBaseWebDriverIT.java) =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java (rev 0) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java 2012-06-13 12:54:52 UTC (rev 3465) @@ -0,0 +1,295 @@ +/* + * #%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.its; + +import com.google.common.collect.Lists; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.ui.PollenFixtures; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; +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 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; + +/** + * Test base class for ui tests. + * + * @author tchemit <chemit@codelutin.com> + * @author ymartel <martel@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 PollenFixtures fixtures ; + + protected WebDriver driver; + + @Before + public void setUp() throws Exception { + driver = seleniumServer.getDriver(); + fixtures = seleniumServer.getFixtures(); + } + + @AfterClass + public static void afterClass() { + WebDriverResource.afterClass(); + + } + + protected PollenBaseWebDriverIT(Class<? extends WebDriver> driverType) { + seleniumServer = new WebDriverResource(driverType); + } + + protected void gotoUrl(String url, boolean strict) { + gotoUrl(url, null, strict); + } + + protected void gotoUrl(String url) { + gotoUrl(url, null, true); + } + + protected void gotoUrl(String url, String fallBackUrl) { + gotoUrl(url, fallBackUrl, true); + } + + protected void gotoUrl(String url, String fallBackUrl, boolean strict) { + driver.get(url); + String expectedUrl; + if (fallBackUrl == null) { + expectedUrl = url; + } else { + expectedUrl = fallBackUrl; + } + + if (strict) { + Assert.assertEquals(expectedUrl, driver.getCurrentUrl()); + } else { + Assert.assertTrue(driver.getCurrentUrl().startsWith(expectedUrl)); + } + } + + protected WebElement findElement(By by) { + WebElement element = driver.findElement(by); + return element; + } + + protected List<WebElement> findElements(By by) { + List<WebElement> result = driver.findElements(by); + return result; + } + + /** Try to log in using the given {@code username} and {@code password}. */ + protected void connect(String username, String password) { + + // click on tologin element (display the login form) + WebElement loginClick = driver.findElement(By.id("tologin")); + loginClick.click(); + + // Find the text input element by its name + WebElement loginElement = driver.findElement(By.name("login")); + Assert.assertEquals("input", loginElement.getTagName()); + Assert.assertTrue(loginElement.isDisplayed()); + loginElement.sendKeys(username); + + WebElement passwordElement = driver.findElement(By.name("password")); + Assert.assertTrue(passwordElement.isDisplayed()); + Assert.assertEquals("input", passwordElement.getTagName()); + passwordElement.sendKeys(password); + + WebElement submit = driver.findElement(By.name("action:login")); + submit.click(); + } + + /** + * Web driver resource. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.4 + */ + public static class WebDriverResource extends TestWatcher { + + /** Logger. */ + private static final Log log = LogFactory.getLog(WebDriverResource.class); + + private static ChromeDriverService service; + + protected static Collection<Object[]> safeDrivers; + + public static Collection<Object[]> driverTypes() { + if (safeDrivers == null) { + + List<Class<? extends WebDriver>> allDrivers = Lists.newArrayList(); + allDrivers.add(HtmlUnitDriver.class); + allDrivers.add(FirefoxDriver.class); + // allDrivers.add(ChromeDriver.class); + // allDrivers.add(InternetExplorerDriver.class); + // allDrivers.add(SafariDriver.class); + + List<Class<?>> checkedDrivers = new ArrayList<Class<?>>(); + for (Class<? extends WebDriver> driver : allDrivers) { + boolean ok = checkDriver(driver); + if (ok) { + checkedDrivers.add(driver); + } + } + 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) { + + boolean result = false; + try { + createDriver(driverType, true); + result = true; + } catch (Exception e) { + + // can not use this driver + if (log.isInfoEnabled()) { + log.info("Can not use driver " + driverType.getName(), e); + } + } + + return result; + } + + private final Class<? extends WebDriver> driverType; + + private final PollenFixtures fixtures; + + protected WebDriver driver; + + public WebDriverResource(Class<? extends WebDriver> driverType) { + this.driverType = driverType; + fixtures = new PollenFixtures(); + } + + public WebDriver getDriver() { + return driver; + } + + public PollenFixtures getFixtures() { + return fixtures; + } + + @Override + protected void starting(Description description) { + String testName = description.getClassName() + "#" + description.getMethodName() + " on [" + driverType.getName() + "]"; + + if (log.isInfoEnabled()) { + log.info("Start test " + testName); + } + + try { + driver = createDriver(driverType, false); + + } catch (Exception e) { + throw new IllegalStateException("Could not begin test " + testName); + } + } + + @Override + protected void finished(Description description) { + + // close current driver + driver.quit(); + } + + public static void afterClass() { + + if (service != null) { + service.stop(); + } + } + + protected static WebDriver createDriver(Class<? extends WebDriver> driverType, boolean clear) throws Exception { + WebDriver result; + + if (ChromeDriver.class == driverType) { + + service = new ChromeDriverService.Builder() + .usingChromeDriverExecutable(new File("/usr/bin/chromium-browser")) + .usingAnyFreePort() + .build(); + service.start(); + + result = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); + + } else { + result = driverType.getConstructor().newInstance(); + } + + if (clear) { + + if (result != null) { + result.close(); + } + + if (service != null) { + service.stop(); + } + + } + return result; + } + } +} Property changes on: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/PollenBaseWebDriverIT.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/SecurityAccessSIT.java =================================================================== --- trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/security/SecurityAccessSIT.java 2012-06-13 12:32:09 UTC (rev 3464) +++ trunk/pollen-ui-struts2/src/test/java/org/chorem/pollen/ui/its/SecurityAccessSIT.java 2012-06-13 12:54:52 UTC (rev 3465) @@ -20,10 +20,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ -package org.chorem.pollen.ui.security; +package org.chorem.pollen.ui.its; import org.chorem.pollen.bean.PollUri; -import org.chorem.pollen.ui.PollenBaseWebDriverIT; import org.junit.Test; import org.openqa.selenium.WebDriver;