Search in sources :

Example 1 with DisabledFileWatcherListener

use of ch.cyberduck.core.local.DisabledFileWatcherListener in project cyberduck by iterate-ch.

the class DefaultWatchEditorTest method testEditNullApplication.

@Test(expected = IOException.class)
public void testEditNullApplication() throws Exception {
    final DefaultWatchEditor editor = new DefaultWatchEditor(new Host(new TestProtocol()), new Path("/remote", EnumSet.of(Path.Type.file)), new DisabledListProgressListener());
    final Local local = new DefaultTemporaryFileService().create("remote");
    new DefaultLocalTouchFeature().touch(local);
    final Path file = new Path("/remote.txt", EnumSet.of(Path.Type.file));
    editor.edit(EditorFactory.getEditor(file.getName()), file, local, new DisabledFileWatcherListener());
}
Also used : Path(ch.cyberduck.core.Path) DefaultLocalTouchFeature(ch.cyberduck.core.local.DefaultLocalTouchFeature) TestProtocol(ch.cyberduck.core.TestProtocol) DefaultTemporaryFileService(ch.cyberduck.core.local.DefaultTemporaryFileService) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DisabledFileWatcherListener(ch.cyberduck.core.local.DisabledFileWatcherListener) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) Test(org.junit.Test)

Example 2 with DisabledFileWatcherListener

use of ch.cyberduck.core.local.DisabledFileWatcherListener in project cyberduck by iterate-ch.

the class DefaultWatchEditorTest method testEditNullApplicationNoFile.

@Test(expected = IOException.class)
public void testEditNullApplicationNoFile() throws Exception {
    final DefaultWatchEditor editor = new DefaultWatchEditor(new Host(new TestProtocol()), new Path("/remote", EnumSet.of(Path.Type.file)), new DisabledListProgressListener());
    final Path file = new Path("/remote", EnumSet.of(Path.Type.file));
    editor.edit(EditorFactory.getEditor(file.getName()), file, new DefaultTemporaryFileService().create("remote"), new DisabledFileWatcherListener());
}
Also used : Path(ch.cyberduck.core.Path) TestProtocol(ch.cyberduck.core.TestProtocol) DefaultTemporaryFileService(ch.cyberduck.core.local.DefaultTemporaryFileService) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DisabledFileWatcherListener(ch.cyberduck.core.local.DisabledFileWatcherListener) Host(ch.cyberduck.core.Host) Test(org.junit.Test)

Example 3 with DisabledFileWatcherListener

use of ch.cyberduck.core.local.DisabledFileWatcherListener in project cyberduck by iterate-ch.

the class DefaultWatchEditorTest method testNotfound.

@Test(expected = NoSuchFileException.class)
public void testNotfound() throws Exception {
    final DefaultWatchEditor editor = new DefaultWatchEditor(new Host(new TestProtocol()), new Path("/remote", EnumSet.of(Path.Type.file)), new DisabledListProgressListener());
    editor.watch(new Application("com.app"), new Local(System.getProperty("java.io.tmpdir") + "/notfound", UUID.randomUUID().toString()), new DisabledFileWatcherListener(), new DisabledApplicationQuitCallback());
}
Also used : Path(ch.cyberduck.core.Path) TestProtocol(ch.cyberduck.core.TestProtocol) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DisabledFileWatcherListener(ch.cyberduck.core.local.DisabledFileWatcherListener) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) Application(ch.cyberduck.core.local.Application) DisabledApplicationQuitCallback(ch.cyberduck.core.local.DisabledApplicationQuitCallback) Test(org.junit.Test)

Example 4 with DisabledFileWatcherListener

use of ch.cyberduck.core.local.DisabledFileWatcherListener in project cyberduck by iterate-ch.

the class NIOEventWatchServiceTest method testListenerEventWatchServiceWindows.

