Skip to content

Commit a220c03

Browse files
committed
update docs for karate-mock-servlet
1 parent 21e6b1d commit a220c03

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

karate-mock-servlet/README.md

+5-16
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,14 @@ So yes, you can test HTTP web-services with the same ease that you expect from t
2222
```
2323

2424
## Switching the HTTP Client
25-
Karate actually allows you to switch the implementation of the Karate [`HttpClient`](../karate-core/src/main/java/com/intuit/karate/http/HttpClient.java) even *during* a test. For mocking a servlet container, you don't need to implement it from scratch and you just need to over-ride one or two methods of the mock-implementation that Karate provides.
25+
You can completely customize the HTTP client used by Karate by implementing the [`HttpClient`](../karate-core/src/main/java/com/intuit/karate/http/HttpClient.java) interface which happens to be very simple.
2626

27-
> If you need to create a completely new `HttpClient` implementation from scratch, the [`MockHttpClient`](src/main/java/com/intuit/karate/mock/servlet/MockHttpClient.java) is a good reference. There are many possibilities here, you can add support for other HTTP clients besides Apache and Jersey, or mock a stack that is not based on Java servlets.
27+
If you need to create a completely new `HttpClient` implementation from scratch, the [`MockHttpClient`](src/main/java/com/intuit/karate/mock/servlet/MockHttpClient.java) is a good reference. There are many possibilities here, you can add support for other HTTP clients besides Apache and Jersey, or mock a stack that is not based on Java servlets.
2828

29-
Let's take a closer look at the following [`configure`](https://github.com/intuit/karate#configure) keys:
30-
31-
Key | Type | Description
32-
------ | ---- | ---------
33-
`httpClientClass` | string | The class name of the implementation you wish to use. By default the Karate Apache (or Jersey) HTTP client is used. You need a zero-argument constructor. If you need more control over construction, refer to the next row.
34-
`httpClientInstance` | Java Object | A fully constructed instance of an `HttpClient` implementation. Useful if you need more dynamic control over things like dependency-injection.
35-
`userDefined` | JSON | You normally would not need this general-purpose extension mechanism where you can pass custom JSON data to the HTTP Client instance via the [`configure`](https://github.com/intuit/karate#configure) keyword. Refer to [this test](../karate-core/src/test/java/com/intuit/karate/http/HttpClientTest.java) for an idea of how you can use this for advanced needs, such as if you wanted to customize your HTTP Client implementation *during* a test.
29+
Karate defaults to the [`ApacheHttpClient`](../karate-core/src/main/java/com/intuit/karate/http/ApacheHttpClient.java), and to change this for a test-run, you can set the [`HttpClientFactory`](../karate-core/src/main/java/com/intuit/karate/http/HttpClientFactory.java) using the [`Runner`](../karate-core/src/main/java/com/intuit/karate/Runner.java) "builder" API.
3630

3731
## Mocking Your Servlet
38-
You only need to over-ride two methods:
39-
* `Servlet getServlet(HttpRequestBuilder request)`
40-
* `ServletContext getServletContext()`
32+
Creating a `Servlet` and `ServletContext` instance is up to you and here is where you would manage configuration for your web-application. And then you can implement `HttpClientFactory` by using the `MockHttpClient` code provide by Karate.
4133

4234
Once you refer to the following examples, you should be able to get up and running for your project.
4335
* Spring MVC Dispatcher Servlet
@@ -47,10 +39,7 @@ Once you refer to the following examples, you should be able to get up and runni
4739

4840
Note that the first example above tests the whole of the [`karate-demo`](../karate-demo) Spring Boot application, and using a [parallel runner](src/test/java/demo/MockSpringMvcServletTest.java)
4941

50-
## Configuration
51-
Everything is typically tied together in [bootstrap configuration](https://github.com/intuit/karate#configuration). If you do this right, your `*.feature` files can be re-used for mock as well as *real* integration tests.
52-
53-
Use the test configuration for this `karate-mock-servlet` project as a reference: [`karate-config.js`](src/test/java/karate-config.js)
42+
If you structure your tests propertly, your `*.feature` files can be re-used for mock as well as *real* integration tests.
5443

5544
## Limitations
5645
Most teams would not run into these, but if you do, please [consider contributing](https://github.com/intuit/karate/projects/3#card-22529274) !

0 commit comments

Comments
 (0)