Skip to content

Commit

Permalink
fix e2e checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
‘xcsnx’ committed Jul 2, 2024
1 parent 7b31e76 commit 660c096
Showing 1 changed file with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public List<RuleDTO> listAllRules() {

/**
* all meta data list.
*
* @return List
*/
public List<MetaDataDTO> listAllMetaData() {
Expand Down Expand Up @@ -231,6 +232,7 @@ private <T extends ResourceDTO, OUT> List<OUT> getMetaDataList(final String uri,

/**
* Fetch the selectors by the given conditions.
*
* @param keyword expected selectors included the word. return all if absent.
* @param plugins expected selectors under specified plugins. return all if absent.
* @return paginated info with list of {@link SelectorDTO}s
Expand All @@ -246,10 +248,11 @@ public SearchedResources<SelectorDTO> searchSelectors(final String keyword, fina

/**
* Fetch the selectors by the given conditions.
* @param keyword expected selectors included the word. return all if absent.
* @param page page.
*
* @param keyword expected selectors included the word. return all if absent.
* @param page page.
* @param pageSize size.
* @param plugins expected selectors under specified plugins. return all if absent.
* @param plugins expected selectors under specified plugins. return all if absent.
* @return paginated info with list of {@link SelectorDTO}s
*/
public SearchedResources<SelectorDTO> searchSelectors(final String keyword, final int page, final int pageSize, final String... plugins) {
Expand Down Expand Up @@ -284,18 +287,18 @@ private <T extends ResourceDTO> SearchedResources<T> search(final String uri, fi
private <T extends ResourceDTO> SearchedResources<T> search(final String uri, final int pageNum, final int pageSize,
final QueryCondition condition, final TypeReference<SearchedResources<T>> valueType) {
SearchCondition searchCondition = SearchCondition.builder()
.pageNum(pageNum)
.pageSize(pageSize)
.condition(condition)
.build();
.pageNum(pageNum)
.pageSize(pageSize)
.condition(condition)
.build();

HttpEntity<SearchCondition> entity = new HttpEntity<>(searchCondition, basicAuth);
ResponseEntity<ShenYuResult> response = template.postForEntity(baseURL + uri, entity, ShenYuResult.class);
ShenYuResult rst = assertAndGet(response, "query success");

return Assertions.assertDoesNotThrow(
() -> mapper.readValue(rst.getData().traverse(), valueType),
"checking cast to SearchedResources<T>"
"checking cast to SearchedResources<T>"
);
}

Expand All @@ -304,12 +307,13 @@ private <T extends ResourceDTO> List<T> getSearch(final String uri, final TypeRe
ShenYuResult rst = assertAndGet(response, "query success");
return Assertions.assertDoesNotThrow(
() -> mapper.readValue(rst.getData().traverse(), valueType),
"checking cast to SearchedResources<T>"
"checking cast to SearchedResources<T>"
);
}

/**
* create selectorDTO.
*
* @param selector selector
* @return SelectorDTO
*/
Expand All @@ -321,6 +325,7 @@ public SelectorDTO create(final SelectorData selector) {

/**
* Create Rule.
*
* @param rule rule
* @return RuleDTO
*/
Expand All @@ -333,18 +338,18 @@ public RuleDTO create(final RuleData rule) {
@SuppressWarnings("unchecked")
private <T extends ResourceData, R extends ResourceDTO> R create(final String uri, final T data) {
log.info("trying to create resource({}) name: {}", data.getClass().getSimpleName(), data.getName());

data.setName(NameUtils.wrap(data.getName(), scenarioId));

HttpEntity<T> entity = new HttpEntity<>(data, basicAuth);
ResponseEntity<ShenYuResult> response = template.postForEntity(baseURL + uri, entity, ShenYuResult.class);
Assertions.assertEquals(HttpStatus.OK, response.getStatusCode(), "status code");

ShenYuResult rst = response.getBody();
Assertions.assertNotNull(rst, "checking http response body");
Assertions.assertEquals(200, rst.getCode(), "checking shenyu result code");
Assertions.assertEquals("create success", rst.getMessage(), "checking shenyu result message");

SearchedResources<?> searchedResources = null;
if (data instanceof SelectorData) {
searchedResources = searchSelectors(data.getName());
Expand All @@ -353,24 +358,25 @@ private <T extends ResourceData, R extends ResourceDTO> R create(final String ur
}
Assertions.assertNotNull(searchedResources, "checking searchedResources object is non-null");
Assertions.assertEquals(1, searchedResources.getTotal(), "checking the total hits of searching");

ResourceDTO created = searchedResources.getList().get(0);
Assertions.assertNotNull(created, "checking created object is non-null");
log.info("create resource({}) successful. name: {}, id: {}", data.getClass().getSimpleName(), data.getName(), created.getId());

return (R) created;
}

/**
* bindingData.
*
* @param bindingData bindingData
*/
public void bindingData(final BindingData bindingData) {
HttpEntity<BindingData> entity = new HttpEntity<>(bindingData, basicAuth);
ResponseEntity<ShenYuResult> response = template.postForEntity(baseURL + "/proxy-selector/binding", entity, ShenYuResult.class);
Assertions.assertEquals(HttpStatus.OK, response.getStatusCode(), "status code");
}

/**
* Delete selectors in batch.
*
Expand Down Expand Up @@ -443,6 +449,7 @@ private void delete(final String uri, final List<String> ids) {

/**
* Fetch Selector by given id.
*
* @param id of selector that needs to fetch
* @return {@link SelectorDTO}
*/
Expand Down Expand Up @@ -481,7 +488,7 @@ private ShenYuResult assertAndGet(final ResponseEntity<ShenYuResult> response, f
/**
* change plugin status.
*
* @param id id
* @param id id
* @param formData formData
*/
public void changePluginStatus(final String id, final MultiValueMap<String, String> formData) {
Expand All @@ -490,7 +497,8 @@ public void changePluginStatus(final String id, final MultiValueMap<String, Stri

private <T extends ResourceDTO> T putResource(final String uri, final String id, final Class<T> valueType, final MultiValueMap<String, String> formData) {
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(formData, basicAuth);
ResponseEntity<ShenYuResult> response = template.exchange(baseURL + uri + "/pluginId=" + id + "&namespaceId=" + SYS_DEFAULT_NAMESPACE_NAMESPACE_ID , HttpMethod.PUT, requestEntity, ShenYuResult.class);
ResponseEntity<ShenYuResult> response = template.exchange(baseURL + uri + "/pluginId=" + id
+ "&namespaceId=" + SYS_DEFAULT_NAMESPACE_NAMESPACE_ID, HttpMethod.PUT, requestEntity, ShenYuResult.class);
Assertions.assertEquals(HttpStatus.OK, response.getStatusCode(), "checking http status");
ShenYuResult rst = response.getBody();
Assertions.assertNotNull(rst, "checking http response body");
Expand All @@ -500,7 +508,7 @@ private <T extends ResourceDTO> T putResource(final String uri, final String id,
/**
* change plugin status.
*
* @param id id
* @param id id
* @param selectorData selectorData
*/
public void changeSelector(final String id, final SelectorData selectorData) {
Expand Down

0 comments on commit 660c096

Please sign in to comment.