-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 #1299 from Nishant-sehgal/develop
Issue-1181 ApacheHttpClient custom content type quotes issue fix
- Loading branch information
Showing
3 changed files
with
94 additions
and
14 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
73 changes: 73 additions & 0 deletions
73
karate-apache/src/test/java/com/intuit/karate/http/apache/ApacheHttpUtilsTest.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,73 @@ | ||
package com.intuit.karate.http.apache; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.http.HttpEntity; | ||
import org.junit.Test; | ||
|
||
/** @author nsehgal */ | ||
public class ApacheHttpUtilsTest { | ||
|
||
@Test | ||
public void testContentTypeWithQuotes() { | ||
final String originalContentType = | ||
"multipart/related; charset=UTF-8; boundary=\"----=_Part_19_1913847857.1592612068756\"; type=\"application/xop+xml\"; start-info=\"text/xml\""; | ||
|
||
HttpEntity httpEntity = | ||
ApacheHttpUtils.getEntity( | ||
"content is not important", originalContentType, StandardCharsets.UTF_8); | ||
|
||
assertEquals(originalContentType, httpEntity.getContentType().getValue()); | ||
} | ||
|
||
@Test | ||
public void testContentTypeWithoutQuotes() { | ||
final String originalContentType = | ||
"multipart/related; charset=UTF-8; boundary=----=_Part_19_1913847857.1592612068756; type=application/xop+xml; start-info=text/xml"; | ||
|
||
final String expectedContentType = | ||
"multipart/related; charset=UTF-8; boundary=\"----=_Part_19_1913847857.1592612068756\"; type=\"application/xop+xml\"; start-info=\"text/xml\""; | ||
|
||
HttpEntity httpEntity = | ||
ApacheHttpUtils.getEntity( | ||
"content is not important", originalContentType, StandardCharsets.UTF_8); | ||
|
||
assertNotEquals(originalContentType, httpEntity.getContentType().getValue()); | ||
assertEquals(expectedContentType, httpEntity.getContentType().getValue()); | ||
} | ||
|
||
@Test | ||
public void testContentTypeWithoutQuotesCharsetInLast() { | ||
final String originalContentType = | ||
"multipart/related; boundary=----=_Part_19_1913847857.1592612068756; type=application/xop+xml; start-info=text/xml; charset=UTF-8"; | ||
|
||
final String expectedContentType = | ||
"multipart/related; boundary=\"----=_Part_19_1913847857.1592612068756\"; type=\"application/xop+xml\"; start-info=\"text/xml\"; charset=UTF-8"; | ||
|
||
HttpEntity httpEntity = | ||
ApacheHttpUtils.getEntity( | ||
"content is not important", originalContentType, StandardCharsets.UTF_8); | ||
|
||
assertNotEquals(originalContentType, httpEntity.getContentType().getValue()); | ||
assertEquals(expectedContentType, httpEntity.getContentType().getValue()); | ||
} | ||
|
||
@Test | ||
public void testContentTypeWithCustomCharset() { | ||
final String originalContentType = | ||
"multipart/related; boundary=----=_Part_19_1913847857.1592612068756; type=application/xop+xml; start-info=text/xml"; | ||
|
||
final String expectedContentType = | ||
"multipart/related; boundary=\"----=_Part_19_1913847857.1592612068756\"; type=\"application/xop+xml\"; start-info=\"text/xml\"; charset=UTF-8"; | ||
|
||
HttpEntity httpEntity = | ||
ApacheHttpUtils.getEntity( | ||
"content is not important", originalContentType, StandardCharsets.UTF_8); | ||
|
||
assertNotEquals(originalContentType, httpEntity.getContentType().getValue()); | ||
assertEquals(expectedContentType, httpEntity.getContentType().getValue()); | ||
} | ||
} |