Commit e93932d3 by hxw

新文件: test/java/com/qiwu/chatbotbackend/ChatCacheTests.java 新文件:

test/java/com/qiwu/chatbotbackend/ChatbotBackendApplicationTests.java 新文件: test/java/com/qiwu/chatbotbackend/FileDeleteTests.java 新文件: test/java/com/qiwu/chatbotbackend/InterfaceTests.java 新文件: test/java/com/qiwu/chatbotbackend/PremiseTests.java 新文件: test/java/com/qiwu/chatbotbackend/VarSlotReplaceTests.java 新文件: test/java/com/qiwu/chatbotbackend/WorldTests.java
parent 21a106ae
package com.qiwu.chatbotbackend;
import com.alibaba.fastjson.JSONObject;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.entity.ArchiveInfo;
import com.qiwu.chatbotbackend.entity.ChatCache;
import com.qiwu.chatbotbackend.processing.ChatCacheController;
import com.qiwu.chatbotbackend.task.utils.DataDeliver;
import org.junit.Test;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.web.WebAppConfiguration;
import javax.servlet.ServletContext;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
@WebAppConfiguration
public class ChatCacheTests {
@Test
public void testFindChatCache() throws Exception {
ServletContext context = new MockServletContext();
Map<String, String> hisInfoPoint = new HashMap<String, String>(){
{
put("site", "Junit");
}
};
GameEnv gameEnv = new GameEnv("7011489633");
ChatCache chatCache = new ChatCache("1112@@@123456789", "rand");
chatCache.setGameEnv(gameEnv);
chatCache.setInfoPoint(hisInfoPoint);
chatCache.setGameStart(true);
//先删除就数据
SqlHelper helper = new SqlHelper();
ChatCacheController.deleteChatCache(helper, "123456789");
Map<String, ChatCache> chatCacheMap = null;
chatCacheMap = new HashMap<String, ChatCache>();
context.setAttribute("chatCache", chatCacheMap);
assertEquals(false, ChatCacheController.findChatCache("111@@@123456789", context));
assertEquals(false, ChatCacheController.findChatCache("1112@@@123456789", context));
chatCacheMap.put("1112@@@123456789", chatCache);
assertEquals(true, ChatCacheController.findChatCache("1112@@@123456789", context));
Boolean flag = ChatCacheController.findChatCache("1112@@@123456789", context);
assertEquals(true, flag);
}
public void testDataDeliver(){
System.out.println("开始");
DataDeliver deliver = new DataDeliver();
JSONObject data = new JSONObject();
data.put("chat_key", "101@@@123456789@@@@123");
data.put("data_type", "archiveList");
data.put("data", new JSONObject());
deliver.setData(data);
deliver.start();
//while(true){}
}
public void testArchiveQuery(){
SqlHelper helper = null;
try {
helper = new SqlHelper();
} catch (SQLException e) {
e.printStackTrace();
}
List<ArchiveInfo> archiveList = helper.queryArchiveByUserKey("@jXgDt40DXCR22Jk7XcJU");
assertEquals(1, archiveList.size());
}
}
package com.qiwu.chatbotbackend;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ChatbotBackendApplicationTests {
@Test
public void contextLoads() {
}
}
package com.qiwu.chatbotbackend;
import com.qiwu.chatbotbackend.db.SqlHelper;
import com.qiwu.chatbotbackend.task.utils.FileFinder;
import org.junit.Test;
import static com.qiwu.chatbotbackend.processing.ChatCacheController.CHAT_CACHE_DIR;
public class FileDeleteTests {
@Test
public void testQuery() throws Exception {
FileFinder.deleteGameArchive(CHAT_CACHE_DIR, "1234567");
SqlHelper helper = new SqlHelper();
helper.deleteArchiveByBotAccount("12345678");
helper.destroy();
}
}
package com.qiwu.chatbotbackend;
import org.junit.Test;
import org.springframework.mock.web.MockServletContext;
import javax.servlet.ServletContext;
import java.util.HashMap;
import java.util.Map;
public class InterfaceTests {
@Test
public void test(){
//Request
ServletContext context = new MockServletContext();
Map<String, String> hisInfoPoint = new HashMap<String, String>(){
{
put("site", "Junit");
}
};
}
}
package com.qiwu.chatbotbackend;
import com.qiwu.chatbotbackend.processing.ActionMatcher;
import org.junit.Test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class PremiseTests {
@Test
public void testpremise() throws Exception {
Map<String, String> curInfoPoint = new HashMap<String, String>() {
{
put("testCondition", "cc:瑞娜");
put("testCondition2", "数量:蓝色药水");
put("testCondition3", "瑞娜:友好度");
put("testCondition4", "瑞娜:友好度");
put("testCondition5", " :瑞娜");
}
};
Map<String, String> hisInfoPoint = new HashMap<String, String>() {
{
put("site", "海边");
}
};
String keyword1 = "+2+1+3+4+6+5+7";
HashSet<String> keywordSet1 = new HashSet<String>(){
{
add("1");
add("2");
}
};
String keyword2 = "+2+1+3+4+6+5+7";
HashSet<String> keywordSet2 = new HashSet<String>(){
{
add("1");
add("2");
add("10");
}
};
String keyword3 = "+2+1+3+4+6+5+7";
HashSet<String> keywordSet3 = new HashSet<String>(){
{
add("10");
add("2");
}
};
HashSet<String> keywordSet4 = new HashSet<String>(){
{
add("");
}
};
String exculdeTestKeywords = "";
ActionMatcher matcher = new ActionMatcher();
Boolean result1 = matcher.premiseSatisfy(keyword1, "match-Have", keywordSet1);
Boolean result2 = matcher.premiseSatisfy(keyword2, "match-Have", keywordSet2);
Boolean result3 = matcher.premiseSatisfy(exculdeTestKeywords, "match-Exlucde", keywordSet2);
Boolean result4 = matcher.premiseSatisfy(keyword3, "match-NotHave", keywordSet3);
Boolean result5 = matcher.premiseSatisfy(keyword3, "match-Any", keywordSet3);
Boolean result6 = matcher.premiseSatisfy("", "match-Any", keywordSet4);
//result = controller.worldOperation(gameEnv, "goods_query", "queryAroundGoodsByClassName:testCondition4", curInfoPoint, hisInfoPoint);
assertEquals(true, result1);
assertEquals(false, result2);
assertEquals(false, result3);
assertEquals(false, result4);
assertEquals(true, result5);
assertEquals(false, result6);
}
}
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<String, StringBuffer> varInitialMap = new HashMap<String, StringBuffer>() {
{
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<String, String> curInfoPoint = new HashMap<String, String>() {
{
put("testCondition", "cc:瑞娜");
put("testCondition2", "数量:蓝色药水");
put("testCondition3", "瑞娜:友好度");
put("testCondition4", "瑞娜:友好度");
put("testCondition5", " :瑞娜");
}
};
Map<String, String> hisInfoPoint = new HashMap<String, String>() {
{
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"));
}
}
package com.qiwu.chatbotbackend;
import com.qiwu.chatbotbackend.GameEnvironment.GameEnv;
import com.qiwu.chatbotbackend.processing.LogWriter;
import com.qiwu.chatbotbackend.processing.WorldController;
import org.junit.Assert;
import org.junit.Test;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class WorldTests {
@Test
public void testQuery() throws Exception {
String result = "";
Map<String , String> curInfoPoint = new HashMap<String, String>(){
{
put("testCondition", "cc:瑞娜");
put("testCondition2", "数量:蓝色药水");
put("testCondition3", "瑞娜:友好度");
put("testCondition4", "瑞娜:友好度");
put("testCondition5", " :瑞娜");
}
};
Map<String , String> hisInfoPoint = new HashMap<String, String>(){
{
put("site", "海边");
}
};
LogWriter logWriter = new LogWriter("config", "text");
// GameEnv gameEnv = new GameEnv("3474861621");
// WorldController controller = new WorldController(logWriter);
//
// result = controller.worldOperation(gameEnv, "goods_query", "queryAttrByGoodsName:testCondition2", curInfoPoint, hisInfoPoint);
// System.out.println(result);
// assertEquals("2", result);
//
// result = controller.worldOperation(gameEnv, "map_query", "queryCanGoBySite:2", curInfoPoint, hisInfoPoint);
// System.out.println(result);
// assertEquals("有、山洞、沙滩、营地", result);
//
// result = controller.worldOperation(gameEnv, "NPC_query", "queryAttrByNPCName:testCondition3", curInfoPoint, hisInfoPoint);
// System.out.println(result);
// assertEquals("100", result);
//
// /**
// * 方法暂不存在
// *
// result = controller.worldOperation(gameEnv, "goods_query", "queryAroundGoodsByClassName:testCondition4", curInfoPoint, hisInfoPoint);
// System.out.println(result);
// assertEquals("100", result);
// */
//
// result = controller.worldOperation(gameEnv, "NPC_query", "queryNpcIntro:testCondition5", curInfoPoint, hisInfoPoint);
// System.out.println(result);
// assertEquals("至始至终的帮手", result);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment