1818import javax .ws .rs .client .ClientBuilder ;
1919import javax .ws .rs .client .Entity ;
2020import javax .ws .rs .client .WebTarget ;
21+ import javax .ws .rs .core .MultivaluedHashMap ;
2122
2223import org .jboss .arquillian .container .test .api .Deployment ;
2324import org .jboss .arquillian .junit .Arquillian ;
@@ -36,8 +37,8 @@ public class MyResourceTest {
3637
3738 @ Deployment (testable = false )
3839 public static WebArchive createDeployment () {
39- return ShrinkWrap .create (WebArchive .class )
40- .addClasses (MyApplication .class , MyResource .class );
40+ return ShrinkWrap .create (WebArchive .class )
41+ .addClasses (MyApplication .class , MyResource .class );
4142 }
4243 private static WebTarget target ;
4344
@@ -66,4 +67,53 @@ public void testValidRequest() {
6667 assertEquals ("foo" , r );
6768 }
6869
70+ @ Test
71+ public void testValidPostRequest () {
72+ MultivaluedHashMap <String , String > map = new MultivaluedHashMap <>();
73+ map .add ("name" , "Penny" );
74+ map .add ("age" , "1" );
75+ target .request ().post (Entity .form (map ));
76+
77+ map .clear ();
78+ map .add ("name" , "Leonard" );
79+ map .add ("age" , "2" );
80+ target .request ().post (Entity .form (map ));
81+ }
82+
83+ @ Test
84+ public void testInvalidPostRequest () {
85+ try {
86+ MultivaluedHashMap <String , String > map = new MultivaluedHashMap <>();
87+ map .add ("name" , null );
88+ map .add ("age" , "1" );
89+ target .request ().post (Entity .form (map ));
90+ } catch (BadRequestException e ) {
91+ assertNotNull (e );
92+ }
93+ }
94+
95+ @ Test
96+ public void testInvalidPostRequestLesserAge () {
97+ try {
98+ MultivaluedHashMap <String , String > map = new MultivaluedHashMap <>();
99+ map .add ("name" , "Penny" );
100+ map .add ("age" , "0" );
101+ target .request ().post (Entity .form (map ));
102+ } catch (BadRequestException e ) {
103+ assertNotNull (e );
104+ }
105+ }
106+
107+ @ Test
108+ public void testInvalidPostRequestGreaterAge () {
109+ try {
110+ MultivaluedHashMap <String , String > map = new MultivaluedHashMap <>();
111+ map .add ("name" , "Penny" );
112+ map .add ("age" , "11" );
113+ target .request ().post (Entity .form (map ));
114+ } catch (BadRequestException e ) {
115+ assertNotNull (e );
116+ }
117+ }
118+
69119}
0 commit comments