diff --git a/samples/jdbc-jc/build.gradle b/samples/jdbc-jc/build.gradle index 685bbbe62a..79830964f4 100644 --- a/samples/jdbc-jc/build.gradle +++ b/samples/jdbc-jc/build.gradle @@ -22,4 +22,6 @@ dependencies { runtime "opensymphony:sitemesh:2.4.2", 'cglib:cglib-nodep:2.2.2', 'ch.qos.logback:logback-classic:0.9.30' + + integrationTestCompile gebDependencies } \ No newline at end of file diff --git a/samples/jdbc-jc/src/integration-test/groovy/org/springframework/security/samples/JdbcJcTests.groovy b/samples/jdbc-jc/src/integration-test/groovy/org/springframework/security/samples/JdbcJcTests.groovy new file mode 100644 index 0000000000..eb5cf0e0fb --- /dev/null +++ b/samples/jdbc-jc/src/integration-test/groovy/org/springframework/security/samples/JdbcJcTests.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 JdbcJcTests 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' + user == '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/jdbc-jc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy b/samples/jdbc-jc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy new file mode 100644 index 0000000000..25ce258a34 --- /dev/null +++ b/samples/jdbc-jc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy @@ -0,0 +1,32 @@ +/* + * 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 home page + * + * @author Rob Winch + */ +class HomePage extends Page { + static url = '' + static at = { assert driver.title == 'Messages : View All'; true} + static content = { + user { $('p.navbar-text').text() } + logout { $('input', type: 'submit').click() } + } +} \ No newline at end of file diff --git a/samples/jdbc-jc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy b/samples/jdbc-jc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy new file mode 100644 index 0000000000..b2a553064b --- /dev/null +++ b/samples/jdbc-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 diff --git a/samples/jdbc-jc/src/test/java/org/springframework/security/samples/config/SecurityConfigTests.java b/samples/jdbc-jc/src/test/java/org/springframework/security/samples/config/SecurityConfigTests.java deleted file mode 100644 index 23fb47981c..0000000000 --- a/samples/jdbc-jc/src/test/java/org/springframework/security/samples/config/SecurityConfigTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2002-2013 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.config; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.web.FilterChainProxy; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -/** - * @author Rob Winch - * - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@WebAppConfiguration -public class SecurityConfigTests { - @Configuration - @ComponentScan(basePackages = "org.springframework.security.samples.config") - public static class Config {} - - @Autowired - private FilterChainProxy springSecurityFilterChain; - - @Test - public void securityConfigurationLoads() {} -} diff --git a/samples/jdbc-jc/src/test/java/org/springframework/security/samples/config/WebMvcTests.java b/samples/jdbc-jc/src/test/java/org/springframework/security/samples/config/WebMvcTests.java deleted file mode 100644 index fa8c37cec5..0000000000 --- a/samples/jdbc-jc/src/test/java/org/springframework/security/samples/config/WebMvcTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2002-2013 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.config; - -import javax.sql.DataSource; - -import junit.framework.Assert; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - -/** - * @author Rob Winch - * - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -@WebAppConfiguration -public class WebMvcTests { - @Configuration - @Import({DataConfiguration.class}) - public static class Config extends WebMvcConfigurerAdapter { - @Autowired - private DataSource dataSource; - - @Override - public void addInterceptors(InterceptorRegistry registry) { - Assert.assertNotNull(dataSource); - } - } - - - - @Test - public void configurationLoads() {} -}