|
15 | 15 | import java.util.Collections; |
16 | 16 | import java.util.HashMap; |
17 | 17 | import java.util.List; |
| 18 | +import java.util.ListIterator; |
18 | 19 | import java.util.Map; |
19 | 20 |
|
20 | 21 | import org.junit.Before; |
@@ -640,6 +641,66 @@ public void testFolderApi() throws Exception { |
640 | 641 | } |
641 | 642 | api.deleteResourcesByPrefix("test_folder", ObjectUtils.emptyMap()); |
642 | 643 | } |
| 644 | + |
| 645 | + @Test |
| 646 | + public void testRestore() throws Exception { |
| 647 | + // should support restoring resources |
| 648 | + cloudinary.uploader().upload(SRC_TEST_IMAGE, |
| 649 | + ObjectUtils.asMap("public_id", "api_test_restore", "backup", true)); |
| 650 | + Map resource = api.resource("api_test_restore", ObjectUtils.emptyMap()); |
| 651 | + assertEquals(resource.get("bytes"), 3381); |
| 652 | + api.deleteResources(Arrays.asList("api_test_restore"), ObjectUtils.emptyMap()); |
| 653 | + resource = api.resource("api_test_restore", ObjectUtils.emptyMap()); |
| 654 | + assertEquals(resource.get("bytes"), 0); |
| 655 | + assertTrue((Boolean) resource.get("placeholder")); |
| 656 | + Map response = api.restore(Arrays.asList("api_test_restore"), ObjectUtils.emptyMap()); |
| 657 | + Map info = (Map) response.get("api_test_restore"); |
| 658 | + assertNotNull(info); |
| 659 | + assertEquals(info.get("bytes"), 3381); |
| 660 | + resource = api.resource("api_test_restore", ObjectUtils.emptyMap()); |
| 661 | + assertEquals(resource.get("bytes"), 3381); |
| 662 | + } |
| 663 | + |
| 664 | + @Test |
| 665 | + public void testUploadMapping() throws Exception { |
| 666 | + try { |
| 667 | + api.deleteUploadMapping("api_test_upload_mapping", ObjectUtils.emptyMap()); |
| 668 | + } catch (Exception e) { |
| 669 | + |
| 670 | + } |
| 671 | + api.createUploadMapping("api_test_upload_mapping", ObjectUtils.asMap("template", "http://cloudinary.com")); |
| 672 | + Map result = api.uploadMapping("api_test_upload_mapping", ObjectUtils.emptyMap()); |
| 673 | + assertEquals(result.get("template"), "http://cloudinary.com"); |
| 674 | + api.updateUploadMapping("api_test_upload_mapping", ObjectUtils.asMap("template", "http://res.cloudinary.com")); |
| 675 | + result = api.uploadMapping("api_test_upload_mapping", ObjectUtils.emptyMap()); |
| 676 | + assertEquals(result.get("template"), "http://res.cloudinary.com"); |
| 677 | + result = api.uploadMappings(ObjectUtils.emptyMap()); |
| 678 | + ListIterator mappings = ((ArrayList) result.get("mappings")).listIterator(); |
| 679 | + boolean found = false; |
| 680 | + while (mappings.hasNext()) { |
| 681 | + Map mapping = (Map) mappings.next(); |
| 682 | + if (mapping.get("folder").equals("api_test_upload_mapping") |
| 683 | + && mapping.get("template").equals("http://res.cloudinary.com")) { |
| 684 | + found = true; |
| 685 | + break; |
| 686 | + } |
| 687 | + } |
| 688 | + assertTrue(found); |
| 689 | + api.deleteUploadMapping("api_test_upload_mapping", ObjectUtils.emptyMap()); |
| 690 | + result = api.uploadMappings(ObjectUtils.emptyMap()); |
| 691 | + found = false; |
| 692 | + while (mappings.hasNext()) { |
| 693 | + Map mapping = (Map) mappings.next(); |
| 694 | + if (mapping.get("folder").equals("api_test_upload_mapping") |
| 695 | + && mapping.get("template").equals("http://res.cloudinary.com")) { |
| 696 | + found = true; |
| 697 | + break; |
| 698 | + } |
| 699 | + } |
| 700 | + assertTrue(!found); |
| 701 | + } |
| 702 | + |
| 703 | + |
643 | 704 |
|
644 | 705 | private void assertContains(Object object, Collection list) { |
645 | 706 | assertTrue(list.contains(object)); |
|
0 commit comments