@Test public void testGetUploadPreset() throws Exception { // should allow getting a single upload_preset String[] tags = {"a", "b", "c"}; Map context = Cloudinary.asMap("a", "b", "c", "d"); Transformation transformation = new Transformation(); transformation.width(100).crop("scale"); Map result = api.createUploadPreset( Cloudinary.asMap( "unsigned", true, "folder", "folder", "transformation", transformation, "tags", tags, "context", context)); String name = result.get("name").toString(); Map preset = api.uploadPreset(name, Cloudinary.emptyMap()); assertEquals(preset.get("name"), name); assertEquals(Boolean.TRUE, preset.get("unsigned")); Map settings = (Map) preset.get("settings"); assertEquals(settings.get("folder"), "folder"); Map outTransformation = (Map) ((org.json.simple.JSONArray) settings.get("transformation")).get(0); assertEquals(outTransformation.get("width"), 100L); assertEquals(outTransformation.get("crop"), "scale"); Object[] outTags = ((org.json.simple.JSONArray) settings.get("tags")).toArray(); assertArrayEquals(tags, outTags); Map outContext = (Map) settings.get("context"); assertEquals(context, outContext); }
@Test public void testListUploadPresets() throws Exception { // should allow creating and listing upload_presets api.createUploadPreset(Cloudinary.asMap("name", "api_test_upload_preset", "folder", "folder")); api.createUploadPreset( Cloudinary.asMap("name", "api_test_upload_preset2", "folder", "folder2")); api.createUploadPreset( Cloudinary.asMap("name", "api_test_upload_preset3", "folder", "folder3")); org.json.simple.JSONArray presets = (org.json.simple.JSONArray) api.uploadPresets(Cloudinary.emptyMap()).get("presets"); assertEquals(((Map) presets.get(0)).get("name"), "api_test_upload_preset3"); assertEquals(((Map) presets.get(1)).get("name"), "api_test_upload_preset2"); assertEquals(((Map) presets.get(2)).get("name"), "api_test_upload_preset"); api.deleteUploadPreset("api_test_upload_preset", Cloudinary.emptyMap()); api.deleteUploadPreset("api_test_upload_preset2", Cloudinary.emptyMap()); api.deleteUploadPreset("api_test_upload_preset3", Cloudinary.emptyMap()); }
@Test public void testDeleteUploadPreset() throws Exception { // should allow deleting upload_presets", :upload_preset => true do api.createUploadPreset(Cloudinary.asMap("name", "api_test_upload_preset4", "folder", "folder")); api.uploadPreset("api_test_upload_preset4", Cloudinary.emptyMap()); api.deleteUploadPreset("api_test_upload_preset4", Cloudinary.emptyMap()); boolean error = false; try { api.uploadPreset("api_test_upload_preset4", Cloudinary.emptyMap()); } catch (Exception e) { error = true; } assertTrue(error); }
@Test public void testUpdateUploadPreset() throws Exception { // should allow updating upload_presets String name = api.createUploadPreset(Cloudinary.asMap("folder", "folder")).get("name").toString(); Map preset = api.uploadPreset(name, Cloudinary.emptyMap()); Map settings = (Map) preset.get("settings"); settings.putAll(Cloudinary.asMap("colors", true, "unsigned", true, "disallow_public_id", true)); api.updateUploadPreset(name, settings); settings.remove("unsigned"); preset = api.uploadPreset(name, Cloudinary.emptyMap()); assertEquals(name, preset.get("name")); assertEquals(Boolean.TRUE, preset.get("unsigned")); assertEquals(settings, preset.get("settings")); api.deleteUploadPreset(name, Cloudinary.emptyMap()); }