diff --git a/src/main/java/com/smartsheet/api/internal/RowColumnResourcesImpl.java b/src/main/java/com/smartsheet/api/internal/RowColumnResourcesImpl.java index 19d0ee1a..18c8b9ba 100644 --- a/src/main/java/com/smartsheet/api/internal/RowColumnResourcesImpl.java +++ b/src/main/java/com/smartsheet/api/internal/RowColumnResourcesImpl.java @@ -78,7 +78,7 @@ public RowColumnResourcesImpl(SmartsheetImpl smartsheet) { * * @param rowId the row id * @param columnId the column id - * @param sheetId the sheet Id + * @param sheetId the sheet ID * @param parameters the pagination parameters * @return the modification history (note that if there is no such resource, this method will throw * ResourceNotFoundException rather than returning null). @@ -108,7 +108,7 @@ public PagedResult getCellHistory( * * @param rowId the row id * @param columnId the column id - * @param sheetId the sheet Id + * @param sheetId the sheet ID * @param pagination the pagination parameters * @param includes cell history inclusion * @param level compatibility level @@ -147,7 +147,7 @@ public PagedResult getCellHistory(long sheetId, long rowId, long co * SmartsheetRestException : if there is any other REST API related error occurred during the operation * SmartsheetException : if there is any other error occurred during the operation * - * @param sheetId the sheet Id + * @param sheetId the sheet ID * @param rowId the row id * @param columnId the column id * @param file the file path @@ -181,7 +181,7 @@ public void addImageToCell( * SmartsheetRestException : if there is any other REST API related error occurred during the operation * SmartsheetException : if there is any other error occurred during the operation * - * @param sheetId the sheet Id + * @param sheetId the sheet ID * @param rowId the row id * @param columnId the column id * @param file the file path @@ -219,7 +219,7 @@ public void addImageToCell( * SmartsheetRestException : if there is any other REST API related error occurred during the operation * SmartsheetException : if there is any other error occurred during the operation * - * @param sheetId the sheet Id + * @param sheetId the sheet ID * @param rowId the row id * @param columnId the column id * @param file the File object @@ -249,7 +249,7 @@ public void addImageToCell(long sheetId, long rowId, long columnId, File file, S * SmartsheetRestException : if there is any other REST API related error occurred during the operation * SmartsheetException : if there is any other error occurred during the operation * - * @param sheetId the sheet Id + * @param sheetId the sheet ID * @param rowId the row id * @param columnId the column id * @param inputStream the input stream of the contents diff --git a/src/main/java/com/smartsheet/api/internal/WebhookResourcesImpl.java b/src/main/java/com/smartsheet/api/internal/WebhookResourcesImpl.java index bb1bcd05..a318099c 100644 --- a/src/main/java/com/smartsheet/api/internal/WebhookResourcesImpl.java +++ b/src/main/java/com/smartsheet/api/internal/WebhookResourcesImpl.java @@ -77,7 +77,7 @@ public PagedResult listWebhooks(PaginationParameters paging) throws Sma *

* It mirrors to the following Smartsheet REST API method: GET /webhooks/{webhookId} * - * @param webhookId the Id of the webhook + * @param webhookId the ID of the webhook * @return the webhook resource. * @throws IllegalArgumentException if any argument is null or empty string * @throws InvalidRequestException if there is any problem with the REST API request @@ -148,7 +148,7 @@ public void deleteWebhook(long webhookId) throws SmartsheetException { *

* It mirrors to the following Smartsheet REST API method: POST /webhooks/{webhookId}/resetsharedsecret * - * @param webhookId the webhook Id + * @param webhookId the webhook ID * @return the Webhook shared secret * @throws IllegalArgumentException if any argument is null or empty string * @throws InvalidRequestException if there is any problem with the REST API request diff --git a/src/main/java/com/smartsheet/api/models/Webhook.java b/src/main/java/com/smartsheet/api/models/Webhook.java index a575e594..c515fc4d 100644 --- a/src/main/java/com/smartsheet/api/models/Webhook.java +++ b/src/main/java/com/smartsheet/api/models/Webhook.java @@ -24,12 +24,12 @@ public class Webhook extends NamedModel { /** - * API Client Id corresponding to third-party app that created the Webhook. + * API Client ID corresponding to third-party app that created the Webhook. */ private String apiClientId; /** - * Id of the object that is subscripted to. + * ID of the object that is subscribed to. */ private Long scopeObjectId; @@ -100,7 +100,7 @@ public class Webhook extends NamedModel { private Integer version; /** - * Get the API client Id corresponding to third-party app that created the webhook. + * Get the API client ID corresponding to third-party app that created the webhook. * * @return apiClientId */ @@ -109,7 +109,7 @@ public String getApiClientId() { } /** - * Set the API client Id corresponding to third-party app that created the webhook. + * Set the API client ID corresponding to third-party app that created the webhook. */ public Webhook setApiClientId(String apiClientId) { this.apiClientId = apiClientId; @@ -117,7 +117,7 @@ public Webhook setApiClientId(String apiClientId) { } /** - * Get the Id of the object that is subscripted to + * Get the ID of the object that is subscripted to * * @return scopeObjectId */ @@ -126,7 +126,7 @@ public Long getScopeObjectId() { } /** - * Set the Id of the object that is subscribed to + * Set the ID of the object that is subscribed to */ public Webhook setScopeObjectId(Long scopeObjectId) { this.scopeObjectId = scopeObjectId; diff --git a/src/test/java/com/smartsheet/api/internal/EventResourcesImplTest.java b/src/test/java/com/smartsheet/api/internal/EventResourcesImplTest.java new file mode 100644 index 00000000..8402edea --- /dev/null +++ b/src/test/java/com/smartsheet/api/internal/EventResourcesImplTest.java @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2023 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.internal; + +import com.smartsheet.api.InvalidRequestException; +import com.smartsheet.api.SmartsheetException; +import com.smartsheet.api.internal.http.DefaultHttpClient; +import com.smartsheet.api.models.EventResult; +import com.smartsheet.api.models.enums.EventObjectType; +import com.smartsheet.api.models.enums.EventSource; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class EventResourcesImplTest extends ResourcesImplBase { + + private EventResourcesImpl eventResources; + + @BeforeEach + public void setUp() throws Exception { + eventResources = new EventResourcesImpl(new SmartsheetImpl("http://localhost:9090/1.1/", + "accessToken", new DefaultHttpClient(), serializer)); + } + + @Test + void testListEvents_sinceExists_happyPath() throws IOException, SmartsheetException { + server.setResponseBody(new File("src/test/resources/listEvents.json")); + String since = "2023-01-30T11:42:30Z"; + Integer maxCount = 5; + Boolean numericDates = true; + + EventResult eventResult = eventResources.listEvents(since, null, maxCount, numericDates); + + assertThat(eventResult).isNotNull(); + assertThat(eventResult.getData()).isNotNull(); + assertThat(eventResult.getMoreAvailable()).isFalse(); + assertThat(eventResult.getNextStreamPosition()).isNotBlank(); + assertThat(eventResult.getData().size()).isEqualTo(2); + + assertThat(eventResult.getData().get(0).getEventId()).isNotBlank(); + assertThat(eventResult.getData().get(0).getUserId()).isNotNull(); + assertThat(eventResult.getData().get(0).getRequestUserId()).isNotNull(); + assertThat(eventResult.getData().get(0).getAccessTokenName()).isNotBlank(); + assertThat(eventResult.getData().get(0).getEventTimestamp()).isNotNull(); + assertThat(eventResult.getData().get(0).getSource().name()).isEqualTo(EventSource.WEB_APP.name()); + assertThat(eventResult.getData().get(0).getObjectType().name()).isEqualTo(EventObjectType.ACCESS_TOKEN.name()); + + assertThat(eventResult.getData().get(1).getEventId()).isNotBlank(); + assertThat(eventResult.getData().get(1).getUserId()).isNotNull(); + assertThat(eventResult.getData().get(1).getRequestUserId()).isNotNull(); + assertThat(eventResult.getData().get(1).getAccessTokenName()).isNotBlank(); + assertThat(eventResult.getData().get(1).getEventTimestamp()).isNotNull(); + assertThat(eventResult.getData().get(1).getSource().name()).isEqualTo(EventSource.WEB_APP.name()); + assertThat(eventResult.getData().get(1).getObjectType().name()).isEqualTo(EventObjectType.ACCESS_TOKEN.name()); + } + + @Test + void testListEvents_streamPosExists_happyPath() throws IOException, SmartsheetException { + server.setResponseBody(new File("src/test/resources/listEvents.json")); + String streamPos = "2023-01-30T11:42:30Z"; + Integer maxCount = 5; + Boolean numericDates = true; + + EventResult eventResult = eventResources.listEvents(null, streamPos, maxCount, numericDates); + + assertThat(eventResult).isNotNull(); + assertThat(eventResult.getData()).isNotNull(); + assertThat(eventResult.getMoreAvailable()).isFalse(); + assertThat(eventResult.getNextStreamPosition()).isNotBlank(); + assertThat(eventResult.getData().size()).isEqualTo(2); + + assertThat(eventResult.getData().get(0).getEventId()).isNotBlank(); + assertThat(eventResult.getData().get(0).getUserId()).isNotNull(); + assertThat(eventResult.getData().get(0).getRequestUserId()).isNotNull(); + assertThat(eventResult.getData().get(0).getAccessTokenName()).isNotBlank(); + assertThat(eventResult.getData().get(0).getEventTimestamp()).isNotNull(); + assertThat(eventResult.getData().get(0).getSource().name()).isEqualTo(EventSource.WEB_APP.name()); + assertThat(eventResult.getData().get(0).getObjectType().name()).isEqualTo(EventObjectType.ACCESS_TOKEN.name()); + + assertThat(eventResult.getData().get(1).getEventId()).isNotBlank(); + assertThat(eventResult.getData().get(1).getUserId()).isNotNull(); + assertThat(eventResult.getData().get(1).getRequestUserId()).isNotNull(); + assertThat(eventResult.getData().get(1).getAccessTokenName()).isNotBlank(); + assertThat(eventResult.getData().get(1).getEventTimestamp()).isNotNull(); + assertThat(eventResult.getData().get(1).getSource().name()).isEqualTo(EventSource.WEB_APP.name()); + assertThat(eventResult.getData().get(1).getObjectType().name()).isEqualTo(EventObjectType.ACCESS_TOKEN.name()); + } + + @Test + void testListEvents_exception() { + String since = "2023-01-30T11:42:30Z"; + Integer maxCount = 5; + Boolean numericDates = true; + + server.setStatus(400); + server.setResponseBody("{\"errorCode\":1032,\"message\":\"Something went wrong\"}"); + assertThatThrownBy(() -> { + eventResources.listEvents(since, null, maxCount, numericDates); + }) + .isInstanceOf(InvalidRequestException.class) + .hasMessage("Something went wrong"); + } + +} diff --git a/src/test/java/com/smartsheet/api/internal/PassthroughResourcesImplTest.java b/src/test/java/com/smartsheet/api/internal/PassthroughResourcesImplTest.java new file mode 100644 index 00000000..7f84eb08 --- /dev/null +++ b/src/test/java/com/smartsheet/api/internal/PassthroughResourcesImplTest.java @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2023 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.internal; + +import com.smartsheet.api.InvalidRequestException; +import com.smartsheet.api.SmartsheetException; +import com.smartsheet.api.internal.http.DefaultHttpClient; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class PassthroughResourcesImplTest extends ResourcesImplBase { + + private PassthroughResourcesImpl passthroughResources; + + @BeforeEach + public void setUp() throws Exception { + passthroughResources = new PassthroughResourcesImpl(new SmartsheetImpl("http://localhost:9090/1.1/", + "accessToken", new DefaultHttpClient(), serializer)); + } + + @Test + void testGetRequest_happyPath() throws SmartsheetException { + server.setResponseBody("{\"resultCode\":0,\"message\":\"SUCCESS\"}"); + Map params = new HashMap<>(); + params.put("sheetId", 1234L); + params.put("rowId", 4567L); + String response = passthroughResources.getRequest("/sheets/rows", params); + assertThat(response).isNotBlank(); + } + + @Test + void testGetRequest_exception() { + Map params = new HashMap<>(); + params.put("sheetId", 1234L); + params.put("rowId", 4567L); + server.setStatus(400); + server.setResponseBody("{\"errorCode\":1032,\"message\":\"Something went wrong\"}"); + assertThatThrownBy(() -> { + passthroughResources.getRequest("/sheets/rows", params); + }) + .isInstanceOf(InvalidRequestException.class) + .hasMessage("Something went wrong"); + } + + @Test + void testPostRequest_happyPath() throws SmartsheetException { + server.setResponseBody("{\"resultCode\":0,\"message\":\"SUCCESS\"}"); + Map params = new HashMap<>(); + params.put("sheetId", 1234L); + params.put("rowId", 4567L); + String payload = "some body here"; + String response = passthroughResources.postRequest("/sheets/rows", payload, params); + assertThat(response).isNotBlank(); + } + + @Test + void testPostRequest_exception() { + Map params = new HashMap<>(); + params.put("sheetId", 1234L); + params.put("rowId", 4567L); + String payload = "some body here"; + server.setStatus(400); + server.setResponseBody("{\"errorCode\":1032,\"message\":\"Something went wrong\"}"); + assertThatThrownBy(() -> { + passthroughResources.postRequest("/sheets/rows", payload, params); + }) + .isInstanceOf(InvalidRequestException.class) + .hasMessage("Something went wrong"); + } + + @Test + void testPutRequest_happyPath() throws SmartsheetException { + server.setResponseBody("{\"resultCode\":0,\"message\":\"SUCCESS\"}"); + Map params = new HashMap<>(); + params.put("sheetId", 1234L); + params.put("rowId", 4567L); + String payload = "some body here"; + String response = passthroughResources.putRequest("/sheets/rows", payload, params); + assertThat(response).isNotBlank(); + } + + @Test + void testPutRequest_exception() { + Map params = new HashMap<>(); + params.put("sheetId", 1234L); + params.put("rowId", 4567L); + String payload = "some body here"; + server.setStatus(400); + server.setResponseBody("{\"errorCode\":1032,\"message\":\"Something went wrong\"}"); + assertThatThrownBy(() -> { + passthroughResources.putRequest("/sheets/rows", payload, params); + }) + .isInstanceOf(InvalidRequestException.class) + .hasMessage("Something went wrong"); + } + + @Test + void testPostRequest_nullPayload_throwsException() { + server.setResponseBody("{\"resultCode\":0,\"message\":\"SUCCESS\"}"); + Map params = new HashMap<>(); + params.put("sheetId", 1234L); + params.put("rowId", 4567L); + String payload = null; + assertThatThrownBy(() -> { + passthroughResources.postRequest("/sheets/rows", payload, params); + }).isInstanceOf(IllegalArgumentException.class); + } + + @Test + void testPutRequest_nullPayload_throwsException() { + server.setResponseBody("{\"resultCode\":0,\"message\":\"SUCCESS\"}"); + Map params = new HashMap<>(); + params.put("sheetId", 1234L); + params.put("rowId", 4567L); + String payload = null; + assertThatThrownBy(() -> { + passthroughResources.putRequest("/sheets/rows", payload, params); + }).isInstanceOf(IllegalArgumentException.class); + } + + @Test + void testDeleteRequest_happyPath() throws SmartsheetException { + server.setResponseBody("{\"resultCode\":0,\"message\":\"SUCCESS\"}"); + String response = passthroughResources.deleteRequest("/sheets/1234/rows/4567"); + assertThat(response).isNotBlank(); + } + + @Test + void testDeleteRequest_exception() { + server.setStatus(400); + server.setResponseBody("{\"errorCode\":1032,\"message\":\"Something went wrong\"}"); + assertThatThrownBy(() -> { + passthroughResources.deleteRequest("/sheets/1234/rows/4567"); + }) + .isInstanceOf(InvalidRequestException.class) + .hasMessage("Something went wrong"); + } + +} diff --git a/src/test/java/com/smartsheet/api/internal/RowColumnResourcesImplTest.java b/src/test/java/com/smartsheet/api/internal/RowColumnResourcesImplTest.java index 3e9fb21c..dab7d9a0 100644 --- a/src/test/java/com/smartsheet/api/internal/RowColumnResourcesImplTest.java +++ b/src/test/java/com/smartsheet/api/internal/RowColumnResourcesImplTest.java @@ -16,6 +16,7 @@ package com.smartsheet.api.internal; +import com.smartsheet.api.InvalidRequestException; import com.smartsheet.api.SmartsheetException; import com.smartsheet.api.internal.http.DefaultHttpClient; import com.smartsheet.api.models.CellHistory; @@ -28,6 +29,7 @@ import java.io.IOException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class RowColumnResourcesImplTest extends ResourcesImplBase { private RowColumnResourcesImpl rowColumnResources; @@ -39,7 +41,7 @@ public void setUp() throws Exception { } @Test - void testGetCellHistory() throws SmartsheetException, IOException { + void testGetCellHistory_happyPath() throws SmartsheetException, IOException { server.setResponseBody(new File("src/test/resources/getCellHistory.json")); PaginationParameters parameters = new PaginationParameters(false, 1, 1); PagedResult cellHistory = rowColumnResources.getCellHistory(123L, 123L, 123L, parameters); @@ -48,4 +50,16 @@ void testGetCellHistory() throws SmartsheetException, IOException { assertThat(cellHistory.getData().get(1).getModifiedBy().getName()).isEqualTo("Joe Smart"); } + @Test + void testGetCellHistory_exception() { + PaginationParameters parameters = new PaginationParameters(false, 1, 1); + server.setStatus(400); + server.setResponseBody("{\"errorCode\":1032,\"message\":\"Something went wrong\"}"); + assertThatThrownBy(() -> { + rowColumnResources.getCellHistory(123L, 123L, 123L, parameters); + }) + .isInstanceOf(InvalidRequestException.class) + .hasMessage("Something went wrong"); + } + } diff --git a/src/test/java/com/smartsheet/api/internal/TokenResourcesImplTest.java b/src/test/java/com/smartsheet/api/internal/TokenResourcesImplTest.java new file mode 100644 index 00000000..d2208b6b --- /dev/null +++ b/src/test/java/com/smartsheet/api/internal/TokenResourcesImplTest.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2023 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.internal; + +import com.smartsheet.api.internal.http.DefaultHttpClient; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; + +class TokenResourcesImplTest extends ResourcesImplBase { + + private TokenResourcesImpl tokenResources; + + @BeforeEach + public void setUp() throws Exception { + tokenResources = new TokenResourcesImpl(new SmartsheetImpl("http://localhost:9090/1.1/", + "accessToken", new DefaultHttpClient(), serializer)); + } + + @Test + void testGetAccessToken() { + assertThatThrownBy(() -> { + tokenResources.getAccessToken(); + }).isInstanceOf(NoSuchMethodException.class); + } + + @Test + void testRevokeAccessToken() { + server.setResponseBody("{\"resultCode\":0,\"message\":\"SUCCESS\"}"); + assertThatCode(() -> tokenResources.revokeAccessToken()).doesNotThrowAnyException(); + } + + @Test + void testRefreshAccessToken() { + assertThatThrownBy(() -> { + tokenResources.refreshAccessToken(); + }).isInstanceOf(NoSuchMethodException.class); + } + +} diff --git a/src/test/java/com/smartsheet/api/internal/WebhookResourcesImplTest.java b/src/test/java/com/smartsheet/api/internal/WebhookResourcesImplTest.java new file mode 100644 index 00000000..8e214d08 --- /dev/null +++ b/src/test/java/com/smartsheet/api/internal/WebhookResourcesImplTest.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2023 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.internal; + +import com.smartsheet.api.InvalidRequestException; +import com.smartsheet.api.SmartsheetException; +import com.smartsheet.api.internal.http.DefaultHttpClient; +import com.smartsheet.api.models.PagedResult; +import com.smartsheet.api.models.PaginationParameters; +import com.smartsheet.api.models.Webhook; +import com.smartsheet.api.models.WebhookSharedSecret; +import com.smartsheet.api.models.enums.WebhookStatus; +import org.assertj.core.util.Lists; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.io.IOException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; + +class WebhookResourcesImplTest extends ResourcesImplBase { + + private WebhookResourcesImpl webhookResources; + + @BeforeEach + public void setUp() throws Exception { + webhookResources = new WebhookResourcesImpl(new SmartsheetImpl("http://localhost:9090/1.1/", + "accessToken", new DefaultHttpClient(), serializer)); + } + + @Test + void testListWebhooks() throws IOException, SmartsheetException { + server.setResponseBody(new File("src/test/resources/listWebhooks.json")); + PaginationParameters parameters = new PaginationParameters(false, 1, 1); + + PagedResult webhookPagedResults = webhookResources.listWebhooks(parameters); + + assertThat(webhookPagedResults.getData().size()).isEqualTo(2); + assertThat(webhookPagedResults.getData().get(0).getApiClientId()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(1).getApiClientId()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(0).getVersion()).isEqualTo(1); + assertThat(webhookPagedResults.getData().get(1).getVersion()).isEqualTo(1); + assertThat(webhookPagedResults.getData().get(1).getApiClientId()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(0).getScope()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(1).getScope()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(0).getApiClientName()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(1).getApiClientName()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(0).getCallbackUrl()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(1).getCallbackUrl()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(0).getSharedSecret()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(1).getSharedSecret()).isNotBlank(); + assertThat(webhookPagedResults.getData().get(0).getEvents().size()).isEqualTo(2); + assertThat(webhookPagedResults.getData().get(1).getEvents().size()).isEqualTo(0); + assertThat(webhookPagedResults.getData().get(0).isEnabled()).isFalse(); + assertThat(webhookPagedResults.getData().get(1).isEnabled()).isTrue(); + assertThat(webhookPagedResults.getData().get(0).getStatus().name()).isEqualTo(WebhookStatus.DISABLED_BY_OWNER.name()); + assertThat(webhookPagedResults.getData().get(1).getStatus().name()).isEqualTo(WebhookStatus.ENABLED.name()); + } + + @Test + void testGetWebhook() throws SmartsheetException, IOException { + server.setResponseBody(new File("src/test/resources/getWebhook.json")); + + Webhook webhook = webhookResources.getWebhook(123L); + + assertThat(webhook.getApiClientId()).isNotBlank(); + assertThat(webhook.getVersion()).isEqualTo(1); + assertThat(webhook.getApiClientId()).isNotBlank(); + assertThat(webhook.getScope()).isNotBlank(); + assertThat(webhook.getApiClientName()).isNotBlank(); + assertThat(webhook.getCallbackUrl()).isNotBlank(); + assertThat(webhook.getSharedSecret()).isNotBlank(); + assertThat(webhook.getEvents().size()).isEqualTo(2); + assertThat(webhook.isEnabled()).isFalse(); + assertThat(webhook.getStatus().name()).isEqualTo(WebhookStatus.DISABLED_BY_OWNER.name()); + } + + @Test + void testDeleteWebhook() throws IOException { + server.setResponseBody(new File("src/test/resources/deleteWebhook.json")); + assertThatCode(() -> webhookResources.deleteWebhook(123L)).doesNotThrowAnyException(); + } + + @Test + void testCreateWebhook() throws SmartsheetException, IOException { + server.setResponseBody(new File("src/test/resources/createWebhook.json")); + Webhook webhookToCreate = new Webhook(); + webhookToCreate.setApiClientId("2382749284kjdskfhjsfhkjds"); + webhookToCreate.setEnabled(false); + webhookToCreate.setScope("some-scope-string"); + webhookToCreate.setStatus(WebhookStatus.DISABLED_BY_OWNER); + webhookToCreate.setDisabledDetails("disabled by owner for additional testing"); + webhookToCreate.setSharedSecret("sdklfldsjwe9oak232m4n22424kh2390283923"); + webhookToCreate.setCallbackUrl("https://foo-callback.smar.com/webhook"); + webhookToCreate.setEvents(Lists.newArrayList("add", "delete")); + + Webhook createdWebhook = webhookResources.createWebhook(webhookToCreate); + + assertThat(createdWebhook.getApiClientId()).isNotBlank(); + assertThat(createdWebhook.getVersion()).isEqualTo(1); + assertThat(createdWebhook.getApiClientId()).isNotBlank(); + assertThat(createdWebhook.getScope()).isNotBlank(); + assertThat(createdWebhook.getApiClientName()).isNotBlank(); + assertThat(createdWebhook.getCallbackUrl()).isNotBlank(); + assertThat(createdWebhook.getSharedSecret()).isNotBlank(); + assertThat(createdWebhook.getEvents().size()).isEqualTo(2); + assertThat(createdWebhook.isEnabled()).isFalse(); + assertThat(createdWebhook.getStatus().name()).isEqualTo(WebhookStatus.DISABLED_BY_OWNER.name()); + } + + @Test + void testUpdateWebhook() throws SmartsheetException, IOException { + server.setResponseBody(new File("src/test/resources/updateWebhook.json")); + Webhook webhookToUpdate = new Webhook(); + webhookToUpdate.setApiClientId("2382749284kjdskfhjsfhkjds"); + webhookToUpdate.setEnabled(false); + webhookToUpdate.setScope("some-scope-string"); + webhookToUpdate.setStatus(WebhookStatus.ENABLED); + webhookToUpdate.setDisabledDetails(""); + webhookToUpdate.setSharedSecret("sdklfldsjwe9oak232m4n22424kh2390283923"); + webhookToUpdate.setCallbackUrl("https://foo-callback.smar.com/webhook"); + webhookToUpdate.setEvents(Lists.newArrayList("add", "delete")); + + Webhook updatedWebhook = webhookResources.updateWebhook(webhookToUpdate); + + assertThat(updatedWebhook.getApiClientId()).isNotBlank(); + assertThat(updatedWebhook.getVersion()).isEqualTo(1); + assertThat(updatedWebhook.getApiClientId()).isNotBlank(); + assertThat(updatedWebhook.getScope()).isNotBlank(); + assertThat(updatedWebhook.getApiClientName()).isNotBlank(); + assertThat(updatedWebhook.getCallbackUrl()).isNotBlank(); + assertThat(updatedWebhook.getSharedSecret()).isNotBlank(); + assertThat(updatedWebhook.getEvents().size()).isEqualTo(2); + assertThat(updatedWebhook.isEnabled()).isTrue(); + assertThat(updatedWebhook.getStatus().name()).isEqualTo(WebhookStatus.ENABLED.name()); + assertThat(updatedWebhook.getDisabledDetails()).isBlank(); + } + + @Test + void testResetSharedSecret_happyPath() throws IOException, SmartsheetException { + server.setResponseBody(new File("src/test/resources/resetSharedSecret.json")); + WebhookSharedSecret webhookSharedSecret = webhookResources.resetSharedSecret(123L); + assertThat(webhookSharedSecret.getSharedSecret()).isNotBlank(); + } + + @Test + void testResetSharedSecret_exception() throws IOException { + server.setStatus(400); + server.setResponseBody(new File("src/test/resources/webhookException.json")); + assertThatThrownBy(() -> { + webhookResources.resetSharedSecret(123L); + }) + .isInstanceOf(InvalidRequestException.class) + .hasMessage("Something went wrong"); + } +} diff --git a/src/test/java/com/smartsheet/api/internal/WorkspaceResourcesImplTest.java b/src/test/java/com/smartsheet/api/internal/WorkspaceResourcesImplTest.java index dfef07b6..b5d63d0c 100644 --- a/src/test/java/com/smartsheet/api/internal/WorkspaceResourcesImplTest.java +++ b/src/test/java/com/smartsheet/api/internal/WorkspaceResourcesImplTest.java @@ -36,6 +36,7 @@ import java.util.EnumSet; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; class WorkspaceResourcesImplTest extends ResourcesImplBase { @@ -112,9 +113,9 @@ void testUpdateWorkspace() throws IOException, SmartsheetException { } @Test - void testDeleteWorkspace() throws IOException, SmartsheetException { + void testDeleteWorkspace() throws IOException { server.setResponseBody(new File("src/test/resources/deleteWorkspace.json")); - workspaceResources.deleteWorkspace(1234L); + assertThatCode(() -> workspaceResources.deleteWorkspace(1234L)).doesNotThrowAnyException(); } @Test diff --git a/src/test/resources/createWebhook.json b/src/test/resources/createWebhook.json new file mode 100644 index 00000000..0d082271 --- /dev/null +++ b/src/test/resources/createWebhook.json @@ -0,0 +1,19 @@ +{ + "resultCode": 0, + "result": { + "apiClientId": "2382749284kjdskfhjsfhkjds", + "scopeObjectId": 827634728462, + "apiClientName": "testClientName1", + "callbackUrl": "https://foo-callback.smar.com/webhook", + "createdAt": "2023-01-30T11:42:30Z", + "modifiedAt": "2023-05-30T11:42:30Z", + "disabledDetails": "disabled by owner for additional testing", + "enabled": false, + "events": ["delete", "add"], + "scope": "some-scope-string", + "sharedSecret": "sdklfldsjwe9oak232m4n22424kh2390283923", + "status": "DISABLED_BY_OWNER", + "version": 1.0 + }, + "message": "SUCCESS" +} diff --git a/src/test/resources/deleteWebhook.json b/src/test/resources/deleteWebhook.json new file mode 100644 index 00000000..04deda86 --- /dev/null +++ b/src/test/resources/deleteWebhook.json @@ -0,0 +1 @@ +{"resultCode":0,"message":"SUCCESS"} \ No newline at end of file diff --git a/src/test/resources/getWebhook.json b/src/test/resources/getWebhook.json new file mode 100644 index 00000000..8758c874 --- /dev/null +++ b/src/test/resources/getWebhook.json @@ -0,0 +1,15 @@ +{ + "apiClientId": "2382749284kjdskfhjsfhkjds", + "scopeObjectId": 827634728462, + "apiClientName": "testClientName1", + "callbackUrl": "https://foo-callback.smar.com/webhook", + "createdAt": "2023-01-30T11:42:30Z", + "modifiedAt": "2023-05-30T11:42:30Z", + "disabledDetails": "disabled by owner for additional testing", + "enabled": false, + "events": ["delete", "add"], + "scope": "some-scope-string", + "sharedSecret": "sdklfldsjwe9oak232m4n22424kh2390283923", + "status": "DISABLED_BY_OWNER", + "version": 1.0 +} \ No newline at end of file diff --git a/src/test/resources/listEvents.json b/src/test/resources/listEvents.json new file mode 100644 index 00000000..e8b484ff --- /dev/null +++ b/src/test/resources/listEvents.json @@ -0,0 +1,28 @@ +{ + "data": [ + { + "accessTokenName": "token name 1", + "action": "CREATE", + "eventId": "12345", + "eventTimestamp": "2023-01-30T11:42:30Z", + "objectId": "23o42843u2kwkhrejwrhkehrw", + "objectType": "ACCESS_TOKEN", + "requestUserId": 548798, + "source": "WEB_APP", + "userId": 548798 + }, + { + "accessTokenName": "token name 2", + "action": "UPDATE", + "eventId": "12345", + "eventTimestamp": "2023-8-28T11:42:30Z", + "objectId": "90348029kwwrkwri2094892", + "objectType": "ACCESS_TOKEN", + "requestUserId": 123456, + "source": "WEB_APP", + "userId": 123456 + } + ], + "moreAvailable": false, + "nextStreamPosition": "0" +} \ No newline at end of file diff --git a/src/test/resources/listWebhooks.json b/src/test/resources/listWebhooks.json new file mode 100644 index 00000000..b90791de --- /dev/null +++ b/src/test/resources/listWebhooks.json @@ -0,0 +1,38 @@ +{ + "pageNumber": 1, + "pageSize": 100, + "totalPages": 1, + "totalCount": 2, + "data": [ + { + "apiClientId": "2382749284kjdskfhjsfhkjds", + "scopeObjectId": 827634728462, + "apiClientName": "testClientName1", + "callbackUrl": "https://foo-callback.smar.com/webhook", + "createdAt": "2023-01-30T11:42:30Z", + "modifiedAt": "2023-05-30T11:42:30Z", + "disabledDetails": "disabled by owner for additional testing", + "enabled": false, + "events": ["delete", "add"], + "scope": "some-scope-string", + "sharedSecret": "sdklfldsjwe9oak232m4n22424kh2390283923", + "status": "DISABLED_BY_OWNER", + "version": 1.0 + }, + { + "apiClientId": "39432809243jkhk234234234", + "scopeObjectId": 873422211111, + "apiClientName": "testClientName2", + "callbackUrl": "https://bar-callback.smar.com/webhook", + "createdAt": "2023-01-14T11:42:30Z", + "modifiedAt": "2023-01-29T11:42:30Z", + "disabledDetails": "", + "enabled": true, + "events": [], + "scope": "some-scope-string", + "sharedSecret": "9087234jhg23j2323423", + "status": "ENABLED", + "version": 1.0 + } + ] +} \ No newline at end of file diff --git a/src/test/resources/resetSharedSecret.json b/src/test/resources/resetSharedSecret.json new file mode 100644 index 00000000..d2f89028 --- /dev/null +++ b/src/test/resources/resetSharedSecret.json @@ -0,0 +1,3 @@ +{ + "sharedSecret": "kdfhskdjfh2398234820942" +} \ No newline at end of file diff --git a/src/test/resources/updateWebhook.json b/src/test/resources/updateWebhook.json new file mode 100644 index 00000000..6ab3432f --- /dev/null +++ b/src/test/resources/updateWebhook.json @@ -0,0 +1,19 @@ +{ + "resultCode": 0, + "result": { + "apiClientId": "2382749284kjdskfhjsfhkjds", + "scopeObjectId": 827634728462, + "apiClientName": "testClientName1", + "callbackUrl": "https://foo-callback.smar.com/webhook", + "createdAt": "2023-01-30T11:42:30Z", + "modifiedAt": "2023-05-30T11:42:30Z", + "disabledDetails": "", + "enabled": true, + "events": ["delete", "add"], + "scope": "some-scope-string", + "sharedSecret": "sdklfldsjwe9oak232m4n22424kh2390283923", + "status": "ENABLED", + "version": 1.0 + }, + "message": "SUCCESS" +} diff --git a/src/test/resources/webhookException.json b/src/test/resources/webhookException.json new file mode 100644 index 00000000..b9b3c816 --- /dev/null +++ b/src/test/resources/webhookException.json @@ -0,0 +1 @@ +{"errorCode":1032,"message":"Something went wrong"} \ No newline at end of file