Browse Source

[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>
pull/3/MERGE
Yichao Yang 4 years ago committed by chenxingchun
parent
commit
90c90b25b0
  1. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
  2. 6
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java
  3. 16
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TenantControllerTest.java
  4. 28
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java

@ -35,7 +35,7 @@ public enum Status {
USER_NAME_NULL(10004,"user name is null", "用户名不能为空"), USER_NAME_NULL(10004,"user name is null", "用户名不能为空"),
HDFS_OPERATION_ERROR(10006, "hdfs operation error", "hdfs操作错误"), HDFS_OPERATION_ERROR(10006, "hdfs operation error", "hdfs操作错误"),
TASK_INSTANCE_NOT_FOUND(10008, "task instance not found", "任务实例不存在"), 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}]不存在"), USER_NOT_EXIST(10010, "user {0} not exists", "用户[{0}]不存在"),
ALERT_GROUP_NOT_EXIST(10011, "alarm group not found", "告警组不存在"), ALERT_GROUP_NOT_EXIST(10011, "alarm group not found", "告警组不存在"),
ALERT_GROUP_EXIST(10012, "alarm group already exists", "告警组名称已存在"), ALERT_GROUP_EXIST(10012, "alarm group already exists", "告警组名称已存在"),

6
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java

@ -327,11 +327,11 @@ public class TenantService extends BaseService{
* @return true if tenant code can user, otherwise return false * @return true if tenant code can user, otherwise return false
*/ */
public Result verifyTenantCode(String tenantCode) { public Result verifyTenantCode(String tenantCode) {
Result result=new Result(); Result result = new Result();
if (checkTenantExists(tenantCode)) { if (checkTenantExists(tenantCode)) {
logger.error("tenant {} has exist, can't create again.", tenantCode); logger.error("tenant {} has exist, can't create again.", tenantCode);
putMsg(result, Status.TENANT_NAME_EXIST); putMsg(result, Status.TENANT_NAME_EXIST, tenantCode);
}else{ } else {
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
} }
return result; return result;

16
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TenantControllerTest.java

@ -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 @Test
public void testQueryTenantlist() throws Exception { public void testQueryTenantlist() throws Exception {

28
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java

@ -16,8 +16,11 @@
*/ */
package org.apache.dolphinscheduler.api.service; package org.apache.dolphinscheduler.api.service;
import com.baomidou.mybatisplus.core.metadata.IPage; import java.util.ArrayList;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.dolphinscheduler.api.enums.Status; import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
@ -41,10 +44,10 @@ import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
import java.util.ArrayList; import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Map;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class TenantServiceTest { public class TenantServiceTest {
@ -61,8 +64,8 @@ public class TenantServiceTest {
@Mock @Mock
private UserMapper userMapper; private UserMapper userMapper;
private String tenantCode ="TenantServiceTest"; private String tenantCode = "TenantServiceTest";
private String tenantName ="TenantServiceTest"; private String tenantName = "TenantServiceTest";
@Test @Test
@ -85,6 +88,7 @@ public class TenantServiceTest {
result = tenantService.createTenant(loginUser, "test", "test", 1, "TenantServiceTest"); result = tenantService.createTenant(loginUser, "test", "test", 1, "TenantServiceTest");
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS)); Assert.assertEquals(Status.SUCCESS,result.get(Constants.STATUS));
} catch (Exception e) { } catch (Exception e) {
logger.error("create tenant error",e); logger.error("create tenant error",e);
Assert.assertTrue(false); Assert.assertTrue(false);
@ -192,11 +196,17 @@ public class TenantServiceTest {
// tenantCode not exist // tenantCode not exist
Result result = tenantService.verifyTenantCode("s00000000000l887888885554444sfjdskfjslakslkdf"); Result result = tenantService.verifyTenantCode("s00000000000l887888885554444sfjdskfjslakslkdf");
logger.info(result.toString()); logger.info(result.toString());
Assert.assertEquals(Status.SUCCESS.getMsg(),result.getMsg()); Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg());
// tenantCode exist // tenantCode exist
result = tenantService.verifyTenantCode(getTenant().getTenantCode()); 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()); logger.info(result.toString());
Assert.assertEquals(Status.TENANT_NAME_EXIST.getMsg(),result.getMsg()); Assert.assertEquals(resultString, result.getMsg());
} }

Loading…
Cancel
Save