-
-
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.
- Loading branch information
Showing
11 changed files
with
216 additions
and
58 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
83 changes: 83 additions & 0 deletions
83
karate-apache/src/test/java/com/intuit/karate/http/apache/ApacheHttpClientTest.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,83 @@ | ||
package com.intuit.karate.http.apache; | ||
|
||
import com.intuit.karate.CallContext; | ||
import com.intuit.karate.Config; | ||
import com.intuit.karate.core.FeatureContext; | ||
import com.intuit.karate.core.ScenarioContext; | ||
import com.intuit.karate.http.Cookie; | ||
import org.apache.http.client.CookieStore; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.lang.reflect.Field; | ||
import java.time.ZonedDateTime; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import static com.intuit.karate.http.Cookie.*; | ||
import static com.intuit.karate.http.HttpClient.construct; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ApacheHttpClientTest { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ApacheHttpClientTest.class); | ||
|
||
private ScenarioContext getContext() { | ||
FeatureContext featureContext = FeatureContext.forEnv(); | ||
CallContext callContext = new CallContext(null, true); | ||
return new ScenarioContext(featureContext, callContext, null, null); | ||
} | ||
|
||
private Config getConfig() { | ||
return new Config(); | ||
} | ||
|
||
private Map<String, String> getCookieMapWithExpiredDate() { | ||
ZonedDateTime currentDate = ZonedDateTime.now(); | ||
Map<String, String> cookieMap = new LinkedHashMap<>(); | ||
cookieMap.put(NAME, "testCookie"); | ||
cookieMap.put(VALUE, "tck"); | ||
cookieMap.put(DOMAIN, ".com"); | ||
cookieMap.put(PATH, "/"); | ||
cookieMap.put(EXPIRES,currentDate.minusDays(1).format(DTFMTR_RFC1123)); | ||
return cookieMap; | ||
} | ||
|
||
private Map<String, String> getCookieMapWithNonExpiredDate() { | ||
ZonedDateTime currentDate = ZonedDateTime.now(); | ||
Map<String, String> cookieMap = new LinkedHashMap<>(); | ||
cookieMap.put(NAME, "testCookie"); | ||
cookieMap.put(VALUE, "tck"); | ||
cookieMap.put(DOMAIN, ".com"); | ||
cookieMap.put(PATH, "/"); | ||
cookieMap.put(EXPIRES, currentDate.plusDays(1).format(DTFMTR_RFC1123)); | ||
return cookieMap; | ||
} | ||
|
||
@Test | ||
public void testExpiredCookieIsRemoved() throws NoSuchFieldException, IllegalAccessException { | ||
com.intuit.karate.http.Cookie c = new Cookie(getCookieMapWithExpiredDate()); | ||
ApacheHttpClient httpClient = (ApacheHttpClient) construct(getConfig(), getContext()); | ||
httpClient.buildCookie(c); | ||
|
||
Field cookieStoreField = httpClient.getClass().getDeclaredField("cookieStore"); | ||
cookieStoreField.setAccessible(true); | ||
CookieStore fieldValue = (CookieStore) cookieStoreField.get(httpClient); | ||
assertEquals(0, fieldValue.getCookies().size()); | ||
} | ||
|
||
@Test | ||
public void testNonExpiredCookieIsPersisted() throws NoSuchFieldException, IllegalAccessException { | ||
com.intuit.karate.http.Cookie c = new Cookie(getCookieMapWithNonExpiredDate()); | ||
ApacheHttpClient httpClient = (ApacheHttpClient) construct(getConfig(), getContext()); | ||
httpClient.buildCookie(c); | ||
|
||
Field cookieStoreField = httpClient.getClass().getDeclaredField("cookieStore"); | ||
cookieStoreField.setAccessible(true); | ||
CookieStore fieldValue = (CookieStore) cookieStoreField.get(httpClient); | ||
assertEquals(1, fieldValue.getCookies().size()); | ||
} | ||
} | ||
|
||
|
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,3 @@ | ||
function fn() { | ||
return { someConfig: 'someValue' } | ||
} |
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,2 @@ | ||
client.class=com.intuit.karate.http.apache.ApacheHttpClient | ||
|
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
Oops, something went wrong.