package test.com.sqsoft.mars.qyweixin.client;

import static org.junit.Assert.*;

import org.junit.Test;

import com.sqsoft.mars.qyweixin.client.QyweixinClient;
import com.sqsoft.mars.qyweixin.client.cgibin.QyweixinCgibinClient;
import com.sqsoft.mars.qyweixin.client.cgibin.QyweixinGettokenRequest;
import com.sqsoft.mars.qyweixin.client.cgibin.QyweixinGettokenResponse;
import com.sqsoft.mars.qyweixin.client.cgibin.material.QyweixinMaterialBatchgetMaterialRequest;
import com.sqsoft.mars.qyweixin.client.cgibin.material.QyweixinMaterialBatchgetMaterialResponse;
import com.sqsoft.mars.qyweixin.client.cgibin.material.QyweixinMaterialBatchgetMpnewsRequest;
import com.sqsoft.mars.qyweixin.client.cgibin.material.QyweixinMaterialBatchgetMpnewsResponse;
import com.sqsoft.mars.qyweixin.client.cgibin.material.QyweixinMaterialClient;
import com.sqsoft.mars.qyweixin.client.execption.QyweixinClientException;

public class TestQyweixinMaterialClient {

	@Test
	public void testExecute() {
		QyweixinMaterialBatchgetMaterialRequest request = new QyweixinMaterialBatchgetMaterialRequest(
				"image");

		request.setOffset(0);
		request.setCount(10);

		request.setAgentid(1);
		QyweixinClient token = new QyweixinCgibinClient("wxaaae3495d41bd64b",
				"TCZCLVrbHo8-R6TGSwte3vYNMn40j0PDoUBKyduYg6pz6gA3Z9f8dT0T33TuBVsM");
		//		QyweixinClient token = new QyweixinCgibinClient("wxd9a0829ab457ae00",
		//				"s73sHOpOxvEtWxn_X0wSTahwPV3OFvDIRq3CMTzcjTbpPvWAD-h5sORxndjT5t14");
		try {
			QyweixinGettokenResponse res = token
					.execute(new QyweixinGettokenRequest());

			QyweixinMaterialClient client = new QyweixinMaterialClient(
					res.getAccess_token());

			QyweixinMaterialBatchgetMaterialResponse response = client
					.execute(request);
			 System.out.println(response.getItemlist().iterator().next()
			 .getFilename());

			QyweixinMaterialBatchgetMpnewsRequest request2 = new QyweixinMaterialBatchgetMpnewsRequest();
			request2.setOffset(0);
			request2.setCount(10);

			request2.setAgentid(1);
			QyweixinMaterialBatchgetMpnewsResponse r = client.execute(request2);
			System.out.println(r.getItemlist().iterator().next().getContent()
					.getArticles().iterator().next().getThumb_media_id());
		} catch (QyweixinClientException e) {
			e.printStackTrace();
		}
	}

}
