So here is my function:
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postMsg(@HeaderParam("FTP-Host") String Host, @HeaderParam("FTP-Port") String Port,
@HeaderParam("FTP-User") String User, @HeaderParam("FTP-Password") String Password,
@HeaderParam("FTP-Path") String Path, @FormDataParam("file") InputStream inputStream) {
try {
InformationHandler informationHandler = new InformationHandler(Path, Host, Port, User, Password);
CountriesStructure worker = new CountriesStructure();
worker.prepareCountriesStructure(inputStream, true, informationHandler);
} catch (UsernameOrPasswordException e) {
e.printStackTrace();
return Response.status(401).entity("Status 401.").build();
} catch (SocketException e) {
e.printStackTrace();
return Response.status(404).entity("Status 404.").build();
} catch (IOException e) {
e.printStackTrace();
return Response.status(400).entity("Status 400.").build();
} catch (JAXBException e) {
e.printStackTrace();
return Response.status(500).entity("Status 500.").build();
} catch (Exception e) {
e.printStackTrace();
return Response.status(500).entity("Status 500.").build();
}
return Response.status(200).entity("Success!").build();
}
And I want to make test in Junit. But I don't have idea how to add headers and file. Here is my test (it works):
@Test
public void firstTest()
throws ClientProtocolException, IOException {
HttpUriRequest request = new HttpGet("http://localhost:8080/JerseyWebApp/ftpaction/upload");
HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request);
assertThat(httpResponse.getStatusLine().getStatusCode(), equalTo(HttpStatus.SC_METHOD_NOT_ALLOWED));
}
But how can I add here headers and file?
Header I think that I can do in that way: request.addHeader(value, key);
or am I wrong?
And I have totally no idea how to add file to test :/