11package com .jaspersoft .jasperserver .jaxrs .client .core ;
22
3+ import com .jaspersoft .jasperserver .jaxrs .client .core .enums .AuthenticationType ;
34import com .jaspersoft .jasperserver .jaxrs .client .core .enums .JRSVersion ;
5+ import com .jaspersoft .jasperserver .jaxrs .client .core .enums .MimeType ;
46import org .mockito .Mockito ;
57import org .powermock .api .mockito .PowerMockito ;
68import org .powermock .api .support .membermodification .MemberMatcher ;
@@ -134,18 +136,23 @@ public void should_load_configuration_from_property_file_with_all_kind_of_setted
134136
135137 @ Test (testName = "setJrsVersion" )
136138 public void should_set_setJrsVersion_field () throws IllegalAccessException {
139+ // Given
137140 RestClientConfiguration config = new RestClientConfiguration ();
138141 config .setJrsVersion (JRSVersion .v5_0_0 );
139142 Field field = field (RestClientConfiguration .class , "jrsVersion" );
143+ // When
140144 Object retrieved = field .get (config );
145+ //Then
141146 assertNotNull (retrieved );
142147 assertEquals (retrieved , JRSVersion .v5_0_0 );
143148 }
144149
145150 @ Test (testName = "setJrsVersion" )
146151 public void should_get_not_null_setJrsVersion_field () throws IllegalAccessException {
152+ // Given
147153 RestClientConfiguration config = new RestClientConfiguration ();
148154 Field field = field (RestClientConfiguration .class , "jrsVersion" );
155+ // When
149156 field .set (config , JRSVersion .v4_7_0 );
150157 assertEquals (config .getJrsVersion (), JRSVersion .v4_7_0 );
151158 }
@@ -179,9 +186,9 @@ public X509Certificate[] getAcceptedIssuers() {
179186 assertEquals (expected , config .getTrustManagers ()[0 ]);
180187 }
181188
182- @ Test
189+ @ Test ( testName = "loadConfiguration" )
183190 public void should_invoke_private_method () throws Exception {
184-
191+ // Given
185192 Properties propertiesSpy = PowerMockito .spy (new Properties ());
186193
187194 propertiesSpy .setProperty ("url" , "http://localhost:8080/jasperserver-pro/" );
@@ -193,30 +200,137 @@ public void should_invoke_private_method() throws Exception {
193200 PowerMockito .whenNew (Properties .class ).withNoArguments ().thenReturn (propertiesSpy );
194201 PowerMockito .doNothing ().when (propertiesSpy ).load (any (InputStream .class ));
195202 PowerMockito .suppress (method (Properties .class , "load" , InputStream .class ));
196-
203+ // When
197204 RestClientConfiguration retrieved = RestClientConfiguration .loadConfiguration ("path" );
198-
205+ //Then
199206 AssertJUnit .assertNotNull (retrieved );
200207 Mockito .verify (propertiesSpy , times (1 )).load (any (InputStream .class ));
201208 }
202209
203- @ Test (expectedExceptions = NullPointerException .class , enabled = false )
210+ @ Test (testName = "ExceptionWhileLoadingProperties" , expectedExceptions = NullPointerException .class , enabled = false )
204211 public void should_throw_an_exception_while_loading_props () throws Exception {
212+ // When
205213 RestClientConfiguration .loadConfiguration ("path" );
206214 }
207215
208- @ Test
216+ @ Test ( testName = "getTrustManagers" )
209217 public void should_return_trusted_manager () throws Exception {
210-
218+ // Given
211219 RestClientConfiguration config = Mockito .spy (new RestClientConfiguration ());
220+ // When
212221 TrustManager [] managers = config .getTrustManagers ();
213222
214223 assertNotNull (managers );
215224 assertTrue (managers .length == 1 );
216225
217226 ((X509TrustManager ) managers [0 ]).checkClientTrusted (null , "abc" );
218227 X509Certificate [] retrieved = ((X509TrustManager ) managers [0 ]).getAcceptedIssuers ();
219-
228+ //Then
220229 Assert .assertNull (retrieved );
221230 }
231+
232+ @ Test (testName = "getAuthenticationType" )
233+ public void should_return_not_null_value_of_authenticationType_field () throws Exception {
234+ // Given
235+ RestClientConfiguration config = new RestClientConfiguration ();
236+ Field field = field (RestClientConfiguration .class , "authenticationType" );
237+ // When
238+ Object retrieved = field .get (config );
239+ //Then
240+ assertNotNull (retrieved );
241+ assertEquals (retrieved , AuthenticationType .SPRING );
242+
243+ }
244+
245+ @ Test (testName = "setAuthenticationType" )
246+ public void should_set_authenticationType_field () throws IllegalAccessException {
247+ // Given
248+ RestClientConfiguration config = new RestClientConfiguration ();
249+ config .setAuthenticationType (AuthenticationType .BASIC );
250+ Field field = field (RestClientConfiguration .class , "authenticationType" );
251+ // When
252+ Object retrieved = field .get (config );
253+ //Then
254+ assertNotNull (retrieved );
255+ assertEquals (retrieved , AuthenticationType .BASIC );
256+ }
257+
258+ @ Test (testName = "getRestrictedHttpMethods" )
259+ public void should_return_not_null_value_of_restrictedHttpMethods_field () throws Exception {
260+ // Given
261+ RestClientConfiguration config = new RestClientConfiguration ();
262+ Field field = field (RestClientConfiguration .class , "restrictedHttpMethods" );
263+ // When
264+ Object retrieved = field .get (config );
265+ //Then
266+ assertNotNull (retrieved );
267+ assertEquals (retrieved , false );
268+
269+ }
270+
271+ @ Test (testName = "setRestrictedHttpMethods" )
272+ public void should_set_restrictedHttpMethods_field () throws IllegalAccessException {
273+ // Given
274+ RestClientConfiguration config = new RestClientConfiguration ();
275+ config .setRestrictedHttpMethods (true );
276+ Field field = field (RestClientConfiguration .class , "restrictedHttpMethods" );
277+ // When
278+ Object retrieved = field .get (config );
279+ //Then
280+ assertNotNull (retrieved );
281+ assertEquals (retrieved , true );
282+ }
283+
284+ @ Test (testName = "setContentMimeType" )
285+ public void should_set_contentMimeType_field () throws IllegalAccessException {
286+ // Given
287+ RestClientConfiguration config = new RestClientConfiguration ();
288+ config .setContentMimeType (MimeType .XML );
289+ Field field = field (RestClientConfiguration .class , "contentMimeType" );
290+ // When
291+ Object retrieved = field .get (config );
292+ //Then
293+ assertNotNull (retrieved );
294+ assertEquals (retrieved , MimeType .XML );
295+
296+ }
297+
298+ @ Test (testName = "getContentMimeType" )
299+ public void should_get_not_null_contentMimeType_field () throws IllegalAccessException {
300+ // Given
301+ RestClientConfiguration config = new RestClientConfiguration ();
302+ Field field = field (RestClientConfiguration .class , "contentMimeType" );
303+ // When
304+ Object retrieved = field .get (config );
305+ //Then
306+ assertNotNull (retrieved );
307+ assertEquals (retrieved , MimeType .JSON );
308+ }
309+
310+ @ Test (testName = "geAcceptMimeType" )
311+ public void should_set_acceptMimeType_field () throws IllegalAccessException {
312+ // Given
313+ RestClientConfiguration config = new RestClientConfiguration ();
314+ config .setAcceptMimeType (MimeType .XML );
315+ Field field = field (RestClientConfiguration .class , "acceptMimeType" );
316+ // When
317+ Object retrieved = field .get (config );
318+ //Then
319+ assertNotNull (retrieved );
320+ assertEquals (retrieved , MimeType .XML );
321+
322+ }
323+
324+ @ Test (testName = "setAcceptMimeType" )
325+ public void should_get_not_null_acceptMimeType_field () throws IllegalAccessException {
326+ // Given
327+ RestClientConfiguration config = new RestClientConfiguration ();
328+ Field field = field (RestClientConfiguration .class , "acceptMimeType" );
329+ // When
330+ Object retrieved = field .get (config );
331+ //Then
332+ assertNotNull (retrieved );
333+ assertEquals (retrieved , MimeType .JSON );
334+ }
335+
222336}
0 commit comments