Skip to content

Commit

Permalink
Part 4 of unit test coverage + tiny readme update to add developer ag…
Browse files Browse the repository at this point in the history
…reement link (#74)

* add legal agreement to README.md

* adding tests to UserResourcesImplTest

* adding tests to SightResourcesImplTest

* code style fixes

* code review comments - part 1

---------

Co-authored-by: Priyanka Lakhe <[email protected]>
  • Loading branch information
priyankalakhe and Priyanka Lakhe authored Oct 28, 2023
1 parent 6e7f44b commit 7a02db8
Show file tree
Hide file tree
Showing 16 changed files with 466 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ Each specific release is available for download via [Github](https://github.com/

See <https://github.com/smartsheet/smartsheet-java-sdk/releases>

## Developer Agreement
Review the [Developer Program Agreement](https://www.smartsheet.com/legal/developer-program-agreement).

## Acknowledgements

We would like to thank the following people for their contributions to this project:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public PagedResult<Sight> listSights(PaginationParameters paging, Date modifiedS
* <p>
* It mirrors to the following Smartsheet REST API method: GET /sights/{sightId}
*
* @param sightId the Id of the Sight
* @param sightId the id of the Sight
* @return the Sight resource.
* @throws IllegalArgumentException if any argument is null or empty string
* @throws InvalidRequestException if there is any problem with the REST API request
Expand All @@ -108,7 +108,7 @@ public Sight getSight(long sightId) throws SmartsheetException {
* <p>
* It mirrors to the following Smartsheet REST API method: GET /sights/{sightId}
*
* @param sightId the Id of the Sight
* @param sightId the id of the Sight
* @param level compatibility level
* @return the Sight resource.
* @throws IllegalArgumentException if any argument is null or empty string
Expand All @@ -127,7 +127,7 @@ public Sight getSight(long sightId, Integer level) throws SmartsheetException {
* <p>
* It mirrors to the following Smartsheet REST API method: GET /sights/{sightId}
*
* @param sightId the Id of the Sight
* @param sightId the id of the Sight
* @param level compatibility level
* @param includes optional parameters to include
* @return the Sight resource.
Expand Down Expand Up @@ -173,7 +173,7 @@ public Sight updateSight(Sight sight) throws SmartsheetException {
* <p>
* It mirrors to the following Smartsheet REST API method: DELETE /sights/{sightId}
*
* @param sightId the Id of the Sight
* @param sightId the id of the Sight
*
* @throws IllegalArgumentException if any argument is null or empty string
* @throws InvalidRequestException if there is any problem with the REST API request
Expand All @@ -191,7 +191,7 @@ public void deleteSight(long sightId) throws SmartsheetException {
* <p>
* It mirrors to the following Smartsheet REST API method: POST /sights/{sightId}/copy
*
* @param sightId the Id of the Sight
* @param sightId the id of the Sight
* @param destination the destination to copy to
* @return the newly created Sight resource.
* @throws IllegalArgumentException if any argument is null or empty string
Expand All @@ -210,7 +210,7 @@ public Sight copySight(long sightId, ContainerDestination destination) throws Sm
* <p>
* It mirrors to the following Smartsheet REST API method: POST /sights/{sightId}/move
*
* @param sightId the Id of the Sight
* @param sightId the id of the Sight
* @param destination the destination to copy to
* @return the newly created Sight resource.
* @throws IllegalArgumentException if any argument is null or empty string
Expand All @@ -229,7 +229,7 @@ public Sight moveSight(long sightId, ContainerDestination destination) throws Sm
* <p>
* It mirrors to the following Smartsheet REST API method: POST /sights/{sightId}/publish
*
* @param sightId the Id of the Sight
* @param sightId the id of the Sight
* @return the Sight's publish status.
* @throws IllegalArgumentException if any argument is null or empty string
* @throws InvalidRequestException if there is any problem with the REST API request
Expand All @@ -247,7 +247,7 @@ public SightPublish getPublishStatus(long sightId) throws SmartsheetException {
* <p>
* It mirrors to the following Smartsheet REST API method: POST /sights/{sightId}/publish
*
* @param sightId the Id of the Sight
* @param sightId the id of the Sight
* @param sightPublish the SightPublish object containing publish status
* @return the Sight's publish status.
* @throws IllegalArgumentException if any argument is null or empty string
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/smartsheet/api/models/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Group extends NamedModel<Long> {
private String owner;

/**
* The the id of the owner of the group.
* The id of the owner of the group.
*/
private Long ownerId;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/smartsheet/api/models/Sight.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class Sight extends NamedModel<Long> {
private Source source;

/**
* A workspace object, limited to only Id and Name
* A workspace object, limited to only id and Name
*/
private Workspace workspace;

Expand Down
150 changes: 150 additions & 0 deletions src/test/java/com/smartsheet/api/internal/SightResourcesImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,25 @@

package com.smartsheet.api.internal;

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.ContainerDestination;
import com.smartsheet.api.models.Sight;
import com.smartsheet.api.models.SightPublish;
import com.smartsheet.api.models.enums.AccessLevel;
import com.smartsheet.api.models.enums.SightInclusion;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.util.EnumSet;

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

class SightResourcesImplTest extends ResourcesImplBase {
private SightResourcesImpl sightResourcesImpl;
Expand All @@ -36,9 +50,145 @@ public void before() {
sightResourcesImpl = new SightResourcesImpl(smartsheetImpl);
}

@Test
void testListSights() throws SmartsheetException, IOException {
server.setResponseBody(new File("src/test/resources/listSights.json"));

PaginationParameters pagination = new PaginationParameters();
pagination.setIncludeAll(true);
pagination.setPageSize(1);
pagination.setPage(1);

PagedResult<Sight> sightPagedResult = sightResourcesImpl.listSights(pagination, null);
assertThat(sightPagedResult.getData()).isNotNull();
assertThat(sightPagedResult.getData()).isNotEmpty();
assertThat(sightPagedResult.getData()).hasSize(1);
assertThat(sightPagedResult.getData().get(0).getAccessLevel()).isEqualTo(AccessLevel.VIEWER);
assertThat(sightPagedResult.getData().get(0).getFavorite()).isFalse();
assertThat(sightPagedResult.getData().get(0).getWidgets()).isEmpty();
assertThat(sightPagedResult.getData().get(0).getWorkspace()).isNotNull();
assertThat(sightPagedResult.getData().get(0).getPermalink()).isNotBlank();
}

@Test
void testGetSight() throws SmartsheetException, IOException {
server.setResponseBody(new File("src/test/resources/getSight.json"));

Sight sight = sightResourcesImpl.getSight(12345L);
assertThat(sight).isNotNull();
assertThat(sight.getAccessLevel()).isEqualTo(AccessLevel.VIEWER);
assertThat(sight.getFavorite()).isFalse();
assertThat(sight.getWidgets()).isEmpty();
assertThat(sight.getWorkspace()).isNotNull();
assertThat(sight.getPermalink()).isNotBlank();
}

@Test
void testGetSightWithLevel() throws SmartsheetException, IOException {
server.setResponseBody(new File("src/test/resources/getSight.json"));

Sight sight = sightResourcesImpl.getSight(12345L, 1);
assertThat(sight).isNotNull();
assertThat(sight.getAccessLevel()).isEqualTo(AccessLevel.VIEWER);
assertThat(sight.getFavorite()).isFalse();
assertThat(sight.getWidgets()).isEmpty();
assertThat(sight.getWorkspace()).isNotNull();
assertThat(sight.getPermalink()).isNotBlank();
}

@Test
void testGetSightWithLevelAndSightInclusion() throws SmartsheetException, IOException {
server.setResponseBody(new File("src/test/resources/getSight.json"));

EnumSet<SightInclusion> includes = EnumSet.of(SightInclusion.SOURCE);

Sight sight = sightResourcesImpl.getSight(12345L, includes, 1);
assertThat(sight).isNotNull();
assertThat(sight.getAccessLevel()).isEqualTo(AccessLevel.VIEWER);
assertThat(sight.getFavorite()).isFalse();
assertThat(sight.getWidgets()).isEmpty();
assertThat(sight.getWorkspace()).isNotNull();
assertThat(sight.getPermalink()).isNotBlank();
}

@Test
void testUpdateSight_SightNull() {
assertThatThrownBy(() -> {
sightResourcesImpl.updateSight(null);
}).isInstanceOf(IllegalArgumentException.class);
}

@Test
void testUpdateSight() throws SmartsheetException, IOException {
server.setResponseBody(new File("src/test/resources/updateSight.json"));

PaginationParameters pagination = new PaginationParameters();
pagination.setIncludeAll(true);
pagination.setPageSize(1);
pagination.setPage(1);

Sight sight = sightResourcesImpl.updateSight(new Sight());
assertThat(sight).isNotNull();
assertThat(sight.getAccessLevel()).isEqualTo(AccessLevel.VIEWER);
assertThat(sight.getFavorite()).isFalse();
assertThat(sight.getWidgets()).isEmpty();
assertThat(sight.getWorkspace()).isNotNull();
assertThat(sight.getPermalink()).isNotBlank();
}

@Test
void updateWithNullSight() {
assertThatThrownBy(() -> sightResourcesImpl.updateSight(null))
.isInstanceOf(IllegalArgumentException.class);
}

@Test
void testDeleteSight() throws IOException {
server.setResponseBody(new File("src/test/resources/updateSight.json"));
assertThatCode(() -> sightResourcesImpl.deleteSight(12345L)).doesNotThrowAnyException();
}

@Test
void testSetPublishStatus() throws IOException, SmartsheetException {
server.setResponseBody(new File("src/test/resources/setSightPublishStatus.json"));
SightPublish sightPublish = sightResourcesImpl.setPublishStatus(1234L, new SightPublish());
assertThat(sightPublish.getReadOnlyFullAccessibleBy()).isEqualTo(Boolean.FALSE.toString());
assertThat(sightPublish.getReadOnlyFullEnabled()).isEqualTo(Boolean.FALSE);
assertThat(sightPublish.getReadOnlyFullUrl()).isNotBlank();
}

@Test
void testGetPublishStatus() throws IOException, SmartsheetException {
server.setResponseBody(new File("src/test/resources/getSightPublishStatus.json"));
SightPublish sightPublish = sightResourcesImpl.getPublishStatus(1234L);
assertThat(sightPublish.getReadOnlyFullAccessibleBy()).isEqualTo(Boolean.FALSE.toString());
assertThat(sightPublish.getReadOnlyFullEnabled()).isEqualTo(Boolean.FALSE);
assertThat(sightPublish.getReadOnlyFullUrl()).isNotBlank();
}

@Test
void testCopySight() throws SmartsheetException, IOException {
server.setResponseBody(new File("src/test/resources/updateSight.json"));

Sight sight = sightResourcesImpl.copySight(12345L, new ContainerDestination());
assertThat(sight).isNotNull();
assertThat(sight.getAccessLevel()).isEqualTo(AccessLevel.VIEWER);
assertThat(sight.getFavorite()).isFalse();
assertThat(sight.getWidgets()).isEmpty();
assertThat(sight.getWorkspace()).isNotNull();
assertThat(sight.getPermalink()).isNotBlank();
}

@Test
void testMoveSight() throws SmartsheetException, IOException {
server.setResponseBody(new File("src/test/resources/updateSight.json"));

Sight sight = sightResourcesImpl.moveSight(12345L, new ContainerDestination());
assertThat(sight).isNotNull();
assertThat(sight.getAccessLevel()).isEqualTo(AccessLevel.VIEWER);
assertThat(sight.getFavorite()).isFalse();
assertThat(sight.getWidgets()).isEmpty();
assertThat(sight.getWorkspace()).isNotNull();
assertThat(sight.getPermalink()).isNotBlank();
}
}
Loading

0 comments on commit 7a02db8

Please sign in to comment.