Skip to content

Commit 4e2e586

Browse files
author
Eugen
committed
Merge pull request eugenp#16 from egmp777/master
Last Changes
2 parents 83ccbf0 + 4bd671c commit 4e2e586

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

httpclient/src/test/java/org/baeldung/httpclient/HttpClientMultipartTest.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,20 @@
3131
public class HttpClientMultipartTest {
3232

3333
private static final String SERVER = "http://echo.200please.com";
34+
private static final String textFileName = "temp.txt";
35+
private static final String imageFileName = "image.jpg";
36+
private static final String zipFileName = "zipFile.zip";
3437
private CloseableHttpClient client;
3538
private HttpPost post;
36-
private String textFileName;
37-
private String imageFileName;
38-
private String zipFileName;
3939
private BufferedReader rd;
4040
private CloseableHttpResponse response;
41+
private java.util.logging.Logger log;
4142

4243
@Before
4344
public final void before() {
4445
client = HttpClientBuilder.create().build();
4546
post = new HttpPost(SERVER);
46-
textFileName = "temp.txt";
47-
imageFileName = "image.jpg";
48-
zipFileName = "zipFile.zip";
47+
log = java.util.logging.Logger.getAnonymousLogger();
4948
}
5049

5150
@After
@@ -54,12 +53,12 @@ public final void after() throws IllegalStateException, IOException {
5453
try {
5554
client.close();
5655
} catch (final IOException e1) {
57-
e1.printStackTrace();
56+
log.throwing("HttpClientMultipartTest", "after()", e1);
5857
}
5958
try {
6059
rd.close();
6160
} catch (final IOException e) {
62-
e.printStackTrace();
61+
log.throwing("HttpClientMultipartTest", "after()", e);
6362
}
6463
try {
6564
final HttpEntity entity = response.getEntity();
@@ -101,7 +100,8 @@ public final void givenFileandMultipleTextParts_whenUploadwithAddPart_thenNoExce
101100

102101
@Test
103102
public final void givenFileandTextPart_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoExeption() throws ClientProtocolException, IOException {
104-
final File file = new File(textFileName);
103+
final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + textFileName);
104+
final File file = new File(url.getPath());
105105
final String message = "This is a multipart post";
106106
final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
107107
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
@@ -122,8 +122,10 @@ public final void givenFileandTextPart_whenUploadwithAddBinaryBodyandAddTextBody
122122

123123
@Test
124124
public final void givenFileandInputStreamandText_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoException() throws ClientProtocolException, IOException {
125-
final InputStream inputStream = new FileInputStream(zipFileName);
126-
final File file = new File(imageFileName);
125+
final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + zipFileName);
126+
final URL url2 = Thread.currentThread().getContextClassLoader().getResource("uploads/" + imageFileName);
127+
final InputStream inputStream = new FileInputStream(url.getPath());
128+
final File file = new File(url2.getPath());
127129
final String message = "This is a multipart post";
128130
final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
129131
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

0 commit comments

Comments
 (0)