Skip to content

Commit

Permalink
Fixes and workarounds for issues from javastravav3api#75 and
Browse files Browse the repository at this point in the history
javastravav3api#77
  • Loading branch information
dshannonau committed Apr 7, 2015
1 parent aa6023f commit 6cfd1a3
Show file tree
Hide file tree
Showing 14 changed files with 346 additions and 73 deletions.
31 changes: 16 additions & 15 deletions src/main/java/test/api/rest/activity/ListActivityPhotosTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ public void testListActivityPhotos_hasNoPhotos() throws Exception {
final StravaPhoto[] photos = api().listActivityPhotos(TestUtils.ACTIVITY_WITHOUT_PHOTOS);

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

assertNotNull("Photos returned as null for a valid activity without photos", photos);
assertEquals("Photos were returned for an activity which has no photos", 0, photos.length);
});
assertNotNull("Photos returned as null for a valid activity without photos", photos);
assertEquals("Photos were returned for an activity which has no photos", 0, photos.length);
});
}

/**
Expand Down Expand Up @@ -142,15 +142,16 @@ public void testListActivityPhotos_privateWithoutViewPrivate() throws Exception
@Test
public void testListActivityPhotos_privateWithViewPrivate() throws Exception {
RateLimitedTestRunner.run(() -> {
final StravaPhoto[] photos = apiWithViewPrivate().listActivityPhotos(TestUtils.ACTIVITY_PRIVATE_WITH_PHOTOS);
assertNotNull(photos);
// TODO This is a workaround for issue javastravav3api#68
if (new Issue68().isIssue()) {
return;
}
// End of workaround
if (new Issue68().isIssue()) {
return;
}
// End of workaround

final StravaPhoto[] photos = apiWithViewPrivate().listActivityPhotos(TestUtils.ACTIVITY_PRIVATE_WITH_PHOTOS);
assertNotNull(photos);

assertFalse(photos.length == 0);
});
assertFalse(photos.length == 0);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import test.api.model.StravaActivityTest;
import test.api.rest.util.ArrayCallback;
import test.api.rest.util.PagingArrayMethodTest;
import test.issues.strava.Issue18;
import test.utils.RateLimitedTestRunner;

public class ListFriendsActivitiesTest extends PagingArrayMethodTest<StravaActivity, Integer> {
Expand Down Expand Up @@ -71,4 +72,15 @@ protected void validate(final StravaActivity activity, final Integer id, final S

}

@Override
public void testPageNumberAndSize() throws Exception {
// TODO This is a workaround for issue javastravav3api#18
// When the issue is fixed, remove this method altogether
if (new Issue18().isIssue()) {
return;
}
// End of workaround
super.testPageNumberAndSize();
}

}
36 changes: 31 additions & 5 deletions src/main/java/test/api/rest/activity/UpdateActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javastrava.api.v3.model.StravaActivity;
import javastrava.api.v3.model.StravaActivityUpdate;
import javastrava.api.v3.model.reference.StravaActivityType;
import javastrava.api.v3.model.reference.StravaResourceState;
import javastrava.api.v3.service.exception.NotFoundException;
import javastrava.api.v3.service.exception.StravaUnknownAPIException;
import javastrava.api.v3.service.exception.UnauthorizedException;
Expand All @@ -16,6 +17,7 @@

import test.api.model.StravaActivityTest;
import test.api.rest.APITest;
import test.issues.strava.Issue36;
import test.issues.strava.Issue72;
import test.utils.RateLimitedTestRunner;
import test.utils.TestUtils;
Expand All @@ -32,18 +34,36 @@ public class UpdateActivityTest extends APITest {
* if not found
*/
private StravaActivity createUpdateAndDelete(final StravaActivity activity, final StravaActivityUpdate update) throws Exception {
final StravaActivity response = apiWithWriteAccess().createManualActivity(activity);
final StravaActivity response = apiWithFullAccess().createManualActivity(activity);
StravaActivity updateResponse = null;
try {
updateResponse = apiWithWriteAccess().updateActivity(response.getId(), update);
updateResponse = apiWithFullAccess().updateActivity(response.getId(), update);
} catch (final Exception e) {
forceDeleteActivity(response);
throw e;
}
updateResponse = waitForUpdateCompletion(updateResponse);
forceDeleteActivity(response);
return updateResponse;
}

