mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-03 04:39:00 +08:00
[Hotfix-3131][api] Fix the new tenant already exists prompt (#3132)
* Bugfix: Fix the new tenant already exists prompt * Feature: Add test cases * Update TenantServiceTest.java Co-authored-by: dailidong <dailidong66@gmail.com> Co-authored-by: qiaozhanwei <qiaozhanwei@outlook.com>
This commit is contained in:
parent
ea56513172
commit
90c90b25b0
@ -35,7 +35,7 @@ public enum Status {
|
||||
USER_NAME_NULL(10004,"user name is null", "用户名不能为空"),
|
||||
HDFS_OPERATION_ERROR(10006, "hdfs operation error", "hdfs操作错误"),
|
||||
TASK_INSTANCE_NOT_FOUND(10008, "task instance not found", "任务实例不存在"),
|
||||
TENANT_NAME_EXIST(10009, "tenant code already exists", "租户编码不能为空"),
|
||||
TENANT_NAME_EXIST(10009, "tenant code {0} already exists", "租户编码[{0}]已存在"),
|
||||
USER_NOT_EXIST(10010, "user {0} not exists", "用户[{0}]不存在"),
|
||||
ALERT_GROUP_NOT_EXIST(10011, "alarm group not found", "告警组不存在"),
|
||||
ALERT_GROUP_EXIST(10012, "alarm group already exists", "告警组名称已存在"),
|
||||
|
@ -327,11 +327,11 @@ public class TenantService extends BaseService{
|
||||
* @return true if tenant code can user, otherwise return false
|
||||
*/
|
||||
public Result verifyTenantCode(String tenantCode) {
|
||||
Result result=new Result();
|
||||
Result result = new Result();
|
||||
if (checkTenantExists(tenantCode)) {
|
||||
logger.error("tenant {} has exist, can't create again.", tenantCode);
|
||||
putMsg(result, Status.TENANT_NAME_EXIST);
|
||||
}else{
|
||||
putMsg(result, Status.TENANT_NAME_EXIST, tenantCode);
|
||||
} else {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
}
|
||||
return result;
|
||||
|
@ -120,7 +120,23 @@ public class TenantControllerTest extends AbstractControllerTest{
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyTenantCodeExists() throws Exception {
|
||||
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
|
||||
paramsMap.add("tenantCode", "tenantCode");
|
||||
|
||||
MvcResult mvcResult = mockMvc.perform(get("/tenant/verify-tenant-code")
|
||||
.header(SESSION_ID, sessionId)
|
||||
.params(paramsMap))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
|
||||
.andReturn();
|
||||
|
||||
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
|
||||
Assert.assertEquals(Status.TENANT_NAME_EXIST.getCode(), result.getCode().intValue());
|
||||
logger.info(mvcResult.getResponse().getContentAsString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryTenantlist() throws Exception {
|
||||
|
@ -16,8 +16,11 @@
|
||||
*/
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.Result;
|
||||
@ -41,10 +44,10 @@ import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TenantServiceTest {
|
||||
@ -61,8 +64,8 @@ public class TenantServiceTest {
|
||||
@Mock
|
||||
private UserMapper userMapper;
|
||||
|
||||
private String tenantCode ="TenantServiceTest";
|
||||
private String tenantName ="TenantServiceTest";
|
||||
private String tenantCode = "TenantServiceTest";
|
||||
private String tenantName = "TenantServiceTest";
|
||||
|
||||
|
||||
@Test
|
||||
@ -85,6 +88,7 @@ public class TenantServiceTest {
|
||||
result = tenantService.createTenant(loginUser, "test", "test", 1, "TenantServiceTest");
|
||||
logger.info(result.toString());
|
||||
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("create tenant error",e);
|
||||
Assert.assertTrue(false);
|
||||
@ -192,11 +196,17 @@ public class TenantServiceTest {
|
||||
// tenantCode not exist
|
||||
Result result = tenantService.verifyTenantCode("s00000000000l887888885554444sfjdskfjslakslkdf");
|
||||
logger.info(result.toString());
|
||||
Assert.assertEquals(Status.SUCCESS.getMsg(),result.getMsg());
|
||||
Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg());
|
||||
// tenantCode exist
|
||||
result = tenantService.verifyTenantCode(getTenant().getTenantCode());
|
||||
String resultString;
|
||||
if (Locale.SIMPLIFIED_CHINESE.getLanguage().equals(LocaleContextHolder.getLocale().getLanguage())) {
|
||||
resultString = "租户编码[TenantServiceTest]已存在";
|
||||
} else {
|
||||
resultString = "tenant code TenantServiceTest already exists";
|
||||
}
|
||||
logger.info(result.toString());
|
||||
Assert.assertEquals(Status.TENANT_NAME_EXIST.getMsg(),result.getMsg());
|
||||
Assert.assertEquals(resultString, result.getMsg());
|
||||
}
|
||||
|
||||
|
||||
@ -261,4 +271,4 @@ public class TenantServiceTest {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user