use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class RestAuthNameCallbackHandlerTest method shouldConvertToJson.
@Test
public void shouldConvertToJson() throws RestAuthException {
//Given
NameCallback nameCallback = new NameCallback("Enter username:");
//When
JsonValue jsonObject = restAuthNameCallbackHandler.convertToJson(nameCallback, 1);
//Then
assertEquals("NameCallback", jsonObject.get("type").asString());
assertNotNull(jsonObject.get("output"));
Assert.assertEquals(1, jsonObject.get("output").size());
Assert.assertEquals("Enter username:", jsonObject.get("output").get(0).get("value").asString());
assertNotNull(jsonObject.get("input"));
Assert.assertEquals(1, jsonObject.get("input").size());
Assert.assertEquals("", jsonObject.get("input").get(0).get("value").asString());
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class RestAuthNameCallbackHandlerTest method shouldConvertFromJson.
@Test
public void shouldConvertFromJson() throws RestAuthException {
//Given
NameCallback nameCallback = new NameCallback("Enter username:");
JsonValue jsonNameCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", "USERNAME").build()).array("output").addLast(JsonValueBuilder.jsonValue().put("value", "Enter username:").build()).put("type", "NameCallback").build();
//When
NameCallback convertedNameCallback = restAuthNameCallbackHandler.convertFromJson(nameCallback, jsonNameCallback);
//Then
Assert.assertEquals(nameCallback, convertedNameCallback);
Assert.assertEquals("Enter username:", convertedNameCallback.getPrompt());
Assert.assertEquals("USERNAME", convertedNameCallback.getName());
}
use of org.forgerock.json.JsonValue 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 org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class RestAuthConfirmationCallbackHandlerTest method shouldConvertFromJson.
@Test
public void shouldConvertFromJson() throws RestAuthException {
//Given
ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[] { "OK", "NO", "CANCEL" }, 0);
JsonValue jsonConfirmationCallback = JsonValueBuilder.jsonValue().array("input").addLast(JsonValueBuilder.jsonValue().put("value", 2).build()).array("output").add(JsonValueBuilder.jsonValue().put("value", "Select confirmation:").build()).add(JsonValueBuilder.jsonValue().put("value", 0).build()).add(JsonValueBuilder.jsonValue().put("value", new String[] { "OK", "NO", "CANCEL" }).build()).add(JsonValueBuilder.jsonValue().put("value", -1).build()).addLast(JsonValueBuilder.jsonValue().put("value", 0).build()).put("type", "ConfirmationCallback").build();
//When
ConfirmationCallback convertedConfirmationCallback = restAuthConfirmationCallbackHandler.convertFromJson(confirmationCallback, jsonConfirmationCallback);
//Then
assertEquals(confirmationCallback, convertedConfirmationCallback);
assertEquals("Select confirmation:", convertedConfirmationCallback.getPrompt());
assertEquals(ConfirmationCallback.INFORMATION, convertedConfirmationCallback.getMessageType());
assertEquals("OK", convertedConfirmationCallback.getOptions()[0]);
assertEquals("NO", convertedConfirmationCallback.getOptions()[1]);
assertEquals("CANCEL", convertedConfirmationCallback.getOptions()[2]);
assertEquals(-1, convertedConfirmationCallback.getOptionType());
assertEquals(0, convertedConfirmationCallback.getDefaultOption());
assertEquals(2, convertedConfirmationCallback.getSelectedIndex());
}
use of org.forgerock.json.JsonValue in project OpenAM by OpenRock.
the class RestAuthConfirmationCallbackHandlerTest method shouldConvertToJson.
@Test
public void shouldConvertToJson() throws RestAuthException {
//Given
ConfirmationCallback confirmationCallback = new ConfirmationCallback("Select confirmation:", ConfirmationCallback.INFORMATION, new String[] { "OK", "NO", "CANCEL" }, 0);
//When
JsonValue jsonObject = restAuthConfirmationCallbackHandler.convertToJson(confirmationCallback, 1);
//Then
assertEquals("ConfirmationCallback", jsonObject.get("type").asString());
assertNotNull(jsonObject.get("output"));
assertEquals(5, jsonObject.get("output").size());
assertEquals("Select confirmation:", jsonObject.get("output").get(0).get("value").asString());
assertEquals(ConfirmationCallback.INFORMATION, (int) jsonObject.get("output").get(1).get("value").asInteger());
assertEquals("OK", jsonObject.get("output").get(2).get("value").get(0).asString());
assertEquals("NO", jsonObject.get("output").get(2).get("value").get(1).asString());
assertEquals("CANCEL", jsonObject.get("output").get(2).get("value").get(2).asString());
assertEquals(-1, (int) jsonObject.get("output").get(3).get("value").asInteger());
assertEquals(0, (int) jsonObject.get("output").get(4).get("value").asInteger());
assertNotNull(jsonObject.get("input"));
assertEquals(1, jsonObject.get("input").size());
assertEquals(0, (int) jsonObject.get("input").get(0).get("value").asInteger());
}
Aggregations