/**
* @param updateResponse
* @return
*/
private StravaActivity waitForUpdateCompletion(final StravaActivity updateResponse) throws Exception {
int i = 0;
StravaActivity response = null;
while (i < 600) {
response = apiWithFullAccess().getActivity(updateResponse.getId(), null);
i++;
if (response.getResourceState() != StravaResourceState.UPDATING) {
return response;
}
}
return response;
}

/**
* <p>
* Test attempting to update an activity using a token that doesn't have write access
Expand Down Expand Up @@ -142,7 +162,7 @@ public void testUpdateActivity_validUpdateAllAtOnce() throws Exception {
final String description = text.sentence();
final String name = text.sentence();
final StravaActivityType type = StravaActivityType.RIDE;
final Boolean privateActivity = Boolean.FALSE;
final Boolean privateActivity = Boolean.TRUE;
final Boolean commute = Boolean.TRUE;
final Boolean trainer = Boolean.TRUE;
final String gearId = TestUtils.GEAR_VALID_ID;
Expand All @@ -163,13 +183,19 @@ public void testUpdateActivity_validUpdateAllAtOnce() throws Exception {
StravaActivityTest.validateActivity(updateResponse);
assertEquals(description, updateResponse.getDescription());

assertEquals(commute, updateResponse.getCommute());
assertEquals(gearId, updateResponse.getGearId());
assertEquals(name, updateResponse.getName());
assertEquals(privateActivity, updateResponse.getPrivateActivity());
assertEquals(trainer, updateResponse.getTrainer());
assertEquals(type, updateResponse.getType());
});

// TODO This is a workaround for javastravav3api#36
// When issue fixed, restore the assertions to normal code
if (!new Issue36().isIssue()) {
assertEquals(commute, updateResponse.getCommute());
}
// End of workaround
});
}

@Test
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/test/api/rest/segment/GetSegmentLeaderboardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class GetSegmentLeaderboardTest extends PagingArrayMethodTest<StravaSegme
protected ArrayCallback<StravaSegmentLeaderboardEntry> callback() {
return (paging -> {
final List<StravaSegmentLeaderboardEntry> list = api().getSegmentLeaderboard(TestUtils.SEGMENT_VALID_ID, null, null, null, null, null, null,
paging.getPage(), paging.getPageSize(), null).getEntries();
paging.getPage(), paging.getPageSize(), 0).getEntries();
final StravaSegmentLeaderboardEntry[] entries = new StravaSegmentLeaderboardEntry[list.size()];
int i = 0;
for (final StravaSegmentLeaderboardEntry entry : list) {
Expand Down Expand Up @@ -112,16 +112,16 @@ public void testGetSegmentLeaderboard_filterByGender() throws Exception {
public void testGetSegmentLeaderboard_filterByInvalidClub() throws Exception {
RateLimitedTestRunner.run(() -> {
// TODO This is a workaround for issue 23
final Issue23 issue23 = new Issue23();
if (issue23.isIssue()) {
return;
}
// End of workaround
final Issue23 issue23 = new Issue23();
if (issue23.isIssue()) {
return;
}
// End of workaround

final StravaSegmentLeaderboard leaderboard = api().getSegmentLeaderboard(TestUtils.SEGMENT_VALID_ID, null, null, null, null,
TestUtils.CLUB_INVALID_ID, null, null, null, null);
assertNull(leaderboard);
});
final StravaSegmentLeaderboard leaderboard = api().getSegmentLeaderboard(TestUtils.SEGMENT_VALID_ID, null, null, null, null,
TestUtils.CLUB_INVALID_ID, null, null, null, null);
assertNull(leaderboard);
});
}

// 9. Filter by leaderboard date range
Expand Down Expand Up @@ -181,12 +181,12 @@ public void testGetSegmentLeaderboard_privateSegment() throws Exception {
final StravaSegmentLeaderboard leaderboard = api().getSegmentLeaderboard(TestUtils.SEGMENT_PRIVATE_ID, null, null, null, null, null, null, null,
null, null);
// Should return an empty leaderboard
assertNotNull(leaderboard);
assertNotNull(leaderboard.getEntries());
// Workaround for issue javastrava-api #71 - see https://github.com/danshannon/javastravav3api/issues/71
// assertTrue(leaderboard.getEntries().isEmpty());
// End of workaround
});
assertNotNull(leaderboard);
assertNotNull(leaderboard.getEntries());
// Workaround for issue javastrava-api #71 - see https://github.com/danshannon/javastravav3api/issues/71
// assertTrue(leaderboard.getEntries().isEmpty());
// End of workaround
});
}

@Test
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/test/api/rest/stream/GetActivityStreamsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import test.api.model.StravaStreamTest;
import test.api.rest.APITest;
import test.issues.strava.Issue21;
import test.issues.strava.Issue88;
import test.utils.RateLimitedTestRunner;
import test.utils.TestUtils;

Expand Down Expand Up @@ -130,6 +131,9 @@ public void testGetActivityStreams_invalidDownsampleType() throws Exception {
@Test
public void testGetActivityStreams_invalidStreamType() throws Exception {
RateLimitedTestRunner.run(() -> {
if (new Issue88().isIssue()) {
return;
}
try {
api().getActivityStreams(TestUtils.ACTIVITY_FOR_AUTHENTICATED_USER, StravaStreamType.UNKNOWN.getValue(), null, null);
} catch (final BadRequestException e) {
Expand All @@ -150,13 +154,13 @@ public void testGetActivityStreams_oneStreamType() throws Exception {
assertEquals(1, streams.length);
assertEquals(StravaStreamType.DISTANCE, streams[0].getType());
// TODO This is a workaround for issue javastravav3api#21
if (new Issue21().isIssue()) {
return;
}
// End of workaround
if (new Issue21().isIssue()) {
return;
}
// End of workaround

validateArray(streams);
});
validateArray(streams);
});
}

/**
Expand All @@ -173,13 +177,13 @@ public void testGetActivityStreams_validActivityAuthenticatedUser() throws Excep
final StravaStream[] streams = api().getActivityStreams(TestUtils.ACTIVITY_FOR_AUTHENTICATED_USER, getAllStreamTypes(), null, null);
assertNotNull(streams);
// TODO This is a workaround for issue javastravav3api#21
if (new Issue21().isIssue()) {
return;
}
// End of workaround
if (new Issue21().isIssue()) {
return;
}
// End of workaround

validateArray(streams);
});
validateArray(streams);
});
}

// 3. Valid activity for other user
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/test/api/rest/stream/GetEffortStreamsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import test.api.model.StravaStreamTest;
import test.api.rest.APITest;
import test.issues.strava.Issue87;
import test.issues.strava.Issue91;
import test.utils.RateLimitedTestRunner;
import test.utils.TestUtils;

Expand Down Expand Up @@ -105,14 +107,20 @@ public void testGetEffortStreams_invalidEffort() throws Exception {
@Test
public void testGetEffortStreams_invalidStreamType() throws Exception {
RateLimitedTestRunner.run(() -> {
try {
api().getEffortStreams(TestUtils.SEGMENT_EFFORT_VALID_ID, StravaStreamType.UNKNOWN.toString(), null, null);
} catch (final BadRequestException e) {
// Expected
return;
}
fail("Should have got an BadRequestException, but didn't");
});
// TODO Workaround for issue javastravav3api#91
if (new Issue91().isIssue()) {
return;
}
// End of workaround

try {
api().getEffortStreams(TestUtils.SEGMENT_EFFORT_VALID_ID, StravaStreamType.UNKNOWN.toString(), null, null);
} catch (final BadRequestException e) {
// Expected
return;
}
fail("Should have got an BadRequestException, but didn't");
});
}

// 5. Only one stream type
Expand Down Expand Up @@ -184,6 +192,12 @@ public void testGetEffortStreams_privateActivityWithViewPrivate() throws Excepti
@Test
public void testGetEffortStreams_privateSegmentWithoutViewPrivate() throws Exception {
RateLimitedTestRunner.run(() -> {
// TODO Workaround for issue javastravav3api#87
if (new Issue87().isIssue()) {
return;
}
// End of workaround

final StravaStream[] streams = api().getEffortStreams(TestUtils.SEGMENT_EFFORT_PRIVATE_ID, getAllStreamTypes(), null, null);
assertNotNull(streams);
assertTrue(streams.length == 0);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/test/api/rest/stream/GetSegmentStreamsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import test.api.model.StravaStreamTest;
import test.api.rest.APITest;
import test.issues.strava.Issue87;
import test.issues.strava.Issue89;
import test.issues.strava.Issue90;
import test.utils.RateLimitedTestRunner;
import test.utils.TestUtils;

Expand Down Expand Up @@ -48,6 +50,9 @@ public void testGetSegmentStreams_downsampledByDistance() throws Exception {
@Test
public void testGetSegmentStreams_downsampledByTime() throws Exception {
RateLimitedTestRunner.run(() -> {
if (new Issue89().isIssue()) {
return;
}
for (final StravaStreamResolutionType resolutionType : StravaStreamResolutionType.values()) {
if (resolutionType != StravaStreamResolutionType.UNKNOWN) {
try {
Expand Down Expand Up @@ -109,6 +114,9 @@ public void testGetSegmentStreams_invalidSegment() throws Exception {
@Test
public void testGetSegmentStreams_invalidStreamType() throws Exception {
RateLimitedTestRunner.run(() -> {
if (new Issue90().isIssue()) {
return;
}
try {
api().getSegmentStreams(TestUtils.SEGMENT_VALID_ID, StravaStreamType.UNKNOWN.toString(), null, null);
} catch (final BadRequestException e) {
Expand Down
39 changes: 30 additions & 9 deletions src/main/java/test/api/rest/upload/UploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,41 @@ public void testUpload_badFileContent() throws Exception {
RateLimitedTestRunner.run(() -> {
final File file = new File("baddata.gpx");
final TypedFile typedFile = new TypedFile("text/xml", file);
StravaUploadResponse response = null;
try {
response = apiWithWriteAccess().upload(StravaActivityType.RIDE, "UploadServicesImplTest.testUpload_noName", null, null, null, "gpx", "ABC",
typedFile);
} catch (final IllegalArgumentException e) {
// Expected
return;
}
final StravaUploadResponse response = apiWithWriteAccess().upload(StravaActivityType.RIDE, "UploadServicesImplTest.testUpload_noName", null, null,
null, "gpx", "ABC", typedFile);

final StravaUploadResponse status = waitForUploadStatus(response);
APITest.forceDeleteActivity(response.getActivityId());
fail("Uploaded a file with an invalid file!");
if (status.getStatus().equals("Your activity is ready.")) {
fail("Uploaded a file with an invalid file!");
}

});
}

/**
* @param response
* @return
*/
private StravaUploadResponse waitForUploadStatus(final StravaUploadResponse response) {
int i = 0;
StravaUploadResponse status = null;
while (i < 30) {
status = api().checkUploadStatus(response.getId());
if (status.getStatus().equals("Your activity is still being processed.")) {
try {
Thread.sleep(2000);
i++;
} catch (final InterruptedException e) {
// ignore
}
} else {
return status;
}
}
return status;
}

@Test
public void testUpload_noFile() throws Exception {
RateLimitedTestRunner.run(() -> {
Expand Down
Loading

0 comments on commit 6cfd1a3

Please sign in to comment.