@Test public void testExplicit() throws IOException { Map result = cloudinary.uploader().explicit("sample", asMap("eager", Collections.singletonList(new Transformation().crop("scale").width(2.0)), "type", "upload", "moderation", "manual")); String url = cloudinary.url().transformation(new Transformation().crop("scale").width(2.0)).format("jpg").version(result.get("version")).generate("sample"); String eagerUrl = (String) ((Map) ((List) result.get("eager")).get(0)).get("url"); String cloudName = cloudinary.config.cloudName; assertEquals(eagerUrl.substring(eagerUrl.indexOf(cloudName)), url.substring(url.indexOf(cloudName))); }
@Test public void testCreateArchive() throws Exception { List<String> toDelete = new ArrayList<>(2); Map result = cloudinary.uploader().createArchive(new ArchiveParams().tags(new String[]{ARCHIVE_TAG})); toDelete.add(result.get("public_id").toString()); assertEquals(2, result.get("file_count")); result = cloudinary.uploader().createArchive( new ArchiveParams().tags(new String[]{ARCHIVE_TAG}).transformations( new Transformation[]{new Transformation().width(0.5), new Transformation().width(2.0)})); toDelete.add(result.get("public_id").toString()); assertEquals(4, result.get("file_count")); cloudinary.api().deleteResources(toDelete, asMap("resource_type", "raw")); }
@Test public void testUploadAsync() throws IOException { Map result = cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("transformation", new Transformation().crop("scale").width(2.0), "async", true, "tags", Arrays.asList(SDK_TEST_TAG, UPLOADER_TAG))); assertEquals((String) result.get("status"), "pending"); }
@Test public void test12Transformations() throws Exception { // should allow listing transformations final Transformation listTest = new Transformation().width(25).crop("scale").overlay(new TextLayer().text(SUFFIX + "_testListTransformations").fontFamily("Arial").fontSize(60)); preloadResource(ObjectUtils.asMap("tags", UPLOAD_TAGS, "eager", Collections.singletonList(listTest))); Map result = api.transformations(ObjectUtils.asMap("max_results", 500)); Map transformation = findByAttr((List<Map>) result.get("transformations"), "name", listTest.generate()); assertNotNull(transformation); assertTrue((Boolean) transformation.get("used")); }
public void testDeleteAllResources() throws Exception { // should allow deleting all resources cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", API_TEST_5, "tags", UPLOAD_TAGS, "eager", Collections.singletonList(new Transformation().crop("scale").width(2.0)))); Map result = api.resource(API_TEST_5, ObjectUtils.emptyMap()); assertEquals(1, ((org.cloudinary.json.JSONArray) result.get("derived")).length()); api.deleteAllResources(ObjectUtils.asMap("keep_original", true)); result = api.resource(API_TEST_5, ObjectUtils.emptyMap()); // assertEquals(0, ((org.cloudinary.json.JSONArray) // result.get("derived")).size()); }
public static String getUrlForMaxWidth(Context context, String imageId) { int width = Utils.getScreenWidth(context); return MediaManager.get().getCloudinary().url().transformation(new Transformation().width(width)).generate(imageId); }
@BeforeClass public static void setUpClass() throws IOException { Cloudinary cloudinary = new Cloudinary(); if (cloudinary.config.apiSecret == null) { System.err.println("Please setup environment for Upload test to run"); } cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG, ARCHIVE_TAG})); cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG, ARCHIVE_TAG}, "resource_type", "raw")); cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG, ARCHIVE_TAG}, "transformation", new Transformation().crop("scale").width(10))); }
@Test public void testCreate() throws Exception { ApiResponse result = api.createStreamingProfile(CREATE_PROFILE_NAME, null, Collections.singletonList(ObjectUtils.asMap( "transformation", new Transformation().crop("limit").width(1200).height(1200).bitRate("5m") )), ObjectUtils.emptyMap()); assertTrue(result.containsKey("data")); Map profile = (Map) result.get("data"); assertThat(profile, (Matcher) hasEntry("name", (Object) CREATE_PROFILE_NAME)); }
@Test public void testShouldSupportIhIw() { String trans = new Transformation().width("iw").height("ih").crop("crop").generate(); assertEquals("c_crop,h_ih,w_iw", trans); }
@Test(expected = NotFound.class) public void test16aTransformationDelete() throws Exception { // should allow deleting named transformation api.createTransformation(API_TEST_TRANSFORMATION_2, new Transformation().crop("scale").width(103).generate(), ObjectUtils.emptyMap()); api.transformation(API_TEST_TRANSFORMATION_2, ObjectUtils.emptyMap()); ApiResponse res = api.deleteTransformation(API_TEST_TRANSFORMATION_2, ObjectUtils.emptyMap()); assertEquals("deleted", res.get("message")); api.transformation(API_TEST_TRANSFORMATION_2, ObjectUtils.emptyMap()); }
@Test public void testUploadAsync() throws Exception { if (cloudinary.config.apiSecret == null) return; JSONObject result = new JSONObject(cloudinary.uploader().upload(getAssetStream(TEST_IMAGE), ObjectUtils.asMap("transformation", new Transformation().crop("scale").width(2.0), "async", true))); assertEquals(result.getString("status"), "pending"); }
@Test public void testBaseTransformationArray() { // should support array of base transformations Transformation transformation = new Transformation().x(100).y(100).width(200).crop("fill").chain().radius(10).chain().crop("crop").width(100); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals("100", transformation.getHtmlWidth()); assertEquals(DEFAULT_UPLOAD_PATH + "c_fill,w_200,x_100,y_100/r_10/c_crop,w_100/test", result); }
@Test public void endIf2() throws Exception { Transformation transformation = new Transformation().ifCondition().width("gt", 100).and().width("lt", 200).then().width(50).crop("scale").endIf(); assertEquals("should serialize to 'if_end'", "if_w_gt_100_and_w_lt_200/c_scale,w_50/if_end", transformation.toString()); transformation = new Transformation().ifCondition().width("gt", 100).and().width("lt", 200).then().width(50).crop("scale").endIf(); assertEquals("force the if clause to be chained", "if_w_gt_100_and_w_lt_200/c_scale,w_50/if_end", transformation.toString()); transformation = new Transformation().ifCondition().width("gt", 100).and().width("lt", 200).then().width(50).crop("scale").ifElse().width(100).crop("crop").endIf(); assertEquals("force the if_else clause to be chained", "if_w_gt_100_and_w_lt_200/c_scale,w_50/if_else/c_crop,w_100/if_end", transformation.toString()); }
@Test public void withLiteral() throws Exception { Transformation transformation = new Transformation().ifCondition("w_lt_200").crop("fill").height(120).width(80); assertEquals("should include the if parameter as the first component in the transformation string", "if_w_lt_200,c_fill,h_120,w_80", transformation.toString()); transformation = new Transformation().crop("fill").height(120).ifCondition("w_lt_200").width(80); assertEquals("should include the if parameter as the first component in the transformation string", "if_w_lt_200,c_fill,h_120,w_80", transformation.toString()); String chained = "[{if: \"w_lt_200\",crop: \"fill\",height: 120, width: 80}, {if: \"w_gt_400\",crop: \"fit\",width: 150,height: 150},{effect: \"sepia\"}]"; List transformations = ObjectUtils.toList(new JSONArray(chained)); transformation = new Transformation(transformations); assertEquals("should allow multiple conditions when chaining transformations", "if_w_lt_200,c_fill,h_120,w_80/if_w_gt_400,c_fit,h_150,w_150/e_sepia", transformation.toString()); }
@Test public void testCrop() { Transformation transformation = new Transformation().width(100).height(101); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "h_101,w_100/test", result); assertEquals("101", transformation.getHtmlHeight()); assertEquals("100", transformation.getHtmlWidth()); transformation = new Transformation().width(100).height(101).crop("crop"); result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "c_crop,h_101,w_100/test", result); }
@Test public void testArrayShouldDefineASetOfVariables() { // using methods Transformation t = new Transformation(); t.ifCondition("face_count > 2") .variables(variable("$z", 5), variable("$foo", "$z * 2")) .crop("scale") .width("$foo * 200"); assertEquals("if_fc_gt_2,$z_5,$foo_$z_mul_2,c_scale,w_$foo_mul_200", t.generate()); }
@Test @TestCaseName("{method}: {0}") @Parameters public void testAutoGravity(String value, String serialized) { Transformation transformation = new Transformation().crop("crop").gravity(value).width(0.5f); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "c_crop," + serialized + ",w_0.5/test", result); }
@Test public void testVariable(){ // using strings Transformation t = new Transformation(); t.variable("$foo", 10) .chain() .ifCondition(faceCount().gt(2)) .crop("scale") .width(new Condition("$foo * 200 / faceCount")) .endIf(); assertEquals("$foo_10/if_fc_gt_2/c_scale,w_$foo_mul_200_div_fc/if_end", t.generate()); }
@Test public void testBaseTransformations() { // should support base transformation Transformation transformation = new Transformation().x(100).y(100).crop("fill").chain().crop("crop").width(100); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals("100", transformation.getHtmlWidth()); assertEquals(DEFAULT_UPLOAD_PATH + "c_fill,x_100,y_100/c_crop,w_100/test", result); }
@Test public void testUnderlay() { Transformation transformation = new Transformation().underlay("text:hello"); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "u_text:hello/test", result); // should not pass width/height to html if underlay transformation = new Transformation().underlay("text:hello").width(100).height(100); result = cloudinary.url().transformation(transformation).generate("test"); assertNull(transformation.getHtmlHeight()); assertNull(transformation.getHtmlWidth()); assertEquals(DEFAULT_UPLOAD_PATH + "h_100,u_text:hello,w_100/test", result); }