3838abstract public class AbstractApiTest {
3939
4040 public static final String SRC_TEST_IMAGE = "../cloudinary-test-common/src/main/resources/old_logo.png" ;
41+ public static final String API_TEST = "api_test" ;
42+ public static final String API_TEST_1 = "api_test1" ;
43+ public static final String API_TEST_2 = "api_test2" ;
44+ public static final String API_TEST_3 = "api_test3" ;
45+ public static final String API_TEST_5 = "api_test5" ;
4146 private Cloudinary cloudinary ;
4247 protected Api api ;
4348 private static String uniqueTag = String .format ("api_test_tag_%d" , new java .util .Date ().getTime ());
@@ -51,7 +56,7 @@ public static void setUpClass() throws IOException {
5156 }
5257 Api api = cloudinary .api ();
5358 try {
54- api .deleteResources (Arrays .asList ("api_test" , "api_test1" , "api_test2" , "api_test3" , "api_test5" ), ObjectUtils .emptyMap ());
59+ api .deleteResources (Arrays .asList (API_TEST , API_TEST_1 , API_TEST_2 , API_TEST_3 , API_TEST_5 ), ObjectUtils .emptyMap ());
5560 } catch (Exception e ) {
5661 }
5762 try {
@@ -82,10 +87,10 @@ public static void setUpClass() throws IOException {
8287 api .deleteUploadPreset ("api_test_upload_preset4" , ObjectUtils .emptyMap ());
8388 } catch (Exception e ) {
8489 }
85- Map options = ObjectUtils .asMap ("public_id" , "api_test" , "tags" , new String []{"api_test_tag" , uniqueTag }, "context" , "key=value" , "eager" ,
90+ Map options = ObjectUtils .asMap ("public_id" , API_TEST , "tags" , new String []{"api_test_tag" , uniqueTag }, "context" , "key=value" , "eager" ,
8691 Collections .singletonList (new Transformation ().width (100 ).crop ("scale" )));
8792 cloudinary .uploader ().upload (SRC_TEST_IMAGE , options );
88- options .put ("public_id" , "api_test1" );
93+ options .put ("public_id" , API_TEST_1 );
8994 cloudinary .uploader ().upload (SRC_TEST_IMAGE , options );
9095 }
9196
@@ -122,7 +127,7 @@ public void test01ResourceTypes() throws Exception {
122127 public void test02Resources () throws Exception {
123128 // should allow listing resources
124129 Map result = api .resources (ObjectUtils .emptyMap ());
125- Map resource = findByAttr ((List <Map >) result .get ("resources" ), "public_id" , "api_test" );
130+ Map resource = findByAttr ((List <Map >) result .get ("resources" ), "public_id" , API_TEST );
126131 assertNotNull (resource );
127132 assertEquals (resource .get ("type" ), "upload" );
128133 }
@@ -133,7 +138,7 @@ public void testTimeoutParameter() throws Exception {
133138 Map <String , Object > options = new HashMap <String , Object >();
134139 options .put ("timeout" , Integer .valueOf (5000 ));
135140 Map result = api .resources (options );
136- Map resource = findByAttr ((List <Map >) result .get ("resources" ), "public_id" , "api_test" );
141+ Map resource = findByAttr ((List <Map >) result .get ("resources" ), "public_id" , API_TEST );
137142 assertNotNull (resource );
138143 assertEquals (resource .get ("type" ), "upload" );
139144 }
@@ -161,17 +166,17 @@ public void test03ResourcesCursor() throws Exception {
161166 public void test04ResourcesByType () throws Exception {
162167 // should allow listing resources by type
163168 Map result = api .resources (ObjectUtils .asMap ("type" , "upload" ));
164- Map resource = findByAttr ((List <Map >) result .get ("resources" ), "public_id" , "api_test" );
169+ Map resource = findByAttr ((List <Map >) result .get ("resources" ), "public_id" , API_TEST );
165170 assertNotNull (resource );
166171 }
167172
168173 @ Test
169174 public void test05ResourcesByPrefix () throws Exception {
170175 // should allow listing resources by prefix
171- Map result = api .resources (ObjectUtils .asMap ("type" , "upload" , "prefix" , "api_test" , "tags" , true , "context" , true ));
176+ Map result = api .resources (ObjectUtils .asMap ("type" , "upload" , "prefix" , API_TEST , "tags" , true , "context" , true ));
172177 List <Map > resources = (List <Map >) result .get ("resources" );
173- assertNotNull (findByAttr (resources , "public_id" , "api_test" ));
174- assertNotNull (findByAttr (resources , "public_id" , "api_test1" ));
178+ assertNotNull (findByAttr (resources , "public_id" , API_TEST ));
179+ assertNotNull (findByAttr (resources , "public_id" , API_TEST_1 ));
175180 assertNotNull (findByAttr ((List <Map >) result .get ("resources" ), "context" , ObjectUtils .asMap ("custom" , ObjectUtils .asMap ("key" , "value" ))));
176181 boolean found = false ;
177182 for (Map r : resources ) {
@@ -208,11 +213,11 @@ public void testResourcesListingStartAt() throws Exception {
208213 @ Test
209214 public void testResourcesByPublicIds () throws Exception {
210215 // should allow listing resources by public ids
211- Map result = api .resourcesByIds (Arrays .asList ("api_test" , "api_test1" , "bogus" ), ObjectUtils .asMap ("type" , "upload" , "tags" , true , "context" , true ));
216+ Map result = api .resourcesByIds (Arrays .asList (API_TEST , API_TEST_1 , "bogus" ), ObjectUtils .asMap ("type" , "upload" , "tags" , true , "context" , true ));
212217 List <Map > resources = (List <Map >) result .get ("resources" );
213218 assertEquals (2 , resources .size ());
214- assertNotNull (findByAttr (resources , "public_id" , "api_test" ));
215- assertNotNull (findByAttr (resources , "public_id" , "api_test1" ));
219+ assertNotNull (findByAttr (resources , "public_id" , API_TEST ));
220+ assertNotNull (findByAttr (resources , "public_id" , API_TEST_1 ));
216221 assertNotNull (findByAttr ((List <Map >) result .get ("resources" ), "context" , ObjectUtils .asMap ("custom" , ObjectUtils .asMap ("key" , "value" ))));
217222 boolean found = false ;
218223 for (Map r : resources ) {
@@ -226,7 +231,7 @@ public void testResourcesByPublicIds() throws Exception {
226231 public void test06ResourcesTag () throws Exception {
227232 // should allow listing resources by tag
228233 Map result = api .resourcesByTag ("api_test_tag" , ObjectUtils .asMap ("tags" , true , "context" , true ));
229- Map resource = findByAttr ((List <Map >) result .get ("resources" ), "public_id" , "api_test" );
234+ Map resource = findByAttr ((List <Map >) result .get ("resources" ), "public_id" , API_TEST );
230235 assertNotNull (resource );
231236 resource = findByAttr ((List <Map >) result .get ("resources" ), "context" , ObjectUtils .asMap ("custom" , ObjectUtils .asMap ("key" , "value" )));
232237 assertNotNull (resource );
@@ -242,9 +247,9 @@ public void test06ResourcesTag() throws Exception {
242247 @ Test
243248 public void test07ResourceMetadata () throws Exception {
244249 // should allow get resource metadata
245- Map resource = api .resource ("api_test" , ObjectUtils .emptyMap ());
250+ Map resource = api .resource (API_TEST , ObjectUtils .emptyMap ());
246251 assertNotNull (resource );
247- assertEquals (resource .get ("public_id" ), "api_test" );
252+ assertEquals (resource .get ("public_id" ), API_TEST );
248253 assertEquals (resource .get ("bytes" ), 3381 );
249254 assertEquals (((List ) resource .get ("derived" )).size (), 1 );
250255 }
@@ -253,14 +258,14 @@ public void test07ResourceMetadata() throws Exception {
253258 public void test08DeleteDerived () throws Exception {
254259 // should allow deleting derived resource
255260 cloudinary .uploader ().upload (SRC_TEST_IMAGE ,
256- ObjectUtils .asMap ("public_id" , "api_test3" , "eager" , Collections .singletonList (new Transformation ().width (101 ).crop ("scale" ))));
257- Map resource = api .resource ("api_test3" , ObjectUtils .emptyMap ());
261+ ObjectUtils .asMap ("public_id" , API_TEST_3 , "eager" , Collections .singletonList (new Transformation ().width (101 ).crop ("scale" ))));
262+ Map resource = api .resource (API_TEST_3 , ObjectUtils .emptyMap ());
258263 assertNotNull (resource );
259264 List <Map > derived = (List <Map >) resource .get ("derived" );
260265 assertEquals (derived .size (), 1 );
261266 String derived_resource_id = (String ) derived .get (0 ).get ("id" );
262267 api .deleteDerivedResources (Arrays .asList (derived_resource_id ), ObjectUtils .emptyMap ());
263- resource = api .resource ("api_test3" , ObjectUtils .emptyMap ());
268+ resource = api .resource (API_TEST_3 , ObjectUtils .emptyMap ());
264269 assertNotNull (resource );
265270 derived = (List <Map >) resource .get ("derived" );
266271 assertEquals (derived .size (), 0 );
@@ -269,11 +274,12 @@ public void test08DeleteDerived() throws Exception {
269274 @ Test (expected = NotFound .class )
270275 public void test09DeleteResources () throws Exception {
271276 // should allow deleting resources
272- cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , "api_test3" ));
273- Map resource = api .resource ("api_test3" , ObjectUtils .emptyMap ());
277+ String public_id = "api_,test3" ;
278+ cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("public_id" , public_id ));
279+ Map resource = api .resource (public_id , ObjectUtils .emptyMap ());
274280 assertNotNull (resource );
275- api .deleteResources (Arrays .asList ("apit_test" , "api_test2" , "api_test3" ), ObjectUtils .emptyMap ());
276- api .resource ("api_test3" , ObjectUtils .emptyMap ());
281+ api .deleteResources (Arrays .asList (API_TEST , API_TEST_2 , public_id ), ObjectUtils .emptyMap ());
282+ api .resource (public_id , ObjectUtils .emptyMap ());
277283 }
278284
279285 @ Test (expected = NotFound .class )
@@ -308,7 +314,7 @@ public void test10Tags() throws Exception {
308314 @ Test
309315 public void test11TagsPrefix () throws Exception {
310316 // should allow listing tag by prefix
311- Map result = api .tags (ObjectUtils .asMap ("prefix" , "api_test" ));
317+ Map result = api .tags (ObjectUtils .asMap ("prefix" , API_TEST ));
312318 List <String > tags = (List <String >) result .get ("tags" );
313319 assertContains ("api_test_tag" , tags );
314320 result = api .tags (ObjectUtils .asMap ("prefix" , "api_test_no_such_tag" ));
@@ -420,11 +426,11 @@ public void test19Ping() throws Exception {
420426 public void testDeleteAllResources () throws Exception {
421427 // should allow deleting all resources
422428 cloudinary .uploader ().upload (SRC_TEST_IMAGE ,
423- ObjectUtils .asMap ("public_id" , "api_test5" , "eager" , Collections .singletonList (new Transformation ().crop ("scale" ).width (2.0 ))));
424- Map result = api .resource ("api_test5" , ObjectUtils .emptyMap ());
429+ ObjectUtils .asMap ("public_id" , API_TEST_5 , "eager" , Collections .singletonList (new Transformation ().crop ("scale" ).width (2.0 ))));
430+ Map result = api .resource (API_TEST_5 , ObjectUtils .emptyMap ());
425431 assertEquals (1 , ((org .cloudinary .json .JSONArray ) result .get ("derived" )).length ());
426432 api .deleteAllResources (ObjectUtils .asMap ("keep_original" , true ));
427- result = api .resource ("api_test5" , ObjectUtils .emptyMap ());
433+ result = api .resource (API_TEST_5 , ObjectUtils .emptyMap ());
428434 // assertEquals(0, ((org.cloudinary.json.JSONArray)
429435 // result.get("derived")).size());
430436 }
0 commit comments