com.cloudinary.test.AbstractSearchTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cloudinary-test-common Show documentation
Show all versions of cloudinary-test-common Show documentation
Cloudinary is a cloud service that offers a solution to a web application's entire image management pipeline. Upload images to the cloud. Automatically perform smart image resizing, cropping and conversion without installing any complex software. Integrate Facebook or Twitter profile image extraction in a snap, in any dimension and style to match your websiteâs graphics requirements. Images are seamlessly delivered through a fast CDN, and much much more. This Java library allows to easily integrate with Cloudinary in Java applications.
package com.cloudinary.test;
import com.cloudinary.Cloudinary;
import com.cloudinary.utils.ObjectUtils;
import org.junit.*;
import org.junit.rules.TestName;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assume.assumeNotNull;
@SuppressWarnings({"rawtypes", "unchecked", "JavaDoc"})
abstract public class AbstractSearchTest extends MockableTest {
@Rule
public TestName currentTest = new TestName();
private static final String SEARCH_TAG = "search_test_tag_" + SUFFIX;
public static final String[] UPLOAD_TAGS = {SDK_TEST_TAG, SEARCH_TAG};
private static final String SEARCH_TEST = "search_test_" + SUFFIX;
private static final String SEARCH_TEST_1 = SEARCH_TEST + "_1";
private static final String SEARCH_TEST_2 = SEARCH_TEST + "_2";
@BeforeClass
public static void setUpClass() throws Exception {
Cloudinary cloudinary = new Cloudinary();
Map options = ObjectUtils.asMap("public_id", SEARCH_TEST, "tags", UPLOAD_TAGS, "context", "stage=in_review");
cloudinary.api().deleteResourcesByTag(SEARCH_TAG, null);
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
options = ObjectUtils.asMap("public_id", SEARCH_TEST_1, "tags", UPLOAD_TAGS, "context", "stage=new");
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
options = ObjectUtils.asMap("public_id", SEARCH_TEST_2, "tags", UPLOAD_TAGS, "context", "stage=validated");
cloudinary.uploader().upload(SRC_TEST_IMAGE, options);
try {
Thread.sleep(5000); //wait for search indexing
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@AfterClass
public static void tearDownClass() throws Exception {
Cloudinary cloudinary = new Cloudinary();
cloudinary.api().deleteResourcesByTag(SEARCH_TAG, null);
}
@Before
public void setUp() {
System.out.println("Running " + this.getClass().getName() + "." + currentTest.getMethodName());
this.cloudinary = new Cloudinary();
assumeNotNull(cloudinary.config.apiSecret);
}
@Test
public void shouldFindResourcesByTag() throws Exception {
Map result = cloudinary.search().expression(String.format("tags:%s", SEARCH_TAG)).execute();
List