Skip to content

Commit

Permalink
follow up to #2392 refactor a ci test that was calling internet
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Dec 1, 2023
1 parent b0facb4 commit 063bead
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 39 deletions.
39 changes: 0 additions & 39 deletions karate-core/src/test/java/com/intuit/karate/HttpTest.java

This file was deleted.

50 changes: 50 additions & 0 deletions karate-core/src/test/java/com/intuit/karate/http/HttpHookTest.java
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 karate-core/src/test/java/com/intuit/karate/http/mock.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@ignore
Feature:

Scenario:
* def response = ({ body: null, path: requestPath })

0 comments on commit 063bead

Please sign in to comment.