Unverified Commit 5868af89 authored by Yichao Yang's avatar Yichao Yang Committed by GitHub
Browse files

[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: default avatardailidong <dailidong66@gmail.com>
Co-authored-by: default avatarqiaozhanwei <qiaozhanwei@outlook.com>
parent 933a67db
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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", "告警组名称已存在"),
+3 −3
Original line number Diff line number Diff line
@@ -330,7 +330,7 @@ public class TenantService extends BaseService{
    Result result = new Result();
    if (checkTenantExists(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 {
      putMsg(result, Status.SUCCESS);
    }
+16 −0
Original line number Diff line number Diff line
@@ -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 {
+20 −10
Original line number Diff line number Diff line
@@ -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 {
@@ -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);
@@ -195,8 +199,14 @@ public class TenantServiceTest {
        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());
    }