use of org.apache.commons.vfs2.provider.VfsComponentContext in project big-data-plugin by pentaho.
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, BUCKET_NAME, "", FileType.FOLDER);
S3KettleProperty s3KettleProperty = mock(S3KettleProperty.class);
when(s3KettleProperty.getPartSize()).thenReturn("5MB");
S3FileSystem fileSystem = new S3FileSystem(rootFileName, new FileSystemOptions(), new StorageUnitConverter(), s3KettleProperty);
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);
}
use of org.apache.commons.vfs2.provider.VfsComponentContext in project big-data-plugin by pentaho.
the class S3NFileNameParserTest method testParseUri.
@Test
public void testParseUri() throws Exception {
VfsComponentContext context = mock(VfsComponentContext.class);
FileName fileName = mock(FileName.class);
String uri = "s3n://bucket/file";
FileName noBaseFile = parser.parseUri(context, null, uri);
assertNotNull(noBaseFile);
assertEquals("bucket", ((S3NFileName) noBaseFile).getBucketId());
FileName withBaseFile = parser.parseUri(context, fileName, uri);
assertNotNull(withBaseFile);
assertEquals("bucket", ((S3NFileName) withBaseFile).getBucketId());
// assumption is that the whole URL is valid until it comes time to resolve to S3 objects
uri = "s3n://s3n/bucket/file";
withBaseFile = parser.parseUri(context, fileName, uri);
assertEquals("s3n", ((S3NFileName) withBaseFile).getBucketId());
// with credentials
uri = "s3n://ThiSiSA+PossibleAcce/ssK3y:PossiblES3cre+K3y@s3n/bucket/file";
withBaseFile = parser.parseUri(context, fileName, uri);
assertEquals("ThiSiSA+PossibleAcce/ssK3y:PossiblES3cre+K3y@s3n", ((S3NFileName) withBaseFile).getBucketId());
}
use of org.apache.commons.vfs2.provider.VfsComponentContext in project big-data-plugin by pentaho.
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());
// with credentials
uri = "s3://ThiSiSA+PossibleAcce/ssK3y:PossiblES3cre+K3y@s3/bucket/file";
withBaseFile = parser.parseUri(context, fileName, uri);
assertEquals("ThiSiSA+PossibleAcce/ssK3y:PossiblES3cre+K3y@s3", ((S3FileName) withBaseFile).getBucketId());
}
use of org.apache.commons.vfs2.provider.VfsComponentContext in project wso2-synapse by wso2.
the class MockFileNameParser method parseUri.
public FileName parseUri(VfsComponentContext context, FileName base, String filename) throws FileSystemException {
StringBuilder name = new StringBuilder();
String scheme = UriParser.extractScheme(filename.split("\\?")[0], name);
if (scheme == null) {
scheme = "test";
}
UriParser.canonicalizePath(name, 0, name.length(), this);
UriParser.fixSeparators(name);
String rootFile = this.extractRootPrefix(filename, name);
FileType fileType = UriParser.normalisePath(name);
String path = name.toString();
return new MockFileName(scheme, "", path, fileType);
}
use of org.apache.commons.vfs2.provider.VfsComponentContext in project commons-vfs by apache.
the class SmbFileNameParser method parseUri.
@Override
public FileName parseUri(final VfsComponentContext context, final FileName base, final String filename) throws FileSystemException {
final StringBuilder name = new StringBuilder();
// Extract the scheme and authority parts
final Authority auth = extractToPath(context, filename, name);
// extract domain
String username = auth.getUserName();
final String domain = extractDomain(username);
if (domain != null) {
username = username.substring(domain.length() + 1);
}
// Decode and adjust separators
UriParser.canonicalizePath(name, 0, name.length(), this);
UriParser.fixSeparators(name);
// Extract the share
final String share = UriParser.extractFirstElement(name);
if (share == null || share.isEmpty()) {
throw new FileSystemException("vfs.provider.smb/missing-share-name.error", filename);
}
// Normalise the path. Do this after extracting the share name,
// to deal with things like smb://hostname/share/..
final FileType fileType = UriParser.normalisePath(name);
final String path = name.toString();
return new SmbFileName(auth.getScheme(), auth.getHostName(), auth.getPort(), username, auth.getPassword(), domain, share, path, fileType);
}
Aggregations