Skip to content

Commit 0af95ee

Browse files
committed
Merge pull request #190 from arjantijms/master
Replaced httpunit by htmlunit
2 parents 4dc1bce + a525570 commit 0af95ee

File tree

11 files changed

+186
-203
lines changed

11 files changed

+186
-203
lines changed

jaspic/basic-authentication/src/test/java/org/javaee7/jaspic/basicauthentication/BasicAuthenticationProtectedTest.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@
44
import static org.junit.Assert.assertTrue;
55

66
import java.io.IOException;
7-
import java.net.URL;
87

98
import org.javaee7.jaspic.common.ArquillianBase;
109
import org.jboss.arquillian.container.test.api.Deployment;
1110
import org.jboss.arquillian.junit.Arquillian;
12-
import org.jboss.arquillian.test.api.ArquillianResource;
1311
import org.jboss.shrinkwrap.api.spec.WebArchive;
1412
import org.junit.Test;
1513
import org.junit.runner.RunWith;
1614
import org.xml.sax.SAXException;
1715

18-
import com.meterware.httpunit.GetMethodWebRequest;
19-
import com.meterware.httpunit.WebConversation;
20-
import com.meterware.httpunit.WebResponse;
21-
2216
/**
2317
* This tests that we can login from a protected resource (a resource for which security constraints have been set) and then
2418
* access it.
@@ -29,31 +23,27 @@
2923
@RunWith(Arquillian.class)
3024
public class BasicAuthenticationProtectedTest extends ArquillianBase {
3125

32-
@ArquillianResource
33-
private URL base;
34-
3526
@Deployment(testable = false)
3627
public static WebArchive createDeployment() {
3728
return defaultArchive();
3829
}
3930

4031
@Test
4132
public void testProtectedPageNotLoggedin() throws IOException, SAXException {
42-
43-
WebResponse getResponse = new WebConversation().getResponse(new GetMethodWebRequest(base + "protected/servlet"));
33+
34+
String response = getFromServerPath("protected/servlet");
4435

4536
// Not logged-in thus should not be accessible.
46-
assertFalse(getResponse.getText().contains("This is a protected servlet"));
37+
assertFalse(response.contains("This is a protected servlet"));
4738
}
4839

4940
@Test
5041
public void testProtectedPageLoggedin() throws IOException, SAXException {
51-
52-
WebResponse getResponse = new WebConversation().getResponse(new GetMethodWebRequest(base
53-
+ "protected/servlet?doLogin=true"));
42+
43+
String response = getFromServerPath("protected/servlet?doLogin=true");
5444

5545
// Now has to be logged-in so page is accessible
56-
assertTrue(getResponse.getText().contains("This is a protected servlet"));
46+
assertTrue(response.contains("This is a protected servlet"));
5747
}
5848

5949
}

jaspic/basic-authentication/src/test/java/org/javaee7/jaspic/basicauthentication/BasicAuthenticationPublicTest.java

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@
33
import static org.junit.Assert.assertTrue;
44

55
import java.io.IOException;
6-
import java.net.URL;
76

87
import org.javaee7.jaspic.common.ArquillianBase;
98
import org.jboss.arquillian.container.test.api.Deployment;
109
import org.jboss.arquillian.junit.Arquillian;
11-
import org.jboss.arquillian.test.api.ArquillianResource;
1210
import org.jboss.shrinkwrap.api.spec.WebArchive;
1311
import org.junit.Test;
1412
import org.junit.runner.RunWith;
1513
import org.xml.sax.SAXException;
1614

17-
import com.meterware.httpunit.GetMethodWebRequest;
18-
import com.meterware.httpunit.WebConversation;
19-
import com.meterware.httpunit.WebResponse;
20-
2115
/**
2216
* This tests that we can login from a public page (a page for which no security constraints have been set).
2317
*
@@ -27,66 +21,62 @@
2721
@RunWith(Arquillian.class)
2822
public class BasicAuthenticationPublicTest extends ArquillianBase {
2923

30-
@ArquillianResource
31-
private URL base;
32-
3324
@Deployment(testable = false)
3425
public static WebArchive createDeployment() {
3526
return defaultArchive();
3627
}
3728

3829
@Test
3930
public void testPublicPageNotLoggedin() throws IOException, SAXException {
40-
41-
WebResponse response = new WebConversation().getResponse(new GetMethodWebRequest(base + "public/servlet"));
31+
32+
String response = getFromServerPath("public/servlet");
4233

4334
// Not logged-in
44-
assertTrue(response.getText().contains("web username: null"));
45-
assertTrue(response.getText().contains("web user has role \"architect\": false"));
35+
assertTrue(response.contains("web username: null"));
36+
assertTrue(response.contains("web user has role \"architect\": false"));
4637
}
4738

4839
@Test
4940
public void testPublicPageLoggedin() throws IOException, SAXException {
5041

5142
// JASPIC has to be able to authenticate a user when accessing a public (non-protected) resource.
52-
53-
WebResponse response = new WebConversation().getResponse(new GetMethodWebRequest(base + "public/servlet?doLogin"));
43+
44+
String response = getFromServerPath("public/servlet?doLogin");
5445

5546
// Now has to be logged-in
56-
assertTrue(response.getText().contains("web username: test"));
57-
assertTrue(response.getText().contains("web user has role \"architect\": true"));
47+
assertTrue(response.contains("web username: test"));
48+
assertTrue(response.contains("web user has role \"architect\": true"));
5849
}
5950

6051
@Test
6152
public void testPublicPageNotRememberLogin() throws IOException, SAXException {
6253

63-
WebConversation conversion = new WebConversation();
6454

6555
// -------------------- Request 1 ---------------------------
66-
67-
WebResponse response = conversion.getResponse(new GetMethodWebRequest(base + "public/servlet"));
56+
57+
String response = getFromServerPath("public/servlet");
6858

6959
// Not logged-in
70-
assertTrue(response.getText().contains("web username: null"));
71-
assertTrue(response.getText().contains("web user has role \"architect\": false"));
60+
assertTrue(response.contains("web username: null"));
61+
assertTrue(response.contains("web user has role \"architect\": false"));
7262

73-
System.out.println(response.getHeaderField("cookie"));
7463

7564
// -------------------- Request 2 ---------------------------
7665

77-
response = new WebConversation().getResponse(new GetMethodWebRequest(base + "public/servlet?doLogin"));
66+
response = getFromServerPath("public/servlet?doLogin");
7867

7968
// Now has to be logged-in
80-
assertTrue(response.getText().contains("web username: test"));
81-
assertTrue(response.getText().contains("web user has role \"architect\": true"));
69+
assertTrue(response.contains("web username: test"));
70+
assertTrue(response.contains("web user has role \"architect\": true"));
8271

72+
8373
// -------------------- Request 3 ---------------------------
8474

85-
response = conversion.getResponse(new GetMethodWebRequest(base + "public/servlet"));
75+
response = getFromServerPath("public/servlet");
8676

8777
// Not logged-in
88-
assertTrue(response.getText().contains("web username: null"));
89-
assertTrue(response.getText().contains("web user has role \"architect\": false"));
78+
assertTrue(response.contains("web username: null"));
79+
assertTrue(response.contains("web user has role \"architect\": false"));
9080
}
9181

9282
}

jaspic/basic-authentication/src/test/java/org/javaee7/jaspic/basicauthentication/BasicAuthenticationStatelessTest.java

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@
44
import static org.junit.Assert.assertTrue;
55

66
import java.io.IOException;
7-
import java.net.URL;
87

98
import org.javaee7.jaspic.common.ArquillianBase;
109
import org.jboss.arquillian.container.test.api.Deployment;
1110
import org.jboss.arquillian.junit.Arquillian;
12-
import org.jboss.arquillian.test.api.ArquillianResource;
1311
import org.jboss.shrinkwrap.api.spec.WebArchive;
1412
import org.junit.Test;
1513
import org.junit.runner.RunWith;
1614
import org.xml.sax.SAXException;
1715

18-
import com.meterware.httpunit.GetMethodWebRequest;
19-
import com.meterware.httpunit.WebConversation;
20-
import com.meterware.httpunit.WebResponse;
21-
2216
/**
2317
*
2418
* @author Arjan Tijms
@@ -27,30 +21,28 @@
2721
@RunWith(Arquillian.class)
2822
public class BasicAuthenticationStatelessTest extends ArquillianBase {
2923

30-
@ArquillianResource
31-
private URL base;
32-
3324
@Deployment(testable = false)
3425
public static WebArchive createDeployment() {
3526
return defaultArchive();
3627
}
28+
3729

3830
/**
3931
* Tests that access to a protected page does not depend on the authenticated identity that was established in a previous
4032
* request.
4133
*/
4234
@Test
4335
public void testProtectedAccessIsStateless() throws IOException, SAXException {
44-
45-
WebConversation conversion = new WebConversation();
36+
4637

4738
// -------------------- Request 1 ---------------------------
4839

4940
// Accessing protected page without login
50-
WebResponse response = conversion.getResponse(new GetMethodWebRequest(base + "protected/servlet"));
51-
41+
String response = getFromServerPath("protected/servlet");
42+
5243
// Not logged-in thus should not be accessible.
53-
assertFalse(response.getText().contains("This is a protected servlet"));
44+
assertFalse(response.contains("This is a protected servlet"));
45+
5446

5547
// -------------------- Request 2 ---------------------------
5648

@@ -61,25 +53,26 @@ public void testProtectedAccessIsStateless() throws IOException, SAXException {
6153
// we're not authenticated and it will deny further attempts to authenticate. This may happen when
6254
// the container does not correctly recognize the JASPIC protocol for "do nothing".
6355

64-
response = conversion.getResponse(new GetMethodWebRequest(base + "protected/servlet?doLogin"));
56+
response = getFromServerPath("protected/servlet?doLogin");
6557

6658
// Now has to be logged-in so page is accessible
6759
assertTrue("Could not access protected page, but should be able to. "
6860
+ "Did the container remember the previously set 'unauthenticated identity'?",
69-
response.getText().contains("This is a protected servlet"));
61+
response.contains("This is a protected servlet"));
62+
7063

7164
// -------------------- Request 3 ---------------------------
7265

7366
// JASPIC is stateless and login (re-authenticate) has to happen for every request
7467
//
7568
// In the following method we do a call without logging in after one where we did login.
7669
// The container should not remember this login and has to deny access.
77-
response = conversion.getResponse(new GetMethodWebRequest(base + "protected/servlet"));
70+
response = getFromServerPath("protected/servlet");
7871

7972
// Not logged-in thus should not be accessible.
8073
assertFalse("Could access protected page, but should not be able to. "
81-
+ "Did the container remember the authenticated identity that was set in previous request?", response.getText()
82-
.contains("This is a protected servlet"));
74+
+ "Did the container remember the authenticated identity that was set in previous request?",
75+
response.contains("This is a protected servlet"));
8376
}
8477

