Request was not matched ==================== [eq...
# help
r
Request was not matched ==================== [equalToJson] | { | "base" : 50.0, | !@@!%@#%#^^ <<<<< Body does not match "height" : 20.0 | } | Can someone help me figure out what I may be missing or doing wrong?
r
youll have to provide more information about your setup. if you can provide a minimal project that reproduces the error you're seeing and share that, that would be ideal
r
Here is what is in my protobuf file. syntax = "proto3"; option java_multiplre_files = true; message CalculateAreaRequest { double base; double height; } message CalculateAreaResult { double base; double height; double area; } service AreaCalculationService { rpc calculateArea(CalculateAreaRequest returns (CalculateAreaResult); }
Here is my JSON mapping file syntax. { "mappings" : [{ "request": { "method" : "POST", "urlPath" : "/grpcservice.calculatearea.CalculateareaService/calculateArea", "multipartPatterns : [ { "bodyPatterns" : [ { "equalToJson" : "{\"base\": 50.0, \"height\":20.0}" } ] } ] }, "response": { "headers" : {"Content-Type": "text/plain"}, "status" : 200 "body" : "{\calulateArea\": \"{{jsonPath request.boty}}\"}", "transformers" : [ "response-template" ] } }] }
Here is a rough version of my unit test.
@Test
public void testCalculation() throws IOException {
double base = 50.0;
double height = 20.0;
MessageOrBuilder calculateAreaRequestMsg = CalculateAreaRequest.newBuilder().setBase(base).setHeight(height);
MessageOrBuilder calculateAreaResponseMsg = CalculateAreaResult.newBuilder().setBase(base).setHeight(height).setArea(base * height);
mockGrpcCalculateAreaService.stubFor(method("calculateArea").withRequestMessage(equalToMessage(calculateAreaRequestMsg)).willReturn(message(calculateAreaResponseMsg)));
CalculateAreaResult result = calculateAreaClient.calculateArea(base, height);
assertEqual(100.0, result.getArea());
}
Hopefully, this is enough information to help me resolve my problem.
r
no need to send thread replies in the channel. it creates a lot of unnecessary noise.
ive ran your unit test locally (with some modification to get it to compile) and everything is working for me
is the grpc extension definitely registered?
r
Hello Rafe, What did you do to get my unit test to work for you? I assume that I registered the gRPC extension properly. I have the following at the top of my unit test file. Am I missing anything or am I doing something that is unnecessary?
private static fina String WIREMOCK_DIR = "src/test/resources/wiremock";
private static final ManagedChannel MANAGED_CHANNEL = ManagedChannelBuilder.forAddress("127.0.0.1", 9090).usePlaintext().build();
@RegisterExtension
static WireMockExtension wireMockExtension = WireMockExtension.newInstance()
.options(wireMockConfig.dynamicPort()
.withRootDirectory(WIREMOCK_DIR)
.extensions(new MockCalculateAreaService(MANAGED_CHANNEL))).build();
@BeforeEach
void init() {
wireMock = wireMockExtension.getRuntimeInfo().getWireMock();
mockGrpcCalculateAreaService = new WireMockGrpcService(wiremock, CalculateAreaServiceGrpc.SERVICE_NAME);
}
r
what is
MockCalculateAreaService
? try replacing
Copy code
.extensions(new MockCalculateAreaService(MANAGED_CHANNEL))).build();
with
Copy code
.extensions(new GrpcExtensionFactory())).build();
r
Ok, I implemented your fix. Unfortunately, I still have the Request not matched issue.
r
it's probably going to be easier if you provide a git repo that reproduces your issues that i can look at