@Test (expectedExceptions = RestAuthException.class) public void shouldFailToConvertFromJsonWithInvalidType() { ChoiceCallback choiceCallback = new ChoiceCallback("Select choice:", new String[]{"1", "34", "66", "93"}, 0, true); JsonValue jsonNameCallback = JsonValueBuilder.jsonValue() .array("input") .addLast(JsonValueBuilder.jsonValue().put("value", 1).build()) .array("output") .add(JsonValueBuilder.jsonValue().put("value", "Select choice:").build()) .add(JsonValueBuilder.jsonValue().put("value", new String[]{"1", "34", "66", "93"}).build()) .addLast(JsonValueBuilder.jsonValue().put("value", "0").build()) .put("type", "PasswordCallback") .build(); restAuthChoiceCallbackHandler.convertFromJson(choiceCallback, jsonNameCallback); fail(); }
public ChoiceCallback convertFromJson(ChoiceCallback callback, JsonValue jsonCallback) { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputField = input.get(0); int selectedIndex = inputField.get("value").asInteger(); callback.setSelectedIndex(selectedIndex); return callback; }
RestAuthChoiceCallbackHandler extends AbstractRestAuthCallbackHandler<ChoiceCallback> { public ChoiceCallback convertFromJson(ChoiceCallback callback, JsonValue jsonCallback) { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputField = input.get(0); int selectedIndex = inputField.get("value").asInteger(); callback.setSelectedIndex(selectedIndex); return callback; } }
RestAuthChoiceCallbackHandler extends AbstractRestAuthCallbackHandler<ChoiceCallback> { public ChoiceCallback convertFromJson(ChoiceCallback callback, JsonValue jsonCallback) { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputField = input.get(0); int selectedIndex = inputField.get("value").asInteger(); callback.setSelectedIndex(selectedIndex); return callback; }  }
RestAuthChoiceCallbackHandler extends AbstractRestAuthCallbackHandler<ChoiceCallback> { public ChoiceCallback convertFromJson(ChoiceCallback callback, JsonValue jsonCallback) { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputField = input.get(0); int selectedIndex = inputField.get("value").asInteger(); callback.setSelectedIndex(selectedIndex); return callback; }  ChoiceCallback handle(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, ChoiceCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(ChoiceCallback callback, int index); ChoiceCallback convertFromJson(ChoiceCallback callback, JsonValue jsonCallback); }
RestAuthChoiceCallbackHandler extends AbstractRestAuthCallbackHandler<ChoiceCallback> { public ChoiceCallback convertFromJson(ChoiceCallback callback, JsonValue jsonCallback) { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputField = input.get(0); int selectedIndex = inputField.get("value").asInteger(); callback.setSelectedIndex(selectedIndex); return callback; }  ChoiceCallback handle(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, ChoiceCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(ChoiceCallback callback, int index); ChoiceCallback convertFromJson(ChoiceCallback callback, JsonValue jsonCallback);  }