Skip to content

Commit fd8bb4d

Browse files
committed
Added printing of last response for JASPIC tests and updated .gitignore
1 parent 3568d3a commit fd8bb4d

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,10 @@ local.properties
9494

9595
# Testing environment specific
9696
derby.log
97+
98+
99+
######################
100+
# Liberty tools
101+
######################
102+
103+
.factorypath

jaspic/common/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<version>1.0-SNAPSHOT</version>
1313
<relativePath>../pom.xml</relativePath>
1414
</parent>
15-
<groupId>org.javaee7</groupId>
15+
1616
<artifactId>jaspic-common</artifactId>
17-
<version>1.0-SNAPSHOT</version>
17+
1818
<packaging>jar</packaging>
1919
<name>Java EE 7 Sample: jaspic - common</name>
2020

@@ -36,5 +36,10 @@
3636
<version>2.13</version>
3737
<scope>provided</scope>
3838
</dependency>
39+
<dependency>
40+
<groupId>org.jsoup</groupId>
41+
<artifactId>jsoup</artifactId>
42+
<version>1.9.1</version>
43+
</dependency>
3944
</dependencies>
4045
</project>

jaspic/common/src/main/java/org/javaee7/jaspic/common/ArquillianBase.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package org.javaee7.jaspic.common;
22

33
import static java.lang.Boolean.getBoolean;
4+
import static java.util.logging.Level.SEVERE;
45
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
6+
import static org.jsoup.Jsoup.parse;
7+
import static org.jsoup.parser.Parser.xmlParser;
58

69
import java.io.File;
710
import java.io.IOException;
811
import java.net.URL;
12+
import java.util.logging.Logger;
913

1014
import org.jboss.arquillian.test.api.ArquillianResource;
1115
import org.jboss.shrinkwrap.api.Archive;
1216
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
1317
import org.jboss.shrinkwrap.api.spec.WebArchive;
1418
import org.junit.After;
1519
import org.junit.Before;
20+
import org.junit.Rule;
21+
import org.junit.rules.TestWatcher;
22+
import org.junit.runner.Description;
1623

1724
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
1825
import com.gargoylesoftware.htmlunit.WebClient;
@@ -25,8 +32,38 @@
2532
public class ArquillianBase {
2633

2734
private static final String WEBAPP_SRC = "src/main/webapp";
35+
private static final Logger logger = Logger.getLogger(ArquillianBase.class.getName());
36+
2837
private WebClient webClient;
38+
private String response;
39+
40+
@Rule
41+
public TestWatcher ruleExample = new TestWatcher() {
42+
@Override
43+
protected void failed(Throwable e, Description description) {
44+
super.failed(e, description);
45+
46+
logger.log(SEVERE,
47+
"\n\nTest failed: " +
48+
description.getClassName() + "." + description.getMethodName() +
49+
50+
"\nMessage: " + e.getMessage() +
51+
52+
"\nLast response: " +
53+
54+
"\n\n" + formatHTML(response) + "\n\n");
55+
56+
}
57+
};
2958

59+
public static String formatHTML(String html) {
60+
try {
61+
return parse(html, "", xmlParser()).toString();
62+
} catch (Exception e) {
63+
return html;
64+
}
65+
}
66+
3067
public static Archive<?> defaultArchive() {
3168
return tryWrapEAR(defaultWebArchive());
3269
}
@@ -48,6 +85,8 @@ public static Archive<?> tryWrapEAR(WebArchive webArchive) {
4885
create(EnterpriseArchive.class, "test.ear")
4986

5087
// Liberty needs to have the binding file in an ear.
88+
// TODO: this is no longer the case and this code can be removed (-bnd.xml
89+
// needs to be moved to correct place)
5190
.addAsManifestResource(resource("ibm-application-bnd.xml"))
5291

5392
// Web module
@@ -82,6 +121,8 @@ public void tearDown() {
82121
webClient.getCookieManager().clearCookies();
83122
webClient.closeAllWindows();
84123
}
124+
125+
85126

86127
protected WebClient getWebClient() {
87128
return webClient;
@@ -100,7 +141,9 @@ protected URL getBase() {
100141
*/
101142
protected String getFromServerPath(final String path) {
102143
try {
103-
return webClient.getPage(base + path).getWebResponse().getContentAsString();
144+
response = null;
145+
response = webClient.getPage(base + path).getWebResponse().getContentAsString();
146+
return response;
104147
} catch (FailingHttpStatusCodeException | IOException e) {
105148
throw new IllegalStateException(e);
106149
}

0 commit comments

Comments
 (0)