Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
90c76ead
Commit
90c76ead
authored
Jan 10, 2018
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交jUnit测试用例 - for - UseAuthrized
parent
934bedb3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
185 additions
and
0 deletions
+185
-0
BaseParametersTests.java
src/test/java/demo/BaseParametersTests.java
+19
-0
UserAuthorizedRepsitoryTests.java
src/test/java/repsitory/UserAuthorizedRepsitoryTests.java
+83
-0
UserAuthorizedServiceTests.java
src/test/java/service/UserAuthorizedServiceTests.java
+83
-0
No files found.
src/test/java/demo/BaseParametersTests.java
0 → 100644
View file @
90c76ead
package
demo
;
import
org.junit.Before
;
import
org.springframework.test.context.TestContextManager
;
/**
* Created by xuran on 2017/12/26.
*/
public
abstract
class
BaseParametersTests
{
private
TestContextManager
testContextManager
;
@Before
public
void
setUpContext
()
throws
Exception
{
//this is where the magic happens, we actually do "by hand" what the spring runner would do for us,
// read the JavaDoc for the class bellow to know exactly what it does, the method names are quite accurate though
this
.
testContextManager
=
new
TestContextManager
(
getClass
());
this
.
testContextManager
.
prepareTestInstance
(
this
);
}
}
src/test/java/repsitory/UserAuthorizedRepsitoryTests.java
0 → 100644
View file @
90c76ead
package
repsitory
;
import
cn.quantgroup.xyqb.Bootstrap
;
import
cn.quantgroup.xyqb.entity.UserAuthorized
;
import
cn.quantgroup.xyqb.model.AuthPattern
;
import
cn.quantgroup.xyqb.repository.IUserAuthorizedRepository
;
import
com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer
;
import
demo.BaseParametersTests
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.data.domain.Example
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.util.Arrays
;
import
java.util.Collection
;
/**
* 业务层测试用例
* @author renwc
* @date 2018-01-05
*/
@Slf4j
@Rollback
@Transactional
@RunWith
(
value
=
Parameterized
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@ContextConfiguration
(
initializers
=
ApolloPropertySourceInitializer
.
class
)
public
class
UserAuthorizedRepsitoryTests
extends
BaseParametersTests
{
@Resource
private
IUserAuthorizedRepository
userAuthorizedRepository
;
UserAuthorized
obj
=
new
UserAuthorized
();
public
UserAuthorizedRepsitoryTests
(
Long
userId
,
String
idNo
,
String
name
,
AuthPattern
authPattern
,
Boolean
available
)
{
obj
.
setUserId
(
userId
);
obj
.
setIdNo
(
idNo
);
obj
.
setName
(
name
);
obj
.
setAuthPattern
(
authPattern
);
obj
.
setAvailable
(
available
);
}
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
data
()
{
Object
[][]
data
=
new
Object
[][]{
{
1L
,
"350504198805144101"
,
"史书一"
,
AuthPattern
.
ZMXY
,
true
},
{
10L
,
"350504198805144102"
,
"史书二"
,
AuthPattern
.
ZMXY
,
true
},
{
20L
,
"350504198805144103"
,
"史书三"
,
AuthPattern
.
FOUR_ELEMENTS_OF_BANK_CARD
,
true
},
{
1L
,
"IDNO-1"
,
"王-1"
,
AuthPattern
.
ZMXY
,
true
}
};
return
Arrays
.
asList
(
data
);
}
@Test
public
void
testExist
()
throws
Exception
{
log
.
info
(
"testExist: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserId
(),
obj
.
getAuthPattern
());
UserAuthorized
obj
=
new
UserAuthorized
();
boolean
exist
=
userAuthorizedRepository
.
exists
(
Example
.
of
(
obj
));
Assert
.
assertNotNull
(
obj
);
}
@Test
public
void
testSave
()
throws
Exception
{
log
.
info
(
"testSave: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserId
(),
obj
.
getAuthPattern
());
UserAuthorized
obj
=
new
UserAuthorized
();
obj
=
userAuthorizedRepository
.
save
(
obj
);
Assert
.
assertNotNull
(
obj
);
}
@Test
public
void
testQuery
(){
log
.
info
(
"testQuery: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserId
(),
obj
.
getAuthPattern
());
UserAuthorized
obj
=
userAuthorizedRepository
.
findByIdNo
(
this
.
obj
.
getIdNo
());
Assert
.
assertNotNull
(
obj
);
}
}
src/test/java/service/UserAuthorizedServiceTests.java
0 → 100644
View file @
90c76ead
package
service
;
import
cn.quantgroup.xyqb.Bootstrap
;
import
cn.quantgroup.xyqb.model.AuthPattern
;
import
cn.quantgroup.xyqb.service.auth.IUserAuthorizedService
;
import
com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer
;
import
demo.BaseParametersTests
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Parameterized
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Arrays
;
import
java.util.Collection
;
/**
* 业务层测试用例
* @author renwc
* @date 2018-01-05
*/
@Slf4j
@Rollback
@Transactional
@RunWith
(
value
=
Parameterized
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@ContextConfiguration
(
initializers
=
ApolloPropertySourceInitializer
.
class
)
public
class
UserAuthorizedServiceTests
extends
BaseParametersTests
{
@Autowired
private
IUserAuthorizedService
userAuthorizedService
;
private
Long
userId
;
private
String
idNo
;
private
String
name
;
private
AuthPattern
authPattern
;
private
Boolean
available
;
public
UserAuthorizedServiceTests
(
Long
userId
,
String
idNo
,
String
name
,
AuthPattern
authPattern
,
Boolean
available
)
{
this
.
userId
=
userId
;
this
.
idNo
=
idNo
;
this
.
name
=
name
;
this
.
authPattern
=
authPattern
;
this
.
available
=
available
;
}
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
data
()
{
Object
[][]
data
=
new
Object
[][]{
{
1L
,
"350504198805144101"
,
"史书一"
,
AuthPattern
.
ZMXY
,
true
},
{
10L
,
"350504198805144102"
,
"史书二"
,
AuthPattern
.
ZMXY
,
true
},
{
20L
,
"350504198805144103"
,
"史书三"
,
AuthPattern
.
FOUR_ELEMENTS_OF_BANK_CARD
,
true
},
{
1L
,
"IDNO-1"
,
"王-1"
,
AuthPattern
.
ZMXY
,
true
}
};
return
Arrays
.
asList
(
data
);
}
@Test
public
void
testExist
()
throws
Exception
{
log
.
info
(
"testExist: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
this
.
name
,
this
.
idNo
,
this
.
userId
,
this
.
authPattern
);
Object
obj
=
userAuthorizedService
.
hasUserAuthorized
(
this
.
idNo
);
Assert
.
assertNotNull
(
obj
);
}
@Test
public
void
testSave
()
throws
Exception
{
log
.
info
(
"testSave: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
this
.
name
,
this
.
idNo
,
this
.
userId
,
this
.
authPattern
);
Object
obj
=
userAuthorizedService
.
createUserAuthorized
(
this
.
name
,
this
.
idNo
,
this
.
userId
,
this
.
authPattern
.
name
());
Assert
.
assertNotNull
(
obj
);
}
@Test
public
void
testQuery
(){
log
.
info
(
"testQuery: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
this
.
name
,
this
.
idNo
,
this
.
userId
,
this
.
authPattern
);
Object
obj
=
userAuthorizedService
.
getUserAuthorizedId
(
this
.
userId
);
Assert
.
assertNotNull
(
obj
);
}
}
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