Skip to content

Commit dfc8841

Browse files
author
Amir Tocker
committed
Add SDK_TEST_TAG to all resources being created.
1 parent 537efbb commit dfc8841

File tree

2 files changed

+100
-129
lines changed

2 files changed

+100
-129
lines changed

cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractApiTest.java

Lines changed: 39 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
11
package com.cloudinary.test;
22

3-
import static org.junit.Assert.assertArrayEquals;
4-
import static org.junit.Assert.assertEquals;
5-
import static org.junit.Assert.assertNotNull;
6-
import static org.junit.Assert.assertNotSame;
7-
import static org.junit.Assert.assertNull;
8-
import static org.junit.Assert.assertTrue;
9-
import static org.junit.Assume.assumeNotNull;
10-
11-
import java.io.IOException;
12-
import java.util.ArrayList;
13-
import java.util.Arrays;
14-
import java.util.Collection;
15-
import java.util.Collections;
16-
import java.util.HashMap;
17-
import java.util.List;
18-
import java.util.ListIterator;
19-
import java.util.Map;
20-
21-
import org.junit.Before;
22-
import org.junit.BeforeClass;
23-
import org.junit.Ignore;
24-
import org.junit.Rule;
25-
import org.junit.Test;
26-
import org.junit.rules.TestName;
27-
283
import com.cloudinary.Api;
294
import com.cloudinary.Cloudinary;
305
import com.cloudinary.Coordinates;
@@ -33,6 +8,14 @@
338
import com.cloudinary.api.exceptions.BadRequest;
349
import com.cloudinary.api.exceptions.NotFound;
3510
import com.cloudinary.utils.ObjectUtils;
11+
import org.junit.*;
12+
import org.junit.rules.TestName;
13+
14+
import java.io.IOException;
15+
import java.util.*;
16+
17+
import static org.junit.Assert.*;
18+
import static org.junit.Assume.assumeNotNull;
3619

