Search in sources :

Example 6 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class DeselectAllTaskTest method testRun.

@Test
public void testRun() throws Exception {
    UndoSupport undoSupport = mock(UndoSupport.class);
    Set<Long> selectedEdges = new HashSet<>();
    selectedEdges.add(r1.get(CyNetwork.SUID, Long.class));
    selectedEdges.add(r2.get(CyNetwork.SUID, Long.class));
    when(edgeTable.getMatchingKeys(CyNetwork.SELECTED, true, Long.class)).thenReturn(selectedEdges);
    Set<Long> selectedNodes = new HashSet<>();
    selectedNodes.add(r3.get(CyNetwork.SUID, Long.class));
    selectedNodes.add(r4.get(CyNetwork.SUID, Long.class));
    when(nodeTable.getMatchingKeys(CyNetwork.SELECTED, true, Long.class)).thenReturn(selectedNodes);
    // run the task
    Task t = new DeselectAllTask(undoSupport, net, networkViewManager, eventHelper);
    t.run(tm);
    // check that the expected rows were set
    verify(r1, times(1)).set("selected", false);
    verify(r2, times(1)).set("selected", false);
    verify(r3, times(1)).set("selected", false);
    verify(r4, times(1)).set("selected", false);
}
Also used : Task(org.cytoscape.work.Task) UndoSupport(org.cytoscape.work.undo.UndoSupport) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class InvertSelectedNodesTaskTest method testRun.

@Test
public void testRun() throws Exception {
    final CyTable nodeTable = mock(CyTable.class);
    when(net.getDefaultNodeTable()).thenReturn(nodeTable);
    UndoSupport undoSupport = mock(UndoSupport.class);
    // more setup
    when(r3.get("selected", Boolean.class)).thenReturn(false);
    when(r4.get("selected", Boolean.class)).thenReturn(true);
    final CyEventHelper eventHelper = mock(CyEventHelper.class);
    // run the task
    Task t = new InvertSelectedNodesTask(undoSupport, net, networkViewManager, eventHelper);
    t.run(tm);
    // check that the expected rows were set
    verify(r3, times(1)).set("selected", true);
    verify(r4, times(1)).set("selected", false);
}
Also used : CyTable(org.cytoscape.model.CyTable) CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) UndoSupport(org.cytoscape.work.undo.UndoSupport) Test(org.junit.Test)

Example 8 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class SelectAllEdgesTaskTest method testRun.

@Test
public void testRun() throws Exception {
    UndoSupport undoSupport = mock(UndoSupport.class);
    Set<CyRow> deselectedEdges = new HashSet<CyRow>();
    deselectedEdges.add(r1);
    deselectedEdges.add(r2);
    when(edgeTable.getMatchingRows(CyNetwork.SELECTED, false)).thenReturn(deselectedEdges);
    // run the task
    Task t = new SelectAllEdgesTask(undoSupport, net, networkViewManager, eventHelper);
    t.run(tm);
    // check that the expected rows were set
    verify(r1, times(1)).set("selected", true);
    verify(r2, times(1)).set("selected", true);
}
Also used : Task(org.cytoscape.work.Task) CyRow(org.cytoscape.model.CyRow) UndoSupport(org.cytoscape.work.undo.UndoSupport) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class NewNetworkSelectedNodesOnlyTaskTest method testNewNetworkSelectedNodesOnlyTask.

@Test
public void testNewNetworkSelectedNodesOnlyTask() throws Exception {
    final UndoSupport undoSupport = mock(UndoSupport.class);
    netmgr.addNetwork(net);
    final CyNode node1 = net.addNode();
    final CyNode node2 = net.addNode();
    final CyNode node3 = net.addNode();
    final CyEdge edge1 = net.addEdge(node1, node2, true);
    // final CyEdge edge2 = net.addEdge(node2, node3, true);
    net.getRow(node1).set(CyNetwork.SELECTED, true);
    // net.getRow(node2).set(CyNetwork.SELECTED, true);
    net.getRow(edge1).set(CyNetwork.SELECTED, true);
    int numberOfNetsBeforeTask = netmgr.getNetworkSet().size();
    List<CyNetwork> netListbeforeTask = new ArrayList<CyNetwork>(netmgr.getNetworkSet());
    final NewNetworkSelectedNodesOnlyTask task = new NewNetworkSelectedNodesOnlyTask(undoSupport, net, cyroot, cnvf, netmgr, networkViewManager, cyNetworkNaming, vmm, appManager, eventHelper, groupMgr, renderingEngineManager, serviceRegistrar);
    assertNotNull("task is null!", task);
    task.setTaskIterator(new TaskIterator(task));
    task.run(mock(TaskMonitor.class));
    int numberOfNetsAfterTask = netmgr.getNetworkSet().size();
    assertEquals(1, numberOfNetsAfterTask - numberOfNetsBeforeTask);
    List<CyNetwork> networkList = new ArrayList<CyNetwork>(netmgr.getNetworkSet());
    networkList.removeAll(netListbeforeTask);
    assertEquals(1, networkList.get(0).getNodeList().size());
    assertEquals(0, networkList.get(0).getEdgeList().size());
}
Also used : TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyEdge(org.cytoscape.model.CyEdge) Test(org.junit.Test)

Example 10 with UndoSupport

use of org.cytoscape.work.undo.UndoSupport in project cytoscape-impl by cytoscape.

the class SelectAllTaskTest method testRun.

@Test
public void testRun() throws Exception {
    UndoSupport undoSupport = mock(UndoSupport.class);
    Set<CyRow> deselectedNodes = new HashSet<CyRow>();
    deselectedNodes.add(r3);
    deselectedNodes.add(r4);
    when(nodeTable.getMatchingRows(CyNetwork.SELECTED, false)).thenReturn(deselectedNodes);
    Set<CyRow> deselectedEdges = new HashSet<CyRow>();
    deselectedEdges.add(r1);
    deselectedEdges.add(r2);
    when(edgeTable.getMatchingRows(CyNetwork.SELECTED, false)).thenReturn(deselectedEdges);
    // run the task
    Task t = new SelectAllTask(undoSupport, net, networkViewManager, eventHelper);
    t.run(tm);
    // check that the expected rows were set
    verify(r1, times(1)).set("selected", true);
    verify(r2, times(1)).set("selected", true);
    verify(r3, times(1)).set("selected", true);
    verify(r4, times(1)).set("selected", true);
}
Also used : Task(org.cytoscape.work.Task) CyRow(org.cytoscape.model.CyRow) UndoSupport(org.cytoscape.work.undo.UndoSupport) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

UndoSupport (org.cytoscape.work.undo.UndoSupport)50 Test (org.junit.Test)21 Task (org.cytoscape.work.Task)19 CyEventHelper (org.cytoscape.event.CyEventHelper)15 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)15 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)12 HashSet (java.util.HashSet)10 TaskIterator (org.cytoscape.work.TaskIterator)10 CyNode (org.cytoscape.model.CyNode)9 ArrayList (java.util.ArrayList)8 CyEdge (org.cytoscape.model.CyEdge)7 CyNetwork (org.cytoscape.model.CyNetwork)7 CyNetworkView (org.cytoscape.view.model.CyNetworkView)7 CyRow (org.cytoscape.model.CyRow)6 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)6 Properties (java.util.Properties)5 CyNetworkManager (org.cytoscape.model.CyNetworkManager)5 CyApplicationManager (org.cytoscape.application.CyApplicationManager)4 CyGroupManager (org.cytoscape.group.CyGroupManager)4 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)4