use of ch.cyberduck.core.features.AttributesFinder in project cyberduck by iterate-ch.
the class MantaMoveFeatureTest method testMoveRename.
@Test
public void testMoveRename() throws BackgroundException {
final Directory directory = new MantaDirectoryFeature(session);
final Touch touch = new MantaTouchFeature(session);
final Move move = new MantaMoveFeature(session);
final Delete delete = new MantaDeleteFeature(session);
final AttributesFinder attributesFinder = new MantaAttributesFinderFeature(session);
final Path drive = new MantaDirectoryFeature(session).mkdir(randomDirectory(), new TransferStatus());
Path targetDirectory = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
directory.mkdir(targetDirectory, null);
assertNotNull(attributesFinder.find(targetDirectory));
Path touchedFile = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
touch.touch(touchedFile, new TransferStatus().withMime("x-application/cyberduck"));
assertNotNull(attributesFinder.find(touchedFile));
Path rename = new Path(targetDirectory, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
assertTrue(move.isSupported(touchedFile, rename));
assertEquals(rename, move.move(touchedFile, rename, new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback()));
assertNotNull(attributesFinder.find(rename));
assertFalse(new MantaFindFeature(session).find(touchedFile));
assertTrue(new MantaFindFeature(session).find(rename));
delete.delete(Collections.singletonList(targetDirectory), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.features.AttributesFinder in project cyberduck by iterate-ch.
the class GraphMoveFeatureTest method testMove.
@Test
public void testMove() throws BackgroundException {
final Directory directory = new GraphDirectoryFeature(session, fileid);
final Touch touch = new GraphTouchFeature(session, fileid);
final Move move = new GraphMoveFeature(session, fileid);
final Delete delete = new GraphDeleteFeature(session, fileid);
final AttributesFinder attributesFinder = new GraphAttributesFinderFeature(session, fileid);
final Path drive = new OneDriveHomeFinderService().find();
Path targetDirectory = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
directory.mkdir(targetDirectory, new TransferStatus());
assertNotNull(attributesFinder.find(targetDirectory));
Path touchedFile = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
touch.touch(touchedFile, new TransferStatus().withMime("x-application/cyberduck"));
assertNotNull(attributesFinder.find(touchedFile));
Path rename = new Path(targetDirectory, touchedFile.getName(), EnumSet.of(Path.Type.file));
assertTrue(move.isSupported(touchedFile, rename));
move.move(touchedFile, rename, new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());
assertNotNull(attributesFinder.find(rename));
delete.delete(Collections.singletonList(targetDirectory), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.features.AttributesFinder in project cyberduck by iterate-ch.
the class GraphMoveFeatureTest method testRename.
@Test
public void testRename() throws BackgroundException {
final Touch touch = new GraphTouchFeature(session, fileid);
final Move move = new GraphMoveFeature(session, fileid);
final Delete delete = new GraphDeleteFeature(session, fileid);
final AttributesFinder attributesFinder = new GraphAttributesFinderFeature(session, fileid);
final Path drive = new OneDriveHomeFinderService().find();
final Path file = touch.touch(new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus().withMime("x-application/cyberduck"));
final PathAttributes attributes = attributesFinder.find(file);
assertNotNull(attributes);
assertEquals(file.attributes().getFileId(), attributes.getFileId());
Path rename = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
assertTrue(move.isSupported(file, rename));
final TransferStatus status = new TransferStatus().exists(true);
final Path target = move.move(file, rename, status, new Delete.DisabledCallback(), new DisabledConnectionCallback());
assertEquals(attributes.getFileId(), target.attributes().getFileId());
assertEquals(attributes, attributesFinder.find(rename));
delete.delete(Collections.singletonList(rename), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.features.AttributesFinder in project cyberduck by iterate-ch.
the class CachingAttributesFinderFeatureTest method testDefaultAttributes.
@Test
public void testDefaultAttributes() throws Exception {
final PathCache cache = new PathCache(1);
final AttributesFinder f = new CachingAttributesFinderFeature(cache, new DefaultAttributesFinderFeature(session));
final String name = new AlphanumericRandomStringService().random();
final Path bucket = new Path("versioning-test-us-east-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Path file = new S3TouchFeature(session).touch(new Path(bucket, name, EnumSet.of(Path.Type.file)), new TransferStatus());
final String initialVersion = file.attributes().getVersionId();
assertNotNull(initialVersion);
final PathAttributes lookup = f.find(file);
assertNotSame(file.attributes(), lookup);
assertEquals(0L, lookup.getSize());
// Test with no specific version id
assertSame(lookup, f.find(new Path(file).withAttributes(PathAttributes.EMPTY)));
// Test cache
assertEquals(0L, new CachingAttributesFinderFeature(cache, new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
fail("Expected cache hit");
return PathAttributes.EMPTY;
}
}).find(file).getSize());
// Test wrong type
try {
f.find(new Path(bucket, name, EnumSet.of(Path.Type.directory)));
fail();
} catch (NotfoundException e) {
// Expected
}
// Overwrite with new version
final TransferStatus status = new TransferStatus();
final byte[] content = RandomUtils.nextBytes(12);
status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
status.setLength(content.length);
final HttpResponseOutputStream<StorageObject> out = new S3WriteFeature(session).write(file, status, new DisabledConnectionCallback());
IOUtils.copy(new ByteArrayInputStream(content), out);
out.close();
assertEquals(initialVersion, f.find(file.withAttributes(new PathAttributes(file.attributes()).withVersionId(initialVersion))).getVersionId());
final String newVersion = ((S3Object) out.getStatus()).getVersionId();
try {
f.find(file.withAttributes(new PathAttributes(file.attributes()).withVersionId(newVersion)));
fail();
} catch (NotfoundException e) {
// Expected
}
cache.clear();
assertEquals(newVersion, f.find(file.withAttributes(new PathAttributes(file.attributes()).withVersionId(newVersion))).getVersionId());
assertEquals(newVersion, f.find(file.withAttributes(PathAttributes.EMPTY)).getVersionId());
assertNotEquals(initialVersion, f.find(file.withAttributes(new PathAttributes(file.attributes()).withVersionId(newVersion))).getVersionId());
assertEquals(new S3AttributesAdapter().toAttributes(out.getStatus()).getVersionId(), f.find(file).getVersionId());
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
use of ch.cyberduck.core.features.AttributesFinder in project cyberduck by iterate-ch.
the class CachingAttributesFinderFeatureTest method testNotFound.
@Test(expected = NotfoundException.class)
public void testNotFound() throws Exception {
final PathCache cache = new PathCache(1);
final CachingAttributesFinderFeature f = new CachingAttributesFinderFeature(cache, new DefaultAttributesFinderFeature(session));
final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
f.find(test);
// Test cache
new CachingAttributesFinderFeature(cache, new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
fail("Expected cache hit");
return PathAttributes.EMPTY;
}
}).find(test);
}
Aggregations