Skip to content

Commit

Permalink
Merge pull request #69 from smartsheet/personal/plakhe/more-unit-test…
Browse files Browse the repository at this point in the history
…-coverage

Adding unit test coverage - part 3
  • Loading branch information
priyankalakhe authored Sep 12, 2023
2 parents 5c38183 + ef47946 commit 11b031f
Show file tree
Hide file tree
Showing 17 changed files with 667 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -108,7 +108,7 @@ public PagedResult<CellHistory> 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
Expand Down Expand Up @@ -147,7 +147,7 @@ public PagedResult<CellHistory> 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public PagedResult<Webhook> listWebhooks(PaginationParameters paging) throws Sma
* <p>
* 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
Expand Down Expand Up @@ -148,7 +148,7 @@ public void deleteWebhook(long webhookId) throws SmartsheetException {
* <p>
* 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
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/smartsheet/api/models/Webhook.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
public class Webhook extends NamedModel<Long> {

/**
* 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;

Expand Down Expand Up @@ -100,7 +100,7 @@ public class Webhook extends NamedModel<Long> {
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
*/
Expand All @@ -109,15 +109,15 @@ 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;
return this;
}

/**
* Get the Id of the object that is subscripted to
* Get the ID of the object that is subscripted to
*
* @return scopeObjectId
*/
Expand All @@ -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;
Expand Down
123 changes: 123 additions & 0 deletions src/test/java/com/smartsheet/api/internal/EventResourcesImplTest.java
Original file line number Diff line number Diff line change
@@ -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");
}

}
Loading

0 comments on commit 11b031f

Please sign in to comment.