Skip to content

Commit 01cd8da

Browse files
andreadimaiogeoand
authored andcommitted
Fix CI Issue and Improvement of test
1 parent 78aec0b commit 01cd8da

File tree

9 files changed

+420
-408
lines changed

9 files changed

+420
-408
lines changed

bam/deployment/src/test/java/com/ibm/generativeai/bam/deployment/HttpErrorTest.java

Lines changed: 0 additions & 282 deletions
This file was deleted.

bam/deployment/src/test/java/com/ibm/generativeai/bam/deployment/Util.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

bam/deployment/src/test/java/com/ibm/generativeai/bam/deployment/AiServiceTest.java renamed to bam/deployment/src/test/java/io/quarkiverse/langchain4j/bam/deployment/AiServiceTest.java

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
package com.ibm.generativeai.bam.deployment;
1+
package io.quarkiverse.langchain4j.bam.deployment;
22

3-
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
4-
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
5-
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
6-
import static com.github.tomakehurst.wiremock.client.WireMock.post;
7-
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
83
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
94
import static org.junit.jupiter.api.Assertions.assertEquals;
105

116
import java.util.List;
127

138
import jakarta.inject.Inject;
149
import jakarta.inject.Singleton;
15-
import jakarta.ws.rs.core.MediaType;
1610

1711
import org.jboss.shrinkwrap.api.ShrinkWrap;
1812
import org.jboss.shrinkwrap.api.spec.JavaArchive;
@@ -38,18 +32,20 @@ public class AiServiceTest {
3832

3933
static WireMockServer wireMockServer;
4034
static ObjectMapper mapper;
35+
static WireMockUtil mockServers;
4136

4237
@RegisterExtension
4338
static QuarkusUnitTest unitTest = new QuarkusUnitTest()
44-
.overrideRuntimeConfigKey("quarkus.langchain4j.bam.base-url", Util.URL)
45-
.overrideRuntimeConfigKey("quarkus.langchain4j.bam.api-key", Util.API_KEY)
46-
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClass(Util.class));
39+
.overrideRuntimeConfigKey("quarkus.langchain4j.bam.base-url", WireMockUtil.URL)
40+
.overrideRuntimeConfigKey("quarkus.langchain4j.bam.api-key", WireMockUtil.API_KEY)
41+
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClass(WireMockUtil.class));
4742

4843
@BeforeAll
4944
static void beforeAll() {
50-
wireMockServer = new WireMockServer(options().port(Util.PORT));
45+
wireMockServer = new WireMockServer(options().port(WireMockUtil.PORT));
5146
wireMockServer.start();
5247
mapper = BamRestApi.objectMapper(new ObjectMapper());
48+
mockServers = new WireMockUtil(wireMockServer);
5349
}
5450

5551
@AfterAll
@@ -90,27 +86,22 @@ void chat() throws Exception {
9086

9187
var body = new TextGenerationRequest(modelId, messages, parameters);
9288

93-
wireMockServer.stubFor(
94-
post(urlEqualTo(Util.URL_CHAT_API.formatted(config.version())))
95-
.withHeader("Authorization", equalTo("Bearer %s".formatted(Util.API_KEY)))
96-
.withRequestBody(equalToJson(mapper.writeValueAsString(body)))
97-
.willReturn(
98-
aResponse()
99-
.withHeader("Content-Type", MediaType.APPLICATION_JSON)
100-
.withStatus(200)
101-
.withBody("""
102-
{
103-
"results": [
104-
{
105-
"generated_token_count": 20,
106-
"input_token_count": 146,
107-
"stop_reason": "max_tokens",
108-
"seed": 40268626,
109-
"generated_text": "AI Response"
110-
}
111-
]
112-
}
113-
""")));
89+
mockServers.mockBuilder(200)
90+
.body(mapper.writeValueAsString(body))
91+
.response("""
92+
{
93+
"results": [
94+
{
95+
"generated_token_count": 20,
96+
"input_token_count": 146,
97+
"stop_reason": "max_tokens",
98+
"seed": 40268626,
99+
"generated_text": "AI Response"
100+
}
101+
]
102+
}
103+
""")
104+
.build();
114105

115106
assertEquals("AI Response", service.chat("Hello"));
116107
}

0 commit comments

Comments
 (0)