Search in sources :

Example 1 with LoadNetworkURLTaskFactoryImpl

use of org.cytoscape.task.internal.export.network.LoadNetworkURLTaskFactoryImpl in project cytoscape-impl by cytoscape.

the class LoadNetworkURLTaskTest method testNullURL.

@Test(expected = NullPointerException.class)
public void testNullURL() throws Exception {
    TaskFactory factory = new LoadNetworkURLTaskFactoryImpl(serviceRegistrar);
    TaskIterator ti = factory.createTaskIterator();
    TaskMonitor tm = mock(TaskMonitor.class);
    boolean first = true;
    while (ti.hasNext()) {
        Task t = ti.next();
        if (first) {
            ((LoadNetworkURLTask) t).url = null;
            first = false;
        }
        t.run(tm);
    }
}
Also used : Task(org.cytoscape.work.Task) LoadNetworkURLTask(org.cytoscape.task.internal.export.network.LoadNetworkURLTask) TaskIterator(org.cytoscape.work.TaskIterator) LoadNetworkURLTaskFactoryImpl(org.cytoscape.task.internal.export.network.LoadNetworkURLTaskFactoryImpl) TaskMonitor(org.cytoscape.work.TaskMonitor) TaskFactory(org.cytoscape.work.TaskFactory) Test(org.junit.Test)

Example 2 with LoadNetworkURLTaskFactoryImpl

use of org.cytoscape.task.internal.export.network.LoadNetworkURLTaskFactoryImpl in project cytoscape-impl by cytoscape.

the class LoadNetworkURLTaskTest method testRun.

@Test
public void testRun() throws Exception {
    TaskFactory factory = new LoadNetworkURLTaskFactoryImpl(serviceRegistrar);
    assertNotNull(netViewManager);
    TaskIterator ti = factory.createTaskIterator();
    TaskMonitor tm = mock(TaskMonitor.class);
    boolean first = true;
    while (ti.hasNext()) {
        Task t = ti.next();
        if (first) {
            ((LoadNetworkURLTask) t).url = url;
            first = false;
        }
        t.run(tm);
    }
    verify(netManager).addNetwork(net, false);
    // verify(networkViewManager).addNetworkView(view);
    verify(tm, atLeast(1)).setProgress(1.0);
}
Also used : Task(org.cytoscape.work.Task) LoadNetworkURLTask(org.cytoscape.task.internal.export.network.LoadNetworkURLTask) TaskIterator(org.cytoscape.work.TaskIterator) LoadNetworkURLTaskFactoryImpl(org.cytoscape.task.internal.export.network.LoadNetworkURLTaskFactoryImpl) TaskMonitor(org.cytoscape.work.TaskMonitor) TaskFactory(org.cytoscape.work.TaskFactory) Test(org.junit.Test)

Example 3 with LoadNetworkURLTaskFactoryImpl

use of org.cytoscape.task.internal.export.network.LoadNetworkURLTaskFactoryImpl in project cytoscape-impl by cytoscape.

the class LoadNetworkURLTaskTest method testBadConnection.

@Test(expected = Exception.class)
public void testBadConnection() throws Exception {
    doThrow(new IOException("bad connection")).when(connection).connect();
    TaskFactory factory = new LoadNetworkURLTaskFactoryImpl(serviceRegistrar);
    TaskIterator ti = factory.createTaskIterator();
    TaskMonitor tm = mock(TaskMonitor.class);
    boolean first = true;
    while (ti.hasNext()) {
        Task t = ti.next();
        if (first) {
            ((LoadNetworkURLTask) t).url = url;
            first = false;
        }
        t.run(tm);
    }
}
Also used : Task(org.cytoscape.work.Task) LoadNetworkURLTask(org.cytoscape.task.internal.export.network.LoadNetworkURLTask) TaskIterator(org.cytoscape.work.TaskIterator) LoadNetworkURLTaskFactoryImpl(org.cytoscape.task.internal.export.network.LoadNetworkURLTaskFactoryImpl) TaskMonitor(org.cytoscape.work.TaskMonitor) TaskFactory(org.cytoscape.work.TaskFactory) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with LoadNetworkURLTaskFactoryImpl

use of org.cytoscape.task.internal.export.network.LoadNetworkURLTaskFactoryImpl 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)

Aggregations

LoadNetworkURLTaskFactoryImpl (org.cytoscape.task.internal.export.network.LoadNetworkURLTaskFactoryImpl)4 Task (org.cytoscape.work.Task)4 TaskIterator (org.cytoscape.work.TaskIterator)4 TaskMonitor (org.cytoscape.work.TaskMonitor)4 Test (org.junit.Test)4 LoadNetworkURLTask (org.cytoscape.task.internal.export.network.LoadNetworkURLTask)3 TaskFactory (org.cytoscape.work.TaskFactory)3 IOException (java.io.IOException)1 URLConnection (java.net.URLConnection)1 StreamUtil (org.cytoscape.io.util.StreamUtil)1 ObservableTask (org.cytoscape.work.ObservableTask)1 TaskObserver (org.cytoscape.work.TaskObserver)1