3720
@SuppressWarnings({"rawtypes", "unchecked"})
3821
abstract public class AbstractApiTest {
@@ -43,9 +26,10 @@ abstract public class AbstractApiTest {
4326
public static final String API_TEST_2 = "api_test2";
4427
public static final String API_TEST_3 = "api_test3";
4528
public static final String API_TEST_5 = "api_test5";
29+
public static final String SDK_TEST_TAG = "cloudinary_java_test";
4630
private Cloudinary cloudinary;
4731
protected Api api;
48-
private static String uniqueTag = String.format("api_test_tag_%d", new java.util.Date().getTime());
32+
private static String uniqueTag = SDK_TEST_TAG + (new java.util.Date().getTime());
4933

5034
@BeforeClass
5135
public static void setUpClass() throws IOException {
@@ -87,7 +71,7 @@ public static void setUpClass() throws IOException {
8771
api.deleteUploadPreset("api_test_upload_preset4", ObjectUtils.emptyMap());
8872
} catch (Exception e) {
8973
}
90-
Map options = ObjectUtils.asMap("public_id", API_TEST, "tags", new String[]{"api_test_tag", uniqueTag}, "context", "key=value", "eager",
74+
Map options = ObjectUtils.asMap("public_id", API_TEST, "tags", new String[]{SDK_TEST_TAG, uniqueTag}, "context", "key=value", "eager",
9175
Collections.singletonList(new Transformation().width(100).crop("scale")));
9276
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
9377
options.put("public_id", API_TEST_1);
@@ -181,7 +165,7 @@ public void test05ResourcesByPrefix() throws Exception {
181165
boolean found = false;
182166
for (Map r : resources) {
183167
ArrayList tags = (ArrayList) r.get("tags");
184-
found = found || tags.contains("api_test_tag");
168+
found = found || tags.contains(SDK_TEST_TAG);
185169
}
186170
assertTrue(found);
187171
}
@@ -204,7 +188,7 @@ public void testResourcesListingStartAt() throws Exception {
204188
Thread.sleep(2000L);
205189
java.util.Date startAt = new java.util.Date();
206190
Thread.sleep(2000L);
207-
Map response = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.emptyMap());
191+
Map response = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("tags", SDK_TEST_TAG));
208192
ApiResponse listResources = api.resources(ObjectUtils.asMap("type", "upload", "start_at", startAt, "direction", "asc"));
209193
List<Map> resources = (List<Map>) listResources.get("resources");
210194
assertEquals(response.get("public_id"), resources.get(0).get("public_id"));
@@ -222,15 +206,15 @@ public void testResourcesByPublicIds() throws Exception {
222206
boolean found = false;
223207
for (Map r : resources) {
224208
ArrayList tags = (ArrayList) r.get("tags");
225-
found = found || tags.contains("api_test_tag");
209+
found = found || tags.contains(SDK_TEST_TAG);
226210
}
227211
assertTrue(found);
228212
}
229213

230214
@Test
231215
public void test06ResourcesTag() throws Exception {
232216
// should allow listing resources by tag
233-
Map result = api.resourcesByTag("api_test_tag", ObjectUtils.asMap("tags", true, "context", true));
217+
Map result = api.resourcesByTag(SDK_TEST_TAG, ObjectUtils.asMap("tags", true, "context", true));
234218
Map resource = findByAttr((List<Map>) result.get("resources"), "public_id", API_TEST);
235219
assertNotNull(resource);
236220
resource = findByAttr((List<Map>) result.get("resources"), "context", ObjectUtils.asMap("custom", ObjectUtils.asMap("key", "value")));
@@ -239,7 +223,7 @@ public void test06ResourcesTag() throws Exception {
239223
boolean found = false;
240224
for (Map r : resources) {
241225
ArrayList tags = (ArrayList) r.get("tags");
242-
found = found || tags.contains("api_test_tag");
226+
found = found || tags.contains(SDK_TEST_TAG);
243227
}
244228
assertTrue(found);
245229
}
@@ -258,7 +242,7 @@ public void test07ResourceMetadata() throws Exception {
258242
public void test08DeleteDerived() throws Exception {
259243
// should allow deleting derived resource
260244
cloudinary.uploader().upload(SRC_TEST_IMAGE,
261-
ObjectUtils.asMap("public_id", API_TEST_3, "eager", Collections.singletonList(new Transformation().width(101).crop("scale"))));
245+
ObjectUtils.asMap("public_id", API_TEST_3, "tags", SDK_TEST_TAG, "eager", Collections.singletonList(new Transformation().width(101).crop("scale"))));
262246
Map resource = api.resource(API_TEST_3, ObjectUtils.emptyMap());
263247
assertNotNull(resource);
264248
List<Map> derived = (List<Map>) resource.get("derived");
@@ -275,7 +259,7 @@ public void test08DeleteDerived() throws Exception {
275259
public void test09DeleteResources() throws Exception {
276260
// should allow deleting resources
277261
String public_id = "api_,test3";
278-
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", public_id));
262+
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", public_id, "tags", SDK_TEST_TAG));
279263
Map resource = api.resource(public_id, ObjectUtils.emptyMap());
280264
assertNotNull(resource);
281265
api.deleteResources(Arrays.asList(API_TEST, API_TEST_2, public_id), ObjectUtils.emptyMap());
@@ -285,7 +269,7 @@ public void test09DeleteResources() throws Exception {
285269
@Test(expected = NotFound.class)
286270
public void test09aDeleteResourcesByPrefix() throws Exception {
287271
// should allow deleting resources
288-
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", "api_test_by_prefix"));
272+
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", "api_test_by_prefix", "tags", SDK_TEST_TAG));
289273
Map resource = api.resource("api_test_by_prefix", ObjectUtils.emptyMap());
290274
assertNotNull(resource);
291275
api.deleteResourcesByPrefix("api_test_by", ObjectUtils.emptyMap());
@@ -308,15 +292,15 @@ public void test10Tags() throws Exception {
308292
// should allow listing tags
309293
Map result = api.tags(ObjectUtils.emptyMap());
310294
List<String> tags = (List<String>) result.get("tags");
311-
assertContains("api_test_tag", tags);
295+
assertContains(SDK_TEST_TAG, tags);
312296
}
313297

314298
@Test
315299
public void test11TagsPrefix() throws Exception {
316300
// should allow listing tag by prefix
317-
Map result = api.tags(ObjectUtils.asMap("prefix", API_TEST));
301+
Map result = api.tags(ObjectUtils.asMap("prefix", SDK_TEST_TAG.substring(0,SDK_TEST_TAG.length()-1)));
318302
List<String> tags = (List<String>) result.get("tags");
319-
assertContains("api_test_tag", tags);
303+
assertContains(SDK_TEST_TAG, tags);
320304
result = api.tags(ObjectUtils.asMap("prefix", "api_test_no_such_tag"));
321305
tags = (List<String>) result.get("tags");
322306
assertEquals(0, tags.size());
@@ -426,7 +410,7 @@ public void test19Ping() throws Exception {
426410
public void testDeleteAllResources() throws Exception {
427411
// should allow deleting all resources
428412
cloudinary.uploader().upload(SRC_TEST_IMAGE,
429-
ObjectUtils.asMap("public_id", API_TEST_5, "eager", Collections.singletonList(new Transformation().crop("scale").width(2.0))));
413+
ObjectUtils.asMap("public_id", API_TEST_5, "tags", SDK_TEST_TAG, "eager", Collections.singletonList(new Transformation().crop("scale").width(2.0))));
430414
Map result = api.resource(API_TEST_5, ObjectUtils.emptyMap());
431415
assertEquals(1, ((org.cloudinary.json.JSONArray) result.get("derived")).length());
432416
api.deleteAllResources(ObjectUtils.asMap("keep_original", true));
@@ -438,16 +422,16 @@ public void testDeleteAllResources() throws Exception {
438422
@Test
439423
public void testManualModeration() throws Exception {
440424
// should support setting manual moderation status
441-
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("moderation", "manual"));
442-
Map apiResult = api.update((String) uploadResult.get("public_id"), ObjectUtils.asMap("moderation_status", "approved"));
425+
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("moderation", "manual", "tags", SDK_TEST_TAG));
426+
Map apiResult = api.update((String) uploadResult.get("public_id"), ObjectUtils.asMap("moderation_status", "approved", "tags", SDK_TEST_TAG));
443427
assertEquals("approved", ((Map) ((List<Map>) apiResult.get("moderation")).get(0)).get("status"));
444428
}
445429

446430
@Test
447431
public void testOcrUpdate() {
448432
// should support requesting ocr info
449433
try {
450-
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.emptyMap());
434+
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap( "tags", SDK_TEST_TAG));
451435
api.update((String) uploadResult.get("public_id"), ObjectUtils.asMap("ocr", "illegal"));
452436
} catch (Exception e) {
453437
assertTrue(e instanceof BadRequest);
@@ -459,7 +443,7 @@ public void testOcrUpdate() {
459443
public void testRawConvertUpdate() {
460444
// should support requesting raw conversion
461445
try {
462-
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.emptyMap());
446+
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap( "tags", SDK_TEST_TAG));
463447
api.update((String) uploadResult.get("public_id"), ObjectUtils.asMap("raw_convert", "illegal"));
464448
} catch (Exception e) {
465449
assertTrue(e instanceof BadRequest);
@@ -471,7 +455,7 @@ public void testRawConvertUpdate() {
471455
public void testCategorizationUpdate() {
472456
// should support requesting categorization
473457
try {
474-
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.emptyMap());
458+
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap( "tags", SDK_TEST_TAG));
475459
api.update((String) uploadResult.get("public_id"), ObjectUtils.asMap("categorization", "illegal"));
476460
} catch (Exception e) {
477461
assertTrue(e instanceof BadRequest);
@@ -483,7 +467,7 @@ public void testCategorizationUpdate() {
483467
public void testDetectionUpdate() {
484468
// should support requesting detection
485469
try {
486-
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.emptyMap());
470+
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap( "tags", SDK_TEST_TAG));
487471
api.update((String) uploadResult.get("public_id"), ObjectUtils.asMap("detection", "illegal"));
488472
} catch (Exception e) {
489473
assertTrue(e instanceof BadRequest);
@@ -495,7 +479,7 @@ public void testDetectionUpdate() {
495479
public void testSimilaritySearchUpdate() {
496480
// should support requesting similarity search
497481
try {
498-
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.emptyMap());
482+
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap( "tags", SDK_TEST_TAG));
499483
api.update((String) uploadResult.get("public_id"), ObjectUtils.asMap("similarity_search", "illegal"));
500484
} catch (Exception e) {
501485
assertTrue(e instanceof BadRequest);
@@ -507,7 +491,7 @@ public void testSimilaritySearchUpdate() {
507491
public void testUpdateCustomCoordinates() throws IOException, Exception {
508492
// should update custom coordinates
509493
Coordinates coordinates = new Coordinates("121,31,110,151");
510-
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.emptyMap());
494+
Map uploadResult = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap( "tags", SDK_TEST_TAG));
511495
cloudinary.api().update(uploadResult.get("public_id").toString(), ObjectUtils.asMap("custom_coordinates", coordinates));
512496
Map result = cloudinary.api().resource(uploadResult.get("public_id").toString(), ObjectUtils.asMap("coordinates", true));
513497
int[] expected = new int[]{121, 31, 110, 151};
@@ -591,9 +575,9 @@ public void testUpdateUploadPreset() throws Exception {
591575
@Test
592576
public void testListByModerationUpdate() throws Exception {
593577
// "should support listing by moderation kind and value
594-
Map result1 = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("moderation", "manual"));
595-
Map result2 = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("moderation", "manual"));
596-
Map result3 = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("moderation", "manual"));
578+
Map result1 = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("moderation", "manual", "tags", SDK_TEST_TAG));
579+
Map result2 = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("moderation", "manual", "tags", SDK_TEST_TAG));
580+
Map result3 = cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("moderation", "manual", "tags", SDK_TEST_TAG));
597581
api.update((String) result1.get("public_id"), ObjectUtils.asMap("moderation_status", "approved"));
598582
api.update((String) result2.get("public_id"), ObjectUtils.asMap("moderation_status", "rejected"));
599583
Map approved = api.resourcesByModeration("manual", "approved", ObjectUtils.asMap("max_results", 1000));
@@ -616,10 +600,10 @@ public void testListByModerationUpdate() throws Exception {
616600
// @Test
617601
public void testFolderApi() throws Exception {
618602
// should allow deleting all resources
619-
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", "test_folder1/item"));
620-
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", "test_folder2/item"));
621-
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", "test_folder1/test_subfolder1/item"));
622-
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", "test_folder1/test_subfolder2/item"));
603+
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", "test_folder1/item", "tags", SDK_TEST_TAG));
604+
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", "test_folder2/item", "tags", SDK_TEST_TAG));
605+
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", "test_folder1/test_subfolder1/item", "tags", SDK_TEST_TAG));
606+
cloudinary.uploader().upload(SRC_TEST_IMAGE, ObjectUtils.asMap("public_id", "test_folder1/test_subfolder2/item", "tags", SDK_TEST_TAG));
623607
Map result = api.rootFolders(null);
624608
assertEquals("test_folder1", ((Map) ((org.cloudinary.json.JSONArray) result.get("folders")).get(0)).get("name"));
625609
assertEquals("test_folder2", ((Map) ((org.cloudinary.json.JSONArray) result.get("folders")).get(1)).get("name"));
@@ -638,7 +622,7 @@ public void testFolderApi() throws Exception {
638622
public void testRestore() throws Exception {
639623
// should support restoring resources
640624
cloudinary.uploader().upload(SRC_TEST_IMAGE,
641-
ObjectUtils.asMap("public_id", "api_test_restore", "backup", true));
625+
ObjectUtils.asMap("public_id", "api_test_restore", "backup", true, "tags", SDK_TEST_TAG));
642626
Map resource = api.resource("api_test_restore", ObjectUtils.emptyMap());
643627
assertEquals(resource.get("bytes"), 3381);
644628
api.deleteResources(Arrays.asList("api_test_restore"), ObjectUtils.emptyMap());

0 commit comments

Comments
 (0)