Skip to content

Commit 96bad6f

Browse files
authored
Update AiCoreServiceTest.java
1 parent 7ec7dff commit 96bad6f

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

core/src/test/java/com/sap/ai/sdk/core/AiCoreServiceTest.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.sap.ai.sdk.core;
22

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;
37
import static org.assertj.core.api.Assertions.assertThat;
48
import static org.assertj.core.api.Assertions.assertThatCode;
59
import static org.assertj.core.api.Assertions.assertThatThrownBy;
610

11+
import com.github.tomakehurst.wiremock.WireMockServer;
712
import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination;
813
import com.sap.cloud.sdk.cloudplatform.connectivity.Header;
914
import com.sap.cloud.sdk.cloudplatform.connectivity.HttpDestination;
@@ -63,17 +68,30 @@ void testCustomBaseDestination() {
6368

6469
@Test
6570
void testGetInferenceDestination() {
66-
var builder = service.getInferenceDestination();
71+
// default resource group destination
72+
val builder = service.getInferenceDestination();
6773
assertThatThrownBy(() -> builder.forScenario("doesn't exist"))
6874
.isExactlyInstanceOf(DeploymentResolutionException.class);
6975

76+
// custom resource group destination
7077
val destination = service.getInferenceDestination("foo").usingDeploymentId("123");
71-
7278
assertThat(destination.getUri())
7379
.hasHost("api.ai.com")
7480
.hasPath("/v2/inference/deployments/123/");
75-
7681
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();
7795
}
7896

7997
@Test

0 commit comments

Comments
 (0)