|
24 | 24 | import io.dapr.client.domain.State;
|
25 | 25 | import io.dapr.client.domain.StateOptions;
|
26 | 26 | import io.dapr.client.domain.TransactionalStateOperation;
|
| 27 | +import io.dapr.client.domain.response.DaprResponse; |
27 | 28 | import io.dapr.config.Properties;
|
28 | 29 | import io.dapr.exceptions.DaprException;
|
29 | 30 | import io.dapr.serializer.DaprObjectSerializer;
|
|
39 | 40 | import okio.BufferedSink;
|
40 | 41 | import org.junit.Before;
|
41 | 42 | import org.junit.Test;
|
| 43 | +import org.junit.jupiter.api.Assertions; |
42 | 44 | import org.mockito.Mockito;
|
43 | 45 | import reactor.core.publisher.Mono;
|
44 | 46 | import reactor.util.context.Context;
|
@@ -417,7 +419,47 @@ public void invokeServiceWithContext() {
|
417 | 419 | }
|
418 | 420 |
|
419 | 421 | @Test
|
420 |
| - public void invokeBinding() { |
| 422 | + public void invokeServiceReturnResponse() throws IOException { |
| 423 | + String resultString = "request success"; |
| 424 | + String resultHeaderName = "test-header"; |
| 425 | + String resultHeaderValue = "1"; |
| 426 | + mockInterceptor.addRule() |
| 427 | + .post("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder") |
| 428 | + .respond(resultString) |
| 429 | + .addHeader(resultHeaderName,resultHeaderValue); |
| 430 | + |
| 431 | + InvokeMethodRequest req = new InvokeMethodRequest("41", "neworder") |
| 432 | + .setBody("request") |
| 433 | + .setHttpExtension(HttpExtension.POST); |
| 434 | + Mono<DaprResponse<String>> result = daprClientHttp.invokeMethod(req, new TypeRef<DaprResponse<String>>() {}); |
| 435 | + DaprResponse<String> response = result.block(); |
| 436 | + Assertions.assertNotNull(response); |
| 437 | + Assertions.assertEquals(200, response.getCode()); |
| 438 | + Assertions.assertEquals(resultString,response.getData()); |
| 439 | + Assertions.assertEquals(resultHeaderValue,response.getHeaders().get(resultHeaderName)); |
| 440 | + } |
| 441 | + |
| 442 | + @Test |
| 443 | + public void invokeBinding() throws IOException { |
| 444 | + String resultString = "request success"; |
| 445 | + String resultHeaderName = "test-header"; |
| 446 | + String resultHeaderValue = "1"; |
| 447 | + Map<String, String> map = new HashMap<>(); |
| 448 | + mockInterceptor.addRule() |
| 449 | + .post("http://127.0.0.1:3000/v1.0/bindings/sample-topic") |
| 450 | + .respond(resultString) |
| 451 | + .addHeader(resultHeaderName,resultHeaderValue); |
| 452 | + |
| 453 | + Mono<DaprResponse<String>> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", new TypeRef<DaprResponse<String>>() {}); |
| 454 | + DaprResponse<String> response = mono.block(); |
| 455 | + Assertions.assertNotNull(response); |
| 456 | + Assertions.assertEquals(200, response.getCode()); |
| 457 | + Assertions.assertEquals(resultString,response.getData()); |
| 458 | + Assertions.assertEquals(resultHeaderValue,response.getHeaders().get(resultHeaderName)); |
| 459 | + } |
| 460 | + |
| 461 | + @Test |
| 462 | + public void invokeBindingReturnResponse() { |
421 | 463 | Map<String, String> map = new HashMap<>();
|
422 | 464 | mockInterceptor.addRule()
|
423 | 465 | .post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
|
0 commit comments