FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JSON-java/tests/TestHTTP.java at master · zerokilobytes/JSON-java · GitHub
zerokilobytes
/
JSON-java
Public
forked from
stleary/JSON-java
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JSON-java
/
tests
/
TestHTTP.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
132 lines (119 loc) · 6.34 KB
Breadcrumbs
JSON-java
/
tests
/
TestHTTP.java
Copy path
File metadata and controls
132 lines (119 loc) · 6.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* File: TestHTTP.java Author: JSON.org
*/
package
org
.
json
.
tests
;
import
org
.
json
.
HTTP
;
import
org
.
json
.
JSONObject
;
import
junit
.
framework
.
TestCase
;
/**
* The Class TestHTTP.
*/
public
class
TestHTTP
extends
TestCase
{
/** The jsonobject. */
JSONObject
jsonobject
=
new
JSONObject
();
/**
* Tests the stub method.
*/
public
void
testToJsonObject_Request
()
{
try
{
jsonobject
=
HTTP
.
toJSONObject
(
"GET / HTTP/1.0
\n
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
\n
Accept-Language: en-us
\n
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)
\n
Host: www.nokko.com
\n
Connection: keep-alive
\n
Accept-encoding: gzip, deflate
\n
"
);
assertEquals
(
"{
\n
\"
Accept-Language
\"
:
\"
en-us
\"
,
\n
\"
Request-URI
\"
:
\"
/
\"
,
\n
\"
Host
\"
:
\"
www.nokko.com
\"
,
\n
\"
Method
\"
:
\"
GET
\"
,
\n
\"
Accept-encoding
\"
:
\"
gzip, deflate
\"
,
\n
\"
User-Agent
\"
:
\"
Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)
\"
,
\n
\"
HTTP-Version
\"
:
\"
HTTP/1.0
\"
,
\n
\"
Connection
\"
:
\"
keep-alive
\"
,
\n
\"
Accept
\"
:
\"
image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
\"
\n
}"
,
jsonobject
.
toString
(
2
));
assertEquals
(
"GET
\"
/
\"
HTTP/1.0
\r
\n
"
+
"Accept-Language: en-us
\r
\n
"
+
"Host: www.nokko.com
\r
\n
"
+
"Accept-encoding: gzip, deflate
\r
\n
"
+
"User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)
\r
\n
"
+
"Connection: keep-alive
\r
\n
"
+
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
\r
\n
\r
\n
"
,
HTTP
.
toString
(
jsonobject
));
}
catch
(
Exception
e
)
{
fail
(
e
.
toString
());
}
}
/**
* Tests the toJsonObject method using response.
*/
public
void
testToJsonObject_Response
()
{
try
{
jsonobject
=
HTTP
.
toJSONObject
(
"HTTP/1.1 200 Oki Doki
\n
Date: Sun, 26 May 2002 17:38:52 GMT
\n
Server: Apache/1.3.23 (Unix) mod_perl/1.26
\n
Keep-Alive: timeout=15, max=100
\n
Connection: Keep-Alive
\n
Transfer-Encoding: chunked
\n
Content-Type: text/html
\n
"
);
assertEquals
(
"{
\n
\"
Reason-Phrase
\"
:
\"
Oki Doki
\"
,
\n
\"
Status-Code
\"
:
\"
200
\"
,
\n
\"
Transfer-Encoding
\"
:
\"
chunked
\"
,
\n
\"
Date
\"
:
\"
Sun, 26 May 2002 17:38:52 GMT
\"
,
\n
\"
Keep-Alive
\"
:
\"
timeout=15, max=100
\"
,
\n
\"
HTTP-Version
\"
:
\"
HTTP/1.1
\"
,
\n
\"
Content-Type
\"
:
\"
text/html
\"
,
\n
\"
Connection
\"
:
\"
Keep-Alive
\"
,
\n
\"
Server
\"
:
\"
Apache/1.3.23 (Unix) mod_perl/1.26
\"
\n
}"
,
jsonobject
.
toString
(
2
));
assertEquals
(
"HTTP/1.1 200 Oki Doki
\r
\n
"
+
"Transfer-Encoding: chunked
\r
\n
"
+
"Date: Sun, 26 May 2002 17:38:52 GMT
\r
\n
"
+
"Keep-Alive: timeout=15, max=100
\r
\n
"
+
"Content-Type: text/html
\r
\n
"
+
"Connection: Keep-Alive
\r
\n
"
+
"Server: Apache/1.3.23 (Unix) mod_perl/1.26
\r
\n
\r
\n
"
,
HTTP
.
toString
(
jsonobject
));
}
catch
(
Exception
e
)
{
fail
(
e
.
toString
());
}
}
/**
* Tests the toString method using null key.
*/
public
void
testToString_NullKey
()
{
try
{
jsonobject
=
new
JSONObject
(
"{
\n
\"
Reason-Phrase
\"
:
\"
Oki Doki
\"
,
\n
\"
Status-Code
\"
:
\"
200
\"
,
\n
\"
Transfer-Encoding
\"
:
\"
chunked
\"
,
\n
\"
Date
\"
:
\"
Sun, 26 May 2002 17:38:52 GMT
\"
,
\n
\"
Keep-Alive
\"
:
\"
timeout=15, max=100
\"
,
\n
\"
HTTP-Version
\"
:
\"
HTTP/1.1
\"
,
\n
\"
Content-Type
\"
:
\"
text/html
\"
,
\n
\"
Connection
\"
:
\"
Keep-Alive
\"
,
\n
\"
Server
\"
:
\"
Apache/1.3.23 (Unix) mod_perl/1.26
\"
\n
}"
);
jsonobject
.
put
(
"testKey"
,
JSONObject
.
NULL
);
assertEquals
(
"HTTP/1.1 200 Oki Doki
\r
\n
Date: Sun, 26 May 2002 17:38:52 GMT
\r
\n
Transfer-Encoding: chunked
\r
\n
Keep-Alive: timeout=15, max=100
\r
\n
Connection: Keep-Alive
\r
\n
Content-Type: text/html
\r
\n
Server: Apache/1.3.23 (Unix) mod_perl/1.26
\r
\n
\r
\n
"
,
HTTP
.
toString
(
jsonobject
));
}
catch
(
Exception
e
)
{
fail
(
e
.
toString
());
}
}
/**
* Tests the toString method using status code but no reason phrase.
*/
public
void
testToString_StatusCodeButNoReasonPhrase
()
{
try
{
jsonobject
=
new
JSONObject
(
"{
\n
\"
Status-Code
\"
:
\"
200
\"
,
\n
\"
Transfer-Encoding
\"
:
\"
chunked
\"
,
\n
\"
Date
\"
:
\"
Sun, 26 May 2002 17:38:52 GMT
\"
,
\n
\"
Keep-Alive
\"
:
\"
timeout=15, max=100
\"
,
\n
\"
HTTP-Version
\"
:
\"
HTTP/1.1
\"
,
\n
\"
Content-Type
\"
:
\"
text/html
\"
,
\n
\"
Connection
\"
:
\"
Keep-Alive
\"
,
\n
\"
Server
\"
:
\"
Apache/1.3.23 (Unix) mod_perl/1.26
\"
\n
}"
);
HTTP
.
toString
(
jsonobject
);
fail
(
"Should have thrown an exception."
);
}
catch
(
Exception
e
)
{
assertEquals
(
"Not enough material for an HTTP header."
,
e
.
getMessage
());
}
}
/**
* Tests the toString method using method but no request uri.
*/
public
void
testToString_MethodButNoRequestUri
()
{
try
{
jsonobject
=
new
JSONObject
(
"{
\n
\"
Accept-Language
\"
:
\"
en-us
\"
,
\n
\"
Host
\"
:
\"
www.nokko.com
\"
,
\n
\"
Method
\"
:
\"
GET
\"
,
\n
\"
Accept-encoding
\"
:
\"
gzip, deflate
\"
,
\n
\"
User-Agent
\"
:
\"
Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)
\"
,
\n
\"
HTTP-Version
\"
:
\"
HTTP/1.0
\"
,
\n
\"
Connection
\"
:
\"
keep-alive
\"
,
\n
\"
Accept
\"
:
\"
image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*
\"
\n
}"
);
HTTP
.
toString
(
jsonobject
);
fail
(
"Should have thrown an exception."
);
}
catch
(
Exception
e
)
{
assertEquals
(
"Not enough material for an HTTP header."
,
e
.
getMessage
());
}
}
/**
* Tests the constructor method.
*/
public
static
void
testConstructor
()
{
HTTP
http
=
new
HTTP
();
assertEquals
(
"HTTP"
,
http
.
getClass
().
getSimpleName
());
}
}
Back
|
FazBrowse Home
|
New Git URL