Improvements to itest-web subproject.

Added to gradle build. Updated deps (testng and jwebunit). New test added for persistent remember-me.
This commit is contained in:
Luke Taylor 2010-02-08 23:57:04 +00:00
parent 70ef0d8b3e
commit e678ba7283
5 changed files with 87 additions and 9 deletions

View File

@ -0,0 +1,29 @@
dependencies {
compile "org.springframework:spring-context:$springVersion",
"org.springframework:spring-web:$springVersion",
'javax.servlet:servlet-api:2.5'
testCompile project(':spring-security-core'),
project(':spring-security-web'),
"org.springframework:spring-core:$springVersion",
"org.springframework:spring-beans:$springVersion",
"org.springframework:spring-webmvc:$springVersion",
"org.mortbay.jetty:jetty:$jettyVersion",
"org.mortbay.jetty:jetty-util:$jettyVersion",
'net.sourceforge.jwebunit:jwebunit-core:2.2',
"org.testng:testng:5.11:jdk15"
testRuntime project(':spring-security-config'),
project(':spring-security-ldap'),
"org.mortbay.jetty:jsp-2.1-jetty:$jettyVersion",
'net.sourceforge.jwebunit:jwebunit-htmlunit-plugin:2.2'
}
test {
useTestNG();
options {
jvmArgs = ["-ea", '-Xms128m', '-Xmx500m']
systemProperties = ['webapp.dir': "$projectDir/src/main/webapp"]
}
}

View File

@ -14,14 +14,14 @@
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
<artifactId>testng</artifactId> <artifactId>testng</artifactId>
<version>5.8</version> <version>5.11</version>
<scope>test</scope> <scope>test</scope>
<classifier>jdk15</classifier> <classifier>jdk15</classifier>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.sourceforge.jwebunit</groupId> <groupId>net.sourceforge.jwebunit</groupId>
<artifactId>jwebunit-htmlunit-plugin</artifactId> <artifactId>jwebunit-htmlunit-plugin</artifactId>
<version>2.1</version> <version>2.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,6 +1,9 @@
package org.springframework.security.integration; package org.springframework.security.integration;
import java.util.List;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import javax.servlet.http.Cookie;
import net.sourceforge.jwebunit.junit.WebTester; import net.sourceforge.jwebunit.junit.WebTester;
@ -16,6 +19,7 @@ import org.springframework.web.servlet.DispatcherServlet;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
/** /**
* Base class which allows the application to be started with a particular Spring application * Base class which allows the application to be started with a particular Spring application
@ -50,14 +54,15 @@ public abstract class AbstractWebServerIntegrationTests {
server = new Server(0); server = new Server(0);
server.addHandler(createWebContext()); server.addHandler(createWebContext());
server.start(); server.start();
tester.getTestContext().setBaseUrl(getBaseUrl());
} }
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private WebAppContext createWebContext() { private WebAppContext createWebContext() {
WebAppContext webCtx = new WebAppContext("src/main/webapp", getContextPath()); String webappDir = System.getProperty("webapp.dir");
WebAppContext webCtx = new WebAppContext(webappDir == null ? "src/main/webapp" : webappDir, getContextPath());
if (StringUtils.hasText(getContextConfigLocations())) { if (StringUtils.hasText(getContextConfigLocations())) {
webCtx.addEventListener(new ContextLoaderListener()); webCtx.addEventListener(new ContextLoaderListener());
@ -83,9 +88,15 @@ public abstract class AbstractWebServerIntegrationTests {
} }
} }
@BeforeMethod
public void initializeTester() {
tester.getTestContext().setBaseUrl(getBaseUrl());
}
@AfterMethod @AfterMethod
public void resetWebConversation() { public void resetWebConversation() {
tester.closeBrowser(); tester.closeBrowser();
tester.setTestContext(null);
} }
protected final String getBaseUrl() { protected final String getBaseUrl() {
@ -104,9 +115,16 @@ public abstract class AbstractWebServerIntegrationTests {
return appCtx; return appCtx;
} }
// protected final HttpUnitDialog getDialog() { @SuppressWarnings("unchecked")
// return tester.getDialog(); protected Cookie getRememberMeCookie() {
// } List<Cookie> cookies = (List<Cookie>) tester.getTestingEngine().getCookies();
for (Cookie c : cookies) {
if (c.getName().equals("SPRING_SECURITY_REMEMBER_ME_COOKIE")) {
return c;
}
}
return null;
}
protected final void submit() { protected final void submit() {
tester.submit(); tester.submit();

View File

@ -1,5 +1,9 @@
package org.springframework.security.integration; package org.springframework.security.integration;
import static org.testng.Assert.*;
import javax.servlet.http.Cookie;
import net.sourceforge.jwebunit.junit.WebTester; import net.sourceforge.jwebunit.junit.WebTester;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -55,6 +59,20 @@ public class InMemoryProviderWebAppTests extends AbstractWebServerIntegrationTes
assertTextPresent("I'm file?with?special?chars.htm"); assertTextPresent("I'm file?with?special?chars.htm");
} }
@Test
public void persistentLoginIsSuccesful() throws Exception {
beginAt("secure/index.html");
tester.checkCheckbox("_spring_security_remember_me");
login("jimi", "jimispassword");
Cookie rememberMe = getRememberMeCookie();
assertNotNull(rememberMe);
tester.closeBrowser();
tester.getTestContext().addCookie(rememberMe);
beginAt("secure/index.html");
assertTextPresent("A Secure Page");
}
@Test @Test
public void maxConcurrentLoginsValueIsRespected() throws Exception { public void maxConcurrentLoginsValueIsRespected() throws Exception {
System.out.println("Client: ******* First login ******* "); System.out.println("Client: ******* First login ******* ");

View File

@ -20,6 +20,10 @@ def String[] docs = [
'manual' 'manual'
] ]
def String[] itest = [
'web'
]
include modules include modules
modules.each {name -> modules.each {name ->
@ -37,15 +41,24 @@ samples.each {name ->
p.projectDir = new File(settingsDir, "samples/${name}"); p.projectDir = new File(settingsDir, "samples/${name}");
} }
include itest
itest.each { name ->
p = findProject(":${name}")
p.name = "itest-${name}"
p.buildFileName = "itest-${name}.gradle"
p.projectDir = new File(settingsDir, "itest/${name}");
}
include docs include docs
docs.each{ name -> docs.each { name ->
p = findProject(":${name}") p = findProject(":${name}")
p.buildFileName = "${name}.gradle" p.buildFileName = "${name}.gradle"
p.projectDir = new File(settingsDir, "docs/${name}"); p.projectDir = new File(settingsDir, "docs/${name}");
} }
rootProject.children.each {project -> rootProject.children.each {project ->
assert project.buildFile.isFile()
assert project.projectDir.isDirectory() assert project.projectDir.isDirectory()
assert project.buildFile.isFile()
} }