|
1 | 1 | package com.sap.ai.sdk.core; |
2 | 2 |
|
| 3 | +import static com.github.tomakehurst.wiremock.client.WireMock.get; |
| 4 | +import static com.github.tomakehurst.wiremock.client.WireMock.okJson; |
| 5 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; |
| 6 | +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; |
3 | 7 | import static org.assertj.core.api.Assertions.assertThat; |
4 | 8 | import static org.assertj.core.api.Assertions.assertThatCode; |
5 | 9 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
6 | 10 |
|
| 11 | +import com.github.tomakehurst.wiremock.WireMockServer; |
7 | 12 | import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination; |
8 | 13 | import com.sap.cloud.sdk.cloudplatform.connectivity.Header; |
9 | 14 | import com.sap.cloud.sdk.cloudplatform.connectivity.HttpDestination; |
@@ -63,17 +68,30 @@ void testCustomBaseDestination() { |
63 | 68 |
|
64 | 69 | @Test |
65 | 70 | void testGetInferenceDestination() { |
66 | | - var builder = service.getInferenceDestination(); |
| 71 | + // default resource group destination |
| 72 | + val builder = service.getInferenceDestination(); |
67 | 73 | assertThatThrownBy(() -> builder.forScenario("doesn't exist")) |
68 | 74 | .isExactlyInstanceOf(DeploymentResolutionException.class); |
69 | 75 |
|
| 76 | + // custom resource group destination |
70 | 77 | val destination = service.getInferenceDestination("foo").usingDeploymentId("123"); |
71 | | - |
72 | 78 | assertThat(destination.getUri()) |
73 | 79 | .hasHost("api.ai.com") |
74 | 80 | .hasPath("/v2/inference/deployments/123/"); |
75 | | - |
76 | 81 | assertThat(destination.getHeaders()).containsExactly(new Header("AI-Resource-Group", "foo")); |
| 82 | + |
| 83 | + // scenario-based destination |
| 84 | + val d = "{\"count\":1,\"resources\":[{\"id\":\"0123456789abcdef\",\"scenarioId\":\"foobar\"}]}"; |
| 85 | + val server = new WireMockServer(wireMockConfig().dynamicPort()); |
| 86 | + server.start(); |
| 87 | + server.stubFor(get(urlEqualTo("/v2/lm/deployments")).willReturn(okJson(d))); |
| 88 | + HttpDestination foobar = |
| 89 | + service |
| 90 | + .withBaseDestination(DefaultHttpDestination.builder(server.baseUrl() + "/v2/").build()) |
| 91 | + .getInferenceDestination() |
| 92 | + .forScenario("foobar"); |
| 93 | + assertThat(foobar.getUri()).hasPath("/v2/inference/deployments/0123456789abcdef/"); |
| 94 | + server.stop(); |
77 | 95 | } |
78 | 96 |
|
79 | 97 | @Test |
|
0 commit comments