Skip to content

Commit

Permalink
Issue 77
Browse files Browse the repository at this point in the history
  • Loading branch information
dshannonau committed Apr 3, 2015
1 parent bf10ac0 commit 150a61e
Show file tree
Hide file tree
Showing 25 changed files with 658 additions and 394 deletions.
3 changes: 2 additions & 1 deletion src/main/java/test/api/model/StravaActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ public static void validateActivity(final StravaActivity activity, final Integer
assertNotNull(activity.getWeightedAverageWatts());
}
} else {
assertNull("Activity " + activity.getId() + " has unexpected cadence", activity.getAverageCadence());
// TODO Issue javastravav3api#84 Apparently optional assertNull("Activity " + activity.getId() + " has unexpected cadence",
// activity.getAverageCadence());
assertNull(activity.getAverageWatts());
assertNull(activity.getDeviceWatts());
assertNull(activity.getWeightedAverageWatts());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ public class StravaSegmentLeaderboardTest extends BeanTest<StravaSegmentLeaderbo

public static void validate(final StravaSegmentLeaderboard leaderboard) {
assertNotNull(leaderboard);
assertNotNull(leaderboard.getAthleteEntries());
// Optional (if using API only) assertNotNull(leaderboard.getAthleteEntries());
assertNotNull(leaderboard.getEffortCount());
assertNotNull(leaderboard.getEntries());
assertNotNull(leaderboard.getEntryCount());
// TODO Apparently optional but see https://github.com/danshannon/javastravav3api/issues/22
// assertNotNull(leaderboard.getKomType());
assertNotNull(leaderboard.getNeighborhoodCount());
for (final StravaSegmentLeaderboardEntry entry : leaderboard.getAthleteEntries()) {
StravaSegmentLeaderboardEntryTest.validate(entry);
if (leaderboard.getAthleteEntries() != null) {
for (final StravaSegmentLeaderboardEntry entry : leaderboard.getAthleteEntries()) {
StravaSegmentLeaderboardEntryTest.validate(entry);
}
}
for (final StravaSegmentLeaderboardEntry entry : leaderboard.getEntries()) {
StravaSegmentLeaderboardEntryTest.validate(entry);
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/test/api/rest/APITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*/
public class APITest {
public static void forceDeleteActivity(final Integer activityId) {
if (activityId == null) {
return;
}
try {
apiWithFullAccess().deleteActivity(activityId);
} catch (final NotFoundException e) {
Expand Down Expand Up @@ -65,7 +68,7 @@ public static API apiWithWriteAccess() {
* @param comment
* @return
*/
public static StravaComment forceCreateComment(Integer activityId, String comment) throws Exception {
public static StravaComment forceCreateComment(final Integer activityId, final String comment) throws Exception {
return apiWithFullAccess().createComment(activityId, comment);
}

Expand All @@ -74,7 +77,7 @@ public static StravaComment forceCreateComment(Integer activityId, String commen
*/
public static StravaComment createPrivateActivityWithComment(final String name) throws Exception {
final StravaActivity activity = createPrivateActivity(name);
StravaComment comment = forceCreateComment(activity.getId(),"name");
final StravaComment comment = forceCreateComment(activity.getId(), "name");
return comment;
}

Expand All @@ -85,5 +88,5 @@ public static StravaActivity createPrivateActivity(final String name) {
assertEquals(Boolean.TRUE, response.getPrivateActivity());
return response;
}

}
43 changes: 31 additions & 12 deletions src/main/java/test/api/rest/activity/CreateCommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import test.api.model.StravaCommentTest;
import test.api.rest.APITest;
import test.issues.strava.Issue30;
import test.issues.strava.Issue74;
import test.utils.RateLimitedTestRunner;
import test.utils.TestUtils;

Expand Down Expand Up @@ -51,18 +53,23 @@ public void testCreateComment_invalidComment() throws Exception {
@Test
public void testCreateComment_noWriteAccess() throws Exception {
RateLimitedTestRunner.run(() -> {

StravaComment comment = null;
try {
comment = api().createComment(TestUtils.ACTIVITY_FOR_AUTHENTICATED_USER, "Test - ignore");
} catch (final UnauthorizedException e) {
// Expected
return;
}
forceDeleteComment(comment);
fail("Created a comment despite not having write access");

});
// TODO This is a workaround for issue javastravav3api#30
if (new Issue30().isIssue()) {
return;
}
// End of workaround

StravaComment comment = null;
try {
comment = api().createComment(TestUtils.ACTIVITY_FOR_AUTHENTICATED_USER, "Test - ignore");
} catch (final UnauthorizedException e) {
// Expected
return;
}
forceDeleteComment(comment);
fail("Created a comment despite not having write access");

});
}

@Test
Expand Down Expand Up @@ -90,6 +97,12 @@ public void testCreateComment_privateActivity() throws Exception {
@Test
public void testCreateComment_privateActivityAuthenticatedUser() throws Exception {
RateLimitedTestRunner.run(() -> {
// TODO This is a workaround for issue javastravav3api#30
if (new Issue30().isIssue()) {
return;
}
// End of workaround

StravaComment comment = null;
try {
comment = apiWithViewPrivate().createComment(TestUtils.ACTIVITY_PRIVATE, "Test - ignore");
Expand All @@ -110,6 +123,12 @@ public void testCreateComment_privateActivityAuthenticatedUser() throws Exceptio
@Test
public void testCreateComment_privateActivityNoViewPrivate() throws Exception {
RateLimitedTestRunner.run(() -> {
// TODO This is a workaround for issue javastravav3api#74
if (new Issue74().isIssue()) {
return;
}
// End of workaround

StravaComment comment = null;
try {
comment = apiWithWriteAccess().createComment(TestUtils.ACTIVITY_PRIVATE, "Test - ignore");
Expand Down
42 changes: 19 additions & 23 deletions src/main/java/test/api/rest/activity/CreateManualActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import static org.junit.Assert.fail;
import javastrava.api.v3.model.StravaActivity;
import javastrava.api.v3.model.reference.StravaActivityType;
import javastrava.api.v3.service.exception.BadRequestException;
import javastrava.api.v3.service.exception.UnauthorizedException;

import org.junit.Test;

import test.api.model.StravaActivityTest;
import test.api.rest.APITest;
import test.issues.strava.Issue49;
import test.utils.RateLimitedTestRunner;
import test.utils.TestUtils;

Expand Down Expand Up @@ -48,24 +50,26 @@ public void testCreateManualActivity_accessTokenDoesNotHaveWriteAccess() throws
@Test
public void testCreateManualActivity_invalidType() throws Exception {
RateLimitedTestRunner.run(() -> {
// Type must be one of the specified values
// This is only a workaround for issue javastravav3api#49
if (new Issue49().isIssue()) {
return;
}
// End of workaround

// Type must be one of the specified values
final StravaActivity activity = TestUtils.createDefaultActivity("CreateManualActivityTest.testCreateManualActivity_invalidType");
StravaActivity stravaResponse = null;
activity.setType(StravaActivityType.UNKNOWN);
try {
stravaResponse = apiWithWriteAccess().createManualActivity(activity);
} catch (final IllegalArgumentException e1) {
} catch (final BadRequestException e1) {
// Expected behaviour
return;
} catch (final Exception e2) {
// Ignore ALL other exceptions
}

// If it did get created, delete it again
forceDeleteActivity(stravaResponse);

return;
}
// If it did get created, delete it again
forceDeleteActivity(stravaResponse);
fail("Created an activity with invalid type in error");
});
});
}

@Test
Expand All @@ -77,11 +81,9 @@ public void testCreateManualActivity_noElapsedTime() throws Exception {
activity.setElapsedTime(null);
try {
stravaResponse = apiWithWriteAccess().createManualActivity(activity);
} catch (final IllegalArgumentException e1) {
} catch (final BadRequestException e1) {
// Expected behaviour
return;
} catch (final Exception e2) {
// Ignore ALL other exceptions
}

// If it did get created, delete it again
Expand Down Expand Up @@ -114,11 +116,9 @@ public void testCreateManualActivity_noName() throws Exception {
activity.setName(null);
try {
stravaResponse = apiWithWriteAccess().createManualActivity(activity);
} catch (final IllegalArgumentException e1) {
} catch (final BadRequestException e1) {
// Expected behaviour
return;
} catch (final Exception e2) {
// Ignore ALL other exceptions
}

// If it did get created, delete it again
Expand All @@ -139,11 +139,9 @@ public void testCreateManualActivity_noStartDate() throws Exception {
activity.setStartDateLocal(null);
try {
stravaResponse = apiWithWriteAccess().createManualActivity(activity);
} catch (final IllegalArgumentException e1) {
} catch (final BadRequestException e) {
// Expected behaviour
return;
} catch (final Exception e2) {
// Ignore ALL other exceptions
}

// If it did get created, delete it again
Expand All @@ -162,11 +160,9 @@ public void testCreateManualActivity_noType() throws Exception {
activity.setType(null);
try {
stravaResponse = apiWithWriteAccess().createManualActivity(activity);
} catch (final IllegalArgumentException e1) {
} catch (final BadRequestException e1) {
// Expected behaviour
return;
} catch (final Exception e2) {
// Ignore ALL other exceptions
}

// If it did get created, delete it again
Expand Down
40 changes: 26 additions & 14 deletions src/main/java/test/api/rest/activity/DeleteCommentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.junit.Test;

import test.api.rest.APITest;
import test.issues.strava.Issue63;
import test.issues.strava.Issue74;
import test.utils.RateLimitedTestRunner;
import test.utils.TestUtils;

Expand Down Expand Up @@ -34,16 +36,22 @@ public void testDeleteComment_byIds() throws Exception {
@Test
public void testDeleteComment_noWriteAccess() throws Exception {
RateLimitedTestRunner.run(() -> {
final StravaComment comment = apiWithWriteAccess().createComment(TestUtils.ACTIVITY_WITH_COMMENTS, "Test - ignore");
try {
api().deleteComment(comment.getActivityId(), comment.getId());
} catch (final UnauthorizedException e) {
// Expected - delete the comment anyway
forceDeleteComment(comment);
return;
}
fail("Deleted a comment using a token without write access");
});
// TODO This is a workaround for issue javastravav3api#63
if (new Issue63().isIssue()) {
return;
}
// End of workaround

final StravaComment comment = apiWithWriteAccess().createComment(TestUtils.ACTIVITY_WITH_COMMENTS, "Test - ignore");
try {
api().deleteComment(comment.getActivityId(), comment.getId());
} catch (final UnauthorizedException e) {
// Expected - delete the comment anyway
forceDeleteComment(comment);
return;
}
fail("Deleted a comment using a token without write access");
});
}

/**
Expand All @@ -55,8 +63,7 @@ public void testDeleteComment_noWriteAccess() throws Exception {
@Test
public void testDeleteComment_privateActivityAuthenticatedUser() throws Exception {
RateLimitedTestRunner.run(() -> {
final StravaComment comment = APITest
.createPrivateActivityWithComment("DeleteCommentTest.testDeleteComment_privateActivityAuthenticatedUser");
final StravaComment comment = APITest.createPrivateActivityWithComment("DeleteCommentTest.testDeleteComment_privateActivityAuthenticatedUser");

// Attempt to delete with full access
try {
Expand All @@ -79,8 +86,13 @@ public void testDeleteComment_privateActivityAuthenticatedUser() throws Exceptio
@Test
public void testDeleteComment_privateActivityNoViewPrivate() throws Exception {
RateLimitedTestRunner.run(() -> {
final StravaComment comment = APITest
.createPrivateActivityWithComment("DeleteCommentTest.testDeleteComment_privateActivityNoViewPrivate");
// TODO This is a workaround for issue javastravaapiv3#74
if (new Issue74().isIssue()) {
return;
}
// End of workaround

final StravaComment comment = APITest.createPrivateActivityWithComment("DeleteCommentTest.testDeleteComment_privateActivityNoViewPrivate");

// Attempt to delete with write access (but not view_private)
try {
Expand Down
31 changes: 17 additions & 14 deletions src/main/java/test/api/rest/activity/GetActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import javastrava.api.v3.model.StravaActivity;
import javastrava.api.v3.model.StravaSegmentEffort;
import javastrava.api.v3.model.reference.StravaResourceState;
import javastrava.api.v3.service.exception.NotFoundException;
import javastrava.api.v3.service.exception.UnauthorizedException;

import org.junit.Test;
Expand Down Expand Up @@ -127,15 +128,13 @@ public void testGetActivity_privateAuthenticatedUser() throws Exception {
@Test
public void testGetActivity_privateBelongsToOtherUser() throws Exception {
RateLimitedTestRunner.run(() -> {
final StravaActivity activity = api().getActivity(TestUtils.ACTIVITY_PRIVATE_OTHER_USER, null);

// Should get an activity which only has an id
assertNotNull(activity);
final StravaActivity comparisonActivity = new StravaActivity();
comparisonActivity.setId(TestUtils.ACTIVITY_PRIVATE_OTHER_USER);
comparisonActivity.setResourceState(StravaResourceState.PRIVATE);
assertEquals(comparisonActivity, activity);
StravaActivityTest.validateActivity(activity);
try {
api().getActivity(TestUtils.ACTIVITY_PRIVATE_OTHER_USER, null);
} catch (final UnauthorizedException e) {
// expected
return;
}
fail("Returned private activity belonging to another user");
});
}

Expand All @@ -151,7 +150,7 @@ public void testGetActivity_privateNoViewPrivateScope() throws Exception {
StravaActivity response = null;
try {
response = api().getActivity(activity.getId(), null);
} catch (UnauthorizedException e) {
} catch (final UnauthorizedException e) {
// expected
return;
} finally {
Expand Down Expand Up @@ -187,9 +186,13 @@ public void testGetActivity_run() throws Exception {
@Test
public void testGetActivity_unknownActivity() throws Exception {
RateLimitedTestRunner.run(() -> {
final StravaActivity activity = api().getActivity(TestUtils.ACTIVITY_INVALID, null);

assertNull("Got an activity for an invalid activity id " + TestUtils.ACTIVITY_INVALID, activity);
try {
api().getActivity(TestUtils.ACTIVITY_INVALID, null);
} catch (final NotFoundException e) {
// expected
return;
}
fail("Returned a non-existent activity");
});
}
}
Loading

0 comments on commit 150a61e

Please sign in to comment.