diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchValueController.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchController.java similarity index 85% rename from apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchValueController.java rename to apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchController.java index 3850675e43a..b0ecf9b25b9 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchValueController.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchController.java @@ -22,7 +22,7 @@ import com.ctrip.framework.apollo.portal.component.config.PortalConfig; import com.ctrip.framework.apollo.portal.entity.vo.ItemInfo; import com.ctrip.framework.apollo.portal.environment.Env; -import com.ctrip.framework.apollo.portal.service.GlobalSearchValueService; +import com.ctrip.framework.apollo.portal.service.GlobalSearchService; import com.google.gson.Gson; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -40,20 +40,20 @@ @RestController -public class GlobalSearchValueController { +public class GlobalSearchController { private final PortalSettings portalSettings; - private final GlobalSearchValueService globalSearchValueService; + private final GlobalSearchService globalSearchService; private final PortalConfig portalConfig; - public GlobalSearchValueController(final PortalSettings portalSettings, final GlobalSearchValueService globalSearchValueService, final PortalConfig portalConfig) { + public GlobalSearchController(final PortalSettings portalSettings, final GlobalSearchService globalSearchService, final PortalConfig portalConfig) { this.portalSettings = portalSettings; - this.globalSearchValueService = globalSearchValueService; + this.globalSearchService = globalSearchService; this.portalConfig = portalConfig; } @PreAuthorize(value = "@permissionValidator.isSuperAdmin()") @GetMapping("/global-search/item-info/by-key-or-value") - public ResponseEntity get_ItemInfo_BySearch(@RequestParam(value = "key", required = false, defaultValue = "") String key, + public ResponseEntity getItemInfoBySearch(@RequestParam(value = "key", required = false, defaultValue = "") String key, @RequestParam(value = "value", required = false , defaultValue = "") String value) { if(key.isEmpty() && value.isEmpty()) { @@ -76,7 +76,7 @@ public ResponseEntity get_ItemInfo_BySearch(@RequestParam(value = "key", requ List envBeyondLimit = new ArrayList<>(); AtomicBoolean hasMoreData = new AtomicBoolean(false); activeEnvs.forEach(env -> { - PageDTO perEnvItemInfos = globalSearchValueService.get_PerEnv_ItemInfo_BySearch(env, key, value,0, portalConfig.getPerEnvSearchMaxResults()); + PageDTO perEnvItemInfos = globalSearchService.getPerEnvItemInfoBySearch(env, key, value,0, portalConfig.getPerEnvSearchMaxResults()); if (!perEnvItemInfos.hasContent()) { return; } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/GlobalSearchValueService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/GlobalSearchService.java similarity index 88% rename from apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/GlobalSearchValueService.java rename to apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/GlobalSearchService.java index 8d94b9e12be..e25b289e91c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/GlobalSearchValueService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/GlobalSearchService.java @@ -30,16 +30,16 @@ import java.util.List; @Service -public class GlobalSearchValueService { +public class GlobalSearchService { - private static final Logger LOGGER = LoggerFactory.getLogger(GlobalSearchValueService.class); + private static final Logger LOGGER = LoggerFactory.getLogger(GlobalSearchService.class); private final AdminServiceAPI.ItemAPI itemAPI; - public GlobalSearchValueService(AdminServiceAPI.ItemAPI itemAPI) { + public GlobalSearchService(AdminServiceAPI.ItemAPI itemAPI) { this.itemAPI = itemAPI; } - public PageDTO get_PerEnv_ItemInfo_BySearch(Env env, String key, String value, int page, int size) { + public PageDTO getPerEnvItemInfoBySearch(Env env, String key, String value, int page, int size) { List perEnvItemInfos = new ArrayList<>(); PageDTO perEnvItemInfoDTOs = itemAPI.getPerEnvItemInfoBySearch(env, key, value, page, size); perEnvItemInfoDTOs.getContent().forEach(itemInfoDTO -> { diff --git a/apollo-portal/src/main/resources/static/global_search_value.html b/apollo-portal/src/main/resources/static/global_search_value.html index 3ac0a86fbf3..1d59578914b 100644 --- a/apollo-portal/src/main/resources/static/global_search_value.html +++ b/apollo-portal/src/main/resources/static/global_search_value.html @@ -73,7 +73,7 @@ {{'Global.Cluster' | translate }} {{'Global.NameSpace' | translate }} {{'Global.Key' | translate }} - {{'Global.Value' | translate }} + {{'Global.Value' | translate }} {{'Global.Operate' | translate }} @@ -82,18 +82,21 @@ {{ item.clusterName }} {{ item.namespaceName }} - {{ item.key }} - + {{ item.key }} + - {{ item.value }} - - {{ needToBeHighlightedValue }}... - ...{{ needToBeHighlightedValue }} - ...{{ needToBeHighlightedValue }}... - | {{'Global.Expand' | translate }} - - | {{'Global.Abbreviate' | translate }} + {{ item.value }} + + {{ item.value }} + + {{ needToBeHighlightedValue }}... + ...{{ needToBeHighlightedValue }} + ...{{ needToBeHighlightedValue }}... + | {{'Global.Expand' | translate }} + + | {{'Global.Abbreviate' | translate }} + diff --git a/apollo-portal/src/main/resources/static/scripts/controller/GlobalSearchValueController.js b/apollo-portal/src/main/resources/static/scripts/controller/GlobalSearchValueController.js index 8846596f063..e719c29f956 100644 --- a/apollo-portal/src/main/resources/static/scripts/controller/GlobalSearchValueController.js +++ b/apollo-portal/src/main/resources/static/scripts/controller/GlobalSearchValueController.js @@ -26,10 +26,12 @@ function GlobalSearchValueController($scope, $window, $translate, toastr, AppUti $scope.needToBeHighlightedKey = ''; $scope.needToBeHighlightedValue = ''; $scope.isShowHighlightKeyword = []; - $scope.isAllItemInfoDirectlyDisplayKey = []; - $scope.isAllItemInfoDirectlyDisplayValue = []; - $scope.isPageItemInfoDirectlyDisplayKey = []; - $scope.isPageItemInfoDirectlyDisplayValue = []; + $scope.isAllItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword = []; + $scope.isAllItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword = []; + $scope.isAllItemInfoDisplayValueInARow = []; + $scope.isPageItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword = []; + $scope.isPageItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword = []; + $scope.isPageItemInfoDisplayValueInARow = []; $scope.currentPage = 1; $scope.pageSize = '10'; $scope.totalItems = 0; @@ -45,8 +47,8 @@ function GlobalSearchValueController($scope, $window, $translate, toastr, AppUti $scope.convertPageSizeToInt = convertPageSizeToInt; $scope.changePage = changePage; $scope.getPagesArray = getPagesArray; - $scope.determineDisplayValue = determineDisplayValue; - $scope.determineDisplayKey = determineDisplayKey; + $scope.determineDisplayKeyOrValueWithoutShowHighlightKeyword = determineDisplayKeyOrValueWithoutShowHighlightKeyword; + $scope.determineDisplayValueInARow = determineDisplayValueInARow; init(); function init() { @@ -66,10 +68,12 @@ function GlobalSearchValueController($scope, $window, $translate, toastr, AppUti $scope.itemInfoSearchValue = itemInfoSearchValue || ''; $scope.allItemInfo = []; $scope.pageItemInfo = []; - $scope.isAllItemInfoDirectlyDisplayKey = []; - $scope.isPageItemInfoDirectlyDisplayKey = []; - $scope.isAllItemInfoDirectlyDisplayValue = []; - $scope.isPageItemInfoDirectlyDisplayValue = []; + $scope.isAllItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword = []; + $scope.isAllItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword = []; + $scope.isAllItemInfoDisplayValueInARow = []; + $scope.isPageItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword = []; + $scope.isPageItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword = []; + $scope.isPageItemInfoDisplayValueInARow = []; $scope.tempKey = itemInfoSearchKey || ''; $scope.tempValue = itemInfoSearchValue || ''; $scope.isShowHighlightKeyword = []; @@ -77,31 +81,34 @@ function GlobalSearchValueController($scope, $window, $translate, toastr, AppUti .then(handleSuccess).catch(handleError); function handleSuccess(result) { let allItemInfo = []; - let isAllItemInfoDirectlyDisplayValue = []; - let isAllItemInfoDirectlyDisplayKey = []; + let isAllItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword = []; + let isAllItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword = []; + let isAllItemInfoDisplayValueInARow = []; if(($scope.itemInfoSearchKey === '') && !($scope.itemInfoSearchValue === '')){ $scope.needToBeHighlightedValue = $scope.itemInfoSearchValue; $scope.needToBeHighlightedKey = ''; result.data.forEach((itemInfo, index) => { allItemInfo.push(itemInfo); - isAllItemInfoDirectlyDisplayValue[index] = determineDisplayValue(itemInfo.value, itemInfoSearchValue); - isAllItemInfoDirectlyDisplayKey[index] = determineDisplayKey(itemInfo.key, ''); + isAllItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword[index] = '0'; + isAllItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword[index] = determineDisplayKeyOrValueWithoutShowHighlightKeyword(itemInfo.value, itemInfoSearchValue); + isAllItemInfoDisplayValueInARow[index] = determineDisplayValueInARow(itemInfo.value, itemInfoSearchValue); }); }else if(!($scope.itemInfoSearchKey === '') && ($scope.itemInfoSearchValue === '')){ $scope.needToBeHighlightedKey = $scope.itemInfoSearchKey; $scope.needToBeHighlightedValue = ''; result.data.forEach((itemInfo, index) => { allItemInfo.push(itemInfo); - isAllItemInfoDirectlyDisplayKey[index] = determineDisplayKey(itemInfo.key, itemInfoSearchKey); - isAllItemInfoDirectlyDisplayValue[index] = '0'; + isAllItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword[index] = determineDisplayKeyOrValueWithoutShowHighlightKeyword(itemInfo.key, itemInfoSearchKey); + isAllItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword[index] = '0'; }); }else{ $scope.needToBeHighlightedKey = $scope.itemInfoSearchKey; $scope.needToBeHighlightedValue = $scope.itemInfoSearchValue; result.data.forEach((itemInfo, index) => { allItemInfo.push(itemInfo); - isAllItemInfoDirectlyDisplayValue[index] = determineDisplayValue(itemInfo.value, itemInfoSearchValue); - isAllItemInfoDirectlyDisplayKey[index] = determineDisplayKey(itemInfo.key, itemInfoSearchKey); + isAllItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword[index] = determineDisplayKeyOrValueWithoutShowHighlightKeyword(itemInfo.value, itemInfoSearchValue); + isAllItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword[index] = determineDisplayKeyOrValueWithoutShowHighlightKeyword(itemInfo.key, itemInfoSearchKey); + isAllItemInfoDisplayValueInARow[index] = determineDisplayValueInARow(itemInfo.value, itemInfoSearchValue); }); } $scope.totalItems = allItemInfo.length; @@ -110,10 +117,12 @@ function GlobalSearchValueController($scope, $window, $translate, toastr, AppUti const startIndex = ($scope.currentPage - 1) * parseInt($scope.pageSize, 10); const endIndex = Math.min(startIndex + parseInt($scope.pageSize, 10), allItemInfo.length); $scope.pageItemInfo = allItemInfo.slice(startIndex, endIndex); - $scope.isAllItemInfoDirectlyDisplayValue = isAllItemInfoDirectlyDisplayValue; - $scope.isAllItemInfoDirectlyDisplayKey = isAllItemInfoDirectlyDisplayKey; - $scope.isPageItemInfoDirectlyDisplayValue = isAllItemInfoDirectlyDisplayValue.slice(startIndex, endIndex); - $scope.isPageItemInfoDirectlyDisplayKey = isAllItemInfoDirectlyDisplayKey.slice(startIndex, endIndex); + $scope.isAllItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword = isAllItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword; + $scope.isAllItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword = isAllItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword; + $scope.isAllItemInfoDisplayValueInARow = isAllItemInfoDisplayValueInARow; + $scope.isPageItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword = isAllItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword.slice(startIndex, endIndex); + $scope.isPageItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword = isAllItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword.slice(startIndex, endIndex); + $scope.isPageItemInfoDisplayValueInARow = isAllItemInfoDisplayValueInARow.slice(startIndex, endIndex); getPagesArray(); if(result.hasMoreData){ toastr.warning(result.message, $translate.instant('Item.GlobalSearch.Tips')); @@ -141,15 +150,17 @@ function GlobalSearchValueController($scope, $window, $translate, toastr, AppUti if (page >= 1 && page <= $scope.totalPages) { $scope.currentPage = page; $scope.isShowHighlightKeyword = []; - $scope.isPageItemInfoDirectlyDisplayKey = []; - $scope.isPageItemInfoDirectlyDisplayValue = []; + $scope.isPageItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword = []; + $scope.isPageItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword = []; + $scope.isPageItemInfoDisplayValueInARow = []; $scope.itemInfoSearchKey = $scope.tempKey; $scope.itemInfoSearchValue = $scope.tempValue; const startIndex = ($scope.currentPage - 1)* parseInt($scope.pageSize, 10); const endIndex = Math.min(startIndex + parseInt($scope.pageSize, 10), $scope.totalItems); $scope.pageItemInfo = $scope.allItemInfo.slice(startIndex, endIndex); - $scope.isPageItemInfoDirectlyDisplayValue = $scope.isAllItemInfoDirectlyDisplayValue.slice(startIndex, endIndex); - $scope.isPageItemInfoDirectlyDisplayKey = $scope.isAllItemInfoDirectlyDisplayKey.slice(startIndex, endIndex); + $scope.isPageItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword = $scope.isAllItemInfoDirectlyDisplayValueWithoutShowHighlightKeyword.slice(startIndex, endIndex); + $scope.isPageItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword = $scope.isAllItemInfoDirectlyDisplayKeyWithoutShowHighlightKeyword.slice(startIndex, endIndex); + $scope.isPageItemInfoDisplayValueInARow = $scope.isAllItemInfoDisplayValueInARow.slice(startIndex, endIndex); getPagesArray(); } } @@ -189,8 +200,57 @@ function GlobalSearchValueController($scope, $window, $translate, toastr, AppUti $scope.pagesArray = pagesArray; } - function determineDisplayValue(value, highlight) { - if (value === highlight) return '0'; + function determineDisplayValueInARow(value, highlight) { + var valueColumn = document.getElementById('valueColumn'); + var testElement = document.createElement('span'); + setupTestElement(testElement, valueColumn); + testElement.innerText = value; + document.body.appendChild(testElement); + const position = determinePosition(value, highlight); + let displayValue = '0'; + if (testElement.scrollWidth > testElement.offsetWidth) { + displayValue = position; + } else { + if (testElement.scrollWidth === testElement.offsetWidth) { + return '0'; + } + switch (position) { + case '1': + testElement.innerText = value + '...' + '| ' + $translate.instant('Global.Expand'); + break; + case '2': + testElement.innerText = '...' + value + '| ' + $translate.instant('Global.Expand'); + break; + case '3': + testElement.innerText = '...' + value + '...' + '| ' + $translate.instant('Global.Expand'); + break; + default: + return '0'; + } + if (testElement.scrollWidth === testElement.offsetWidth) { + displayValue = '0'; + } else { + displayValue = position; + } + } + document.body.removeChild(testElement); + return displayValue; + } + + function setupTestElement(element, valueColumn) { + element.style.visibility = 'hidden'; + element.style.position = 'absolute'; + element.style.whiteSpace = 'nowrap'; + element.style.display = 'inline-block'; + element.style.fontFamily = '"Open Sans", sans-serif'; + const devicePixelRatio = window.devicePixelRatio; + const zoomLevel = Math.round((window.outerWidth / window.innerWidth) * 100) / 100; + element.style.fontSize = `${13 * devicePixelRatio * zoomLevel}px`; + element.style.padding = `${8 * devicePixelRatio * zoomLevel}px`; + element.style.width = `${valueColumn.offsetWidth * devicePixelRatio * zoomLevel}px`; + } + + function determinePosition(value, highlight) { const position = value.indexOf(highlight); if (position === -1) return '-1'; if (position === 0) return '1'; @@ -198,8 +258,8 @@ function GlobalSearchValueController($scope, $window, $translate, toastr, AppUti return "3"; } - function determineDisplayKey(key, highlight) { - return key === highlight ? '0' : '-1'; + function determineDisplayKeyOrValueWithoutShowHighlightKeyword(keyorvalue, highlight) { + return keyorvalue === highlight ? '0' : '-1'; } function jumpToTheEditingPage(appid,env,cluster){ diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchValueControllerTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchControllerTest.java similarity index 74% rename from apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchValueControllerTest.java rename to apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchControllerTest.java index e908caec654..4a433dc12f5 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchValueControllerTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/controller/GlobalSearchControllerTest.java @@ -25,7 +25,7 @@ import com.ctrip.framework.apollo.portal.component.config.PortalConfig; import com.ctrip.framework.apollo.portal.entity.vo.ItemInfo; import com.ctrip.framework.apollo.portal.environment.Env; -import com.ctrip.framework.apollo.portal.service.GlobalSearchValueService; +import com.ctrip.framework.apollo.portal.service.GlobalSearchService; import com.google.gson.Gson; import org.junit.Before; import org.junit.Test; @@ -47,7 +47,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(MockitoJUnitRunner.class) -public class GlobalSearchValueControllerTest { +public class GlobalSearchControllerTest { private MockMvc mockMvc; @@ -58,10 +58,10 @@ public class GlobalSearchValueControllerTest { private PortalConfig portalConfig; @Mock - private GlobalSearchValueService globalSearchValueService; + private GlobalSearchService globalSearchService; @InjectMocks - private GlobalSearchValueController globalSearchValueController; + private GlobalSearchController globalSearchController; private final List activeEnvs = new ArrayList<>(); @@ -71,7 +71,7 @@ public class GlobalSearchValueControllerTest { public void setUp() { when(portalSettings.getActiveEnvs()).thenReturn(activeEnvs); when(portalConfig.getPerEnvSearchMaxResults()).thenReturn(perEnvSearchMaxResults); - mockMvc = MockMvcBuilders.standaloneSetup(globalSearchValueController).build(); + mockMvc = MockMvcBuilders.standaloneSetup(globalSearchController).build(); } @Test @@ -98,7 +98,7 @@ public void testGet_ItemInfo_BySearch_WithNoActiveEnvs_ReturnBadRequestAndTips() @Test public void testGet_ItemInfo_BySearch_WithKeyAndValueAndActiveEnvs_ReturnEmptyItemInfos() throws Exception { activeEnvs.add(Env.DEV); - when(globalSearchValueService.get_PerEnv_ItemInfo_BySearch(any(Env.class), anyString(), anyString(),eq(0),eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(new ArrayList<>(), PageRequest.of(0,1), 0L)); + when(globalSearchService.getPerEnvItemInfoBySearch(any(Env.class), anyString(), anyString(),eq(0),eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(new ArrayList<>(), PageRequest.of(0,1), 0L)); List allEnvMockItemInfos = new ArrayList<>(); ObjectMapper objectMapper = new ObjectMapper(); Map body = new HashMap<>(); @@ -112,7 +112,7 @@ public void testGet_ItemInfo_BySearch_WithKeyAndValueAndActiveEnvs_ReturnEmptyIt .andExpect(content().json(objectMapper.writeValueAsString(body))); verify(portalSettings,times(1)).getActiveEnvs(); verify(portalConfig,times(1)).getPerEnvSearchMaxResults(); - verify(globalSearchValueService,times(1)).get_PerEnv_ItemInfo_BySearch(any(Env.class), anyString(), anyString(),eq(0),eq(perEnvSearchMaxResults)); + verify(globalSearchService,times(1)).getPerEnvItemInfoBySearch(any(Env.class), anyString(), anyString(),eq(0),eq(perEnvSearchMaxResults)); } @Test @@ -124,8 +124,8 @@ public void testGet_ItemInfo_BySearch_WithKeyAndValueAndActiveEnvs_ReturnExpecte List allEnvMockItemInfos = new ArrayList<>(); devMockItemInfos.add(new ItemInfo("appid1","env1","cluster1","namespace1","query-key","query-value")); proMockItemInfos.add(new ItemInfo("appid2","env2","cluster2","namespace2","query-key","query-value")); - when(globalSearchValueService.get_PerEnv_ItemInfo_BySearch(eq(Env.DEV), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(devMockItemInfos, PageRequest.of(0,1), 201L)); - when(globalSearchValueService.get_PerEnv_ItemInfo_BySearch(eq(Env.PRO), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(proMockItemInfos, PageRequest.of(0,1), 201L)); + when(globalSearchService.getPerEnvItemInfoBySearch(eq(Env.DEV), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(devMockItemInfos, PageRequest.of(0,1), 201L)); + when(globalSearchService.getPerEnvItemInfoBySearch(eq(Env.PRO), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(proMockItemInfos, PageRequest.of(0,1), 201L)); allEnvMockItemInfos.addAll(devMockItemInfos); allEnvMockItemInfos.addAll(proMockItemInfos); ObjectMapper objectMapper = new ObjectMapper(); @@ -142,9 +142,9 @@ public void testGet_ItemInfo_BySearch_WithKeyAndValueAndActiveEnvs_ReturnExpecte .andExpect(content().json(objectMapper.writeValueAsString(body))); verify(portalSettings,times(1)).getActiveEnvs(); verify(portalConfig,times(5)).getPerEnvSearchMaxResults(); - verify(globalSearchValueService, times(1)).get_PerEnv_ItemInfo_BySearch(eq(Env.DEV), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); - verify(globalSearchValueService, times(1)).get_PerEnv_ItemInfo_BySearch(eq(Env.PRO), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); - verify(globalSearchValueService, times(2)).get_PerEnv_ItemInfo_BySearch(any(Env.class), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); + verify(globalSearchService, times(1)).getPerEnvItemInfoBySearch(eq(Env.DEV), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); + verify(globalSearchService, times(1)).getPerEnvItemInfoBySearch(eq(Env.PRO), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); + verify(globalSearchService, times(2)).getPerEnvItemInfoBySearch(any(Env.class), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); } @Test @@ -156,8 +156,8 @@ public void testGet_ItemInfo_BySearch_WithKeyAndValueAndActiveEnvs_ReturnExpecte List allEnvMockItemInfos = new ArrayList<>(); devMockItemInfos.add(new ItemInfo("appid1","env1","cluster1","namespace1","query-key","query-value")); proMockItemInfos.add(new ItemInfo("appid2","env2","cluster2","namespace2","query-key","query-value")); - when(globalSearchValueService.get_PerEnv_ItemInfo_BySearch(eq(Env.DEV), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(devMockItemInfos, PageRequest.of(0,1), 1L)); - when(globalSearchValueService.get_PerEnv_ItemInfo_BySearch(eq(Env.PRO), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(proMockItemInfos, PageRequest.of(0,1), 1L)); + when(globalSearchService.getPerEnvItemInfoBySearch(eq(Env.DEV), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(devMockItemInfos, PageRequest.of(0,1), 1L)); + when(globalSearchService.getPerEnvItemInfoBySearch(eq(Env.PRO), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(proMockItemInfos, PageRequest.of(0,1), 1L)); allEnvMockItemInfos.addAll(devMockItemInfos); allEnvMockItemInfos.addAll(proMockItemInfos); ObjectMapper objectMapper = new ObjectMapper(); @@ -171,8 +171,8 @@ public void testGet_ItemInfo_BySearch_WithKeyAndValueAndActiveEnvs_ReturnExpecte .andExpect(status().isOk()) .andExpect(content().json(objectMapper.writeValueAsString(body))); verify(portalSettings,times(1)).getActiveEnvs(); - verify(globalSearchValueService, times(1)).get_PerEnv_ItemInfo_BySearch(eq(Env.DEV), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); - verify(globalSearchValueService, times(1)).get_PerEnv_ItemInfo_BySearch(eq(Env.PRO), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); - verify(globalSearchValueService, times(2)).get_PerEnv_ItemInfo_BySearch(any(Env.class), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); + verify(globalSearchService, times(1)).getPerEnvItemInfoBySearch(eq(Env.DEV), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); + verify(globalSearchService, times(1)).getPerEnvItemInfoBySearch(eq(Env.PRO), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); + verify(globalSearchService, times(2)).getPerEnvItemInfoBySearch(any(Env.class), eq("query-key"), eq("query-value"),eq(0),eq(perEnvSearchMaxResults)); } } diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/GlobalSearchValueServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/GlobalSearchServiceTest.java similarity index 88% rename from apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/GlobalSearchValueServiceTest.java rename to apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/GlobalSearchServiceTest.java index d4544a7f695..ffafe9ba944 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/GlobalSearchValueServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/GlobalSearchServiceTest.java @@ -42,13 +42,13 @@ import static org.mockito.Mockito.verify; @RunWith(MockitoJUnitRunner.class) -public class GlobalSearchValueServiceTest { +public class GlobalSearchServiceTest { @Mock private AdminServiceAPI.ItemAPI itemAPI; @InjectMocks - private GlobalSearchValueService globalSearchValueService; + private GlobalSearchService globalSearchService; private final int perEnvSearchMaxResults = 200; @@ -58,7 +58,7 @@ public void testGet_PerEnv_ItemInfo_BySearch_withKeyAndValue_ReturnExpectedItemI List mockItemInfoDTOs = new ArrayList<>(); mockItemInfoDTOs.add(itemInfoDTO); Mockito.when(itemAPI.getPerEnvItemInfoBySearch(any(Env.class), eq("TestKey"), eq("TestValue"), eq(0), eq(perEnvSearchMaxResults))).thenReturn(new PageDTO<>(mockItemInfoDTOs, PageRequest.of(0, 1), 1L)); - PageDTO mockItemInfos = globalSearchValueService.get_PerEnv_ItemInfo_BySearch(Env.PRO, "TestKey", "TestValue", 0, 200); + PageDTO mockItemInfos = globalSearchService.getPerEnvItemInfoBySearch(Env.PRO, "TestKey", "TestValue", 0, 200); assertEquals(1, mockItemInfos.getContent().size()); ItemInfo itemInfo = new ItemInfo("TestApp", Env.PRO.getName(), "TestCluster", "TestNamespace", "TestKey", "TestValue"); List expectedResults = new ArrayList<>(); @@ -71,7 +71,7 @@ public void testGet_PerEnv_ItemInfo_BySearch_withKeyAndValue_ReturnExpectedItemI public void testGet_PerEnv_ItemInfo_withKeyAndValue_BySearch_ReturnEmptyItemInfos() { Mockito.when(itemAPI.getPerEnvItemInfoBySearch(any(Env.class), anyString(), anyString(), eq(0), eq(perEnvSearchMaxResults))) .thenReturn(new PageDTO<>(new ArrayList<>(), PageRequest.of(0, 1), 0L)); - PageDTO result = globalSearchValueService.get_PerEnv_ItemInfo_BySearch(Env.PRO, "NonExistentKey", "NonExistentValue", 0, 200); + PageDTO result = globalSearchService.getPerEnvItemInfoBySearch(Env.PRO, "NonExistentKey", "NonExistentValue", 0, 200); assertEquals(0, result.getContent().size()); }