@SuppressWarnings("unchecked") @Test public void testEscapePublicId() { // should escape public_ids Map<String, String> tests = asMap("a b", "a%20b", "a+b", "a%2Bb", "a%20b", "a%20b", "a-b", "a-b", "a??b", "a%3F%3Fb"); for (Map.Entry<String, String> entry : tests.entrySet()) { String result = cloudinary.url().generate(entry.getKey()); assertEquals(DEFAULT_UPLOAD_PATH + "" + entry.getValue(), result); } }
@Test public void testSpriteCss() { String result = cloudinary.url().generateSpriteCss("test"); assertEquals("http://res.cloudinary.com/test123/image/sprite/test.css", result); result = cloudinary.url().generateSpriteCss("test.css"); assertEquals("http://res.cloudinary.com/test123/image/sprite/test.css", result); }
@Test public void testVideoTag() { String expectedUrl = VIDEO_UPLOAD_PATH + "movie"; String expectedTag = "<video poster='%s.jpg'>" + "<source src='%s.webm' type='video/webm'>" + "<source src='%s.mp4' type='video/mp4'>" + "<source src='%s.ogv' type='video/ogg'>" + "</video>"; expectedTag = String.format(expectedTag, expectedUrl, expectedUrl, expectedUrl, expectedUrl); assertEquals(expectedTag, cloudinary.url().videoTag("movie", emptyMap())); assertEquals(expectedTag, cloudinary.url().publicId("movie").videoTag()); assertEquals(expectedTag, cloudinary.url().videoTag("movie")); }
@Test public void testIgnoreHttp() { // should ignore http links only if type is not given or is asset String result = cloudinary.url().generate("http://test"); assertEquals("http://test", result); result = cloudinary.url().type("asset").generate("http://test"); assertEquals("http://test", result); result = cloudinary.url().type("fetch").generate("http://test"); assertEquals("http://res.cloudinary.com/test123/image/fetch/http://test", result); }
@Test public void testSecureAkamai() { // should default to akamai if secure is given with private_cdn and no // secure_distribution cloudinary.config.secure = true; cloudinary.config.privateCdn = true; String result = cloudinary.url().generate("test"); assertEquals("https://test123-res.cloudinary.com/image/upload/test", result); }
@Test public void testType() { // should use type from options String result = cloudinary.url().type("facebook").generate("test"); assertEquals("http://res.cloudinary.com/test123/image/facebook/test", result); }
@Test public void testHttpEscape() { // should escape http urls String result = cloudinary.url().type("youtube").generate("http://www.youtube.com/watch?v=d9NF2edxy-M"); assertEquals("http://res.cloudinary.com/test123/image/youtube/http://www.youtube.com/watch%3Fv%3Dd9NF2edxy-M", result); }
@Test public void testAspectRatio() { String actual = cloudinary.url().transformation(new Transformation().aspectRatio("1.5")) .generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "ar_1.5/test", actual); actual = cloudinary.url().transformation(new Transformation().aspectRatio(1.5)) .generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "ar_1.5/test", actual); actual = cloudinary.url().transformation(new Transformation().aspectRatio(3, 2)) .generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "ar_3:2/test", actual); }
@Test public void testAngle() { // should support angle Transformation transformation = new Transformation().angle(12); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "a_12/test", result); transformation = new Transformation().angle("exif", "12"); result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "a_exif.12/test", result); }
@Test public void testSupportUrlSuffixForPrivateCdn() { String actual = cloudinary.url().suffix("hello").privateCdn(true).generate("test"); assertEquals("http://test123-res.cloudinary.com/images/test/hello", actual); actual = cloudinary.url().suffix("hello").privateCdn(true).transformation(new Transformation().angle(0)).generate("test"); assertEquals("http://test123-res.cloudinary.com/images/a_0/test/hello", actual); }
@Test public void testSupportUrlSuffixForVideoUploads() { String actual = cloudinary.url().suffix("hello").privateCdn(true).resourceType("video").generate("test"); assertEquals("http://test123-res.cloudinary.com/videos/test/hello", actual); }
@Test public void testSupportUseRootPathForPrivateCdn() { String actual = cloudinary.url().privateCdn(true).useRootPath(true).generate("test"); assertEquals("http://test123-res.cloudinary.com/test", actual); actual = cloudinary.url().privateCdn(true).transformation(new Transformation().angle(0)).useRootPath(true).generate("test"); assertEquals("http://test123-res.cloudinary.com/a_0/test", actual); }
@Test public void testSupportUseRootPathTogetherWithUrlSuffixForPrivateCdn() { String actual = cloudinary.url().privateCdn(true).suffix("hello").useRootPath(true).generate("test"); assertEquals("http://test123-res.cloudinary.com/test/hello", actual); }
@Test public void testEffectWithParam() { // should support effect with param Transformation transformation = new Transformation().effect("sepia", 10); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "e_sepia:10/test", result); }
@Test public void testDensity() { // should support density Transformation transformation = new Transformation().density(150); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "dn_150/test", result); }
@Test public void testPage() { // should support page Transformation transformation = new Transformation().page(5); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "pg_5/test", result); }
@Test public void testUrlInTag() { String message = "should add token to an image tag url"; String url = cloudinary.url().signed(true).resourceType("image").type("authenticated").version("1486020273").imageTag("sample.jpg"); assertThat(url, Matchers.matchesPattern("<img.*src='http://res.cloudinary.com/test123/image/authenticated/v1486020273/sample.jpg\\?__cld_token__=st=11111111~exp=11111411~hmac=9bd6f41e2a5893da8343dc8eb648de8bf73771993a6d1457d49851250caf3b80.*>")); } }
@Test public void testUrlCloneConfig(){ // verify that secure (from url.config) is cloned as well: Url url = cloudinary.url().cloudName("cloud").format("frmt").publicId("123").secure(true); assertEquals("https://res.cloudinary.com/cloud/image/upload/123.frmt", url.clone().generate()); } }
@Test public void testVariousOptions() { // should use x, y, radius, prefix, gravity and quality from options Transformation transformation = new Transformation().x(1).y(2).radius(3).gravity("center").quality(0.4).prefix("a"); String result = cloudinary.url().transformation(transformation).generate("test"); assertEquals(DEFAULT_UPLOAD_PATH + "g_center,p_a,q_0.4,r_3,x_1,y_2/test", result); }
@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); }