package com.qiwu.chatbotbackend; import com.alibaba.fastjson.JSONObject; import com.qiwu.chatbotbackend.entity.ChatCache; import com.qiwu.chatbotbackend.gameDesign.PlotConstructor2; import com.qiwu.chatbotbackend.processing.ActionMatcher; import com.qiwu.chatbotbackend.task.utils.BasicBotUtil; import org.junit.Test; import java.util.HashMap; import java.util.Map; import static org.junit.Assert.assertEquals; public class VarSlotReplaceTests { @Test public void testPlotReplace() throws Exception { Map varInitialMap = new HashMap() { { put("onlineModeTalkers", new StringBuffer(",哈娜,张三,李四,王五")); } }; JSONObject branchNode = new JSONObject(); branchNode.put("plotText", "【张三@正常】sdf${sdfs}【李四@正常】sdf${sdfs}【大侠@正常】sdf${sdfs}【无知@正常】sdf${sdfs}"); PlotConstructor2.varSlotFilt(branchNode, varInitialMap); assertEquals("【张三@正常】sdf${sdfs}【李四@正常】sdf${sdfs}【大侠@正常】sdf【无知@正常】sdf", branchNode.getString("plotText")); } @Test public void testReplyReplace() throws Exception { ActionMatcher matcher = new ActionMatcher(); Map curInfoPoint = new HashMap() { { put("testCondition", "cc:瑞娜"); put("testCondition2", "数量:蓝色药水"); put("testCondition3", "瑞娜:友好度"); put("testCondition4", "瑞娜:友好度"); put("testCondition5", " :瑞娜"); } }; Map hisInfoPoint = new HashMap() { { put("site", "海边"); } }; ChatCache chatCache = new ChatCache("1", "1"); chatCache.setInfoPoint(hisInfoPoint); BasicBotUtil botUtil = new BasicBotUtil(curInfoPoint, chatCache, null, null); assertEquals("瑞娜sdfs", botUtil.varSlotReplace("{testCondition-1}sdfs")); assertEquals("海边sdfs", botUtil.varSlotReplace("{site-2}sdfs")); } }