2323
2424public class UploaderTest extends InstrumentationTestCase {
2525
26-
27- private Cloudinary cloudinary ;
26+
27+ public static final String TEST_IMAGE = "images/old_logo.png" ;
28+ private Cloudinary cloudinary ;
2829 private static boolean first = true ;
2930
3031 public void setUp () throws Exception {
@@ -44,7 +45,7 @@ protected InputStream getAssetStream(String filename) throws IOException {
4445 public void testUpload () throws Exception {
4546 if (cloudinary .config .apiSecret == null )
4647 return ;
47- JSONObject result = new JSONObject (cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("colors" , true )));
48+ JSONObject result = new JSONObject (cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("colors" , true )));
4849 assertEquals (result .getLong ("width" ), 241L );
4950 assertEquals (result .getLong ("height" ), 51L );
5051 assertNotNull (result .get ("colors" ));
@@ -59,7 +60,7 @@ public void testUpload() throws Exception {
5960 public void testUnsignedUpload () throws Exception {
6061 if (cloudinary .config .apiSecret == null )
6162 return ;
62- JSONObject result = new JSONObject (cloudinary .uploader ().unsignedUpload (getAssetStream ("images/logo.png" ), "sample_preset_dhfjhriu" ,
63+ JSONObject result = new JSONObject (cloudinary .uploader ().unsignedUpload (getAssetStream (TEST_IMAGE ), "sample_preset_dhfjhriu" ,
6364 ObjectUtils .emptyMap ()));
6465 assertEquals (result .getLong ("width" ), 241L );
6566 assertEquals (result .getLong ("height" ), 51L );
@@ -74,7 +75,7 @@ public void testUnsignedUpload() throws Exception {
7475 public void testUploadUrl () throws Exception {
7576 if (cloudinary .config .apiSecret == null )
7677 return ;
77- JSONObject result = new JSONObject (cloudinary .uploader ().upload ("http://cloudinary.com/images/logo .png" , ObjectUtils .emptyMap ()));
78+ JSONObject result = new JSONObject (cloudinary .uploader ().upload ("http://cloudinary.com/images/old_logo .png" , ObjectUtils .emptyMap ()));
7879 assertEquals (result .getLong ("width" ), 241L );
7980 assertEquals (result .getLong ("height" ), 51L );
8081 Map <String , Object > to_sign = new HashMap <String , Object >();
@@ -113,7 +114,7 @@ public void testUploadExternalSignature() throws Exception {
113114 params .put ("timestamp" , Long .valueOf (System .currentTimeMillis () / 1000L ).toString ());
114115 params .put ("signature" , this .cloudinary .apiSignRequest (params , apiSecret ));
115116 Cloudinary emptyCloudinary = new Cloudinary (config );
116- JSONObject result = new JSONObject (emptyCloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), params ));
117+ JSONObject result = new JSONObject (emptyCloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), params ));
117118 assertEquals (result .getLong ("width" ), 241L );
118119 assertEquals (result .getLong ("height" ), 51L );
119120 Map <String , Object > to_sign = new HashMap <String , Object >();
@@ -126,7 +127,7 @@ public void testUploadExternalSignature() throws Exception {
126127 public void testRename () throws Exception {
127128 if (cloudinary .config .apiSecret == null )
128129 return ;
129- JSONObject result = new JSONObject (cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .emptyMap ()));
130+ JSONObject result = new JSONObject (cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .emptyMap ()));
130131
131132 cloudinary .uploader ().rename (result .getString ("public_id" ), result .get ("public_id" ) + "2" , ObjectUtils .emptyMap ());
132133
@@ -154,15 +155,15 @@ public void testExplicit() throws Exception {
154155 public void testEager () throws Exception {
155156 if (cloudinary .config .apiSecret == null )
156157 return ;
157- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ),
158+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ),
158159 ObjectUtils .asMap ("eager" , Collections .singletonList (new Transformation ().crop ("scale" ).width (2.0 ))));
159160 }
160161
161162 public void testHeaders () throws Exception {
162163 if (cloudinary .config .apiSecret == null )
163164 return ;
164- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("headers" , new String [] { "Link: 1" }));
165- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("headers" , ObjectUtils .asMap ("Link" , "1" )));
165+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("headers" , new String [] { "Link: 1" }));
166+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("headers" , ObjectUtils .asMap ("Link" , "1" )));
166167 }
167168
168169 public void testText () throws Exception {
@@ -176,8 +177,8 @@ public void testText() throws Exception {
176177 public void testSprite () throws Exception {
177178 if (cloudinary .config .apiSecret == null )
178179 return ;
179- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("tags" , "sprite_test_tag" , "public_id" , "sprite_test_tag_1" ));
180- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("tags" , "sprite_test_tag" , "public_id" , "sprite_test_tag_2" ));
180+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("tags" , "sprite_test_tag" , "public_id" , "sprite_test_tag_1" ));
181+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("tags" , "sprite_test_tag" , "public_id" , "sprite_test_tag_2" ));
181182 JSONObject result = new JSONObject (cloudinary .uploader ().generate_sprite ("sprite_test_tag" , ObjectUtils .emptyMap ()));
182183 assertEquals (2 , result .getJSONObject ("image_infos" ).length ());
183184 result = new JSONObject (cloudinary .uploader ().generate_sprite ("sprite_test_tag" , ObjectUtils .asMap ("transformation" , "w_100" )));
@@ -190,8 +191,8 @@ public void testSprite() throws Exception {
190191 public void testMulti () throws Exception {
191192 if (cloudinary .config .apiSecret == null )
192193 return ;
193- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("tags" , "multi_test_tag" , "public_id" , "multi_test_tag_1" ));
194- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("tags" , "multi_test_tag" , "public_id" , "multi_test_tag_2" ));
194+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("tags" , "multi_test_tag" , "public_id" , "multi_test_tag_1" ));
195+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("tags" , "multi_test_tag" , "public_id" , "multi_test_tag_2" ));
195196 JSONObject result = new JSONObject (cloudinary .uploader ().multi ("multi_test_tag" , ObjectUtils .emptyMap ()));
196197 assertTrue ((result .getString ("url" )).endsWith (".gif" ));
197198 result = new JSONObject (cloudinary .uploader ().multi ("multi_test_tag" , ObjectUtils .asMap ("transformation" , "w_100" )));
@@ -205,9 +206,9 @@ public void testUniqueFilename() throws Exception {
205206 if (cloudinary .config .apiSecret == null )
206207 return ;
207208
208- File f = new File (getInstrumentation ().getContext ().getCacheDir () + "/logo .png" );
209+ File f = new File (getInstrumentation ().getContext ().getCacheDir () + "/old_logo .png" );
209210
210- InputStream is = getAssetStream ("images/logo.png" );
211+ InputStream is = getAssetStream (TEST_IMAGE );
211212 int size = is .available ();
212213 byte [] buffer = new byte [size ];
213214 is .read (buffer );
@@ -232,7 +233,7 @@ public void testFaceCoordinates() throws Exception {
232233 Rectangle rect2 = new Rectangle (120 , 30 , 229 , 270 );
233234 coordinates .addRect (rect1 );
234235 coordinates .addRect (rect2 );
235- JSONObject result = new JSONObject (cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("face_coordinates" , coordinates , "faces" , true )));
236+ JSONObject result = new JSONObject (cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("face_coordinates" , coordinates , "faces" , true )));
236237 JSONArray resultFaces = result .getJSONArray ("faces" );
237238 assertEquals (2 , resultFaces .length ());
238239
@@ -258,14 +259,14 @@ public void testContext() throws Exception {
258259 return ;
259260 @ SuppressWarnings ("rawtypes" )
260261 Map context = ObjectUtils .asMap ("caption" , "some caption" , "alt" , "alternative" );
261- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("context" , context ));
262+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("context" , context ));
262263 }
263264
264265 public void testModerationRequest () throws Exception {
265266 // should support requesting manual moderation
266267 if (cloudinary .config .apiSecret == null )
267268 return ;
268- JSONObject result = new JSONObject (cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("moderation" , "manual" )));
269+ JSONObject result = new JSONObject (cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("moderation" , "manual" )));
269270 assertEquals ("manual" , result .getJSONArray ("moderation" ).getJSONObject (0 ).getString ("kind" ));
270271 assertEquals ("pending" , result .getJSONArray ("moderation" ).getJSONObject (0 ).getString ("status" ));
271272 }
@@ -286,7 +287,7 @@ public void testCategorizationRequest() {
286287 if (cloudinary .config .apiSecret == null )
287288 return ;
288289 try {
289- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("categorization" , "illegal" ));
290+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("categorization" , "illegal" ));
290291 } catch (Exception e ) {
291292 assertTrue (e .getMessage ().matches (".*illegal is not a valid.*" ));
292293 }
@@ -297,7 +298,7 @@ public void testDetectionRequest() {
297298 if (cloudinary .config .apiSecret == null )
298299 return ;
299300 try {
300- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("detection" , "illegal" ));
301+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("detection" , "illegal" ));
301302 } catch (Exception e ) {
302303 assertTrue (e .getMessage ().matches (".*illegal is not a valid.*" ));
303304 }
@@ -309,7 +310,7 @@ public void testAutoTaggingRequest() {
309310 return ;
310311
311312 try {
312- cloudinary .uploader ().upload (getAssetStream ("images/logo.png" ), ObjectUtils .asMap ("auto_tagging" , 0.5f ));
313+ cloudinary .uploader ().upload (getAssetStream (TEST_IMAGE ), ObjectUtils .asMap ("auto_tagging" , 0.5f ));
313314 } catch (Exception e ) {
314315 for (int i = 0 ; i < e .getStackTrace ().length ; i ++) {
315316 StackTraceElement x = e .getStackTrace ()[i ];
0 commit comments