-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathTestFileBucket.java
More file actions
215 lines (215 loc) · 6.81 KB
/
TestFileBucket.java
File metadata and controls
215 lines (215 loc) · 6.81 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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//import com.UpYun;
//import com.upyun.UpException;
//import org.junit.Assert;
//import org.junit.Test;
//
//import java.io.File;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import static org.junit.Assert.assertTrue;
//
//
////请求太频繁容易失败 影响 maven 上传 注释之
//public class TestFileBucket {
//
// private static final String BUCKET_NAME = "sdkimg";
// private static final String OPERATOR_NAME = "tester";
// private static final String OPERATOR_PWD = "grjxv2mxELR3";
//
// private UpYun upyun = new UpYun(BUCKET_NAME, OPERATOR_NAME, OPERATOR_PWD);
//
// /**
// * 根目录
// */
// private static final String DIR_ROOT = "/";
// /**
// * 多级目录
// */
// private static final String DIR_MORE = "/1/2/3/";
// /**
// * 目录名
// */
// private static final String FOLDER_NAME = "tmp";
// /**
// * 上传到upyun的文件名
// */
// private static final String FILE_NAME = "test.txt";
// /**
// * 本地待上传的测试文件
// */
// private static final String SAMPLE_TXT_FILE = System.getProperty("user.dir") + "/test.txt";
//
// private static final String content = "tmp content";
//
//
// //创建目录测试
// @Test
// public void testMkDir() throws IOException, UpException {
// // 方法1:创建一级目录
// String dir1 = DIR_ROOT + FOLDER_NAME;
//
// boolean result1 = upyun.mkDir(dir1);
// assertTrue(result1);
//
// // 方法2:创建多级目录,自动创建父级目录(最多10级)
// String dir2 = DIR_MORE + FOLDER_NAME;
//
// boolean result2 = upyun.mkDir(dir2, true);
// assertTrue(result2);
// }
//
// //上传普通文件测试
// @Test
// public void testWriteFile() throws IOException, UpException {
// // 保存在又拍云的文件路径
// String filePath = DIR_ROOT + FILE_NAME;
// // 保存在又拍云的文件路径:多级目录
// String filePath2 = DIR_MORE + FILE_NAME;
//
// /*
// * 上传方法1:文本内容直接上传
// */
// boolean result1 = upyun.writeFile(filePath, content);
// assertTrue(result1);
//
// /*
// * 上传方法2:文本内容直接上传,可自动创建父级目录(最多10级)
// */
// boolean result2 = upyun.writeFile(filePath2, content, true);
// assertTrue(result2);
//
// /*
// * 上传方法3:采用数据流模式上传文件(节省内存),可自动创建父级目录(最多10级)
// */
// File file = new File(SAMPLE_TXT_FILE);
// boolean result3 = upyun.writeFile(filePath, file, true);
// assertTrue(result3);
//
// /*
// * 上传方法4:对待上传的文件设置 MD5 值,确保上传到 Upyun 的文件的完整性和正确性
// */
// File file4 = new File(SAMPLE_TXT_FILE);
// // 设置待上传文件的 Content-MD5 值
// // 如果又拍云服务端收到的文件MD5值与用户设置的不一致,将回报 406 NotAcceptable 错误
// upyun.setContentMD5(UpYun.md5(file4));
//
// boolean result4 = upyun.writeFile(filePath, file4, true);
// assertTrue(result4);
//
// }
//
// //获取文件信息测试
// @Test
// public void testGetFileInfo() throws IOException, UpException {
// // upyun空间下存在的文件的路径
// String filePath = DIR_ROOT + FILE_NAME;
//
// Map<String, String> result = upyun.getFileInfo(filePath);
// Assert.assertNotNull(result);
// }
//
// //读取目录文件列表测试
// @Test
// public void testReadDir() throws IOException, UpException {
//
// // 参数可以换成其他目录路径
// String dirPath = DIR_ROOT;
//
// // 读取目录列表,将返回 List 或 NULL
// Map<String, String> params = new HashMap<String, String>();
//
// params.put(UpYun.PARAMS.KEY_X_LIST_LIMIT.getValue(), "10");
// List<UpYun.FolderItem> items = upyun.readDir(dirPath, params);
// UpYun.FolderItemIter folderItemIter = upyun.readDirIter(dirPath, params);
// String json = upyun.readDirJson(dirPath, params);
// assertTrue(items.size() > 0);
// }
//
// //获取空间使用量测试
// @Test
// public void testGetBucketUsage() throws IOException, UpException {
// long usage = upyun.getBucketUsage();
//
// assertTrue(usage > 0);
// }
//
// //获取目录大小信息测试
// @Test
// public void testGetFolderUsage() throws IOException, UpException {
// // 带查询的目录,如 "/" 或 "/tmp"
// String dirPath = DIR_ROOT;
//
// long usage = upyun.getFolderUsage(dirPath);
//
// assertTrue(usage > 0);
// }
//
// //读取文件测试
// @Test
// public void testReadFile() throws IOException, UpException {
// // upyun空间下存在的文件的路径
// String filePath = DIR_ROOT + FILE_NAME;
//
// /*
// * 方法1:直接读取文本内容
// */
// String datas = upyun.readFile(filePath);
// assertTrue(content.equals(datas));
//
// /*
// * 方法2:下载文件,采用数据流模式下载文件(节省内存)
// */
// // 要写入的本地临时文件
// File file = File.createTempFile("upyunTempFile_", "");
//
// // 把upyun空间下的文件下载到本地的临时文件
// boolean result = upyun.readFile(filePath, file);
// assertTrue(result);
// }
//
// //删除文件测试
// @Test
// public void testDeleteFile() throws IOException, UpException {
// // upyun空间下存在的文件的路径
// String filePath = DIR_ROOT + FILE_NAME;
//
// // 删除文件
// boolean result = upyun.deleteFile(filePath, null);
//
// assertTrue(result);
// }
//
// //删除目录测试
// @Test
// public void testRmDir() throws IOException, UpException {
// // 带删除的目录必须存在,并且目录下已不存在任何文件或子目录
// String dirPath = DIR_MORE + FOLDER_NAME;
//
// boolean result = upyun.rmDir(dirPath);
//
// assertTrue(result);
// }
//
// //复制文件测试
// @Test
// public void testCopyFile() throws IOException, UpException {
// String filePath = DIR_ROOT + FILE_NAME;
//
// boolean result = upyun.copyFile("/test.aa", "/" + BUCKET_NAME + filePath);
//
// assertTrue(result);
// }
//
// //移动文件测试
// @Test
// public void testMoveFile() throws IOException, UpException {
// String filePath = DIR_ROOT + FILE_NAME;
//
// boolean result = upyun.moveFile("/test.aa", "/" + BUCKET_NAME + filePath);
//
// assertTrue(result);
// }
//}