summaryrefslogtreecommitdiffstats
path: root/webservice/src/main/test/app/market/webservice/user/AppRestTest.java
blob: c15f1bfb37d60fe5710595a9294afda3472ea222 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package app.market.webservice.user;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.junit.Test;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

import app.market.model.app.App;
import app.market.utils.constants.Constants;
import app.market.utils.json.JsonMapperUtils;
//import app.market.utils.webservice.WebServiceClient;
public class AppRestTest {

    //@Test
   /* public void saveApp(){
    	RestTemplate rest = new RestTemplate();
    	App app = new App();
    	app.setAppName("testAppkkkkkkkkkkkkkkkkkk");
    	app.setTypeId("0001");
    	app.setDeveloper("3e93dfe1-6ff0-4520-a668-b00c315c862b");
    	app.setVersionName("1.0");
    	app.setAppAbstract("lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllthis is play app apppklj;pppppjkljlkjlkjlkjlkjlkjlkj");

        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());

        String appJsonStr = JsonMapperUtils.writeValueAsString(app);
        HttpEntity<String> entity = new HttpEntity<String>(appJsonStr, headers);

    	String str = rest.postForObject(WebServiceClient.REST_APP_INFO, entity, String.class);

    	System.out.println(str);
    }

    @Test
    public void delAppInfo(){
    	RestTemplate rest = new RestTemplate();

        HttpHeaders headers = new HttpHeaders();
        headers.add( Constants.TOKEN_AUTHORIZATION, "cddd" );

    	//rest.delete(WebServiceClient.REST_APP_INFO_PARM_ID, new String[]{"f02bc432-6ef9-4165-932e-3aede966ce1d"});
    	HttpEntity<String> formEntity = new HttpEntity<String>("", headers);
        ResponseEntity<String> exchange = rest.exchange(WebServiceClient.REST_APP_INFO_PARM_ID, HttpMethod.DELETE, formEntity, String.class, new String[]{"f02bc432-6ef9-4165-932e-3aede966ce1d"});

        System.out.println( exchange.getBody() );
    	//rest.delete(WebServiceClient.REST_APP_PARM_ID);
    }

    //@Test
    public void getAppInfo(){
    	RestTemplate rest = new RestTemplate();
    	String str = rest.getForObject(WebServiceClient.REST_APP_INFO_PARM_ID, String.class, new String[]{"f435bee3-acf7-4a0c-baa7-320f7330895a"});

    	System.out.println( str );
    }

    //@Test
    public void getAppType(){
    	RestTemplate rest = new RestTemplate();
    	String str = rest.getForObject(WebServiceClient.REST_APP_TYPE_COLLECTION, String.class);

    	System.out.println("getAppType=======" + str );
    }

    //@Test
	public void uploadAppFile() {
		RestTemplate rest = new RestTemplate();
		HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_OCTET_STREAM_VALUE);

		// 找到目标文件
		File file = new File("D:/aa.docx");
		// 建立数据的输入通道
		FileInputStream fileInputStream = null;
		try {
			fileInputStream = new FileInputStream(file);

//			// 建立缓冲数组配合循环读取文件的数据。
//			// 保存每次读取到的字节个数。
//			byte[] buf = new byte[1024];
//			int length = 0;
//			// 存储读取到的数据缓冲数组的长度一般是1024的倍数,因为与计算机的处理单位。理论上缓冲数组越大,效率越高
//			while ((length = fileInputStream.read(buf)) != -1) {
//				// read方法如果读取到了文件的末尾,那么会返回-1表示。
//				System.out.println(length);
//				System.out.print(new String(buf, 0, length));
//			}
			// 关闭资源
			// fileInputStream.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
		}


//    	App app = new App();
//    	app.setAppName("testApp");
//
//        HttpHeaders headers = new HttpHeaders();
//        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
//        headers.setContentType(type);
//        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
//
//        String appJsonStr = JsonMapperUtils.writeValueAsString(app);
//        HttpEntity<String> entity = new HttpEntity<String>(appJsonStr, headers);
        HttpEntity<InputStream> entity = new HttpEntity<InputStream>(fileInputStream, headers);

		String str = rest.postForObject(WebServiceClient.REST_APP_FILE, entity, String.class,new String[] {"aa"});

		System.out.println(str);
	}

//	//@Test
//	public void testUpload() throws Exception {
//		String url = WebServiceClient.REST_APP_FILE_TEXT;
//		String filePath = "D:\\aa.docx";
//
//		RestTemplate rest = new RestTemplate();
//		FileSystemResource resource = new FileSystemResource(new File(filePath));
//		MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
//		param.add("jarFile", resource);
//		param.add("fileName", "test.txt");
//
//		//String string = rest.postForObject(url, param, String.class);
//
//		HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String,Object>>(param);
//		ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
//		System.out.println(responseEntity.getBody());
//
//		//System.out.println(string);
//	}

    //@Test
    public void selectAppList() {

        RestTemplate rest = new RestTemplate();
        //"/api/appRest/selectPaginationDataByExample/{appName}/{appTypeId}/{appDeveloper}/{sort}/{order}/{offset}/{limit}"
        String str = rest.getForObject( WebServiceClient.REST_APP_COLLECTION_APP, String.class,new String[] { "%22%22", "%22%22","%22%22","1","asc","0","10" } );

        System.out.println( str );
    }*/

}