Search in sources :

Example 21 with ObservableTask

use of org.cytoscape.work.ObservableTask in project cytoscape-impl by cytoscape.

the class LoadNetworkURLTaskFactoryTest method testObserver.

@Test
public void testObserver() throws Exception {
    URLConnection con = mock(URLConnection.class);
    StreamUtil streamUtil = mock(StreamUtil.class);
    when(streamUtil.getURLConnection(url)).thenReturn(con);
    LoadNetworkURLTaskFactoryImpl factory = new LoadNetworkURLTaskFactoryImpl(serviceRegistrar);
    TaskMonitor taskMonitor = mock(TaskMonitor.class);
    TaskObserver observer = mock(TaskObserver.class);
    TaskIterator iterator = factory.createTaskIterator(url, observer);
    while (iterator.hasNext()) {
        Task t = iterator.next();
        t.run(taskMonitor);
        if (t instanceof ObservableTask)
            observer.taskFinished((ObservableTask) t);
    }
    // This is sort of a stupid verification.  We should actually be testing the results, here....
    verify(observer, times(1)).taskFinished(any(ObservableTask.class));
}
Also used : TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) LoadNetworkURLTaskFactoryImpl(org.cytoscape.task.internal.export.network.LoadNetworkURLTaskFactoryImpl) TaskMonitor(org.cytoscape.work.TaskMonitor) StreamUtil(org.cytoscape.io.util.StreamUtil) URLConnection(java.net.URLConnection) Test(org.junit.Test)

Example 22 with ObservableTask

use of org.cytoscape.work.ObservableTask in project cytoscape-impl by cytoscape.

the class LoadVizmapFileTaskFactoryTest method testObserver.

@Test
public void testObserver() throws Exception {
    VizmapReaderManager vizmapReaderMgr = mock(VizmapReaderManager.class);
    VizmapReader reader = mock(VizmapReader.class);
    when(vizmapReaderMgr.getReader(any(URI.class), any(String.class))).thenReturn(reader);
    VisualMappingManager vmMgr = mock(VisualMappingManager.class);
    SynchronousTaskManager<?> syncTaskManager = mock(SynchronousTaskManager.class);
    SyncTunableMutatorFactory mutatorFactory = new SyncTunableMutatorFactory(new SyncTunableHandlerFactory());
    TunableRecorderManager recorderManager = new TunableRecorderManager();
    TunableSetter tunableSetter = new TunableSetterImpl(mutatorFactory, recorderManager);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(VizmapReaderManager.class)).thenReturn(vizmapReaderMgr);
    when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
    when(serviceRegistrar.getService(SynchronousTaskManager.class)).thenReturn(syncTaskManager);
    when(serviceRegistrar.getService(TunableSetter.class)).thenReturn(tunableSetter);
    LoadVizmapFileTaskFactory factory = new LoadVizmapFileTaskFactoryImpl(serviceRegistrar);
    File file = new File("");
    TaskObserver observer = mock(TaskObserver.class);
    TaskIterator iterator = factory.createTaskIterator(file, observer);
    TaskMonitor taskMonitor = mock(TaskMonitor.class);
    while (iterator.hasNext()) {
        Task t = iterator.next();
        t.run(taskMonitor);
        if (t instanceof ObservableTask)
            observer.taskFinished((ObservableTask) t);
    }
    verify(observer, times(1)).taskFinished(any(ObservableTask.class));
}
Also used : Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) SyncTunableHandlerFactory(org.cytoscape.work.internal.sync.SyncTunableHandlerFactory) VizmapReader(org.cytoscape.io.read.VizmapReader) URI(java.net.URI) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) VizmapReaderManager(org.cytoscape.io.read.VizmapReaderManager) TunableSetter(org.cytoscape.work.TunableSetter) LoadVizmapFileTaskFactory(org.cytoscape.task.read.LoadVizmapFileTaskFactory) TaskObserver(org.cytoscape.work.TaskObserver) ObservableTask(org.cytoscape.work.ObservableTask) TunableRecorderManager(org.cytoscape.work.internal.sync.TunableRecorderManager) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) SyncTunableMutatorFactory(org.cytoscape.work.internal.sync.SyncTunableMutatorFactory) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) TunableSetterImpl(org.cytoscape.work.internal.sync.TunableSetterImpl) File(java.io.File) Test(org.junit.Test)

Aggregations

ObservableTask (org.cytoscape.work.ObservableTask)22 TaskIterator (org.cytoscape.work.TaskIterator)17 TaskObserver (org.cytoscape.work.TaskObserver)16 Task (org.cytoscape.work.Task)13 FinishStatus (org.cytoscape.work.FinishStatus)12 TaskMonitor (org.cytoscape.work.TaskMonitor)11 Test (org.junit.Test)6 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)5 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)4 File (java.io.File)3 CyApplicationManager (org.cytoscape.application.CyApplicationManager)3 NetworkViewTestSupport (org.cytoscape.ding.NetworkViewTestSupport)3 CyGroupManager (org.cytoscape.group.CyGroupManager)3 CyNetwork (org.cytoscape.model.CyNetwork)3 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)3 CyNetworkManager (org.cytoscape.model.CyNetworkManager)3 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)3 CyRootNetworkManagerImpl (org.cytoscape.model.internal.CyRootNetworkManagerImpl)3 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)3 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)3