-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from sashirestela/67-multipart-convert-collect…
…ions-to-bytearray Convert collections to bytearray in Multipart
- Loading branch information
Showing
6 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/test/java/io/github/sashirestela/cleverclient/support/HttpMultipartTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.github.sashirestela.cleverclient.support; | ||
|
||
import io.github.sashirestela.cleverclient.http.ITest; | ||
import io.github.sashirestela.cleverclient.util.JsonUtil; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class HttpMultipartTest { | ||
|
||
@Test | ||
void testToByteArrays() { | ||
String[] expectedData = { | ||
"Content-Disposition: form-data", | ||
"Content-Type: text/plain\r\n", | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", | ||
"Content-Disposition: form-data", | ||
"; name=\"id\"\r\n", | ||
"101\r\n", | ||
"Content-Disposition: form-data", | ||
"; name=\"text\"\r\n", | ||
"Testing\r\n", | ||
"Content-Disposition: form-data", | ||
"; name=\"group[]\"\r\n", | ||
"one\r\n", | ||
"Content-Disposition: form-data", | ||
"; name=\"group[]\"\r\n", | ||
"two\r\n", | ||
"Content-Disposition: form-data", | ||
"; name=\"numbers[]\"\r\n", | ||
"13\r\n", | ||
"Content-Disposition: form-data", | ||
"; name=\"numbers[]\"\r\n", | ||
"25\r\n", | ||
"Content-Disposition: form-data", | ||
"; name=\"numbers[]\"\r\n", | ||
"37\r\n" | ||
}; | ||
var object = new ITest.MultipartClass(Paths.get("src/test/resources/loremipsum.txt"), 101, "Testing", | ||
List.of("one", "two"), new Integer[] { 13, 25, 37 }); | ||
var objectMap = JsonUtil.objectToMap(object); | ||
var bytesList = HttpMultipart.toByteArrays(objectMap); | ||
var i = 0; | ||
for (byte[] bytes : bytesList) { | ||
var currentData = new String(bytes); | ||
if (!currentData.startsWith("--") && !currentData.startsWith("\r\n") | ||
&& !currentData.contains("filename=")) { | ||
assertEquals(expectedData[i], currentData); | ||
i++; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. |