Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qing-wq committed Oct 11, 2024
1 parent 0f50324 commit e4be769
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ static class ComponentScanWithBasePackages {
static class ComponentScanWithBasePackageClasses {
}

@ComponentScan(basePackages = "${test.basePackages}")
static class ComponentScanWithPlaceholder {
}

@Test
void should_create_AI_service_that_use_componentScan_value() {

Expand Down Expand Up @@ -98,4 +102,30 @@ void should_create_AI_service_that_use_componentScan_basePackageClasses() {
assertThat(answer).containsIgnoringCase("Berlin");
});
}

@Test
void should_create_AI_service_that_use_componentScan_with_placeholder() {

contextRunner
.withPropertyValues(
"langchain4j.open-ai.chat-model.api-key=" + "sk-6d1s3M2cPvSCb6byweSI5GdekMo0FF87u3Cg1nhofwQyq2fA",
"langchain4j.open-ai.chat-model.base-url=" + "https://api.chatanywhere.tech",
"langchain4j.open-ai.chat-model.max-tokens=20",
"langchain4j.open-ai.chat-model.temperature=0.0",
"test.basePackages=dev.langchain4j.service.spring.mode.automatic.differentPackage.package2"
)
.withUserConfiguration(DifferentPackageAiServiceApplication.class)
.withUserConfiguration(ComponentScanWithBasePackageClasses.class)
.run(context -> {

// given
DifferentPackageAiService aiService = context.getBean(DifferentPackageAiService.class);

// when
String answer = aiService.chat("What is the capital of Germany?");

// then
assertThat(answer).containsIgnoringCase("Berlin");
});
}
}

0 comments on commit e4be769

Please sign in to comment.