Skip to content

Commit 81afadc

Browse files
author
Darren Greaves
committed
Merge pull request #84 from samwilson/setuptests
Some more information about setting up integration tests
2 parents 048e16f + c4354a9 commit 81afadc

File tree

4 files changed

+51
-24
lines changed

4 files changed

+51
-24
lines changed

Flickr4Java/BUILDING.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,38 @@ The following tasks are available:
1919

2020
## Testing
2121

22-
Most of the tests are integration tests, and require hitting the actual Flickr
23-
API service with DELETE permissions. The safest and easiest way to do this is to
24-
set up a test user account, the following photos etc.:
25-
26-
1. At least one photo in one album
27-
2. At least one collection with title and description, containing at least one album
28-
(the ID of the collection can be retrieved manually via the
29-
[API explorer](https://www.flickr.com/services/api/explore/flickr.collections.getTree)
30-
and be added as `collectionid` in `src/test/resources/setup.properties`)
31-
3. *[List is incomplete]*
32-
3322
To test:
3423

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

4031
(The `-q` above just hides some of the more verbose output; it can be left out.)
32+
33+
Most of the tests are integration tests and require hitting the actual Flickr
34+
API service with DELETE permissions. The safest and easiest way to do this is to
35+
set up a test user account with the following:
36+
37+
1. At least one photo with a location set, in at least one album, with exactly 3 tags.
38+
Add this photo's ID as `photoid` and `geo.write.photoid` in `setup.properties`.
39+
2. At least one collection with title and description, containing at least one album
40+
(the ID of the collection should be retrieved manually via the
41+
[API explorer](https://www.flickr.com/services/api/explore/flickr.collections.getTree)
42+
and be added as `collectionid` in `setup.properties`).
43+
3. At least one comment on another user's photo.
44+
4. Following at least one other user.
45+
5. At least one favorite.
46+
6. Allows 'anyone' "to see your stuff on a map".
47+
7. A member of at least one group, whose ID is saved as `testgroupid`.
48+
8. A gallery, containing at least one photo.
49+
9. An "[own Flickr address](https://www.flickr.com/profile_url.gne)" set to `username` (see below).
50+
10. *[List is incomplete]*
51+
52+
The last few keys in the `setup.properties` need to be as follows:
53+
54+
* Set the following keys in `setup.properties` to match your test user:
55+
`nsid`, `username`, `displayname`, and `email`.
56+
* Point `imagefile` to a test image that will be uploaded (and then deleted).

Flickr4Java/src/test/java/com/flickr4java/flickr/test/FavoritesInterfaceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void testGetPublicList() throws FlickrException {
4545
FavoritesInterface iface = flickr.getFavoritesInterface();
4646
Collection<Photo> favorites = iface.getPublicList(testProperties.getNsid(), 0, 0, null);
4747
assertNotNull(favorites);
48-
assertTrue(favorites.size() > 1);
48+
assertTrue(favorites.size() > 0);
4949
}
5050

5151
@Test

Flickr4Java/src/test/java/com/flickr4java/flickr/test/PeopleInterfaceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public void testFindByEmail() throws FlickrException {
3333
User person = iface.findByEmail(testProperties.getEmail());
3434
assertNotNull(person);
3535
assertEquals(person.getId(), testProperties.getNsid());
36-
assertEquals(person.getUsername(), testProperties.getDisplayname());
36+
assertEquals(person.getUsername(), testProperties.getUsername());
3737
}
3838

3939
@Test
4040
public void testFindByUsername() throws FlickrException {
4141
PeopleInterface iface = flickr.getPeopleInterface();
42-
User person = iface.findByUsername(testProperties.getDisplayname());
42+
User person = iface.findByUsername(testProperties.getUsername());
4343
assertNotNull(person);
4444
assertEquals(testProperties.getNsid(), person.getId());
4545
assertEquals(testProperties.getUsername(), person.getUsername());
@@ -56,7 +56,7 @@ public void testGetInfo() throws FlickrException {
5656
User person = iface.getInfo(testProperties.getNsid());
5757
assertNotNull(person);
5858
assertEquals(testProperties.getNsid(), person.getId());
59-
assertEquals(testProperties.getDisplayname(), person.getUsername());
59+
assertEquals(testProperties.getDisplayname(), person.getRealName());
6060
assertTrue(person.getMobileurl().startsWith("https://m.flickr.com/photostream.gne"));
6161
assertEquals(person.getPhotosurl(), String.format("https://www.flickr.com/photos/%s/", testProperties.getUsername()));
6262
assertEquals(person.getProfileurl(), String.format("https://www.flickr.com/people/%s/", testProperties.getUsername()));
@@ -93,15 +93,15 @@ public void testGetPhotos() throws FlickrException {
9393
PeopleInterface iface = flickr.getPeopleInterface();
9494
PhotoList<Photo> photos = iface.getPhotos(testProperties.getNsid(), null, null, null, null, null, null, null, null, 15, 1);
9595
assertNotNull(photos);
96-
assertTrue(photos.size() > 1);
96+
assertTrue(photos.size() > 0);
9797
}
9898

9999
@Test
100100
public void testGetPhotosOf() throws FlickrException {
101101
PeopleInterface iface = flickr.getPeopleInterface();
102102
PhotoList<Photo> photos = iface.getPhotosOf(testProperties.getNsid(), null, null, 10, 1);
103103
assertNotNull(photos);
104-
assertTrue(photos.size() > 1);
104+
assertTrue(photos.size() > 0);
105105
}
106106

107107
@Test

Flickr4Java/src/test/java/com/flickr4java/flickr/test/PhotosInterfaceTest.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,23 @@ public void teardown() {
6666
public void testAddAndRemoveTags() throws FlickrException {
6767
PhotosInterface iface = flickr.getPhotosInterface();
6868
String photoId = testProperties.getPhotoId();
69+
Photo photo = iface.getInfo(photoId, null);
70+
71+
// Find number of existing tags
72+
int preCount = photo.getTags().size();
73+
int postCount = preCount + 1;
74+
75+
// Add a tag
6976
String[] tagsToAdd = { "test" };
7077
iface.addTags(photoId, tagsToAdd);
71-
Photo photo = iface.getInfo(photoId, null);
78+
79+
// Check that it was added
80+
photo = iface.getInfo(photoId, null);
7281
Collection<Tag> tags = photo.getTags();
7382
assertNotNull(tags);
74-
assertEquals(4, tags.size());
83+
assertEquals(postCount, tags.size());
7584

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

94+
// Remove and check that it was removed
8495
iface.removeTag(tagId);
8596
photo = iface.getInfo(photoId, null);
8697
tags = photo.getTags();
8798
assertNotNull(tags);
88-
assertEquals(3, tags.size());
99+
assertEquals(preCount, tags.size());
89100
}
90101

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

111122
User owner = photo.getOwner();
112123
assertEquals(testProperties.getNsid(), owner.getId());
113-
assertEquals(testProperties.getDisplayname(), owner.getUsername());
124+
assertEquals(testProperties.getUsername(), owner.getUsername());
114125

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

0 commit comments

Comments
 (0)