Skip to content

Commit

Permalink
Merge pull request #303 from wiremock/update-grpc
Browse files Browse the repository at this point in the history
update grpc docs to 0.7.0.
  • Loading branch information
RafeArnold authored Jul 29, 2024
2 parents 7bcde1d + 28a648b commit 8ae5d82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ wiremock_version: 3.9.1
wiremock_baseline: 3.x
pageEditPrefix: https://github.com/wiremock/wiremock.org/edit/main/

grpc_extension_version: 0.6.0
grpc_extension_version: 0.7.0

community_slack:
join_url: https://slack.wiremock.org/
Expand Down
29 changes: 18 additions & 11 deletions _docs/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Maven:
</dependency>
```

Create a root directory for WireMock e.g. `src/test/resources/wiremock` and create a subdirectory under this named `grpc`.
Create a root directory for WireMock, typically `src/test/resources/wiremock`, and create a subdirectory in it named `grpc`.

Put the descriptor files generated by `protoc` from your `.proto` files into the `grpc` directory.
Copy the descriptor files generated by `protoc` from your `.proto` files into the `grpc` subdirectory.

Initialise WireMock server with the extension enabled and the root directory set to the path created in the previous steps:

Expand All @@ -72,7 +72,7 @@ WireMockGrpcService mockGreetingService =

### Stubbing via JSON matching + responses

To specify request criteria and response data via JSON:
To specify request criteria and response data using JSON:

```java
mockGreetingService.stubFor(
Expand All @@ -81,8 +81,9 @@ mockGreetingService.stubFor(
.willReturn(json("{ "greeting": "Hi Tom from JSON" }")));
```

Or, with a templated response:

Or with a templated response:
{% raw %}

```java
mockGreetingService.stubFor(
Expand All @@ -93,6 +94,8 @@ mockGreetingService.stubFor(
"{ \"greeting\": \"Hello {{jsonPath request.body '$.name'}}\" }")));
```

{% endraw %}

### Stubbing via Java message objects

Matching and stubbing in the Java DSL can also be specified using the Java classes generated by `protoc`:
Expand Down Expand Up @@ -126,13 +129,13 @@ For a more complete set of examples, see the [Java demo project](https://github.

### Setup

Download the <a id="wiremock-standalone-download" href="https://repo1.maven.org/maven2/org/wiremock/wiremock-standalone/{{ site.wiremock_version }}/wiremock-standalone-{{ site.wiremock_version }}.jar">standalone JAR</a> at version 3.2.0 or above
Download the <a id="wiremock-standalone-download" href="https://repo1.maven.org/maven2/org/wiremock/wiremock-standalone/{{ site.wiremock_version }}/wiremock-standalone-{{ site.wiremock_version }}.jar">standalone JAR</a> at version 3.2.0 or above
and the <a id="wiremock-standalone-download" href="https://repo1.maven.org/maven2/org/wiremock/wiremock-grpc-extension-standalone/{{ site.grpc_extension_version }}/wiremock-grpc-extension-standalone-{{ site.grpc_extension_version }}.jar">gRPC extension JAR</a> into your working directory.

Create a WireMock data directory with a subdirectory for stub mappings and one for descriptor files:
Create a WireMock data directory with two subdirectories; one for stub mappings, and another for descriptor files:

```bash
mkdir -p wiremock/mappings wiremock/grpc
mkdir -p wiremock wiremock/mappings wiremock/grpc
```

Compile your proto files into descriptors:
Expand All @@ -141,12 +144,12 @@ Compile your proto files into descriptors:
protoc --descriptor_set_out wiremock/grpc/services.dsc ExampleServices.proto
```

Run WireMock with both on the classpath:
Run WireMock, with both directories you just created on the classpath:

```bash
java -cp wiremock-standalone-{{ site.wiremock_version }}.jar:wiremock-grpc-extension-standalone-{{ site.grpc_extension_version }}.jar \
java -cp wiremock-standalone-{{ versions.wiremock_version }}.jar:wiremock-grpc-extension-standalone-{{ versions.grpc_extension_version }}.jar \
wiremock.Run \
--root-dir wiremock-data
--root-dir wiremock
```

### Stubbing
Expand All @@ -172,6 +175,10 @@ gRPC stubs are defined using WireMock's standard JSON format. Requests should al
}
```

## Reloading gRPC descriptor files

If you plan to update your gRPC descriptor files at runtime, you can inform WireMock to reload all file descriptors via a POST to the admin API endpoint `/__admin/ext/grpc/reset`.

## More Demos

For more see the [standalone demo project](https://github.com/wiremock/wiremock-grpc-demos/tree/main/standalone).
For more see the [standalone demo project](https://github.com/wiremock/wiremock-grpc-demos/tree/main/standalone).

0 comments on commit 8ae5d82

Please sign in to comment.