-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test($auth-center): create unit tests for
auth-center-biz
create unit tests for `auth-center-biz` BREAKING CHANGE: use Mockito for unit test; create unit tests for `auth-center-biz`
- Loading branch information
1 parent
ceb256b
commit a7519c7
Showing
10 changed files
with
114 additions
and
25 deletions.
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3
...way-bootstrap/src/test/java/com/jmsoftware/maf/apigateway/ApiGatewayApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...java/com/jmsoftware/maf/authcenter/permission/service/impl/PermissionServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.jmsoftware.maf.authcenter.permission.service.impl; | ||
|
||
import com.google.common.collect.Lists; | ||
import com.google.common.collect.Sets; | ||
import com.jmsoftware.maf.authcenter.permission.configuration.PermissionConfiguration; | ||
import com.jmsoftware.maf.authcenter.permission.service.PermissionDomainService; | ||
import com.jmsoftware.maf.authcenter.role.service.RoleDomainService; | ||
import com.jmsoftware.maf.common.bean.ResponseBodyBean; | ||
import com.jmsoftware.maf.common.domain.authcenter.permission.GetPermissionListByRoleIdListPayload; | ||
import com.jmsoftware.maf.common.domain.springbootstarter.HttpApiResourcesResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.cloud.client.discovery.DiscoveryClient; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Description: PermissionServiceImplTest, change description here. | ||
* | ||
* @author Johnny Miller (鍾俊), e-mail: johnnysviva@outlook.com, date: 4/3/22 10:19 PM | ||
**/ | ||
@Slf4j | ||
@ExtendWith(MockitoExtension.class) | ||
class PermissionServiceImplTest { | ||
@InjectMocks | ||
private PermissionServiceImpl permissionService; | ||
@Mock | ||
private PermissionDomainService permissionDomainService; | ||
@Mock | ||
private RoleDomainService roleDomainService; | ||
@Mock | ||
private DiscoveryClient discoveryClient; | ||
@Mock | ||
private RestTemplate restTemplate; | ||
@Mock | ||
private PermissionConfiguration permissionConfiguration; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
log.info("PermissionServiceImplTest setUp"); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
log.info("PermissionServiceImplTest tearDown"); | ||
} | ||
|
||
@Test | ||
void getPermissionListByRoleIdList() { | ||
when(this.roleDomainService.checkAdmin(anyList())).thenReturn(false); | ||
when(this.permissionDomainService.getPermissionListByRoleIdList(anyList(), anyList())) | ||
.thenReturn(Lists.newArrayList()); | ||
|
||
val payload = new GetPermissionListByRoleIdListPayload(); | ||
payload.setRoleIdList(Lists.newArrayList()); | ||
payload.setPermissionTypeList(Lists.newArrayList()); | ||
val response = this.permissionService.getPermissionListByRoleIdList(payload); | ||
log.info("Permission list response: {}", response); | ||
verify(this.roleDomainService).checkAdmin(anyList()); | ||
verify(this.permissionDomainService).getPermissionListByRoleIdList(anyList(), anyList()); | ||
assertEquals(0, response.getPermissionList().size()); | ||
} | ||
|
||
@Test | ||
void getServicesInfo() { | ||
when(this.discoveryClient.getServices()) | ||
.thenReturn(Lists.newArrayList( | ||
"auth-center", "oss-center", "maf-mis", "api-gateway", "spring-boot-admin")); | ||
when(this.permissionConfiguration.getIgnoredServiceIds()) | ||
.thenReturn(Sets.newHashSet("api-gateway", "spring-boot-admin")); | ||
when(this.restTemplate.getForObject(anyString(), any())) | ||
.thenReturn(ResponseBodyBean.ofSuccess(new HttpApiResourcesResponse())); | ||
|
||
val servicesInfo = this.permissionService.getServicesInfo(); | ||
log.info("Services info: {}", servicesInfo); | ||
verify(this.discoveryClient).getServices(); | ||
assertNotEquals(0, servicesInfo.getList().size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...enter/auth-center-bootstrap/src/test/java/com/jmsoftware/maf/authcenter/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package com.jmsoftware.maf.authcenter; |
3 changes: 1 addition & 2 deletions
3
...-mis-bootstrap/src/test/java/com/jmsoftware/maf/mafmis/ExercisePoMisApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...rap/src/test/java/com/jmsoftware/maf/springbootadmin/SpringBootAdminApplicationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters