|
1 | 1 | package com.cloudinary.test;
|
2 | 2 |
|
3 | 3 | import com.cloudinary.Cloudinary;
|
| 4 | +import com.cloudinary.Search; |
4 | 5 | import com.cloudinary.utils.ObjectUtils;
|
5 | 6 | import org.junit.*;
|
6 | 7 | import org.junit.rules.TestName;
|
7 | 8 |
|
8 |
| -import java.util.List; |
9 |
| -import java.util.Map; |
| 9 | +import java.lang.reflect.Field; |
| 10 | +import java.util.*; |
10 | 11 |
|
11 |
| -import static org.junit.Assert.assertEquals; |
12 |
| -import static org.junit.Assert.assertNull; |
| 12 | +import static org.junit.Assert.*; |
13 | 13 | import static org.junit.Assume.assumeNotNull;
|
14 | 14 |
|
15 | 15 | @SuppressWarnings({"rawtypes", "unchecked", "JavaDoc"})
|
@@ -74,12 +74,46 @@ public void shouldFindResourceByAssetId() throws Exception {
|
74 | 74 | assertEquals(1, resources.size());
|
75 | 75 | }
|
76 | 76 |
|
| 77 | + @Test |
| 78 | + public void testShouldNotDuplicateValues() throws Exception { |
| 79 | + Search request = cloudinary.search().maxResults(1). |
| 80 | + sortBy("created_at", "asc") |
| 81 | + .sortBy("created_at", "desc") |
| 82 | + .sortBy("public_id", "asc") |
| 83 | + .aggregate("format") |
| 84 | + .aggregate("format") |
| 85 | + .aggregate("resource_type") |
| 86 | + .withField("context") |
| 87 | + .withField("context") |
| 88 | + .withField("tags"); |
| 89 | + Field[] fields = Search.class.getDeclaredFields(); |
| 90 | + for(Field field : fields) { |
| 91 | + if(field.getName() == "aggregateParam") { |
| 92 | + field.setAccessible(true); |
| 93 | + ArrayList<String> aggregateList = (ArrayList<String>) field.get(request); |
| 94 | + Set<String> testSet = new HashSet<String>(aggregateList); |
| 95 | + assertTrue(aggregateList.size() == testSet.size()); |
| 96 | + } |
| 97 | + if (field.getName() == "withFieldParam") { |
| 98 | + field.setAccessible(true); |
| 99 | + ArrayList<String> withFieldList = (ArrayList<String>) field.get(request); |
| 100 | + Set<String> testSet = new HashSet<String>(withFieldList); |
| 101 | + assertTrue(withFieldList.size() == testSet.size()); |
| 102 | + } |
| 103 | + if (field.getName() == "sortByParam") { |
| 104 | + field.setAccessible(true); |
| 105 | + ArrayList<HashMap<String, Object>> sortByList = (ArrayList<HashMap<String, Object>>) field.get(request); |
| 106 | + Set<HashMap<String, Object>> testSet = new HashSet<HashMap<String, Object>>(sortByList); |
| 107 | + assertTrue(sortByList.size() == testSet.size()); |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + |
77 | 112 | @Test
|
78 | 113 | public void shouldPaginateResourcesLimitedByTagAndOrderdByAscendingPublicId() throws Exception {
|
79 | 114 | List<Map> resources;
|
80 | 115 | Map result = cloudinary.search().maxResults(1).expression(String.format("tags:%s", SEARCH_TAG)).sortBy("public_id", "asc").execute();
|
81 | 116 | resources = (List<Map>) result.get("resources");
|
82 |
| - |
83 | 117 | assertEquals(1, resources.size());
|
84 | 118 | assertEquals(3, result.get("total_count"));
|
85 | 119 | assertEquals(SEARCH_TEST, resources.get(0).get("public_id"));
|
|
0 commit comments