ExampleControllerTest.java 3.25 KB
package cn.com.glsx.merchants.controller;

import java.net.URL;
import java.util.Base64;

import cn.com.glsx.merchants.model.request.MerchantRequest;
import cn.com.glsx.merchants.remote.MerchantRemote;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import com.rop.request.UploadFile;

/**
 * @Title: ExampleControllerTest.java
 * @Description:
 * @author Alvin  
 * @date 2019年9月3日 上午9:33:00
 * @version V1.0  
 * @Company: didihu.com.cn
 * @Copyright Copyright (c) 2018
 */
public class ExampleControllerTest extends BaseControllerTest {
	@Autowired
	private MerchantRemote merchantRemote;

	@Test
	public void testGetExample() throws Exception{
		MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
		params.add("v", "1.0.0");
		params.add("method", "merchants.api.example");
		params.add("name", "alvin");
		System.out.println(get(params));
	}
	
	@Test
	public void testPostExample() throws Exception{
		MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
		params.add("v", "1.0.0");
		params.add("method", "merchants.api.example");
		params.add("name", "alvin");
		System.out.println(post(params));
	}
	
	@Test
	public void testComplexRequest() throws Exception{
		MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
		params.add("v", "1.0.0");
		params.add("method", "merchants.api.example.complex");
		params.add("name", "alvin");
		params.add("age", "18");
		params.add("data", "18");
		params.add("hobby[0]", "编程");
		params.add("hobby[1]", "打球");
		params.add("address.province", "广东省");
		params.add("address.city", "深圳市");
		params.add("address.area", "南山区");
		params.add("workExperiences[0].company", "深圳广联赛讯股份有限公司");
		params.add("workExperiences[0].address.province", "广东省");
		params.add("workExperiences[0].address.city", "深圳市");
		params.add("workExperiences[0].address.streets[0].no", "3370号");
		params.add("workExperiences[0].address.streets[0].name", "留仙大道");
		params.add("workExperiences[0].startTime", "2010-11-11 00:00:00");
		params.add("workExperiences[0].endTime", "2020-11-11 00:00:00");
		System.out.println(post(params));
	}
	
	@Test
	public void testUpload() throws Exception{
		MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(4);
		params.add("v", "1.0.0");
		params.add("method", "merchants.api.example.upload");
		ClassPathResource resource = new ClassPathResource("logo.png");
		UploadFile uploadFile = new UploadFile(resource.getFile());
		MultiValueMap<String, String> fileParams = new LinkedMultiValueMap<String, String>(4);
		fileParams.add("file", "png@" + Base64.getEncoder().encodeToString(uploadFile.getContent()));
		System.out.println(upload(params, fileParams));
	}


	@Test
	public void test() throws Exception{

		MerchantRequest merchantRequest=new MerchantRequest();
		merchantRequest.setSource("OP");
		System.out.println(merchantRemote.findAllMerchantRemote(merchantRequest));
	}
}