Skip to content

Commit

Permalink
Aiven acl deletion if not found on cluster (#1474)
Browse files Browse the repository at this point in the history
Acl deletion aiven 404

Signed-off-by: muralibasani <[email protected]>
Co-authored-by: muralibasani <[email protected]>
  • Loading branch information
muralibasani and muralibasani authored Jul 17, 2023
1 parent e8d0db9 commit 6ef760e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

Expand Down Expand Up @@ -254,6 +255,11 @@ public String deleteAcls(ClusterAclRequest clusterAclRequest) throws Exception {
restTemplate.exchange(uri, HttpMethod.DELETE, request, Object.class);
} catch (Exception e) {
log.error("Exception:", e);
if (e instanceof HttpClientErrorException) {
if (((HttpClientErrorException) e).getStatusCode() == HttpStatus.NOT_FOUND) {
return ApiResultStatus.SUCCESS.value;
}
}
throw new Exception("Error in deleting acls " + e.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

Expand Down Expand Up @@ -334,4 +335,29 @@ public void deleteAclsTestFailure() throws Exception {
exception.isInstanceOf(Exception.class);
exception.hasMessage("Error in deleting acls ");
}

@Test
public void deleteAclsTestFailure404() throws Exception {
ClusterAclRequest clusterAclRequest =
ClusterAclRequest.builder()
.aivenAclKey("4322342")
.projectName("testproject")
.serviceName("serviceName")
.build();
String aclsUrl =
ACLS_BASE_URL
+ clusterAclRequest.getProjectName()
+ "/service/"
+ clusterAclRequest.getServiceName()
+ "/acl/"
+ clusterAclRequest.getAivenAclKey();
when(restTemplate.exchange(
eq(aclsUrl), eq(HttpMethod.DELETE), any(HttpEntity.class), any(Class.class)))
.thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));

String actual = aivenApiService.deleteAcls(clusterAclRequest);
String expected = ApiResultStatus.SUCCESS.value;

assertThat(actual).isEqualTo(expected);
}
}

0 comments on commit 6ef760e

Please sign in to comment.