Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions Flickr4Java/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,38 @@ The following tasks are available:

## Testing

Most of the tests are integration tests, and require hitting the actual Flickr
API service with DELETE permissions. The safest and easiest way to do this is to
set up a test user account, the following photos etc.:

1. At least one photo in one album
2. At least one collection with title and description, containing at least one album
(the ID of the collection can be retrieved manually via the
[API explorer](https://www.flickr.com/services/api/explore/flickr.collections.getTree)
and be added as `collectionid` in `src/test/resources/setup.properties`)
3. *[List is incomplete]*

To test:

1. Copy `src/test/resources/setup.properties.example` to `src/test/resources/setup.properties`
2. Run `gradle compiletestjava -q` — compile all sources
3. Run `gradle setuptests -q` — this will prompt for authorisation and update the above `setup.properties` file
4. Run `gradle test`
3. Run `gradle setuptests -q` — this will prompt for authorisation
and update the `setup.properties` file with the test user's details
4. Run `gradle test` — can be run as `gradle -Dtest.single=NameOfTest test` to
run only one test (because the full suite can take quite a while)

(The `-q` above just hides some of the more verbose output; it can be left out.)

Most of the tests are integration tests and require hitting the actual Flickr
API service with DELETE permissions. The safest and easiest way to do this is to
set up a test user account with the following:

1. At least one photo with a location set, in at least one album, with exactly 3 tags.
Add this photo's ID as `photoid` and `geo.write.photoid` in `setup.properties`.
2. At least one collection with title and description, containing at least one album
(the ID of the collection should be retrieved manually via the
[API explorer](https://www.flickr.com/services/api/explore/flickr.collections.getTree)
and be added as `collectionid` in `setup.properties`).
3. At least one comment on another user's photo.
4. Following at least one other user.
5. At least one favorite.
6. Allows 'anyone' "to see your stuff on a map".
7. A member of at least one group, whose ID is saved as `testgroupid`.
8. A gallery, containing at least one photo.
9. An "[own Flickr address](https://www.flickr.com/profile_url.gne)" set to `username` (see below).
10. *[List is incomplete]*

The last few keys in the `setup.properties` need to be as follows:

* Set the following keys in `setup.properties` to match your test user:
`nsid`, `username`, `displayname`, and `email`.
* Point `imagefile` to a test image that will be uploaded (and then deleted).
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testGetPublicList() throws FlickrException {
FavoritesInterface iface = flickr.getFavoritesInterface();
Collection<Photo> favorites = iface.getPublicList(testProperties.getNsid(), 0, 0, null);
assertNotNull(favorites);
assertTrue(favorites.size() > 1);
assertTrue(favorites.size() > 0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public void testFindByEmail() throws FlickrException {
User person = iface.findByEmail(testProperties.getEmail());
assertNotNull(person);
assertEquals(person.getId(), testProperties.getNsid());
assertEquals(person.getUsername(), testProperties.getDisplayname());
assertEquals(person.getUsername(), testProperties.getUsername());
}

@Test
public void testFindByUsername() throws FlickrException {
PeopleInterface iface = flickr.getPeopleInterface();
User person = iface.findByUsername(testProperties.getDisplayname());
User person = iface.findByUsername(testProperties.getUsername());
assertNotNull(person);
assertEquals(testProperties.getNsid(), person.getId());
assertEquals(testProperties.getUsername(), person.getUsername());
Expand All @@ -56,7 +56,7 @@ public void testGetInfo() throws FlickrException {
User person = iface.getInfo(testProperties.getNsid());
assertNotNull(person);
assertEquals(testProperties.getNsid(), person.getId());
assertEquals(testProperties.getDisplayname(), person.getUsername());
assertEquals(testProperties.getDisplayname(), person.getRealName());
assertTrue(person.getMobileurl().startsWith("https://m.flickr.com/photostream.gne"));
assertEquals(person.getPhotosurl(), String.format("https://www.flickr.com/photos/%s/", testProperties.getUsername()));
assertEquals(person.getProfileurl(), String.format("https://www.flickr.com/people/%s/", testProperties.getUsername()));
Expand Down Expand Up @@ -93,15 +93,15 @@ public void testGetPhotos() throws FlickrException {
PeopleInterface iface = flickr.getPeopleInterface();
PhotoList<Photo> photos = iface.getPhotos(testProperties.getNsid(), null, null, null, null, null, null, null, null, 15, 1);
assertNotNull(photos);
assertTrue(photos.size() > 1);
assertTrue(photos.size() > 0);
}

@Test
public void testGetPhotosOf() throws FlickrException {
PeopleInterface iface = flickr.getPeopleInterface();
PhotoList<Photo> photos = iface.getPhotosOf(testProperties.getNsid(), null, null, 10, 1);
assertNotNull(photos);
assertTrue(photos.size() > 1);
assertTrue(photos.size() > 0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,23 @@ public void teardown() {
public void testAddAndRemoveTags() throws FlickrException {
PhotosInterface iface = flickr.getPhotosInterface();
String photoId = testProperties.getPhotoId();
Photo photo = iface.getInfo(photoId, null);

// Find number of existing tags
int preCount = photo.getTags().size();
int postCount = preCount + 1;

// Add a tag
String[] tagsToAdd = { "test" };
iface.addTags(photoId, tagsToAdd);
Photo photo = iface.getInfo(photoId, null);

// Check that it was added
photo = iface.getInfo(photoId, null);
Collection<Tag> tags = photo.getTags();
assertNotNull(tags);
assertEquals(4, tags.size());
assertEquals(postCount, tags.size());

// Get the added tag's ID
String tagId = null;
for (Tag tag : tags) {
if (tag.getValue().equals("test")) {
Expand All @@ -81,11 +91,12 @@ public void testAddAndRemoveTags() throws FlickrException {
}
}

// Remove and check that it was removed
iface.removeTag(tagId);
photo = iface.getInfo(photoId, null);
tags = photo.getTags();
assertNotNull(tags);
assertEquals(3, tags.size());
assertEquals(preCount, tags.size());
}

@Test
Expand All @@ -110,7 +121,7 @@ public void testGetInfo() throws FlickrException {

User owner = photo.getOwner();
assertEquals(testProperties.getNsid(), owner.getId());
assertEquals(testProperties.getDisplayname(), owner.getUsername());
assertEquals(testProperties.getUsername(), owner.getUsername());

List<Tag> tags = (List<Tag>) photo.getTags();
assertEquals("green", (tags.get(0)).getValue());
Expand Down Expand Up @@ -325,7 +336,7 @@ public void testGetThumbnailImage() throws FlickrException, IOException {
Photo photo = iface.getInfo(photoId, null);
BufferedImage image = iface.getImage(photo, Size.THUMB);
assertNotNull(image);
assertEquals(67, image.getWidth());
assertTrue(67==image.getWidth() || 68==image.getWidth());
assertEquals(100, image.getHeight());
ImageIO.write(image, "jpg", thumbnailFile);
}
Expand Down