From b70a9bb94b5fc3f9aac1c00773119d75bba9c96f Mon Sep 17 00:00:00 2001 From: Nitzan Jaitman Date: Thu, 4 Jun 2020 12:28:16 +0300 Subject: [PATCH 1/6] Add `createTestCloud` task for use in travis. --- .travis.yml | 2 +- build.gradle | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a1e91f8e..4be9bdc1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,5 +27,5 @@ branches: - staging-test # ciTest is configured to skip the various timeout tests that don't work in travis -script: ./gradlew clean -DCLOUDINARY_URL=$CLOUDINARY_URL -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i +script: ./gradlew clean createTestCloud -P${MODULE} -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i diff --git a/build.gradle b/build.gradle index ae4b253b..c70fc025 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import groovy.json.JsonSlurper + allprojects { repositories { @@ -6,4 +8,32 @@ allprojects { } project.ext.set("publishGroupId", group) +} + +task createTestCloud { + println("Task CreateTestCloud called with module $moduleName") + + // core does not use test clouds, skip + if (moduleName == "core") { + println "Skipping test cloud creation..." + return + } + + println "Creating test cloud..." + def baseUrl = new URL('https://sub-account-testing.cloudinary.com/create_sub_account') + def connection = baseUrl.openConnection() + connection.with { + + doOutput = true + requestMethod = 'POST' + def json = new JsonSlurper().parseText(content.text) + def cloud = json["payload"]["cloudName"] + def key = json["payload"]["cloudApiKey"] + def secret = json["payload"]["cloudApiSecret"] + def cloudinaryUrl = "cloudinary://$key:$secret@$cloud" + + System.setProperty("CLOUDINARY_URL", cloudinaryUrl) + + println("Test cloud created succesfully!") + } } \ No newline at end of file From e0459d5e7e17806081e169857685fbe13c2fc958 Mon Sep 17 00:00:00 2001 From: Nitzan Jaitman Date: Thu, 4 Jun 2020 12:40:27 +0300 Subject: [PATCH 2/6] Fix `createTestCloud` task --- build.gradle | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index c70fc025..ffb810ea 100644 --- a/build.gradle +++ b/build.gradle @@ -10,30 +10,32 @@ allprojects { project.ext.set("publishGroupId", group) } -task createTestCloud { - println("Task CreateTestCloud called with module $moduleName") - - // core does not use test clouds, skip - if (moduleName == "core") { - println "Skipping test cloud creation..." - return - } - - println "Creating test cloud..." - def baseUrl = new URL('https://sub-account-testing.cloudinary.com/create_sub_account') - def connection = baseUrl.openConnection() - connection.with { - - doOutput = true - requestMethod = 'POST' - def json = new JsonSlurper().parseText(content.text) - def cloud = json["payload"]["cloudName"] - def key = json["payload"]["cloudApiKey"] - def secret = json["payload"]["cloudApiSecret"] - def cloudinaryUrl = "cloudinary://$key:$secret@$cloud" - - System.setProperty("CLOUDINARY_URL", cloudinaryUrl) - - println("Test cloud created succesfully!") +tasks.create('createTestCloud') { + doFirst { + println("Task CreateTestCloud called with module $moduleName") + + // core does not use test clouds, skip + if (moduleName == "core") { + println "Skipping test cloud creation..." + return + } + + println "Creating test cloud..." + def baseUrl = new URL('https://sub-account-testing.cloudinary.com/create_sub_account') + def connection = baseUrl.openConnection() + connection.with { + + doOutput = true + requestMethod = 'POST' + def json = new JsonSlurper().parseText(content.text) + def cloud = json["payload"]["cloudName"] + def key = json["payload"]["cloudApiKey"] + def secret = json["payload"]["cloudApiSecret"] + def cloudinaryUrl = "cloudinary://$key:$secret@$cloud" + + System.setProperty("CLOUDINARY_URL", cloudinaryUrl) + + println("Test cloud created succesfully!") + } } } \ No newline at end of file From 055d31a7e22421ada43c939664daff90e34d47f0 Mon Sep 17 00:00:00 2001 From: Nitzan Jaitman Date: Thu, 4 Jun 2020 12:56:37 +0300 Subject: [PATCH 3/6] Attach `createTestCloud` task to each project and fix travis script. --- .travis.yml | 2 +- build.gradle | 54 ++++++++++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4be9bdc1..81632fc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,5 +27,5 @@ branches: - staging-test # ciTest is configured to skip the various timeout tests that don't work in travis -script: ./gradlew clean createTestCloud -P${MODULE} -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i +script: ./gradlew clean createTestCloud -PmoduleName=${MODULE} -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i diff --git a/build.gradle b/build.gradle index ffb810ea..3b349ff6 100644 --- a/build.gradle +++ b/build.gradle @@ -8,34 +8,34 @@ allprojects { } project.ext.set("publishGroupId", group) -} -tasks.create('createTestCloud') { - doFirst { - println("Task CreateTestCloud called with module $moduleName") - - // core does not use test clouds, skip - if (moduleName == "core") { - println "Skipping test cloud creation..." - return - } - - println "Creating test cloud..." - def baseUrl = new URL('https://sub-account-testing.cloudinary.com/create_sub_account') - def connection = baseUrl.openConnection() - connection.with { - - doOutput = true - requestMethod = 'POST' - def json = new JsonSlurper().parseText(content.text) - def cloud = json["payload"]["cloudName"] - def key = json["payload"]["cloudApiKey"] - def secret = json["payload"]["cloudApiSecret"] - def cloudinaryUrl = "cloudinary://$key:$secret@$cloud" - - System.setProperty("CLOUDINARY_URL", cloudinaryUrl) - - println("Test cloud created succesfully!") + tasks.create('createTestCloud') { + doFirst { + println("Task CreateTestCloud called with module $moduleName") + + // core does not use test clouds, skip + if (moduleName == "core") { + println "Skipping test cloud creation..." + return + } + + println "Creating test cloud..." + def baseUrl = new URL('https://sub-account-testing.cloudinary.com/create_sub_account') + def connection = baseUrl.openConnection() + connection.with { + + doOutput = true + requestMethod = 'POST' + def json = new JsonSlurper().parseText(content.text) + def cloud = json["payload"]["cloudName"] + def key = json["payload"]["cloudApiKey"] + def secret = json["payload"]["cloudApiSecret"] + def cloudinaryUrl = "cloudinary://$key:$secret@$cloud" + + System.setProperty("CLOUDINARY_URL", cloudinaryUrl) + + println("Test cloud created succesfully!") + } } } } \ No newline at end of file From ad1ffe342b67495128b76a2b6e6f94d16faea9e5 Mon Sep 17 00:00:00 2001 From: Nitzan Jaitman Date: Thu, 4 Jun 2020 16:15:31 +0300 Subject: [PATCH 4/6] Fix `createTestCloud` task to write a separate file in `before_script` --- .travis.yml | 5 +++-- build.gradle | 59 +++++++++++++++++++++++++++------------------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/.travis.yml b/.travis.yml index 81632fc0..0103c3b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ branches: except: - staging-test -# ciTest is configured to skip the various timeout tests that don't work in travis -script: ./gradlew clean createTestCloud -PmoduleName=${MODULE} -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i +before_script: ./gradlew createTestSubAccount -PmoduleName=${MODULE} +# ciTest is configured to skip the various timeout tests that don't work in travis +script: source tools/cloudinary_url.txt && ./gradlew -PmoduleName=${MODULE} -DCLOUDINARY_URL=$CLOUDINARY_URL -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i diff --git a/build.gradle b/build.gradle index 3b349ff6..85d4edeb 100644 --- a/build.gradle +++ b/build.gradle @@ -8,34 +8,37 @@ allprojects { } project.ext.set("publishGroupId", group) +} - tasks.create('createTestCloud') { - doFirst { - println("Task CreateTestCloud called with module $moduleName") - - // core does not use test clouds, skip - if (moduleName == "core") { - println "Skipping test cloud creation..." - return - } - - println "Creating test cloud..." - def baseUrl = new URL('https://sub-account-testing.cloudinary.com/create_sub_account') - def connection = baseUrl.openConnection() - connection.with { - - doOutput = true - requestMethod = 'POST' - def json = new JsonSlurper().parseText(content.text) - def cloud = json["payload"]["cloudName"] - def key = json["payload"]["cloudApiKey"] - def secret = json["payload"]["cloudApiSecret"] - def cloudinaryUrl = "cloudinary://$key:$secret@$cloud" - - System.setProperty("CLOUDINARY_URL", cloudinaryUrl) - - println("Test cloud created succesfully!") - } +tasks.create('createTestSubAccount') { + doFirst { + println("Task createTestSubAccount called with module $moduleName") + + // core does not use test clouds, skip + if (moduleName == "core") { + println "Skipping test cloud creation..." + return + } + + println "Creating test cloud..." + def baseUrl = new URL('https://sub-account-testing.cloudinary.com/create_sub_account') + def connection = baseUrl.openConnection() + connection.with { + doOutput = true + requestMethod = 'POST' + def json = new JsonSlurper().parseText(content.text) + def cloud = json["payload"]["cloudName"] + def key = json["payload"]["cloudApiKey"] + def secret = json["payload"]["cloudApiSecret"] + def cloudinaryUrl = "CLOUDINARY_URL=cloudinary://$key:$secret@$cloud" + + def dir = new File("${projectDir.path}${File.separator}tools") + dir.mkdir() + def file = new File(dir , "cloudinary_url.txt") + file.createNewFile() + file.text = cloudinaryUrl + + println("Test sub-account created succesfully!") } } -} \ No newline at end of file +} From 4627bd077bc0d2480a1f0aa0358b9d25758a0af0 Mon Sep 17 00:00:00 2001 From: Nitzan Jaitman Date: Thu, 4 Jun 2020 17:02:32 +0300 Subject: [PATCH 5/6] Fix `createTestCloud` for modules that don't need cloud --- .travis.yml | 2 +- build.gradle | 50 +++++++++++++++++++++++++------------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0103c3b2..72169c8a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,4 +29,4 @@ branches: before_script: ./gradlew createTestSubAccount -PmoduleName=${MODULE} # ciTest is configured to skip the various timeout tests that don't work in travis -script: source tools/cloudinary_url.txt && ./gradlew -PmoduleName=${MODULE} -DCLOUDINARY_URL=$CLOUDINARY_URL -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i +script: source tools/cloudinary_url.txt && ./gradlew -DCLOUDINARY_URL=$CLOUDINARY_URL -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i diff --git a/build.gradle b/build.gradle index 85d4edeb..4a3b9f77 100644 --- a/build.gradle +++ b/build.gradle @@ -14,31 +14,31 @@ tasks.create('createTestSubAccount') { doFirst { println("Task createTestSubAccount called with module $moduleName") - // core does not use test clouds, skip - if (moduleName == "core") { - println "Skipping test cloud creation..." - return - } + def cloudinaryUrl = "" + + // core does not use test clouds, skip (keep empty file for a more readable generic travis test script) + if (moduleName != "core") { + println "Creating test cloud..." + def baseUrl = new URL('https://sub-account-testing.cloudinary.com/create_sub_account') + def connection = baseUrl.openConnection() + connection.with { + doOutput = true + requestMethod = 'POST' + def json = new JsonSlurper().parseText(content.text) + def cloud = json["payload"]["cloudName"] + def key = json["payload"]["cloudApiKey"] + def secret = json["payload"]["cloudApiSecret"] + cloudinaryUrl = "CLOUDINARY_URL=cloudinary://$key:$secret@$cloud" + } - println "Creating test cloud..." - def baseUrl = new URL('https://sub-account-testing.cloudinary.com/create_sub_account') - def connection = baseUrl.openConnection() - connection.with { - doOutput = true - requestMethod = 'POST' - def json = new JsonSlurper().parseText(content.text) - def cloud = json["payload"]["cloudName"] - def key = json["payload"]["cloudApiKey"] - def secret = json["payload"]["cloudApiSecret"] - def cloudinaryUrl = "CLOUDINARY_URL=cloudinary://$key:$secret@$cloud" - - def dir = new File("${projectDir.path}${File.separator}tools") - dir.mkdir() - def file = new File(dir , "cloudinary_url.txt") - file.createNewFile() - file.text = cloudinaryUrl - - println("Test sub-account created succesfully!") } + + def dir = new File("${projectDir.path}${File.separator}tools") + dir.mkdir() + def file = new File(dir, "cloudinary_url.txt") + file.createNewFile() + file.text = cloudinaryUrl + + println("Test sub-account created succesfully!") } -} +} \ No newline at end of file From 9c6be884ea506b862389db96dc4d262b38dc6502 Mon Sep 17 00:00:00 2001 From: Nitzan Jaitman Date: Sun, 7 Jun 2020 13:12:44 +0300 Subject: [PATCH 6/6] Use unique upload id instead of relying on an existing `sample` resource in tests. --- .../test/AbstractStructuredMetadataTest.java | 16 +++++++++------- .../cloudinary/test/AbstractUploaderTest.java | 8 +++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractStructuredMetadataTest.java b/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractStructuredMetadataTest.java index 1dac0970..1256545b 100644 --- a/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractStructuredMetadataTest.java +++ b/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractStructuredMetadataTest.java @@ -17,7 +17,7 @@ public abstract class AbstractStructuredMetadataTest extends MockableTest { private static final String METADATA_UPLOADER_TAG = SDK_TEST_TAG + "_uploader"; - + private static final String PUBLIC_ID = "before_class_public_id" + SUFFIX; protected Api api; public static final List metadataFieldExternalIds = new ArrayList(); @@ -27,6 +27,8 @@ public static void setUpClass() throws IOException { if (cloudinary.config.apiSecret == null) { System.err.println("Please setup environment for Upload test to run"); } + + cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("public_id", PUBLIC_ID)); } @AfterClass @@ -221,9 +223,9 @@ public void testUploaderUpdateMetadata() throws Exception { StringMetadataField field = newFieldInstance("testUploaderUpdateMetadata"); ApiResponse fieldResult = addFieldToAccount(field); String fieldId = fieldResult.get("external_id").toString(); - Map result = cloudinary.uploader().updateMetadata(Collections.singletonMap(fieldId, "123456"), new String[]{"sample"}, null); + Map result = cloudinary.uploader().updateMetadata(Collections.singletonMap(fieldId, "123456"), new String[]{PUBLIC_ID}, null); assertNotNull(result); - assertEquals("sample", ((List) result.get("public_ids")).get(0).toString()); + assertEquals(PUBLIC_ID, ((List) result.get("public_ids")).get(0).toString()); } @Test @@ -231,15 +233,15 @@ public void testSetField() throws Exception { SetMetadataField field = createSetField("test123"); ApiResponse fieldResult = addFieldToAccount(field); String fieldId = fieldResult.get("external_id").toString(); - Map result = cloudinary.uploader().updateMetadata(asMap(fieldId, new String[]{"id2", "id3"}), new String[]{"sample"}, null); + Map result = cloudinary.uploader().updateMetadata(asMap(fieldId, new String[]{"id2", "id3"}), new String[]{PUBLIC_ID}, null); assertNotNull(result); - assertEquals("sample", ((List) result.get("public_ids")).get(0).toString()); + assertEquals(PUBLIC_ID, ((List) result.get("public_ids")).get(0).toString()); List list = new ArrayList(2); list.add("id1"); list.add("id2"); - result = cloudinary.uploader().updateMetadata(asMap(fieldId, list), new String[]{"sample"}, null); + result = cloudinary.uploader().updateMetadata(asMap(fieldId, list), new String[]{PUBLIC_ID}, null); assertNotNull(result); - assertEquals("sample", ((List) result.get("public_ids")).get(0).toString()); + assertEquals(PUBLIC_ID, ((List) result.get("public_ids")).get(0).toString()); } // Metadata test helpers private SetMetadataField createSetField(String labelPrefix) { diff --git a/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractUploaderTest.java b/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractUploaderTest.java index b111836b..3b79ba70 100644 --- a/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractUploaderTest.java +++ b/cloudinary-test-common/src/main/java/com/cloudinary/test/AbstractUploaderTest.java @@ -31,7 +31,8 @@ abstract public class AbstractUploaderTest extends MockableTest { public static final int SRC_TEST_IMAGE_W = 241; public static final int SRC_TEST_IMAGE_H = 51; private static Map> toDelete = new HashMap>(); - public static final String SRC_FULLY_QUALIFIED_IMAGE="image/upload/sample"; + private static final String UPLOADER_TEST_PUBLIC_ID = "uploader_test"; + public static final String SRC_FULLY_QUALIFIED_IMAGE="image/upload/" + UPLOADER_TEST_PUBLIC_ID; public static final String SRC_FULLY_QUALIFIED_VIDEO="video/upload/dog"; @BeforeClass @@ -42,6 +43,7 @@ public static void setUpClass() throws IOException { } cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG, ARCHIVE_TAG})); + cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG}, "public_id", UPLOADER_TEST_PUBLIC_ID, "transformation", "f_jpg")); cloudinary.uploader().upload(SRC_TEST_VIDEO, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG, ARCHIVE_TAG}, "public_id", "dog", "resource_type", "video")); cloudinary.uploader().upload(SRC_TEST_IMAGE, asMap("tags", new String[]{SDK_TEST_TAG, UPLOADER_TAG, ARCHIVE_TAG}, "resource_type", "raw")); cloudinary.uploader().upload(SRC_TEST_IMAGE, @@ -224,8 +226,8 @@ public void testUniqueFilename() throws Exception { @Test public void testExplicit() throws IOException { - Map result = cloudinary.uploader().explicit("sample", asMap("eager", Collections.singletonList(new Transformation().crop("scale").width(2.0)), "type", "upload", "moderation", "manual")); - String url = cloudinary.url().transformation(new Transformation().crop("scale").width(2.0)).format("jpg").version(result.get("version")).generate("sample"); + Map result = cloudinary.uploader().explicit(UPLOADER_TEST_PUBLIC_ID, asMap("eager", Collections.singletonList(new Transformation().crop("scale").width(2.0)), "type", "upload", "moderation", "manual")); + String url = cloudinary.url().transformation(new Transformation().crop("scale").width(2.0)).format("jpg").version(result.get("version")).generate(UPLOADER_TEST_PUBLIC_ID); String eagerUrl = (String) ((Map) ((List) result.get("eager")).get(0)).get("url"); String cloudName = cloudinary.config.cloudName; assertEquals(eagerUrl.substring(eagerUrl.indexOf(cloudName)), url.substring(url.indexOf(cloudName)));