Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
fix: check top api parameter when deleting top apis
Browse files Browse the repository at this point in the history
  • Loading branch information
aelamrani committed Mar 6, 2018
1 parent 5859e8c commit 3e39bb2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Expand Up @@ -98,9 +98,11 @@ public List<TopApiEntity> update(final List<UpdateTopApiEntity> topApis) {

@Override
public void delete(final String apiId) {
final List<TopApiEntity> topApis = findAll();
topApis.removeIf(topApiEntity -> apiId.equals(topApiEntity.getApi()));
parameterService.updateMultipleValue(PORTAL_TOP_APIS.getKey(),
topApis.stream().sorted(comparing(TopApiEntity::getOrder)).map(TopApiEntity::getApi).collect(toList()));
if (!parameterService.findAll(PORTAL_TOP_APIS.getKey()).isEmpty()) {
final List<TopApiEntity> topApis = findAll();
topApis.removeIf(topApiEntity -> apiId.equals(topApiEntity.getApi()));
parameterService.updateMultipleValue(PORTAL_TOP_APIS.getKey(),
topApis.stream().sorted(comparing(TopApiEntity::getOrder)).map(TopApiEntity::getApi).collect(toList()));
}
}
}
Expand Up @@ -139,6 +139,7 @@ public void shouldDelete() {
final ApiEntity api2 = new ApiEntity();
api2.setId("2");

when(parameterService.findAll(eq(PORTAL_TOP_APIS.getKey()))).thenReturn(asList("1", "2"));
when(parameterService.findAll(eq(PORTAL_TOP_APIS.getKey()), any(), any())).thenReturn(asList(api1, api2));

topApiService.delete("1");
Expand Down

0 comments on commit 3e39bb2

Please sign in to comment.