我有一个 Resteasy Webservice 方法,它采用 MultipartFormDataInput 对象作为其参数,并从中提取大量信息。我想为此方法编写一个 jUnit 测试,但我无法找到任何方法来创建该对象并将虚拟数据放入其中,以便我可以直接调用我的 webservice 方法。服务方法从表单中提取数据,如下所示......
@POST
@Path("/requestDeviceCode")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes("multipart/form-data")
public DeviceCodeModel requestDeviceCode(final MultipartFormDataInput inputMultipart) {
// process the form data - only field in the form is the token
Map<String, List<InputPart>> formData = null; // we'll put the form data in here
formData = inputMultipart.getFormDataMap();
String token = null;
try {
token = formData.get("Token").get(0).getBodyAsString();
this._logger.debug("Pulled encrypted token out of input form, it's " + token);
Run Code Online (Sandbox Code Playgroud)
这工作正常,但尝试创建一个对象作为参数传递给“requestDeviceCode”让我陷入困境。我尝试过这个的变体...
// create a multipartForm (input to …Run Code Online (Sandbox Code Playgroud)