Skip to content

Commit

Permalink
Fixes from running functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boncey committed May 2, 2020
1 parent d55d1fa commit fc0a32c
Show file tree
Hide file tree
Showing 6 changed files with 528 additions and 66 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,15 @@ Flickr4Java is available on Maven Central so the above settings should be all yo
### Testing
The tests now run against captured responses from Flickr (see `src/test/resources/payloads`) and don't contact the Flickr API at all.
This means there is no longer any need to create a test account and populate a properties file.

#### Functional testing against the Flickr API.
This is the setup to run the tests against the Flickr API.
*Not for the faint-hearted. Only do this to test large refactorings etc.*

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).
Run tests as follows.

mvn -DsetupPropertiesPath=/path/to/your/setup.properties clean install

Expect lots of failures and general flakiness as data has changed on Flickr and the tests or data need updating.

4 changes: 2 additions & 2 deletions src/main/java/com/flickr4java/flickr/REST.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ public com.flickr4java.flickr.Response postMultiPart(String path, UploadMetaData
// Ensure all parameters (including oauth) are added to payload so signature matches
uploadParameters.putAll(request.getOauthParameters());

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

try {
return handleResponse(request, service);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ public void testGetValues() throws FlickrException {
@Test
public void testGetRecentValues() throws FlickrException {
MachinetagsInterface machinetagsInterface = flickr.getMachinetagsInterface();
String namespace = "ceramics";
String predicate = "material";
String namespace = "filmdev";
String predicate = "recipe";
Calendar addedSince = Calendar.getInstance();
addedSince.add(Calendar.YEAR, -10);
NamespacesList<Value> list = machinetagsInterface.getRecentValues(namespace, predicate, addedSince.getTime());
assertTrue(list.size() >= 3);
boolean contentFound = false;
for (Value value : list) {
if (value.getValue().equals("mixed_media")) {
if (value.getValue().equals("8040")) {
contentFound = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testCreateOAuthService() {
@Test
public void testSignRequest() {
// No proxy credentials
OAuth10aService service = new ServiceBuilder("foo").build(FlickrApi.instance());
OAuth10aService service = new ServiceBuilder("foo").apiSecret("bar").build(FlickrApi.instance());
OAuthRequest request = new OAuthRequest(Verb.GET, "http://foobar");
assertTrue(request.getOauthParameters().isEmpty());
OAuthUtilities.signRequest(service, request, null);
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/com/flickr4java/flickr/test/UploaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void testUploadInputStream() throws IOException, FlickrException {
* @throws FlickrException if there was a problem connecting to Flickr
*/
@Test
public void testReplaceInputStream() throws IOException, FlickrException {
public void testReplaceInputStream() throws IOException, FlickrException, InterruptedException {
Uploader uploader = flickr.getUploader();
PhotosInterface pint = flickr.getPhotosInterface();
File imageFile = new File(testProperties.getImageFile());
Expand All @@ -112,6 +112,9 @@ public void testReplaceInputStream() throws IOException, FlickrException {
photoId = uploader.upload(uploadIS, metaData);
}

// Fix some odd timing issue
Thread.sleep(1500);

try (InputStream replaceIS = new FileInputStream(imageFile)) {

try {
Expand Down Expand Up @@ -148,7 +151,7 @@ public void testReplaceInputStream() throws IOException, FlickrException {
* @throws FlickrException if there was a problem connecting to Flickr
*/
@Test
public void testReplaceByteArray() throws IOException, FlickrException {
public void testReplaceByteArray() throws IOException, FlickrException, InterruptedException {
File imageFile = new File(testProperties.getImageFile());
Uploader uploader = flickr.getUploader();
PhotosInterface pint = flickr.getPhotosInterface();
Expand All @@ -159,6 +162,9 @@ public void testReplaceByteArray() throws IOException, FlickrException {
UploadMetaData metaData = buildPrivatePhotoMetadata();
String photoId = uploader.upload(Files.readAllBytes(imageFile.toPath()), metaData);

// Fix some odd timing issue
Thread.sleep(1500);

try {
photoId = uploader.replace(Files.readAllBytes(imageFile.toPath()), photoId, false);
assertNotNull(photoId);
Expand Down
Loading

0 comments on commit fc0a32c

Please sign in to comment.