Search in sources :

Example 21 with NetworkTestSupport

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

the class TestCyGroupFactory method testGroupCreate.

@Test
public void testGroupCreate() throws Exception {
    CyGroupFactory factory = TestCyGroupFactory.getFactory();
    // Net to create a network to test this..
    NetworkTestSupport support = new NetworkTestSupport();
    CyNetwork network = support.getNetwork();
    // Create some nodes and edges
    CyNode node1 = network.addNode();
    CyNode node2 = network.addNode();
    CyNode node3 = network.addNode();
    CyNode node4 = network.addNode();
    CyNode node5 = network.addNode();
    List<CyNode> groupNodes = new ArrayList<CyNode>();
    groupNodes.add(node1);
    groupNodes.add(node2);
    groupNodes.add(node3);
    CyEdge edge1 = network.addEdge(node1, node2, false);
    CyEdge edge2 = network.addEdge(node2, node3, false);
    CyEdge edge3 = network.addEdge(node2, node4, false);
    CyEdge edge4 = network.addEdge(node2, node5, false);
    CyEdge edge5 = network.addEdge(node3, node5, false);
    List<CyEdge> groupEdges = new ArrayList<CyEdge>();
    groupEdges.add(edge1);
    groupEdges.add(edge2);
    groupEdges.add(edge3);
    groupEdges.add(edge4);
    CyGroup group1 = factory.createGroup(network, groupNodes, null, true);
    assertNotNull(group1);
    assertTrue("group1 node count = 3", group1.getNodeList().size() == 3);
    assertTrue("group1 internal edge count = 2", group1.getInternalEdgeList().size() == 2);
    assertTrue("group1 external edge count = 3", group1.getExternalEdgeList().size() == 3);
    CyGroup group2 = factory.createGroup(network, groupNodes, new ArrayList<CyEdge>(), true);
    assertNotNull(group2);
    assertTrue("group2 node count = 3", group2.getNodeList().size() == 3);
    assertTrue("group2 internal edge count = 0", group2.getInternalEdgeList().size() == 0);
    assertTrue("group2 external edge count = 0", group2.getExternalEdgeList().size() == 0);
    CyGroup group3 = factory.createGroup(network, groupNodes, groupEdges, true);
    assertNotNull(group3);
    assertTrue("group3 node count = 3", group3.getNodeList().size() == 3);
    assertTrue("group3 internal edge count = 2", group3.getInternalEdgeList().size() == 2);
    assertTrue("group3 external edge count = 2", group3.getExternalEdgeList().size() == 2);
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) Test(org.junit.Test)

Example 22 with NetworkTestSupport

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

the class TestCyGroupFactory method testMemberEdges.

/*
     * Tests for this scenario:

                           group
                     +- - - - - - - - +
                     |        2       |
                        +-------> B
                     |  |         ^   |    Collapse
                        |         |5      ===========>
                     |  v         |   |
               1        +     3   v                            1
            A<--------->G<------->C   |                 A+---------->G
                        ^         ^
                     |  |         |6  |      Expand
                        |         |       <===========
                     |  |     4   v   |
                        +-------->D
                     |                |
                     +- - - - - - - - +
    */
@Test
public void testMemberEdges() throws Exception {
    // Set up our data structures
    final CyGroupFactory factory = TestCyGroupFactory.getFactory();
    final NetworkTestSupport support = new NetworkTestSupport();
    final CyNetwork net = support.getNetwork();
    final CyNode nodeA = net.addNode();
    final CyNode nodeB = net.addNode();
    final CyNode nodeC = net.addNode();
    final CyNode nodeD = net.addNode();
    final CyNode nodeG = net.addNode();
    final CyEdge edge1 = net.addEdge(nodeA, nodeG, false);
    final CyEdge edge2 = net.addEdge(nodeG, nodeB, false);
    final CyEdge edge3 = net.addEdge(nodeG, nodeC, false);
    final CyEdge edge4 = net.addEdge(nodeG, nodeD, false);
    final CyEdge edge5 = net.addEdge(nodeC, nodeB, false);
    final CyEdge edge6 = net.addEdge(nodeC, nodeD, false);
    final CyGroup group = factory.createGroup(net, nodeG, Arrays.asList(nodeB, nodeC, nodeD), Arrays.asList(edge2, edge3, edge4, edge5, edge6), true);
    // Assert our group has the right nodes and edges
    assertFalse(group.isCollapsed(net));
    assertEqualWithoutOrder(group.getNodeList(), Arrays.asList(nodeB, nodeC, nodeD));
    assertEqualWithoutOrder(group.getInternalEdgeList(), Arrays.asList(edge5, edge6));
    assertEquals(group.getExternalEdgeList().size(), 0);
    // Assert that the network was unaffected by the group creation
    assertEqualWithoutOrder(net.getNodeList(), Arrays.asList(nodeA, nodeB, nodeC, nodeD, nodeG));
    assertEqualWithoutOrder(net.getEdgeList(), Arrays.asList(edge1, edge2, edge3, edge4, edge5, edge6));
    // Collapse the group
    group.collapse(net);
    assertTrue(group.isCollapsed(net));
    // Test to see if our network is what we expect
    assertEqualWithoutOrder(net.getNodeList(), Arrays.asList(nodeA, nodeG));
    assertEqualWithoutOrder(net.getEdgeList(), Arrays.asList(edge1));
    // Expand the group
    group.expand(net);
    assertFalse(group.isCollapsed(net));
    // Assert that the network has returned to its original state
    assertEqualWithoutOrder(net.getNodeList(), Arrays.asList(nodeA, nodeB, nodeC, nodeD, nodeG));
    assertEqualWithoutOrder(net.getEdgeList(), Arrays.asList(edge1, edge2, edge3, edge4, edge5, edge6));
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) Test(org.junit.Test)

