-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTest.java
More file actions
149 lines (138 loc) · 2.74 KB
/
Test.java
File metadata and controls
149 lines (138 loc) · 2.74 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
package net.dmcloud.cloudkey;
import java.util.ArrayList;
import java.util.Map;
import net.dmcloud.util.*;
import junit.framework.TestCase;
public class Test extends TestCase
{
public static String user_id = "YOUR USER ID";
public static String api_key = "YOUR API KEY";
public static String video_id = "YOUR VIDEO ID";
public void testCloudKey_Normalize()
{
assertEquals
(
Helpers.normalize
(
DCArray.create()
.push("foo")
.push(42)
.push("bar")
), "foo42bar"
);
assertEquals
(
Helpers.normalize
(
DCObject.create()
.push("yellow", 1)
.push("red", 2)
.push("pink", 3)
), "pink3red2yellow1"
);
assertEquals
(
Helpers.normalize
(
DCArray.create()
.push("foo")
.push(42)
.push
(
DCObject.create()
.push("yellow", 1)
.push("red", 2)
.push("pink", 3)
)
.push("bar")
), "foo42pink3red2yellow1bar"
);
}
public void testCloudKey_getEmbedUrl()
{
try
{
CloudKey cloud = new CloudKey(user_id, api_key);
String[] referers = {"http://test.dmcloud.net"};
cloud.mediaGetEmbedUrl(CloudKey.API_URL, video_id, CloudKey.SECLEVEL_REFERER, "", "", "", null, referers, 0);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void testCloudKey_getStreamUrl()
{
try
{
CloudKey cloud = new CloudKey(user_id, api_key);
cloud.mediaGetStreamUrl(video_id);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void testCloudKey()
{
try
{
CloudKey cloud = new CloudKey(user_id, api_key);
DCObject result = cloud.call
(
"media.list",
DCObject.create()
.push("fields", DCArray.create().push("id").push("meta.title"))
);
DCArray list = DCArray.create((ArrayList)result.get("list"));
for(int i=0; i<list.size(); i++)
{
DCObject item = DCObject.create((Map)list.get(i));
assertEquals((!item.pull("meta.title").equals("")), true);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void testCloudKeyError()
{
Boolean error = false;
try
{
CloudKey cloud = new CloudKey(user_id.substring(0, 2), api_key);
cloud.call
(
"media.list",
DCObject.create()
.push("fields", DCArray.create().push("id").push("meta.title"))
);
}
catch (Exception e)
{
error = true;
assertEquals(((DCException)e).getCode(), 400);
}
finally
{
assertEquals(error.booleanValue(), true);
}
}
public void testCloudKeySign_UrlError()
{
Boolean error = false;
try
{
Helpers.sign_url("", "", CloudKey.SECLEVEL_COUNTRY, "", "", "", null, null, 0);
}
catch (Exception e)
{
error = true;
}
finally
{
assertEquals(error.booleanValue(), true);
}
}
}