Skip to content

Commit a4701bc

Browse files
michael-simonsrwinch
authored andcommitted
Migrate javaconfig-jdbc groovy->java
See #4939.
1 parent 1d32fff commit a4701bc

File tree

8 files changed

+234
-126
lines changed

8 files changed

+234
-126
lines changed

samples/javaconfig/jdbc/spring-security-samples-javaconfig-jdbc.gradle

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2002-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
apply plugin: 'io.spring.convention.spring-sample-war'
218

319
dependencies {
@@ -17,5 +33,5 @@ dependencies {
1733

1834
runtime 'opensymphony:sitemesh'
1935

20-
integrationTestCompile gebDependencies
36+
integrationTestCompile seleniumDependencies
2137
}

samples/javaconfig/jdbc/src/integration-test/groovy/org/springframework/security/samples/JdbcJcTests.groovy

Lines changed: 0 additions & 56 deletions
This file was deleted.

samples/javaconfig/jdbc/src/integration-test/groovy/org/springframework/security/samples/pages/HomePage.groovy

Lines changed: 0 additions & 32 deletions
This file was deleted.

samples/javaconfig/jdbc/src/integration-test/groovy/org/springframework/security/samples/pages/LoginPage.groovy

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2002-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.samples;
17+
18+
import org.junit.After;
19+
import org.junit.Before;
20+
import org.junit.Test;
21+
import org.openqa.selenium.WebDriver;
22+
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
23+
import org.springframework.security.samples.pages.HomePage;
24+
import org.springframework.security.samples.pages.LoginPage;
25+
import org.springframework.transaction.annotation.Transactional;
26+
27+
/**
28+
* @author Michael Simons
29+
*/
30+
@Transactional
31+
public class JdbcJcTests {
32+
private WebDriver driver;
33+
34+
private int port;
35+
36+
@Before
37+
public void setup() {
38+
this.port = Integer.parseInt(System.getProperty("app.httpPort"));
39+
this.driver = new HtmlUnitDriver();
40+
}
41+
42+
@After
43+
public void tearDown() {
44+
this.driver.quit();
45+
}
46+
47+
@Test
48+
public void accessHomePageWithUnauthenticatedUserSendsToLoginPage() {
49+
final LoginPage loginPage = HomePage.to(this.driver, this.port);
50+
loginPage.assertAt();
51+
}
52+
53+
@Test
54+
public void authenticatedUserIsSentToOriginalPage() {
55+
final String userName = "user";
56+
final HomePage homePage = HomePage.to(this.driver, this.port)
57+
.loginForm()
58+
.username(userName)
59+
.password("password")
60+
.submit();
61+
homePage
62+
.assertAt()
63+
.andTheUserNameDisplayedIs(userName);
64+
}
65+
66+
@Test
67+
public void authenticatedUserLogsOut() {
68+
LoginPage loginPage = HomePage.to(this.driver, this.port)
69+
.loginForm()
70+
.username("user")
71+
.password("password")
72+
.submit()
73+
.logout();
74+
loginPage.assertAt();
75+
76+
loginPage = HomePage.to(this.driver, this.port);
77+
loginPage.assertAt();
78+
}
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2002-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.samples.pages;
17+
18+
import org.openqa.selenium.WebDriver;
19+
import org.openqa.selenium.WebElement;
20+
import org.openqa.selenium.support.FindBy;
21+
import org.openqa.selenium.support.PageFactory;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* @author Michael Simons
27+
*/
28+
public class HomePage {
29+
private final WebDriver webDriver;
30+
31+
@FindBy(css = "input[type=submit]")
32+
private WebElement logoutButton;
33+
34+
public static LoginPage to(WebDriver driver, int port) {
35+
driver.get("http://localhost:" + port +"/");
36+
return PageFactory.initElements(driver, LoginPage.class);
37+
}
38+
39+
public HomePage(WebDriver webDriver) {
40+
this.webDriver = webDriver;
41+
}
42+
43+
public Content assertAt() {
44+
assertThat(this.webDriver.getTitle()).endsWith("View All");
45+
return PageFactory.initElements(this.webDriver, Content.class);
46+
}
47+
48+
public LoginPage logout() {
49+
this.logoutButton.submit();
50+
return PageFactory.initElements(this.webDriver, LoginPage.class);
51+
}
52+
53+
public static class Content {
54+
@FindBy(css = "p.navbar-text")
55+
private WebElement message;
56+
57+
public Content andTheUserNameDisplayedIs(final String userName) {
58+
assertThat(message.getText()).isEqualTo(userName);
59+
return this;
60+
}
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2002-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.samples.pages;
17+
18+
import org.openqa.selenium.WebDriver;
19+
import org.openqa.selenium.WebElement;
20+
import org.openqa.selenium.support.FindBy;
21+
import org.openqa.selenium.support.PageFactory;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* @author Michael Simons
27+
*/
28+
public class LoginPage {
29+
30+
private final WebDriver webDriver;
31+
32+
private final LoginForm loginForm;
33+
34+
public LoginPage(WebDriver webDriver) {
35+
this.webDriver = webDriver;
36+
this.loginForm = PageFactory.initElements(this.webDriver, LoginForm.class);
37+
}
38+
39+
public LoginPage assertAt() {
40+
assertThat(this.webDriver.getTitle()).isEqualTo("Login Page");
41+
return this;
42+
}
43+
44+
public LoginForm loginForm() {
45+
return this.loginForm;
46+
}
47+
48+
public static class LoginForm {
49+
private WebDriver webDriver;
50+
private WebElement username;
51+
private WebElement password;
52+
@FindBy(css = "input[type=submit]")
53+
private WebElement submit;
54+
55+
public LoginForm(WebDriver webDriver) {
56+
this.webDriver = webDriver;
57+
}
58+
59+
public LoginForm username(String username) {
60+
this.username.sendKeys(username);
61+
return this;
62+
}
63+
64+
public LoginForm password(String password) {
65+
this.password.sendKeys(password);
66+
return this;
67+
}
68+
69+
public HomePage submit() {
70+
this.submit.click();
71+
return PageFactory.initElements(this.webDriver, HomePage.class);
72+
}
73+
}
74+
}

samples/javaconfig/messages/spring-security-samples-javaconfig-messages.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
apply plugin: 'io.spring.convention.spring-sample-war'
24

35
dependencies {

0 commit comments

Comments
 (0)