private static List<EffectData> generateVideoEffects(Context context, Resource resource) { List<EffectData> effects = new ArrayList<>(); Transformation transformation; transformation = new Transformation().angle(20); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_rotation), context.getString(R.string.effect_video_rotate))); transformation = new Transformation().effect("fade", 1000); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_fade_in), context.getString(R.string.effect_video_fade_in))); transformation = new Transformation().chain().overlay("video:" + resource.getCloudinaryPublicId()).width(0.5).flags("relative").gravity("north_east"); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_overlay), context.getString(R.string.effect_desc_video_overlay))); transformation = new Transformation().effect("noise", 50); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_noise), context.getString(R.string.effect_desc_video_noise))); transformation = new Transformation().effect("blur", 200); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_blur), context.getString(R.string.effect_desc_video_blur))); transformation = new Transformation().effect("reverse"); effects.add(new EffectData(resource.getCloudinaryPublicId(), transformation, context.getString(R.string.effect_video_name_reverse), context.getString(R.string.effect_desc_video_reverse))); return effects; }
@SuppressWarnings("unchecked") @Test public void testOptionsSerialization() throws IOException, ClassNotFoundException { Map<String, Object> options = new HashMap<>(); options.put("integer", 12); options.put("string", "twelve"); options.put("transformation", new Transformation().angle(30)); options.put("array", new int[]{1, 2, 3}); Map<String, Object> newMap = (Map<String, Object>) ObjectUtils.deserialize(ObjectUtils.serialize(options)); assertEquals(12, newMap.get("integer")); assertEquals("twelve", newMap.get("string")); assertEquals(new Transformation().angle(30).generate(), ((Transformation) newMap.get("transformation")).generate()); assertTrue(Arrays.equals(new int[]{1, 2, 3}, (int[]) newMap.get("array"))); } }
.createDerived(true) .maxImages(2) .transformation(new Transformation().angle(90)) .format("gif");
@Test() public void testDeleteDerivedByTransformation() throws Exception { // should allow deleting resources String public_id = "api_test_123" + SUFFIX; List<Transformation> transformations = new ArrayList<Transformation>(); transformations.add(new Transformation().angle(90)); transformations.add(new Transformation().width(120)); cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", public_id, "tags", UPLOAD_TAGS, "eager", transformations)); Map resource = api.resource(public_id, ObjectUtils.emptyMap()); assertNotNull(resource); List derived = ((List) resource.get("derived")); assertTrue(derived.size() == 2); api.deleteDerivedByTransformation(ObjectUtils.asArray(public_id), ObjectUtils.asArray(transformations), ObjectUtils.emptyMap()); resource = api.resource(public_id, ObjectUtils.emptyMap()); assertNotNull(resource); derived = ((List) resource.get("derived")); assertTrue(derived.size() == 0); }
@Test public void testNotSignTheUrlSuffix() { Pattern pattern = Pattern.compile("s--[0-9A-Za-z_-]{8}--"); String url = cloudinary.url().format("jpg").signed(true).generate("test"); Matcher matcher = pattern.matcher(url); matcher.find(); String expectedSignature = url.substring(matcher.start(), matcher.end()); String actual = cloudinary.url().format("jpg").privateCdn(true).signed(true).suffix("hello").generate("test"); assertEquals("http://test123-res.cloudinary.com/images/" + expectedSignature + "/test/hello.jpg", actual); url = cloudinary.url().format("jpg").signed(true).transformation(new Transformation().angle(0)).generate("test"); matcher = pattern.matcher(url); matcher.find(); expectedSignature = url.substring(matcher.start(), matcher.end()); actual = cloudinary.url().format("jpg").privateCdn(true).signed(true).suffix("hello").transformation(new Transformation().angle(0)).generate("test"); assertEquals("http://test123-res.cloudinary.com/images/" + expectedSignature + "/a_0/test/hello.jpg", actual); }
@Test public void testResponsiveBreakpointsToJson() { assertEquals("an empty ResponsiveBreakpoint should have create_derived=true", "{\"create_derived\":true}", new ResponsiveBreakpoint().toString() ); String[] expectedArr = "{\"create_derived\":false,\"max_width\":500,\"min_width\":100,\"max_images\":5,\"transformation\":\"a_45\"}".split("[{}]")[1].split(",(?=\")"); Arrays.sort(expectedArr); JSONObject actual = new ResponsiveBreakpoint().createDerived(false) .transformation(new Transformation().angle(45)) .maxWidth(500) .minWidth(100) .maxImages(5); String[] actualArr = actual.toString().split("[{}]")[1].split(",(?=\")"); Arrays.sort(actualArr); assertArrayEquals(expectedArr, actualArr); }
@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 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); }