use of org.forgerock.openam.core.rest.authn.callbackhandlers.RestAuthCallbackHandler in project OpenAM by OpenRock.
the class RestAuthCallbackHandlerManagerTest method shouldHandleCallbacksIntoJson.
@Test
public void shouldHandleCallbacksIntoJson() throws RestAuthResponseException, RestAuthException {
//Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
Callback callback1 = mock(Callback.class);
Callback callback2 = mock(Callback.class);
Callback[] callbacks = new Callback[] { callback1, callback2 };
RestAuthCallbackHandler restAuthCallbackHandler1 = mock(RestAuthCallbackHandler.class);
RestAuthCallbackHandler restAuthCallbackHandler2 = mock(RestAuthCallbackHandler.class);
JsonValue jsonCallback1 = new JsonValue(new LinkedHashMap<String, String>());
jsonCallback1.put("KEY1", "VALUE1");
JsonValue jsonCallback2 = new JsonValue(new LinkedHashMap<String, String>());
jsonCallback2.put("KEY2", "VALUE2");
given(restAuthCallbackHandlerFactory.getRestAuthCallbackHandler(Matchers.<Class<? extends Callback>>anyObject())).willReturn(restAuthCallbackHandler1).willReturn(restAuthCallbackHandler1).willReturn(restAuthCallbackHandler2);
given(restAuthCallbackHandler1.updateCallbackFromRequest(request, response, callback1)).willReturn(false);
given(restAuthCallbackHandler2.updateCallbackFromRequest(request, response, callback2)).willReturn(false);
given(restAuthCallbackHandler1.convertToJson(callback1, 1)).willReturn(jsonCallback1);
given(restAuthCallbackHandler2.convertToJson(callback2, 2)).willReturn(jsonCallback2);
//When
JsonValue jsonCallbacks = restAuthCallbackHandlerManager.handleCallbacks(request, response, callbacks);
//Then
verify(restAuthCallbackHandler1).updateCallbackFromRequest(request, response, callback1);
verify(restAuthCallbackHandler2, never()).updateCallbackFromRequest(request, response, callback2);
verify(restAuthCallbackHandler1).convertToJson(callback1, 1);
verify(restAuthCallbackHandler2).convertToJson(callback2, 2);
assertEquals(jsonCallbacks.size(), 2);
assertEquals(jsonCallbacks.get(0).get("KEY1").asString(), "VALUE1");
assertEquals(jsonCallbacks.get(1).get("KEY2").asString(), "VALUE2");
}
Aggregations