2424
2525@ SuppressWarnings ({"rawtypes" , "unchecked" , "JavaDoc" })
2626abstract public class AbstractApiTest extends MockableTest {
27- private static final String SRC_TEST_IMAGE = "../cloudinary-test-common/src/main/resources/old_logo.png" ;
28- private static final int SUFFIX = new Random ().nextInt (99999 );
2927 private static final String API_TEST = "api_test_" + SUFFIX ;
3028 private static final String API_TEST_1 = API_TEST + "_1" ;
3129 private static final String API_TEST_2 = API_TEST + "_2" ;
3230 private static final String API_TEST_3 = API_TEST + "_3" ;
3331 private static final String API_TEST_5 = API_TEST + "_5" ;
34- private static final String SDK_TEST_TAG = "cloudinary_java_test_" + SUFFIX ;
3532 public static final String API_TEST_TRANSFORMATION = "api_test_transformation_" + SUFFIX ;
3633 public static final String API_TEST_TRANSFORMATION_2 = API_TEST_TRANSFORMATION + "2" ;
3734 public static final String API_TEST_TRANSFORMATION_3 = API_TEST_TRANSFORMATION + "3" ;
3835 public static final String API_TEST_UPLOAD_PRESET = "api_test_upload_preset_" + SUFFIX ;
3936 public static final String API_TEST_UPLOAD_PRESET_2 = API_TEST_UPLOAD_PRESET + "2" ;
4037 public static final String API_TEST_UPLOAD_PRESET_3 = API_TEST_UPLOAD_PRESET + "3" ;
4138 public static final String API_TEST_UPLOAD_PRESET_4 = API_TEST_UPLOAD_PRESET + "4" ;
42- private Cloudinary cloudinary ;
4339 protected Api api ;
44- private static final String uniqueTag = SDK_TEST_TAG + (new java .util .Date ().getTime ());
4540
4641 @ BeforeClass
4742 public static void setUpClass () throws IOException {
@@ -59,16 +54,11 @@ public static void setUpClass() throws IOException {
5954
6055 @ AfterClass
6156 public static void tearDownClass () {
62- Cloudinary cloudinary = new Cloudinary ();
63- Api api = cloudinary .api ();
57+ Api api = MockableTest .cleanUp ();
6458 try {
6559 api .deleteResources (Arrays .asList (API_TEST , API_TEST_1 , API_TEST_2 , API_TEST_3 , API_TEST_5 ), ObjectUtils .emptyMap ());
6660 } catch (Exception ignored ) {
6761 }
68- try {
69- api .deleteResourcesByTag (uniqueTag , ObjectUtils .emptyMap ());
70- } catch (Exception ignored ) {
71- }
7262 try {
7363 api .deleteTransformation (API_TEST_TRANSFORMATION , ObjectUtils .emptyMap ());
7464 } catch (Exception ignored ) {
@@ -132,19 +122,16 @@ public void test01ResourceTypes() throws Exception {
132122 @ Test
133123 public void test02Resources () throws Exception {
134124 // should allow listing resources
135- Map result = api .resources (ObjectUtils .emptyMap ());
136- final List <Map > resources = (List ) result .get ("resources" );
137- assertThat (resources , hasItem (allOf (hasEntry ("public_id" , API_TEST ),hasEntry ("type" , "upload" ))));
138- }
125+ Map resource = preloadResource ();
139126
140- @ Test
141- public void testTimeoutParameter () throws Exception {
142- // should allow listing resources
143- Map < String , Object > options = new HashMap < String , Object >( );
144- options . put ( "timeout" , Integer . valueOf ( 5000 ));
145- Map result = api . resources ( options );
146- List < Map > resources = ( List ) result . get ( "resources" );
147- assertThat (resources , hasItem (allOf (hasEntry ("public_id" , API_TEST ),hasEntry ("type" , "upload" ))));
127+ final List < Map > resources = new ArrayList < Map >();
128+ String next_cursor = null ;
129+ do {
130+ Map result = api . resources ( ObjectUtils . asMap ( "max_results" , 500 , "next_cursor" , next_cursor ) );
131+ resources . addAll (( List ) result . get ( "resources" ));
132+ next_cursor = ( String ) result . get ( "next_cursor" );
133+ } while ( next_cursor != null );
134+ assertThat (resources , hasItem (allOf (hasEntry ("public_id" , ( String ) resource . get ( "public_id" ) ),hasEntry ("type" , "upload" ))));
148135 }
149136
150137 @ Test
@@ -169,9 +156,10 @@ public void test03ResourcesCursor() throws Exception {
169156 @ Test
170157 public void test04ResourcesByType () throws Exception {
171158 // should allow listing resources by type
159+ Map resource = preloadResource ();
172160 Map result = api .resources (ObjectUtils .asMap ("type" , "upload" ));
173161 List <Map > resources = (List ) result .get ("resources" );
174- assertThat (resources , hasItem (hasEntry ("public_id" , API_TEST )));
162+ assertThat (resources , hasItem (hasEntry ("public_id" , ( String ) resource . get ( "public_id" ) )));
175163 }
176164
177165 @ Test
@@ -280,7 +268,7 @@ public void test09DeleteResources() throws Exception {
280268 cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , public_id , "tags" , SDK_TEST_TAG ));
281269 Map resource = api .resource (public_id , ObjectUtils .emptyMap ());
282270 assertNotNull (resource );
283- api .deleteResources (Arrays .asList (API_TEST , API_TEST_2 , public_id ), ObjectUtils .emptyMap ());
271+ api .deleteResources (Arrays .asList (API_TEST_2 , public_id ), ObjectUtils .emptyMap ());
284272 api .resource (public_id , ObjectUtils .emptyMap ());
285273 }
286274
@@ -337,9 +325,11 @@ public void test12Transformations() throws Exception {
337325 @ Test
338326 public void test13TransformationMetadata () throws Exception {
339327 // should allow getting transformation metadata
340- Map transformation = api .transformation ("c_scale,w_100" , ObjectUtils .emptyMap ());
328+ final Transformation tr = new Transformation ().crop ("scale" ).width (100 );
329+ preloadResource (ObjectUtils .asMap ("eager" , Collections .singletonList (tr )));
330+ Map transformation = api .transformation ("c_scale,w_100" , ObjectUtils .asMap ("max_results" , 500 ));
341331 assertNotNull (transformation );
342- assertEquals (new Transformation ((List <Map >) transformation .get ("info" )).generate (), new Transformation (). crop ( "scale" ). width ( 100 ) .generate ());
332+ assertEquals (new Transformation ((List <Map >) transformation .get ("info" )).generate (), tr .generate ());
343333 }
344334
345335 @ Test
0 commit comments