Skip to content

Commit 75c9e74

Browse files
authored
Use automatically generated test accounts in tests. (#214)
1 parent 7a45624 commit 75c9e74

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ branches:
2626
except:
2727
- staging-test
2828

29-
# ciTest is configured to skip the various timeout tests that don't work in travis
30-
script: ./gradlew clean -DCLOUDINARY_URL=$CLOUDINARY_URL -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i
29+
before_script: ./gradlew createTestSubAccount -PmoduleName=${MODULE}
3130

31+
# ciTest is configured to skip the various timeout tests that don't work in travis
32+
script: source tools/cloudinary_url.txt && ./gradlew -DCLOUDINARY_URL=$CLOUDINARY_URL -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i

build.gradle

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import groovy.json.JsonSlurper
2+
13
allprojects {
24

35
repositories {
@@ -6,4 +8,37 @@ allprojects {
68
}
79

810
project.ext.set("publishGroupId", group)
11+
}
12+
13+
tasks.create('createTestSubAccount') {
14+
doFirst {
15+
println("Task createTestSubAccount called with module $moduleName")
16+
17+
def cloudinaryUrl = ""
18+
19+
// core does not use test clouds, skip (keep empty file for a more readable generic travis test script)
20+
if (moduleName != "core") {
21+
println "Creating test cloud..."
22+
def baseUrl = new URL('https://sub-account-testing.cloudinary.com/create_sub_account')
23+
def connection = baseUrl.openConnection()
24+
connection.with {
25+
doOutput = true
26+
requestMethod = 'POST'
27+
def json = new JsonSlurper().parseText(content.text)
28+
def cloud = json["payload"]["cloudName"]
29+
def key = json["payload"]["cloudApiKey"]
30+
def secret = json["payload"]["cloudApiSecret"]
31+
cloudinaryUrl = "CLOUDINARY_URL=cloudinary://$key:$secret@$cloud"
32+
}
33+
34+
}
35+
36+
def dir = new File("${projectDir.path}${File.separator}tools")
37+
dir.mkdir()
38+
def file = new File(dir, "cloudinary_url.txt")
39+
file.createNewFile()
40+
file.text = cloudinaryUrl
41+
42+
println("Test sub-account created succesfully!")
43+
}
944
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
public abstract class AbstractStructuredMetadataTest extends MockableTest {
1919
private static final String METADATA_UPLOADER_TAG = SDK_TEST_TAG + "_uploader";
20-
20+
private static final String PUBLIC_ID = "before_class_public_id" + SUFFIX;
2121
protected Api api;
2222
public static final List<String> metadataFieldExternalIds = new ArrayList<String>();
2323

@@ -27,6 +27,8 @@ public static void setUpClass() throws IOException {
2727
if (cloudinary.config.apiSecret == null) {
2828
System.err.println("Please setup environment for Upload test to run");
2929
}
30+
31+
cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("public_id", PUBLIC_ID));
3032
}
3133

3234
@AfterClass
@@ -221,25 +223,25 @@ public void testUploaderUpdateMetadata() throws Exception {
221223
StringMetadataField field = newFieldInstance("testUploaderUpdateMetadata");
222224
ApiResponse fieldResult = addFieldToAccount(field);
223225
String fieldId = fieldResult.get("external_id").toString();
224-
Map result = cloudinary.uploader().updateMetadata(Collections.<String, Object>singletonMap(fieldId, "123456"), new String[]{"sample"}, null);
226+
Map result = cloudinary.uploader().updateMetadata(Collections.<String, Object>singletonMap(fieldId, "123456"), new String[]{PUBLIC_ID}, null);
225227
assertNotNull(result);
226-
assertEquals("sample", ((List) result.get("public_ids")).get(0).toString());
228+
assertEquals(PUBLIC_ID, ((List) result.get("public_ids")).get(0).toString());
227229
}
228230

229231
@Test
230232
public void testSetField() throws Exception {
231233
SetMetadataField field = createSetField("test123");
232234
ApiResponse fieldResult = addFieldToAccount(field);
233235
String fieldId = fieldResult.get("external_id").toString();
234-
Map result = cloudinary.uploader().updateMetadata(asMap(fieldId, new String[]{"id2", "id3"}), new String[]{"sample"}, null);
236+
Map result = cloudinary.uploader().updateMetadata(asMap(fieldId, new String[]{"id2", "id3"}), new String[]{PUBLIC_ID}, null);
235237
assertNotNull(result);
236-
assertEquals("sample", ((List) result.get("public_ids")).get(0).toString());
238+
assertEquals(PUBLIC_ID, ((List) result.get("public_ids")).get(0).toString());
237239
List<String> list = new ArrayList<String>(2);
238240
list.add("id1");
239241
list.add("id2");
240-
result = cloudinary.uploader().updateMetadata(asMap(fieldId, list), new String[]{"sample"}, null);
242+
result = cloudinary.uploader().updateMetadata(asMap(fieldId, list), new String[]{PUBLIC_ID}, null);
241243
assertNotNull(result);
242-
assertEquals("sample", ((List) result.get("public_ids")).get(0).toString());
244+
assertEquals(PUBLIC_ID, ((List) result.get("public_ids")).get(0).toString());
243245
}
244246
// Metadata test helpers
245247
private SetMetadataField createSetField(String labelPrefix) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ abstract public class AbstractUploaderTest extends MockableTest {
3131
public static final int SRC_TEST_IMAGE_W = 241;
3232
public static final int SRC_TEST_IMAGE_H = 51;
3333
private static Map<String, Set<String>> toDelete = new HashMap<String, Set<String>>();
34-
public static final String SRC_FULLY_QUALIFIED_IMAGE="image/upload/sample";
34+
private static final String UPLOADER_TEST_PUBLIC_ID = "uploader_test";
35+
public static final String SRC_FULLY_QUALIFIED_IMAGE="image/upload/" + UPLOADER_TEST_PUBLIC_ID;
3536
public static final String SRC_FULLY_QUALIFIED_VIDEO="video/upload/dog";
3637

3738
@BeforeClass
@@ -42,6 +43,7 @@ public static void setUpClass() throws IOException {
4243
}
4344

4445
cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG, ARCHIVE_TAG}));
46+
cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG}, "public_id", UPLOADER_TEST_PUBLIC_ID, "transformation", "f_jpg"));
4547
cloudinary.uploader().upload(SRC_TEST_VIDEO, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG, ARCHIVE_TAG}, "public_id", "dog", "resource_type", "video"));
4648
cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG, ARCHIVE_TAG}, "resource_type", "raw"));
4749
cloudinary.uploader().upload(SRC_TEST_IMAGE,
@@ -225,8 +227,8 @@ public void testUniqueFilename() throws Exception {
225227

226228
@Test
227229
public void testExplicit() throws IOException {
228-
Map result = cloudinary.uploader().explicit("sample", asMap("eager", Collections.singletonList(new Transformation().crop("scale").width(2.0)), "type", "upload", "moderation", "manual"));
229-
String url = cloudinary.url().transformation(new Transformation().crop("scale").width(2.0)).format("jpg").version(result.get("version")).generate("sample");
230+
Map result = cloudinary.uploader().explicit(UPLOADER_TEST_PUBLIC_ID, asMap("eager", Collections.singletonList(new Transformation().crop("scale").width(2.0)), "type", "upload", "moderation", "manual"));
231+
String url = cloudinary.url().transformation(new Transformation().crop("scale").width(2.0)).format("jpg").version(result.get("version")).generate(UPLOADER_TEST_PUBLIC_ID);
230232
String eagerUrl = (String) ((Map) ((List) result.get("eager")).get(0)).get("url");
231233
String cloudName = cloudinary.config.cloudName;
232234
assertEquals(eagerUrl.substring(eagerUrl.indexOf(cloudName)), url.substring(url.indexOf(cloudName)));

0 commit comments

Comments
 (0)