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
7a2e1808
Commit
7a2e1808
authored
Feb 02, 2018
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新jUnit(已绿,但事务没自动会滚)
parent
5710fb8b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
40 additions
and
29 deletions
+40
-29
UserAuthorizedServiceImpl.java
...oup/xyqb/service/auth/impl/UserAuthorizedServiceImpl.java
+2
-0
BaseParametersTests.java
src/test/java/demo/BaseParametersTests.java
+2
-1
RepsitoryTests.java
src/test/java/demo/RepsitoryTests.java
+2
-1
ServiceTests.java
src/test/java/demo/ServiceTests.java
+2
-1
UserAuthorizedRepsitoryTests.java
src/test/java/repsitory/UserAuthorizedRepsitoryTests.java
+12
-12
UserAuthorizedServiceTests.java
src/test/java/service/UserAuthorizedServiceTests.java
+17
-12
UserAuthorizedControllerTests.java
src/test/java/web/UserAuthorizedControllerTests.java
+3
-2
No files found.
src/main/java/cn/quantgroup/xyqb/service/auth/impl/UserAuthorizedServiceImpl.java
View file @
7a2e1808
...
@@ -14,6 +14,7 @@ import org.springframework.cache.annotation.Cacheable;
...
@@ -14,6 +14,7 @@ import org.springframework.cache.annotation.Cacheable;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.transaction.Transactional
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.util.Objects
;
import
java.util.Objects
;
...
@@ -65,6 +66,7 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
...
@@ -65,6 +66,7 @@ public class UserAuthorizedServiceImpl implements IUserAuthorizedService {
return
(
StringUtils
.
isBlank
(
name
)
||
StringUtils
.
isBlank
(
authPattern
)
||
!
iIdCardService
.
isIdCardValid
(
idNo
));
return
(
StringUtils
.
isBlank
(
name
)
||
StringUtils
.
isBlank
(
authPattern
)
||
!
iIdCardService
.
isIdCardValid
(
idNo
));
}
}
@Transactional
@Override
@Override
public
UserAuthorized
createUserAuthorized
(
UserAuthorizedParam
userAuthorizedParam
)
{
public
UserAuthorized
createUserAuthorized
(
UserAuthorizedParam
userAuthorizedParam
)
{
// 数据检查,以及检查userUuid是否存在
// 数据检查,以及检查userUuid是否存在
...
...
src/test/java/demo/BaseParametersTests.java
View file @
7a2e1808
...
@@ -2,12 +2,13 @@ package demo;
...
@@ -2,12 +2,13 @@ package demo;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.springframework.test.context.TestContextManager
;
import
org.springframework.test.context.TestContextManager
;
import
org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests
;
/**
/**
* @author renwc
* @author renwc
* @date 2018-01-05
* @date 2018-01-05
*/
*/
public
abstract
class
BaseParametersTests
{
public
abstract
class
BaseParametersTests
extends
AbstractTransactionalJUnit4SpringContextTests
{
private
TestContextManager
testContextManager
;
private
TestContextManager
testContextManager
;
@Before
@Before
public
void
setUpContext
()
throws
Exception
{
public
void
setUpContext
()
throws
Exception
{
...
...
src/test/java/demo/RepsitoryTests.java
View file @
7a2e1808
...
@@ -10,6 +10,7 @@ import org.junit.runner.RunWith;
...
@@ -10,6 +10,7 @@ import org.junit.runner.RunWith;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -28,7 +29,7 @@ import java.time.Instant;
...
@@ -28,7 +29,7 @@ import java.time.Instant;
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@ContextConfiguration
(
initializers
=
ApolloPropertySourceInitializer
.
class
)
@ContextConfiguration
(
initializers
=
ApolloPropertySourceInitializer
.
class
)
public
class
RepsitoryTests
{
public
class
RepsitoryTests
extends
AbstractTransactionalJUnit4SpringContextTests
{
@Resource
@Resource
private
IUserRepository
userRepository
;
private
IUserRepository
userRepository
;
...
...
src/test/java/demo/ServiceTests.java
View file @
7a2e1808
...
@@ -10,6 +10,7 @@ import org.junit.runner.RunWith;
...
@@ -10,6 +10,7 @@ import org.junit.runner.RunWith;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -27,7 +28,7 @@ import java.time.Instant;
...
@@ -27,7 +28,7 @@ import java.time.Instant;
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@ContextConfiguration
(
initializers
=
ApolloPropertySourceInitializer
.
class
)
@ContextConfiguration
(
initializers
=
ApolloPropertySourceInitializer
.
class
)
public
class
ServiceTests
{
public
class
ServiceTests
extends
AbstractTransactionalJUnit4SpringContextTests
{
@Resource
@Resource
private
IUserService
userService
;
private
IUserService
userService
;
...
...
src/test/java/repsitory/UserAuthorizedRepsitoryTests.java
View file @
7a2e1808
...
@@ -49,10 +49,10 @@ public class UserAuthorizedRepsitoryTests extends BaseParametersTests {
...
@@ -49,10 +49,10 @@ public class UserAuthorizedRepsitoryTests extends BaseParametersTests {
@Parameterized
.
Parameters
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
data
()
{
public
static
Collection
<
Object
[]>
data
()
{
Object
[][]
data
=
new
Object
[][]{
Object
[][]
data
=
new
Object
[][]{
{
1L
,
"350504198805144101"
,
"史书一"
,
AuthPattern
.
ZMXY
,
true
},
{
"711892ae-191b-445a-a4eb-3c0b7bab7840"
,
"350504198805144101"
,
"史书一"
,
AuthPattern
.
ZMXY
,
true
},
{
10L
,
"350504198805144102"
,
"史书二"
,
AuthPattern
.
ZMXY
,
true
},
{
"711892ae-191b-445a-a4eb-3c0b7bab7841"
,
"350504198805144102"
,
"史书二"
,
AuthPattern
.
ZMXY
,
true
},
{
20L
,
"350504198805144103"
,
"史书三"
,
AuthPattern
.
FOUR_ELEMENTS_OF_BANK_CARD
,
true
},
{
"711892ae-191b-445a-a4eb-3c0b7bab7842"
,
"350504198805144103"
,
"史书三"
,
AuthPattern
.
FOUR_ELEMENTS_OF_BANK_CARD
,
true
},
{
1L
,
"IDNO-1"
,
"王-1"
,
AuthPattern
.
ZMXY
,
true
}
{
"711892ae-191b-445a-a4eb-3c0b7bab7843"
,
"IDNO-1"
,
"王-1"
,
AuthPattern
.
ZMXY
,
true
}
};
};
return
Arrays
.
asList
(
data
);
return
Arrays
.
asList
(
data
);
}
}
...
@@ -60,24 +60,24 @@ public class UserAuthorizedRepsitoryTests extends BaseParametersTests {
...
@@ -60,24 +60,24 @@ public class UserAuthorizedRepsitoryTests extends BaseParametersTests {
@Test
@Test
public
void
testExist
()
throws
Exception
{
public
void
testExist
()
throws
Exception
{
log
.
info
(
"testExist: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
log
.
info
(
"testExist: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
UserAuthorized
obj
=
new
UserAuthorized
();
boolean
exist
=
userAuthorizedRepository
.
exists
(
Example
.
of
(
obj
));
boolean
exist
=
userAuthorizedRepository
.
exists
(
Example
.
of
(
obj
));
Assert
.
assert
NotNull
(
obj
);
Assert
.
assert
False
(
exist
);
}
}
@Test
@Test
public
void
testSave
()
throws
Exception
{
public
void
testSave
()
throws
Exception
{
log
.
info
(
"testSave: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
log
.
info
(
"testSave: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
UserAuthorized
obj
=
new
UserAuthorized
(
);
Object
o
=
userAuthorizedRepository
.
save
(
obj
);
obj
=
userAuthorizedRepository
.
save
(
obj
);
Assert
.
assertNotNull
(
o
);
Assert
.
assert
NotNull
(
obj
);
Assert
.
assert
Equals
(
obj
,
o
);
}
}
@Test
@Test
public
void
testQuery
(){
public
void
test
Then
Query
(){
log
.
info
(
"testQuery: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
log
.
info
(
"testQuery: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
UserAuthorized
obj
=
userAuthorizedRepository
.
findByIdNo
(
this
.
obj
.
getIdNo
());
UserAuthorized
o
=
userAuthorizedRepository
.
findByIdNo
(
this
.
obj
.
getIdNo
());
Assert
.
assertNotNull
(
obj
);
Assert
.
assertNotNull
(
o
);
Assert
.
assertEquals
(
obj
.
getIdNo
(),
o
.
getIdNo
());
}
}
}
}
src/test/java/service/UserAuthorizedServiceTests.java
View file @
7a2e1808
package
service
;
package
service
;
import
cn.quantgroup.xyqb.Bootstrap
;
import
cn.quantgroup.xyqb.Bootstrap
;
import
cn.quantgroup.xyqb.entity.UserAuthorized
;
import
cn.quantgroup.xyqb.model.AuthPattern
;
import
cn.quantgroup.xyqb.model.AuthPattern
;
import
cn.quantgroup.xyqb.model.UserAuthorizedParam
;
import
cn.quantgroup.xyqb.model.UserAuthorizedParam
;
import
cn.quantgroup.xyqb.service.auth.IUserAuthorizedService
;
import
cn.quantgroup.xyqb.service.auth.IUserAuthorizedService
;
...
@@ -8,8 +9,10 @@ import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
...
@@ -8,8 +9,10 @@ import com.ctrip.framework.apollo.spring.config.ApolloPropertySourceInitializer;
import
demo.BaseParametersTests
;
import
demo.BaseParametersTests
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Assert
;
import
org.junit.Assert
;
import
org.junit.FixMethodOrder
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.MethodSorters
;
import
org.junit.runners.Parameterized
;
import
org.junit.runners.Parameterized
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.annotation.Rollback
;
...
@@ -27,8 +30,9 @@ import java.util.Optional;
...
@@ -27,8 +30,9 @@ import java.util.Optional;
* @date 2018-01-05
* @date 2018-01-05
*/
*/
@Slf4j
@Slf4j
@Rollback
@Rollback
(
true
)
@Transactional
@Transactional
@FixMethodOrder
(
MethodSorters
.
NAME_ASCENDING
)
@RunWith
(
value
=
Parameterized
.
class
)
@RunWith
(
value
=
Parameterized
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@SpringBootTest
(
classes
=
Bootstrap
.
class
)
@ContextConfiguration
(
initializers
=
ApolloPropertySourceInitializer
.
class
)
@ContextConfiguration
(
initializers
=
ApolloPropertySourceInitializer
.
class
)
...
@@ -48,10 +52,10 @@ public class UserAuthorizedServiceTests extends BaseParametersTests {
...
@@ -48,10 +52,10 @@ public class UserAuthorizedServiceTests extends BaseParametersTests {
@Parameterized
.
Parameters
@Parameterized
.
Parameters
public
static
Collection
<
Object
[]>
data
()
{
public
static
Collection
<
Object
[]>
data
()
{
Object
[][]
data
=
new
Object
[][]{
Object
[][]
data
=
new
Object
[][]{
{
1L
,
"350504198805144101"
,
"史书一"
,
AuthPattern
.
ZMXY
,
true
},
{
"55544ae9-a1dd-458b-a7ac-2b4e64e59f99"
,
"350504198805144101"
,
"史书一"
,
AuthPattern
.
ZMXY
,
true
},
{
10L
,
"350504198805144102"
,
"史书二"
,
AuthPattern
.
ZMXY
,
true
},
{
"2f7715f1-e59e-4169-8214-89aef11d2291"
,
"350504198805144102"
,
"史书二"
,
AuthPattern
.
ZMXY
,
true
},
{
20L
,
"350504198805144103"
,
"史书三"
,
AuthPattern
.
FOUR_ELEMENTS_OF_BANK_CARD
,
true
},
{
"7addad2f-100b-49fa-ac44-bb729dfca06e"
,
"350504198805144103"
,
"史书三"
,
AuthPattern
.
FOUR_ELEMENTS_OF_BANK_CARD
,
true
},
{
1L
,
"IDNO-1"
,
"王-1"
,
AuthPattern
.
ZMXY
,
true
}
{
"2dae9875-71ba-47bd-9332-0e4922f75f12"
,
"IDNO-1"
,
"王-1"
,
AuthPattern
.
ZMXY
,
true
}
};
};
return
Arrays
.
asList
(
data
);
return
Arrays
.
asList
(
data
);
}
}
...
@@ -59,22 +63,23 @@ public class UserAuthorizedServiceTests extends BaseParametersTests {
...
@@ -59,22 +63,23 @@ public class UserAuthorizedServiceTests extends BaseParametersTests {
@Test
@Test
public
void
testExist
()
throws
Exception
{
public
void
testExist
()
throws
Exception
{
log
.
info
(
"testExist: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
log
.
info
(
"testExist: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
Object
obj
=
userAuthorizedService
.
hasUserAuthorized
(
this
.
obj
.
getIdNo
());
Boolean
exist
=
userAuthorizedService
.
hasUserAuthorized
(
this
.
obj
.
getIdNo
());
Assert
.
assert
NotNull
(
obj
);
Assert
.
assert
False
(
exist
);
}
}
@Test
@Test
public
void
testSave
()
throws
Exception
{
public
void
testSave
()
throws
Exception
{
log
.
info
(
"testSave: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
log
.
info
(
"testSave: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
Object
obj
=
userAuthorizedService
.
createUserAuthorized
(
this
.
obj
);
UserAuthorized
o
=
userAuthorizedService
.
createUserAuthorized
(
this
.
obj
);
Assert
.
assertNotNull
(
obj
);
Assert
.
assertNotNull
(
o
);
Assert
.
assertEquals
(
obj
.
getIdNo
(),
o
.
getIdNo
());
}
}
@Test
@Test
public
void
testQuery
(){
public
void
test
Then
Query
(){
log
.
info
(
"testQuery: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
log
.
info
(
"testQuery: name:{}, idNo:{}, userId:{}, authPattern:{}"
,
obj
.
getName
(),
obj
.
getIdNo
(),
obj
.
getUserUuid
(),
obj
.
getAuthPattern
());
Object
o
bj
=
userAuthorizedService
.
getUserAuthorizedId
(
this
.
obj
.
getUserUuid
());
Object
o
=
userAuthorizedService
.
getUserAuthorizedId
(
this
.
obj
.
getUserUuid
());
Assert
.
assertNotNull
(
o
bj
);
Assert
.
assertNotNull
(
o
);
}
}
}
}
src/test/java/web/UserAuthorizedControllerTests.java
View file @
7a2e1808
...
@@ -38,11 +38,12 @@ public class UserAuthorizedControllerTests extends BaseParametersTests {
...
@@ -38,11 +38,12 @@ public class UserAuthorizedControllerTests extends BaseParametersTests {
private
TestRestTemplate
restTemplate
;
private
TestRestTemplate
restTemplate
;
private
UserAuthorizedParam
obj
=
new
UserAuthorizedParam
();
private
UserAuthorizedParam
obj
=
new
UserAuthorizedParam
();
{
{
Long
userId
=
1L
;
String
userUuid
=
"711892ae-191b-445a-a4eb-3c0b7bab7840"
;
String
idNo
=
"350504198805144101"
;
String
idNo
=
"350504198805144101"
;
String
name
=
"史书一"
;
String
name
=
"史书一"
;
AuthPattern
authPattern
=
AuthPattern
.
ZMXY
;
AuthPattern
authPattern
=
AuthPattern
.
ZMXY
;
Boolean
available
=
true
;
Boolean
available
=
true
;
obj
.
setUserUuid
(
userUuid
);
obj
.
setIdNo
(
idNo
);
obj
.
setIdNo
(
idNo
);
obj
.
setName
(
name
);
obj
.
setName
(
name
);
obj
.
setAuthPattern
(
Optional
.
ofNullable
(
authPattern
).
orElse
(
AuthPattern
.
ZMXY
).
name
());
obj
.
setAuthPattern
(
Optional
.
ofNullable
(
authPattern
).
orElse
(
AuthPattern
.
ZMXY
).
name
());
...
@@ -64,7 +65,7 @@ public class UserAuthorizedControllerTests extends BaseParametersTests {
...
@@ -64,7 +65,7 @@ public class UserAuthorizedControllerTests extends BaseParametersTests {
@Test
@Test
public
void
testQuery
(){
public
void
testQuery
(){
ResponseEntity
<
String
>
phil
=
restTemplate
.
getForEntity
(
"/user/auth/{model}?user
Id={userId}"
,
String
.
class
,
"getUserAuthorizedId"
);
ResponseEntity
<
String
>
phil
=
restTemplate
.
getForEntity
(
"/user/auth/{model}?user
Uuid={userUuid}"
,
String
.
class
,
"getUserAuthorizedId"
,
obj
.
getUserUuid
()
);
Assert
.
assertEquals
(
phil
.
getStatusCode
(),
HttpStatus
.
OK
);
Assert
.
assertEquals
(
phil
.
getStatusCode
(),
HttpStatus
.
OK
);
}
}
...
...
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