1+ /*
2+ * Copyright 2011 <a href="mailto:fabmars@gmail.com">Fabien Marsaud</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 .servlet .config ;
17+
18+ import junit .framework .Assert ;
19+
20+ import org .apache .http .client .methods .HttpGet ;
21+ import org .jboss .arquillian .container .test .api .Deployment ;
22+ import org .jboss .arquillian .junit .Arquillian ;
23+ import org .jboss .shrinkwrap .api .spec .WebArchive ;
24+ import org .junit .Test ;
25+ import org .junit .runner .RunWith ;
26+ import org .ocpsoft .rewrite .config .ConfigurationProvider ;
27+ import org .ocpsoft .rewrite .servlet .ServletRoot ;
28+ import org .ocpsoft .rewrite .test .HttpAction ;
29+ import org .ocpsoft .rewrite .test .RewriteTest ;
30+
31+ /**
32+ * @author <a href="mailto:fabmars@gmail.com">Fabien Marsaud</a>
33+ */
34+ @ RunWith (Arquillian .class )
35+ public class RequestNullBindingTest extends RewriteTest
36+ {
37+ @ Deployment (testable = false )
38+ public static WebArchive getDeployment ()
39+ {
40+ WebArchive deployment = RewriteTest
41+ .getDeployment ()
42+ .addPackages (true , ServletRoot .class .getPackage ())
43+ .addAsServiceProvider (ConfigurationProvider .class , RequestNullBindingTestProvider .class );
44+ return deployment ;
45+ }
46+
47+ //"123" should be converted to 123L, OK
48+ @ Test
49+ public void testNotNullBinding () throws Exception
50+ {
51+ HttpAction <HttpGet > action = get ("/foo/123" );
52+ Assert .assertEquals (200 , action .getResponse ().getStatusLine ().getStatusCode ());
53+ }
54+
55+ //"abc" can't be converted to Long so we're expecting an error 500 here.
56+ @ Test
57+ public void testNonLongBinding () throws Exception
58+ {
59+ HttpAction <HttpGet > action = get ("/foo/abc" );
60+ Assert .assertEquals (500 , action .getResponse ().getStatusLine ().getStatusCode ());
61+ }
62+
63+ // "" should be converted to null
64+ @ Test
65+ public void testNullBinding1 () throws Exception
66+ {
67+ HttpAction <HttpGet > action = get ("/foo/" );
68+ Assert .assertEquals (200 , action .getResponse ().getStatusLine ().getStatusCode ());
69+ }
70+
71+ // idem
72+ @ Test
73+ public void testNullBinding2 () throws Exception
74+ {
75+ HttpAction <HttpGet > action = get ("/bar//" );
76+ Assert .assertEquals (200 , action .getResponse ().getStatusLine ().getStatusCode ());
77+ }
78+ }
0 commit comments