|
6 | 6 | import com.cloudinary.api.exceptions.BadRequest; |
7 | 7 | import com.cloudinary.metadata.*; |
8 | 8 |
|
| 9 | +import com.cloudinary.test.helpers.Feature; |
9 | 10 | import com.cloudinary.utils.ObjectUtils; |
10 | 11 | import org.hamcrest.Matchers; |
11 | 12 | import org.junit.*; |
@@ -196,7 +197,7 @@ public void testReorderMetadataFieldsByLabel() throws Exception { |
196 | 197 | AddStringField("some_value"); |
197 | 198 | AddStringField("aaa"); |
198 | 199 | AddStringField("zzz"); |
199 | | - |
| 200 | + |
200 | 201 | ApiResponse result = api.reorderMetadataFields("label", null, Collections.EMPTY_MAP); |
201 | 202 | assertThat(getField(result, 0), Matchers.containsString("aaa")); |
202 | 203 |
|
@@ -309,6 +310,55 @@ public void testSetField() throws Exception { |
309 | 310 | assertNotNull(result); |
310 | 311 | assertEquals(PUBLIC_ID, ((List) result.get("public_ids")).get(0).toString()); |
311 | 312 | } |
| 313 | + |
| 314 | + @Test |
| 315 | + public void testListMetadataRules() throws Exception { |
| 316 | + Assume.assumeTrue(MockableTest.shouldTestFeature(Feature.CONDITIONAL_METADATA_RULES)); |
| 317 | + ApiResponse result = cloudinary.api().listMetadataRules(null); |
| 318 | + assertNotNull(result); |
| 319 | + } |
| 320 | + |
| 321 | + @Test |
| 322 | + public void testAddMetadataRule() throws Exception { |
| 323 | + Assume.assumeTrue(MockableTest.shouldTestFeature(Feature.CONDITIONAL_METADATA_RULES)); |
| 324 | + SetMetadataField field = createSetField("test123"); |
| 325 | + ApiResponse response = addFieldToAccount(field); |
| 326 | + assertNotNull(response); |
| 327 | + |
| 328 | + String externalId = (String) response.get("external_id"); |
| 329 | + MetadataRule rule = new MetadataRule(externalId, "category-employee", new MetadataRuleCondition("category", false, null, "employee"), new MetadataRuleResult(true, "all", null, null)); |
| 330 | + ApiResponse result = cloudinary.api().addMetadataRule(rule, ObjectUtils.asMap()); |
| 331 | + assertNotNull(result); |
| 332 | + |
| 333 | + String name = (String) result.get("name"); |
| 334 | + assertEquals(name, "category-employee"); |
| 335 | + } |
| 336 | + |
| 337 | + @Test |
| 338 | + public void testUpdateMetadataRule() throws Exception { |
| 339 | + Assume.assumeTrue(MockableTest.shouldTestFeature(Feature.CONDITIONAL_METADATA_RULES)); |
| 340 | + ApiResponse response = cloudinary.api().listMetadataRules(null); |
| 341 | + List metadataRules = (List) response.get("metadata_rules"); |
| 342 | + assertNotNull(metadataRules); |
| 343 | + String externalId = (String) ((Map) metadataRules.get(0)).get("external_id"); |
| 344 | + |
| 345 | + MetadataRule rule = new MetadataRule(null, "test_name", null, null); |
| 346 | + ApiResponse result = cloudinary.api().updateMetadataRule(externalId, rule, ObjectUtils.asMap()); |
| 347 | + assertNotNull(result); |
| 348 | + } |
| 349 | + |
| 350 | + @Test |
| 351 | + public void testDeleteMetadataRule() throws Exception { |
| 352 | + Assume.assumeTrue(MockableTest.shouldTestFeature(Feature.CONDITIONAL_METADATA_RULES)); |
| 353 | + ApiResponse response = cloudinary.api().listMetadataRules(null); |
| 354 | + List metadataRules = (List) response.get("metadata_rules"); |
| 355 | + assertNotNull(metadataRules); |
| 356 | + String externalId = (String) ((Map) metadataRules.get(0)).get("external_id"); |
| 357 | + |
| 358 | + ApiResponse result = cloudinary.api().deleteMetadataRule(externalId, ObjectUtils.emptyMap()); |
| 359 | + assertNotNull(result); |
| 360 | + } |
| 361 | + |
312 | 362 | // Metadata test helpers |
313 | 363 | private SetMetadataField createSetField(String labelPrefix) { |
314 | 364 | SetMetadataField setField = new SetMetadataField(); |
|
0 commit comments