1 Star 0 Fork 191

984141790 / hm-tools-wxmp-adapter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ReplyMessagesTest.java 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
JHybo 提交于 2020-06-04 23:52 . 被动回复用户消息 测试 OK
package top.hmtools.wxmp.message;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.jsonzou.jmockdata.JMockData;
import top.hmtools.wxmp.core.model.message.BaseMessage;
import top.hmtools.wxmp.message.reply.model.EReplyMessages;
public class ReplyMessagesTest {
private final Logger logger = LoggerFactory.getLogger(ReplyMessagesTest.class);
private ObjectMapper objectMapper;
@Test
public void generateReplyMessageBean(){
EReplyMessages[] values = EReplyMessages.values();
for(EReplyMessages item:values){
BaseMessage message = (BaseMessage)JMockData.mock(item.getClassName());
this.printFormatedJson(item.getEventName()+"(json)", message);
this.logger.info(item.getEventName()+"(xml):\r\n{}",message.toXmlMsg());
}
}
/**
* 格式化打印json字符串到控制台
* @param title
* @param obj
*/
protected synchronized void printFormatedJson(String title,Object obj) {
if(this.objectMapper == null){
this.objectMapper = new ObjectMapper();
}
try {
//阿里的fastjson具有很好的兼容性,所以才多次一举
String jsonString = JSON.toJSONString(obj);
Object tempObj = JSON.parse(jsonString);
String formatedJsonStr = this.objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(tempObj);
this.logger.info("\n{}:\n{}",title,formatedJsonStr);
} catch (JsonProcessingException e) {
this.logger.error("格式化打印json异常:",e);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/qj153291/hm-tools-wxmp-adapter.git
git@gitee.com:qj153291/hm-tools-wxmp-adapter.git
qj153291
hm-tools-wxmp-adapter
hm-tools-wxmp-adapter
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891