Skip to content

Commit

Permalink
[ISSUE alibaba#12017] Add unit tests for the config section
Browse files Browse the repository at this point in the history
* Add unit tests for the config section

* Update uri of query method
  • Loading branch information
RickonZhang0929 committed Aug 21, 2024
1 parent e3a03eb commit a201da9
Show file tree
Hide file tree
Showing 3 changed files with 515 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.model.v2.Result;
import com.alibaba.nacos.auth.annotation.Secured;
import com.alibaba.nacos.auth.enums.ApiType;
import com.alibaba.nacos.plugin.auth.constant.ApiType;
import com.alibaba.nacos.common.utils.NamespaceUtil;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.constant.Constants;
Expand Down Expand Up @@ -76,44 +76,6 @@ public ConsoleConfigController(ConfigProxy configProxy) {

}

/**
* Get configure information list.
*
* @param dataId Data ID string value.
* @param group Group string value.
* @param namespaceId Namespace string value.
* @param configTags Configuration tags.
* @param appName Application name string value.
* @param pageNo Page number.
* @param pageSize Page size.
* @return Result containing the configuration information.
* @throws ServletException If a servlet-specific error occurs.
* @throws IOException If an I/O error occurs.
* @throws NacosException If a Nacos-specific error occurs.
*/
@GetMapping
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG, apiType = ApiType.CONSOLE_API)
public Result<Page<ConfigInfo>> getConfigList(@RequestParam("dataId") String dataId,
@RequestParam("group") String group,
@RequestParam(value = "namespaceId", required = false, defaultValue = StringUtils.EMPTY) String namespaceId,
@RequestParam(value = "config_tags", required = false) String configTags,
@RequestParam(value = "appName", required = false) String appName, @RequestParam("pageNo") int pageNo,
@RequestParam("pageSize") int pageSize) throws IOException, ServletException, NacosException {
// check tenant
ParamUtils.checkTenant(namespaceId);
namespaceId = NamespaceUtil.processNamespaceParameter(namespaceId);
Map<String, Object> configAdvanceInfo = new HashMap<>(100);
if (StringUtils.isNotBlank(appName)) {
configAdvanceInfo.put("appName", appName);
}
if (StringUtils.isNotBlank(configTags)) {
configAdvanceInfo.put("config_tags", configTags);
}

return Result.success(
configProxy.getConfigList(pageNo, pageSize, dataId, group, namespaceId, configAdvanceInfo));
}

/**
* Get the specific configuration information.
*
Expand All @@ -123,7 +85,7 @@ public Result<Page<ConfigInfo>> getConfigList(@RequestParam("dataId") String dat
* @return Result containing detailed configuration information.
* @throws NacosException If a Nacos-specific error occurs.
*/
@GetMapping("/detail")
@GetMapping
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG, apiType = ApiType.CONSOLE_API)
public Result<ConfigAllInfo> getConfigDetail(@RequestParam("dataId") String dataId,
@RequestParam("group") String group,
Expand Down Expand Up @@ -223,6 +185,44 @@ public Result<Boolean> batchDeleteConfigs(HttpServletRequest request, @RequestPa
return Result.success(configProxy.batchDeleteConfigs(ids, clientIp, srcUser));
}

/**
* Get configure information list.
*
* @param dataId Data ID string value.
* @param group Group string value.
* @param namespaceId Namespace string value.
* @param configTags Configuration tags.
* @param appName Application name string value.
* @param pageNo Page number.
* @param pageSize Page size.
* @return Result containing the configuration information.
* @throws ServletException If a servlet-specific error occurs.
* @throws IOException If an I/O error occurs.
* @throws NacosException If a Nacos-specific error occurs.
*/
@GetMapping("/list")
@Secured(action = ActionTypes.READ, signType = SignType.CONFIG, apiType = ApiType.CONSOLE_API)
public Result<Page<ConfigInfo>> getConfigList(@RequestParam("dataId") String dataId,
@RequestParam("group") String group,
@RequestParam(value = "namespaceId", required = false, defaultValue = StringUtils.EMPTY) String namespaceId,
@RequestParam(value = "config_tags", required = false) String configTags,
@RequestParam(value = "appName", required = false) String appName, @RequestParam("pageNo") int pageNo,
@RequestParam("pageSize") int pageSize) throws IOException, ServletException, NacosException {
// check tenant
ParamUtils.checkTenant(namespaceId);
namespaceId = NamespaceUtil.processNamespaceParameter(namespaceId);
Map<String, Object> configAdvanceInfo = new HashMap<>(100);
if (StringUtils.isNotBlank(appName)) {
configAdvanceInfo.put("appName", appName);
}
if (StringUtils.isNotBlank(configTags)) {
configAdvanceInfo.put("config_tags", configTags);
}

return Result.success(
configProxy.getConfigList(pageNo, pageSize, dataId, group, namespaceId, configAdvanceInfo));
}

/**
* Search config list by config detail.
*
Expand Down
Loading

0 comments on commit a201da9

Please sign in to comment.