55import com .cloudinary .Coordinates ;
66import com .cloudinary .Transformation ;
77import com .cloudinary .api .ApiResponse ;
8- import com .cloudinary .api .RateLimit ;
98import com .cloudinary .api .exceptions .BadRequest ;
109import com .cloudinary .api .exceptions .NotFound ;
1110import com .cloudinary .transformation .TextLayer ;
1211import com .cloudinary .utils .ObjectUtils ;
13- import static org .hamcrest .Matchers .hasEntry ;
14- import static org .hamcrest .Matchers .hasItem ;
15- import static org .hamcrest .Matchers .equalTo ;
1612import org .junit .*;
17- import org .junit .rules .ExpectedException ;
1813import org .junit .rules .TestName ;
1914
2015import java .io .IOException ;
2116import java .util .*;
2217
18+ import static org .hamcrest .Matchers .*;
2319import static org .hamcrest .core .AllOf .allOf ;
2420import static org .hamcrest .core .IsNot .not ;
2521import static org .junit .Assert .*;
@@ -42,6 +38,7 @@ abstract public class AbstractApiTest extends MockableTest {
4238 public static final String [] UPLOAD_TAGS = {SDK_TEST_TAG , uniqueTag };
4339 public static final String EXPLICIT_TRANSFORMATION_NAME = "c_scale,l_text:Arial_60:" + SUFFIX + ",w_100" ;
4440 public static final Transformation EXPLICIT_TRANSFORMATION = new Transformation ().width (100 ).crop ("scale" ).overlay (new TextLayer ().text (SUFFIX ).fontFamily ("Arial" ).fontSize (60 ));
41+ public static final String TEST_KEY = "test-key" + SUFFIX ;
4542
4643 protected Api api ;
4744
@@ -58,15 +55,17 @@ public static void setUpClass() throws IOException {
5855 options .put ("public_id" , API_TEST_1 );
5956 cloudinary .uploader ().upload (SRC_TEST_IMAGE , options );
6057
61- options = ObjectUtils .asMap ("public_id" , "context_1" , "tags" , new String []{SDK_TEST_TAG , uniqueTag }, "context" , "test-key=alt" );
58+ String context1 = TEST_KEY + "=alt" ;
59+ String context2 = TEST_KEY + "=alternate" ;
60+ options = ObjectUtils .asMap ("public_id" , "context_1" , "tags" , new String []{SDK_TEST_TAG , uniqueTag }, "context" , context1 );
6261 cloudinary .uploader ().upload (SRC_TEST_IMAGE , options );
63- options = ObjectUtils .asMap ("public_id" , "context_2" , "tags" , new String []{SDK_TEST_TAG , uniqueTag }, "context" , "test-key=alternate" );
62+ options = ObjectUtils .asMap ("public_id" , "context_2" , "tags" , new String []{SDK_TEST_TAG , uniqueTag }, "context" , context2 );
6463 cloudinary .uploader ().upload (SRC_TEST_IMAGE , options );
6564 }
6665
6766 @ AfterClass
6867 public static void tearDownClass () {
69- Api api = MockableTest .cleanUp ();
68+ Api api = MockableTest .cleanUp ();
7069 try {
7170// api.deleteResources(Arrays.asList(API_TEST, API_TEST_1, API_TEST_2, API_TEST_3, API_TEST_5), ObjectUtils.emptyMap());
7271 api .deleteResourcesByTag (uniqueTag , ObjectUtils .emptyMap ());
@@ -102,6 +101,7 @@ public static void tearDownClass() {
102101 }
103102
104103 }
104+
105105 @ Rule
106106 public TestName currentTest = new TestName ();
107107
@@ -143,8 +143,8 @@ public void test02Resources() throws Exception {
143143 Map result = api .resources (ObjectUtils .asMap ("max_results" , 500 , "next_cursor" , next_cursor ));
144144 resources .addAll ((List ) result .get ("resources" ));
145145 next_cursor = (String ) result .get ("next_cursor" );
146- } while (next_cursor != null );
147- assertThat (resources , hasItem (allOf (hasEntry ("public_id" , (String ) resource .get ("public_id" )),hasEntry ("type" , "upload" ))));
146+ } while (next_cursor != null );
147+ assertThat (resources , hasItem (allOf (hasEntry ("public_id" , (String ) resource .get ("public_id" )), hasEntry ("type" , "upload" ))));
148148 }
149149
150150 @ Test
@@ -183,9 +183,9 @@ public void test05ResourcesByPrefix() throws Exception {
183183 assertThat (resources , hasItem (hasEntry ("public_id" , (Object ) API_TEST )));
184184 assertThat (resources , hasItem (hasEntry ("public_id" , (Object ) API_TEST_1 )));
185185// resources = (List<Map<? extends String, ?>>) result.get("resources");
186- assertThat (resources , hasItem (allOf (hasEntry ("public_id" , API_TEST ),hasEntry ("type" , "upload" ))));
186+ assertThat (resources , hasItem (allOf (hasEntry ("public_id" , API_TEST ), hasEntry ("type" , "upload" ))));
187187 assertThat (resources , hasItem (hasEntry ("context" , ObjectUtils .asMap ("custom" , ObjectUtils .asMap ("key" , "value" )))));
188- assertThat (resources , hasItem (hasEntry (equalTo ("tags" ), hasItem ( SDK_TEST_TAG ))));
188+ assertThat (resources , hasItem (hasEntry (equalTo ("tags" ), hasItem (SDK_TEST_TAG ))));
189189 }
190190
191191 @ Test
@@ -338,15 +338,15 @@ public void test10Tags() throws Exception {
338338 // should allow listing tags
339339 Map result = api .tags (ObjectUtils .asMap ("max_results" , 500 ));
340340 List <String > tags = (List <String >) result .get ("tags" );
341- assertThat ( tags , hasItem (SDK_TEST_TAG ));
341+ assertThat (tags , hasItem (SDK_TEST_TAG ));
342342 }
343343
344344 @ Test
345345 public void test11TagsPrefix () throws Exception {
346346 // should allow listing tag by prefix
347- Map result = api .tags (ObjectUtils .asMap ("prefix" , SDK_TEST_TAG .substring (0 ,SDK_TEST_TAG .length ()- 1 )));
347+ Map result = api .tags (ObjectUtils .asMap ("prefix" , SDK_TEST_TAG .substring (0 , SDK_TEST_TAG .length () - 1 )));
348348 List <String > tags = (List <String >) result .get ("tags" );
349- assertThat ( tags , hasItem (SDK_TEST_TAG ));
349+ assertThat (tags , hasItem (SDK_TEST_TAG ));
350350 result = api .tags (ObjectUtils .asMap ("prefix" , "api_test_no_such_tag" ));
351351 tags = (List <String >) result .get ("tags" );
352352 assertEquals (0 , tags .size ());
@@ -429,14 +429,14 @@ public void test17aTransformationDeleteImplicit() throws Exception {
429429
430430 @ Test
431431 public void test20ResourcesContext () throws Exception {
432- Map result = api .resourcesByContext ("test-key" , ObjectUtils .emptyMap ());
432+ Map result = api .resourcesByContext (TEST_KEY , ObjectUtils .emptyMap ());
433433
434434 List <Map > resources = (List <Map >) result .get ("resources" );
435- assertEquals (2 ,resources .size ());
436- result = api .resourcesByContext ("test-key" , "alt" , ObjectUtils .emptyMap ());
435+ assertEquals (2 , resources .size ());
436+ result = api .resourcesByContext (TEST_KEY , "alt" , ObjectUtils .emptyMap ());
437437
438438 resources = (List <Map >) result .get ("resources" );
439- assertEquals (1 ,resources .size ());
439+ assertEquals (1 , resources .size ());
440440 }
441441
442442 /**
@@ -497,7 +497,7 @@ public void testManualModeration() throws Exception {
497497 public void testOcrUpdate () {
498498 // should support requesting ocr info
499499 try {
500- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
500+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("tags" , UPLOAD_TAGS ));
501501 api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("ocr" , "illegal" ));
502502 } catch (Exception e ) {
503503 assertTrue (e instanceof BadRequest );
@@ -509,7 +509,7 @@ public void testOcrUpdate() {
509509 public void testRawConvertUpdate () {
510510 // should support requesting raw conversion
511511 try {
512- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
512+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("tags" , UPLOAD_TAGS ));
513513 api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("raw_convert" , "illegal" ));
514514 } catch (Exception e ) {
515515 assertTrue (e instanceof BadRequest );
@@ -521,7 +521,7 @@ public void testRawConvertUpdate() {
521521 public void testCategorizationUpdate () {
522522 // should support requesting categorization
523523 try {
524- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
524+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("tags" , UPLOAD_TAGS ));
525525 api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("categorization" , "illegal" ));
526526 } catch (Exception e ) {
527527 assertTrue (e instanceof BadRequest );
@@ -533,7 +533,7 @@ public void testCategorizationUpdate() {
533533 public void testDetectionUpdate () {
534534 // should support requesting detection
535535 try {
536- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
536+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("tags" , UPLOAD_TAGS ));
537537 api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("detection" , "illegal" ));
538538 } catch (Exception e ) {
539539 assertTrue (e instanceof BadRequest );
@@ -545,7 +545,7 @@ public void testDetectionUpdate() {
545545 public void testSimilaritySearchUpdate () {
546546 // should support requesting similarity search
547547 try {
548- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
548+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("tags" , UPLOAD_TAGS ));
549549 api .update ((String ) uploadResult .get ("public_id" ), ObjectUtils .asMap ("similarity_search" , "illegal" ));
550550 } catch (Exception e ) {
551551 assertTrue (e instanceof BadRequest );
@@ -557,7 +557,7 @@ public void testSimilaritySearchUpdate() {
557557 public void testUpdateCustomCoordinates () throws IOException , Exception {
558558 // should update custom coordinates
559559 Coordinates coordinates = new Coordinates ("121,31,110,151" );
560- Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ( "tags" , UPLOAD_TAGS ));
560+ Map uploadResult = cloudinary .uploader ().upload (SRC_TEST_IMAGE , ObjectUtils .asMap ("tags" , UPLOAD_TAGS ));
561561 cloudinary .api ().update (uploadResult .get ("public_id" ).toString (), ObjectUtils .asMap ("custom_coordinates" , coordinates ));
562562 Map result = cloudinary .api ().resource (uploadResult .get ("public_id" ).toString (), ObjectUtils .asMap ("coordinates" , true ));
563563 int [] expected = new int []{121 , 31 , 110 , 151 };
0 commit comments