Skip to content

Commit

Permalink
fix cr
Browse files Browse the repository at this point in the history
  • Loading branch information
‘xcsnx’ committed Sep 21, 2024
1 parent 6a74640 commit baa6f81
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion shenyu-admin/src/main/resources/mappers/app-auth-sqlmap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@
<include refid="Base_Column_List"/>
FROM app_auth
<where>
namespace_id = #{namespaceId, jdbcType=VARCHAR}
<if test="namespaceId != null and namespaceId != ''">
AND namespace_id = #{namespaceId, jdbcType=VARCHAR}
</if>
<if test="appKey != null and appKey != ''">
AND app_key = #{appKey, jdbcType=VARCHAR}
</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.admin.mapper.AppAuthMapper;
import org.apache.shenyu.admin.mapper.AuthPathMapper;
import org.apache.shenyu.admin.mapper.NamespaceMapper;
import org.apache.shenyu.admin.model.dto.AppAuthDTO;
import org.apache.shenyu.admin.model.dto.AuthApplyDTO;
import org.apache.shenyu.admin.model.dto.AuthPathDTO;
Expand Down Expand Up @@ -90,6 +91,9 @@ public final class AppAuthControllerTest {
@Mock
private AppAuthMapper appAuthMapper;

@Mock
private NamespaceMapper namespaceMapper;

private final AppAuthVO appAuthVO = new AppAuthVO("0001", "testAppKey", "testAppSecret",
"testUser", "18600000000", "{\"extInfo\": \"test\"}",
true, true, null, null,
Expand Down Expand Up @@ -139,8 +143,12 @@ public void testApply() throws Exception {
authApplyDTO.setExtInfo("{\"extInfo\": \"test\"}");
authApplyDTO.setOpen(true);
authApplyDTO.setPathList(pathList);
authApplyDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID);
given(this.appAuthService.applyCreate(authApplyDTO)).willReturn(
ShenyuAdminResult.success(ShenyuResultMessage.CREATE_SUCCESS));
SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class));
when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper);
when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true);
this.mockMvc.perform(MockMvcRequestBuilders.post("/appAuth/apply")
.contentType(MediaType.APPLICATION_JSON)
.content(GsonUtils.getInstance().toJson(authApplyDTO)))
Expand All @@ -162,6 +170,10 @@ public void testApplyWithAppKey() throws Exception {
authApplyDTO.setExtInfo("{\"extInfo\": \"test\"}");
authApplyDTO.setOpen(true);
authApplyDTO.setPathList(pathList);
authApplyDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID);
SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class));
when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper);
when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true);
given(this.appAuthService.applyUpdate(authApplyDTO)).willReturn(
ShenyuAdminResult.success(ShenyuResultMessage.CREATE_SUCCESS));
this.mockMvc.perform(MockMvcRequestBuilders.post("/appAuth/apply")
Expand All @@ -187,11 +199,15 @@ public void testFindPageByQuery() throws Exception {
final AppAuthQuery appAuthQuery = new AppAuthQuery("testAppKey", "18600000000", pageParameter, SYS_DEFAULT_NAMESPACE_ID);
final CommonPager<AppAuthVO> commonPager = new CommonPager<>(pageParameter, Collections.singletonList(appAuthVO));
given(this.appAuthService.listByPage(appAuthQuery)).willReturn(commonPager);
SpringBeanUtils.getInstance().setApplicationContext(mock(ConfigurableApplicationContext.class));
when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper);
when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true);
this.mockMvc.perform(MockMvcRequestBuilders.get("/appAuth/findPageByQuery")
.param("appKey", "testAppKey")
.param("phone", "18600000000")
.param("currentPage", String.valueOf(pageParameter.getCurrentPage()))
.param("pageSize", String.valueOf(pageParameter.getPageSize())))
.param("pageSize", String.valueOf(pageParameter.getPageSize()))
.param("namespaceId",SYS_DEFAULT_NAMESPACE_ID))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message", is(ShenyuResultMessage.QUERY_SUCCESS)))
.andExpect(jsonPath("$.data.dataList[0].appKey", is(appAuthVO.getAppKey())))
Expand All @@ -216,12 +232,15 @@ public void testUpdateDetail() throws Exception {
appAuthDTO.setAppKey("app key");
appAuthDTO.setAppSecret("app secret");
appAuthDTO.setPhone("1234567");
appAuthDTO.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID);
given(this.appAuthService.updateDetail(appAuthDTO)).willReturn(
ShenyuAdminResult.success(ShenyuResultMessage.UPDATE_SUCCESS));
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
SpringBeanUtils.getInstance().setApplicationContext(context);
when(SpringBeanUtils.getInstance().getBean(AppAuthMapper.class)).thenReturn(appAuthMapper);
when(appAuthMapper.existed(appAuthDTO.getId())).thenReturn(true);
when(SpringBeanUtils.getInstance().getBean(NamespaceMapper.class)).thenReturn(namespaceMapper);
when(namespaceMapper.existed(SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true);
this.mockMvc.perform(MockMvcRequestBuilders.post("/appAuth/updateDetail")
.contentType(MediaType.APPLICATION_JSON)
.content(GsonUtils.getInstance().toJson(appAuthDTO)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.sql.Timestamp;
import java.util.List;

import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void testSelectById() {
@Test
public void testByQuery() {
AppAuthQuery appAuthQuery = new AppAuthQuery();
appAuthQuery.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID);
List<AppAuthDO> appAuthDOsWithQuery = appAuthMapper.selectByQuery(appAuthQuery);
assertThat(appAuthDOsWithQuery.size(), greaterThan(0));

Expand All @@ -90,6 +92,7 @@ public void testCountByQuery() {
AppAuthQuery appAuthQuery = new AppAuthQuery();
appAuthQuery.setPhone(appAuthDO.getPhone());
appAuthQuery.setAppKey(appAuthDO.getAppKey());
appAuthQuery.setNamespaceId(SYS_DEFAULT_NAMESPACE_ID);
int count = appAuthMapper.countByQuery(appAuthQuery);
assertEquals(1, count);
}
Expand Down Expand Up @@ -145,6 +148,7 @@ private AppAuthDO buildAppAuthDO() {
.enabled(false)
.phone("18800000000")
.userId(UUIDUtils.getInstance().generateShortUuid())
.namespaceId(SYS_DEFAULT_NAMESPACE_ID)
.dateCreated(now)
.dateUpdated(now)
.build();
Expand Down

0 comments on commit baa6f81

Please sign in to comment.