@@ -58,14 +58,22 @@ public class RestClientConfigurationTest extends PowerMockTestCase {
5858 setProperty ("readTimeout" , "20" );
5959 }};
6060
61- private Properties fakePropsWithUnproperAcceptMimeTypeAndContentMimeType = new Properties () {{
61+ private Properties fakePropsWithUnproperAcceptMimeType = new Properties () {{
6262 setProperty ("url" , "http://localhost:8080/jasperserver-pro/" );
63- setProperty ("contentMimeType" , "UnacceptableContentMimeType " );
63+ setProperty ("contentMimeType" , "XML " );
6464 setProperty ("acceptMimeType" , "UnacceptableAcceptMimeType" );
6565 setProperty ("connectionTimeout" , "" );
6666 setProperty ("readTimeout" , "" );
6767 }};
6868
69+ private Properties fakePropsWithUnproperContentMimeType = new Properties () {{
70+ setProperty ("url" , "http://localhost:8080/jasperserver-pro/" );
71+ setProperty ("contentMimeType" , "UnacceptableContentMimeType" );
72+ setProperty ("acceptMimeType" , "XML" );
73+ setProperty ("connectionTimeout" , "" );
74+ setProperty ("readTimeout" , "" );
75+ }};
76+
6977 @ Test (testName = "RestClientConfiguration_parametrized_constructor" )
7078 public void should_invoke_default_constructor_and_pass_valid_URL_to_setJasperReportsServerUrl_method () throws Exception {
7179 String fakedValidUrl = "http://localhost:8080/jasperserver-pro/" ;
@@ -113,7 +121,7 @@ public void should_load_configuration_from_property_file() throws Exception {
113121 assertNotNull (configuration .getTrustManagers ());
114122 }
115123
116- @ Test (testName = "loadConfiguration" , enabled = false )
124+ @ Test (testName = "loadConfiguration" )
117125 public void should_load_configuration_from_property_file_with_all_kind_of_setted_values () throws Exception {
118126 // Given
119127 mockStaticPartial (RestClientConfiguration .class , "loadProperties" );
@@ -134,6 +142,49 @@ public void should_load_configuration_from_property_file_with_all_kind_of_setted
134142 assertNotNull (configuration .getTrustManagers ());
135143 }
136144
145+
146+ @ Test (testName = "loadConfiguration" )
147+ public void should_load_configuration_from_property_file_with_unsupported_contentMimeType () throws Exception {
148+ // Given
149+ mockStaticPartial (RestClientConfiguration .class , "loadProperties" );
150+ Method [] methods = MemberMatcher .methods (RestClientConfiguration .class , "loadProperties" );
151+
152+ expectPrivate (RestClientConfiguration .class , methods [0 ], "superCoolPath" ).andReturn (fakePropsWithUnproperContentMimeType );
153+ replay (RestClientConfiguration .class );
154+
155+ // When
156+ RestClientConfiguration configuration = RestClientConfiguration .loadConfiguration ("superCoolPath" );
157+
158+ // Then
159+ assertEquals (configuration .getJasperReportsServerUrl (), fakePropsWithUnproperContentMimeType .getProperty ("url" ));
160+ assertEquals (configuration .getContentMimeType (), MimeType .JSON );
161+ assertEquals (configuration .getAcceptMimeType ().toString (), fakePropsWithUnproperContentMimeType .getProperty ("acceptMimeType" ));
162+ assertNull (configuration .getConnectionTimeout ());
163+ assertNull (configuration .getReadTimeout ());
164+ assertNotNull (configuration .getTrustManagers ());
165+ }
166+ @ Test (testName = "loadConfiguration" )
167+ public void should_load_configuration_from_property_file_with_unsupported_acceptMimeType () throws Exception {
168+ // Given
169+ mockStaticPartial (RestClientConfiguration .class , "loadProperties" );
170+ Method [] methods = MemberMatcher .methods (RestClientConfiguration .class , "loadProperties" );
171+
172+ expectPrivate (RestClientConfiguration .class , methods [0 ], "superCoolPath" ).andReturn (fakePropsWithUnproperAcceptMimeType );
173+ replay (RestClientConfiguration .class );
174+
175+ // When
176+ RestClientConfiguration configuration = RestClientConfiguration .loadConfiguration ("superCoolPath" );
177+
178+ // Then
179+ assertEquals (configuration .getJasperReportsServerUrl (), fakePropsWithUnproperAcceptMimeType .getProperty ("url" ));
180+ assertEquals (configuration .getContentMimeType ().toString (), fakePropsWithUnproperAcceptMimeType .getProperty ("contentMimeType" ));
181+ assertEquals (configuration .getAcceptMimeType (), MimeType .JSON );
182+ assertNull (configuration .getConnectionTimeout ());
183+ assertNull (configuration .getReadTimeout ());
184+ assertNotNull (configuration .getTrustManagers ());
185+ }
186+
187+
137188 @ Test (testName = "setJrsVersion" )
138189 public void should_set_setJrsVersion_field () throws IllegalAccessException {
139190 // Given
@@ -230,27 +281,38 @@ public void should_return_trusted_manager() throws Exception {
230281 }
231282
232283 @ Test (testName = "getAuthenticationType" )
233- public void should_return_not_null_value_of_authenticationType_field () throws Exception {
284+ public void should_return_not_null_default_value_of_authenticationType_field () throws Exception {
234285 // Given
235286 RestClientConfiguration config = new RestClientConfiguration ();
287+ //Then
236288 Field field = field (RestClientConfiguration .class , "authenticationType" );
237- // When
238289 Object retrieved = field .get (config );
239- //Then
240290 assertNotNull (retrieved );
241291 assertEquals (retrieved , AuthenticationType .SPRING );
242292
243293 }
244294
295+ @ Test (testName = "getAuthenticationType" )
296+ public void should_return_not_null_value_of_authenticationType_field () throws Exception {
297+ // Given
298+ RestClientConfiguration config = new RestClientConfiguration ();
299+ // When
300+ AuthenticationType authenticationType = config .getAuthenticationType ();
301+ //Then
302+ assertNotNull (authenticationType );
303+ assertEquals (authenticationType , AuthenticationType .SPRING );
304+
305+ }
306+
245307 @ Test (testName = "setAuthenticationType" )
246308 public void should_set_authenticationType_field () throws IllegalAccessException {
247309 // Given
248310 RestClientConfiguration config = new RestClientConfiguration ();
311+ // When
249312 config .setAuthenticationType (AuthenticationType .BASIC );
313+ //Then
250314 Field field = field (RestClientConfiguration .class , "authenticationType" );
251- // When
252315 Object retrieved = field .get (config );
253- //Then
254316 assertNotNull (retrieved );
255317 assertEquals (retrieved , AuthenticationType .BASIC );
256318 }
@@ -259,24 +321,35 @@ public void should_set_authenticationType_field() throws IllegalAccessException
259321 public void should_return_not_null_value_of_restrictedHttpMethods_field () throws Exception {
260322 // Given
261323 RestClientConfiguration config = new RestClientConfiguration ();
324+ //Then
262325 Field field = field (RestClientConfiguration .class , "restrictedHttpMethods" );
263- // When
264326 Object retrieved = field .get (config );
265- //Then
266327 assertNotNull (retrieved );
267328 assertEquals (retrieved , false );
268329
269330 }
270331
332+ @ Test (testName = "getRestrictedHttpMethods" )
333+ public void should_return_not_null_default_value_of_restrictedHttpMethods_field () throws Exception {
334+ // Given
335+ RestClientConfiguration config = new RestClientConfiguration ();
336+ // When
337+ Boolean retrieved = config .getRestrictedHttpMethods ();
338+ //Then
339+ assertNotNull (retrieved );
340+ assertEquals (retrieved , Boolean .FALSE );
341+
342+ }
343+
271344 @ Test (testName = "setRestrictedHttpMethods" )
272345 public void should_set_restrictedHttpMethods_field () throws IllegalAccessException {
273346 // Given
274347 RestClientConfiguration config = new RestClientConfiguration ();
348+ // When
275349 config .setRestrictedHttpMethods (true );
350+ //Then
276351 Field field = field (RestClientConfiguration .class , "restrictedHttpMethods" );
277- // When
278352 Object retrieved = field .get (config );
279- //Then
280353 assertNotNull (retrieved );
281354 assertEquals (retrieved , true );
282355 }
@@ -285,11 +358,11 @@ public void should_set_restrictedHttpMethods_field() throws IllegalAccessExcepti
285358 public void should_set_contentMimeType_field () throws IllegalAccessException {
286359 // Given
287360 RestClientConfiguration config = new RestClientConfiguration ();
361+ // When
288362 config .setContentMimeType (MimeType .XML );
363+ //Then
289364 Field field = field (RestClientConfiguration .class , "contentMimeType" );
290- // When
291365 Object retrieved = field .get (config );
292- //Then
293366 assertNotNull (retrieved );
294367 assertEquals (retrieved , MimeType .XML );
295368
@@ -299,23 +372,22 @@ public void should_set_contentMimeType_field() throws IllegalAccessException {
299372 public void should_get_not_null_contentMimeType_field () throws IllegalAccessException {
300373 // Given
301374 RestClientConfiguration config = new RestClientConfiguration ();
375+ //Then
302376 Field field = field (RestClientConfiguration .class , "contentMimeType" );
303- // When
304377 Object retrieved = field .get (config );
305- //Then
306378 assertNotNull (retrieved );
307379 assertEquals (retrieved , MimeType .JSON );
308380 }
309381
310- @ Test (testName = "geAcceptMimeType " )
382+ @ Test (testName = "getAcceptMimeType " )
311383 public void should_set_acceptMimeType_field () throws IllegalAccessException {
312384 // Given
313385 RestClientConfiguration config = new RestClientConfiguration ();
386+ // When
314387 config .setAcceptMimeType (MimeType .XML );
388+ //Then
315389 Field field = field (RestClientConfiguration .class , "acceptMimeType" );
316- // When
317390 Object retrieved = field .get (config );
318- //Then
319391 assertNotNull (retrieved );
320392 assertEquals (retrieved , MimeType .XML );
321393
@@ -325,12 +397,37 @@ public void should_set_acceptMimeType_field() throws IllegalAccessException {
325397 public void should_get_not_null_acceptMimeType_field () throws IllegalAccessException {
326398 // Given
327399 RestClientConfiguration config = new RestClientConfiguration ();
400+ //Then
328401 Field field = field (RestClientConfiguration .class , "acceptMimeType" );
329- // When
330402 Object retrieved = field .get (config );
331- //Then
332403 assertNotNull (retrieved );
333404 assertEquals (retrieved , MimeType .JSON );
334405 }
335406
407+ @ Test (testName = "setConnectionTimeout" )
408+ public void should_set_connectionTimeout_field () throws IllegalAccessException {
409+ // Given
410+ RestClientConfiguration config = new RestClientConfiguration ();
411+ // When
412+ config .setConnectionTimeout (100 );
413+ //Then
414+ Field field = field (RestClientConfiguration .class , "connectionTimeout" );
415+ Object retrieved = field .get (config );
416+ assertNotNull (retrieved );
417+ assertEquals (retrieved , 100 );
418+
419+ }
420+
421+ @ Test (testName = "setReadTimeout" )
422+ public void should_set_readTimeout_field () throws IllegalAccessException {
423+ // Given
424+ RestClientConfiguration config = new RestClientConfiguration ();
425+ // When
426+ config .setReadTimeout (100 );
427+ //Then
428+ Field field = field (RestClientConfiguration .class , "readTimeout" );
429+ Object retrieved = field .get (config );
430+ assertNotNull (retrieved );
431+ assertEquals (retrieved , 100 );
432+ }
336433}
0 commit comments