|
5 | 5 | import com.cloudinary.api.ApiResponse; |
6 | 6 | import com.cloudinary.api.exceptions.BadRequest; |
7 | 7 | import com.cloudinary.metadata.*; |
| 8 | + |
| 9 | +import org.hamcrest.Matchers; |
8 | 10 | import org.junit.*; |
9 | 11 | import org.junit.rules.TestName; |
10 | 12 |
|
@@ -172,6 +174,38 @@ public void testRestoreDatasourceEntries() throws Exception { |
172 | 174 | assertNotNull(result); |
173 | 175 | } |
174 | 176 |
|
| 177 | + @Test |
| 178 | + public void testReorderMetadataFieldsByLabel() throws Exception { |
| 179 | + AddStringField("some_value"); |
| 180 | + AddStringField("aaa"); |
| 181 | + AddStringField("zzz"); |
| 182 | + |
| 183 | + ApiResponse result = api.reorderMetadataFields("label", null, Collections.EMPTY_MAP); |
| 184 | + assertThat(getField(result, 0), Matchers.containsString("aaa")); |
| 185 | + |
| 186 | + result = api.reorderMetadataFields("label", "desc", Collections.EMPTY_MAP); |
| 187 | + assertThat(getField(result, 0), Matchers.containsString("zzz")); |
| 188 | + |
| 189 | + result = api.reorderMetadataFields("label", "asc", Collections.EMPTY_MAP); |
| 190 | + assertThat(getField(result, 0), Matchers.containsString("aaa")); |
| 191 | + } |
| 192 | + |
| 193 | + @Test(expected = IllegalArgumentException.class) |
| 194 | + public void testReorderMetadataFieldsOrderByIsRequired() throws Exception { |
| 195 | + api.reorderMetadataFields(null, null, Collections.EMPTY_MAP); |
| 196 | + } |
| 197 | + |
| 198 | + private String getField(ApiResponse result, int index) { |
| 199 | + String actual = ((Map)((ArrayList)result.get("metadata_fields")).get(index)).get("label").toString(); |
| 200 | + return actual; |
| 201 | + } |
| 202 | + |
| 203 | + private void AddStringField(String labelPrefix) throws Exception { |
| 204 | + StringMetadataField field = newFieldInstance(labelPrefix); |
| 205 | + ApiResponse fieldResult = addFieldToAccount(field); |
| 206 | + String fieldId = fieldResult.get("external_id").toString(); |
| 207 | + } |
| 208 | + |
175 | 209 | @Test |
176 | 210 | public void testUploadWithMetadata() throws Exception { |
177 | 211 | StringMetadataField field = newFieldInstance("testUploadWithMetadata"); |
|
0 commit comments