Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
32213ae0
authored
Dec 25, 2017
by
许雪里
Committed by
GitHub
Dec 25, 2017
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge pull request #238 from lorelib/master
添加对controller层的测试代码
parents
3b5dee19
9f77e62f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
0 deletions
xxl-job-admin/src/test/java/com/xxl/job/admin/controller/AbstractSpringMvcTest.java
xxl-job-admin/src/test/java/com/xxl/job/admin/controller/IndexControllerTest.java
xxl-job-admin/src/test/java/com/xxl/job/admin/controller/JobInfoControllerTest.java
xxl-job-admin/src/test/java/com/xxl/job/admin/controller/AbstractSpringMvcTest.java
0 → 100644
View file @
32213ae0
package
com
.
xxl
.
job
.
admin
.
controller
;
import
org.junit.Before
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.test.web.servlet.MockMvc
;
import
org.springframework.test.web.servlet.setup.MockMvcBuilders
;
import
org.springframework.web.context.WebApplicationContext
;
@WebAppConfiguration
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
locations
=
{
"classpath*:spring/*.xml"
})
public
class
AbstractSpringMvcTest
{
@Autowired
private
WebApplicationContext
applicationContext
;
protected
MockMvc
mockMvc
;
@Before
public
void
setup
()
{
this
.
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
this
.
applicationContext
).
build
();
}
}
xxl-job-admin/src/test/java/com/xxl/job/admin/controller/IndexControllerTest.java
0 → 100644
View file @
32213ae0
package
com
.
xxl
.
job
.
admin
.
controller
;
import
org.junit.Test
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MvcResult
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.*;
public
class
IndexControllerTest
extends
AbstractSpringMvcTest
{
@Test
public
void
testLogin
()
throws
Exception
{
MvcResult
ret
=
mockMvc
.
perform
(
post
(
"/login"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
param
(
"userName"
,
"admin"
)
.
param
(
"password"
,
"123456"
)
).
andReturn
();
System
.
out
.
println
(
ret
.
getResponse
().
getContentAsString
());
}
}
xxl-job-admin/src/test/java/com/xxl/job/admin/controller/JobInfoControllerTest.java
0 → 100644
View file @
32213ae0
package
com
.
xxl
.
job
.
admin
.
controller
;
import
com.xxl.job.admin.core.model.XxlJobInfo
;
import
org.codehaus.jackson.map.ObjectMapper
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MvcResult
;
import
javax.servlet.http.Cookie
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.*;
public
class
JobInfoControllerTest
extends
AbstractSpringMvcTest
{
Cookie
cookie
;
@Before
public
void
login
()
throws
Exception
{
MvcResult
ret
=
mockMvc
.
perform
(
post
(
"/login"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
param
(
"userName"
,
"admin"
)
.
param
(
"password"
,
"123456"
)
).
andReturn
();
cookie
=
ret
.
getResponse
().
getCookie
(
"LOGIN_IDENTITY"
);
}
@Test
public
void
testAdd
()
throws
Exception
{
XxlJobInfo
jobInfo
=
new
XxlJobInfo
();
jobInfo
.
setJobGroup
(
1
);
jobInfo
.
setJobDesc
(
"autoEnquiryStatisPerWeek"
);
jobInfo
.
setExecutorRouteStrategy
(
"FIRST"
);
jobInfo
.
setJobCron
(
"0 0 1 ? * MON"
);
jobInfo
.
setGlueType
(
"BEAN"
);
jobInfo
.
setExecutorHandler
(
"AutoEnquriy"
);
jobInfo
.
setExecutorBlockStrategy
(
"SERIAL_EXECUTION"
);
jobInfo
.
setExecutorFailStrategy
(
"FAIL_ALARM"
);
jobInfo
.
setAuthor
(
"listening"
);
ObjectMapper
mapper
=
new
ObjectMapper
();
String
jobInfoStr
=
mapper
.
writeValueAsString
(
jobInfo
);
MvcResult
ret
=
mockMvc
.
perform
(
post
(
"/jobinfo/add"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
content
(
jobInfoStr
)
.
cookie
(
cookie
)
).
andReturn
();
System
.
out
.
println
(
ret
.
getResponse
().
getContentAsString
());
}
}
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