Author: mes
Date: 2010-09-01 16:33:15 -0700 (Wed, 01 Sep 2010)
New Revision: 21661
Added:
core3/core-task-impl/trunk/src/test/
core3/core-task-impl/trunk/src/test/java/
core3/core-task-impl/trunk/src/test/java/org/
core3/core-task-impl/trunk/src/test/java/org/cytoscape/
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/AbstractLoadNetworkTaskTester.java
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTaskTest.java
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTaskTest.java
Modified:
core3/core-task-impl/trunk/pom.xml
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTask.java
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTaskFactoryImpl.java
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTaskFactoryImpl.java
Log:
added unit tests for file loading
Modified: core3/core-task-impl/trunk/pom.xml
===================================================================
--- core3/core-task-impl/trunk/pom.xml 2010-09-01 22:58:13 UTC (rev 21660)
+++ core3/core-task-impl/trunk/pom.xml 2010-09-01 23:33:15 UTC (rev 21661)
@@ -115,6 +115,18 @@
<artifactId>core-task-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.8.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTask.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTask.java
2010-09-01 22:58:13 UTC (rev 21660)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTask.java
2010-09-01 23:33:15 UTC (rev 21661)
@@ -59,6 +59,9 @@
*/
public void run(TaskMonitor taskMonitor) throws Exception {
this.taskMonitor = taskMonitor;
+
+ if ( file == null )
+ throw new NullPointerException("No file specified!");
reader = mgr.getReader((file.toURI()));
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTaskFactoryImpl.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTaskFactoryImpl.java
2010-09-01 22:58:13 UTC (rev 21660)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTaskFactoryImpl.java
2010-09-01 23:33:15 UTC (rev 21661)
@@ -61,10 +61,6 @@
this.cyNetworkNaming = cyNetworkNaming;
}
- public void setNamingUtil(CyNetworkNaming namingUtil) {
- this.cyNetworkNaming = namingUtil;
- }
-
public TaskIterator getTaskIterator() {
return new TaskIterator(new LoadNetworkFileTask(mgr, netmgr,
props, cyNetworkNaming));
}
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTaskFactoryImpl.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTaskFactoryImpl.java
2010-09-01 22:58:13 UTC (rev 21660)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTaskFactoryImpl.java
2010-09-01 23:33:15 UTC (rev 21661)
@@ -66,10 +66,6 @@
this.streamUtil = streamUtil;
}
- public void setNamingUtil(CyNetworkNaming namingUtil) {
- this.cyNetworkNaming = namingUtil;
- }
-
public TaskIterator getTaskIterator() {
return new TaskIterator(new LoadNetworkURLTask(mgr, netmgr,
props, cyNetworkNaming, streamUtil));
}
Added:
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/AbstractLoadNetworkTaskTester.java
===================================================================
---
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/AbstractLoadNetworkTaskTester.java
(rev 0)
+++
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/AbstractLoadNetworkTaskTester.java
2010-09-01 23:33:15 UTC (rev 21661)
@@ -0,0 +1,102 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+
+package org.cytoscape.task.internal.loadnetwork;
+
+import static org.mockito.Mockito.*;
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.Before;
+
+import java.util.Properties;
+import java.net.URI;
+
+import org.cytoscape.io.read.CyNetworkViewReaderManager;
+import org.cytoscape.session.CyNetworkManager;
+import org.cytoscape.session.CyNetworkNaming;
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.Task;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.io.read.CyNetworkViewReader;
+
+public class AbstractLoadNetworkTaskTester {
+
+ URI uri;
+
+ CyNetworkViewReaderManager mgr;
+ CyNetworkManager netmgr;
+ CyProperty<Properties> props;
+ CyNetworkNaming namingUtil;
+
+ CyNetwork net;
+ CyNetworkView view;
+ CyNetworkView[] views;
+ CyNetworkViewReader reader;
+
+ public void setUp() throws Exception {
+ CyRow attrs = mock(CyRow.class);
+
+ net = mock(CyNetwork.class);
+ when(net.getNodeCount()).thenReturn(2);
+ when(net.getEdgeCount()).thenReturn(1);
+ when(net.attrs()).thenReturn(attrs);
+
+ view = mock(CyNetworkView.class);
+ when(view.getModel()).thenReturn(net);
+
+ views = new CyNetworkView[] {view};
+
+ reader = mock(CyNetworkViewReader.class);
+ when(reader.getNetworkViews()).thenReturn(views);
+
+ mgr = mock(CyNetworkViewReaderManager.class);
+ when(mgr.getReader(uri)).thenReturn(reader);
+
+ netmgr = mock(CyNetworkManager.class);
+
+ Properties p = new Properties();
+ p.setProperty("viewThreshold","1000");
+
+ props = mock(CyProperty.class);
+ when(props.getProperties()).thenReturn(p);
+
+ namingUtil = mock(CyNetworkNaming.class);
+ }
+}
Added:
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTaskTest.java
===================================================================
---
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTaskTest.java
(rev 0)
+++
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkFileTaskTest.java
2010-09-01 23:33:15 UTC (rev 21661)
@@ -0,0 +1,105 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+
+package org.cytoscape.task.internal.loadnetwork;
+
+import static org.mockito.Mockito.*;
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.Before;
+
+import java.io.File;
+import java.util.Properties;
+
+import org.cytoscape.io.read.CyNetworkViewReaderManager;
+import org.cytoscape.session.CyNetworkManager;
+import org.cytoscape.session.CyNetworkNaming;
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.Task;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.io.read.CyNetworkViewReader;
+
+public class LoadNetworkFileTaskTest extends AbstractLoadNetworkTaskTester {
+
+ File file;
+
+ @Before
+ public void setUp() throws Exception {
+ file = new File("/tmp/asdfasdf");
+ uri = file.toURI();
+ super.setUp();
+ }
+
+ @Test
+ public void testRun() throws Exception {
+ TaskFactory factory = new LoadNetworkFileTaskFactoryImpl(mgr,
netmgr, props, namingUtil );
+ TaskIterator ti = factory.getTaskIterator();
+ TaskMonitor tm = mock(TaskMonitor.class);
+ boolean first = true;
+ while ( ti.hasNext() ) {
+ Task t = ti.next();
+ if ( first ) {
+ ((LoadNetworkFileTask)t).file = file;
+ first = false;
+ }
+ t.run(tm);
+ }
+ verify(netmgr).addNetwork(net);
+ verify(netmgr).addNetworkView(view);
+ verify(tm).setProgress(1.0);
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testNullFile() throws Exception {
+ TaskFactory factory = new LoadNetworkFileTaskFactoryImpl(mgr,
netmgr, props, namingUtil );
+ TaskIterator ti = factory.getTaskIterator();
+ TaskMonitor tm = mock(TaskMonitor.class);
+ boolean first = true;
+ while ( ti.hasNext() ) {
+ Task t = ti.next();
+ if ( first ) {
+ ((LoadNetworkFileTask)t).file = null;
+ first = false;
+ }
+ t.run(tm);
+ }
+ }
+}
Added:
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTaskTest.java
===================================================================
---
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTaskTest.java
(rev 0)
+++
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/loadnetwork/LoadNetworkURLTaskTest.java
2010-09-01 23:33:15 UTC (rev 21661)
@@ -0,0 +1,138 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+
+package org.cytoscape.task.internal.loadnetwork;
+
+import static org.mockito.Mockito.*;
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.Before;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Properties;
+
+import org.cytoscape.io.read.CyNetworkViewReaderManager;
+import org.cytoscape.session.CyNetworkManager;
+import org.cytoscape.session.CyNetworkNaming;
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.TaskFactory;
+import org.cytoscape.work.Task;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.io.read.CyNetworkViewReader;
+import org.cytoscape.io.util.StreamUtil;
+
+public class LoadNetworkURLTaskTest extends AbstractLoadNetworkTaskTester {
+
+ URL url;
+
+ @Before
+ public void setUp() throws Exception {
+ url = new URL("http://example.com");
+ uri = url.toURI();
+ super.setUp();
+ }
+
+ @Test
+ public void testRun() throws Exception {
+ URLConnection con = mock(URLConnection.class);
+ StreamUtil streamUtil = mock(StreamUtil.class);
+ when(streamUtil.getURLConnection(url)).thenReturn(con);
+
+ TaskFactory factory = new LoadNetworkURLTaskFactoryImpl(mgr,
netmgr, props, namingUtil, streamUtil );
+ TaskIterator ti = factory.getTaskIterator();
+ 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(netmgr).addNetwork(net);
+ verify(netmgr).addNetworkView(view);
+ verify(tm).setProgress(1.0);
+ }
+
+ @Test(expected=Exception.class)
+ public void testBadConnection() throws Exception {
+ URLConnection con = mock(URLConnection.class);
+ doThrow(new IOException("bad connection")).when(con).connect();
+
+ StreamUtil streamUtil = mock(StreamUtil.class);
+ when(streamUtil.getURLConnection(url)).thenReturn(con);
+
+ TaskFactory factory = new LoadNetworkURLTaskFactoryImpl(mgr,
netmgr, props, namingUtil, streamUtil );
+ TaskIterator ti = factory.getTaskIterator();
+ 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);
+ }
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testNullURL() throws Exception {
+ URLConnection con = mock(URLConnection.class);
+ StreamUtil streamUtil = mock(StreamUtil.class);
+ when(streamUtil.getURLConnection(url)).thenReturn(con);
+
+ TaskFactory factory = new LoadNetworkURLTaskFactoryImpl(mgr,
netmgr, props, namingUtil, streamUtil );
+ TaskIterator ti = factory.getTaskIterator();
+ 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);
+ }
+ }
+}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.