Search in sources :

Example 16 with AttributesFinder

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());
}
Also used : Delete(ch.cyberduck.core.features.Delete) Path(ch.cyberduck.core.Path) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) Touch(ch.cyberduck.core.features.Touch) Move(ch.cyberduck.core.features.Move) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Directory(ch.cyberduck.core.features.Directory) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 17 with AttributesFinder

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());
}
Also used : Delete(ch.cyberduck.core.features.Delete) Path(ch.cyberduck.core.Path) GraphAttributesFinderFeature(ch.cyberduck.core.onedrive.features.GraphAttributesFinderFeature) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) GraphMoveFeature(ch.cyberduck.core.onedrive.features.GraphMoveFeature) Touch(ch.cyberduck.core.features.Touch) GraphTouchFeature(ch.cyberduck.core.onedrive.features.GraphTouchFeature) GraphDirectoryFeature(ch.cyberduck.core.onedrive.features.GraphDirectoryFeature) Move(ch.cyberduck.core.features.Move) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) GraphDeleteFeature(ch.cyberduck.core.onedrive.features.GraphDeleteFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Directory(ch.cyberduck.core.features.Directory) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 18 with AttributesFinder

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());
}
Also used : Delete(ch.cyberduck.core.features.Delete) Path(ch.cyberduck.core.Path) GraphAttributesFinderFeature(ch.cyberduck.core.onedrive.features.GraphAttributesFinderFeature) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) GraphMoveFeature(ch.cyberduck.core.onedrive.features.GraphMoveFeature) PathAttributes(ch.cyberduck.core.PathAttributes) Touch(ch.cyberduck.core.features.Touch) GraphTouchFeature(ch.cyberduck.core.onedrive.features.GraphTouchFeature) Move(ch.cyberduck.core.features.Move) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) GraphDeleteFeature(ch.cyberduck.core.onedrive.features.GraphDeleteFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 19 with AttributesFinder

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();
}
Also used : Delete(ch.cyberduck.core.features.Delete) S3TouchFeature(ch.cyberduck.core.s3.S3TouchFeature) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) S3AttributesAdapter(ch.cyberduck.core.s3.S3AttributesAdapter) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) S3Object(org.jets3t.service.model.S3Object) PathCache(ch.cyberduck.core.PathCache) Path(ch.cyberduck.core.Path) NotfoundException(ch.cyberduck.core.exception.NotfoundException) StorageObject(org.jets3t.service.model.StorageObject) S3DefaultDeleteFeature(ch.cyberduck.core.s3.S3DefaultDeleteFeature) PathAttributes(ch.cyberduck.core.PathAttributes) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) S3WriteFeature(ch.cyberduck.core.s3.S3WriteFeature) SHA256ChecksumCompute(ch.cyberduck.core.io.SHA256ChecksumCompute) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) AbstractS3Test(ch.cyberduck.core.s3.AbstractS3Test) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 20 with AttributesFinder

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);
}
Also used : PathCache(ch.cyberduck.core.PathCache) Path(ch.cyberduck.core.Path) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) ListProgressListener(ch.cyberduck.core.ListProgressListener) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDAVTest(ch.cyberduck.core.dav.AbstractDAVTest)

Aggregations

AttributesFinder (ch.cyberduck.core.features.AttributesFinder)28 Test (org.junit.Test)23 Path (ch.cyberduck.core.Path)22 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)18 PathAttributes (ch.cyberduck.core.PathAttributes)15 Delete (ch.cyberduck.core.features.Delete)15 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)14 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)14 IntegrationTest (ch.cyberduck.test.IntegrationTest)14 ListProgressListener (ch.cyberduck.core.ListProgressListener)11 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)10 Find (ch.cyberduck.core.features.Find)10 Move (ch.cyberduck.core.features.Move)10 Host (ch.cyberduck.core.Host)9 NullLocal (ch.cyberduck.core.NullLocal)8 NullSession (ch.cyberduck.core.NullSession)8 TestProtocol (ch.cyberduck.core.TestProtocol)8 Touch (ch.cyberduck.core.features.Touch)7 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6