1 package com.foxinmy.weixin4j.wxa.api;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.io.IOException;
6 import java.io.InputStream;
7
8 import org.junit.Test;
9
10 import com.alibaba.fastjson.JSON;
11 import com.foxinmy.weixin4j.util.IOUtil;
12
13 public class TemplateResultTest {
14
15 @Test
16 public void test() throws IOException {
17 TemplateResult t = readTemplate();
18 assertEquals(0, t.getErrCode());
19 assertEquals("ok", t.getErrMsg());
20 assertEquals("AT0002", t.getId());
21 assertEquals("购买成功通知", t.getTitle());
22 assertEquals(3, t.getKeywords().size());
23 assertEquals(3, t.getKeywords().get(0).getId());
24 assertEquals("购买地点", t.getKeywords().get(0).getName());
25 assertEquals("TIT造舰厂", t.getKeywords().get(0).getExample());
26 }
27
28 private TemplateResult readTemplate() throws IOException {
29 InputStream inputStream = getClass().getResourceAsStream("Template.json");
30 try {
31 TemplateResult t = JSON.parseObject(inputStream, TemplateResult.class);
32 return t;
33 } finally {
34 IOUtil.close(inputStream);
35 }
36 }
37
38 }