11package org .javaee8 .servlet .mapping ;
22
33import static org .jboss .shrinkwrap .api .ShrinkWrap .create ;
4- import static org .junit .Assert .assertEquals ;
4+ import static org .junit .Assert .assertTrue ;
55
66import java .io .IOException ;
77import java .net .URL ;
88
9- import org .javaee8 .servlet .mapping .Servlet ;
9+ import javax .servlet .http .MappingMatch ;
10+
1011import org .jboss .arquillian .container .test .api .Deployment ;
12+ import org .jboss .arquillian .container .test .api .RunAsClient ;
1113import org .jboss .arquillian .junit .Arquillian ;
1214import org .jboss .arquillian .test .api .ArquillianResource ;
1315import org .jboss .shrinkwrap .api .spec .WebArchive ;
1416import org .junit .After ;
1517import org .junit .Before ;
1618import org .junit .Test ;
1719import org .junit .runner .RunWith ;
18- import org .xml .sax .SAXException ;
1920
2021import com .gargoylesoftware .htmlunit .TextPage ;
2122import com .gargoylesoftware .htmlunit .WebClient ;
@@ -31,7 +32,7 @@ public class ServletMappingTest {
3132
3233 private WebClient webClient ;
3334
34- @ Deployment ( testable = false )
35+ @ Deployment
3536 public static WebArchive createDeployment () {
3637 return create (WebArchive .class )
3738 .addClass (Servlet .class );
@@ -46,15 +47,82 @@ public void setup() {
4647 public void teardown () {
4748 webClient .close ();
4849 }
50+
51+ @ Test
52+ @ RunAsClient
53+ public void testPath () throws IOException {
54+
55+ // Test Servet is mapped to /path/*, so name after "/path/*" can be anything
56+ TextPage page = webClient .getPage (base + "path/foo" );
57+ String content = page .getContent ();
58+
59+ System .out .println ("\n Content for `" + base + "path/foo" + "` :\n " + content + "\n " );
60+
61+ assertTrue (content .contains ("Mapping match:" + MappingMatch .PATH .name ()));
62+ assertTrue (content .contains ("Match value:foo" ));
63+ assertTrue (content .contains ("Pattern:/path/*" ));
64+ }
4965
5066 @ Test
51- public void testGet () throws IOException {
67+ @ RunAsClient
68+ public void testExtension () throws IOException {
69+
70+ // Test Servet is mapped to *.ext, so name before ".ext" can be anything
5271 TextPage page = webClient .getPage (base + "foo.ext" );
72+ String content = page .getContent ();
73+
74+ System .out .println ("\n Content for `" + base + "foo.ext" + "` :\n " + content + "\n " );
75+
76+ assertTrue (content .contains ("Mapping match:" + MappingMatch .EXTENSION .name ()));
77+ assertTrue (content .contains ("Match value:foo" ));
78+ assertTrue (content .contains ("Pattern:*.ext" ));
79+ }
80+
81+ @ Test
82+ @ RunAsClient
83+ public void testRoot () throws IOException {
84+
85+ // Test Servet is mapped to the root of the web application
86+ TextPage page = webClient .getPage (base );
87+ String content = page .getContent ();
5388
54- System .out .println (page . getContent () );
89+ System .out .println (" \n Content for `" + base + "` : \n " + content + " \n " );
5590
56- assertEquals ("" , "" );
91+ assertTrue (content .contains ("Mapping match:" + MappingMatch .CONTEXT_ROOT .name ()));
92+ assertTrue (content .contains ("Match value:" ));
93+ assertTrue (content .contains ("Pattern:/" ));
5794 }
95+
96+ @ Test
97+ @ RunAsClient
98+ public void testDefault () throws IOException {
99+
100+ // Test Servet is mapped to the "default", which is a fallback if nothing else matches
101+ TextPage page = webClient .getPage (base + "doesnotexist" );
102+ String content = page .getContent ();
103+
104+ System .out .println ("\n Content for `" + base + "doesnotexist" + "` :\n " + content + "\n " );
105+
106+ assertTrue (content .contains ("Mapping match:" + MappingMatch .DEFAULT .name ()));
107+ assertTrue (content .contains ("Match value:doesnotexist" ));
108+ assertTrue (content .contains ("Pattern:/" ));
109+ }
110+
111+ @ Test
112+ @ RunAsClient
113+ public void testExact () throws IOException {
114+
115+ // Test Servet is mapped to an exact name ("/exact"), which is thus not a wildcard of any kind
116+ TextPage page = webClient .getPage (base + "exact" );
117+ String content = page .getContent ();
118+
119+ System .out .println ("\n Content for `" + base + "exact" + "` :\n " + content + "\n " );
120+
121+ assertTrue (content .contains ("Mapping match:" + MappingMatch .EXACT .name ()));
122+ assertTrue (content .contains ("Match value:exact" ));
123+ assertTrue (content .contains ("Pattern:/exact" ));
124+ }
125+
58126
59127
60128}
0 commit comments