diff --git a/gradle.properties b/gradle.properties index fb344226..353e0349 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,3 +28,4 @@ spockVersion=1.0-groovy-2.4 webjarsTaglibVersion=0.3 jstlVersion=1.2.1 groovyVersion=2.4.4 +lombokVersion=1.16.8 diff --git a/gradle/java.gradle b/gradle/java.gradle index 53910cec..2c620e7d 100644 --- a/gradle/java.gradle +++ b/gradle/java.gradle @@ -28,6 +28,11 @@ ext.gebDependencies = spockDependencies + [ "org.codehaus.groovy:groovy:$groovyVersion" ] +ext.seleniumDependencies = [ + "org.seleniumhq.selenium:selenium-htmlunit-driver:$seleniumVersion", + "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion" +] + ext.jstlDependencies = [ "javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:$jstlVersion", "org.apache.taglibs:taglibs-standard-jstlel:1.2.1" diff --git a/gradle/tomcat.gradle b/gradle/tomcat.gradle index 88f69325..bbc08612 100644 --- a/gradle/tomcat.gradle +++ b/gradle/tomcat.gradle @@ -45,9 +45,7 @@ task integrationTomcatStop(type: com.bmuschko.gradle.tomcat.tasks.TomcatStop) { integrationTest { dependsOn integrationTomcatRun doFirst { - def host = 'localhost:' + integrationTomcatRun.httpPort - systemProperties['geb.build.baseUrl'] = 'http://'+host+'/' + integrationTomcatRun.contextPath - systemProperties['geb.build.reportsDir'] = 'build/geb-reports' + systemProperties['tomcat.port'] = integrationTomcatRun.httpPort } finalizedBy integrationTomcatStop } diff --git a/samples/boot/build.gradle b/samples/boot/build.gradle index 630a3cd9..445e1ac6 100644 --- a/samples/boot/build.gradle +++ b/samples/boot/build.gradle @@ -29,8 +29,7 @@ dependencies { testCompile "org.springframework.boot:spring-boot-starter-test" - integrationTestCompile gebDependencies, - "org.spockframework:spock-spring:$spockVersion" + integrationTestCompile seleniumDependencies } @@ -38,9 +37,6 @@ integrationTest { doFirst { def port = reservePort() - def host = 'localhost:' + port - systemProperties['geb.build.baseUrl'] = 'http://'+host+'/' - systemProperties['geb.build.reportsDir'] = 'build/geb-reports' systemProperties['server.port'] = port systemProperties['management.port'] = 0 diff --git a/samples/boot/src/integration-test/groovy/sample/BootTests.groovy b/samples/boot/src/integration-test/groovy/sample/BootTests.groovy deleted file mode 100644 index f158edbd..00000000 --- a/samples/boot/src/integration-test/groovy/sample/BootTests.groovy +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.* -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.test.IntegrationTest -import org.springframework.boot.test.SpringApplicationConfiguration -import org.springframework.boot.test.SpringApplicationContextLoader -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.web.WebAppConfiguration -import sample.pages.HomePage -import sample.pages.LoginPage -import spock.lang.Stepwise -import pages.* - -/** - * Tests the demo that supports multiple sessions - * - * @author Rob Winch - */ -@Stepwise -@ContextConfiguration(classes = Application, loader = SpringApplicationContextLoader) -@WebAppConfiguration -@IntegrationTest -class BootTests extends GebReportingSpec { - - def 'Unauthenticated user sent to log in page'() { - when: 'unauthenticated user request protected page' - via HomePage - then: 'sent to the log in page' - at LoginPage - } - - def 'Log in views home page'() { - when: 'log in successfully' - login() - then: 'sent to original page' - at HomePage - and: 'the username is displayed' - username == 'user' - and: 'Spring Session Management is being used' - driver.manage().cookies.find { it.name == 'SESSION' } - and: 'Standard Session is NOT being used' - !driver.manage().cookies.find { it.name == 'JSESSIONID' } - } - - def 'Log out success'() { - when: - logout() - then: - at LoginPage - } - - def 'Logged out user sent to log in page'() { - when: 'logged out user request protected page' - via HomePage - then: 'sent to the log in page' - at LoginPage - } -} diff --git a/samples/boot/src/integration-test/java/sample/BootTests.java b/samples/boot/src/integration-test/java/sample/BootTests.java new file mode 100644 index 00000000..c348db82 --- /dev/null +++ b/samples/boot/src/integration-test/java/sample/BootTests.java @@ -0,0 +1,83 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; +import sample.pages.HomePage; +import sample.pages.LoginPage; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder; + +/** + * @author Eddú Meléndez + */ +@RunWith(SpringRunner.class) +@AutoConfigureMockMvc +@SpringBootTest(webEnvironment = WebEnvironment.MOCK) +public class BootTests { + + @Autowired + private MockMvc mockMvc; + + private WebDriver driver; + + @Before + public void setup() { + this.driver = MockMvcHtmlUnitDriverBuilder + .mockMvcSetup(this.mockMvc) + .build(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void home() { + LoginPage login = HomePage.go(this.driver); + login.assertAt(); + } + + @Test + public void login() { + LoginPage login = HomePage.go(this.driver); + HomePage home = login.login(); + home.assertAt(); + home.containCookie("SESSION"); + home.doesNotContainCookie("JSESSIONID"); + } + + @Test + public void logout() { + LoginPage login = HomePage.go(this.driver); + HomePage home = login.login(); + home.logout(); + login.assertAt(); + } + +} diff --git a/samples/httpsession-jdbc-boot/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/boot/src/integration-test/java/sample/pages/BasePage.java similarity index 56% rename from samples/httpsession-jdbc-boot/src/integration-test/groovy/sample/pages/HomePage.groovy rename to samples/boot/src/integration-test/java/sample/pages/BasePage.java index ae2c3e94..763c0787 100644 --- a/samples/httpsession-jdbc-boot/src/integration-test/groovy/sample/pages/HomePage.groovy +++ b/samples/boot/src/integration-test/java/sample/pages/BasePage.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,28 @@ * limitations under the License. */ -package sample.pages +package sample.pages; -import geb.* +import org.openqa.selenium.WebDriver; /** - * The home page - * - * @author Rob Winch + * @author Eddú Meléndez */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Spring Session Sample - Secured Content'; true} - static content = { - username { $('#un').text() } - logout(to:LoginPage) { $('input[type=submit]').click() } +public class BasePage { + + private WebDriver driver; + + public BasePage(WebDriver driver) { + this.driver = driver; } + + public WebDriver getDriver() { + return this.driver; + } + + public static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost"; + driver.get(baseUrl + get); + } + } diff --git a/samples/boot/src/integration-test/java/sample/pages/HomePage.java b/samples/boot/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..a751fd2f --- /dev/null +++ b/samples/boot/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,63 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.Set; + +import org.openqa.selenium.By; +import org.openqa.selenium.Cookie; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class HomePage extends BasePage { + + public HomePage(WebDriver driver) { + super(driver); + } + + public static LoginPage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, LoginPage.class); + } + + public void assertAt() { + assertThat(getDriver().getTitle()).isEqualTo("Spring Session Sample - Secured Content"); + } + + public void containCookie(String cookieName) { + Set cookies = getDriver().manage().getCookies(); + assertThat(cookies).extracting("name").contains(cookieName); + } + + public void doesNotContainCookie(String cookieName) { + Set cookies = getDriver().manage().getCookies(); + assertThat(cookies).extracting("name").doesNotContain(cookieName); + } + + public HomePage logout() { + WebElement logout = getDriver().findElement(By.cssSelector("input[type=\"submit\"]")); + logout.click(); + return PageFactory.initElements(getDriver(), HomePage.class); + } + +} diff --git a/samples/boot/src/integration-test/java/sample/pages/LoginPage.java b/samples/boot/src/integration-test/java/sample/pages/LoginPage.java new file mode 100644 index 00000000..f4be4d45 --- /dev/null +++ b/samples/boot/src/integration-test/java/sample/pages/LoginPage.java @@ -0,0 +1,54 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class LoginPage extends BasePage { + + @FindBy(name = "username") + private WebElement username; + + @FindBy(name = "password") + private WebElement password; + + @FindBy(name = "submit") + private WebElement button; + + public LoginPage(WebDriver driver) { + super(driver); + } + + public void assertAt() { + assertThat(getDriver().getTitle()).isEqualTo("Login Page"); + } + + public HomePage login() { + this.username.sendKeys("user"); + this.password.sendKeys("password"); + this.button.click(); + return PageFactory.initElements(getDriver(), HomePage.class); + } +} diff --git a/samples/custom-cookie/build.gradle b/samples/custom-cookie/build.gradle index 7edb6f84..41b0360a 100644 --- a/samples/custom-cookie/build.gradle +++ b/samples/custom-cookie/build.gradle @@ -14,7 +14,9 @@ dependencies { providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion" - testCompile "junit:junit:$junitVersion" + testCompile "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies } diff --git a/samples/custom-cookie/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/custom-cookie/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index c865fc43..00000000 --- a/samples/custom-cookie/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.* -import sample.pages.HomePage; -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - */ -@Stepwise -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 1 - attributes[0].name == 'a' - attributes[0].value == 'b' - } -} diff --git a/samples/custom-cookie/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/custom-cookie/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index 25215292..00000000 --- a/samples/custom-cookie/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/custom-cookie/src/integration-test/java/sample/AttributeTests.java b/samples/custom-cookie/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..191ab84e --- /dev/null +++ b/samples/custom-cookie/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,66 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class AttributeTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void home() { + HomePage home = HomePage.go(this.driver); + home.assertAt(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(1); + assertThat(home.row(0).getAttributeName()).isEqualTo("a"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/custom-cookie/src/integration-test/java/sample/pages/HomePage.java b/samples/custom-cookie/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..00e29651 --- /dev/null +++ b/samples/custom-cookie/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,108 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void assertAt() { + assertThat(this.driver.getTitle()).isEqualTo("Session Attributes"); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/findbyusername/build.gradle b/samples/findbyusername/build.gradle index 8f746c5d..80d4ad5c 100644 --- a/samples/findbyusername/build.gradle +++ b/samples/findbyusername/build.gradle @@ -30,10 +30,10 @@ dependencies { "org.apache.httpcomponents:httpclient" testCompile "org.springframework.boot:spring-boot-starter-test", - "org.assertj:assertj-core:$assertjVersion" + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" - integrationTestCompile gebDependencies, - "org.spockframework:spock-spring:$spockVersion" + integrationTestCompile seleniumDependencies } @@ -41,9 +41,6 @@ integrationTest { doFirst { def port = reservePort() - def host = 'localhost:' + port - systemProperties['geb.build.baseUrl'] = 'http://'+host+'/' - systemProperties['geb.build.reportsDir'] = 'build/geb-reports' systemProperties['server.port'] = port systemProperties['management.port'] = 0 diff --git a/samples/findbyusername/src/integration-test/groovy/sample/FindByUsernameTests.groovy b/samples/findbyusername/src/integration-test/groovy/sample/FindByUsernameTests.groovy deleted file mode 100644 index 21228034..00000000 --- a/samples/findbyusername/src/integration-test/groovy/sample/FindByUsernameTests.groovy +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.Browser -import geb.spock.* - -import org.openqa.selenium.htmlunit.HtmlUnitDriver -import org.springframework.boot.test.IntegrationTest -import org.springframework.boot.test.SpringApplicationContextLoader -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.web.WebAppConfiguration - -import pages.* -import sample.pages.HomePage -import sample.pages.LoginPage -import spock.lang.Stepwise - -/** - * Tests findbyusername web application - * - * @author Rob Winch - */ -@Stepwise -@ContextConfiguration(classes = FindByUsernameApplication, loader = SpringApplicationContextLoader) -@WebAppConfiguration -@IntegrationTest -class FindByUsernameTests extends MultiBrowserGebSpec { - def 'Unauthenticated user sent to log in page'() { - given: 'unauthenticated user request protected page' - withBrowserSession a, { - via HomePage - then: 'sent to the log in page' - at LoginPage - } - } - - def 'Log in views home page'() { - when: 'log in successfully' - a.login() - then: 'sent to original page' - a.at HomePage - and: 'the username is displayed' - a.username == 'user' - and: 'Spring Session Management is being used' - a.driver.manage().cookies.find { it.name == 'SESSION' } - and: 'Standard Session is NOT being used' - !a.driver.manage().cookies.find { it.name == 'JSESSIONID' } - and: 'Session id exists and terminate disabled' - a.sessionId - a.terminate(a.sessionId).@disabled - } - - def 'Other Browser: Unauthenticated user sent to log in page'() { - given: - withBrowserSession b, { - via HomePage - then: 'sent to the log in page' - at LoginPage - } - } - - def 'Other Browser: Log in views home page'() { - when: 'log in successfully' - b.login() - then: 'sent to original page' - b.at HomePage - and: 'the username is displayed' - b.username == 'user' - and: 'Spring Session Management is being used' - b.driver.manage().cookies.find { it.name == 'SESSION' } - and: 'Standard Session is NOT being used' - !b.driver.manage().cookies.find { it.name == 'JSESSIONID' } - and: 'Session id exists and terminate disabled' - b.sessionId - b.terminate(b.sessionId).@disabled - } - - def 'Other Browser: Terminate Original'() { - setup: 'get the session id from browser a' - def sessionId = a.sessionId - when: 'we terminate browser a session' - b.terminate(sessionId).click(HomePage) - then: 'session is not listed' - !b.terminate(sessionId) - when: 'browser a visits home page after session was terminated' - a.via HomePage - then: 'browser a sent to log in' - a.at LoginPage - } -} diff --git a/samples/findbyusername/src/integration-test/groovy/sample/MultiBrowserGebSpec.groovy b/samples/findbyusername/src/integration-test/groovy/sample/MultiBrowserGebSpec.groovy deleted file mode 100644 index 6f38c197..00000000 --- a/samples/findbyusername/src/integration-test/groovy/sample/MultiBrowserGebSpec.groovy +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample; -import geb.* -import spock.lang.* - -/** - * https://github.com/kensiprell/geb-multibrowser - */ -abstract class MultiBrowserGebSpec extends Specification { - String gebConfEnv = null - String gebConfScript = null - - // Map of geb browsers which can be referenced by name in the spec - // THese currently share the same config. This is not a problem for - // my uses, but I can see potential for wanting to configure different - // browsers separately - @Shared _browsers = createBrowserMap() - def currentBrowser - - def createBrowserMap() { - [:].withDefault { new Browser(createConf()) } - } - - Configuration createConf() { - // Use the standard configured geb driver, but turn off cacheing so - // we can run multiple - def conf = new ConfigurationLoader(gebConfEnv).getConf(gebConfScript) - conf.cacheDriver = false - return conf - } - - def withBrowserSession(browser, Closure c) { - currentBrowser = browser - def returnedValue = c.call() - currentBrowser = null - returnedValue - } - - void resetBrowsers() { - _browsers.each { k, browser -> - if (browser.config?.autoClearCookies) { - browser.clearCookiesQuietly() - } - browser.quit() - } - _browsers = createBrowserMap() - } - - def propertyMissing(String name) { - if(currentBrowser) { - return currentBrowser."$name" - } else { - return _browsers[name] - } - } - - def methodMissing(String name, args) { - if(currentBrowser) { - return currentBrowser."$name"(*args) - } else { - def browser = _browsers[name] - if(args) { - return browser."${args[0]}"(*(args[1..-1])) - } else { - return browser - } - } - } - - def propertyMissing(String name, value) { - if(!currentBrowser) throw new IllegalArgumentException("No context for setting property $name") - currentBrowser."$name" = value - } - - private isSpecStepwise() { - this.class.getAnnotation(Stepwise) != null - } - - def cleanup() { - if (!isSpecStepwise()) resetBrowsers() - } - - def cleanupSpec() { - if (isSpecStepwise()) resetBrowsers() - } -} diff --git a/samples/findbyusername/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/findbyusername/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index a9d002df..00000000 --- a/samples/findbyusername/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Spring Session Sample - Secured Content'; true} - static content = { - username { $('#un').text() } - logout(to:LoginPage) { $('input[type=submit]').click() } - sessions { moduleList AttributeRow, $("table tr").tail() } - terminate(required:false) { sessionId -> $("#terminate-$sessionId") } - sessionId { $("#session-id").text() } - } -} - -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - location { cell(0).text() } - created { cell(1).text() } - lastUpdated { cell(2).text() } - information { cell(3).text() } - terminate { cell(4).text() } - } -} diff --git a/samples/findbyusername/src/integration-test/java/sample/FindByUsernameTests.java b/samples/findbyusername/src/integration-test/java/sample/FindByUsernameTests.java new file mode 100644 index 00000000..cdf6de4c --- /dev/null +++ b/samples/findbyusername/src/integration-test/java/sample/FindByUsernameTests.java @@ -0,0 +1,76 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; +import sample.pages.HomePage; +import sample.pages.LoginPage; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder; + +/** + * @author Eddú Meléndez + */ +@RunWith(SpringRunner.class) +@AutoConfigureMockMvc +@SpringBootTest(webEnvironment = WebEnvironment.MOCK) +public class FindByUsernameTests { + + @Autowired + private MockMvc mockMvc; + + private WebDriver driver; + + @Before + public void setup() { + this.driver = MockMvcHtmlUnitDriverBuilder + .mockMvcSetup(this.mockMvc) + .build(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void home() { + LoginPage login = HomePage.go(this.driver); + login.assertAt(); + } + + @Test + public void login() { + LoginPage login = HomePage.go(this.driver); + HomePage home = login.login(); + home.assertAt(); + home.containCookie("SESSION"); + home.doesNotContainCookie("JSESSIONID"); + home.terminateButtonDisabled(); + } + +} diff --git a/samples/boot/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/findbyusername/src/integration-test/java/sample/pages/BasePage.java similarity index 56% rename from samples/boot/src/integration-test/groovy/sample/pages/HomePage.groovy rename to samples/findbyusername/src/integration-test/java/sample/pages/BasePage.java index ae2c3e94..763c0787 100644 --- a/samples/boot/src/integration-test/groovy/sample/pages/HomePage.groovy +++ b/samples/findbyusername/src/integration-test/java/sample/pages/BasePage.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,28 @@ * limitations under the License. */ -package sample.pages +package sample.pages; -import geb.* +import org.openqa.selenium.WebDriver; /** - * The home page - * - * @author Rob Winch + * @author Eddú Meléndez */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Spring Session Sample - Secured Content'; true} - static content = { - username { $('#un').text() } - logout(to:LoginPage) { $('input[type=submit]').click() } +public class BasePage { + + private WebDriver driver; + + public BasePage(WebDriver driver) { + this.driver = driver; } + + public WebDriver getDriver() { + return this.driver; + } + + public static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost"; + driver.get(baseUrl + get); + } + } diff --git a/samples/findbyusername/src/integration-test/java/sample/pages/HomePage.java b/samples/findbyusername/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..e7487e29 --- /dev/null +++ b/samples/findbyusername/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,75 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.Set; + +import org.openqa.selenium.By; +import org.openqa.selenium.Cookie; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class HomePage extends BasePage { + + public HomePage(WebDriver driver) { + super(driver); + } + + public static LoginPage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, LoginPage.class); + } + + public void assertAt() { + assertThat(getDriver().getTitle()).isEqualTo("Spring Session Sample - Secured Content"); + } + + public void containCookie(String cookieName) { + Set cookies = getDriver().manage().getCookies(); + assertThat(cookies).extracting("name").contains(cookieName); + } + + public void doesNotContainCookie(String cookieName) { + Set cookies = getDriver().manage().getCookies(); + assertThat(cookies).extracting("name").doesNotContain(cookieName); + } + + public void terminateButtonDisabled() { + Set cookies = getDriver().manage().getCookies(); + String cookieValue = null; + for (Cookie cookie : cookies) { + if ("SESSION".equals(cookie.getName())) { + cookieValue = cookie.getValue(); + } + } + WebElement element = getDriver().findElement(By.id("terminate-" + cookieValue)); + assertThat(element.isEnabled()).isFalse(); + } + + public HomePage logout() { + WebElement logout = getDriver().findElement(By.cssSelector("input[type=\"submit\"]")); + logout.click(); + return PageFactory.initElements(getDriver(), HomePage.class); + } + +} diff --git a/samples/findbyusername/src/integration-test/java/sample/pages/LoginPage.java b/samples/findbyusername/src/integration-test/java/sample/pages/LoginPage.java new file mode 100644 index 00000000..9c5388d0 --- /dev/null +++ b/samples/findbyusername/src/integration-test/java/sample/pages/LoginPage.java @@ -0,0 +1,55 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class LoginPage extends BasePage { + + @FindBy(name = "username") + private WebElement username; + + @FindBy(name = "password") + private WebElement password; + + @FindBy(tagName = "button") + private WebElement button; + + public LoginPage(WebDriver driver) { + super(driver); + } + + public void assertAt() { + assertThat(getDriver().getTitle()).isEqualTo("Spring Session Sample - Log In"); + } + + public HomePage login() { + this.username.sendKeys("user"); + this.password.sendKeys("password"); + this.button.click(); + return PageFactory.initElements(getDriver(), HomePage.class); + } + +} diff --git a/samples/findbyusername/src/main/java/sample/FindByUsernameApplication.java b/samples/findbyusername/src/main/java/sample/FindByUsernameApplication.java index 0bca487f..6bd12819 100644 --- a/samples/findbyusername/src/main/java/sample/FindByUsernameApplication.java +++ b/samples/findbyusername/src/main/java/sample/FindByUsernameApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,16 +17,12 @@ package sample; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; /** * @author Rob Winch */ -@Configuration -@ComponentScan -@EnableAutoConfiguration +@SpringBootApplication public class FindByUsernameApplication { public static void main(String[] args) { diff --git a/samples/grails3/build.gradle b/samples/grails3/build.gradle index 2f2d54f5..b652e80d 100644 --- a/samples/grails3/build.gradle +++ b/samples/grails3/build.gradle @@ -55,8 +55,9 @@ dependencies { runtime "com.h2database:h2" testCompile "org.grails:grails-plugin-testing" testCompile "org.grails.plugins:geb" - testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1" - testRuntime "net.sourceforge.htmlunit:htmlunit:2.18" + testCompile "org.assertj:assertj-core:$assertjVersion" + testCompile "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1" + testCompile "net.sourceforge.htmlunit:htmlunit:2.18" compile "org.springframework.boot:spring-boot-starter-redis" compile 'org.springframework.session:spring-session:1.1.1.RELEASE' diff --git a/samples/hazelcast-spring/build.gradle b/samples/hazelcast-spring/build.gradle index e4d0c6de..bf0d2a80 100644 --- a/samples/hazelcast-spring/build.gradle +++ b/samples/hazelcast-spring/build.gradle @@ -15,7 +15,8 @@ dependencies { providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion", "javax.servlet:jsp-api:$jspApiVersion" - testCompile "junit:junit:$junitVersion" + testCompile "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies } diff --git a/samples/hazelcast-spring/src/integration-test/groovy/sample/HazelcastSpringTests.groovy b/samples/hazelcast-spring/src/integration-test/groovy/sample/HazelcastSpringTests.groovy deleted file mode 100644 index df2c1cab..00000000 --- a/samples/hazelcast-spring/src/integration-test/groovy/sample/HazelcastSpringTests.groovy +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.GebReportingSpec -import pages.* -import sample.pages.HomePage -import sample.pages.LoginPage -import spock.lang.Stepwise - -/** - * Ensures that Spring Security and Session are working - * - * @author Rob Winch - */ -@Stepwise -class HazelcastSpringTests extends GebReportingSpec { - - def 'Unauthenticated user sent to log in page'() { - when: 'unauthenticated user request protected page' - via HomePage - then: 'sent to the log in page' - at LoginPage - } - - def 'Log in views home page'() { - when: 'log in successfully' - login() - then: 'sent to original page' - at HomePage - and: 'the username is displayed' - username == 'user' - and: 'Spring Session Management is being used' - driver.manage().cookies.find { it.name == 'SESSION' } - and: 'Standard Session is NOT being used' - !driver.manage().cookies.find { it.name == 'JSESSIONID' } - } - - def 'Log out success'() { - when: - logout() - then: - at LoginPage - } - - def 'Logged out user sent to log in page'() { - when: 'logged out user request protected page' - via HomePage - then: 'sent to the log in page' - at LoginPage - } -} diff --git a/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/LoginPage.groovy b/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/LoginPage.groovy deleted file mode 100644 index d8a5beaf..00000000 --- a/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/LoginPage.groovy +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.Page - -/** - * The Links Page - * - * @author Rob Winch - */ -class LoginPage extends Page { - static url = '/login' - static at = { assert driver.title == 'Login Page'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - login(required:false) { user='user', pass='password' -> - form.username = user - form.password = pass - submit.click(HomePage) - } - } -} diff --git a/samples/hazelcast-spring/src/integration-test/java/sample/HazelcastSpringTests.java b/samples/hazelcast-spring/src/integration-test/java/sample/HazelcastSpringTests.java new file mode 100644 index 00000000..44470337 --- /dev/null +++ b/samples/hazelcast-spring/src/integration-test/java/sample/HazelcastSpringTests.java @@ -0,0 +1,59 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; +import sample.pages.LoginPage; + +/** + * @author Eddú Meléndez + */ +public class HazelcastSpringTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void goHomeRedirectLoginPage() { + LoginPage login = HomePage.go(this.driver); + login.assertAt(); + } + + @Test + public void login() { + LoginPage login = HomePage.go(this.driver); + login.assertAt(); + HomePage home = login.login(); + home.containCookie("SESSION"); + home.doesNotContainCookie("JSESSIONID"); + } + +} diff --git a/samples/findbyusername/src/integration-test/groovy/sample/pages/LoginPage.groovy b/samples/hazelcast-spring/src/integration-test/java/sample/pages/BasePage.java similarity index 54% rename from samples/findbyusername/src/integration-test/groovy/sample/pages/LoginPage.groovy rename to samples/hazelcast-spring/src/integration-test/java/sample/pages/BasePage.java index b93ad5f9..a486c3d0 100644 --- a/samples/findbyusername/src/integration-test/groovy/sample/pages/LoginPage.groovy +++ b/samples/hazelcast-spring/src/integration-test/java/sample/pages/BasePage.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,28 @@ * limitations under the License. */ -package sample.pages +package sample.pages; -import geb.* +import org.openqa.selenium.WebDriver; /** - * The Links Page - * - * @author Rob Winch + * @author Eddú Meléndez */ -class LoginPage extends Page { - static url = '/login' - static at = { assert driver.title == 'Spring Session Sample - Log In'; true} - static content = { - form { $('form') } - submit { $('button[type=submit]') } - login(required:false) { user='user', pass='password' -> - form.username = user - form.password = pass - submit.click(HomePage) - } +public class BasePage { + + private WebDriver driver; + + public BasePage(WebDriver driver) { + this.driver = driver; } + + public WebDriver getDriver() { + return this.driver; + } + + public static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + } diff --git a/samples/hazelcast-spring/src/integration-test/java/sample/pages/HomePage.java b/samples/hazelcast-spring/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..61b36942 --- /dev/null +++ b/samples/hazelcast-spring/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,55 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.Set; + +import org.openqa.selenium.Cookie; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class HomePage extends BasePage { + + public HomePage(WebDriver driver) { + super(driver); + } + + public static LoginPage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, LoginPage.class); + } + + public void assertAt() { + assertThat(getDriver().getTitle()).isEqualTo("Secured Content"); + } + + public void containCookie(String cookieName) { + Set cookies = getDriver().manage().getCookies(); + assertThat(cookies).extracting("name").contains(cookieName); + } + + public void doesNotContainCookie(String cookieName) { + Set cookies = getDriver().manage().getCookies(); + assertThat(cookies).extracting("name").doesNotContain(cookieName); + } + +} diff --git a/samples/hazelcast-spring/src/integration-test/java/sample/pages/LoginPage.java b/samples/hazelcast-spring/src/integration-test/java/sample/pages/LoginPage.java new file mode 100644 index 00000000..ab67fcad --- /dev/null +++ b/samples/hazelcast-spring/src/integration-test/java/sample/pages/LoginPage.java @@ -0,0 +1,55 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class LoginPage extends BasePage { + + @FindBy(name = "username") + private WebElement username; + + @FindBy(name = "password") + private WebElement password; + + @FindBy(name = "submit") + private WebElement button; + + public LoginPage(WebDriver driver) { + super(driver); + } + + public void assertAt() { + assertThat(getDriver().getTitle()).isEqualTo("Login Page"); + } + + public HomePage login() { + this.username.sendKeys("user"); + this.password.sendKeys("password"); + this.button.click(); + return PageFactory.initElements(getDriver(), HomePage.class); + } + +} diff --git a/samples/hazelcast/build.gradle b/samples/hazelcast/build.gradle index 9ad15362..3d1a8955 100644 --- a/samples/hazelcast/build.gradle +++ b/samples/hazelcast/build.gradle @@ -11,7 +11,9 @@ dependencies { providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion" - testCompile "junit:junit:$junitVersion" + testCompile "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies } diff --git a/samples/hazelcast/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/hazelcast/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index c865fc43..00000000 --- a/samples/hazelcast/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.* -import sample.pages.HomePage; -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - */ -@Stepwise -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 1 - attributes[0].name == 'a' - attributes[0].value == 'b' - } -} diff --git a/samples/hazelcast/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/hazelcast/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index 25215292..00000000 --- a/samples/hazelcast/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/hazelcast/src/integration-test/java/sample/AttributeTests.java b/samples/hazelcast/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..191ab84e --- /dev/null +++ b/samples/hazelcast/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,66 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class AttributeTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void home() { + HomePage home = HomePage.go(this.driver); + home.assertAt(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(1); + assertThat(home.row(0).getAttributeName()).isEqualTo("a"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/hazelcast/src/integration-test/java/sample/pages/HomePage.java b/samples/hazelcast/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..00e29651 --- /dev/null +++ b/samples/hazelcast/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,108 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void assertAt() { + assertThat(this.driver.getTitle()).isEqualTo("Session Attributes"); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/httpsession-gemfire-boot/build.gradle b/samples/httpsession-gemfire-boot/build.gradle index 620b4e12..06d1ddb6 100644 --- a/samples/httpsession-gemfire-boot/build.gradle +++ b/samples/httpsession-gemfire-boot/build.gradle @@ -29,8 +29,8 @@ dependencies { testCompile "org.springframework.boot:spring-boot-starter-test" - integrationTestCompile gebDependencies, - "org.spockframework:spock-spring:$spockVersion" + integrationTestCompile seleniumDependencies, + "org.projectlombok:lombok:$lombokVersion" integrationTestRuntime "org.springframework.shell:spring-shell:1.0.0.RELEASE" } @@ -70,11 +70,8 @@ integrationTest { dependsOn runGemFireServer doFirst { def port = reservePort() - def host = 'localhost:' + port systemProperties['server.port'] = port systemProperties['management.port'] = 0 - systemProperties['geb.build.baseUrl'] = 'http://'+host+'/' - systemProperties['geb.build.reportsDir'] = 'build/geb-reports' systemProperties['gemfire.cache.server.port'] = runGemFireServer.port } doLast { diff --git a/samples/httpsession-gemfire-boot/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/httpsession-gemfire-boot/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index 0abc6ea3..00000000 --- a/samples/httpsession-gemfire-boot/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2002-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.GebReportingSpec -import org.springframework.boot.test.IntegrationTest -import org.springframework.boot.test.SpringApplicationContextLoader -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.web.WebAppConfiguration -import sample.client.Application -import sample.pages.HomePage -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - * @author John Blum - */ -@Stepwise -@IntegrationTest -@WebAppConfiguration -@ContextConfiguration(classes = Application, loader = SpringApplicationContextLoader) -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 2 - attributes[0..1]*.name == ['requestCount', 'a'] - attributes.find { it.name == 'requestCount' }?.value == '1' - attributes.find { it.name == 'a' }?.value == 'b' - } -} diff --git a/samples/httpsession-gemfire-boot/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/httpsession-gemfire-boot/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index 1d288aaa..00000000 --- a/samples/httpsession-gemfire-boot/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2002-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - * @author John Blum - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true } - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - // attributes { $("table tr").tail().moduleList(AttributeRow) } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/httpsession-gemfire-boot/src/integration-test/java/sample/AttributeTests.java b/samples/httpsession-gemfire-boot/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..e89e2ba0 --- /dev/null +++ b/samples/httpsession-gemfire-boot/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,82 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; +import sample.client.Application; +import sample.pages.HomePage; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootContextLoader; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.MOCK) +@AutoConfigureMockMvc +@ContextConfiguration(classes = Application.class, loader = SpringBootContextLoader.class) +public class AttributeTests { + + @Autowired + private MockMvc mockMvc; + + private WebDriver driver; + + @Before + public void setup() { + this.driver = MockMvcHtmlUnitDriverBuilder + .mockMvcSetup(this.mockMvc) + .build(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(2); + assertThat(home.row(0).getAttributeName()).isEqualTo("requestCount"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("1"); + assertThat(home.row(1).getAttributeName()).isEqualTo("a"); + assertThat(home.row(1).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/httpsession-gemfire-boot/src/integration-test/java/sample/pages/HomePage.java b/samples/httpsession-gemfire-boot/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..8d3442f4 --- /dev/null +++ b/samples/httpsession-gemfire-boot/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,102 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost"; + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/httpsession-gemfire-clientserver-xml/build.gradle b/samples/httpsession-gemfire-clientserver-xml/build.gradle index a4fd6ac8..38b07825 100644 --- a/samples/httpsession-gemfire-clientserver-xml/build.gradle +++ b/samples/httpsession-gemfire-clientserver-xml/build.gradle @@ -19,9 +19,11 @@ dependencies { runtime "org.springframework.shell:spring-shell:1.0.0.RELEASE" - testCompile "junit:junit:$junitVersion" + testCompile "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies integrationTestRuntime "org.springframework.shell:spring-shell:1.0.0.RELEASE" } diff --git a/samples/httpsession-gemfire-clientserver-xml/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/httpsession-gemfire-clientserver-xml/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index c865fc43..00000000 --- a/samples/httpsession-gemfire-clientserver-xml/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.* -import sample.pages.HomePage; -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - */ -@Stepwise -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 1 - attributes[0].name == 'a' - attributes[0].value == 'b' - } -} diff --git a/samples/httpsession-gemfire-clientserver-xml/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/httpsession-gemfire-clientserver-xml/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index 25215292..00000000 --- a/samples/httpsession-gemfire-clientserver-xml/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/httpsession-gemfire-clientserver-xml/src/integration-test/java/sample/AttributeTests.java b/samples/httpsession-gemfire-clientserver-xml/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..6628f7a3 --- /dev/null +++ b/samples/httpsession-gemfire-clientserver-xml/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class AttributeTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(1); + assertThat(home.row(0).getAttributeName()).isEqualTo("a"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/httpsession-gemfire-clientserver-xml/src/integration-test/java/sample/pages/HomePage.java b/samples/httpsession-gemfire-clientserver-xml/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..dbb01fed --- /dev/null +++ b/samples/httpsession-gemfire-clientserver-xml/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,102 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/httpsession-gemfire-clientserver/build.gradle b/samples/httpsession-gemfire-clientserver/build.gradle index 5b51a3dd..ed125ba3 100644 --- a/samples/httpsession-gemfire-clientserver/build.gradle +++ b/samples/httpsession-gemfire-clientserver/build.gradle @@ -14,9 +14,11 @@ dependencies { runtime "org.springframework.shell:spring-shell:1.0.0.RELEASE" - testCompile "junit:junit:$junitVersion" + testCompile "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies integrationTestRuntime "org.springframework.shell:spring-shell:1.0.0.RELEASE" } diff --git a/samples/httpsession-gemfire-clientserver/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/httpsession-gemfire-clientserver/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index c865fc43..00000000 --- a/samples/httpsession-gemfire-clientserver/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.* -import sample.pages.HomePage; -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - */ -@Stepwise -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 1 - attributes[0].name == 'a' - attributes[0].value == 'b' - } -} diff --git a/samples/httpsession-gemfire-clientserver/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/httpsession-gemfire-clientserver/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index 25215292..00000000 --- a/samples/httpsession-gemfire-clientserver/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/httpsession-gemfire-clientserver/src/integration-test/java/sample/AttributeTests.java b/samples/httpsession-gemfire-clientserver/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..6628f7a3 --- /dev/null +++ b/samples/httpsession-gemfire-clientserver/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class AttributeTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(1); + assertThat(home.row(0).getAttributeName()).isEqualTo("a"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/httpsession-gemfire-clientserver/src/integration-test/java/sample/pages/HomePage.java b/samples/httpsession-gemfire-clientserver/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..dbb01fed --- /dev/null +++ b/samples/httpsession-gemfire-clientserver/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,102 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/httpsession-gemfire-p2p-xml/build.gradle b/samples/httpsession-gemfire-p2p-xml/build.gradle index e53487d0..3278a77e 100644 --- a/samples/httpsession-gemfire-p2p-xml/build.gradle +++ b/samples/httpsession-gemfire-p2p-xml/build.gradle @@ -13,7 +13,9 @@ dependencies { testCompile "junit:junit:$junitVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies, + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" integrationTestRuntime "org.springframework.shell:spring-shell:1.0.0.RELEASE" } diff --git a/samples/httpsession-gemfire-p2p-xml/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/httpsession-gemfire-p2p-xml/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index c865fc43..00000000 --- a/samples/httpsession-gemfire-p2p-xml/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.* -import sample.pages.HomePage; -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - */ -@Stepwise -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 1 - attributes[0].name == 'a' - attributes[0].value == 'b' - } -} diff --git a/samples/httpsession-gemfire-p2p-xml/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/httpsession-gemfire-p2p-xml/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index 25215292..00000000 --- a/samples/httpsession-gemfire-p2p-xml/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/httpsession-gemfire-p2p-xml/src/integration-test/java/sample/AttributeTests.java b/samples/httpsession-gemfire-p2p-xml/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..6628f7a3 --- /dev/null +++ b/samples/httpsession-gemfire-p2p-xml/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class AttributeTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(1); + assertThat(home.row(0).getAttributeName()).isEqualTo("a"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/httpsession-gemfire-p2p-xml/src/integration-test/java/sample/pages/HomePage.java b/samples/httpsession-gemfire-p2p-xml/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..dbb01fed --- /dev/null +++ b/samples/httpsession-gemfire-p2p-xml/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,102 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/httpsession-gemfire-p2p/build.gradle b/samples/httpsession-gemfire-p2p/build.gradle index e53487d0..3278a77e 100644 --- a/samples/httpsession-gemfire-p2p/build.gradle +++ b/samples/httpsession-gemfire-p2p/build.gradle @@ -13,7 +13,9 @@ dependencies { testCompile "junit:junit:$junitVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies, + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" integrationTestRuntime "org.springframework.shell:spring-shell:1.0.0.RELEASE" } diff --git a/samples/httpsession-gemfire-p2p/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/httpsession-gemfire-p2p/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index c865fc43..00000000 --- a/samples/httpsession-gemfire-p2p/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.* -import sample.pages.HomePage; -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - */ -@Stepwise -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 1 - attributes[0].name == 'a' - attributes[0].value == 'b' - } -} diff --git a/samples/httpsession-gemfire-p2p/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/httpsession-gemfire-p2p/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index 25215292..00000000 --- a/samples/httpsession-gemfire-p2p/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/httpsession-gemfire-p2p/src/integration-test/java/sample/AttributeTests.java b/samples/httpsession-gemfire-p2p/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..6628f7a3 --- /dev/null +++ b/samples/httpsession-gemfire-p2p/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class AttributeTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(1); + assertThat(home.row(0).getAttributeName()).isEqualTo("a"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/httpsession-gemfire-p2p/src/integration-test/java/sample/pages/HomePage.java b/samples/httpsession-gemfire-p2p/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..dbb01fed --- /dev/null +++ b/samples/httpsession-gemfire-p2p/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,102 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/httpsession-jdbc-boot/build.gradle b/samples/httpsession-jdbc-boot/build.gradle index dbe2d358..f3869ceb 100644 --- a/samples/httpsession-jdbc-boot/build.gradle +++ b/samples/httpsession-jdbc-boot/build.gradle @@ -28,10 +28,11 @@ dependencies { "org.webjars:webjars-locator", "com.h2database:h2" - testCompile "org.springframework.boot:spring-boot-starter-test" + testCompile "org.springframework.boot:spring-boot-starter-test", + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" - integrationTestCompile gebDependencies, - "org.spockframework:spock-spring:$spockVersion" + integrationTestCompile seleniumDependencies } diff --git a/samples/httpsession-jdbc-boot/src/integration-test/groovy/sample/BootTests.groovy b/samples/httpsession-jdbc-boot/src/integration-test/groovy/sample/BootTests.groovy deleted file mode 100644 index f158edbd..00000000 --- a/samples/httpsession-jdbc-boot/src/integration-test/groovy/sample/BootTests.groovy +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.* -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.test.IntegrationTest -import org.springframework.boot.test.SpringApplicationConfiguration -import org.springframework.boot.test.SpringApplicationContextLoader -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.web.WebAppConfiguration -import sample.pages.HomePage -import sample.pages.LoginPage -import spock.lang.Stepwise -import pages.* - -/** - * Tests the demo that supports multiple sessions - * - * @author Rob Winch - */ -@Stepwise -@ContextConfiguration(classes = Application, loader = SpringApplicationContextLoader) -@WebAppConfiguration -@IntegrationTest -class BootTests extends GebReportingSpec { - - def 'Unauthenticated user sent to log in page'() { - when: 'unauthenticated user request protected page' - via HomePage - then: 'sent to the log in page' - at LoginPage - } - - def 'Log in views home page'() { - when: 'log in successfully' - login() - then: 'sent to original page' - at HomePage - and: 'the username is displayed' - username == 'user' - and: 'Spring Session Management is being used' - driver.manage().cookies.find { it.name == 'SESSION' } - and: 'Standard Session is NOT being used' - !driver.manage().cookies.find { it.name == 'JSESSIONID' } - } - - def 'Log out success'() { - when: - logout() - then: - at LoginPage - } - - def 'Logged out user sent to log in page'() { - when: 'logged out user request protected page' - via HomePage - then: 'sent to the log in page' - at LoginPage - } -} diff --git a/samples/httpsession-jdbc-boot/src/integration-test/groovy/sample/pages/LoginPage.groovy b/samples/httpsession-jdbc-boot/src/integration-test/groovy/sample/pages/LoginPage.groovy deleted file mode 100644 index 68f98597..00000000 --- a/samples/httpsession-jdbc-boot/src/integration-test/groovy/sample/pages/LoginPage.groovy +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The Links Page - * - * @author Rob Winch - */ -class LoginPage extends Page { - static url = '/login' - static at = { assert driver.title == 'Login Page'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - login(required:false) { user='user', pass='password' -> - form.username = user - form.password = pass - submit.click(HomePage) - } - } -} diff --git a/samples/httpsession-jdbc-boot/src/integration-test/java/sample/BootTests.java b/samples/httpsession-jdbc-boot/src/integration-test/java/sample/BootTests.java new file mode 100644 index 00000000..73e27228 --- /dev/null +++ b/samples/httpsession-jdbc-boot/src/integration-test/java/sample/BootTests.java @@ -0,0 +1,84 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; +import sample.pages.HomePage; +import sample.pages.LoginPage; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder; + +/** + * @author Eddú Meléndez + */ +@RunWith(SpringRunner.class) +@AutoConfigureMockMvc +@SpringBootTest(webEnvironment = WebEnvironment.MOCK) +public class BootTests { + + @Autowired + private MockMvc mockMvc; + + private WebDriver driver; + + @Before + public void setup() { + this.driver = MockMvcHtmlUnitDriverBuilder + .mockMvcSetup(this.mockMvc) + .build(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void home() { + LoginPage login = HomePage.go(this.driver); + login.assertAt(); + HomePage home = login.login(); + home.assertAt(); + } + + @Test + public void login() { + LoginPage login = HomePage.go(this.driver); + HomePage home = login.login(); + home.containCookie("SESSION"); + home.doesNotContainCookie("JSESSIONID"); + } + + @Test + public void logout() { + LoginPage login = HomePage.go(this.driver); + HomePage home = login.login(); + login = home.logout(); + login.assertAt(); + } + +} diff --git a/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/httpsession-jdbc-boot/src/integration-test/java/sample/pages/BasePage.java similarity index 56% rename from samples/hazelcast-spring/src/integration-test/groovy/sample/pages/HomePage.groovy rename to samples/httpsession-jdbc-boot/src/integration-test/java/sample/pages/BasePage.java index b98a276e..763c0787 100644 --- a/samples/hazelcast-spring/src/integration-test/groovy/sample/pages/HomePage.groovy +++ b/samples/httpsession-jdbc-boot/src/integration-test/java/sample/pages/BasePage.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,20 +14,28 @@ * limitations under the License. */ -package sample.pages +package sample.pages; -import geb.Page +import org.openqa.selenium.WebDriver; /** - * The home page - * - * @author Rob Winch + * @author Eddú Meléndez */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Secured Content'; true} - static content = { - username { $('#un').text() } - logout(to:LoginPage) { $('input[type=submit]').click() } +public class BasePage { + + private WebDriver driver; + + public BasePage(WebDriver driver) { + this.driver = driver; } + + public WebDriver getDriver() { + return this.driver; + } + + public static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost"; + driver.get(baseUrl + get); + } + } diff --git a/samples/httpsession-jdbc-boot/src/integration-test/java/sample/pages/HomePage.java b/samples/httpsession-jdbc-boot/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..5169002f --- /dev/null +++ b/samples/httpsession-jdbc-boot/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,63 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.Set; + +import org.openqa.selenium.By; +import org.openqa.selenium.Cookie; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class HomePage extends BasePage { + + public HomePage(WebDriver driver) { + super(driver); + } + + public static LoginPage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, LoginPage.class); + } + + public void assertAt() { + assertThat(getDriver().getTitle()).isEqualTo("Spring Session Sample - Secured Content"); + } + + public void containCookie(String cookieName) { + Set cookies = getDriver().manage().getCookies(); + assertThat(cookies).extracting("name").contains(cookieName); + } + + public void doesNotContainCookie(String cookieName) { + Set cookies = getDriver().manage().getCookies(); + assertThat(cookies).extracting("name").doesNotContain(cookieName); + } + + public LoginPage logout() { + WebElement logout = getDriver().findElement(By.cssSelector("input[type=\"submit\"]")); + logout.click(); + return PageFactory.initElements(getDriver(), LoginPage.class); + } + +} diff --git a/samples/httpsession-jdbc-boot/src/integration-test/java/sample/pages/LoginPage.java b/samples/httpsession-jdbc-boot/src/integration-test/java/sample/pages/LoginPage.java new file mode 100644 index 00000000..ab67fcad --- /dev/null +++ b/samples/httpsession-jdbc-boot/src/integration-test/java/sample/pages/LoginPage.java @@ -0,0 +1,55 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class LoginPage extends BasePage { + + @FindBy(name = "username") + private WebElement username; + + @FindBy(name = "password") + private WebElement password; + + @FindBy(name = "submit") + private WebElement button; + + public LoginPage(WebDriver driver) { + super(driver); + } + + public void assertAt() { + assertThat(getDriver().getTitle()).isEqualTo("Login Page"); + } + + public HomePage login() { + this.username.sendKeys("user"); + this.password.sendKeys("password"); + this.button.click(); + return PageFactory.initElements(getDriver(), HomePage.class); + } + +} diff --git a/samples/httpsession-jdbc-xml/build.gradle b/samples/httpsession-jdbc-xml/build.gradle index f3feeb74..efb72306 100644 --- a/samples/httpsession-jdbc-xml/build.gradle +++ b/samples/httpsession-jdbc-xml/build.gradle @@ -12,7 +12,9 @@ dependencies { providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion" - testCompile "junit:junit:$junitVersion" + testCompile "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies } diff --git a/samples/httpsession-jdbc-xml/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/httpsession-jdbc-xml/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index ffdbdb17..00000000 --- a/samples/httpsession-jdbc-xml/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample - -import geb.spock.* -import sample.pages.HomePage; -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - */ -@Stepwise -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 1 - attributes[0].name == 'a' - attributes[0].value == 'b' - } -} diff --git a/samples/httpsession-jdbc-xml/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/httpsession-jdbc-xml/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index c5dfe31a..00000000 --- a/samples/httpsession-jdbc-xml/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/httpsession-jdbc-xml/src/integration-test/java/sample/AttributeTests.java b/samples/httpsession-jdbc-xml/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..6628f7a3 --- /dev/null +++ b/samples/httpsession-jdbc-xml/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class AttributeTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(1); + assertThat(home.row(0).getAttributeName()).isEqualTo("a"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/httpsession-jdbc-xml/src/integration-test/java/sample/pages/HomePage.java b/samples/httpsession-jdbc-xml/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..dbb01fed --- /dev/null +++ b/samples/httpsession-jdbc-xml/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,102 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/httpsession-jdbc/build.gradle b/samples/httpsession-jdbc/build.gradle index f3feeb74..efb72306 100644 --- a/samples/httpsession-jdbc/build.gradle +++ b/samples/httpsession-jdbc/build.gradle @@ -12,7 +12,9 @@ dependencies { providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion" - testCompile "junit:junit:$junitVersion" + testCompile "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies } diff --git a/samples/httpsession-jdbc/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/httpsession-jdbc/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index ffdbdb17..00000000 --- a/samples/httpsession-jdbc/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample - -import geb.spock.* -import sample.pages.HomePage; -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - */ -@Stepwise -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 1 - attributes[0].name == 'a' - attributes[0].value == 'b' - } -} diff --git a/samples/httpsession-jdbc/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/httpsession-jdbc/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index c5dfe31a..00000000 --- a/samples/httpsession-jdbc/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/httpsession-jdbc/src/integration-test/java/sample/AttributeTests.java b/samples/httpsession-jdbc/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..6628f7a3 --- /dev/null +++ b/samples/httpsession-jdbc/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class AttributeTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(1); + assertThat(home.row(0).getAttributeName()).isEqualTo("a"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/httpsession-jdbc/src/integration-test/java/sample/pages/HomePage.java b/samples/httpsession-jdbc/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..dbb01fed --- /dev/null +++ b/samples/httpsession-jdbc/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,102 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/httpsession-redis-json/build.gradle b/samples/httpsession-redis-json/build.gradle index 151efcdc..e1d4bda4 100644 --- a/samples/httpsession-redis-json/build.gradle +++ b/samples/httpsession-redis-json/build.gradle @@ -33,11 +33,10 @@ dependencies { "org.apache.httpcomponents:httpclient" testCompile "org.springframework.boot:spring-boot-starter-test", - "org.assertj:assertj-core:$assertjVersion" + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" testCompile "org.skyscreamer:jsonassert:$jsonassertVersion" - testCompile "org.assertj:assertj-core:$assertjVersion" - integrationTestCompile gebDependencies, - "org.spockframework:spock-spring:$spockVersion" + integrationTestCompile seleniumDependencies } // @@ -45,9 +44,6 @@ integrationTest { doFirst { def port = reservePort() - def host = 'localhost:' + port - systemProperties['geb.build.baseUrl'] = 'http://'+host+'/' - systemProperties['geb.build.reportsDir'] = 'build/geb-reports' systemProperties['server.port'] = port systemProperties['management.port'] = 0 diff --git a/samples/httpsession-redis-json/src/integration-test/groovy/samples/HttpRedisJsonTest.groovy b/samples/httpsession-redis-json/src/integration-test/groovy/samples/HttpRedisJsonTest.groovy deleted file mode 100644 index a557c490..00000000 --- a/samples/httpsession-redis-json/src/integration-test/groovy/samples/HttpRedisJsonTest.groovy +++ /dev/null @@ -1,54 +0,0 @@ -package samples - -import geb.spock.* -import sample.Application -import samples.pages.* -import spock.lang.Stepwise - -import org.springframework.boot.test.IntegrationTest -import org.springframework.boot.test.SpringApplicationContextLoader -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.web.WebAppConfiguration - -/** - * @author jitendra on 15/3/16. - */ -@Stepwise -@ContextConfiguration(classes = Application, loader = SpringApplicationContextLoader) -@WebAppConfiguration -@IntegrationTest -class HttpRedisJsonTest extends GebSpec { - - def'login page test'() { - when: - to LoginPage - then: - at LoginPage - } - - def"Unauthenticated user sent to login page"() { - when: - via HomePage - then: - at LoginPage - } - - def"Successful Login test"() { - when: - login() - then: - at HomePage - driver.manage().cookies.find {it.name == "SESSION"} - !driver.manage().cookies.find {it.name == "JSESSIONID"} - } - - def"Set and get attributes in session"() { - when: - setAttribute("Demo Key", "Demo Value") - - then: - at SetAttributePage - tdKey()*.text().contains("Demo Key") - tdKey()*.text().contains("Demo Value") - } -} diff --git a/samples/httpsession-redis-json/src/integration-test/groovy/samples/pages/HomePage.groovy b/samples/httpsession-redis-json/src/integration-test/groovy/samples/pages/HomePage.groovy deleted file mode 100644 index 214a20c6..00000000 --- a/samples/httpsession-redis-json/src/integration-test/groovy/samples/pages/HomePage.groovy +++ /dev/null @@ -1,26 +0,0 @@ -package samples.pages - -import geb.Page - -/** - * @author jitendra on 15/3/16. - */ -class HomePage extends Page { - static url="/" - - static at= - { - driver.title == "Spring Session Sample - Home" - } - - static content= - { - form { $('form') } - submit { $('button[type=submit]') } - setAttribute(required: false) { key = 'project', value = 'SessionRedisJson' -> - form.key = key - form.value = value - submit.click(SetAttributePage) - } - } -} diff --git a/samples/httpsession-redis-json/src/integration-test/groovy/samples/pages/LoginPage.groovy b/samples/httpsession-redis-json/src/integration-test/groovy/samples/pages/LoginPage.groovy deleted file mode 100644 index 4402fe9b..00000000 --- a/samples/httpsession-redis-json/src/integration-test/groovy/samples/pages/LoginPage.groovy +++ /dev/null @@ -1,27 +0,0 @@ -package samples.pages - -import geb.Page - -/** - * @author jitendra on 15/3/16. - */ -class LoginPage extends Page { - static url="/login" - - static at= - { - assert title == "Spring Session Sample - Login" - return true - } - - static content= - { - form { $('form') } - submit { $('button[type=submit]') } - login(required: false) { user = 'user', pass = 'password' -> - form.username = user - form.password = pass - submit.click(HomePage) - } - } -} diff --git a/samples/httpsession-redis-json/src/integration-test/groovy/samples/pages/SetAttributePage.groovy b/samples/httpsession-redis-json/src/integration-test/groovy/samples/pages/SetAttributePage.groovy deleted file mode 100644 index 83a61556..00000000 --- a/samples/httpsession-redis-json/src/integration-test/groovy/samples/pages/SetAttributePage.groovy +++ /dev/null @@ -1,20 +0,0 @@ -package samples.pages - -import geb.Page - -/** - * @author jitendra on 15/3/16. - */ -class SetAttributePage extends Page { - static url="/setValue" - - static at= - { - title == "Spring Session Sample - Home" - } - - static content= - { - tdKey { $('td') } - } -} diff --git a/samples/httpsession-redis-json/src/integration-test/java/samples/HttpRedisJsonTest.java b/samples/httpsession-redis-json/src/integration-test/java/samples/HttpRedisJsonTest.java new file mode 100644 index 00000000..02ab3736 --- /dev/null +++ b/samples/httpsession-redis-json/src/integration-test/java/samples/HttpRedisJsonTest.java @@ -0,0 +1,95 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package samples; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openqa.selenium.WebDriver; +import sample.Application; +import samples.pages.HomePage; +import samples.pages.LoginPage; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootContextLoader; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.MOCK) +@AutoConfigureMockMvc +@ContextConfiguration(classes = Application.class, loader = SpringBootContextLoader.class) +public class HttpRedisJsonTest { + + @Autowired + private MockMvc mockMvc; + + private WebDriver driver; + + @Before + public void setup() { + this.driver = MockMvcHtmlUnitDriverBuilder + .mockMvcSetup(this.mockMvc) + .build(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void goLoginRedirectToLogin() { + LoginPage login = LoginPage.go(this.driver); + login.assertAt(); + } + + @Test + public void goHomeRedirectLoginPage() { + LoginPage login = HomePage.go(this.driver); + login.assertAt(); + } + + @Test + public void login() { + LoginPage login = LoginPage.go(this.driver); + HomePage home = login.login(); + home.containCookie("SESSION"); + home.doesNotContainCookie("JSESSIONID"); + } + + @Test + public void createAttribute() { + LoginPage login = LoginPage.go(this.driver); + login.login(); + login.addAttribute("Demo Key", "Demo Value"); + assertThat(login.attributes()).extracting("key").contains("Demo Key"); + assertThat(login.attributes()).extracting("value").contains("Demo Value"); + } + +} diff --git a/samples/boot/src/integration-test/groovy/sample/pages/LoginPage.groovy b/samples/httpsession-redis-json/src/integration-test/java/samples/pages/BasePage.java similarity index 56% rename from samples/boot/src/integration-test/groovy/sample/pages/LoginPage.groovy rename to samples/httpsession-redis-json/src/integration-test/java/samples/pages/BasePage.java index 68f98597..a8d2859a 100644 --- a/samples/boot/src/integration-test/groovy/sample/pages/LoginPage.groovy +++ b/samples/httpsession-redis-json/src/integration-test/java/samples/pages/BasePage.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,25 +14,28 @@ * limitations under the License. */ -package sample.pages +package samples.pages; -import geb.* +import org.openqa.selenium.WebDriver; /** - * The Links Page - * - * @author Rob Winch + * @author Eddú Meléndez */ -class LoginPage extends Page { - static url = '/login' - static at = { assert driver.title == 'Login Page'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - login(required:false) { user='user', pass='password' -> - form.username = user - form.password = pass - submit.click(HomePage) - } +public class BasePage { + + private WebDriver driver; + + public BasePage(WebDriver driver) { + this.driver = driver; } + + public WebDriver getDriver() { + return this.driver; + } + + public static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost"; + driver.get(baseUrl + get); + } + } diff --git a/samples/httpsession-redis-json/src/integration-test/java/samples/pages/HomePage.java b/samples/httpsession-redis-json/src/integration-test/java/samples/pages/HomePage.java new file mode 100644 index 00000000..092a54e2 --- /dev/null +++ b/samples/httpsession-redis-json/src/integration-test/java/samples/pages/HomePage.java @@ -0,0 +1,51 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package samples.pages; + +import java.util.Set; + +import org.openqa.selenium.Cookie; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class HomePage extends BasePage { + + public HomePage(WebDriver driver) { + super(driver); + } + + public static LoginPage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, LoginPage.class); + } + + public void containCookie(String cookieName) { + Set cookies = getDriver().manage().getCookies(); + assertThat(cookies).extracting("name").contains(cookieName); + } + + public void doesNotContainCookie(String cookieName) { + Set cookies = getDriver().manage().getCookies(); + assertThat(cookies).extracting("name").doesNotContain(cookieName); + } + +} diff --git a/samples/httpsession-redis-json/src/integration-test/java/samples/pages/LoginPage.java b/samples/httpsession-redis-json/src/integration-test/java/samples/pages/LoginPage.java new file mode 100644 index 00000000..8a4403cb --- /dev/null +++ b/samples/httpsession-redis-json/src/integration-test/java/samples/pages/LoginPage.java @@ -0,0 +1,105 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package samples.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class LoginPage extends BasePage { + + public LoginPage(WebDriver driver) { + super(driver); + } + + public void assertAt() { + assertThat(getDriver().getTitle()).isEqualTo("Spring Session Sample - Login"); + } + + public static LoginPage go(WebDriver driver) { + get(driver, "/login"); + return PageFactory.initElements(driver, LoginPage.class); + } + + public HomePage login() { + WebElement username = getDriver().findElement(By.name("username")); + WebElement password = getDriver().findElement(By.name("password")); + WebElement button = getDriver().findElement(By.cssSelector("button[type=\"submit\"]")); + + username.sendKeys("user"); + password.sendKeys("password"); + button.click(); + return PageFactory.initElements(getDriver(), HomePage.class); + } + + public void addAttribute(String name, String value) { + WebElement form = getDriver().findElement(By.name("f")); + WebElement attributeName = form.findElement(By.name("key")); + WebElement attributeValue = form.findElement(By.name("value")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("button[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = getDriver().findElement(By.tagName("table")); + List trs = table.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + if (!tds.isEmpty()) { + Row row = Row.builder() + .driver(getDriver()) + .key(tds.get(0).getText()) + .value(tds.get(1).getText()) + .build(); + rows.add(row); + } + } + return rows; + } + + @Data + @Builder + public static class Row { + + final String key; + + final String value; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/httpsession-xml/build.gradle b/samples/httpsession-xml/build.gradle index 7edb6f84..41b0360a 100644 --- a/samples/httpsession-xml/build.gradle +++ b/samples/httpsession-xml/build.gradle @@ -14,7 +14,9 @@ dependencies { providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion" - testCompile "junit:junit:$junitVersion" + testCompile "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies } diff --git a/samples/httpsession-xml/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/httpsession-xml/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index c865fc43..00000000 --- a/samples/httpsession-xml/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.* -import sample.pages.HomePage; -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - */ -@Stepwise -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 1 - attributes[0].name == 'a' - attributes[0].value == 'b' - } -} diff --git a/samples/httpsession-xml/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/httpsession-xml/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index 25215292..00000000 --- a/samples/httpsession-xml/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/httpsession-xml/src/integration-test/java/sample/AttributeTests.java b/samples/httpsession-xml/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..6628f7a3 --- /dev/null +++ b/samples/httpsession-xml/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class AttributeTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(1); + assertThat(home.row(0).getAttributeName()).isEqualTo("a"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/httpsession-xml/src/integration-test/java/sample/pages/HomePage.java b/samples/httpsession-xml/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..dbb01fed --- /dev/null +++ b/samples/httpsession-xml/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,102 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +} diff --git a/samples/httpsession/build.gradle b/samples/httpsession/build.gradle index 7edb6f84..41b0360a 100644 --- a/samples/httpsession/build.gradle +++ b/samples/httpsession/build.gradle @@ -14,7 +14,9 @@ dependencies { providedCompile "javax.servlet:javax.servlet-api:$servletApiVersion" - testCompile "junit:junit:$junitVersion" + testCompile "junit:junit:$junitVersion", + "org.assertj:assertj-core:$assertjVersion", + "org.projectlombok:lombok:$lombokVersion" - integrationTestCompile gebDependencies + integrationTestCompile seleniumDependencies } diff --git a/samples/httpsession/src/integration-test/groovy/sample/AttributeTests.groovy b/samples/httpsession/src/integration-test/groovy/sample/AttributeTests.groovy deleted file mode 100644 index c865fc43..00000000 --- a/samples/httpsession/src/integration-test/groovy/sample/AttributeTests.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample - -import geb.spock.* -import sample.pages.HomePage; -import spock.lang.Stepwise -import pages.* - -/** - * Tests the CAS sample application using service tickets. - * - * @author Rob Winch - */ -@Stepwise -class AttributeTests extends GebReportingSpec { - def 'first visit no attributes'() { - when: - to HomePage - then: - attributes.empty - } - - def 'create attribute'() { - when: - createAttribute('a','b') - then: - attributes.size() == 1 - attributes[0].name == 'a' - attributes[0].value == 'b' - } -} diff --git a/samples/httpsession/src/integration-test/groovy/sample/pages/HomePage.groovy b/samples/httpsession/src/integration-test/groovy/sample/pages/HomePage.groovy deleted file mode 100644 index 25215292..00000000 --- a/samples/httpsession/src/integration-test/groovy/sample/pages/HomePage.groovy +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2014-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package sample.pages - -import geb.* - -/** - * The home page - * - * @author Rob Winch - */ -class HomePage extends Page { - static url = '' - static at = { assert driver.title == 'Session Attributes'; true} - static content = { - form { $('form') } - submit { $('input[type=submit]') } - createAttribute(required:false) { name, value -> - form.attributeName = name - form.attributeValue = value - submit.click(HomePage) - } - attributes { moduleList AttributeRow, $("table tr").tail() } - } -} -class AttributeRow extends Module { - static content = { - cell { $("td", it) } - name { cell(0).text() } - value { cell(1).text() } - } -} diff --git a/samples/httpsession/src/integration-test/java/sample/AttributeTests.java b/samples/httpsession/src/integration-test/java/sample/AttributeTests.java new file mode 100644 index 00000000..6628f7a3 --- /dev/null +++ b/samples/httpsession/src/integration-test/java/sample/AttributeTests.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +import sample.pages.HomePage; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class AttributeTests { + + private WebDriver driver; + + @Before + public void setup() { + this.driver = new HtmlUnitDriver(); + } + + @After + public void tearDown() { + this.driver.quit(); + } + + @Test + public void noAttributes() { + HomePage home = HomePage.go(this.driver); + assertThat(home.attributes().size()).isEqualTo(0); + } + + @Test + public void createAttribute() { + HomePage home = HomePage.go(this.driver); + home.addAttribute("a", "b"); + assertThat(home.attributes().size()).isEqualTo(1); + assertThat(home.row(0).getAttributeName()).isEqualTo("a"); + assertThat(home.row(0).getAttributeValue()).isEqualTo("b"); + } + +} diff --git a/samples/httpsession/src/integration-test/java/sample/pages/HomePage.java b/samples/httpsession/src/integration-test/java/sample/pages/HomePage.java new file mode 100644 index 00000000..00e29651 --- /dev/null +++ b/samples/httpsession/src/integration-test/java/sample/pages/HomePage.java @@ -0,0 +1,108 @@ +/* + * Copyright 2014-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package sample.pages; + +import java.util.ArrayList; +import java.util.List; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.PageFactory; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Eddú Meléndez + */ +public class HomePage { + + private WebDriver driver; + + private List rows; + + public HomePage(WebDriver driver) { + this.driver = driver; + this.rows = new ArrayList(); + } + + private static void get(WebDriver driver, String get) { + String baseUrl = "http://localhost:" + System.getProperty("tomcat.port"); + driver.get(baseUrl + get); + } + + public static HomePage go(WebDriver driver) { + get(driver, "/"); + return PageFactory.initElements(driver, HomePage.class); + } + + public void assertAt() { + assertThat(this.driver.getTitle()).isEqualTo("Session Attributes"); + } + + public void addAttribute(String name, String value) { + WebElement form = this.driver.findElement(By.tagName("form")); + WebElement attributeName = form.findElement(By.name("attributeName")); + WebElement attributeValue = form.findElement(By.name("attributeValue")); + + attributeName.sendKeys(name); + attributeValue.sendKeys(value); + + form.findElement(By.cssSelector("input[type=\"submit\"]")).click(); + } + + public List attributes() { + WebElement table = this.driver.findElement(By.tagName("table")); + WebElement tbody = table.findElement(By.tagName("tbody")); + List trs = tbody.findElements(By.tagName("tr")); + + List rows = new ArrayList(); + for (WebElement tr : trs) { + List tds = tr.findElements(By.cssSelector("td")); + Row row = Row.builder() + .driver(this.driver) + .attributeName(tds.get(0).getText()) + .attributeValue(tds.get(1).getText()) + .build(); + rows.add(row); + } + this.rows.addAll(rows); + return this.rows; + } + + public Row row(int index) { + return this.rows.get(index); + } + + @Data + @Builder + public static class Row { + + final String attributeName; + + final String attributeValue; + + @Getter(AccessLevel.PRIVATE) + final WebDriver driver; + + } + +}