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