-
-
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.
follow up to #2392 refactor a ci test that was calling internet
- Loading branch information
Showing
3 changed files
with
55 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
karate-core/src/test/java/com/intuit/karate/http/HttpHookTest.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,50 @@ | ||
package com.intuit.karate.http; | ||
|
||
import com.intuit.karate.Http; | ||
import com.intuit.karate.RuntimeHook; | ||
import com.intuit.karate.core.MockServer; | ||
import com.intuit.karate.core.ScenarioRuntime; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
class HttpHookTest { | ||
|
||
static MockServer server; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
server = MockServer | ||
.feature("classpath:com/intuit/karate/http/mock.feature") | ||
.http(0).build(); | ||
} | ||
|
||
static class TestRuntimeHook implements RuntimeHook { | ||
@Override | ||
public void beforeHttpCall(HttpRequest request, ScenarioRuntime sr) { | ||
String url = request.getUrl(); | ||
request.setUrl(url + "/foo"); | ||
} | ||
|
||
@Override | ||
public void afterHttpCall(HttpRequest request, Response response, ScenarioRuntime sr) { | ||
response.setBody(response.json().set("bar", "baz").toString()); | ||
} | ||
} | ||
|
||
@Test | ||
void testInvokeWithoutHook() { | ||
Response response = Http.to("http://localhost:" + server.getPort() + "/hello").get(); | ||
assertEquals("/hello", response.json().get("path").toString()); | ||
} | ||
|
||
@Test | ||
void testInvokeWithHook() { | ||
Response response = Http.to("http://localhost:" + server.getPort() + "/hello") | ||
.hook(new TestRuntimeHook()).get(); | ||
assertEquals("/hello/foo", response.json().get("path").toString()); | ||
assertEquals("baz", response.json().get("bar").toString()); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
karate-core/src/test/java/com/intuit/karate/http/mock.feature
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,5 @@ | ||
@ignore | ||
Feature: | ||
|
||
Scenario: | ||
* def response = ({ body: null, path: requestPath }) |