Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/com/smartsheet/api/ReportResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,19 @@ Report getReport(
* @return the created ShareResources object
*/
ShareResources shareResources();

/**
* <p>Deletes a report.</p>
*
* <p>Mirrors the following Smartsheet REST API method: DELETE /reports/{reportId}</p>
*
* @param id the id of the report
* @throws IllegalArgumentException if any argument is null or empty string
* @throws InvalidRequestException if there is any problem with the REST API request
* @throws AuthorizationException if there is any problem with the REST API authorization (access token)
* @throws ResourceNotFoundException if the resource cannot be found
* @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
* @throws SmartsheetException if there is any other error during the operation
*/
void deleteReport(long id) throws SmartsheetException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,8 @@ public ReportPublish updatePublishStatus(long id, ReportPublish reportPublish) t
public ShareResources shareResources() {
return this.shares;
}

public void deleteReport(long id) throws SmartsheetException {
this.deleteResource(REPORTS_PATH + id, Report.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,10 @@ void testGetReportAsCsv() throws SmartsheetException, IOException {
byte[] data = Files.readAllBytes(Paths.get(file.getPath()));
assertThat(output.toByteArray()).hasSameSizeAs(data);
}

@Test
void testDeleteReport() throws IOException {
server.setResponseBody(new File("src/test/resources/deleteReport.json"));
assertThatCode(() -> reportResources.deleteReport(1122334L)).doesNotThrowAnyException();
}
}
94 changes: 94 additions & 0 deletions src/test/java/com/smartsheet/api/sdktest/ReportsTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2025 Smartsheet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.smartsheet.api.sdktest;

import com.github.tomakehurst.wiremock.verification.LoggedRequest;
import com.smartsheet.api.Smartsheet;
import com.smartsheet.api.SmartsheetException;
import com.smartsheet.api.WiremockClient;
import com.smartsheet.api.WiremockClientWrapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.net.URI;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;

public class ReportsTests {

private static final long TEST_REPORT_ID = 1123581321L;

@Test
void testDeleteReportGeneratedUrlIsCorrect() throws SmartsheetException {
String requestId = UUID.randomUUID().toString();
WiremockClientWrapper wrapper = Utils.createWiremockSmartsheetClient(
"/reports/delete-report/all-response-body-properties",
requestId
);
Smartsheet smartsheet = wrapper.getSmartsheet();
WiremockClient wiremockClient = wrapper.getWiremockClient();

smartsheet.reportResources().deleteReport(TEST_REPORT_ID);
LoggedRequest wiremockRequest = wiremockClient.findWiremockRequest(requestId);
String path = URI.create(wiremockRequest.getUrl()).getPath();

assertThat(path).isEqualTo("/2.0/reports/" + TEST_REPORT_ID);
assertThat(wiremockRequest.getMethod().getName()).isEqualTo("DELETE");
}

@Test
void testRemoveUserFromPlanAllResponseBodyProperties() throws SmartsheetException {
String requestId = UUID.randomUUID().toString();
WiremockClientWrapper wrapper = Utils.createWiremockSmartsheetClient(
"/reports/delete-report/all-response-body-properties",
requestId
);
Smartsheet smartsheet = wrapper.getSmartsheet();

Assertions.assertDoesNotThrow(() -> {
smartsheet.reportResources().deleteReport(TEST_REPORT_ID);
});
}

@Test
void testUpgradeUserError500Response() {
String requestId = UUID.randomUUID().toString();
WiremockClientWrapper wrapper = Utils.createWiremockSmartsheetClient("/errors/500-response", requestId);
Smartsheet smartsheet = wrapper.getSmartsheet();

SmartsheetException exception = Assertions.assertThrows(SmartsheetException.class, () -> {
smartsheet.reportResources().deleteReport(TEST_REPORT_ID);
});

assertThat(exception.getMessage()).contains("Internal Server Error");
}

@Test
void testUpgradeUserError400Response() {
String requestId = UUID.randomUUID().toString();
WiremockClientWrapper wrapper = Utils.createWiremockSmartsheetClient("/errors/400-response", requestId);
Smartsheet smartsheet = wrapper.getSmartsheet();

SmartsheetException exception = Assertions.assertThrows(SmartsheetException.class, () -> {
smartsheet.reportResources().deleteReport(TEST_REPORT_ID);
});

assertThat(exception.getMessage()).contains("Malformed Request");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.smartsheet.api.sdktest.users;
package com.smartsheet.api.sdktest;

import com.smartsheet.api.Smartsheet;
import com.smartsheet.api.WiremockClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.smartsheet.api.SmartsheetException;
import com.smartsheet.api.WiremockClient;
import com.smartsheet.api.WiremockClientWrapper;
import com.smartsheet.api.sdktest.Utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.smartsheet.api.models.TokenPaginatedResult;
import com.smartsheet.api.models.UserPlan;
import com.smartsheet.api.models.enums.SeatType;
import com.smartsheet.api.sdktest.Utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.smartsheet.api.models.User;
import com.smartsheet.api.models.enums.SeatType;
import com.smartsheet.api.models.enums.UserStatus;
import com.smartsheet.api.sdktest.Utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.smartsheet.api.SmartsheetException;
import com.smartsheet.api.WiremockClient;
import com.smartsheet.api.WiremockClientWrapper;
import com.smartsheet.api.sdktest.Utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.smartsheet.api.SmartsheetException;
import com.smartsheet.api.WiremockClient;
import com.smartsheet.api.WiremockClientWrapper;
import com.smartsheet.api.sdktest.Utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.smartsheet.api.WiremockClientWrapper;
import com.smartsheet.api.models.enums.DowngradeSeatType;
import com.smartsheet.api.models.enums.UpgradeSeatType;
import com.smartsheet.api.sdktest.Utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down
1 change: 1 addition & 0 deletions src/test/resources/deleteReport.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"resultCode":0,"message":"SUCCESS"}