Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webmagic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
webmagic
Commits
83ada974
Commit
83ada974
authored
Apr 08, 2017
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix test
parent
fe95a684
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
8 deletions
+18
-8
Request.java
...gic-core/src/main/java/us/codecraft/webmagic/Request.java
+4
-0
HttpClientDownloaderTest.java
...decraft/webmagic/downloader/HttpClientDownloaderTest.java
+14
-8
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/Request.java
View file @
83ada974
...
...
@@ -141,6 +141,10 @@ public class Request implements Serializable {
return
requestBody
;
}
public
void
setRequestBody
(
HttpRequestBody
requestBody
)
{
this
.
requestBody
=
requestBody
;
}
@Override
public
String
toString
()
{
return
"Request{"
+
...
...
webmagic-core/src/test/java/us/codecraft/webmagic/downloader/HttpClientDownloaderTest.java
View file @
83ada974
...
...
@@ -3,6 +3,7 @@ package us.codecraft.webmagic.downloader;
import
com.github.dreamhead.moco.HttpServer
;
import
com.github.dreamhead.moco.Runnable
;
import
com.github.dreamhead.moco.Runner
;
import
org.apache.commons.collections.map.HashedMap
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpUriRequest
;
...
...
@@ -14,12 +15,14 @@ import us.codecraft.webmagic.Page;
import
us.codecraft.webmagic.Request
;
import
us.codecraft.webmagic.Site
;
import
us.codecraft.webmagic.Task
;
import
us.codecraft.webmagic.model.HttpRequestBody
;
import
us.codecraft.webmagic.selector.Html
;
import
us.codecraft.webmagic.utils.CharsetUtils
;
import
us.codecraft.webmagic.utils.HttpConstant
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Map
;
import
static
com
.
github
.
dreamhead
.
moco
.
Moco
.*;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -124,17 +127,12 @@ public class HttpClientDownloaderTest {
@Override
public
void
run
()
throws
Exception
{
Request
request
=
new
Request
();
request
.
setUrl
(
"http://127.0.0.1:12306/search"
);
request
.
putParams
(
"q"
,
"webmagic"
);
request
.
setUrl
(
"http://127.0.0.1:12306/search?q=webmagic"
);
request
.
setMethod
(
HttpConstant
.
Method
.
GET
);
Map
<
String
,
Object
>
params
=
new
HashedMap
();
params
.
put
(
"q"
,
"webmagic"
);
HttpUriRequest
httpUriRequest
=
httpUriRequestConverter
.
convert
(
request
,
site
,
null
);
assertThat
(
EntityUtils
.
toString
(
HttpClients
.
custom
().
build
().
execute
(
httpUriRequest
).
getEntity
())).
isEqualTo
(
"get"
);
request
.
setMethod
(
HttpConstant
.
Method
.
POST
);
httpUriRequest
=
httpUriRequestConverter
.
convert
(
request
,
site
,
null
);
assertThat
(
EntityUtils
.
toString
(
HttpClients
.
custom
().
build
().
execute
(
httpUriRequest
).
getEntity
())).
isEqualTo
(
"post"
);
request
.
setMethod
(
HttpConstant
.
Method
.
PUT
);
httpUriRequest
=
httpUriRequestConverter
.
convert
(
request
,
site
,
null
);
assertThat
(
EntityUtils
.
toString
(
HttpClients
.
custom
().
build
().
execute
(
httpUriRequest
).
getEntity
())).
isEqualTo
(
"put"
);
request
.
setMethod
(
HttpConstant
.
Method
.
DELETE
);
httpUriRequest
=
httpUriRequestConverter
.
convert
(
request
,
site
,
null
);
assertThat
(
EntityUtils
.
toString
(
HttpClients
.
custom
().
build
().
execute
(
httpUriRequest
).
getEntity
())).
isEqualTo
(
"delete"
);
...
...
@@ -144,6 +142,14 @@ public class HttpClientDownloaderTest {
request
.
setMethod
(
HttpConstant
.
Method
.
TRACE
);
httpUriRequest
=
httpUriRequestConverter
.
convert
(
request
,
site
,
null
);
assertThat
(
EntityUtils
.
toString
(
HttpClients
.
custom
().
build
().
execute
(
httpUriRequest
).
getEntity
())).
isEqualTo
(
"trace"
);
request
.
setUrl
(
"http://127.0.0.1:12306/search"
);
request
.
setMethod
(
HttpConstant
.
Method
.
POST
);
request
.
setRequestBody
(
HttpRequestBody
.
form
(
params
,
"utf-8"
));
httpUriRequest
=
httpUriRequestConverter
.
convert
(
request
,
site
,
null
);
assertThat
(
EntityUtils
.
toString
(
HttpClients
.
custom
().
build
().
execute
(
httpUriRequest
).
getEntity
())).
isEqualTo
(
"post"
);
request
.
setMethod
(
HttpConstant
.
Method
.
PUT
);
httpUriRequest
=
httpUriRequestConverter
.
convert
(
request
,
site
,
null
);
assertThat
(
EntityUtils
.
toString
(
HttpClients
.
custom
().
build
().
execute
(
httpUriRequest
).
getEntity
())).
isEqualTo
(
"put"
);
}
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment