use of javax.security.auth.callback.ChoiceCallback in project OpenAM by OpenRock.
the class PersistModuleProcesserTest method shouldReturnLoginSucceedWithoutSavingProfileWhenUserChooseToNotSaveProfile.
@Test
public void shouldReturnLoginSucceedWithoutSavingProfileWhenUserChooseToNotSaveProfile() throws AuthLoginException {
//Given
processor = new PersistModuleProcessor(devicePrintProfile, false, profilePersister);
ChoiceCallback choiceCallback = mock(ChoiceCallback.class);
Callback[] callbacks = new Callback[] { choiceCallback };
int state = SAVE_PROFILE_STATE;
given(choiceCallback.getSelectedIndexes()).willReturn(new int[] { 1 });
//When
int newState = processor.process(callbacks, state);
//Then
assertThat(newState).isEqualTo(ISAuthConstants.LOGIN_SUCCEED);
verifyZeroInteractions(profilePersister);
}
use of javax.security.auth.callback.ChoiceCallback in project OpenAM by OpenRock.
the class RestAuthChoiceCallbackHandlerTest method shouldConvertFromJson.
@Test
public void shouldConvertFromJson() throws RestAuthException {
//Given
ChoiceCallback choiceCallback = new ChoiceCallback("Select choice:", new String[] { "1", "34", "66", "93" }, 0, true);
JsonValue jsonNameCallback = json(object(field("input", array(object(field("value", 1)))), field("output", array(object(field("value", "Select choice:")), object(field("value", array("1", "34", "66", "93"))), object(field("value", "0")))), field("type", "ChoiceCallback")));
//When
ChoiceCallback convertedChoiceCallback = restAuthChoiceCallbackHandler.convertFromJson(choiceCallback, jsonNameCallback);
//Then
assertEquals(choiceCallback, convertedChoiceCallback);
assertEquals("Select choice:", convertedChoiceCallback.getPrompt());
assertEquals(new String[] { "1", "34", "66", "93" }, convertedChoiceCallback.getChoices());
assertEquals(0, convertedChoiceCallback.getDefaultChoice());
assertEquals(new int[] { 1 }, convertedChoiceCallback.getSelectedIndexes());
}
use of javax.security.auth.callback.ChoiceCallback in project OpenAM by OpenRock.
the class RestAuthChoiceCallbackHandlerTest method shouldNotUpdateCallbackFromRequest.
@Test
public void shouldNotUpdateCallbackFromRequest() throws RestAuthResponseException, RestAuthException {
//Given
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
ChoiceCallback choiceCallback = mock(ChoiceCallback.class);
//When
boolean updated = restAuthChoiceCallbackHandler.updateCallbackFromRequest(request, response, choiceCallback);
//Then
assertFalse(updated);
}
use of javax.security.auth.callback.ChoiceCallback in project OpenAM by OpenRock.
the class RestAuthChoiceCallbackHandlerTest method shouldFailToConvertFromJsonWithInvalidValue.
@Test(expectedExceptions = JsonValueException.class)
public void shouldFailToConvertFromJsonWithInvalidValue() throws RestAuthException {
//Given
ChoiceCallback choiceCallback = new ChoiceCallback("Select choice:", new String[] { "A", "B", "C", "D" }, 0, true);
JsonValue jsonNameCallback = json(object(field("input", array(object(field("value", "A")))), field("output", array(object(field("value", "Select choice:")), object(field("value", array("A", "B", "C", "D"))), object(field("value", "0")))), field("type", "ChoiceCallback")));
System.out.println("shouldFailToConvertFromJsonWithInvalidValue");
System.out.println(jsonNameCallback.toString());
//When
restAuthChoiceCallbackHandler.convertFromJson(choiceCallback, jsonNameCallback);
//Then
fail();
}
use of javax.security.auth.callback.ChoiceCallback in project OpenAM by OpenRock.
the class RestAuthChoiceCallbackHandlerTest method shouldConvertToJsonWithPreSelectedIndexes.
@Test
public void shouldConvertToJsonWithPreSelectedIndexes() throws RestAuthException {
//Given
ChoiceCallback choiceCallback = new ChoiceCallback("Select choice:", new String[] { "1", "34", "66", "93" }, 0, false);
choiceCallback.setSelectedIndex(1);
//When
JsonValue jsonObject = restAuthChoiceCallbackHandler.convertToJson(choiceCallback, 1);
//Then
assertEquals("ChoiceCallback", jsonObject.get("type").asString());
assertNotNull(jsonObject.get("output"));
assertEquals(3, jsonObject.get("output").size());
assertEquals("Select choice:", jsonObject.get("output").get(0).get("value").asString());
assertEquals("1", jsonObject.get("output").get(1).get("value").get(0).asString());
assertEquals("34", jsonObject.get("output").get(1).get("value").get(1).asString());
assertEquals("66", jsonObject.get("output").get(1).get("value").get(2).asString());
assertEquals("93", jsonObject.get("output").get(1).get("value").get(3).asString());
assertEquals(0, (int) jsonObject.get("output").get(2).get("value").asInteger());
assertNotNull(jsonObject.get("input"));
assertEquals(1, jsonObject.get("input").size());
assertEquals(1, (int) jsonObject.get("input").get(0).get("value").asInteger());
}
Aggregations