-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathMediaHandlerTest.java
More file actions
144 lines (103 loc) · 4.28 KB
/
MediaHandlerTest.java
File metadata and controls
144 lines (103 loc) · 4.28 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
import com.upyun.MediaHandler;
import com.upyun.Result;
import com.upyun.UpException;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class MediaHandlerTest {
private static final String BUCKET_NAME = "formtest";
private static final String OPERATOR_NAME = "one";
private static final String OPERATOR_PWD = "qwertyuiop";
@Test
public void testMediaProcess() {
MediaHandler handler = new MediaHandler(BUCKET_NAME, OPERATOR_NAME, OPERATOR_PWD);
//初始化参数组 Map
Map<String, Object> paramsMap = new HashMap<String, Object>();
paramsMap.put(MediaHandler.Params.BUCKET_NAME, BUCKET_NAME);
paramsMap.put(MediaHandler.Params.NOTIFY_URL, "http://httpbin.org/post");
paramsMap.put(MediaHandler.Params.ACCEPT, "json");
paramsMap.put(MediaHandler.Params.SOURCE, "/test.mp4");
JSONArray array = new JSONArray();
JSONObject json = new JSONObject();
json.put(MediaHandler.Params.TYPE, "video");
json.put(MediaHandler.Params.AVOPTS, "/s/240p(4:3)/as/1/r/30");
json.put(MediaHandler.Params.RETURN_INFO, "true");
json.put(MediaHandler.Params.SAVE_AS, "testProcess.mp4");
JSONObject json2 = new JSONObject();
json2.put(MediaHandler.Params.TYPE, "video");
json2.put(MediaHandler.Params.AVOPTS, "/s/240p(4:3)/as/1/r/30");
json2.put(MediaHandler.Params.RETURN_INFO, "true");
json2.put(MediaHandler.Params.SAVE_AS, "testProcess2.mp4");
array.put(json2);
array.put(json);
paramsMap.put(MediaHandler.Params.TASKS, array);
Result result = null;
try {
result = handler.process(paramsMap);
} catch (IOException e) {
e.printStackTrace();
} catch (UpException e) {
e.printStackTrace();
}
assertNotNull(result);
assertTrue(result.isSucceed());
assertNotNull(result.getMsg());
String[] ids = handler.getTaskId(result.getMsg());
assertNotNull(ids);
}
@Test
public void testMediaStatus() {
String[] ids = new String[]{"02774703e7f5cc855681a7c42d819722", "921110d3843e92ac7932ff216e5ea348"};
MediaHandler handle = new MediaHandler(BUCKET_NAME, OPERATOR_NAME, OPERATOR_PWD);
//初始化参数组 Map
Map<String, Object> paramsMap = new HashMap<String, Object>();
paramsMap.put(MediaHandler.Params.BUCKET_NAME, BUCKET_NAME);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ids.length; i++) {
sb.append(ids[i] + ",");
}
String task_ids = sb.toString().substring(0, sb.length() - 1);
paramsMap.put(MediaHandler.Params.TASK_IDS, task_ids);
Result result = null;
try {
result = handle.getStatus(paramsMap);
} catch (IOException e) {
e.printStackTrace();
} catch (UpException e) {
e.printStackTrace();
}
assertNotNull(result);
assertTrue(result.isSucceed());
assertNotNull(result.getMsg());
}
@Test
public void testMediaResult() {
String[] ids = new String[]{"02774703e7f5cc855681a7c42d819722", "921110d3843e92ac7932ff216e5ea348"};
MediaHandler handle = new MediaHandler(BUCKET_NAME, OPERATOR_NAME, OPERATOR_PWD);
//初始化参数组 Map
Map<String, Object> paramsMap = new HashMap<String, Object>();
paramsMap.put(MediaHandler.Params.BUCKET_NAME, BUCKET_NAME);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ids.length; i++) {
sb.append(ids[i] + ",");
}
String task_ids = sb.toString().substring(0, sb.length() - 1);
paramsMap.put(MediaHandler.Params.TASK_IDS, task_ids);
Result result = null;
try {
result = handle.getStatus(paramsMap);
} catch (IOException e) {
e.printStackTrace();
} catch (UpException e) {
e.printStackTrace();
}
assertNotNull(result);
assertTrue(result.isSucceed());
assertNotNull(result.getMsg());
}
}