use of org.jets3t.service.model.S3Object in project pentaho-kettle by pentaho.
the class S3ObjectsProviderTest method setUp.
@Before
public void setUp() throws Exception {
bucket2Objects = generateTestS3ObjectsInBucket(BUCKET2, false);
bucket3Objects = generateTestS3ObjectsInBucket(BUCKET3, true);
testObject = new S3Object(BUCKET1, "tests3Object", "TestString");
s3serviceMock = getS3ServiceMock(testUserCredentials);
provider = new S3ObjectsProvider(s3serviceMock);
}
use of org.jets3t.service.model.S3Object in project tutorials by eugenp.
the class JetS3tLiveTest method whenFileMoved_NewInstanceIsSame.
@Test
public void whenFileMoved_NewInstanceIsSame() throws Exception {
// get a bucket
S3Bucket bucket = createBucket();
assertNotNull(bucket);
// create another bucket
S3Bucket tgtBucket = s3Service.createBucket(TgtBucket);
// Put a binary file
S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
s3Service.putObject(BucketName, fileObject);
// Copy it
s3Service.moveObject(BucketName, "test.jpg", TgtBucket, new S3Object("spidey.jpg"), false);
// Download
S3Object newFileObject = s3Service.getObject(TgtBucket, "spidey.jpg");
// Save to a different name
File newFile = new File("src/test/resources/spidey.jpg");
Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
// Get hashes and compare
String origMD5 = getFileMD5("src/test/resources/test.jpg");
String newMD5 = getFileMD5("src/test/resources/spidey.jpg");
assertTrue(origMD5.equals(newMD5));
// Clean up
deleteBucket();
s3Service.deleteObject(TgtBucket, "spidey.jpg");
s3Service.deleteBucket(TgtBucket);
}
use of org.jets3t.service.model.S3Object in project tutorials by eugenp.
the class JetS3tLiveTest method whenFileRenamed_NewNameIsSame.
@Test
public void whenFileRenamed_NewNameIsSame() throws Exception {
// get a bucket
S3Bucket bucket = createBucket();
assertNotNull(bucket);
// Put a binary file
S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
s3Service.putObject(BucketName, fileObject);
// Copy it
s3Service.renameObject(BucketName, "test.jpg", new S3Object("spidey.jpg"));
// Download
S3Object newFileObject = s3Service.getObject(BucketName, "spidey.jpg");
// Save to a different name
File newFile = new File("src/test/resources/spidey.jpg");
Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
// Get hashes and compare
String origMD5 = getFileMD5("src/test/resources/test.jpg");
String newMD5 = getFileMD5("src/test/resources/spidey.jpg");
assertTrue(origMD5.equals(newMD5));
// Clean up
deleteObject("test.jpg");
deleteObject("spidey.jpg");
deleteBucket();
}
use of org.jets3t.service.model.S3Object in project tutorials by eugenp.
the class JetS3tLiveTest method whenFileCopied_CopyIsSame.
@Test
public void whenFileCopied_CopyIsSame() throws Exception {
// get a bucket
S3Bucket bucket = createBucket();
assertNotNull(bucket);
// Put a binary file
S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
s3Service.putObject(BucketName, fileObject);
// Copy it
S3Object targetObject = new S3Object("testcopy.jpg");
s3Service.copyObject(BucketName, "test.jpg", BucketName, targetObject, false);
// Download
S3Object newFileObject = s3Service.getObject(BucketName, "testcopy.jpg");
// Save to a different name
File newFile = new File("src/test/resources/testcopy.jpg");
Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
// Get hashes and compare
String origMD5 = getFileMD5("src/test/resources/test.jpg");
String newMD5 = getFileMD5("src/test/resources/testcopy.jpg");
assertTrue(origMD5.equals(newMD5));
// Clean up
deleteObject("test.jpg");
deleteObject("testcopy.jpg");
deleteBucket();
}
use of org.jets3t.service.model.S3Object in project tutorials by eugenp.
the class JetS3tLiveTest method givenStreamDataUploaded_StreamDataIsDownloaded.
@Test
public void givenStreamDataUploaded_StreamDataIsDownloaded() throws Exception {
// get a bucket
S3Bucket bucket = createBucket();
assertNotNull(bucket);
// Create a stream
ByteArrayInputStream testStream = new ByteArrayInputStream("test stream".getBytes());
// Create and populate object
S3Object streamObject = new S3Object("stream");
streamObject.setDataInputStream(testStream);
streamObject.setContentLength(testStream.available());
streamObject.setContentType("text/plain");
// Put it
s3Service.putObject(BucketName, streamObject);
// Get it
S3Object newStreamObject = s3Service.getObject(BucketName, "stream");
// Convert back to string
String testString = new BufferedReader(new InputStreamReader(newStreamObject.getDataInputStream())).lines().collect(Collectors.joining("\n"));
assertTrue("test stream".equals(testString));
// Clean up
deleteObject("stream");
deleteBucket();
}
Aggregations