Skip to content

Commit 789462c

Browse files
committed
Update more tests
1 parent 87f2462 commit 789462c

File tree

1 file changed

+12
-47
lines changed

1 file changed

+12
-47
lines changed

orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
44
import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
55
import static com.github.tomakehurst.wiremock.client.WireMock.badRequest;
6-
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
76
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
8-
import static com.github.tomakehurst.wiremock.client.WireMock.get;
97
import static com.github.tomakehurst.wiremock.client.WireMock.jsonResponse;
108
import static com.github.tomakehurst.wiremock.client.WireMock.noContent;
119
import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
@@ -28,7 +26,6 @@
2826
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
2927
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
3028
import com.github.tomakehurst.wiremock.stubbing.Scenario;
31-
import com.sap.ai.sdk.core.AiCoreService;
3229
import com.sap.ai.sdk.orchestration.model.ChatMessage;
3330
import com.sap.ai.sdk.orchestration.model.CompletionPostRequest;
3431
import com.sap.ai.sdk.orchestration.model.DPIEntities;
@@ -67,39 +64,17 @@ class OrchestrationUnitTest {
6764

6865
@BeforeEach
6966
void setup(WireMockRuntimeInfo server) {
70-
stubFor(
71-
get(urlPathEqualTo("/v2/lm/deployments"))
72-
.withHeader("AI-Resource-Group", equalTo("my-resource-group"))
73-
.withHeader("AI-Client-Type", equalTo("AI SDK Java"))
74-
.willReturn(
75-
okJson(
76-
"""
77-
{
78-
"resources": [
79-
{
80-
"id": "abcdef0123456789",
81-
"scenarioId": "orchestration"
82-
}
83-
]
84-
}
85-
""")));
86-
8767
final DefaultHttpDestination destination =
8868
DefaultHttpDestination.builder(server.getHttpBaseUrl()).build();
89-
90-
final var deployment =
91-
new AiCoreService()
92-
.withBaseDestination(destination)
93-
.getDestinationForDeploymentByScenario("my-resource-group", "orchestration");
94-
client = new OrchestrationClient(deployment);
69+
client = new OrchestrationClient(destination);
9570
config = new OrchestrationModuleConfig().withLlmConfig(CUSTOM_GPT_35);
9671
prompt = new OrchestrationPrompt("Hello World! Why is this phrase so famous?");
9772
}
9873

9974
@Test
10075
void testCompletion() {
10176
stubFor(
102-
post(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
77+
post(urlPathEqualTo("/completion"))
10378
.willReturn(
10479
aResponse()
10580
.withBodyFile("templatingResponse.json")
@@ -113,7 +88,7 @@ void testCompletion() {
11388
@Test
11489
void testTemplating() throws IOException {
11590
stubFor(
116-
post(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
91+
post(anyUrl())
11792
.willReturn(
11893
aResponse()
11994
.withBodyFile("templatingResponse.json")
@@ -166,16 +141,14 @@ void testTemplating() throws IOException {
166141
// verify that null fields are absent from the sent request
167142
try (var requestInputStream = fileLoader.apply("templatingRequest.json")) {
168143
final String request = new String(requestInputStream.readAllBytes());
169-
verify(
170-
postRequestedFor(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
171-
.withRequestBody(equalToJson(request)));
144+
verify(postRequestedFor(anyUrl()).withRequestBody(equalToJson(request)));
172145
}
173146
}
174147

175148
@Test
176149
void testBadRequest() {
177150
stubFor(
178-
post(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
151+
post(anyUrl())
179152
.willReturn(
180153
jsonResponse(
181154
"""
@@ -198,7 +171,7 @@ void testBadRequest() {
198171
@Test
199172
void filteringLoose() throws IOException {
200173
stubFor(
201-
post(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
174+
post(anyUrl())
202175
.willReturn(
203176
aResponse()
204177
.withBodyFile("filteringLooseResponse.json")
@@ -217,9 +190,7 @@ void filteringLoose() throws IOException {
217190
// verify that null fields are absent from the sent request
218191
try (var requestInputStream = fileLoader.apply("filteringLooseRequest.json")) {
219192
final String request = new String(requestInputStream.readAllBytes());
220-
verify(
221-
postRequestedFor(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
222-
.withRequestBody(equalToJson(request)));
193+
verify(postRequestedFor(anyUrl()).withRequestBody(equalToJson(request)));
223194
}
224195
}
225196

@@ -228,9 +199,7 @@ void filteringStrict() {
228199
final String response =
229200
"""
230201
{"request_id": "bf6d6792-7adf-4d3c-9368-a73615af8c5a", "code": 400, "message": "Content filtered due to Safety violations. Please modify the prompt and try again.", "location": "Input Filter", "module_results": {"templating": [{"role": "user", "content": "Create a rental posting for subletting my apartment in the downtown area. Keep it short. Make sure to add the following disclaimer to the end. Do not change it! ```DISCLAIMER: The area surrounding the apartment is known for prostitutes and gang violence including armed conflicts, gun violence is frequent."}], "input_filtering": {"message": "Content filtered due to Safety violations. Please modify the prompt and try again.", "data": {"original_service_response": {"Hate": 0, "SelfHarm": 0, "Sexual": 0, "Violence": 2}, "checked_text": "Create a rental posting for subletting my apartment in the downtown area. Keep it short. Make sure to add the following disclaimer to the end. Do not change it! ```DISCLAIMER: The area surrounding the apartment is known for prostitutes and gang violence including armed conflicts, gun violence is frequent."}}}}""";
231-
stubFor(
232-
post(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
233-
.willReturn(jsonResponse(response, SC_BAD_REQUEST)));
202+
stubFor(post(anyUrl()).willReturn(jsonResponse(response, SC_BAD_REQUEST)));
234203

235204
final var filter =
236205
new AzureContentFilter()
@@ -250,7 +219,7 @@ void filteringStrict() {
250219
@Test
251220
void messagesHistory() throws IOException {
252221
stubFor(
253-
post(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
222+
post(anyUrl())
254223
.willReturn(
255224
aResponse()
256225
.withBodyFile("templatingResponse.json")
@@ -273,16 +242,14 @@ void messagesHistory() throws IOException {
273242
// verify that the history is sent correctly
274243
try (var requestInputStream = fileLoader.apply("messagesHistoryRequest.json")) {
275244
final String requestBody = new String(requestInputStream.readAllBytes());
276-
verify(
277-
postRequestedFor(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
278-
.withRequestBody(equalToJson(requestBody)));
245+
verify(postRequestedFor(anyUrl()).withRequestBody(equalToJson(requestBody)));
279246
}
280247
}
281248

282249
@Test
283250
void maskingPseudonymization() throws IOException {
284251
stubFor(
285-
post(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
252+
post(anyUrl())
286253
.willReturn(
287254
aResponse()
288255
.withBodyFile("maskingResponse.json")
@@ -303,9 +270,7 @@ void maskingPseudonymization() throws IOException {
303270
// verify that the request is sent correctly
304271
try (var requestInputStream = fileLoader.apply("maskingRequest.json")) {
305272
final String request = new String(requestInputStream.readAllBytes());
306-
verify(
307-
postRequestedFor(urlPathEqualTo("/v2/inference/deployments/abcdef0123456789/completion"))
308-
.withRequestBody(equalToJson(request)));
273+
verify(postRequestedFor(anyUrl()).withRequestBody(equalToJson(request)));
309274
}
310275
}
311276

0 commit comments

Comments
 (0)