use of ch.cyberduck.core.onedrive.features.GraphTouchFeature in project cyberduck by iterate-ch.
the class GraphReadFeatureTest method testReadInterrupt.
@Test
public void testReadInterrupt() throws Exception {
final Path drive = new OneDriveHomeFinderService().find();
final Path test = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
new GraphTouchFeature(session, fileid).touch(test, new TransferStatus());
// Unknown length in status
final TransferStatus status = new TransferStatus();
// Read a single byte
{
final InputStream in = new GraphReadFeature(session, fileid).read(test, status, new DisabledConnectionCallback());
assertNotNull(in.read());
in.close();
}
{
final InputStream in = new GraphReadFeature(session, fileid).read(test, status, new DisabledConnectionCallback());
assertNotNull(in);
in.close();
}
new GraphDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.onedrive.features.GraphTouchFeature in project cyberduck by iterate-ch.
the class GraphReadFeatureTest method testReadRange.
@Test
public void testReadRange() throws Exception {
final Path drive = new OneDriveHomeFinderService().find();
final Path test = new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
new GraphTouchFeature(session, fileid).touch(test, new TransferStatus());
final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
final byte[] content = RandomUtils.nextBytes(1000);
final OutputStream out = local.getOutputStream(false);
assertNotNull(out);
IOUtils.write(content, out);
out.close();
new DefaultUploadFeature<>(new GraphWriteFeature(session, fileid)).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
final TransferStatus status = new TransferStatus();
status.setLength(content.length);
status.setAppend(true);
status.setOffset(100L);
final GraphReadFeature read = new GraphReadFeature(session, fileid);
assertTrue(read.offset(test));
final InputStream in = read.read(test, status.withLength(content.length - 100), new DisabledConnectionCallback());
assertNotNull(in);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100);
new StreamCopier(status, status).transfer(in, buffer);
final byte[] reference = new byte[content.length - 100];
System.arraycopy(content, 100, reference, 0, content.length - 100);
assertArrayEquals(reference, buffer.toByteArray());
in.close();
new GraphDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.onedrive.features.GraphTouchFeature in project cyberduck by iterate-ch.
the class GraphAttributesFinderFeatureTest method testFindFile.
@Test
public void testFindFile() throws Exception {
final Path file = new Path(new OneDriveHomeFinderService().find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
new GraphTouchFeature(session, fileid).touch(file, new TransferStatus().withMime("x-application/cyberduck"));
final PathAttributes attributes = new GraphAttributesFinderFeature(session, fileid).find(file);
assertNotNull(attributes);
assertNotEquals(-1L, attributes.getSize());
assertNotEquals(-1L, attributes.getCreationDate());
assertNotEquals(-1L, attributes.getModificationDate());
assertNotNull(attributes.getETag());
assertNull(attributes.getVersionId());
assertNotNull(attributes.getLink());
assertNotNull(attributes.getFileId());
new GraphDeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.onedrive.features.GraphTouchFeature in project cyberduck by iterate-ch.
the class GraphAttributesFinderFeatureTest method testChangedFileId.
@Test
public void testChangedFileId() throws Exception {
final GraphFileIdProvider fileid = new GraphFileIdProvider(session);
final Path drive = new OneDriveHomeFinderService().find();
final Path test = new GraphTouchFeature(session, fileid).touch(new Path(drive, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
final String previousnodeid = test.attributes().getFileId();
new GraphDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
final String latestnodeid = new GraphTouchFeature(session, fileid).touch(new Path(drive, test.getName(), EnumSet.of(Path.Type.file)), new TransferStatus()).attributes().getFileId();
assertNotNull(latestnodeid);
// Assume previously seen but changed on server
fileid.cache(test, previousnodeid);
final GraphAttributesFinderFeature f = new GraphAttributesFinderFeature(session, fileid);
assertEquals(latestnodeid, f.find(test).getFileId());
new GraphDeleteFeature(session, fileid).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.onedrive.features.GraphTouchFeature in project cyberduck by iterate-ch.
the class GraphCopyFeatureTest method testCopyToExistingFile.
@Test
public void testCopyToExistingFile() throws Exception {
final Path folder = new GraphDirectoryFeature(session, fileid).mkdir(new Path(new OneDriveHomeFinderService().find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
final Path test = new GraphTouchFeature(session, fileid).touch(new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
final Path copy = new GraphTouchFeature(session, fileid).touch(new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
new GraphCopyFeature(session, fileid).copy(test, copy, new TransferStatus().exists(true), new DisabledConnectionCallback(), new DisabledStreamListener());
final Find find = new DefaultFindFeature(session);
assertTrue(find.find(test));
assertTrue(find.find(copy));
new GraphDeleteFeature(session, fileid).delete(Arrays.asList(test, copy), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Aggregations