diff --git a/README.md b/README.md index 11c5f9e8..1fd119c7 100644 --- a/README.md +++ b/README.md @@ -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. + diff --git a/src/main/java/com/flickr4java/flickr/REST.java b/src/main/java/com/flickr4java/flickr/REST.java index 1e32cd71..c97c4369 100644 --- a/src/main/java/com/flickr4java/flickr/REST.java +++ b/src/main/java/com/flickr4java/flickr/REST.java @@ -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); diff --git a/src/test/java/com/flickr4java/flickr/test/MachinetagsInterfaceTest.java b/src/test/java/com/flickr4java/flickr/test/MachinetagsInterfaceTest.java index ad644391..2e7ada76 100644 --- a/src/test/java/com/flickr4java/flickr/test/MachinetagsInterfaceTest.java +++ b/src/test/java/com/flickr4java/flickr/test/MachinetagsInterfaceTest.java @@ -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 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; } } diff --git a/src/test/java/com/flickr4java/flickr/test/OAuthUtilitiesTest.java b/src/test/java/com/flickr4java/flickr/test/OAuthUtilitiesTest.java index ce90bcc0..73df6e75 100644 --- a/src/test/java/com/flickr4java/flickr/test/OAuthUtilitiesTest.java +++ b/src/test/java/com/flickr4java/flickr/test/OAuthUtilitiesTest.java @@ -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); diff --git a/src/test/java/com/flickr4java/flickr/test/UploaderTest.java b/src/test/java/com/flickr4java/flickr/test/UploaderTest.java index be0383a3..49555eae 100644 --- a/src/test/java/com/flickr4java/flickr/test/UploaderTest.java +++ b/src/test/java/com/flickr4java/flickr/test/UploaderTest.java @@ -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()); @@ -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 { @@ -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(); @@ -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); diff --git a/src/test/resources/payloads/get/flickr.machinetags.getRecentValues.xml b/src/test/resources/payloads/get/flickr.machinetags.getRecentValues.xml index 386b938e..7c5fb029 100644 --- a/src/test/resources/payloads/get/flickr.machinetags.getRecentValues.xml +++ b/src/test/resources/payloads/get/flickr.machinetags.getRecentValues.xml @@ -1,61 +1,505 @@ - - mixed_media - dfggdf - dfgdfg - puppy - porcelain - fur - table - fruit - counter - bag - terra_cotta - stoneware - none, - camera - small_child - dog - earthenware - silver_leaf - paint - glaze - glass - digital_image - other - black_clay - kiln-cast_glass - wood - leather_pillow - slipware - trails - hiking - boys - marley - hill - grass_hill - grass - cyrus - mn - flower - boy - kiln_cast_glass - cast_iron - bus - chocolate - booy - _wood - charcoal - nylon_flocking - clover - nature - porcelain_slip - limoges_porcelain - royal_copenhagen_porcelain - resin - human_flesh - t_material - clay_and_brick - + + 12449 + 8040 + 12425 + 12315 + 12488 + 12487 + 12483 + 12486 + 10555 + 12485 + 12484 + 12435 + 12316 + 12481 + 12480 + 12479 + 11313 + 12478 + 12477 + 12476 + 12475 + 12473 + 12472 + 12470 + 12469 + 12434 + 12468 + 12467 + 12466 + 11432 + 12263 + 12465 + 12462 + 12464 + 12072 + 10119 + 10875 + 12461 + 12457 + 10291 + 12460 + 11360 + 12459 + 12450 + 11087 + 10312 + 12262 + 12456 + 12455 + 12454 + 9504 + 12453 + 10716 + 12452 + 11982 + 12451 + 12447 + 10862 + 10840 + 6986 + 10290 + 12403 + 6936 + 10266 + 12445 + 10035 + 10476 + 12443 + 12326 + 12314 + 7309 + 8209 + 10974 + 11394 + 12442 + 6282 + 12441 + 12317 + 12440 + 12439 + 12438 + 7329 + 12327 + 12430 + 12436 + 12429 + 7920 + 12432 + 9089 + 12431 + 6283 + 6354 + 6277 + 9128 + 6472 + 12426 + 12428 + 12424 + 5773 + 12207 + 6279 + 6890 + 10719 + 11315 + 10809 + 10688 + 11634 + 12417 + 12367 + 12423 + 12422 + 11192 + 12420 + 6965 + 12419 + 7565 + 12418 + 9898 + 6284 + 12416 + 12413 + 12415 + 12412 + 12397 + 12411 + 12410 + 12392 + 11461 + 11719 + 10363 + 12409 + 9142 + 12401 + 12408 + 12345 + 12319 + 12407 + 8031 + 12406 + 12405 + 8324 + 12277 + 12404 + 11673 + 12402 + 8174 + 12372 + 12400 + 12360 + 12399 + 12398 + 12396 + 12395 + 12394 + 12393 + 12376 + 12391 + 12390 + 10055 + 12389 + 12388 + 12387 + 12384 + 12383 + 12382 + 12381 + 12380 + 12334 + 9503 + 12379 + 12378 + 12377 + 12226 + 12375 + 12374 + 12371 + 12370 + 12369 + 12368 + 12363 + 12366 + 12365 + 12364 + 11513 + 12362 + 12361 + 12358 + 12359 + 12357 + 12356 + 12355 + 12354 + 12353 + 12352 + 12197 + 12331 + 12117 + 12349 + 12348 + 12346 + 12344 + 12343 + 12308 + 12309 + 12310 + 12342 + 12341 + 12339 + 12338 + 12321 + 12337 + 12320 + 10714 + 12335 + 12328 + 12325 + 12324 + 12323 + 12322 + 12071 + 12318 + 12313 + 12312 + 12311 + 12306 + 12307 + 11638 + 9075 + 8686 + 12305 + 12304 + 12303 + 12302 + 12300 + 12008 + 12299 + 12298 + 12297 + 12295 + 12294 + 12009 + 12293 + 12274 + 12292 + 12291 + 12214 + 12235 + 12290 + 12289 + 9930 + 12288 + 12287 + 12285 + 12196 + 12282 + 12284 + 12283 + 12280 + 12281 + 12278 + 12276 + 12275 + 11659 + 12258 + 12273 + 12272 + 12271 + 10681 + 12270 + 12269 + 12268 + 12267 + 12266 + 12265 + 12264 + 12176 + 12261 + 12260 + 12259 + 12215 + 12255 + 12253 + 12252 + 12250 + 12247 + 12246 + 12243 + 11692 + 12191 + 12223 + 12192 + 12242 + 12241 + 8570 + 11606 + 12240 + 12239 + 10503 + 12019 + 11570 + 12238 + 12218 + 12237 + 12171 + 11717 + 12236 + 12234 + 9499 + 12233 + 12231 + 11833 + 12230 + 12211 + 12216 + 12229 + 12227 + 12225 + 12224 + 12222 + 12198 + 12219 + 12217 + 12213 + 12212 + 12210 + 12204 + 12209 + 12208 + 11628 + 12206 + 12205 + 12203 + 11469 + 12202 + 12200 + 12199 + 12186 + 12195 + 12194 + 12193 + 12190 + 12189 + 12188 + 12187 + 12185 + 12184 + 12183 + 12182 + 12181 + 12180 + 12178 + 12177 + 11840 + 12175 + 12172 + 12174 + 12173 + 11725 + 12170 + 12168 + 12167 + 12166 + 12165 + 6362 + 12164 + 12163 + 12079 + 12160 + 12162 + 12161 + 12159 + 12158 + 12157 + 12156 + 12151 + 12155 + 12154 + 12153 + 12150 + 12149 + 12148 + 12145 + 9302 + 12138 + 12144 + 12143 + 12131 + 12125 + 12142 + 11528 + 11892 + 12141 + 12140 + 12139 + 12137 + 11724 + 11901 + 12136 + 12135 + 12134 + 12133 + 12132 + 12129 + 12115 + 12126 + 12124 + 12123 + 8005 + 11746 + 12112 + 11958 + 11970 + 11991 + 12122 + 11523 + 12121 + 12120 + 12119 + 12116 + 12114 + 12067 + 12109 + 12113 + 12108 + 12107 + 12106 + 12105 + 12104 + 12086 + 12103 + 12102 + 12101 + 12100 + 12099 + 12098 + 12097 + 12096 + 12091 + 12087 + 11758 + 12095 + 12094 + 12092 + 12090 + 11603 + 12053 + 12078 + 12089 + 12084 + 12082 + 12083 + 11660 + 11765 + 11976 + 12081 + 12080 + 12077 + 9853 + 12076 + 12075 + 12073 + 12069 + 12068 + 12066 + 12065 + 12064 + 12063 + 12062 + 12061 + 12060 + 12059 + 12058 + 12054 + 12057 + 12056 + 12055 + 12035 + 12052 + 12051 + 12050 + 11379 + 12048 + 12047 + 12046 + 12045 + 12044 + 12043 + 12042 + 12041 + 12040 + 12039 + 12038 + 12037 + 12036 + 11932 + 11748 + 12034 + 12033 + 12032 + 12031 + \ No newline at end of file