Skip to content

Commit 87fa4db

Browse files
author
Amir Tocker
committed
Refactor tests for stability
1 parent 330f11b commit 87fa4db

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractApiTest.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.cloudinary.api.ApiResponse;
88
import com.cloudinary.api.exceptions.BadRequest;
99
import com.cloudinary.api.exceptions.NotFound;
10+
import com.cloudinary.transformation.TextLayer;
1011
import com.cloudinary.utils.ObjectUtils;
1112
import static org.hamcrest.Matchers.hasEntry;
1213
import static org.hamcrest.Matchers.hasItem;
@@ -37,6 +38,9 @@ abstract public class AbstractApiTest extends MockableTest {
3738
public static final String API_TEST_UPLOAD_PRESET_3 = API_TEST_UPLOAD_PRESET + "3";
3839
public static final String API_TEST_UPLOAD_PRESET_4 = API_TEST_UPLOAD_PRESET + "4";
3940
public static final String[] UPLOAD_TAGS = {SDK_TEST_TAG, uniqueTag};
41+
public static final String EXPLICIT_TRANSFORMATION_NAME = "c_scale,l_text:Arial_60:" + SUFFIX + ",w_100";
42+
public static final Transformation EXPLICIT_TRANSFORMATION = new Transformation().width(100).crop("scale").overlay(new TextLayer().text(SUFFIX).fontFamily("Arial").fontSize(60));
43+
4044
protected Api api;
4145

4246
@BeforeClass
@@ -47,7 +51,7 @@ public static void setUpClass() throws IOException {
4751
return;
4852
}
4953
Map options = ObjectUtils.asMap("public_id", API_TEST, "tags", new String[]{SDK_TEST_TAG, uniqueTag}, "context", "key=value", "eager",
50-
Collections.singletonList(new Transformation().width(100).crop("scale")));
54+
Collections.singletonList(EXPLICIT_TRANSFORMATION));
5155
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
5256
options.put("public_id", API_TEST_1);
5357
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
@@ -330,7 +334,7 @@ public void test11TagsPrefix() throws Exception {
330334
public void test12Transformations() throws Exception {
331335
// should allow listing transformations
332336
Map result = api.transformations(ObjectUtils.emptyMap());
333-
Map transformation = findByAttr((List<Map>) result.get("transformations"), "name", "c_scale,w_100");
337+
Map transformation = findByAttr((List<Map>) result.get("transformations"), "name", EXPLICIT_TRANSFORMATION_NAME);
334338

335339
assertNotNull(transformation);
336340
assertTrue((Boolean) transformation.get("used"));
@@ -339,22 +343,21 @@ public void test12Transformations() throws Exception {
339343
@Test
340344
public void test13TransformationMetadata() throws Exception {
341345
// should allow getting transformation metadata
342-
final Transformation tr = new Transformation().crop("scale").width(100);
343-
preloadResource(ObjectUtils.asMap("eager", Collections.singletonList(tr)));
344-
Map transformation = api.transformation("c_scale,w_100", ObjectUtils.asMap("max_results", 500));
346+
preloadResource(ObjectUtils.asMap("eager", Collections.singletonList(EXPLICIT_TRANSFORMATION)));
347+
Map transformation = api.transformation(EXPLICIT_TRANSFORMATION_NAME, ObjectUtils.asMap("max_results", 500));
345348
assertNotNull(transformation);
346-
assertEquals(new Transformation((List<Map>) transformation.get("info")).generate(), tr.generate());
349+
assertEquals(new Transformation((List<Map>) transformation.get("info")).generate(), EXPLICIT_TRANSFORMATION.generate());
347350
}
348351

349352
@Test
350353
public void test14TransformationUpdate() throws Exception {
351354
// should allow updating transformation allowed_for_strict
352-
api.updateTransformation("c_scale,w_100", ObjectUtils.asMap("allowed_for_strict", true), ObjectUtils.emptyMap());
353-
Map transformation = api.transformation("c_scale,w_100", ObjectUtils.emptyMap());
355+
api.updateTransformation(EXPLICIT_TRANSFORMATION_NAME, ObjectUtils.asMap("allowed_for_strict", true), ObjectUtils.emptyMap());
356+
Map transformation = api.transformation(EXPLICIT_TRANSFORMATION_NAME, ObjectUtils.emptyMap());
354357
assertNotNull(transformation);
355358
assertEquals(transformation.get("allowed_for_strict"), true);
356-
api.updateTransformation("c_scale,w_100", ObjectUtils.asMap("allowed_for_strict", false), ObjectUtils.emptyMap());
357-
transformation = api.transformation("c_scale,w_100", ObjectUtils.emptyMap());
359+
api.updateTransformation(EXPLICIT_TRANSFORMATION_NAME, ObjectUtils.asMap("allowed_for_strict", false), ObjectUtils.emptyMap());
360+
transformation = api.transformation(EXPLICIT_TRANSFORMATION_NAME, ObjectUtils.emptyMap());
358361
assertNotNull(transformation);
359362
assertEquals(transformation.get("allowed_for_strict"), false);
360363
}
@@ -398,8 +401,8 @@ public void test16bTransformationDelete() throws Exception {
398401
@Test
399402
public void test17aTransformationDeleteImplicit() throws Exception {
400403
// should allow deleting implicit transformation
401-
api.transformation("c_scale,w_100", ObjectUtils.emptyMap());
402-
api.deleteTransformation("c_scale,w_100", ObjectUtils.emptyMap());
404+
api.transformation(EXPLICIT_TRANSFORMATION_NAME, ObjectUtils.emptyMap());
405+
api.deleteTransformation(EXPLICIT_TRANSFORMATION_NAME, ObjectUtils.emptyMap());
403406
}
404407

405408
@Test
@@ -420,7 +423,7 @@ public void test20ResourcesContext() throws Exception {
420423
*/
421424
@Test(expected = NotFound.class)
422425
public void test17bTransformationDeleteImplicit() throws Exception {
423-
api.transformation("c_scale,w_100", ObjectUtils.emptyMap());
426+
api.transformation(EXPLICIT_TRANSFORMATION_NAME, ObjectUtils.emptyMap());
424427
}
425428

426429
@Test
@@ -556,9 +559,7 @@ public void testGetUploadPreset() throws Exception {
556559
// should allow getting a single upload_preset
557560
String[] tags = {"a", "b", "c"};
558561
Map context = ObjectUtils.asMap("a", "b", "c", "d");
559-
Transformation transformation = new Transformation();
560-
transformation.width(100).crop("scale");
561-
Map result = api.createUploadPreset(ObjectUtils.asMap("unsigned", true, "folder", "folder", "transformation", transformation, "tags", tags, "context",
562+
Map result = api.createUploadPreset(ObjectUtils.asMap("unsigned", true, "folder", "folder", "transformation", EXPLICIT_TRANSFORMATION, "tags", tags, "context",
562563
context));
563564
String name = result.get("name").toString();
564565
Map preset = api.uploadPreset(name, ObjectUtils.emptyMap());

cloudinary-test-common/src/main/java/com/cloudinary/test/MockableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class MockableTest {
1313

1414
public static final String SRC_TEST_IMAGE = "../cloudinary-test-common/src/main/resources/old_logo.png";
1515
public static final String REMOTE_TEST_IMAGE = "http://cloudinary.com/images/old_logo.png";
16-
protected static final int SUFFIX = new Random().nextInt(99999);
16+
protected static final String SUFFIX = String.valueOf(new Random().nextInt(99999));
1717
protected static final String SDK_TEST_TAG = "cloudinary_java_test_" + SUFFIX;
1818
protected static final String uniqueTag = SDK_TEST_TAG + (new java.util.Date().getTime());
1919
protected Cloudinary cloudinary;

0 commit comments

Comments
 (0)