From 50302a0145dd5bc0e322b798d0181d0e1e77c2fa Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Fri, 16 Jun 2023 15:44:53 +0800 Subject: [PATCH] =?UTF-8?q?test(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=84=E7=BB=87=E7=AE=A1=E7=90=86=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/OrganizationServiceImpl.java | 3 --- .../OrganizationControllerTests.java | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationServiceImpl.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationServiceImpl.java index 5595659686..0000ad3986 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationServiceImpl.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationServiceImpl.java @@ -48,9 +48,6 @@ public class OrganizationServiceImpl implements OrganizationService{ OrganizationExample example = new OrganizationExample(); example.createCriteria().andNumEqualTo(100001L); List organizations = organizationMapper.selectByExample(example); - if (CollectionUtils.isEmpty(organizations)) { - throw new MSException(Translator.get("organization_default_not_exists")); - } Organization organization = organizations.get(0); BeanUtils.copyBean(organizationDTO, organization); return organizationDTO; diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java index 49e696c22c..9ef8e8241d 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationControllerTests.java @@ -21,6 +21,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import java.util.Arrays; +import java.util.Collections; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -91,7 +92,7 @@ public class OrganizationControllerTests extends BaseTest{ @Test @Order(4) - public void testAddOrganizationMember() throws Exception { + public void testAddOrganizationMemberPass() throws Exception { OrganizationMemberRequest organizationMemberRequest = new OrganizationMemberRequest(); organizationMemberRequest.setOrganizationId("default-organization-3"); organizationMemberRequest.setMemberIds(Arrays.asList("admin", "default-admin")); @@ -105,6 +106,20 @@ public class OrganizationControllerTests extends BaseTest{ @Test @Order(5) + public void testAddOrganizationMemberNotPass() throws Exception { + OrganizationMemberRequest organizationMemberRequest = new OrganizationMemberRequest(); + organizationMemberRequest.setOrganizationId("default-organization-3"); + organizationMemberRequest.setMemberIds(Collections.emptyList()); + mockMvc.perform(MockMvcRequestBuilders.post(REQ_PREFIX + "/add-member") + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken) + .content(JSON.toJSONString(organizationMemberRequest)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isBadRequest()); + } + + @Test + @Order(6) public void testRemoveOrganizationMember() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get(REQ_PREFIX + "/remove-member/default-organization-3/admin") .header(SessionConstants.HEADER_TOKEN, sessionId) @@ -113,7 +128,7 @@ public class OrganizationControllerTests extends BaseTest{ } @Test - @Order(6) + @Order(7) public void testGetOrganizationProject() throws Exception { ProjectRequest projectRequest = new ProjectRequest(); projectRequest.setCurrent(1);