From 15ab3316b3407f44c5c176a3ca394019a543a106 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Thu, 12 Jun 2014 12:01:32 -0500 Subject: [PATCH] SEC-2630: Add helloworld-jc Gebintegration tests --- samples/helloworld-jc/build.gradle | 4 +- samples/helloworld-jc/pom.xml | 48 ++++++++++++++++ .../security/samples/HelloWorldJcTests.groovy | 56 +++++++++++++++++++ .../security/samples/pages/HomePage.groovy} | 27 +++++---- .../security/samples/pages/LoginPage.groovy | 37 ++++++++++++ 5 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/HelloWorldJcTests.groovy rename samples/helloworld-jc/src/{test/java/org/springframework/security/samples/config/SecurityConfigTests.java => integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy} (55%) create mode 100644 samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy diff --git a/samples/helloworld-jc/build.gradle b/samples/helloworld-jc/build.gradle index 70868f0e11..0efd980377 100644 --- a/samples/helloworld-jc/build.gradle +++ b/samples/helloworld-jc/build.gradle @@ -3,7 +3,7 @@ apply from: WAR_SAMPLE_GRADLE dependencies { providedCompile "javax.servlet:javax.servlet-api:3.0.1", - 'javax.servlet.jsp:jsp-api:2.1' + 'javax.servlet.jsp:jsp-api:2.1' compile project(":spring-security-config"), project(":spring-security-web"), @@ -11,4 +11,6 @@ dependencies { "org.slf4j:jcl-over-slf4j:$slf4jVersion" runtime "ch.qos.logback:logback-classic:$logbackVersion" + + integrationTestCompile gebDependencies } \ No newline at end of file diff --git a/samples/helloworld-jc/pom.xml b/samples/helloworld-jc/pom.xml index de1116f466..c34639623c 100644 --- a/samples/helloworld-jc/pom.xml +++ b/samples/helloworld-jc/pom.xml @@ -124,24 +124,72 @@ 0.9.29 runtime + + commons-httpclient + commons-httpclient + 3.1 + test + junit junit 4.11 test + + org.codehaus.groovy + groovy + 2.0.5 + test + org.easytesting fest-assert 1.4 test + + org.gebish + geb-spock + 0.9.0 + test + org.mockito mockito-core 1.9.5 test + + org.seleniumhq.selenium + selenium-htmlunit-driver + 2.33.0 + test + + + org.spockframework + spock-core + 0.7-groovy-2.0 + test + + + junit-dep + junit + + + + + org.spockframework + spock-spring + 0.7-groovy-2.0 + test + + + junit-dep + junit + + + org.springframework spring-test diff --git a/samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/HelloWorldJcTests.groovy b/samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/HelloWorldJcTests.groovy new file mode 100644 index 0000000000..c21fa82aca --- /dev/null +++ b/samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/HelloWorldJcTests.groovy @@ -0,0 +1,56 @@ +/* + * Copyright 2011 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 org.springframework.security.samples + +import geb.spock.* +import spock.lang.Shared +import spock.lang.Stepwise +import org.springframework.security.samples.pages.* + +/** + * Tests the CAS sample application using service tickets. + * + * @author Rob Winch + */ +@Stepwise +class HelloWorldJcTests extends GebReportingSpec { + def 'access home page with unauthenticated user sends to login page'() { + when: 'Unauthenticated user accesses the Home Page' + via HomePage + then: 'The login page is displayed' + at LoginPage + } + + def 'authenticated user is sent to original page'() { + when: 'user authenticates' + login() + then: 'The home page is displayed' + at HomePage + and: 'The username is displayed' + message == 'Hello user' + } + + def 'authenticated user logs out'() { + when: 'user logs out' + logout() + then: 'the login page is displayed' + at LoginPage + when: 'Unauthenticated user accesses the Home Page' + via HomePage + then: 'The login page is displayed' + at LoginPage + } +} \ No newline at end of file diff --git a/samples/helloworld-jc/src/test/java/org/springframework/security/samples/config/SecurityConfigTests.java b/samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy similarity index 55% rename from samples/helloworld-jc/src/test/java/org/springframework/security/samples/config/SecurityConfigTests.java rename to samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy index 53e0c04696..83e1128cfd 100644 --- a/samples/helloworld-jc/src/test/java/org/springframework/security/samples/config/SecurityConfigTests.java +++ b/samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2011 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. @@ -13,21 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.security.samples.config; +package org.springframework.security.samples.pages; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import geb.* /** - * @author Rob Winch + * The home page * + * @author Rob Winch */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes=SecurityConfig.class) -public class SecurityConfigTests { - - @Test - public void securityConfigurationLoads() {} -} +class HomePage extends Page { + static url = '' + static at = { assert driver.title == 'Hello Security'; true} + static content = { + message { $('p').text() } + logout { $('input', type: 'submit').click() } + } +} \ No newline at end of file diff --git a/samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy b/samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy new file mode 100644 index 0000000000..b2a553064b --- /dev/null +++ b/samples/helloworld-jc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy @@ -0,0 +1,37 @@ +/* + * Copyright 2011 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 org.springframework.security.samples.pages; + +import geb.* + +/** + * The login page. + * + * @author Rob Winch + */ +class LoginPage extends Page { + static url = 'login' + static at = { assert driver.title == 'Login Page'; true} + static content = { + login(required:false) { user='user', password='password' -> + loginForm.username = user + loginForm.password = password + submit.click() + } + loginForm { $('form') } + submit { $('input', type: 'submit') } + } +} \ No newline at end of file