View Javadoc
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 TemplateListResultTest {
14  
15  	@Test
16  	public void testTemplatesInLibrary() throws IOException {
17  		TemplateListResult r = readTemplateList("TemplateListInLibrary.json");
18  		assertEquals(0, r.getErrCode());
19  		assertEquals("ok", r.getErrMsg());
20  		assertEquals(599, r.getTotalCount().longValue());
21  
22  		assertEquals(5, r.getList().size());
23  
24  		assertEquals("AT0002", r.getList().get(0).getId());
25  		assertEquals("购买成功通知", r.getList().get(0).getTitle());
26  
27  		assertEquals("AT0003", r.getList().get(1).getId());
28  		assertEquals("购买失败通知", r.getList().get(1).getTitle());
29  	}
30  
31  	@Test
32  	public void testMyTemplates() throws IOException {
33  		TemplateListResult r = readTemplateList("TemplateList.json");
34  		assertEquals(0, r.getErrCode());
35  		assertEquals("ok", r.getErrMsg());
36  		assertEquals("wDYzYZVxobJivW9oMpSCpuvACOfJXQIoKUm0PY397Tc", r.getList().get(0).getId());
37  		assertEquals("购买成功通知", r.getList().get(0).getTitle());
38  		assertEquals("购买地点{{keyword1.DATA}}\n购买时间{{keyword2.DATA}}\n物品名称{{keyword3.DATA}}\n", r.getList().get(0).getContent());
39  		assertEquals("购买地点:TIT造舰厂\n购买时间:2016年6月6日\n物品名称:咖啡\n", r.getList().get(0).getExample());
40  	}
41  
42  	private TemplateListResult readTemplateList(String resourceName) throws IOException {
43  		InputStream inputStream = getClass().getResourceAsStream(resourceName);
44  		try {
45  			TemplateListResult tl = JSON.parseObject(inputStream, TemplateListResult.class);
46  			return tl;
47  		} finally {
48  			IOUtil.close(inputStream);
49  		}
50  	}
51  
52  }