Search in sources :

Example 11 with NetworkTestSupport

use of org.cytoscape.model.NetworkTestSupport in project cytoscape-impl by cytoscape.

the class ColumnFilterTest method testColumnFilterList.

@Test
public void testColumnFilterList() {
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    network.getDefaultNodeTable().createListColumn("l", String.class, false);
    CyNode n1 = network.addNode();
    CyNode n2 = network.addNode();
    CyNode n3 = network.addNode();
    network.getRow(n1).set("l", Arrays.asList("a", "b", "c"));
    network.getRow(n2).set("l", Arrays.asList("c", "d"));
    network.getRow(n3).set("l", Arrays.asList("a", "a"));
    ColumnFilter columnFilter = new ColumnFilter("l", Predicate.IS, "a");
    columnFilter.setAnyMatch(true);
    assertTrue(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertTrue(columnFilter.accepts(network, n3));
    columnFilter.setAnyMatch(false);
    assertFalse(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertTrue(columnFilter.accepts(network, n3));
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) Test(org.junit.Test)

Example 12 with NetworkTestSupport

use of org.cytoscape.model.NetworkTestSupport in project cytoscape-impl by cytoscape.

the class ColumnFilterTest method testColumnFilterBoolean.

@Test
public void testColumnFilterBoolean() {
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    network.getDefaultNodeTable().createColumn("b", Boolean.class, false);
    CyNode n1 = network.addNode();
    CyNode n2 = network.addNode();
    CyNode n3 = network.addNode();
    network.getRow(n1).set("b", true);
    network.getRow(n2).set("b", false);
    ColumnFilter columnFilter = new ColumnFilter("b", Predicate.IS, true);
    assertTrue(columnFilter.accepts(network, n1));
    assertFalse(columnFilter.accepts(network, n2));
    assertFalse(columnFilter.accepts(network, n3));
    columnFilter.setPredicateAndCriterion(Predicate.IS, false);
    assertFalse(columnFilter.accepts(network, n1));
    assertTrue(columnFilter.accepts(network, n2));
    assertFalse(columnFilter.accepts(network, n3));
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) Test(org.junit.Test)

Example 13 with NetworkTestSupport

use of org.cytoscape.model.NetworkTestSupport in project cytoscape-impl by cytoscape.

the class TopologyFilterTest method testTopologyFilter.

@Test
public void testTopologyFilter() {
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    network.getDefaultNodeTable().createColumn("s", String.class, false);
    CyNode n1 = network.addNode();
    CyNode n2 = network.addNode();
    CyNode n3 = network.addNode();
    CyNode n4 = network.addNode();
    CyNode n5 = network.addNode();
    CyNode n6 = network.addNode();
    CyNode n7 = network.addNode();
    CyNode n8 = network.addNode();
    network.addEdge(n1, n2, false);
    network.addEdge(n1, n3, false);
    network.addEdge(n1, n4, false);
    network.addEdge(n2, n5, false);
    network.addEdge(n3, n6, false);
    network.addEdge(n4, n7, false);
    network.addEdge(n7, n8, false);
    TopologyFilter topologyFilter = new TopologyFilter();
    topologyFilter.setThreshold(6);
    topologyFilter.setDistance(2);
    topologyFilter.setPredicate(Predicate.GREATER_THAN_OR_EQUAL);
    assertTrue(topologyFilter.accepts(network, n1));
    topologyFilter.setDistance(1);
    assertFalse(topologyFilter.accepts(network, n1));
    network.getRow(n2).set("s", "a");
    network.getRow(n6).set("s", "a");
    ColumnFilter columnFilter = new ColumnFilter("s", Predicate.IS, "a");
    assertTrue(columnFilter.accepts(network, n2));
    assertTrue(columnFilter.accepts(network, n6));
    topologyFilter.append(columnFilter);
    topologyFilter.setThreshold(2);
    topologyFilter.setDistance(2);
    assertTrue(topologyFilter.accepts(network, n1));
    topologyFilter.setDistance(1);
    assertFalse(topologyFilter.accepts(network, n1));
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) ColumnFilter(org.cytoscape.filter.internal.filters.column.ColumnFilter) TopologyFilter(org.cytoscape.filter.internal.filters.topology.TopologyFilter) Test(org.junit.Test)

Example 14 with NetworkTestSupport

use of org.cytoscape.model.NetworkTestSupport in project cytoscape-impl by cytoscape.

the class OBOReaderTest method setUp.

@Before
public void setUp() throws Exception {
    viewSupport = new NetworkViewTestSupport();
    netSupport = new NetworkTestSupport();
    netViewFactory = viewSupport.getNetworkViewFactory();
    netFactory = netSupport.getNetworkFactory();
    eventHelper = mock(CyEventHelper.class);
    serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyNetworkViewFactory.class)).thenReturn(netViewFactory);
    when(serviceRegistrar.getService(CyNetworkFactory.class)).thenReturn(netFactory);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Before(org.junit.Before)

Example 15 with NetworkTestSupport

use of org.cytoscape.model.NetworkTestSupport in project cytoscape-impl by cytoscape.

the class NewNetworkSelectedNodesOnlyTaskFactoryTest method testObserver.

@Test
public void testObserver() throws Exception {
    NetworkViewTestSupport viewSupport = new NetworkViewTestSupport();
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetworkFactory networkFactory = networkSupport.getNetworkFactory();
    UndoSupport undoSupport = mock(UndoSupport.class);
    CyRootNetworkManager crnf = new CyRootNetworkManagerImpl();
    CyNetworkViewFactory cnvf = viewSupport.getNetworkViewFactory();
    CyNetworkManager netmgr = mock(CyNetworkManager.class);
    CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
    CyNetworkNaming naming = mock(CyNetworkNaming.class);
    VisualMappingManager vmm = mock(VisualMappingManager.class);
    CyApplicationManager appManager = mock(CyApplicationManager.class);
    CyEventHelper eventHelper = mock(CyEventHelper.class);
    CyGroupManager groupMgr = mock(CyGroupManager.class);
    RenderingEngineManager renderingEngineMgr = mock(RenderingEngineManager.class);
    CyLayoutAlgorithm defLayout = mock(CyLayoutAlgorithm.class);
    CyLayoutAlgorithmManager layoutMgr = mock(CyLayoutAlgorithmManager.class);
    when(layoutMgr.getDefaultLayout()).thenReturn(defLayout);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyLayoutAlgorithmManager.class)).thenReturn(layoutMgr);
    NewNetworkSelectedNodesOnlyTaskFactoryImpl factory = new NewNetworkSelectedNodesOnlyTaskFactoryImpl(undoSupport, crnf, cnvf, netmgr, networkViewManager, naming, vmm, appManager, eventHelper, groupMgr, renderingEngineMgr, serviceRegistrar);
    CyNetwork network = networkFactory.createNetwork();
    CyNode node = network.addNode();
    network.getRow(node).set(CyNetwork.SELECTED, true);
    TaskObserver observer = mock(TaskObserver.class);
    TaskMonitor taskMonitor = mock(TaskMonitor.class);
    TaskIterator iterator = factory.createTaskIterator(network);
    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 : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) CyNetwork(org.cytoscape.model.CyNetwork) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) CyNode(org.cytoscape.model.CyNode) CyGroupManager(org.cytoscape.group.CyGroupManager) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyRootNetworkManagerImpl(org.cytoscape.model.internal.CyRootNetworkManagerImpl) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyApplicationManager(org.cytoscape.application.CyApplicationManager) TaskObserver(org.cytoscape.work.TaskObserver) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyLayoutAlgorithmManager(org.cytoscape.view.layout.CyLayoutAlgorithmManager) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) Test(org.junit.Test)

Aggregations

NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)23 CyNetwork (org.cytoscape.model.CyNetwork)17 CyNode (org.cytoscape.model.CyNode)16 Test (org.junit.Test)15 ColumnFilter (org.cytoscape.filter.internal.filters.column.ColumnFilter)7 NetworkViewTestSupport (org.cytoscape.ding.NetworkViewTestSupport)6 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)6 TaskMonitor (org.cytoscape.work.TaskMonitor)6 Before (org.junit.Before)6 CyApplicationManager (org.cytoscape.application.CyApplicationManager)4 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)4 TaskIterator (org.cytoscape.work.TaskIterator)4 CyEventHelper (org.cytoscape.event.CyEventHelper)3 CyEdge (org.cytoscape.model.CyEdge)3 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)3 CyRootNetworkManagerImpl (org.cytoscape.model.internal.CyRootNetworkManagerImpl)3 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 CompositeFilterImpl (org.cytoscape.filter.internal.filters.composite.CompositeFilterImpl)2