Added Caps to File name constants
This commit is contained in:
parent
9c444da4e0
commit
b5be074c97
|
@ -33,9 +33,9 @@ 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 TEXTFILENAME = "temp.txt";
|
||||||
private static final String imageFileName = "image.jpg";
|
private static final String IMAGEFILENAME = "image.jpg";
|
||||||
private static final String zipFileName = "zipFile.zip";
|
private static final String ZIPFILENAME = "zipFile.zip";
|
||||||
private static final Logger LOGGER = Logger.getLogger("org.baeldung.httpclient.HttpClientMultipartTest");
|
private static final Logger LOGGER = Logger.getLogger("org.baeldung.httpclient.HttpClientMultipartTest");
|
||||||
private CloseableHttpClient client;
|
private CloseableHttpClient client;
|
||||||
private HttpPost post;
|
private HttpPost post;
|
||||||
|
@ -78,7 +78,7 @@ public class HttpClientMultipartTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void givenFileandMultipleTextParts_whenUploadwithAddPart_thenNoExceptions() throws IOException {
|
public final void givenFileandMultipleTextParts_whenUploadwithAddPart_thenNoExceptions() throws IOException {
|
||||||
final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + textFileName);
|
final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + TEXTFILENAME);
|
||||||
final File file = new File(url.getPath());
|
final File file = new File(url.getPath());
|
||||||
final FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY);
|
final FileBody fileBody = new FileBody(file, ContentType.DEFAULT_BINARY);
|
||||||
final StringBody stringBody1 = new StringBody("This is message 1", ContentType.MULTIPART_FORM_DATA);
|
final StringBody stringBody1 = new StringBody("This is message 1", ContentType.MULTIPART_FORM_DATA);
|
||||||
|
@ -103,12 +103,12 @@ public class HttpClientMultipartTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void givenFileandTextPart_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoExeption() throws ClientProtocolException, IOException {
|
public final void givenFileandTextPart_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoExeption() throws ClientProtocolException, IOException {
|
||||||
final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + textFileName);
|
final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + TEXTFILENAME);
|
||||||
final File file = new File(url.getPath());
|
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);
|
||||||
builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, textFileName);
|
builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, TEXTFILENAME);
|
||||||
builder.addTextBody("text", message, ContentType.DEFAULT_BINARY);
|
builder.addTextBody("text", message, ContentType.DEFAULT_BINARY);
|
||||||
final HttpEntity entity = builder.build();
|
final HttpEntity entity = builder.build();
|
||||||
post.setEntity(entity);
|
post.setEntity(entity);
|
||||||
|
@ -125,15 +125,15 @@ public class HttpClientMultipartTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void givenFileandInputStreamandText_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoException() throws ClientProtocolException, IOException {
|
public final void givenFileandInputStreamandText_whenUploadwithAddBinaryBodyandAddTextBody_ThenNoException() throws ClientProtocolException, IOException {
|
||||||
final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + zipFileName);
|
final URL url = Thread.currentThread().getContextClassLoader().getResource("uploads/" + ZIPFILENAME);
|
||||||
final URL url2 = Thread.currentThread().getContextClassLoader().getResource("uploads/" + imageFileName);
|
final URL url2 = Thread.currentThread().getContextClassLoader().getResource("uploads/" + IMAGEFILENAME);
|
||||||
final InputStream inputStream = new FileInputStream(url.getPath());
|
final InputStream inputStream = new FileInputStream(url.getPath());
|
||||||
final File file = new File(url2.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);
|
||||||
builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, imageFileName);
|
builder.addBinaryBody("upfile", file, ContentType.DEFAULT_BINARY, IMAGEFILENAME);
|
||||||
builder.addBinaryBody("upstream", inputStream, ContentType.create("application/zip"), zipFileName);
|
builder.addBinaryBody("upstream", inputStream, ContentType.create("application/zip"), ZIPFILENAME);
|
||||||
builder.addTextBody("text", message, ContentType.TEXT_PLAIN);
|
builder.addTextBody("text", message, ContentType.TEXT_PLAIN);
|
||||||
final HttpEntity entity = builder.build();
|
final HttpEntity entity = builder.build();
|
||||||
post.setEntity(entity);
|
post.setEntity(entity);
|
||||||
|
@ -155,7 +155,7 @@ public class HttpClientMultipartTest {
|
||||||
final byte[] bytes = "binary code".getBytes();
|
final byte[] bytes = "binary code".getBytes();
|
||||||
final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
|
||||||
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
|
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
|
||||||
builder.addBinaryBody("upfile", bytes, ContentType.DEFAULT_BINARY, textFileName);
|
builder.addBinaryBody("upfile", bytes, ContentType.DEFAULT_BINARY, TEXTFILENAME);
|
||||||
builder.addTextBody("text", message, ContentType.TEXT_PLAIN);
|
builder.addTextBody("text", message, ContentType.TEXT_PLAIN);
|
||||||
final HttpEntity entity = builder.build();
|
final HttpEntity entity = builder.build();
|
||||||
post.setEntity(entity);
|
post.setEntity(entity);
|
||||||
|
|
Loading…
Reference in New Issue