public class BlobScaleTest extends BaseServiceTest<AbstractCommonList> {
private final Logger logger = LoggerFactory.getLogger(BlobScaleTest.class);
-
+
private static final int IMAGE_SIZE = 1000;
private static final int IMAGE_EDGE = -15;
private static final int MIN_FONTSIZE = 15;
private List<String> allGeneratedImages = new ArrayList<String>();
private static Random generator = new Random(System.currentTimeMillis());
-
+
@Override
protected CollectionSpaceClient getClientInstance() throws Exception {
return new BlobClient();
private int getImagesToCreate() {
int result = DEFAULT_IMAGES_TO_CREATE;
-
+
String imagesToCreate = System.getProperty(IMAGES_TO_CREATE_PROP);
try {
result = Integer.parseInt(imagesToCreate);
+ result
+ " images.");
}
-
+
return result;
}
-
+
@Test(dataProvider = "testName", dependsOnMethods = {"scaleTest"})
public void scaleGETTest(String testName) throws Exception {
this.setupRead();
BlobClient client = new BlobClient();
-
+
// We seem to sometimes need a delay before Nuxeo finishes creating all the derivatives, so
// we'll put our thread to sleep for 3 seconds before checking
Thread.sleep(3000); // sleep for 3 seconds
-
+
for (int i = 0; i < allGeneratedImages.size(); i++) {
Response res = client.getDerivativeContent(allGeneratedImages.get(i), "Thumbnail");
try {
assertStatusCode(res, testName);
- logger.debug(String.format("Performed GET operation on Thumbnail derivative of image blob ID = '%s'.",
+ logger.debug(String.format("Performed GET operation on Thumbnail derivative of image blob ID = '%s'.",
allGeneratedImages.get(i)));
} finally {
res.close();
}
- }
+ }
}
-
+
@Test(dataProvider = "testName")
public void scaleTest(String testName) throws Exception {
this.createDirectory(GENERATED_IMAGES);
int imagesToCreate = getImagesToCreate();
BlobClient client = new BlobClient();
Profiler profiler = new Profiler(this, 1);
-
+
for (int i = 0; i < imagesToCreate; i++, profiler.reset()) {
- File jpegFile = createJpeg(GENERATED_IMAGES);
+ File jpegFile = createJpeg(GENERATED_IMAGES);
URL url = jpegFile.toURI().toURL();
-
+
profiler.start();
- Response res = client.createBlobFromURI("http://farm6.static.flickr.com/5289/5688023100_15e00cde47_o.jpg");//url.toString());
+ Response res = client.createBlobFromURI("https://farm6.static.flickr.com/5289/5688023100_15e00cde47_o.jpg");//url.toString());
try {
profiler.stop();
assertStatusCode(res, testName);
+ " - "
+ " : "
+ jpegFile.getAbsolutePath());
-
+
String csid = extractId(res);
this.knownResourceId = csid;
allResourceIdsCreated.add(csid);
}
}
}
-
+
private void createDirectory(String dirName) {
boolean success = (
new File(dirName)).mkdir();
if (success) {
- logger.debug("Directory: "
+ logger.debug("Directory: "
+ dirName + " created");
- }
+ }
}
-
+
public File createJpeg(String destDir) {
File result = null;
- BufferedImage image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_RGB);
+ BufferedImage image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
for (int i = 0; i < IMAGE_SIZE; i = i + 10) {
int x = random(IMAGE_EDGE, IMAGE_SIZE);
random(MIN_FONTSIZE, MAX_FONTSIZE));
g.setFont(newFont);
}
- try {
+ try {
ImageIO.write(image, "jpg", result = new File(destDir
+ File.separator
+ System.currentTimeMillis()
+ ".jpg"));
- } catch (IOException e) {
- e.printStackTrace();
- }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
return result;
}
private final String CLASS_NAME = BlobServiceTest.class.getName();
private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
-
+
private final static String KNOWN_IMAGE_FILENAME = "01-03-09_1546.jpg";
private final static int WIDTH_DIMENSION_INDEX = 0;
private final static int HEIGHT_DIMENSION_INDEX = 1;
-
+
private final static String KNOWN_IMAGE_SIZE = "56261";
private final static BigDecimal KNOWN_IMAGE_WIDTH = new BigDecimal(640.0);
private final static BigDecimal KNOWN_IMAGE_HEIGHT = new BigDecimal(480.0);
-
- private final static String PUBLIC_URL_BIRD = "http://farm6.static.flickr.com/5289/5688023100_15e00cde47_o.jpg";
- private final static String PUBLIC_URL_DECK = "http://farm8.staticflickr.com/7231/6962564226_4bdfc17599_k_d.jpg";
-
-
+
+ private final static String PUBLIC_URL_BIRD = "https://farm6.static.flickr.com/5289/5688023100_15e00cde47_o.jpg";
+ private final static String PUBLIC_URL_DECK = "https://farm8.staticflickr.com/7231/6962564226_4bdfc17599_k_d.jpg";
+
+
private boolean blobCleanup = true;
@Override
protected String getServiceName() {
return BlobClient.SERVICE_NAME;
}
-
+
@Override
protected CollectionSpaceClient getClientInstance() throws Exception {
return new BlobClient();
this.blobCleanup = false;
}
}
-
+
private boolean isBlobCleanup() {
return blobCleanup;
}
-
+
/**
* Looks in the .../src/test/resources/blobs directory for files from which to create Blob
* instances.
protected void createBlob(String testName, boolean fromUri, String uri) throws Exception {
setupCreate();
BlobClient client = new BlobClient();
-
+
String currentDir = this.getResourceDir();
String blobsDirPath = currentDir + File.separator + BLOBS_DIR;
File blobsDir = new File(blobsDirPath);
logger.debug("Directory: " + blobsDirPath + " is missing or cannot be read.");
}
}
-
+
/*
* For a known image file, make sure we're getting back the correct metadata about it.
*/
@Test(dataProvider = "testName", dependsOnMethods = {"createBlobWithURI"})
public void testImageDimensions(String testName) throws Exception {
setupCreate();
-
+
String currentDir = this.getResourceDir();
String blobsDirPath = currentDir
+ File.separator + BLOBS_DIR + File.separator + KNOWN_IMAGE_FILENAME;
res = client.createBlobFromURI(uri);
String blobCsid = null;
try {
- assertStatusCode(res, testName);
+ assertStatusCode(res, testName);
blobCsid = extractId(res);
if (isBlobCleanup() == true) {
allResourceIdsCreated.add(blobCsid);
readResponse.close();
}
}
-
+
Assert.assertEquals(blobsCommon.getLength(), KNOWN_IMAGE_SIZE, "The known image blob was not the expected size of " + KNOWN_IMAGE_SIZE);
-
+
MeasuredPartGroup measuredImagePart = blobsCommon.getMeasuredPartGroupList().getMeasuredPartGroup().get(0);
Assert.assertEquals(measuredImagePart.getMeasuredPart(), BlobClient.IMAGE_MEASURED_PART_LABEL, "First measured part of the image blob was not the image itself.");
-
+
List<DimensionSubGroup> dimensionSubGroupList = measuredImagePart.getDimensionSubGroupList().getDimensionSubGroup();
DimensionSubGroup widthDimension = dimensionSubGroupList.get(WIDTH_DIMENSION_INDEX);
Assert.assertEquals(widthDimension.getDimension(), BlobClient.IMAGE_WIDTH_LABEL, "First dimension item of the image blob was not the width.");
Assert.assertTrue(widthDimension.getValue().compareTo(KNOWN_IMAGE_WIDTH) == 0);
-
+
DimensionSubGroup heightDimension = dimensionSubGroupList.get(HEIGHT_DIMENSION_INDEX);
Assert.assertEquals(heightDimension.getDimension(), BlobClient.IMAGE_HEIGHT_LABEL, "Second dimension item of the image blob was not the height.");
Assert.assertTrue(heightDimension.getValue().compareTo(KNOWN_IMAGE_HEIGHT) == 0);
}
-
+
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"CRUDTests"})
public void createBlobWithURI(String testName) throws Exception {
createBlob(testName, true /*with URI*/, null);
}
-
+
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"CRUDTests"})
public void createBlobWithURL1(String testName) throws Exception {
createBlob(testName, true /*with URI*/, PUBLIC_URL_BIRD);
- }
-
+ }
+
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"CRUDTests"})
public void createBlobWithURL2(String testName) throws Exception {
createBlob(testName, true /*with URI*/, PUBLIC_URL_DECK);
- }
-
+ }
+
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"createBlobWithURI"})
public void createBlobWithPost(String testName) throws Exception {
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
-
+
@Override
protected PoxPayloadOut createInstance(String identifier) throws Exception {
return createBlobInstance(identifier);
- }
-
+ }
+
private PoxPayloadOut createBlobInstance(String exitNumber) throws Exception {
BlobClient client = new BlobClient();
String identifier = "blobNumber-" + exitNumber;
@Override
@Test(dataProvider = "testName",
dependsOnMethods = {
- "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
+ "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
public void CRUDTests(String testName) {
// Do nothing. Simply here to for a TestNG execution order for our tests
}
@Override
protected BlobsCommon updateInstance(BlobsCommon blobsCommon) {
BlobsCommon result = new BlobsCommon();
-
+
result.setName("updated-" + blobsCommon.getName());
-
+
return result;
}