diff --git a/cloudinary-core/src/main/java/com/cloudinary/Api.java b/cloudinary-core/src/main/java/com/cloudinary/Api.java index 0fe6c180..1627c997 100644 --- a/cloudinary-core/src/main/java/com/cloudinary/Api.java +++ b/cloudinary-core/src/main/java/com/cloudinary/Api.java @@ -244,7 +244,7 @@ public ApiResponse updateUploadPreset(String name, Map options) throws Exception if (options == null) options = ObjectUtils.emptyMap(); Map params = Util.buildUploadParams(options); Util.clearEmpty(params); - params.putAll(ObjectUtils.only(options, "unsigned", "disallow_public_id","live")); + params.putAll(ObjectUtils.only(options, "unsigned", "disallow_public_id", "live")); return callApi(HttpMethod.PUT, Arrays.asList("upload_presets", name), params, options); } @@ -252,7 +252,7 @@ public ApiResponse createUploadPreset(Map options) throws Exception { if (options == null) options = ObjectUtils.emptyMap(); Map params = Util.buildUploadParams(options); Util.clearEmpty(params); - params.putAll(ObjectUtils.only(options, "name", "unsigned", "disallow_public_id","live")); + params.putAll(ObjectUtils.only(options, "name", "unsigned", "disallow_public_id", "live")); return callApi(HttpMethod.POST, Arrays.asList("upload_presets"), params, options); } @@ -268,6 +268,13 @@ public ApiResponse subFolders(String ofFolderPath, Map options) throws Exception return callApi(HttpMethod.GET, Arrays.asList("folders", ofFolderPath), ObjectUtils.emptyMap(), options); } + //Creates an empty folder + public ApiResponse createFolder(String folderName, Map options) throws Exception { + if (options == null) + options = ObjectUtils.emptyMap(); + return callApi(HttpMethod.POST, Arrays.asList("folders", folderName), ObjectUtils.emptyMap(), options); + } + public ApiResponse restore(Iterable publicIds, Map options) throws Exception { if (options == null) options = ObjectUtils.emptyMap(); @@ -583,7 +590,7 @@ private ApiResponse updateResourcesAccessMode(String accessMode, String byKey, O */ public ApiResponse addMetadataField(MetadataField field) throws Exception { return callApi(HttpMethod.POST, Collections.singletonList("metadata_fields"), - ObjectUtils.toMap(field), ObjectUtils.asMap ("content_type", "json")); + ObjectUtils.toMap(field), ObjectUtils.asMap("content_type", "json")); } /** @@ -639,7 +646,7 @@ public ApiResponse updateMetadataFieldDatasource(String fieldExternalId, List entriesExternalId) throws Exception { List uri = Arrays.asList("metadata_fields", fieldExternalId, "datasource"); - return callApi(HttpMethod.DELETE, uri,Collections.singletonMap("external_ids", entriesExternalId) , Collections.emptyMap()); + return callApi(HttpMethod.DELETE, uri, Collections.singletonMap("external_ids", entriesExternalId), Collections.emptyMap()); } /** diff --git a/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractApiTest.java b/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractApiTest.java index 068768c6..5ae9598c 100644 --- a/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractApiTest.java +++ b/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractApiTest.java @@ -46,6 +46,7 @@ abstract public class AbstractApiTest extends MockableTest { public static final Transformation DELETE_TRANSFORMATION = new Transformation().width(100).crop("scale").overlay(new TextLayer().text(SUFFIX + "_delete").fontFamily("Arial").fontSize(60)); public static final String TEST_KEY = "test-key" + SUFFIX; public static final String API_TEST_RESTORE = "api_test_restore" + SUFFIX; + public static final Set createdFolders = new HashSet(); protected Api api; @@ -119,6 +120,12 @@ public static void tearDownClass() { api.deleteUploadPreset(API_TEST_UPLOAD_PRESET_4, ObjectUtils.emptyMap()); } catch (Exception ignored) { } + try { + for (String folder : createdFolders) { + api.deleteFolder(folder, ObjectUtils.emptyMap()); + } + } catch (Exception ignored) { + } } @@ -484,7 +491,8 @@ public void testListTransformationByNamed() throws Exception { } finally { try { api.deleteTransformation(name, null); - } catch (Exception ignored){} + } catch (Exception ignored) { + } } } @@ -653,7 +661,7 @@ public void testGetUploadPreset() throws Exception { String[] tags = {"a", "b", "c"}; Map context = ObjectUtils.asMap("a", "b", "c", "d"); Map result = api.createUploadPreset(ObjectUtils.asMap("unsigned", true, "folder", "folder", "transformation", EXPLICIT_TRANSFORMATION, "tags", tags, "context", - context,"live",true)); + context, "live", true)); String name = result.get("name").toString(); Map preset = api.uploadPreset(name, ObjectUtils.emptyMap()); assertEquals(preset.get("name"), name); @@ -693,7 +701,7 @@ public void testUpdateUploadPreset() throws Exception { String name = api.createUploadPreset(ObjectUtils.asMap("folder", "folder")).get("name").toString(); Map preset = api.uploadPreset(name, ObjectUtils.emptyMap()); Map settings = (Map) preset.get("settings"); - settings.putAll(ObjectUtils.asMap("colors", true, "unsigned", true, "disallow_public_id", true,"live",true)); + settings.putAll(ObjectUtils.asMap("colors", true, "unsigned", true, "disallow_public_id", true, "live", true)); api.updateUploadPreset(name, settings); settings.remove("unsigned"); preset = api.uploadPreset(name, ObjectUtils.emptyMap()); @@ -758,6 +766,14 @@ public void testFolderApi() throws Exception { api.deleteResourcesByPrefix("test_folder", ObjectUtils.emptyMap()); } + @Test + public void testCreateFolder() throws Exception { + String apTestCreateFolder = "api_test_create_folder" + "_" + SUFFIX; + createdFolders.add(apTestCreateFolder); + Map result = api.createFolder("apTestCreateFolder", null); + assertTrue((Boolean) result.get("success")); + } + @Test public void testRestore() throws Exception { // should support restoring resources @@ -946,7 +962,7 @@ public void testDeleteFolder() throws Exception { Thread.sleep(5000); api.deleteResources(Collections.singletonList(uploadResult.get("public_id").toString()), emptyMap()); ApiResponse result = api.deleteFolder(toDelete, emptyMap()); - assertTrue(((ArrayList)result.get("deleted")).contains(toDelete)); + assertTrue(((ArrayList) result.get("deleted")).contains(toDelete)); // should throw exception (folder not found): api.deleteFolder(cloudinary.randomPublicId(), emptyMap()); @@ -958,4 +974,4 @@ public void testCinemagraphAnalysisResource() throws Exception { ApiResponse res = api.resource(API_TEST, Collections.singletonMap("cinemagraph_analysis", true)); assertNotNull(res.get("cinemagraph_analysis")); } -} \ No newline at end of file +}