diff --git a/.travis.yml b/.travis.yml index a1e91f8e..72169c8a 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 -DCLOUDINARY_URL=$CLOUDINARY_URL -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 -DCLOUDINARY_URL=$CLOUDINARY_URL -DCLOUDINARY_ACCOUNT_URL=$CLOUDINARY_ACCOUNT_URL ciTest -p cloudinary-${MODULE} -i diff --git a/build.gradle b/build.gradle index ae4b253b..4a3b9f77 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,5 @@ +import groovy.json.JsonSlurper + allprojects { repositories { @@ -6,4 +8,37 @@ allprojects { } project.ext.set("publishGroupId", group) +} + +tasks.create('createTestSubAccount') { + doFirst { + println("Task createTestSubAccount called with module $moduleName") + + 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" + } + + } + + 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 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)));