Search in sources :

Example 1 with S3NFileName

use of org.apache.hop.vfs.s3.s3n.vfs.S3NFileName in project hop by apache.

the class S3NFileObjectTest method testDoCreateFolder.

@Test
public void testDoCreateFolder() throws Exception {
    S3NFileObject notRootBucket = spy(new S3NFileObject(new S3NFileName(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());
}
Also used : S3NFileObject(org.apache.hop.vfs.s3.s3n.vfs.S3NFileObject) S3NFileName(org.apache.hop.vfs.s3.s3n.vfs.S3NFileName) Test(org.junit.Test)

Example 2 with S3NFileName

use of org.apache.hop.vfs.s3.s3n.vfs.S3NFileName in project hop by apache.

the class S3NFileSystemTest method setUp.

@Before
public void setUp() throws Exception {
    fileName = new S3NFileName(S3FileNameTest.SCHEME, "/", "", FileType.FOLDER);
    fileSystem = new S3NFileSystem(fileName, new FileSystemOptions());
}
Also used : S3NFileSystem(org.apache.hop.vfs.s3.s3n.vfs.S3NFileSystem) S3NFileName(org.apache.hop.vfs.s3.s3n.vfs.S3NFileName) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Before(org.junit.Before)

Example 3 with S3NFileName

use of org.apache.hop.vfs.s3.s3n.vfs.S3NFileName in project hop by apache.

the class S3NFileObjectTest method testDoRename.

@Test
public void testDoRename() throws Exception {
    String someNewBucketName = "someNewBucketName";
    String someNewKey = "some/newKey";
    S3NFileName newFileName = new S3NFileName(SCHEME, someNewBucketName, "/" + someNewBucketName + "/" + someNewKey, FileType.FILE);
    S3NFileObject newFile = new S3NFileObject(newFileName, fileSystemSpy);
    ArgumentCaptor<CopyObjectRequest> copyObjectRequestArgumentCaptor = ArgumentCaptor.forClass(CopyObjectRequest.class);
    when(s3ServiceMock.doesBucketExistV2(someNewBucketName)).thenReturn(true);
    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());
}
Also used : S3NFileName(org.apache.hop.vfs.s3.s3n.vfs.S3NFileName) S3NFileObject(org.apache.hop.vfs.s3.s3n.vfs.S3NFileObject) Test(org.junit.Test)

Example 4 with S3NFileName

use of org.apache.hop.vfs.s3.s3n.vfs.S3NFileName in project hop by apache.

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());
}
Also used : VfsComponentContext(org.apache.commons.vfs2.provider.VfsComponentContext) FileName(org.apache.commons.vfs2.FileName) S3NFileName(org.apache.hop.vfs.s3.s3n.vfs.S3NFileName) Test(org.junit.Test)

Example 5 with S3NFileName

use of org.apache.hop.vfs.s3.s3n.vfs.S3NFileName in project hop by apache.

the class S3NFileNameTest method testAppendRootUriWithNonDefaultPort.

@Test
public void testAppendRootUriWithNonDefaultPort() {
    fileName = new S3NFileName(SCHEME, "", "FooFolder", FileType.FOLDER);
    String expectedUri = SCHEME + "://" + "FooFolder";
    assertEquals(expectedUri, fileName.getURI());
    fileName = new S3NFileName(SCHEME, "FooBucket", "/FooBucket/FooFolder", FileType.FOLDER);
    expectedUri = SCHEME + "://FooBucket/FooBucket/" + "FooFolder";
    assertEquals(expectedUri, fileName.getURI());
}
Also used : S3NFileName(org.apache.hop.vfs.s3.s3n.vfs.S3NFileName) Test(org.junit.Test)

Aggregations

S3NFileName (org.apache.hop.vfs.s3.s3n.vfs.S3NFileName)6 Test (org.junit.Test)4 S3NFileObject (org.apache.hop.vfs.s3.s3n.vfs.S3NFileObject)3 VfsComponentContext (org.apache.commons.vfs2.provider.VfsComponentContext)2 S3NFileSystem (org.apache.hop.vfs.s3.s3n.vfs.S3NFileSystem)2 Before (org.junit.Before)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 ArrayList (java.util.ArrayList)1 FileName (org.apache.commons.vfs2.FileName)1 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)1 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)1