44import com .cloudinary .api .ApiResponse ;
55import com .cloudinary .api .exceptions .BadRequest ;
66import com .cloudinary .api .exceptions .NotFound ;
7- import com .cloudinary .metadata . StringMetadataField ;
7+ import com .cloudinary .test . rules . RetryRule ;
88import com .cloudinary .transformation .TextLayer ;
99import com .cloudinary .utils .ObjectUtils ;
1010import org .junit .*;
@@ -53,6 +53,8 @@ abstract public class AbstractApiTest extends MockableTest {
5353 private static String assetId1 ;
5454 private static String assetId2 ;
5555
56+ private static final int SLEEP_TIMEOUT = 5000 ;
57+
5658
5759 protected Api api ;
5860
@@ -137,6 +139,9 @@ public static void tearDownClass() {
137139 @ Rule
138140 public TestName currentTest = new TestName ();
139141
142+ @ Rule
143+ public RetryRule retryRule = new RetryRule ();
144+
140145 @ Before
141146 public void setUp () {
142147 System .out .println ("Running " + this .getClass ().getName () + "." + currentTest .getMethodName ());
@@ -909,8 +914,10 @@ public void testRestoreDifferentVersionsOfDeletedAsset() throws Exception {
909914 "tags" , UPLOAD_TAGS
910915 ));
911916 assertEquals (firstUpload .get ("public_id" ), TEST_RESOURCE_PUBLIC_ID );
917+ Thread .sleep (SLEEP_TIMEOUT );
912918 ApiResponse firstDelete = api .deleteResources (Collections .singletonList (TEST_RESOURCE_PUBLIC_ID ), ObjectUtils .emptyMap ());
913919 assertTrue (firstDelete .containsKey ("deleted" ));
920+ Thread .sleep (SLEEP_TIMEOUT );
914921
915922 Map secondUpload = uploader .upload (SRC_TEST_IMAGE ,
916923 ObjectUtils .asMap (
@@ -920,13 +927,15 @@ public void testRestoreDifferentVersionsOfDeletedAsset() throws Exception {
920927 "tags" , UPLOAD_TAGS
921928 ));
922929 assertEquals (secondUpload .get ("public_id" ), TEST_RESOURCE_PUBLIC_ID );
930+ Thread .sleep (SLEEP_TIMEOUT );
923931 ApiResponse secondDelete = api .deleteResources (Collections .singletonList (TEST_RESOURCE_PUBLIC_ID ), ObjectUtils .emptyMap ());
924932 assertTrue (secondDelete .containsKey ("deleted" ));
925-
933+ Thread . sleep ( SLEEP_TIMEOUT );
926934 assertNotEquals (firstUpload .get ("bytes" ), secondUpload .get ("bytes" ));
927935
928936 ApiResponse getVersionsResp = api .resource (TEST_RESOURCE_PUBLIC_ID , ObjectUtils .asMap ("versions" , true ));
929937 List <Map > versions = (List <Map >) getVersionsResp .get ("versions" );
938+ Assert .assertTrue (versions .size () > 1 );
930939 Object firstAssetVersion = versions .get (0 ).get ("version_id" );
931940 Object secondAssetVersion = versions .get (1 ).get ("version_id" );
932941
@@ -937,7 +946,7 @@ public void testRestoreDifferentVersionsOfDeletedAsset() throws Exception {
937946 ApiResponse secondVerRestore = api .restore (Collections .singletonList (TEST_RESOURCE_PUBLIC_ID ),
938947 ObjectUtils .asMap ("versions" , Collections .singletonList (secondAssetVersion )));
939948 assertEquals (((Map ) secondVerRestore .get (TEST_RESOURCE_PUBLIC_ID )).get ("bytes" ), secondUpload .get ("bytes" ));
940-
949+ Thread . sleep ( SLEEP_TIMEOUT );
941950 ApiResponse finalDeleteResp = api .deleteResources (Collections .singletonList (TEST_RESOURCE_PUBLIC_ID ), ObjectUtils .emptyMap ());
942951 assertTrue (finalDeleteResp .containsKey ("deleted" ));
943952 }
@@ -1157,7 +1166,7 @@ public void testQualityAnalysis() throws Exception {
11571166 public void testDeleteFolder () throws Exception {
11581167 String toDelete = "todelete_" + SUFFIX ;
11591168 Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , asMap ("tags" , UPLOAD_TAGS , "folder" , toDelete ));
1160- Thread .sleep (5000 );
1169+ Thread .sleep (SLEEP_TIMEOUT );
11611170 api .deleteResources (Collections .singletonList (uploadResult .get ("public_id" ).toString ()), emptyMap ());
11621171 ApiResponse result = api .deleteFolder (toDelete , emptyMap ());
11631172 assertTrue (((ArrayList ) result .get ("deleted" )).contains (toDelete ));
0 commit comments