11package com .cloudinary .test ;
22
3- import static org .junit .Assert .assertEquals ;
4- import static org .junit .Assert .assertNull ;
5- import static org .junit .Assert .assertTrue ;
6-
73import java .io .UnsupportedEncodingException ;
84import java .net .URI ;
95import java .net .URLDecoder ;
6+ import java .util .Arrays ;
107import java .util .HashMap ;
118import java .util .Map ;
12- import java .util .Set ;
139import java .util .regex .Matcher ;
1410import java .util .regex .Pattern ;
1511
12+ import com .cloudinary .ResponsiveBreakpoint ;
13+ import org .cloudinary .json .JSONArray ;
14+ import org .cloudinary .json .JSONObject ;
1615import org .junit .Before ;
1716import org .junit .Rule ;
1817import org .junit .Test ;
1918import org .junit .rules .TestName ;
2019
2120import com .cloudinary .Cloudinary ;
22- import com .cloudinary .ResponsiveBreakpoints ;
2321import com .cloudinary .Transformation ;
2422import com .cloudinary .transformation .*;
2523import com .cloudinary .utils .ObjectUtils ;
2624
25+ import static org .junit .Assert .*;
26+
2727public class CloudinaryTest {
2828 private static final String DEFAULT_ROOT_PATH = "http://res.cloudinary.com/test123/" ;
2929 private static final String DEFAULT_UPLOAD_PATH = DEFAULT_ROOT_PATH + "image/upload/" ;
@@ -269,7 +269,7 @@ public void testOverlay() {
269269 assertNull (transformation .getHtmlWidth ());
270270 assertEquals (DEFAULT_UPLOAD_PATH + "h_100,l_text:hello,w_100/test" , result );
271271
272- transformation = new Transformation ().overlay (new TextLayerBuilder ().text ("goodbye" ));
272+ transformation = new Transformation ().overlay (new TextLayer ().text ("goodbye" ));
273273 result = cloudinary .url ().transformation (transformation ).generate ("test" );
274274 assertEquals (DEFAULT_UPLOAD_PATH + "l_text:goodbye/test" , result );
275275 }
@@ -906,23 +906,23 @@ public void testAspectRatio() {
906906 @ Test
907907 public void testOverlayOptions () {
908908 Object tests [] = {
909- new LayerBuilder ().publicId ("logo" ),
909+ new Layer ().publicId ("logo" ),
910910 "logo" ,
911- new LayerBuilder ().publicId ("folder/logo" ),
911+ new Layer ().publicId ("folder/logo" ),
912912 "folder:logo" ,
913- new LayerBuilder ().publicId ("logo" ).type ("private" ),
913+ new Layer ().publicId ("logo" ).type ("private" ),
914914 "private:logo" ,
915- new LayerBuilder ().publicId ("logo" ).format ("png" ),
915+ new Layer ().publicId ("logo" ).format ("png" ),
916916 "logo.png" ,
917- new LayerBuilder ().resourceType ("video" ).publicId ("cat" ),
917+ new Layer ().resourceType ("video" ).publicId ("cat" ),
918918 "video:cat" ,
919- new TextLayerBuilder ().text ("Hello World, Nice to meet you?" ).fontFamily ("Arial" ).fontSize (18 ),
919+ new TextLayer ().text ("Hello World, Nice to meet you?" ).fontFamily ("Arial" ).fontSize (18 ),
920920 "text:Arial_18:Hello%20World%E2%80%9A%20Nice%20to%20meet%20you%3F" ,
921- new TextLayerBuilder ().text ("Hello World, Nice to meet you?" ).fontFamily ("Arial" ).fontSize (18 )
921+ new TextLayer ().text ("Hello World, Nice to meet you?" ).fontFamily ("Arial" ).fontSize (18 )
922922 .fontWeight ("bold" ).fontStyle ("italic" ).letterSpacing ("4" ).lineSpacing (3 ),
923923 "text:Arial_18_bold_italic_letter_spacing_4_line_spacing_3:Hello%20World%E2%80%9A%20Nice%20to%20meet%20you%3F" ,
924- new SubtitlesLayerBuilder ().publicId ("sample_sub_en.srt" ), "subtitles:sample_sub_en.srt" ,
925- new SubtitlesLayerBuilder ().publicId ("sample_sub_he.srt" ).fontFamily ("Arial" ).fontSize (40 ),
924+ new SubtitlesLayer ().publicId ("sample_sub_en.srt" ), "subtitles:sample_sub_en.srt" ,
925+ new SubtitlesLayer ().publicId ("sample_sub_he.srt" ).fontFamily ("Arial" ).fontSize (40 ),
926926 "subtitles:Arial_40:sample_sub_he.srt" };
927927
928928 for (int i = 0 ; i < tests .length ; i += 2 ) {
@@ -935,44 +935,40 @@ public void testOverlayOptions() {
935935 @ Test (expected = IllegalArgumentException .class )
936936 public void testOverlayError1 () {
937937 // Must supply font_family for text in overlay
938- cloudinary .url ().transformation (new Transformation ().overlay (new TextLayerBuilder ().fontStyle ("italic" ))).generate ("test" );
938+ cloudinary .url ().transformation (new Transformation ().overlay (new TextLayer ().fontStyle ("italic" ))).generate ("test" );
939939 }
940940
941941 @ Test (expected = IllegalArgumentException .class )
942942 public void testOverlayError2 () {
943943 // Must supply public_id for for non-text underlay
944- cloudinary .url ().transformation (new Transformation ().underlay (new LayerBuilder ().resourceType ("video" ))).generate ("test" );
944+ cloudinary .url ().transformation (new Transformation ().underlay (new Layer ().resourceType ("video" ))).generate ("test" );
945945 }
946946
947947 @ Test
948948 public void testResponsiveBreakpointsToJson () {
949- assertEquals (
949+ assertEquals ("an empty ResponsiveBreakpoint should have create_derived=true" ,
950950 "[{\" create_derived\" :true}]" ,
951- ResponsiveBreakpoints .toJsonString (
952- new ResponsiveBreakpoints ()
953- ));
954-
955- assertEquals (
956- "[{\" create_derived\" :false,\" max_width\" :500,\" min_width\" :100,\" max_images\" :5,\" transformation\" :\" a_45\" }]" ,
957- ResponsiveBreakpoints .toJsonString (
958- new ResponsiveBreakpoints ().createDerived (false )
959- .transformation (new Transformation ().angle (45 ))
960- .maxWidth (500 )
961- .minWidth (100 )
962- .maxImages (5 )
963- ));
964- assertEquals (
965- "[{\" create_derived\" :false,\" max_width\" :500,\" min_width\" :100,\" max_images\" :5,\" transformation\" :\" a_45\" },{\" create_derived\" :true}]" ,
966- ResponsiveBreakpoints .toJsonString (
967- new ResponsiveBreakpoints []{
968- new ResponsiveBreakpoints ().createDerived (false )
969- .transformation (new Transformation ().angle (45 ))
970- .maxWidth (500 )
971- .minWidth (100 )
972- .maxImages (5 ),
973- new ResponsiveBreakpoints ()
974- }
975- ));
951+ new ResponsiveBreakpoint ().toString ()
952+ );
953+ JSONObject expected = new JSONObject ("{\" create_derived\" :false,\" max_width\" :500,\" min_width\" :100,\" max_images\" :5,\" transformation\" :\" a_45\" }" );
954+ JSONObject actual = new ResponsiveBreakpoint ().createDerived (false )
955+ .transformation (new Transformation ().angle (45 ))
956+ .maxWidth (500 )
957+ .minWidth (100 )
958+ .maxImages (5 )
959+ ;
960+ assertTrue (actual .similar (expected ));
961+
962+ JSONArray actualArray = new JSONArray (Arrays .asList (
963+ new ResponsiveBreakpoint ().createDerived (false )
964+ .transformation (new Transformation ().angle (45 ))
965+ .maxWidth (500 )
966+ .minWidth (100 )
967+ .maxImages (5 ),
968+ new ResponsiveBreakpoint ()
969+ ));;
970+ JSONArray expectedArray = new JSONArray ("[{\" create_derived\" :false,\" max_width\" :500,\" min_width\" :100,\" max_images\" :5,\" transformation\" :\" a_45\" },{\" create_derived\" :true}]" );
971+ assertTrue (actualArray .similar (expectedArray ));
976972 }
977973
978974 public static Map <String , String > getUrlParameters (URI uri ) throws UnsupportedEncodingException {
0 commit comments