You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ch...@apache.org on 2020/09/28 03:31:22 UTC
[incubator-dolphinscheduler] branch 1.3.3-release updated:
[Hotfix-3131][api] Fix the new tenant already exists prompt (#3132)
This is an automated email from the ASF dual-hosted git repository.
chenxingchun pushed a commit to branch 1.3.3-release
in repository https://gitbox.apache.org/repos/asf/incubator-dolphinscheduler.git
The following commit(s) were added to refs/heads/1.3.3-release by this push:
new 92cbea6 [Hotfix-3131][api] Fix the new tenant already exists prompt (#3132)
92cbea6 is described below
commit 92cbea628cfd63413e51e2081c4d3212c6802b31
Author: Yichao Yang <10...@qq.com>
AuthorDate: Mon Jul 13 08:48:59 2020 +0800
[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 <da...@gmail.com>
Co-authored-by: qiaozhanwei <qi...@outlook.com>
(cherry picked from commit 5868af89478cda9a0f87a82340c6bc17800d5ba6)
---
.../apache/dolphinscheduler/api/enums/Status.java | 2 +-
.../api/service/TenantService.java | 6 ++---
.../api/controller/TenantControllerTest.java | 16 ++++++++++++
.../api/service/TenantServiceTest.java | 30 ++++++++++++++--------
4 files changed, 40 insertions(+), 14 deletions(-)
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
index 49dac87..9bb8e65 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/enums/Status.java
+++ b/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", "用户名不能为空"),
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", "告警组名称已存在"),
diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java
index 2fded4d3..a78c951 100644
--- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java
+++ b/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
*/
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;
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TenantControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TenantControllerTest.java
index b3beacf..60516b5 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/TenantControllerTest.java
+++ b/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
public void testQueryTenantlist() throws Exception {
diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java
index d6fb6b2..f7f506b 100644
--- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java
+++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java
@@ -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 {
}
-}
\ No newline at end of file
+}