Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 35 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import groovy.json.JsonSlurper

allprojects {

repositories {
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that writing to a file?
no outputStream blabla is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a groovy's enhancement to java's File class, it's does all the stream operations inside.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? it was soooo elegant in Java 😒


println("Test sub-account created succesfully!")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> metadataFieldExternalIds = new ArrayList<String>();

Expand All @@ -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
Expand Down Expand Up @@ -221,25 +223,25 @@ 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.<String, Object>singletonMap(fieldId, "123456"), new String[]{"sample"}, null);
Map result = cloudinary.uploader().updateMetadata(Collections.<String, Object>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
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<String> list = new ArrayList<String>(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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Set<String>> toDelete = new HashMap<String, Set<String>>();
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
Expand All @@ -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,
Expand Down Expand Up @@ -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)));
Expand Down