use of org.apache.hop.vfs.s3.s3.vfs.S3FileName in project hop by apache.
the class S3FileNameParserTest method testParseUri.
@Test
public void testParseUri() throws Exception {
VfsComponentContext context = mock(VfsComponentContext.class);
FileName fileName = mock(FileName.class);
String uri = "s3://bucket/file";
FileName noBaseFile = parser.parseUri(context, null, uri);
assertNotNull(noBaseFile);
assertEquals("bucket", ((S3FileName) noBaseFile).getBucketId());
FileName withBaseFile = parser.parseUri(context, fileName, uri);
assertNotNull(withBaseFile);
assertEquals("bucket", ((S3FileName) withBaseFile).getBucketId());
// assumption is that the whole URL is valid until it comes time to resolve to S3 objects
uri = "s3://s3/bucket/file";
withBaseFile = parser.parseUri(context, fileName, uri);
assertEquals("s3", ((S3FileName) withBaseFile).getBucketId());
}
use of org.apache.hop.vfs.s3.s3.vfs.S3FileName in project hop by apache.
the class S3FileNameTest method testAppendRootUriWithNonDefaultPort.
@Test
public void testAppendRootUriWithNonDefaultPort() {
String fooFolder = "FooFolder";
String fooBucket = "FooBucket";
fileName = new S3FileName(SCHEME, DELIMITER, fooFolder, FileType.FOLDER);
String expectedUri = SCHEME + SCHEME_DELIMITER + fooFolder;
assertEquals(expectedUri, fileName.getURI());
fileName = new S3FileName(SCHEME, fooBucket, fooBucket + DELIMITER + fooFolder, FileType.FOLDER);
expectedUri = SCHEME + SCHEME_DELIMITER + fooBucket + DELIMITER + fooFolder;
assertEquals(expectedUri, fileName.getURI());
}
use of org.apache.hop.vfs.s3.s3.vfs.S3FileName in project hop by apache.
the class S3FileObjectTest method testDoRename.
@Test
public void testDoRename() throws Exception {
String someNewBucketName = "someNewBucketName";
String someNewKey = "some/newKey";
S3FileName newFileName = new S3FileName(SCHEME, someNewBucketName, someNewBucketName + "/" + someNewKey, FileType.FILE);
S3FileObject newFile = new S3FileObject(newFileName, fileSystemSpy);
ArgumentCaptor<CopyObjectRequest> copyObjectRequestArgumentCaptor = ArgumentCaptor.forClass(CopyObjectRequest.class);
when(s3ServiceMock.doesBucketExistV2(someNewBucketName)).thenReturn(true);
s3FileObjectFileSpy.doAttach();
s3FileObjectFileSpy.moveTo(newFile);
verify(s3ServiceMock).copyObject(copyObjectRequestArgumentCaptor.capture());
assertEquals(someNewBucketName, copyObjectRequestArgumentCaptor.getValue().getDestinationBucketName());
assertEquals(someNewKey, copyObjectRequestArgumentCaptor.getValue().getDestinationKey());
assertEquals(BUCKET_NAME, copyObjectRequestArgumentCaptor.getValue().getSourceBucketName());
assertEquals(origKey, copyObjectRequestArgumentCaptor.getValue().getSourceKey());
}
use of org.apache.hop.vfs.s3.s3.vfs.S3FileName in project hop by apache.
the class S3FileObjectTest method testDoCreateFolder.
@Test
public void testDoCreateFolder() throws Exception {
S3FileObject notRootBucket = spy(new S3FileObject(new S3FileName(SCHEME, BUCKET_NAME, BUCKET_NAME + "/" + origKey, FileType.IMAGINARY), fileSystemSpy));
notRootBucket.createFolder();
ArgumentCaptor<PutObjectRequest> putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class);
verify(s3ServiceMock).putObject(putObjectRequestArgumentCaptor.capture());
assertEquals(BUCKET_NAME, putObjectRequestArgumentCaptor.getValue().getBucketName());
assertEquals("some/key/", putObjectRequestArgumentCaptor.getValue().getKey());
}
use of org.apache.hop.vfs.s3.s3.vfs.S3FileName in project hop by apache.
the class S3FileObjectTest method setUp.
@Before
public void setUp() throws Exception {
s3ServiceMock = mock(AmazonS3.class);
S3Object s3Object = new S3Object();
s3Object.setKey(OBJECT_NAME);
s3Object.setBucketName(BUCKET_NAME);
filename = new S3FileName(SCHEME, BUCKET_NAME, BUCKET_NAME, FileType.FOLDER);
S3FileName rootFileName = new S3FileName(SCHEME, "", "", FileType.FOLDER);
S3HopProperty s3HopProperty = mock(S3HopProperty.class);
when(s3HopProperty.getPartSize()).thenReturn("5MB");
S3FileSystem fileSystem = new S3FileSystem(rootFileName, new FileSystemOptions(), new StorageUnitConverter(), s3HopProperty);
fileSystemSpy = spy(fileSystem);
VfsComponentContext context = mock(VfsComponentContext.class);
final DefaultFileSystemManager fsm = new DefaultFileSystemManager();
FilesCache cache = mock(FilesCache.class);
fsm.setFilesCache(cache);
fsm.setCacheStrategy(CacheStrategy.ON_RESOLVE);
when(context.getFileSystemManager()).thenReturn(fsm);
fileSystemSpy.setContext(context);
S3FileObject s3FileObject = new S3FileObject(filename, fileSystemSpy);
s3FileObjectBucketSpy = spy(s3FileObject);
s3FileObjectFileSpy = spy(new S3FileObject(new S3FileName(SCHEME, BUCKET_NAME, BUCKET_NAME + "/" + origKey, FileType.IMAGINARY), fileSystemSpy));
S3FileObject s3FileObjectRoot = new S3FileObject(rootFileName, fileSystemSpy);
s3FileObjectSpyRoot = spy(s3FileObjectRoot);
// specify the behaviour of S3 Service
// when( s3ServiceMock.getBucket( BUCKET_NAME ) ).thenReturn( testBucket );
when(s3ServiceMock.getObject(BUCKET_NAME, OBJECT_NAME)).thenReturn(s3Object);
when(s3ServiceMock.getObject(BUCKET_NAME, OBJECT_NAME)).thenReturn(s3Object);
when(s3ServiceMock.listBuckets()).thenReturn(createBuckets());
when(s3ServiceMock.doesBucketExistV2(BUCKET_NAME)).thenReturn(true);
childObjectListing = mock(ObjectListing.class);
when(childObjectListing.getObjectSummaries()).thenReturn(createObjectSummaries(0)).thenReturn(new ArrayList<>());
when(childObjectListing.getCommonPrefixes()).thenReturn(new ArrayList<>()).thenReturn(createCommonPrefixes(3));
when(childObjectListing.isTruncated()).thenReturn(true).thenReturn(false);
when(s3ServiceMock.listObjects(any(ListObjectsRequest.class))).thenReturn(childObjectListing);
when(s3ServiceMock.listObjects(anyString(), anyString())).thenReturn(childObjectListing);
when(s3ServiceMock.listNextBatchOfObjects(any(ObjectListing.class))).thenReturn(childObjectListing);
s3ObjectMock = mock(S3Object.class);
s3ObjectInputStream = mock(S3ObjectInputStream.class);
s3ObjectMetadata = mock(ObjectMetadata.class);
when(s3ObjectMock.getObjectContent()).thenReturn(s3ObjectInputStream);
when(s3ServiceMock.getObjectMetadata(anyString(), anyString())).thenReturn(s3ObjectMetadata);
when(s3ObjectMetadata.getContentLength()).thenReturn(contentLength);
when(s3ObjectMetadata.getLastModified()).thenReturn(testDate);
when(s3ServiceMock.getObject(anyString(), anyString())).thenReturn(s3ObjectMock);
when(fileSystemSpy.getS3Client()).thenReturn(s3ServiceMock);
}
Aggregations