|
| 1 | +package io.dapr.it.methodinvoke.http; |
| 2 | + |
| 3 | +import com.github.tomakehurst.wiremock.WireMockServer; |
| 4 | +import com.github.tomakehurst.wiremock.client.WireMock; |
| 5 | +import io.dapr.client.DaprClient; |
| 6 | +import io.dapr.client.DaprClientBuilder; |
| 7 | +import io.dapr.client.domain.HttpExtension; |
| 8 | +import org.junit.jupiter.api.AfterAll; |
| 9 | +import org.junit.jupiter.api.BeforeAll; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | + |
| 12 | +import java.util.Map; |
| 13 | + |
| 14 | +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
| 15 | +import static com.github.tomakehurst.wiremock.client.WireMock.post; |
| 16 | +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; |
| 17 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; |
| 18 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 19 | +import static org.junit.jupiter.api.Assertions.fail; |
| 20 | + |
| 21 | +public class GH_1314_IT { |
| 22 | + |
| 23 | + private static WireMockServer wireMockServer; |
| 24 | + |
| 25 | + @BeforeAll |
| 26 | + static void setup() { |
| 27 | + wireMockServer = new WireMockServer(3500); |
| 28 | + |
| 29 | + wireMockServer.start(); |
| 30 | + |
| 31 | + WireMock.configureFor("localhost", 3500); |
| 32 | + |
| 33 | + stubFor(post( |
| 34 | + urlEqualTo("/v1.0/invoke/say-hello/method/say-hello/hello") |
| 35 | + ) |
| 36 | + .willReturn(aResponse() |
| 37 | + .withStatus(200) |
| 38 | + .withHeader("Content-Type", "application/json") |
| 39 | + .withBody("\"Hello from say-hello app!\""))); |
| 40 | + } |
| 41 | + |
| 42 | + @AfterAll |
| 43 | + static void teardown() { |
| 44 | + wireMockServer.stop(); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void testInvokeSayHelloWithoutLeadingSlash() { |
| 49 | + String urlWithoutLeadingSlash = "say-hello/hello"; |
| 50 | + |
| 51 | + sayHelloUsingURL(urlWithoutLeadingSlash); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void testInvokeSayHelloWithLeadingSlash() { |
| 56 | + String urlWithLeadingSlash = "/say-hello/hello"; |
| 57 | + |
| 58 | + sayHelloUsingURL(urlWithLeadingSlash); |
| 59 | + } |
| 60 | + |
| 61 | + private static void sayHelloUsingURL(String url) { |
| 62 | + DaprClient client = new DaprClientBuilder().build(); |
| 63 | + |
| 64 | + try { |
| 65 | + Map<String, String> requestData = Map.of("message", "Hello"); |
| 66 | + |
| 67 | + String response = client.invokeMethod( |
| 68 | + "say-hello", |
| 69 | + url, |
| 70 | + requestData, |
| 71 | + HttpExtension.POST, |
| 72 | + String.class |
| 73 | + ).block(); |
| 74 | + |
| 75 | + assertEquals("Hello from say-hello app!", response); |
| 76 | + } catch (Exception e) { |
| 77 | + fail("Exception occurred: " + e.getMessage()); |
| 78 | + } finally { |
| 79 | + try { |
| 80 | + client.close(); |
| 81 | + } catch (Exception e) { |
| 82 | + fail(e); |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | +} |
0 commit comments