8578
/**
@@ -89,12 +82,11 @@ public void testProtectedAccessIsStateless() throws IOException, SAXException {
8982
@Test
9083
public void testProtectedAccessIsStateless2() throws IOException, SAXException {
9184

92-
WebConversation conversion = new WebConversation();
93-
9485
// -------------------- Request 1 ---------------------------
9586

9687
// Start with doing a login
97-
WebResponse response = conversion.getResponse(new GetMethodWebRequest(base + "protected/servlet?doLogin"));
88+
String response = getFromServerPath("protected/servlet?doLogin");
89+
9890

9991
// -------------------- Request 2 ---------------------------
10092

@@ -104,13 +96,12 @@ public void testProtectedAccessIsStateless2() throws IOException, SAXException {
10496
// The container should not remember this login and has to deny access.
10597

10698
// Accessing protected page without login
107-
108-
response = conversion.getResponse(new GetMethodWebRequest(base + "protected/servlet"));
99+
response = getFromServerPath("protected/servlet");
109100

110101
// Not logged-in thus should not be accessible.
111102
assertFalse("Could access protected page, but should not be able to. "
112-
+ "Did the container remember the authenticated identity that was set in previous request?", response.getText()
113-
.contains("This is page A."));
103+
+ "Did the container remember the authenticated identity that was set in previous request?",
104+
response.contains("This is a protected servlet"));
114105
}
115106

116107
/**
@@ -119,28 +110,28 @@ public void testProtectedAccessIsStateless2() throws IOException, SAXException {
119110
*/
120111
@Test
121112
public void testUserIdentityIsStateless() throws IOException, SAXException {
122-
123-
WebConversation conversion = new WebConversation();
113+
124114

125115
// -------------------- Request 1 ---------------------------
126116

127117
// Accessing protected page with login
128-
WebResponse response = conversion.getResponse(new GetMethodWebRequest(base + "protected/servlet?doLogin"));
118+
String response = getFromServerPath("protected/servlet?doLogin");
119+
129120

130121
// -------------------- Request 2 ---------------------------
131122

132123
// Accessing public page without login
133-
response = conversion.getResponse(new GetMethodWebRequest(base + "public/servlet"));
124+
response = getFromServerPath("public/servlet");
134125

135126
// No details should linger around
136127
assertFalse("User principal was 'test', but it should be null here. "
137128
+ "The container seemed to have remembered it from the previous request.",
138-
response.getText().contains("web username: test"));
129+
response.contains("web username: test"));
139130
assertTrue("User principal was not null, but it should be null here. ",
140-
response.getText().contains("web username: null"));
131+
response.contains("web username: null"));
141132
assertTrue("The unauthenticated user has the role 'architect', which should not be the case. "
142133
+ "The container seemed to have remembered it from the previous request.",
143-
response.getText().contains("web user has role \"architect\": false"));
134+
response.contains("web user has role \"architect\": false"));
144135
}
145136

146137
}

jaspic/common/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,28 @@
1616
<version>1.0-SNAPSHOT</version>
1717
<packaging>jar</packaging>
1818

19+
<!--
20+
Normally these are all test dependencies, but this module needs them in the compile phase since
21+
it provides a base class for unit tests
22+
-->
1923
<dependencies>
2024
<dependency>
2125
<groupId>org.jboss.arquillian.junit</groupId>
2226
<artifactId>arquillian-junit-container</artifactId>
2327
<scope>provided</scope>
2428
</dependency>
29+
<dependency>
30+
<groupId>junit</groupId>
31+
<artifactId>junit</artifactId>
32+
<version>4.11</version>
33+
<scope>provided</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>net.sourceforge.htmlunit</groupId>
37+
<artifactId>htmlunit</artifactId>
38+
<version>2.13</version>
39+
<scope>provided</scope>
40+
</dependency>
2541
</dependencies>
2642

2743
</project>

0 commit comments

Comments
 (0)