feat(ai-house): 解除房源与资料库强绑定
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package com.gxwebsoft.house.ai;
|
||||
|
||||
import com.gxwebsoft.house.entity.HouseKnowledgeEntry;
|
||||
import com.gxwebsoft.house.entity.HouseKnowledgeLocation;
|
||||
import com.gxwebsoft.house.service.HouseKnowledgeService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyCollection;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class HouseAiKnowledgeSearchEngineTest {
|
||||
|
||||
@Mock
|
||||
private HouseKnowledgeService houseKnowledgeService;
|
||||
|
||||
private HouseAiKnowledgeSearchEngine searchEngine;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
searchEngine = new HouseAiKnowledgeSearchEngine();
|
||||
ReflectionTestUtils.setField(searchEngine, "houseKnowledgeService", houseKnowledgeService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void fuzzyNameSearchReturnsKnowledgeWithoutHouseBinding() {
|
||||
HouseKnowledgeLocation location = location(101, "航洋国际城");
|
||||
HouseKnowledgeEntry entry = new HouseKnowledgeEntry();
|
||||
entry.setEntryId(9001);
|
||||
entry.setLocationId(101);
|
||||
entry.setTitle("水电收费");
|
||||
entry.setContent("水费按表计费,电费按商业标准计费");
|
||||
when(houseKnowledgeService.listLocations(any(), eq(2001)))
|
||||
.thenReturn(Collections.singletonList(location));
|
||||
when(houseKnowledgeService.listActiveEntries(anyCollection(), eq(2001)))
|
||||
.thenReturn(Collections.singletonList(entry));
|
||||
|
||||
HouseAiKnowledgeSearchResult result = searchEngine.search("航洋城", "南宁", "fuzzy",
|
||||
0, 20, 2001);
|
||||
|
||||
assertEquals(1, result.getTotalCount());
|
||||
assertEquals("航洋国际城", result.getItems().get(0).getLocationName());
|
||||
assertEquals(9001, result.getItems().get(0).getEntryId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyKeywordReturnsAllEntriesWithCursor() {
|
||||
HouseKnowledgeLocation location = location(101, "航洋城");
|
||||
HouseKnowledgeEntry first = new HouseKnowledgeEntry();
|
||||
first.setEntryId(1);
|
||||
first.setLocationId(101);
|
||||
first.setTitle("物业");
|
||||
HouseKnowledgeEntry second = new HouseKnowledgeEntry();
|
||||
second.setEntryId(2);
|
||||
second.setLocationId(101);
|
||||
second.setTitle("停车");
|
||||
when(houseKnowledgeService.listLocations(any(), eq(2001)))
|
||||
.thenReturn(Collections.singletonList(location));
|
||||
when(houseKnowledgeService.listActiveEntries(anyCollection(), eq(2001)))
|
||||
.thenReturn(java.util.Arrays.asList(first, second));
|
||||
|
||||
HouseAiKnowledgeSearchResult result = searchEngine.search(null, "南宁", "exact",
|
||||
0, 1, 2001);
|
||||
|
||||
assertEquals(2, result.getTotalCount());
|
||||
assertEquals(1, result.getItems().size());
|
||||
assertEquals(Integer.valueOf(1), result.getNextCursor());
|
||||
}
|
||||
|
||||
private HouseKnowledgeLocation location(int id, String name) {
|
||||
HouseKnowledgeLocation location = new HouseKnowledgeLocation();
|
||||
location.setLocationId(id);
|
||||
location.setCity("南宁");
|
||||
location.setLocationType(HouseKnowledgeLocation.TYPE_COMMUNITY);
|
||||
location.setLocationName(name);
|
||||
location.setStatus(0);
|
||||
return location;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user