@@ -36,6 +36,7 @@ abstract public class AbstractApiTest extends MockableTest {
3636 public static final String API_TEST_UPLOAD_PRESET_2 = API_TEST_UPLOAD_PRESET + "2" ;
3737 public static final String API_TEST_UPLOAD_PRESET_3 = API_TEST_UPLOAD_PRESET + "3" ;
3838 public static final String API_TEST_UPLOAD_PRESET_4 = API_TEST_UPLOAD_PRESET + "4" ;
39+ public static final String [] UPLOAD_TAGS = {SDK_TEST_TAG , uniqueTag };
3940 protected Api api ;
4041
4142 @ BeforeClass
@@ -61,7 +62,8 @@ public static void setUpClass() throws IOException {
6162 public static void tearDownClass () {
6263 Api api = MockableTest .cleanUp ();
6364 try {
64- api .deleteResources (Arrays .asList (API_TEST , API_TEST_1 , API_TEST_2 , API_TEST_3 , API_TEST_5 ), ObjectUtils .emptyMap ());
65+ // api.deleteResources(Arrays.asList(API_TEST, API_TEST_1, API_TEST_2, API_TEST_3, API_TEST_5), ObjectUtils.emptyMap());
66+ api .deleteResourcesByTag (uniqueTag , ObjectUtils .emptyMap ());
6567 } catch (Exception ignored ) {
6668 }
6769 try {
@@ -183,12 +185,20 @@ public void test05ResourcesByPrefix() throws Exception {
183185 @ Test
184186 public void testResourcesListingDirection () throws Exception {
185187 // should allow listing resources in both directions
186- Map result = api .resourcesByTag (uniqueTag , ObjectUtils .asMap ("type" , "upload" , "direction" , "asc" ));
188+ Map result = api .resourcesByTag (uniqueTag , ObjectUtils .asMap ("type" , "upload" , "direction" , "asc" , "max_results" , 500 ));
187189 List <Map > resources = (List <Map >) result .get ("resources" );
188- result = api .resourcesByTag (uniqueTag , ObjectUtils .asMap ("type" , "upload" , "direction" , -1 ));
190+ ArrayList <String > resourceIds = new ArrayList <String >();
191+ for (Map resource : resources ) {
192+ resourceIds .add ((String ) resource .get ("public_id" ));
193+ }
194+ result = api .resourcesByTag (uniqueTag , ObjectUtils .asMap ("type" , "upload" , "direction" , -1 , "max_results" , 500 ));
189195 List <Map > resourcesDesc = (List <Map >) result .get ("resources" );
190- Collections .reverse (resources );
191- assertEquals (resources , resourcesDesc );
196+ ArrayList <String > resourceIdsDesc = new ArrayList <String >();
197+ for (Map resource : resourcesDesc ) {
198+ resourceIdsDesc .add ((String ) resource .get ("public_id" ));
199+ }
200+ Collections .reverse (resourceIds );
201+ assertEquals (resourceIds , resourceIdsDesc );
192202 }
193203
194204 @ Ignore
@@ -198,7 +208,7 @@ public void testResourcesListingStartAt() throws Exception {
198208 Thread .sleep (2000L );
199209 java .util .Date startAt = new java .util .Date ();
200210 Thread .sleep (2000L );
201- Map response = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("tags" , SDK_TEST_TAG ));
211+ Map response = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("tags" , UPLOAD_TAGS ));
202212 ApiResponse listResources = api .resources (ObjectUtils .asMap ("type" , "upload" , "start_at" , startAt , "direction" , "asc" ));
203213 List <Map > resources = (List <Map >) listResources .get ("resources" );
204214 assertEquals (response .get ("public_id" ), resources .get (0 ).get ("public_id" ));
@@ -252,7 +262,7 @@ public void test07ResourceMetadata() throws Exception {
252262 public void test08DeleteDerived () throws Exception {
253263 // should allow deleting derived resource
254264 cloudinary .uploader ().upload (SRC_TEST_IMAGE ,
255- ObjectUtils .asMap ("public_id" , API_TEST_3 , "tags" , SDK_TEST_TAG , "eager" , Collections .singletonList (new Transformation ().width (101 ).crop ("scale" ))));
265+ ObjectUtils .asMap ("public_id" , API_TEST_3 , "tags" , UPLOAD_TAGS , "eager" , Collections .singletonList (new Transformation ().width (101 ).crop ("scale" ))));
256266 Map resource = api .resource (API_TEST_3 , ObjectUtils .emptyMap ());
257267 assertNotNull (resource );
258268 List <Map > derived = (List <Map >) resource .get ("derived" );
@@ -269,7 +279,7 @@ public void test08DeleteDerived() throws Exception {
269279 public void test09DeleteResources () throws Exception {
270280 // should allow deleting resources
271281 String public_id = "api_,test3" ;
272- cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , public_id , "tags" , SDK_TEST_TAG ));
282+ cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , public_id , "tags" , UPLOAD_TAGS ));
273283 Map resource = api .resource (public_id , ObjectUtils .emptyMap ());
274284 assertNotNull (resource );
275285 api .deleteResources (Arrays .asList (API_TEST_2 , public_id ), ObjectUtils .emptyMap ());
@@ -279,7 +289,7 @@ public void test09DeleteResources() throws Exception {
279289 @ Test (expected = NotFound .class )
280290 public void test09aDeleteResourcesByPrefix () throws Exception {
281291 // should allow deleting resources
282- cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "api_test_by_prefix" , "tags" , SDK_TEST_TAG ));
292+ cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "api_test_by_prefix" , "tags" , UPLOAD_TAGS ));
283293 Map resource = api .resource ("api_test_by_prefix" , ObjectUtils .emptyMap ());
284294 assertNotNull (resource );
285295 api .deleteResourcesByPrefix ("api_test_by" , ObjectUtils .emptyMap ());
@@ -434,7 +444,7 @@ public void test19Ping() throws Exception {
434444 public void testDeleteAllResources () throws Exception {
435445 // should allow deleting all resources
436446 cloudinary .uploader ().upload (SRC_TEST_IMAGE ,
437- ObjectUtils .asMap ("public_id" , API_TEST_5 , "tags" , SDK_TEST_TAG , "eager" , Collections .singletonList (new Transformation ().crop ("scale" ).width (2.0 ))));
447+ ObjectUtils .asMap ("public_id" , API_TEST_5 , "tags" , UPLOAD_TAGS , "eager" , Collections .singletonList (new Transformation ().crop ("scale" ).width (2.0 ))));
438448 Map result = api .resource (API_TEST_5 , ObjectUtils .emptyMap ());
439449 assertEquals (1 , ((org .cloudinary .json .JSONArray ) result .get ("derived" )).length ());
440450 api .deleteAllResources (ObjectUtils .asMap ("keep_original" , true ));
@@ -446,16 +456,16 @@ public void testDeleteAllResources() throws Exception {
446456 @ Test
447457 public void testManualModeration () throws Exception {
448458 // should support setting manual moderation status
449- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("moderation" , "manual" , "tags" , SDK_TEST_TAG ));
450- Map apiResult = api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("moderation_status" , "approved" , "tags" , SDK_TEST_TAG ));
459+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("moderation" , "manual" , "tags" , UPLOAD_TAGS ));
460+ Map apiResult = api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("moderation_status" , "approved" , "tags" , UPLOAD_TAGS ));
451461 assertEquals ("approved" , ((Map ) ((List <Map >) apiResult .get ("moderation" )).get (0 )).get ("status" ));
452462 }
453463
454464 @ Test
455465 public void testOcrUpdate () {
456466 // should support requesting ocr info
457467 try {
458- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , SDK_TEST_TAG ));
468+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
459469 api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("ocr" , "illegal" ));
460470 } catch (Exception e ) {
461471 assertTrue (e instanceof BadRequest );
@@ -467,7 +477,7 @@ public void testOcrUpdate() {
467477 public void testRawConvertUpdate () {
468478 // should support requesting raw conversion
469479 try {
470- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , SDK_TEST_TAG ));
480+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
471481 api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("raw_convert" , "illegal" ));
472482 } catch (Exception e ) {
473483 assertTrue (e instanceof BadRequest );
@@ -479,7 +489,7 @@ public void testRawConvertUpdate() {
479489 public void testCategorizationUpdate () {
480490 // should support requesting categorization
481491 try {
482- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , SDK_TEST_TAG ));
492+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
483493 api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("categorization" , "illegal" ));
484494 } catch (Exception e ) {
485495 assertTrue (e instanceof BadRequest );
@@ -491,7 +501,7 @@ public void testCategorizationUpdate() {
491501 public void testDetectionUpdate () {
492502 // should support requesting detection
493503 try {
494- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , SDK_TEST_TAG ));
504+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
495505 api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("detection" , "illegal" ));
496506 } catch (Exception e ) {
497507 assertTrue (e instanceof BadRequest );
@@ -503,7 +513,7 @@ public void testDetectionUpdate() {
503513 public void testSimilaritySearchUpdate () {
504514 // should support requesting similarity search
505515 try {
506- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , SDK_TEST_TAG ));
516+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
507517 api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("similarity_search" , "illegal" ));
508518 } catch (Exception e ) {
509519 assertTrue (e instanceof BadRequest );
@@ -515,7 +525,7 @@ public void testSimilaritySearchUpdate() {
515525 public void testUpdateCustomCoordinates () throws IOException , Exception {
516526 // should update custom coordinates
517527 Coordinates coordinates = new Coordinates ("121,31,110,151" );
518- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , SDK_TEST_TAG ));
528+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
519529 cloudinary .api ().update (uploadResult .get ("public_id" ).toString (), ObjectUtils .asMap ("custom_coordinates" , coordinates ));
520530 Map result = cloudinary .api ().resource (uploadResult .get ("public_id" ).toString (), ObjectUtils .asMap ("coordinates" , true ));
521531 int [] expected = new int []{121 , 31 , 110 , 151 };
@@ -601,9 +611,9 @@ public void testListByModerationUpdate() throws Exception {
601611 // "should support listing by moderation kind and value
602612 List <Map > resources ;
603613
604- Map result1 = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("moderation" , "manual" , "tags" , SDK_TEST_TAG ));
605- Map result2 = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("moderation" , "manual" , "tags" , SDK_TEST_TAG ));
606- Map result3 = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("moderation" , "manual" , "tags" , SDK_TEST_TAG ));
614+ Map result1 = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("moderation" , "manual" , "tags" , UPLOAD_TAGS ));
615+ Map result2 = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("moderation" , "manual" , "tags" , UPLOAD_TAGS ));
616+ Map result3 = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("moderation" , "manual" , "tags" , UPLOAD_TAGS ));
607617 api .update ((String ) result1 .get ("public_id" ), ObjectUtils .asMap ("moderation_status" , "approved" ));
608618 api .update ((String ) result2 .get ("public_id" ), ObjectUtils .asMap ("moderation_status" , "rejected" ));
609619 Map approved = api .resourcesByModeration ("manual" , "approved" , ObjectUtils .asMap ("max_results" , 1000 ));
@@ -632,10 +642,10 @@ public void testListByModerationUpdate() throws Exception {
632642 // @Test
633643 public void testFolderApi () throws Exception {
634644 // should allow deleting all resources
635- cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "test_folder1/item" , "tags" , SDK_TEST_TAG ));
636- cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "test_folder2/item" , "tags" , SDK_TEST_TAG ));
637- cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "test_folder1/test_subfolder1/item" , "tags" , SDK_TEST_TAG ));
638- cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "test_folder1/test_subfolder2/item" , "tags" , SDK_TEST_TAG ));
645+ cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "test_folder1/item" , "tags" , UPLOAD_TAGS ));
646+ cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "test_folder2/item" , "tags" , UPLOAD_TAGS ));
647+ cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "test_folder1/test_subfolder1/item" , "tags" , UPLOAD_TAGS ));
648+ cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "test_folder1/test_subfolder2/item" , "tags" , UPLOAD_TAGS ));
639649 Map result = api .rootFolders (null );
640650 assertEquals ("test_folder1" , ((Map ) ((org .cloudinary .json .JSONArray ) result .get ("folders" )).get (0 )).get ("name" ));
641651 assertEquals ("test_folder2" , ((Map ) ((org .cloudinary .json .JSONArray ) result .get ("folders" )).get (1 )).get ("name" ));
@@ -654,7 +664,7 @@ public void testFolderApi() throws Exception {
654664 public void testRestore () throws Exception {
655665 // should support restoring resources
656666 cloudinary .uploader ().upload (SRC_TEST_IMAGE ,
657- ObjectUtils .asMap ("public_id" , "api_test_restore" , "backup" , true , "tags" , SDK_TEST_TAG ));
667+ ObjectUtils .asMap ("public_id" , "api_test_restore" , "backup" , true , "tags" , UPLOAD_TAGS ));
658668 Map resource = api .resource ("api_test_restore" , ObjectUtils .emptyMap ());
659669 assertEquals (resource .get ("bytes" ), 3381 );
660670 api .deleteResources (Collections .singletonList ("api_test_restore" ), ObjectUtils .emptyMap ());
0 commit comments