11package org .javaee7 .jaspic .common ;
22
33import static java .lang .Boolean .getBoolean ;
4+ import static java .util .logging .Level .SEVERE ;
45import static org .jboss .shrinkwrap .api .ShrinkWrap .create ;
6+ import static org .jsoup .Jsoup .parse ;
7+ import static org .jsoup .parser .Parser .xmlParser ;
58
69import java .io .File ;
710import java .io .IOException ;
811import java .net .URL ;
12+ import java .util .logging .Logger ;
913
1014import org .jboss .arquillian .test .api .ArquillianResource ;
1115import org .jboss .shrinkwrap .api .Archive ;
1216import org .jboss .shrinkwrap .api .spec .EnterpriseArchive ;
1317import org .jboss .shrinkwrap .api .spec .WebArchive ;
1418import org .junit .After ;
1519import org .junit .Before ;
20+ import org .junit .Rule ;
21+ import org .junit .rules .TestWatcher ;
22+ import org .junit .runner .Description ;
1623
1724import com .gargoylesoftware .htmlunit .FailingHttpStatusCodeException ;
1825import com .gargoylesoftware .htmlunit .WebClient ;
2532public 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 \n Test failed: " +
48+ description .getClassName () + "." + description .getMethodName () +
49+
50+ "\n Message: " + e .getMessage () +
51+
52+ "\n Last 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