Last Changes

This commit is contained in:
egmp777 2014-05-23 17:28:26 -05:00
parent 83ccbf07c0
commit 4bd671cdb7
1 changed files with 13 additions and 11 deletions

View File

@ -31,21 +31,20 @@ import org.junit.Test;
public class HttpClientMultipartTest { public class HttpClientMultipartTest {
private static final String SERVER = "http://echo.200please.com"; private static final String SERVER = "http://echo.200please.com";
private static final String textFileName = "temp.txt";
private static final String imageFileName = "image.jpg";
private static final String zipFileName = "zipFile.zip";
private CloseableHttpClient client; private CloseableHttpClient client;
private HttpPost post; private HttpPost post;
private String textFileName;
private String imageFileName;
private String zipFileName;
private BufferedReader rd; private BufferedReader rd;
private CloseableHttpResponse response; private CloseableHttpResponse response;
private java.util.logging.Logger log;
@Before @Before
public final void before() { public final void before() {
client = HttpClientBuilder.create().build(); client = HttpClientBuilder.create().build();
post = new HttpPost(SERVER); post = new HttpPost(SERVER);
textFileName = "temp.txt"; log = java.util.logging.Logger.getAnonymousLogger();
imageFileName = "image.jpg";
zipFileName = "zipFile.zip";
} }
@After @After
@ -54,12 +53,12 @@ public class HttpClientMultipartTest {
try { try {
client.close(); client.close();
} catch (final IOException e1) { } catch (final IOException e1) {
e1.printStackTrace(); log.throwing("HttpClientMultipartTest", "after()", e1);
} }
try { try {
rd.close(); rd.close();
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); log.throwing("HttpClientMultipartTest", "after()", e);
} }
try { try {
final HttpEntity entity = response.getEntity(); final HttpEntity entity = response.getEntity();
@ -101,7 +100,8 @@ public class HttpClientMultipartTest {
@Test @Test
public final void givenFileandTextPart_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoExeption() throws ClientProtocolException, IOException { public final void givenFileandTextPart_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoExeption() throws ClientProtocolException, IOException {
final File file = new File(textFileName); final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + textFileName);
final File file = new File(url.getPath());
final String message = "This is a multipart post"; final String message = "This is a multipart post";
final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
@ -122,8 +122,10 @@ public class HttpClientMultipartTest {
@Test @Test
public final void givenFileandInputStreamandText_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoException() throws ClientProtocolException, IOException { public final void givenFileandInputStreamandText_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoException() throws ClientProtocolException, IOException {
final InputStream inputStream = new FileInputStream(zipFileName); final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + zipFileName);
final File file = new File(imageFileName); final URL url2 = Thread.currentThread().getContextClassLoader().getResource("uploads/" + imageFileName);
final InputStream inputStream = new FileInputStream(url.getPath());
final File file = new File(url2.getPath());
final String message = "This is a multipart post"; final String message = "This is a multipart post";
final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);