Skip to content

Commit

Permalink
Merge branch 'issue75'
Browse files Browse the repository at this point in the history
  • Loading branch information
dshannonau committed Mar 30, 2015
2 parents a8c3f4d + 445b858 commit 0de0e10
Show file tree
Hide file tree
Showing 34 changed files with 354 additions and 231 deletions.
5 changes: 4 additions & 1 deletion src/main/java/sample-test-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ test.segmentEffortServicesImplTest.segmentEffortPrivateId=

# Segment effort id for an effort on a private segment that belongs to another user
test.segmentEffortServicesImplTest.segmentEffortOtherUserPrivateId=


# Segment effort id for an effort on a private activity
test.segmentEffortServicesImplTest.segmentEffortPrivateActivityId=

##############
# SEGMENT SERVICES DATA
##############
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/test/api/model/StravaActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public static void validateActivity(final StravaActivity activity, final Integer
}
return;
}
if (state == StravaResourceState.META) {
if (state == StravaResourceState.META || state == StravaResourceState.PRIVATE) {
assertNull(activity.getAchievementCount());
assertNull(activity.getAthlete());
assertNull(activity.getName());
Expand Down Expand Up @@ -279,7 +279,7 @@ public static void validateActivity(final StravaActivity activity, final Integer
assertNull(activity.getMovingTime());
assertNull(activity.getName());
assertNull(activity.getPhotoCount());
// assertNull(activity.getPrivateActivity());
assertNull(activity.getPrivateActivity());
assertNull(activity.getSegmentEfforts());
assertNull(activity.getSplitsMetric());
assertNull(activity.getSplitsStandard());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/test/api/model/StravaClubTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void validate(final StravaClub club, final Integer id, final Strav
assertNull(club.getState());
return;
}
if (state == StravaResourceState.META) {
if (state == StravaResourceState.META || state == StravaResourceState.PRIVATE) {
return;
}
fail("Unexpected state " + state + " for club " + club);
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/test/api/model/StravaMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ public class StravaMapTest extends BeanTest<StravaMap> {
* @param id
* @param state
*/
public static void validateMap(final StravaMap map, final String id, final StravaResourceState state,
final StravaActivity activity) {
public static void validateMap(final StravaMap map, final String id, final StravaResourceState state, final StravaActivity activity) {
assertNotNull(map);
assertEquals(id, map.getId());
assertEquals(state, map.getResourceState());

if (activity != null && (activity.getManual() || activity.getTrainer())) {
if ((activity != null) && (activity.getManual() || activity.getTrainer())) {
return;
}

if (state == StravaResourceState.DETAILED) {
assertNotNull(map.getPolyline());
assertNotNull(map.getSummaryPolyline());
// Optional ßassertNotNull(map.getSummaryPolyline());
}
if (state == StravaResourceState.SUMMARY) {
assertNull(map.getPolyline());
Expand All @@ -42,7 +41,7 @@ public static void validateMap(final StravaMap map, final String id, final Strav
assertNotNull(map.getPolyline());
assertNotNull(map.getSummaryPolyline());
}
if (state == StravaResourceState.UNKNOWN || state == StravaResourceState.UPDATING) {
if ((state == StravaResourceState.UNKNOWN) || (state == StravaResourceState.UPDATING)) {
fail("Unexpected state " + state + " for map " + map);
}

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/test/api/model/StravaSegmentEffortTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ public static void validateSegmentEffort(final StravaSegmentEffort effort, final
assertEquals(id, effort.getId());
assertEquals(state, effort.getResourceState());

if (state == StravaResourceState.DETAILED || state == StravaResourceState.SUMMARY) {
if ((state == StravaResourceState.DETAILED) || (state == StravaResourceState.SUMMARY)) {
if (effort.getActivity() != null) {
StravaActivityTest.validateActivity(effort.getActivity(), effort.getActivity().getId(), effort.getActivity()
.getResourceState());
StravaActivityTest.validateActivity(effort.getActivity(), effort.getActivity().getId(), effort.getActivity().getResourceState());
}
if (effort.getAthlete() != null) {
StravaAthleteTest.validateAthlete(effort.getAthlete(), effort.getAthlete().getId(), effort.getAthlete()
.getResourceState());
StravaAthleteTest.validateAthlete(effort.getAthlete(), effort.getAthlete().getId(), effort.getAthlete().getResourceState());
}
if (effort.getActivity() != null && effort.getActivity().getAthlete() != null) {
if ((effort.getActivity() != null) && (effort.getActivity().getAthlete() != null)) {
assertEquals(effort.getActivity().getAthlete().getId(), effort.getAthlete().getId());
}
// Only returned for rides, and then only if it was measured
Expand Down Expand Up @@ -138,7 +136,7 @@ public static void validateSegmentEffort(final StravaSegmentEffort effort, final
// assertNotNull(effort.getStartIndex());
return;
}
if (state == StravaResourceState.META) {
if ((state == StravaResourceState.META) || (state == StravaResourceState.PRIVATE)) {
assertNotNull(effort.getId());
assertNull(effort.getActivity());
assertNull(effort.getAthlete());
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/test/api/model/StravaSegmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ public static void validateSegment(final StravaSegment segment, final Integer id
assertEquals(id, segment.getId());
assertEquals(state, segment.getResourceState());

if (state == StravaResourceState.DETAILED || state == StravaResourceState.SUMMARY) {
if ((state == StravaResourceState.DETAILED) || (state == StravaResourceState.SUMMARY)) {
assertNotNull(segment.getActivityType());
assertFalse("Segment " + segment.getId() + " has an unknown activity type",
segment.getActivityType() == StravaSegmentActivityType.UNKNOWN);
assertFalse("Segment " + segment.getId() + " has an unknown activity type", segment.getActivityType() == StravaSegmentActivityType.UNKNOWN);
// Optional sassertNull(segment.getAthleteCount());

// Can be null, if the athlete's never done the segment (and it's only returned with starred segments anyway)
if (segment.getAthletePrEffort() != null) {
StravaSegmentEffortTest.validateSegmentEffort(segment.getAthletePrEffort(), segment.getAthletePrEffort().getId(),
segment.getAthletePrEffort().getResourceState());
StravaSegmentEffortTest.validateSegmentEffort(segment.getAthletePrEffort(), segment.getAthletePrEffort().getId(), segment.getAthletePrEffort()
.getResourceState());
}

assertNotNull(segment.getAverageGrade());
Expand Down Expand Up @@ -88,7 +87,7 @@ public static void validateSegment(final StravaSegment segment, final Integer id
assertNull(segment.getUpdatedAt());
return;
}
if (state == StravaResourceState.META) {
if ((state == StravaResourceState.META) || (state == StravaResourceState.PRIVATE)) {
assertNull(segment.getActivityType());
assertNull(segment.getAthleteCount());
assertNull(segment.getAthletePrEffort());
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/test/api/service/StravaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@
*/
public class StravaTest {
protected void forceDeleteActivity(final Integer activityId) {
stravaWithFullAccess().deleteActivity(activityId);
try {
stravaWithFullAccess().deleteActivity(activityId);
} catch (NotFoundException e) {
// ignore
}
}

protected StravaActivity forceDeleteActivity(final StravaActivity activity) {
return stravaWithFullAccess().deleteActivity(activity.getId());
try {
return stravaWithFullAccess().deleteActivity(activity.getId());
} catch (NotFoundException e) {
// Ignore
return null;
}
}

protected void forceDeleteComment(final StravaComment comment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import javastrava.api.v3.model.StravaActivity;
import javastrava.api.v3.service.exception.NotFoundException;
import javastrava.api.v3.service.exception.UnauthorizedException;

import org.junit.Test;
Expand All @@ -15,8 +16,7 @@
public class DeleteActivityTest extends StravaTest {
/**
* <p>
* Attempt to create an {@link StravaActivity} for the user, using a token which has not been granted write access through the
* OAuth process
* Attempt to create an {@link StravaActivity} for the user, using a token which has not been granted write access through the OAuth process
* </p>
*
* <p>
Expand All @@ -29,21 +29,20 @@ public class DeleteActivityTest extends StravaTest {
public void testDeleteActivity_accessTokenDoesNotHaveWriteAccess() throws Exception {
RateLimitedTestRunner.run(() -> {
// Create the activity using a service which DOES have write access
final StravaActivity activity = TestUtils
.createDefaultActivity("DeleteActivityTest.testDeleteActivity_accessTokenDoesNotHaveWriteAccess");
final StravaActivity stravaResponse = stravaWithWriteAccess().createManualActivity(activity);
final StravaActivity activity = TestUtils.createDefaultActivity("DeleteActivityTest.testDeleteActivity_accessTokenDoesNotHaveWriteAccess");
final StravaActivity stravaResponse = stravaWithWriteAccess().createManualActivity(activity);

// Now get a token without write access and attempt to delete
try {
strava().deleteActivity(stravaResponse.getId());
fail("Succeeded in deleting an activity despite not having write access");
} catch (final UnauthorizedException e) {
// Expected behaviour
}
// Now get a token without write access and attempt to delete
try {
strava().deleteActivity(stravaResponse.getId());
fail("Succeeded in deleting an activity despite not having write access");
} catch (final UnauthorizedException e) {
// Expected behaviour
}

// Delete the activity using a token with write access
forceDeleteActivity(stravaResponse);
});
// Delete the activity using a token with write access
forceDeleteActivity(stravaResponse);
});
}

/**
Expand All @@ -58,18 +57,22 @@ public void testDeleteActivity_accessTokenDoesNotHaveWriteAccess() throws Except
@Test
public void testDeleteActivity_invalidActivity() throws Exception {
RateLimitedTestRunner.run(() -> {
final StravaActivity stravaResponse = stravaWithWriteAccess().deleteActivity(TestUtils.ACTIVITY_INVALID);
assertNull("deleted an activity that doesn't exist", stravaResponse);
try {
stravaWithWriteAccess().deleteActivity(TestUtils.ACTIVITY_INVALID);
} catch (final NotFoundException e) {
// Expected
return;
}
fail("deleted an activity that doesn't exist");
});
}

@Test
public void testDeleteActivity_privateActivity() throws Exception {
RateLimitedTestRunner.run(() -> {
final StravaActivity activity = TestUtils
.createDefaultActivity("DeleteActivityTest.testDeleteActivity_privateActivity");
final StravaActivity activity = TestUtils.createDefaultActivity("DeleteActivityTest.testDeleteActivity_privateActivity");
activity.setPrivateActivity(Boolean.TRUE);
final StravaActivity createResponse = stravaWithWriteAccess().createManualActivity(activity);
final StravaActivity createResponse = stravaWithFullAccess().createManualActivity(activity);
assertEquals(Boolean.TRUE, createResponse.getPrivateActivity());
StravaActivity deleteResponse = null;
try {
Expand All @@ -85,10 +88,9 @@ public void testDeleteActivity_privateActivity() throws Exception {
@Test
public void testDeleteActivity_privateActivityNoViewPrivate() throws Exception {
RateLimitedTestRunner.run(() -> {
final StravaActivity activity = TestUtils
.createDefaultActivity("DeleteActivityTest.testDeleteActivity_privateActivityNoViewPrivate");
final StravaActivity activity = TestUtils.createDefaultActivity("DeleteActivityTest.testDeleteActivity_privateActivityNoViewPrivate");
activity.setPrivateActivity(Boolean.TRUE);
final StravaActivity createResponse = stravaWithWriteAccess().createManualActivity(activity);
final StravaActivity createResponse = stravaWithFullAccess().createManualActivity(activity);
try {
stravaWithWriteAccess().deleteActivity(createResponse.getId());
} catch (final UnauthorizedException e) {
Expand All @@ -109,8 +111,8 @@ public void testDeleteActivity_privateActivityNoViewPrivate() throws Exception {
* </p>
*
* <p>
* In order to avoid deleting genuine data, this test creates the activity first, checks that it has been successfully written
* (i.e. that it can be read back from the API) and then deletes it again
* In order to avoid deleting genuine data, this test creates the activity first, checks that it has been successfully written (i.e. that it can be read
* back from the API) and then deletes it again
* </p>
*
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void testGetActivity_privateBelongsToOtherUser() throws Exception {
assertNotNull(activity);
final StravaActivity comparisonActivity = new StravaActivity();
comparisonActivity.setId(TestUtils.ACTIVITY_PRIVATE_OTHER_USER);
comparisonActivity.setResourceState(StravaResourceState.META);
comparisonActivity.setResourceState(StravaResourceState.PRIVATE);
assertEquals(comparisonActivity, activity);
StravaActivityTest.validateActivity(activity);
});
Expand All @@ -164,7 +164,7 @@ public void testGetActivity_privateNoViewPrivateScope() throws Exception {
} finally {
forceDeleteActivity(response);
}
StravaActivityTest.validateActivity(response, response.getId(), StravaResourceState.META);
StravaActivityTest.validateActivity(response, response.getId(), StravaResourceState.PRIVATE);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertTrue;
import javastrava.api.v3.auth.model.Token;
import javastrava.api.v3.model.StravaActivity;
import javastrava.api.v3.model.reference.StravaResourceState;
import javastrava.api.v3.service.ActivityService;
import javastrava.api.v3.service.exception.UnauthorizedException;
import javastrava.api.v3.service.impl.ActivityServiceImpl;
Expand Down Expand Up @@ -72,14 +74,9 @@ public void testImplementation_implementationIsCached() throws Exception {
@Test
public void testImplementation_invalidToken() throws Exception {
RateLimitedTestRunner.run(() -> {
try {
final ActivityService service = ActivityServiceImpl.instance(TestUtils.INVALID_TOKEN);
service.getActivity(TestUtils.ACTIVITY_FOR_AUTHENTICATED_USER);
} catch (final UnauthorizedException e) {
// This is the expected behaviour
return;
}
fail("Got a service for an invalid token!");
final ActivityService service = ActivityServiceImpl.instance(TestUtils.INVALID_TOKEN);
StravaActivity activity = service.getActivity(TestUtils.ACTIVITY_FOR_AUTHENTICATED_USER);
assertEquals(StravaResourceState.PRIVATE, activity.getResourceState());
});
}

Expand All @@ -100,15 +97,9 @@ public void testImplementation_revokedToken() throws Exception {
final ActivityService activityServices = ActivityServiceImpl.instance(TestUtils.getRevokedToken());

// Check that it can't be used
try {
activityServices.getActivity(TestUtils.ACTIVITY_FOR_AUTHENTICATED_USER);
} catch (final UnauthorizedException e) {
// Expected behaviour
return;
}
final StravaActivity activity = activityServices.getActivity(TestUtils.ACTIVITY_FOR_AUTHENTICATED_USER);
assertTrue(activity.getResourceState() == StravaResourceState.PRIVATE);

// If we get here, then the service is working despite the token being revoked
fail("Got a usable service implementation using a revoked token");
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package test.api.service.impl.activityservice;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -126,7 +125,11 @@ public void testListActivityPhotos_privateWithViewPrivate() throws Exception {
RateLimitedTestRunner.run(() -> {
final List<StravaPhoto> photos = stravaWithViewPrivate().listActivityPhotos(TestUtils.ACTIVITY_PRIVATE_WITH_PHOTOS);
assertNotNull(photos);
assertFalse(photos.size() == 0);
});
// TODO This is a test workaround for issue javastrava-api #68
// See https://github.com/danshannon/javastravav3api/issues/68
// When resolved, uncomment the following line
// assertFalse(photos.size() == 0);
// End of workaround
});
}
}
Loading

0 comments on commit 0de0e10

Please sign in to comment.