1+ /*
2+ * Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+ package org .ocpsoft .rewrite .gwt .config ;
17+
18+ import junit .framework .Assert ;
19+
20+ import org .apache .http .client .methods .HttpGet ;
21+ import org .apache .http .client .methods .HttpHead ;
22+ import org .jboss .arquillian .container .test .api .Deployment ;
23+ import org .jboss .arquillian .junit .Arquillian ;
24+ import org .jboss .shrinkwrap .api .asset .StringAsset ;
25+ import org .jboss .shrinkwrap .api .spec .WebArchive ;
26+ import org .junit .Test ;
27+ import org .junit .runner .RunWith ;
28+ import org .ocpsoft .rewrite .config .ConfigurationProvider ;
29+ import org .ocpsoft .rewrite .gwt .server .history .HistoryRewriteConfiguration ;
30+ import org .ocpsoft .rewrite .test .HttpAction ;
31+ import org .ocpsoft .rewrite .test .RewriteTest ;
32+
33+ /**
34+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
35+ */
36+ @ RunWith (Arquillian .class )
37+ public class HistoryRewriteRootContextConfigurationTest extends RewriteTest
38+ {
39+ @ Deployment (testable = false )
40+ public static WebArchive getDeployment ()
41+ {
42+ WebArchive deployment = RewriteTest
43+ .getDeployment ("ROOT.war" )
44+ .addAsWebResource (new StringAsset ("" ), "index.html" )
45+ .addAsServiceProvider (ConfigurationProvider .class , HistoryRewriteConfiguration .class );
46+ return deployment ;
47+ }
48+
49+ @ Test
50+ public void testContextPathServedFromHeadRequest ()
51+ {
52+ HttpAction <HttpHead > action = head ("/?org.ocpsoft.rewrite.gwt.history.contextPath" );
53+ Assert .assertEquals (200 , action .getResponse ().getStatusLine ().getStatusCode ());
54+
55+ Assert .assertEquals (action .getContextPath (),
56+ action .getResponseHeaderValues ("org.ocpsoft.rewrite.gwt.history.contextPath" ).get (0 ));
57+ }
58+
59+ @ Test
60+ public void testContextPathNotServedFromGetRequest ()
61+ {
62+ HttpAction <HttpGet > action = get ("/index.html?org.ocpsoft.rewrite.gwt.history.contextPath" );
63+ Assert .assertEquals (200 , action .getResponse ().getStatusLine ().getStatusCode ());
64+
65+ Assert .assertTrue (action .getResponseHeaderValues ("org.ocpsoft.rewrite.gwt.history.contextPath" ).isEmpty ());
66+ }
67+
68+ @ Test
69+ public void testContextPathServedFromCookieOnNormalRequest ()
70+ {
71+ HttpAction <HttpGet > action = get ("/index.html" );
72+ Assert .assertEquals (200 , action .getResponse ().getStatusLine ().getStatusCode ());
73+
74+ String cookie = action .getResponseHeaderValues ("Set-Cookie" ).get (0 );
75+ Assert .assertTrue (cookie .contains ("org.ocpsoft.rewrite.gwt.history.contextPath=" + action .getContextPath ()));
76+ }
77+
78+ }
0 commit comments