use of ch.cyberduck.core.s3.S3SingleUploadService in project cyberduck by iterate-ch.
the class S3SingleUploadServiceTest method testUploadVault.
@Test
public void testUploadVault() throws Exception {
final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
final int length = 5242880;
final byte[] content = RandomUtils.nextBytes(length);
IOUtils.write(content, local.getOutputStream(false));
final TransferStatus writeStatus = new TransferStatus();
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
writeStatus.setLength(content.length);
final BytecountStreamListener count = new BytecountStreamListener();
final CryptoUploadFeature m = new CryptoUploadFeature<>(session, new S3SingleUploadService(session, new S3WriteFeature(session)), new S3WriteFeature(session), cryptomator);
m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), count, writeStatus, null);
assertEquals(content.length, count.getSent());
assertTrue(writeStatus.isComplete());
assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test));
assertEquals(content.length, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(test).getSize());
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final TransferStatus readStatus = new TransferStatus().withLength(content.length);
final InputStream in = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(test, readStatus, new DisabledConnectionCallback());
new StreamCopier(readStatus, readStatus).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
local.delete();
}
Aggregations