Example 23 with NetworkTestSupport

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

the class AbstractNetworkReaderTest method setUp.

@Before
public void setUp() throws Exception {
    taskMonitor = mock(TaskMonitor.class);
    CyLayoutAlgorithm def = mock(CyLayoutAlgorithm.class);
    Object context = new Object();
    when(def.createLayoutContext()).thenReturn(context);
    when(def.getDefaultLayoutContext()).thenReturn(context);
    when(def.createTaskIterator(Mockito.any(CyNetworkView.class), Mockito.any(Object.class), Mockito.anySet(), Mockito.any(String.class))).thenReturn(new TaskIterator(new SimpleTask()));
    layouts = mock(CyLayoutAlgorithmManager.class);
    when(layouts.getDefaultLayout()).thenReturn(def);
    NetworkTestSupport nts = new NetworkTestSupport();
    netFactory = nts.getNetworkFactory();
    netManager = nts.getNetworkManager();
    rootNetManager = nts.getRootNetworkFactory();
    netTableManager = nts.getNetworkTableManager();
    TableTestSupport tblTestSupport = new TableTestSupport();
    tableFactory = tblTestSupport.getTableFactory();
    tableManager = mock(CyTableManager.class);
    GroupTestSupport groupTestSupport = new GroupTestSupport();
    groupManager = groupTestSupport.getGroupManager();
    groupFactory = groupTestSupport.getGroupFactory();
    properties = new Properties();
    CyProperty<Properties> cyProperties = new SimpleCyProperty<>("Test", properties, Properties.class, SavePolicy.DO_NOT_SAVE);
    NetworkViewTestSupport nvts = new NetworkViewTestSupport();
    setViewThreshold(DEF_THRESHOLD);
    viewFactory = nvts.getNetworkViewFactory();
    readUtil = new ReadUtils(new StreamUtilImpl(serviceRegistrar));
    defRenderer = mock(NetworkViewRenderer.class);
    when(defRenderer.getNetworkViewFactory()).thenReturn(viewFactory);
    lexicon = new BasicVisualLexicon(new NullVisualProperty("MINIMAL_ROOT", "Minimal Root Visual Property"));
    renderingEngineManager = mock(RenderingEngineManager.class);
    when(renderingEngineManager.getDefaultVisualLexicon()).thenReturn(lexicon);
    applicationManager = mock(CyApplicationManager.class);
    when(applicationManager.getDefaultNetworkViewRenderer()).thenReturn(defRenderer);
    serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyProperty.class, "(cyPropertyName=cytoscape3.props)")).thenReturn(cyProperties);
    when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(applicationManager);
    when(serviceRegistrar.getService(CyNetworkFactory.class)).thenReturn(netFactory);
    when(serviceRegistrar.getService(CyNetworkViewFactory.class)).thenReturn(viewFactory);
    when(serviceRegistrar.getService(CyNetworkManager.class)).thenReturn(netManager);
    when(serviceRegistrar.getService(CyNetworkTableManager.class)).thenReturn(netTableManager);
    when(serviceRegistrar.getService(CyRootNetworkManager.class)).thenReturn(rootNetManager);
    when(serviceRegistrar.getService(CyLayoutAlgorithmManager.class)).thenReturn(layouts);
    when(serviceRegistrar.getService(CyTableManager.class)).thenReturn(tableManager);
    when(serviceRegistrar.getService(CyTableFactory.class)).thenReturn(tableFactory);
    when(serviceRegistrar.getService(CyGroupManager.class)).thenReturn(groupManager);
    when(serviceRegistrar.getService(CyGroupFactory.class)).thenReturn(groupFactory);
    when(serviceRegistrar.getService(RenderingEngineManager.class)).thenReturn(renderingEngineManager);
}
Also used : NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) Properties(java.util.Properties) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) StreamUtilImpl(org.cytoscape.io.internal.util.StreamUtilImpl) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyApplicationManager(org.cytoscape.application.CyApplicationManager) TaskIterator(org.cytoscape.work.TaskIterator) CyLayoutAlgorithmManager(org.cytoscape.view.layout.CyLayoutAlgorithmManager) CyTableManager(org.cytoscape.model.CyTableManager) TaskMonitor(org.cytoscape.work.TaskMonitor) TableTestSupport(org.cytoscape.model.TableTestSupport) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) GroupTestSupport(org.cytoscape.group.GroupTestSupport) ReadUtils(org.cytoscape.io.internal.util.ReadUtils) CyNetworkView(org.cytoscape.view.model.CyNetworkView) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer) Before(org.junit.Before)

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