use of org.apache.hop.vfs.s3.s3n.vfs.S3NFileName in project hop by apache.
the class S3NFileObjectTest 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 S3NFileName(SCHEME, BUCKET_NAME, "/" + BUCKET_NAME, FileType.FOLDER);
S3NFileName rootFileName = new S3NFileName(SCHEME, BUCKET_NAME, "", FileType.FOLDER);
S3NFileSystem fileSystem = new S3NFileSystem(rootFileName, new FileSystemOptions());
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);
S3NFileObject s3FileObject = new S3NFileObject(filename, fileSystemSpy);
s3FileObjectBucketSpy = spy(s3FileObject);
s3FileObjectFileSpy = spy(new S3NFileObject(new S3NFileName(SCHEME, BUCKET_NAME, "/" + BUCKET_NAME + "/" + origKey, FileType.IMAGINARY), fileSystemSpy));
S3NFileObject s3FileObjectRoot = new S3NFileObject(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