|
| 1 | +package com.cloudinary.test; |
| 2 | + |
| 3 | +import com.cloudinary.Api; |
| 4 | +import com.cloudinary.Cloudinary; |
| 5 | +import com.cloudinary.api.ApiResponse; |
| 6 | +import com.cloudinary.utils.ObjectUtils; |
| 7 | +import org.junit.Before; |
| 8 | +import org.junit.Rule; |
| 9 | +import org.junit.Test; |
| 10 | +import org.junit.rules.TestName; |
| 11 | + |
| 12 | +import java.util.List; |
| 13 | + |
| 14 | +import static org.junit.Assert.*; |
| 15 | +import static org.junit.Assume.assumeNotNull; |
| 16 | + |
| 17 | +@SuppressWarnings({"rawtypes"}) |
| 18 | +abstract public class AbstractFoldersApiTest extends MockableTest { |
| 19 | + protected Api api; |
| 20 | + |
| 21 | + @Rule |
| 22 | + public TestName currentTest = new TestName(); |
| 23 | + |
| 24 | + @Before |
| 25 | + public void setUp() { |
| 26 | + System.out.println("Running " + this.getClass().getName() + "." + currentTest.getMethodName()); |
| 27 | + this.cloudinary = new Cloudinary(); |
| 28 | + assumeNotNull(cloudinary.config.apiSecret); |
| 29 | + this.api = cloudinary.api(); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void testRootFolderWithParams() throws Exception { |
| 34 | + String rootFolder1Name = "rootFolderWithParamsTest1" + SUFFIX; |
| 35 | + assertTrue((Boolean) api.createFolder(rootFolder1Name, null).get("success")); |
| 36 | + |
| 37 | + String rootFolder2Name = "rootFolderWithParamsTest2" + SUFFIX; |
| 38 | + assertTrue((Boolean) api.createFolder(rootFolder2Name, null).get("success")); |
| 39 | + |
| 40 | + Thread.sleep(500); |
| 41 | + |
| 42 | + ApiResponse rootResponse1 = api.rootFolders(ObjectUtils.asMap("max_results", 1)); |
| 43 | + List rootFolders1 = (List) rootResponse1.get("folders"); |
| 44 | + assertNotNull(rootFolders1); |
| 45 | + assertEquals(1, rootFolders1.size()); |
| 46 | + |
| 47 | + String nextCursor = (String) rootResponse1.get("next_cursor"); |
| 48 | + assertNotNull(nextCursor); |
| 49 | + |
| 50 | + ApiResponse rootResponse2 = api.rootFolders(ObjectUtils.asMap("max_results", 1, "next_cursor", nextCursor)); |
| 51 | + List folders2 = (List) rootResponse2.get("folders"); |
| 52 | + assertNotNull(folders2); |
| 53 | + assertEquals(1, folders2.size()); |
| 54 | + |
| 55 | + assertTrue(((List) api.deleteFolder(rootFolder1Name, null).get("deleted")).contains(rootFolder1Name)); |
| 56 | + assertTrue(((List) api.deleteFolder(rootFolder2Name, null).get("deleted")).contains(rootFolder2Name)); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testSubFolderWithParams() throws Exception { |
| 61 | + String rootFolderName = "subfolderWithParamsTest" + SUFFIX; |
| 62 | + assertTrue((Boolean) api.createFolder(rootFolderName, null).get("success")); |
| 63 | + |
| 64 | + String subFolder1Name = rootFolderName + "/subfolder1" + SUFFIX; |
| 65 | + assertTrue((Boolean) api.createFolder(subFolder1Name, null).get("success")); |
| 66 | + |
| 67 | + String subFolder2Name = rootFolderName + "/subfolder2" + SUFFIX; |
| 68 | + assertTrue((Boolean) api.createFolder(subFolder2Name, null).get("success")); |
| 69 | + |
| 70 | + Thread.sleep(500); |
| 71 | + |
| 72 | + ApiResponse response = api.subFolders(rootFolderName, ObjectUtils.asMap("max_results", 1)); |
| 73 | + List folders = (List) response.get("folders"); |
| 74 | + assertNotNull(folders); |
| 75 | + assertEquals(1, folders.size()); |
| 76 | + |
| 77 | + String nextCursor = (String) response.get("next_cursor"); |
| 78 | + assertNotNull(nextCursor); |
| 79 | + |
| 80 | + ApiResponse response2 = api.subFolders(rootFolderName, ObjectUtils.asMap("max_results", 1, "next_cursor", nextCursor)); |
| 81 | + List folders2 = (List) response2.get("folders"); |
| 82 | + assertNotNull(folders2); |
| 83 | + assertEquals(1, folders2.size()); |
| 84 | + |
| 85 | + ApiResponse result = api.deleteFolder(rootFolderName, null); |
| 86 | + assertTrue(((List) result.get("deleted")).contains(rootFolderName)); |
| 87 | + } |
| 88 | +} |
0 commit comments