Skip to content

Commit fc0a32c

Browse files
author
boncey
committed
Fixes from running functional tests
1 parent d55d1fa commit fc0a32c

6 files changed

Lines changed: 528 additions & 66 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,15 @@ Flickr4Java is available on Maven Central so the above settings should be all yo
5757
### Testing
5858
The tests now run against captured responses from Flickr (see `src/test/resources/payloads`) and don't contact the Flickr API at all.
5959
This means there is no longer any need to create a test account and populate a properties file.
60+
61+
#### Functional testing against the Flickr API.
62+
This is the setup to run the tests against the Flickr API.
63+
*Not for the faint-hearted. Only do this to test large refactorings etc.*
64+
65+
Create up a `setup.properties` file (see `src/test/resources/setup.properties.example`) with details of a real account on Flickr (I recommend setting up a test account for this purpose).
66+
Run tests as follows.
67+
68+
mvn -DsetupPropertiesPath=/path/to/your/setup.properties clean install
69+
70+
Expect lots of failures and general flakiness as data has changed on Flickr and the tests or data need updating.
71+

src/main/java/com/flickr4java/flickr/REST.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ public com.flickr4java.flickr.Response postMultiPart(String path, UploadMetaData
204204
// Ensure all parameters (including oauth) are added to payload so signature matches
205205
uploadParameters.putAll(request.getOauthParameters());
206206

207-
request.addFileByteArrayBodyPartPayloadInMultipartPayload(metaData.getFilemimetype(), payload.getPayload());
207+
request.addFileByteArrayBodyPartPayloadInMultipartPayload(payload.getPayload(), "photo", metaData.getFilename());
208208
uploadParameters.entrySet().forEach(e ->
209-
request.addFileByteArrayBodyPartPayloadInMultipartPayload(null, e.getValue().getBytes()));
209+
request.addFileByteArrayBodyPartPayloadInMultipartPayload(null, e.getValue().getBytes(), e.getKey()));
210210

211211
try {
212212
return handleResponse(request, service);

src/test/java/com/flickr4java/flickr/test/MachinetagsInterfaceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ public void testGetValues() throws FlickrException {
9393
@Test
9494
public void testGetRecentValues() throws FlickrException {
9595
MachinetagsInterface machinetagsInterface = flickr.getMachinetagsInterface();
96-
String namespace = "ceramics";
97-
String predicate = "material";
96+
String namespace = "filmdev";
97+
String predicate = "recipe";
9898
Calendar addedSince = Calendar.getInstance();
9999
addedSince.add(Calendar.YEAR, -10);
100100
NamespacesList<Value> list = machinetagsInterface.getRecentValues(namespace, predicate, addedSince.getTime());
101101
assertTrue(list.size() >= 3);
102102
boolean contentFound = false;
103103
for (Value value : list) {
104-
if (value.getValue().equals("mixed_media")) {
104+
if (value.getValue().equals("8040")) {
105105
contentFound = true;
106106
}
107107
}

src/test/java/com/flickr4java/flickr/test/OAuthUtilitiesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void testCreateOAuthService() {
3434
@Test
3535
public void testSignRequest() {
3636
// No proxy credentials
37-
OAuth10aService service = new ServiceBuilder("foo").build(FlickrApi.instance());
37+
OAuth10aService service = new ServiceBuilder("foo").apiSecret("bar").build(FlickrApi.instance());
3838
OAuthRequest request = new OAuthRequest(Verb.GET, "http://foobar");
3939
assertTrue(request.getOauthParameters().isEmpty());
4040
OAuthUtilities.signRequest(service, request, null);

src/test/java/com/flickr4java/flickr/test/UploaderTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void testUploadInputStream() throws IOException, FlickrException {
9898
* @throws FlickrException if there was a problem connecting to Flickr
9999
*/
100100
@Test
101-
public void testReplaceInputStream() throws IOException, FlickrException {
101+
public void testReplaceInputStream() throws IOException, FlickrException, InterruptedException {
102102
Uploader uploader = flickr.getUploader();
103103
PhotosInterface pint = flickr.getPhotosInterface();
104104
File imageFile = new File(testProperties.getImageFile());
@@ -112,6 +112,9 @@ public void testReplaceInputStream() throws IOException, FlickrException {
112112
photoId = uploader.upload(uploadIS, metaData);
113113
}
114114

115+
// Fix some odd timing issue
116+
Thread.sleep(1500);
117+
115118
try (InputStream replaceIS = new FileInputStream(imageFile)) {
116119

117120
try {
@@ -148,7 +151,7 @@ public void testReplaceInputStream() throws IOException, FlickrException {
148151
* @throws FlickrException if there was a problem connecting to Flickr
149152
*/
150153
@Test
151-
public void testReplaceByteArray() throws IOException, FlickrException {
154+
public void testReplaceByteArray() throws IOException, FlickrException, InterruptedException {
152155
File imageFile = new File(testProperties.getImageFile());
153156
Uploader uploader = flickr.getUploader();
154157
PhotosInterface pint = flickr.getPhotosInterface();
@@ -159,6 +162,9 @@ public void testReplaceByteArray() throws IOException, FlickrException {
159162
UploadMetaData metaData = buildPrivatePhotoMetadata();
160163
String photoId = uploader.upload(Files.readAllBytes(imageFile.toPath()), metaData);
161164

165+
// Fix some odd timing issue
166+
Thread.sleep(1500);
167+
162168
try {
163169
photoId = uploader.replace(Files.readAllBytes(imageFile.toPath()), photoId, false);
164170
assertNotNull(photoId);

0 commit comments

Comments
 (0)