From 021146adc4bb249ce4060366aa76c06dcb8bfba3 Mon Sep 17 00:00:00 2001 From: Max Inno Date: Fri, 11 Sep 2026 23:17:17 +0300 Subject: [PATCH] feat: add support for asynchronous branch, directory and file deletion Delete endpoints for branches, directories and files now accept an optional Prefer: respond-async header, returning a delete job status that can be polled via new checkBranchDeletionStatus, checkDirectoryDeletionStatus and checkFileDeletionStatus methods. --- .../crowdin/client/branches/BranchesApi.java | 60 ++++++++ .../client/core/model/DeleteJobStatus.java | 33 +++++ .../model/DeleteJobStatusResponseObject.java | 9 ++ .../client/sourcefiles/SourceFilesApi.java | 139 +++++++++++++++++- .../client/branches/BranchesApiTest.java | 27 ++++ .../crowdin/client/framework/RequestMock.java | 11 ++ .../client/framework/TestHttpClient.java | 6 +- .../sourcefiles/SourceFilesApiTest.java | 57 +++++++ .../api/branches/deleteJobStatus.json | 14 ++ .../sourcefiles/branchDeleteJobStatus.json | 14 ++ .../sourcefiles/directoryDeleteJobStatus.json | 14 ++ .../api/sourcefiles/fileDeleteJobStatus.json | 17 +++ 12 files changed, 395 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/crowdin/client/core/model/DeleteJobStatus.java create mode 100644 src/main/java/com/crowdin/client/core/model/DeleteJobStatusResponseObject.java create mode 100644 src/test/resources/api/branches/deleteJobStatus.json create mode 100644 src/test/resources/api/sourcefiles/branchDeleteJobStatus.json create mode 100644 src/test/resources/api/sourcefiles/directoryDeleteJobStatus.json create mode 100644 src/test/resources/api/sourcefiles/fileDeleteJobStatus.json diff --git a/src/main/java/com/crowdin/client/branches/BranchesApi.java b/src/main/java/com/crowdin/client/branches/BranchesApi.java index c2259ea74..a51d967ed 100644 --- a/src/main/java/com/crowdin/client/branches/BranchesApi.java +++ b/src/main/java/com/crowdin/client/branches/BranchesApi.java @@ -7,8 +7,12 @@ import com.crowdin.client.core.http.exceptions.HttpException; import com.crowdin.client.core.model.ClientConfig; import com.crowdin.client.core.model.Credentials; +import com.crowdin.client.core.model.DeleteJobStatus; +import com.crowdin.client.core.model.DeleteJobStatusResponseObject; import com.crowdin.client.core.model.ResponseObject; +import java.util.Collections; + public class BranchesApi extends CrowdinApi { public BranchesApi(Credentials credentials) { @@ -19,6 +23,62 @@ public BranchesApi(Credentials credentials, ClientConfig clientConfig) { super(credentials, clientConfig); } + /** + * @param projectId project identifier + * @param branchId branch identifier + * @see + */ + public void deleteBranch(Long projectId, Long branchId) throws HttpException, HttpBadRequestException { + this.deleteBranch(projectId, branchId, null); + } + + /** + * @param projectId project identifier + * @param branchId branch identifier + * @param isAsync whether to delete the branch asynchronously + * @return delete job status when deleting asynchronously, or {@code null} for a synchronous deletion + * @see + */ + public ResponseObject deleteBranch(Long projectId, Long branchId, Boolean isAsync) throws HttpException, HttpBadRequestException { + String url = this.url + "/projects/" + projectId + "/branches/" + branchId; + if (!Boolean.TRUE.equals(isAsync)) { + this.httpClient.delete(url, new HttpRequestConfig(), Void.class); + return null; + } + + DeleteJobStatusResponseObject response = this.httpClient.delete( + url, + new HttpRequestConfig(Collections.emptyMap(), Collections.singletonMap("Prefer", "respond-async")), + DeleteJobStatusResponseObject.class + ); + return ResponseObject.of(response.getData()); + } + + /** + * @param projectId project identifier + * @param branchId branch identifier + * @param jobIdentifier delete job identifier + * @return delete job status + * @see + */ + public ResponseObject checkBranchDeletionStatus(Long projectId, Long branchId, String jobIdentifier) throws HttpException, HttpBadRequestException { + DeleteJobStatusResponseObject response = this.httpClient.get( + this.url + "/projects/" + projectId + "/branches/" + branchId + "/jobs/" + jobIdentifier, + new HttpRequestConfig(), + DeleteJobStatusResponseObject.class + ); + return ResponseObject.of(response.getData()); + } + /** * @param projectId project identifier * @param branchId branch identifier diff --git a/src/main/java/com/crowdin/client/core/model/DeleteJobStatus.java b/src/main/java/com/crowdin/client/core/model/DeleteJobStatus.java new file mode 100644 index 000000000..aa59b0a85 --- /dev/null +++ b/src/main/java/com/crowdin/client/core/model/DeleteJobStatus.java @@ -0,0 +1,33 @@ +package com.crowdin.client.core.model; + +import lombok.Data; + +import java.util.Date; + +@Data +public class DeleteJobStatus { + + private String identifier; + private String status; + private Integer progress; + private Attributes attributes; + private Date createdAt; + private Date updatedAt; + private Date startedAt; + private Date finishedAt; + private Error error; + + @Data + public static class Attributes { + + private Long branchId; + private Long directoryId; + private Long fileId; + } + + @Data + public static class Error { + + private String message; + } +} diff --git a/src/main/java/com/crowdin/client/core/model/DeleteJobStatusResponseObject.java b/src/main/java/com/crowdin/client/core/model/DeleteJobStatusResponseObject.java new file mode 100644 index 000000000..e7a5f95bf --- /dev/null +++ b/src/main/java/com/crowdin/client/core/model/DeleteJobStatusResponseObject.java @@ -0,0 +1,9 @@ +package com.crowdin.client.core.model; + +import lombok.Data; + +@Data +public class DeleteJobStatusResponseObject { + + private DeleteJobStatus data; +} diff --git a/src/main/java/com/crowdin/client/sourcefiles/SourceFilesApi.java b/src/main/java/com/crowdin/client/sourcefiles/SourceFilesApi.java index 20f6c38b4..c53dd69d4 100644 --- a/src/main/java/com/crowdin/client/sourcefiles/SourceFilesApi.java +++ b/src/main/java/com/crowdin/client/sourcefiles/SourceFilesApi.java @@ -7,6 +7,7 @@ import com.crowdin.client.core.model.*; import com.crowdin.client.sourcefiles.model.*; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -101,7 +102,51 @@ public ResponseObject getBranch(Long projectId, Long branchId) throws Ht * */ public void deleteBranch(Long projectId, Long branchId) throws HttpException, HttpBadRequestException { - this.httpClient.delete(this.url + "/projects/" + projectId + "/branches/" + branchId, new HttpRequestConfig(), Void.class); + this.deleteBranch(projectId, branchId, null); + } + + /** + * @param projectId project identifier + * @param branchId branch identifier + * @param isAsync whether to delete the branch asynchronously + * @return delete job status when deleting asynchronously, or {@code null} for a synchronous deletion + * @see + */ + public ResponseObject deleteBranch(Long projectId, Long branchId, Boolean isAsync) throws HttpException, HttpBadRequestException { + String url = this.url + "/projects/" + projectId + "/branches/" + branchId; + if (!Boolean.TRUE.equals(isAsync)) { + this.httpClient.delete(url, new HttpRequestConfig(), Void.class); + return null; + } + + DeleteJobStatusResponseObject response = this.httpClient.delete( + url, + new HttpRequestConfig(Collections.emptyMap(), Collections.singletonMap("Prefer", "respond-async")), + DeleteJobStatusResponseObject.class + ); + return ResponseObject.of(response.getData()); + } + + /** + * @param projectId project identifier + * @param branchId branch identifier + * @param jobIdentifier delete job identifier + * @return delete job status + * @see + */ + public ResponseObject checkBranchDeletionStatus(Long projectId, Long branchId, String jobIdentifier) throws HttpException, HttpBadRequestException { + DeleteJobStatusResponseObject response = this.httpClient.get( + this.url + "/projects/" + projectId + "/branches/" + branchId + "/jobs/" + jobIdentifier, + new HttpRequestConfig(), + DeleteJobStatusResponseObject.class + ); + return ResponseObject.of(response.getData()); } /** @@ -237,7 +282,51 @@ public ResponseObject getDirectory(Long projectId, Long directoryId) * */ public void deleteDirectory(Long projectId, Long directoryId) throws HttpException, HttpBadRequestException { - this.httpClient.delete(this.url + "/projects/" + projectId + "/directories/" + directoryId, new HttpRequestConfig(), Void.class); + this.deleteDirectory(projectId, directoryId, null); + } + + /** + * @param projectId project identifier + * @param directoryId directory identifier + * @param isAsync whether to delete the directory asynchronously + * @return delete job status when deleting asynchronously, or {@code null} for a synchronous deletion + * @see + */ + public ResponseObject deleteDirectory(Long projectId, Long directoryId, Boolean isAsync) throws HttpException, HttpBadRequestException { + String url = this.url + "/projects/" + projectId + "/directories/" + directoryId; + if (!Boolean.TRUE.equals(isAsync)) { + this.httpClient.delete(url, new HttpRequestConfig(), Void.class); + return null; + } + + DeleteJobStatusResponseObject response = this.httpClient.delete( + url, + new HttpRequestConfig(Collections.emptyMap(), Collections.singletonMap("Prefer", "respond-async")), + DeleteJobStatusResponseObject.class + ); + return ResponseObject.of(response.getData()); + } + + /** + * @param projectId project identifier + * @param directoryId directory identifier + * @param jobIdentifier delete job identifier + * @return delete job status + * @see + */ + public ResponseObject checkDirectoryDeletionStatus(Long projectId, Long directoryId, String jobIdentifier) throws HttpException, HttpBadRequestException { + DeleteJobStatusResponseObject response = this.httpClient.get( + this.url + "/projects/" + projectId + "/directories/" + directoryId + "/jobs/" + jobIdentifier, + new HttpRequestConfig(), + DeleteJobStatusResponseObject.class + ); + return ResponseObject.of(response.getData()); } /** @@ -388,7 +477,51 @@ public ResponseObject updateOrRestoreFile(Long projectId, Lo * */ public void deleteFile(Long projectId, Long fileId) throws HttpException, HttpBadRequestException { - this.httpClient.delete(this.url + "/projects/" + projectId + "/files/" + fileId, new HttpRequestConfig(), Void.class); + this.deleteFile(projectId, fileId, null); + } + + /** + * @param projectId project identifier + * @param fileId file identifier + * @param isAsync whether to delete the file asynchronously + * @return delete job status when deleting asynchronously, or {@code null} for a synchronous deletion + * @see + */ + public ResponseObject deleteFile(Long projectId, Long fileId, Boolean isAsync) throws HttpException, HttpBadRequestException { + String url = this.url + "/projects/" + projectId + "/files/" + fileId; + if (!Boolean.TRUE.equals(isAsync)) { + this.httpClient.delete(url, new HttpRequestConfig(), Void.class); + return null; + } + + DeleteJobStatusResponseObject response = this.httpClient.delete( + url, + new HttpRequestConfig(Collections.emptyMap(), Collections.singletonMap("Prefer", "respond-async")), + DeleteJobStatusResponseObject.class + ); + return ResponseObject.of(response.getData()); + } + + /** + * @param projectId project identifier + * @param fileId file identifier + * @param jobIdentifier delete job identifier + * @return delete job status + * @see + */ + public ResponseObject checkFileDeletionStatus(Long projectId, Long fileId, String jobIdentifier) throws HttpException, HttpBadRequestException { + DeleteJobStatusResponseObject response = this.httpClient.get( + this.url + "/projects/" + projectId + "/files/" + fileId + "/jobs/" + jobIdentifier, + new HttpRequestConfig(), + DeleteJobStatusResponseObject.class + ); + return ResponseObject.of(response.getData()); } /** diff --git a/src/test/java/com/crowdin/client/branches/BranchesApiTest.java b/src/test/java/com/crowdin/client/branches/BranchesApiTest.java index a195487a2..52f110b86 100644 --- a/src/test/java/com/crowdin/client/branches/BranchesApiTest.java +++ b/src/test/java/com/crowdin/client/branches/BranchesApiTest.java @@ -1,14 +1,17 @@ package com.crowdin.client.branches; import com.crowdin.client.branches.model.*; +import com.crowdin.client.core.model.DeleteJobStatus; import com.crowdin.client.core.model.ResponseObject; import com.crowdin.client.framework.RequestMock; import com.crowdin.client.framework.TestClient; +import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.junit.jupiter.api.Test; import java.util.Arrays; +import java.util.Collections; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -21,12 +24,16 @@ class BranchesApiTest extends TestClient { private final Long sourceBranchId = 8L; private final String cloneId = "aaee1685-c92a-4da6-8a08-c28b4db5cd4a"; private final String mergeId = "50fb3506-4127-4ba8-8296-f97dc7e3e0c3"; + private final String deleteJobIdentifier = "50fb3506-4127-4ba8-8296-f97dc7e3e0c3"; private final String name = "cloned"; private final String title = "Cloned Branch"; @Override public List getMocks() { return Arrays.asList( + RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + id, HttpDelete.METHOD_NAME), + RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + id, HttpDelete.METHOD_NAME, "api/branches/deleteJobStatus.json", Collections.emptyMap(), Collections.singletonMap("Prefer", "respond-async")), + RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + id + "/jobs/" + deleteJobIdentifier, HttpGet.METHOD_NAME, "api/branches/deleteJobStatus.json"), RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + id + "/clones", HttpPost.METHOD_NAME, "api/branches/cloneBranchRequest.json", "api/branches/branchCloneStatus.json"), RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + id + "/clones/" + cloneId, HttpGet.METHOD_NAME, "api/branches/branchCloneStatus.json"), RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + id + "/merges", HttpPost.METHOD_NAME, "api/branches/mergeBranchRequest.json", "api/branches/branchMergeStatus.json"), @@ -51,6 +58,26 @@ public void checkCloneBranchStatusTest() { assertEquals(response.getData().getIdentifier(), cloneId); } + @Test + public void deleteBranchTest() { + this.getBranchesApi().deleteBranch(projectId, id); + } + + @Test + public void deleteBranchAsyncTest() { + ResponseObject response = this.getBranchesApi().deleteBranch(projectId, id, true); + assertEquals(deleteJobIdentifier, response.getData().getIdentifier()); + assertEquals("created", response.getData().getStatus()); + assertEquals(id, response.getData().getAttributes().getBranchId()); + } + + @Test + public void checkBranchDeletionStatusTest() { + ResponseObject response = this.getBranchesApi().checkBranchDeletionStatus(projectId, id, deleteJobIdentifier); + assertEquals(deleteJobIdentifier, response.getData().getIdentifier()); + assertEquals(id, response.getData().getAttributes().getBranchId()); + } + @Test public void mergeBranchTest() { MergeBranchRequest request = new MergeBranchRequest(); diff --git a/src/test/java/com/crowdin/client/framework/RequestMock.java b/src/test/java/com/crowdin/client/framework/RequestMock.java index 036e1f5ab..2109a283c 100644 --- a/src/test/java/com/crowdin/client/framework/RequestMock.java +++ b/src/test/java/com/crowdin/client/framework/RequestMock.java @@ -41,6 +41,17 @@ public static RequestMock build(String url, String httpMethod, String responseFi ); } + public static RequestMock build(String url, String httpMethod, String responseFile, Map urlParams, Map headers) { + return new RequestMock( + url, + null, + responseFile, + httpMethod, + urlParams, + headers + ); + } + public static RequestMock build(String url, String httpMethod, String responseFile) { return new RequestMock( url, diff --git a/src/test/java/com/crowdin/client/framework/TestHttpClient.java b/src/test/java/com/crowdin/client/framework/TestHttpClient.java index 84a774ab2..91a91645a 100644 --- a/src/test/java/com/crowdin/client/framework/TestHttpClient.java +++ b/src/test/java/com/crowdin/client/framework/TestHttpClient.java @@ -80,13 +80,13 @@ private T request(String url, for (int i = 0; i < requestMocks.size(); ++i) { RequestMock requestMock = requestMocks.get(i); if (!config.getHeaders().equals(requestMock.getHeaders())) { - throw new AssertionError("No match for request headers : " + requestKey); + continue; } Map urlParams = config.getUrlParams().entrySet().stream() .filter(entry -> entry.getValue().isPresent()) .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get())); if (!urlParams.equals(requestMock.getUrlParams())) { - throw new AssertionError("No match for url query parameters : " + requestKey); + continue; } //request @@ -132,10 +132,10 @@ private T request(String url, } return this.jsonTransformer.parse(responsePayloadMock, clazz); } + throw new AssertionError("No match for request : " + requestKey); } catch (Exception e) { throw new AssertionError("Failed to execute test", e); } - return null; } private String getRequestKey(String url, String httpMethod) { diff --git a/src/test/java/com/crowdin/client/sourcefiles/SourceFilesApiTest.java b/src/test/java/com/crowdin/client/sourcefiles/SourceFilesApiTest.java index 681f051ff..dab3df5a3 100644 --- a/src/test/java/com/crowdin/client/sourcefiles/SourceFilesApiTest.java +++ b/src/test/java/com/crowdin/client/sourcefiles/SourceFilesApiTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.Test; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,6 +41,9 @@ public class SourceFilesApiTest extends TestClient { private final Long referenceId = 123L; private final Long fileRevisionId = 2L; private final Long buildId = 42L; + private final String branchDeleteJobIdentifier = "branch-delete-job"; + private final String directoryDeleteJobIdentifier = "directory-delete-job"; + private final String fileDeleteJobIdentifier = "file-delete-job"; private final String branchName = "develop-master"; private final String branchTitle = "Master branch"; private final String sequentBranchName1 = "develop-master-#1"; @@ -72,6 +76,8 @@ public List getMocks() { RequestMock.build(this.url + "/projects/" + projectId + "/branches", HttpPost.METHOD_NAME, "api/sourcefiles/addBranchRequest.json", "api/sourcefiles/branch.json"), RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + branchId, HttpGet.METHOD_NAME, "api/sourcefiles/branch.json"), RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + branchId, HttpDelete.METHOD_NAME), + RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + branchId, HttpDelete.METHOD_NAME, "api/sourcefiles/branchDeleteJobStatus.json", Collections.emptyMap(), Collections.singletonMap("Prefer", "respond-async")), + RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + branchId + "/jobs/" + branchDeleteJobIdentifier, HttpGet.METHOD_NAME, "api/sourcefiles/branchDeleteJobStatus.json"), RequestMock.build(this.url + "/projects/" + projectId + "/branches/" + branchId, HttpPatch.METHOD_NAME, "api/sourcefiles/editBranch.json", "api/sourcefiles/branch.json"), RequestMock.build(this.url + "/branches", HttpGet.METHOD_NAME, "api/sourcefiles/searchBranches.json", new HashMap() {{ put("filter", branchName); @@ -87,6 +93,8 @@ public List getMocks() { RequestMock.build(this.url + "/projects/" + projectId + "/directories", HttpPost.METHOD_NAME, "api/sourcefiles/addDirectoryRequest.json", "api/sourcefiles/directory.json"), RequestMock.build(this.url + "/projects/" + projectId + "/directories/" + directoryId, HttpGet.METHOD_NAME, "api/sourcefiles/directory.json"), RequestMock.build(this.url + "/projects/" + projectId + "/directories/" + directoryId, HttpDelete.METHOD_NAME), + RequestMock.build(this.url + "/projects/" + projectId + "/directories/" + directoryId, HttpDelete.METHOD_NAME, "api/sourcefiles/directoryDeleteJobStatus.json", Collections.emptyMap(), Collections.singletonMap("Prefer", "respond-async")), + RequestMock.build(this.url + "/projects/" + projectId + "/directories/" + directoryId + "/jobs/" + directoryDeleteJobIdentifier, HttpGet.METHOD_NAME, "api/sourcefiles/directoryDeleteJobStatus.json"), RequestMock.build(this.url + "/projects/" + projectId + "/directories/" + directoryId, HttpPatch.METHOD_NAME, "api/sourcefiles/editDirectory.json", "api/sourcefiles/directory.json"), RequestMock.build(this.url + "/directories", HttpGet.METHOD_NAME, "api/sourcefiles/searchDirectories.json", new HashMap() {{ put("filter", directoryName); @@ -104,6 +112,8 @@ public List getMocks() { RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId, HttpGet.METHOD_NAME, "api/sourcefiles/file.json"), RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId, HttpPut.METHOD_NAME, "api/sourcefiles/updateOrRestoreFileRequest.json", "api/sourcefiles/file.json"), RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId, HttpDelete.METHOD_NAME), + RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId, HttpDelete.METHOD_NAME, "api/sourcefiles/fileDeleteJobStatus.json", Collections.emptyMap(), Collections.singletonMap("Prefer", "respond-async")), + RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId + "/jobs/" + fileDeleteJobIdentifier, HttpGet.METHOD_NAME, "api/sourcefiles/fileDeleteJobStatus.json"), RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId, HttpPatch.METHOD_NAME, "api/sourcefiles/editFile.json", "api/sourcefiles/file.json"), RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId + "/download", HttpGet.METHOD_NAME, "api/sourcefiles/downloadLink.json"), RequestMock.build(this.url + "/projects/" + projectId + "/files/" + fileId + "/preview", HttpGet.METHOD_NAME, "api/sourcefiles/downloadLink.json"), @@ -211,6 +221,21 @@ public void deleteBranchTest() { this.getSourceFilesApi().deleteBranch(projectId, branchId); } + @Test + public void deleteBranchAsyncTest() { + ResponseObject response = this.getSourceFilesApi().deleteBranch(projectId, branchId, true); + assertEquals(branchDeleteJobIdentifier, response.getData().getIdentifier()); + assertEquals("finished", response.getData().getStatus()); + assertEquals(branchId, response.getData().getAttributes().getBranchId()); + } + + @Test + public void checkBranchDeletionStatusTest() { + ResponseObject response = this.getSourceFilesApi().checkBranchDeletionStatus(projectId, branchId, branchDeleteJobIdentifier); + assertEquals(branchDeleteJobIdentifier, response.getData().getIdentifier()); + assertEquals(branchId, response.getData().getAttributes().getBranchId()); + } + @Test public void editBranchTest() { PatchRequest request = new PatchRequest(); @@ -359,6 +384,21 @@ public void deleteDirectoryTest() { this.getSourceFilesApi().deleteDirectory(projectId, directoryId); } + @Test + public void deleteDirectoryAsyncTest() { + ResponseObject response = this.getSourceFilesApi().deleteDirectory(projectId, directoryId, true); + assertEquals(directoryDeleteJobIdentifier, response.getData().getIdentifier()); + assertEquals("in_progress", response.getData().getStatus()); + assertEquals(directoryId, response.getData().getAttributes().getDirectoryId()); + } + + @Test + public void checkDirectoryDeletionStatusTest() { + ResponseObject response = this.getSourceFilesApi().checkDirectoryDeletionStatus(projectId, directoryId, directoryDeleteJobIdentifier); + assertEquals(directoryDeleteJobIdentifier, response.getData().getIdentifier()); + assertEquals(directoryId, response.getData().getAttributes().getDirectoryId()); + } + @Test public void editDirectoryTest() { PatchRequest request = new PatchRequest(); @@ -517,6 +557,23 @@ public void deleteFileTest() { this.getSourceFilesApi().deleteFile(projectId, fileId); } + @Test + public void deleteFileAsyncTest() { + ResponseObject response = this.getSourceFilesApi().deleteFile(projectId, fileId, true); + assertEquals(fileDeleteJobIdentifier, response.getData().getIdentifier()); + assertEquals("failed", response.getData().getStatus()); + assertEquals(fileId, response.getData().getAttributes().getFileId()); + assertEquals("File deletion failed", response.getData().getError().getMessage()); + } + + @Test + public void checkFileDeletionStatusTest() { + ResponseObject response = this.getSourceFilesApi().checkFileDeletionStatus(projectId, fileId, fileDeleteJobIdentifier); + assertEquals(fileDeleteJobIdentifier, response.getData().getIdentifier()); + assertEquals(fileId, response.getData().getAttributes().getFileId()); + assertEquals("File deletion failed", response.getData().getError().getMessage()); + } + @Test public void editFileTest() { PatchRequest request = new PatchRequest(); diff --git a/src/test/resources/api/branches/deleteJobStatus.json b/src/test/resources/api/branches/deleteJobStatus.json new file mode 100644 index 000000000..4dd167a11 --- /dev/null +++ b/src/test/resources/api/branches/deleteJobStatus.json @@ -0,0 +1,14 @@ +{ + "data": { + "identifier": "50fb3506-4127-4ba8-8296-f97dc7e3e0c3", + "status": "created", + "progress": 0, + "attributes": { + "branchId": 14 + }, + "createdAt": "2019-09-23T11:26:54+00:00", + "updatedAt": "2019-09-23T11:26:54+00:00", + "startedAt": "2019-09-23T11:26:54+00:00", + "finishedAt": "2019-09-23T11:26:54+00:00" + } +} diff --git a/src/test/resources/api/sourcefiles/branchDeleteJobStatus.json b/src/test/resources/api/sourcefiles/branchDeleteJobStatus.json new file mode 100644 index 000000000..67cd47723 --- /dev/null +++ b/src/test/resources/api/sourcefiles/branchDeleteJobStatus.json @@ -0,0 +1,14 @@ +{ + "data": { + "identifier": "branch-delete-job", + "status": "finished", + "progress": 100, + "attributes": { + "branchId": 34 + }, + "createdAt": "2019-09-23T11:26:54+00:00", + "updatedAt": "2019-09-23T11:26:54+00:00", + "startedAt": "2019-09-23T11:26:54+00:00", + "finishedAt": "2019-09-23T11:26:54+00:00" + } +} diff --git a/src/test/resources/api/sourcefiles/directoryDeleteJobStatus.json b/src/test/resources/api/sourcefiles/directoryDeleteJobStatus.json new file mode 100644 index 000000000..7fda5aa79 --- /dev/null +++ b/src/test/resources/api/sourcefiles/directoryDeleteJobStatus.json @@ -0,0 +1,14 @@ +{ + "data": { + "identifier": "directory-delete-job", + "status": "in_progress", + "progress": 50, + "attributes": { + "directoryId": 4 + }, + "createdAt": "2019-09-23T11:26:54+00:00", + "updatedAt": "2019-09-23T11:26:54+00:00", + "startedAt": "2019-09-23T11:26:54+00:00", + "finishedAt": "2019-09-23T11:26:54+00:00" + } +} diff --git a/src/test/resources/api/sourcefiles/fileDeleteJobStatus.json b/src/test/resources/api/sourcefiles/fileDeleteJobStatus.json new file mode 100644 index 000000000..cb5f5dcb4 --- /dev/null +++ b/src/test/resources/api/sourcefiles/fileDeleteJobStatus.json @@ -0,0 +1,17 @@ +{ + "data": { + "identifier": "file-delete-job", + "status": "failed", + "progress": 100, + "attributes": { + "fileId": 44 + }, + "error": { + "message": "File deletion failed" + }, + "createdAt": "2019-09-23T11:26:54+00:00", + "updatedAt": "2019-09-23T11:26:54+00:00", + "startedAt": "2019-09-23T11:26:54+00:00", + "finishedAt": "2019-09-23T11:26:54+00:00" + } +}