Skip to content

Commit 78c5a92

Browse files
committed
Create separate test class for Layer
1 parent 80278ef commit 78c5a92

File tree

2 files changed

+132
-72
lines changed

2 files changed

+132
-72
lines changed

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

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -254,37 +254,6 @@ public void testAngle() {
254254
assertEquals(DEFAULT_UPLOAD_PATH + "a_exif.12/test", result);
255255
}
256256

257-
@Test
258-
public void testOverlay() {
259-
// should support overlay
260-
Transformation transformation = new Transformation().overlay("text:hello");
261-
String result = cloudinary.url().transformation(transformation).generate("test");
262-
assertEquals(DEFAULT_UPLOAD_PATH + "l_text:hello/test", result);
263-
// should not pass width/height to html if overlay
264-
transformation = new Transformation().overlay("text:hello").width(100).height(100);
265-
result = cloudinary.url().transformation(transformation).generate("test");
266-
assertNull(transformation.getHtmlHeight());
267-
assertNull(transformation.getHtmlWidth());
268-
assertEquals(DEFAULT_UPLOAD_PATH + "h_100,l_text:hello,w_100/test", result);
269-
270-
transformation = new Transformation().overlay(new TextLayer().text("goodbye"));
271-
result = cloudinary.url().transformation(transformation).generate("test");
272-
assertEquals(DEFAULT_UPLOAD_PATH + "l_text:goodbye/test", result);
273-
}
274-
275-
@Test
276-
public void testUnderlay() {
277-
Transformation transformation = new Transformation().underlay("text:hello");
278-
String result = cloudinary.url().transformation(transformation).generate("test");
279-
assertEquals(DEFAULT_UPLOAD_PATH + "u_text:hello/test", result);
280-
// should not pass width/height to html if underlay
281-
transformation = new Transformation().underlay("text:hello").width(100).height(100);
282-
result = cloudinary.url().transformation(transformation).generate("test");
283-
assertNull(transformation.getHtmlHeight());
284-
assertNull(transformation.getHtmlWidth());
285-
assertEquals(DEFAULT_UPLOAD_PATH + "h_100,u_text:hello,w_100/test", result);
286-
}
287-
288257
@Test
289258
public void testFetchFormat() {
290259
// should support format for fetch urls
@@ -901,47 +870,6 @@ public void testAspectRatio() {
901870
assertEquals(DEFAULT_UPLOAD_PATH + "ar_3:2/test", actual);
902871
}
903872

904-
@Test
905-
public void testOverlayOptions() {
906-
Object tests[] = {
907-
new Layer().publicId("logo"),
908-
"logo",
909-
new Layer().publicId("folder/logo"),
910-
"folder:logo",
911-
new Layer().publicId("logo").type("private"),
912-
"private:logo",
913-
new Layer().publicId("logo").format("png"),
914-
"logo.png",
915-
new Layer().resourceType("video").publicId("cat"),
916-
"video:cat",
917-
new TextLayer().text("Hello World, Nice to meet you?").fontFamily("Arial").fontSize(18),
918-
"text:Arial_18:Hello%20World%E2%80%9A%20Nice%20to%20meet%20you%3F",
919-
new TextLayer().text("Hello World, Nice to meet you?").fontFamily("Arial").fontSize(18)
920-
.fontWeight("bold").fontStyle("italic").letterSpacing("4"),
921-
"text:Arial_18_bold_italic_letter_spacing_4:Hello%20World%E2%80%9A%20Nice%20to%20meet%20you%3F",
922-
new SubtitlesLayer().publicId("sample_sub_en.srt"), "subtitles:sample_sub_en.srt",
923-
new SubtitlesLayer().publicId("sample_sub_he.srt").fontFamily("Arial").fontSize(40),
924-
"subtitles:Arial_40:sample_sub_he.srt" };
925-
926-
for (int i = 0; i < tests.length; i += 2) {
927-
Object layer = tests[i];
928-
String expected = (String) tests[i + 1];
929-
assertEquals(expected, layer.toString());
930-
}
931-
}
932-
933-
@Test(expected = IllegalArgumentException.class)
934-
public void testOverlayError1() {
935-
// Must supply font_family for text in overlay
936-
cloudinary.url().transformation(new Transformation().overlay(new TextLayer().fontStyle("italic"))).generate("test");
937-
}
938-
939-
@Test(expected = IllegalArgumentException.class)
940-
public void testOverlayError2() {
941-
// Must supply public_id for for non-text underlay
942-
cloudinary.url().transformation(new Transformation().underlay(new Layer().resourceType("video"))).generate("test");
943-
}
944-
945873
public static Map<String, String> getUrlParameters(URI uri) throws UnsupportedEncodingException {
946874
Map<String, String> params = new HashMap<String, String>();
947875
for (String param : uri.getRawQuery().split("&")) {
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package com.cloudinary.transformation;
2+
3+
import com.cloudinary.Cloudinary;
4+
import com.cloudinary.Transformation;
5+
import org.junit.After;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
import static org.junit.Assert.*;
10+
11+
/**
12+
* Created by amir on 03/11/2015.
13+
*/
14+
public class LayerTest {
15+
private static final String DEFAULT_ROOT_PATH = "http://res.cloudinary.com/test123/";
16+
private static final String DEFAULT_UPLOAD_PATH = DEFAULT_ROOT_PATH + "image/upload/";
17+
private static final String VIDEO_UPLOAD_PATH = DEFAULT_ROOT_PATH + "video/upload/";
18+
private Cloudinary cloudinary;
19+
20+
@Before
21+
public void setUp() {
22+
this.cloudinary = new Cloudinary("cloudinary://a:b@test123?load_strategies=false");
23+
}
24+
25+
@After
26+
public void tearDown() throws Exception {
27+
28+
}
29+
30+
@Test
31+
public void testOverlay() {
32+
// should support overlay
33+
Transformation transformation = new Transformation().overlay("text:hello");
34+
String result = cloudinary.url().transformation(transformation).generate("test");
35+
assertEquals(DEFAULT_UPLOAD_PATH + "l_text:hello/test", result);
36+
// should not pass width/height to html if overlay
37+
transformation = new Transformation().overlay("text:hello").width(100).height(100);
38+
result = cloudinary.url().transformation(transformation).generate("test");
39+
assertNull(transformation.getHtmlHeight());
40+
assertNull(transformation.getHtmlWidth());
41+
assertEquals(DEFAULT_UPLOAD_PATH + "h_100,l_text:hello,w_100/test", result);
42+
43+
transformation = new Transformation().overlay(new TextLayer().text("goodbye"));
44+
result = cloudinary.url().transformation(transformation).generate("test");
45+
assertEquals(DEFAULT_UPLOAD_PATH + "l_text:goodbye/test", result);
46+
}
47+
48+
@Test
49+
public void testUnderlay() {
50+
Transformation transformation = new Transformation().underlay("text:hello");
51+
String result = cloudinary.url().transformation(transformation).generate("test");
52+
assertEquals(DEFAULT_UPLOAD_PATH + "u_text:hello/test", result);
53+
// should not pass width/height to html if underlay
54+
transformation = new Transformation().underlay("text:hello").width(100).height(100);
55+
result = cloudinary.url().transformation(transformation).generate("test");
56+
assertNull(transformation.getHtmlHeight());
57+
assertNull(transformation.getHtmlWidth());
58+
assertEquals(DEFAULT_UPLOAD_PATH + "h_100,u_text:hello,w_100/test", result);
59+
}
60+
61+
62+
@Test
63+
public void testLayerOptions() {
64+
Object tests[] = {
65+
new Layer().publicId("logo"),
66+
"logo",
67+
new Layer().publicId("folder/logo"),
68+
"folder:logo",
69+
new Layer().publicId("logo").type("private"),
70+
"private:logo",
71+
new Layer().publicId("logo").format("png"),
72+
"logo.png",
73+
new Layer().resourceType("video").publicId("cat"),
74+
"video:cat",
75+
new TextLayer().text("Hello World, Nice to meet you?").fontFamily("Arial").fontSize(18),
76+
"text:Arial_18:Hello%20World%E2%80%9A%20Nice%20to%20meet%20you%3F",
77+
new TextLayer().text("Hello World, Nice to meet you?").fontFamily("Arial").fontSize(18)
78+
.fontWeight("bold").fontStyle("italic").letterSpacing("4"),
79+
"text:Arial_18_bold_italic_letter_spacing_4:Hello%20World%E2%80%9A%20Nice%20to%20meet%20you%3F",
80+
new SubtitlesLayer().publicId("sample_sub_en.srt"), "subtitles:sample_sub_en.srt",
81+
new SubtitlesLayer().publicId("sample_sub_he.srt").fontFamily("Arial").fontSize(40),
82+
"subtitles:Arial_40:sample_sub_he.srt" };
83+
84+
for (int i = 0; i < tests.length; i += 2) {
85+
Object layer = tests[i];
86+
String expected = (String) tests[i + 1];
87+
assertEquals(expected, layer.toString());
88+
}
89+
}
90+
91+
@Test(expected = IllegalArgumentException.class)
92+
public void testOverlayError1() {
93+
// Must supply font_family for text in overlay
94+
cloudinary.url().transformation(new Transformation().overlay(new TextLayer().fontStyle("italic"))).generate("test");
95+
}
96+
97+
@Test(expected = IllegalArgumentException.class)
98+
public void testOverlayError2() {
99+
// Must supply public_id for for non-text underlay
100+
cloudinary.url().transformation(new Transformation().underlay(new Layer().resourceType("video"))).generate("test");
101+
}
102+
103+
@Test
104+
public void testResourceType() throws Exception {
105+
106+
}
107+
108+
@Test
109+
public void testType() throws Exception {
110+
111+
}
112+
113+
@Test
114+
public void testPublicId() throws Exception {
115+
116+
}
117+
118+
@Test
119+
public void testFormat() throws Exception {
120+
121+
}
122+
123+
@Test
124+
public void testToString() throws Exception {
125+
126+
}
127+
128+
@Test
129+
public void testFormattedPublicId() throws Exception {
130+
131+
}
132+
}

0 commit comments

Comments
 (0)