@Deployment(testable = false)
public static WebArchive deploy() throws URISyntaxException {
return ShrinkWrap.create(WebArchive.class)
.addClasses(TestServlet.class);
}
cd javaee7-samples/servlet/file-upload/Now we are ready to start testing. You can run all the tests in this sample by executing:
mvn test
Or you can run individual tests by executing one of the following:mvn test -Dtest=FileUploadTest
@Deployment(testable = false)
public static WebArchive deploy() throws URISyntaxException {
return ShrinkWrap.create(WebArchive.class)
.addClasses(TestServlet.class);
}
@Test
public void uploadFile() throws IOException, URISyntaxException {
// HttpClient client = new DefaultHttpClient();
// HttpPost postRequest = new HttpPost(new URL(base, "TestServlet").toURI());
//
// MultipartEntity multiPartEntity = new MultipartEntity();
// FileBody fileBody = new FileBody(new File("pom.xml"));
// multiPartEntity.addPart("attachment", fileBody);
//
// postRequest.setEntity(multiPartEntity);
// HttpResponse response = client.execute(postRequest);
//
// String servletOutput = EntityUtils.toString(response.getEntity());
//
// assertThat(response.getStatusLine().getStatusCode(), is(equalTo(200)));
// assertThat(servletOutput, containsString("Received 1 parts"));
// assertThat(servletOutput, containsString("writing pom.xml part"));
// assertThat(servletOutput, containsString("uploaded to: /tmp/pom.xml"));
}
There's a lot more about JavaEE to cover. If you're ready to learn more, check out the other available samples.
git clone git://github.com/javaee-samples/javaee7-samples.git
cd javaee7-samples/servlet/file-upload/
Do the changes as you see fit and send a pull request!
Good Luck!