embeddign优化
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package com.cst.langchain4jheima.service;
|
||||
|
||||
/**
|
||||
* Author: 李中华 wx: spllzh email(qq): 28668817@qq.com
|
||||
* Date: 2025/8/5 19:02
|
||||
**/
|
||||
|
||||
|
||||
import com.cst.langchain4jheima.Langchain4jHeima20250803Application;
|
||||
import com.cst.langchain4jheima.pojo.Reservation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
||||
@SpringBootTest(classes = Langchain4jHeima20250803Application.class)
|
||||
class ReservationServiceTest {
|
||||
|
||||
@Autowired
|
||||
private IReservationService reservationService;
|
||||
|
||||
@Test
|
||||
void testSaveReservation() {
|
||||
// 创建测试数据
|
||||
Reservation reservation = new Reservation();
|
||||
reservation.setName("张三");
|
||||
reservation.setGender("男");
|
||||
reservation.setPhone("13800138000");
|
||||
reservation.setProvince("北京市");
|
||||
reservation.setDatetime(LocalDateTime.now());
|
||||
|
||||
// 测试保存功能
|
||||
boolean result = reservationService.save(reservation);
|
||||
|
||||
// 验证保存成功
|
||||
assertTrue(result);
|
||||
assertNotNull(reservation.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetReservationsByPhone() {
|
||||
// 先保存一条测试数据
|
||||
Reservation reservation = new Reservation();
|
||||
reservation.setName("李四");
|
||||
reservation.setGender("女");
|
||||
reservation.setPhone("13900139000");
|
||||
reservation.setProvince("上海市");
|
||||
reservation.setDatetime(LocalDateTime.now());
|
||||
reservationService.save(reservation);
|
||||
|
||||
// 测试根据手机号查询功能
|
||||
List<Reservation> reservations = ((com.cst.langchain4jheima.service.impl.ReservationServiceImpl) reservationService)
|
||||
.getReservationsByPhone("13900139000");
|
||||
|
||||
// 验证查询结果
|
||||
assertNotNull(reservations);
|
||||
assertFalse(reservations.isEmpty());
|
||||
assertEquals("李四", reservations.get(0).getName());
|
||||
assertEquals("13900139000", reservations.get(0).getPhone());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetReservationsByPhoneWithNoResults() {
|
||||
// 测试查询不存在的手机号
|
||||
List<Reservation> reservations = ((com.cst.langchain4jheima.service.impl.ReservationServiceImpl) reservationService)
|
||||
.getReservationsByPhone("00000000000");
|
||||
|
||||
// 验证查询结果为空
|
||||
assertNotNull(reservations);
|
||||
assertTrue(reservations.isEmpty());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user