@Test
public void testListenerEventWatchServiceWindows() throws Exception {
    assumeTrue(Factory.Platform.getDefault().equals(Factory.Platform.Name.windows));
    final FileWatcher watcher = new FileWatcher(new NIOEventWatchService());
    final Local file = LocalFactory.get(LocalFactory.get(System.getProperty("java.io.tmpdir")), String.format("é%s", new AlphanumericRandomStringService().random()));
    final CountDownLatch update = new CountDownLatch(1);
    final CountDownLatch delete = new CountDownLatch(1);
    final FileWatcherListener listener = new DisabledFileWatcherListener() {

        @Override
        public void fileWritten(final Local file) {
            try {
                assertEquals(new File(file.getAbsolute()).getCanonicalPath(), new File(file.getAbsolute()).getCanonicalPath());
            } catch (IOException e) {
                fail();
            }
            update.countDown();
        }

        @Override
        public void fileDeleted(final Local file) {
            try {
                assertEquals(new File(file.getAbsolute()).getCanonicalPath(), new File(file.getAbsolute()).getCanonicalPath());
            } catch (IOException e) {
                fail();
            }
            delete.countDown();
        }
    };
    LocalTouchFactory.get().touch(file);
    assertTrue(watcher.register(file.getParent(), new FileWatcher.DefaultFileFilter(file), listener).await(1, TimeUnit.SECONDS));
    final ProcessBuilder sh = new ProcessBuilder("cmd", "/c", String.format("echo 'Test' >> %s", file.getAbsolute()));
    final Process cat = sh.start();
    assertTrue(cat.waitFor(5L, TimeUnit.SECONDS));
    assertTrue(update.await(5L, TimeUnit.SECONDS));
    file.delete();
    assertTrue(delete.await(5L, TimeUnit.SECONDS));
    watcher.close();
}
Also used : FileWatcher(ch.cyberduck.core.local.FileWatcher) FileWatcherListener(ch.cyberduck.core.local.FileWatcherListener) DisabledFileWatcherListener(ch.cyberduck.core.local.DisabledFileWatcherListener) DisabledFileWatcherListener(ch.cyberduck.core.local.DisabledFileWatcherListener) Local(ch.cyberduck.core.Local) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) Test(org.junit.Test)

Example 5 with DisabledFileWatcherListener

use of ch.cyberduck.core.local.DisabledFileWatcherListener in project cyberduck by iterate-ch.

the class FSEventWatchServiceTest method testListener.

@Test
@Ignore
public void testListener() throws Exception {
    final FileWatcher watcher = new FileWatcher(new FSEventWatchService());
    final Local file = LocalFactory.get(LocalFactory.get(System.getProperty("java.io.tmpdir")), String.format("é%s", new AlphanumericRandomStringService().random()));
    final CountDownLatch update = new CountDownLatch(1);
    final CountDownLatch delete = new CountDownLatch(1);
    final FileWatcherListener listener = new DisabledFileWatcherListener() {

        @Override
        public void fileWritten(final Local file) {
            try {
                assertEquals(new File(file.getAbsolute()).getCanonicalPath(), new File(file.getAbsolute()).getCanonicalPath());
            } catch (IOException e) {
                fail();
            }
            update.countDown();
        }

        @Override
        public void fileDeleted(final Local file) {
            try {
                assertEquals(new File(file.getAbsolute()).getCanonicalPath(), new File(file.getAbsolute()).getCanonicalPath());
            } catch (IOException e) {
                fail();
            }
            delete.countDown();
        }
    };
    LocalTouchFactory.get().touch(file);
    assertTrue(file.exists());
    assertTrue(watcher.register(file.getParent(), new FileWatcher.DefaultFileFilter(file), listener).await(1, TimeUnit.SECONDS));
    final ProcessBuilder sh = new ProcessBuilder("sh", "-c", String.format("echo 'Test' >> %s", file.getAbsolute()));
    final Process cat = sh.start();
    assertTrue(cat.waitFor(5L, TimeUnit.SECONDS));
    assertTrue(update.await(5L, TimeUnit.SECONDS));
    file.delete();
    assertTrue(delete.await(5L, TimeUnit.SECONDS));
    watcher.close();
}
Also used : FileWatcher(ch.cyberduck.core.local.FileWatcher) FileWatcherListener(ch.cyberduck.core.local.FileWatcherListener) DisabledFileWatcherListener(ch.cyberduck.core.local.DisabledFileWatcherListener) DisabledFileWatcherListener(ch.cyberduck.core.local.DisabledFileWatcherListener) Local(ch.cyberduck.core.Local) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DisabledFileWatcherListener (ch.cyberduck.core.local.DisabledFileWatcherListener)9 Test (org.junit.Test)9 Local (ch.cyberduck.core.Local)8 FileWatcher (ch.cyberduck.core.local.FileWatcher)5 Host (ch.cyberduck.core.Host)4 Path (ch.cyberduck.core.Path)4 TestProtocol (ch.cyberduck.core.TestProtocol)4 FileWatcherListener (ch.cyberduck.core.local.FileWatcherListener)4 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)3 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)3 DefaultTemporaryFileService (ch.cyberduck.core.local.DefaultTemporaryFileService)3 File (java.io.File)3 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Application (ch.cyberduck.core.local.Application)2 DisabledApplicationQuitCallback (ch.cyberduck.core.local.DisabledApplicationQuitCallback)2 ConnectionCallback (ch.cyberduck.core.ConnectionCallback)1 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)1 NullSession (ch.cyberduck.core.NullSession)1 NullTransferSession (ch.cyberduck.core.NullTransferSession)1