Skip to content

Commit cd3449b

Browse files
michael-simonsrwinch
authored andcommitted
Migrate javaconfig-form groovy->java
See #4939
1 parent 196f027 commit cd3449b

File tree

7 files changed

+230
-128
lines changed

7 files changed

+230
-128
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
apply plugin: 'io.spring.convention.spring-sample-war'
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+
*/
216

17+
apply plugin: 'io.spring.convention.spring-sample-war'
318

419
dependencies {
520
compile project(':spring-security-config')
@@ -9,7 +24,6 @@ dependencies {
924
compile 'javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api'
1025
compile 'javax.validation:validation-api'
1126
compile 'org.hibernate:hibernate-validator'
12-
compile 'org.springframework:spring-jdbc'
1327
compile 'org.springframework:spring-webmvc'
1428
compile slf4jDependencies
1529

@@ -18,5 +32,5 @@ dependencies {
1832

1933
runtime 'opensymphony:sitemesh'
2034

21-
integrationTestCompile gebDependencies
35+
integrationTestCompile seleniumDependencies
2236
}

samples/javaconfig/form/src/integration-test/groovy/org/springframework/security/samples/FormJcTests.groovy

-56
This file was deleted.

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

-32
This file was deleted.

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

-37
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
26+
/**
27+
* @author Michael Simons
28+
*/
29+
public class FormJcTests {
30+
private WebDriver driver;
31+
32+
private int port;
33+
34+
@Before
35+
public void setup() {
36+
this.port = Integer.parseInt(System.getProperty("app.httpPort"));
37+
this.driver = new HtmlUnitDriver();
38+
}
39+
40+
@After
41+
public void tearDown() {
42+
this.driver.quit();
43+
}
44+
45+
@Test
46+
public void accessHomePageWithUnauthenticatedUserSendsToLoginPage() {
47+
final LoginPage loginPage = HomePage.to(this.driver, this.port);
48+
loginPage.assertAt();
49+
}
50+
51+
@Test
52+
public void authenticatedUserIsSentToOriginalPage() {
53+
final String userName = "user";
54+
final HomePage homePage = HomePage.to(this.driver, this.port)
55+
.loginForm()
56+
.username(userName)
57+
.password("password")
58+
.submit();
59+
homePage
60+
.assertAt()
61+
.andTheUserNameDisplayedIs(userName);
62+
}
63+
64+
@Test
65+
public void authenticatedUserLogsOut() {
66+
LoginPage loginPage = HomePage.to(this.driver, this.port)
67+
.loginForm()
68+
.username("user")
69+
.password("password")
70+
.submit()
71+
.logout();
72+
loginPage.assertAt();
73+
74+
loginPage = HomePage.to(this.driver, this.port);
75+
loginPage.assertAt();
76+
}
77+
}
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()).isEqualTo("SecureMail: 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("SecureMail: Please Login");
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 = "button[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+
}

0 commit comments

Comments
 (0)