Skip to content

Commit 738b328

Browse files
authored
Fix eager transformation chaining. (#159)
1 parent 3550095 commit 738b328

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

cloudinary-core/src/main/java/com/cloudinary/EagerTransformation.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ public String getFormat() {
2727
return format;
2828
}
2929

30+
@Override
31+
public String generate(Iterable<Map> optionsList) {
32+
List<String> components = new ArrayList<String>();
33+
for (Map options : optionsList) {
34+
if (options.size() > 0) {
35+
components.add(super.generate(options));
36+
}
37+
}
38+
39+
if (StringUtils.isNotBlank(format)){
40+
components.add(format);
41+
}
42+
43+
return StringUtils.join(components, "/");
44+
}
45+
3046
@Override
3147
public String generate(Map options) {
3248
List<String> eager = new ArrayList<>();

cloudinary-core/src/test/java/com/cloudinary/test/CloudinaryTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.cloudinary.test;
22

3-
import com.cloudinary.Cloudinary;
4-
import com.cloudinary.ResponsiveBreakpoint;
5-
import com.cloudinary.Transformation;
6-
import com.cloudinary.Url;
3+
import com.cloudinary.*;
74
import com.cloudinary.transformation.*;
85
import com.cloudinary.utils.ObjectUtils;
96
import junitparams.JUnitParamsRunner;
@@ -16,6 +13,7 @@
1613
import org.junit.rules.TestName;
1714
import org.junit.runner.RunWith;
1815

16+
import java.io.IOException;
1917
import java.io.UnsupportedEncodingException;
2018
import java.net.URI;
2119
import java.net.URLDecoder;
@@ -678,6 +676,18 @@ public void testShouldSupportAutoWidth(String width, String result) {
678676
assertEquals(result, trans);
679677
}
680678

679+
@Test
680+
public void testEagerWithStreamingProfile() throws IOException {
681+
Transformation transformation = new EagerTransformation().format("m3u8").streamingProfile("full_hd");
682+
assertEquals("sp_full_hd/m3u8", transformation.generate());
683+
}
684+
685+
@Test
686+
public void testEagerWithChaining() throws IOException {
687+
Transformation transformation = new EagerTransformation().angle(13).chain().effect("sepia").chain().format("webp");
688+
assertEquals("a_13/e_sepia/webp", transformation.generate());
689+
}
690+
681691
@Test
682692
public void testShouldSupportIhIw() {
683693
String trans = new Transformation().width("iw").height("ih").crop("crop").generate();

cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractUploaderTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,6 @@ public void testUniqueFilename() throws Exception {
194194
assertEquals(result.get("public_id"), "old_logo");
195195
}
196196

197-
@Test
198-
public void testEagerWithStreamingProfile() throws IOException {
199-
Transformation transformation = new EagerTransformation().format("m3u8").streamingProfile("full_hd");
200-
assertEquals("sp_full_hd/m3u8", transformation.generate());
201-
}
202-
203197
@Test
204198
public void testExplicit() throws IOException {
205199
Map result = cloudinary.uploader().explicit("sample", asMap("eager", Collections.singletonList(new Transformation().crop("scale").width(2.0)), "type", "upload", "moderation", "manual"));

0 commit comments

Comments
 (0)