Source:
<code>public void testProcessRequest() <START> throws ExecutionException, InterruptedException, UnsupportedEncodingException, JSONException, URISyntaxException { <END> SecurityServiceCallback callback = new SecurityServiceCallback(); RestRequest restRequest = null; try { securityService.processRequest(restRequest, callback).get(); Assert.fail("Should have thrown IllegalArgumentException "); } catch (IllegalArgumentException e) { } restRequest = createRestRequest(RestMethod.POST, "/", null); Future<Void> result = securityService.processRequest(restRequest, null); result.get(); restRequest = createRestRequest(RestMethod.GET, "/", null); result = securityService.processRequest(restRequest, null); result.get(); restRequest = createRestRequest(RestMethod.DELETE, "/", null); result = securityService.processRequest(restRequest, null); result.get(); restRequest = createRestRequest(RestMethod.HEAD, "/", null); result = securityService.processRequest(restRequest, null); result.get(); callback = new SecurityServiceCallback(); restRequest = createRestRequest(RestMethod.POST, "/", null); securityService.processRequest(restRequest, callback).get(); Assert.assertTrue("Call back should have been invoked", callback.callbackInvoked.get()); Assert.assertNull("Exception should not have been thrown", callback.exception); callback = new SecurityServiceCallback(); restRequest = createRestRequest(RestMethod.GET, "/", null); securityService.processRequest(restRequest, callback).get(); Assert.assertTrue("Call back should have been invoked", callback.callbackInvoked.get()); Assert.assertNull("Exception should not have been thrown", callback.exception); callback = new SecurityServiceCallback(); restRequest = createRestRequest(RestMethod.DELETE, "/", null); securityService.processRequest(restRequest, callback).get(); Assert.assertTrue("Call back should have been invoked", callback.callbackInvoked.get()); Assert.assertNull("Exception should not have been thrown", callback.exception); callback = new SecurityServiceCallback(); restRequest = createRestRequest(RestMethod.HEAD, "/", null); securityService.processRequest(restRequest, callback).get(); Assert.assertTrue("Call back should have been invoked", callback.callbackInvoked.get()); Assert.assertNull("Exception should not have been thrown", callback.exception); }</code><technical_language>throws Exception</technical_language>

Target:
public void testProcessRequest() throws Exception { SecurityServiceCallback callback = new SecurityServiceCallback(); RestRequest restRequest = null; try { securityService.processRequest(restRequest, callback).get(); Assert.fail("Should have thrown IllegalArgumentException "); } catch (IllegalArgumentException e) { } RestMethod[] methods = new RestMethod[]{RestMethod.POST, RestMethod.GET, RestMethod.DELETE, RestMethod.HEAD}; for (RestMethod restMethod : methods) { restRequest = createRestRequest(restMethod, "/", null); securityService.processRequest(restRequest, null).get(); } callback = new SecurityServiceCallback(); for (RestMethod restMethod : methods) { restRequest = createRestRequest(restMethod, "/", null); securityService.processRequest(restRequest, callback).get(); Assert.assertTrue("Call back should have been invoked", callback.callbackInvoked.get()); Assert.assertNull("Exception should not have been thrown", callback.exception); callback.reset(); } callback = new SecurityServiceCallback(); securityService.close(); for (RestMethod restMethod : methods) { restRequest = createRestRequest(restMethod, "/", null); try { securityService.processRequest(restRequest, callback).get(); Assert.fail("Process Request should have failed because Security Service is closed"); } catch (ExecutionException e) { Assert.assertTrue("Exception should have been an instance of RestServiceException", e.getCause() instanceof RestServiceException); RestServiceException re = (RestServiceException) e.getCause(); Assert.assertEquals("Unexpected RestServerErrorCode (Future)", RestServiceErrorCode.ServiceUnavailable, re.getErrorCode()); re = (RestServiceException) callback.exception; Assert.assertEquals("Unexpected RestServerErrorCode (Callback)", RestServiceErrorCode.ServiceUnavailable, re.getErrorCode()); } callback.reset(); } }