ExampleControllerTest.java
3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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));
}
}