Author: mes
Date: 2010-10-01 18:26:10 -0700 (Fri, 01 Oct 2010)
New Revision: 22136

Modified:
   core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java
   
core3/session-api/trunk/src/test/java/org/cytoscape/session/CySessionTest.java
Log:
added javadoc and unit tests

Modified: 
core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java
===================================================================
--- core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java  
2010-10-02 00:14:08 UTC (rev 22135)
+++ core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java  
2010-10-02 01:26:10 UTC (rev 22136)
@@ -43,7 +43,25 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
+/**
+ * A session is an immutable snapshot of the data contents of Cytoscape.
+ * Sessions are only meant for saving and restoring the state of Cytoscape
+ * and are not meant to be used interactively for anything besides 
+ * writing, reading, and restoring from session files.
+ * <br/>
+ * Using the data returned from the various methods in a CySession object
+ * should be sufficient to recreate all aspects of Cytoscape at the time
+ * the session was created.
+ * <br/>
+ * Creating an instance of CySession is done following the builder pattern.
+ * For example, the following code creates a session that only includes
+ * a list of networkViews and cytoscape properties, but nothing else.  
+ * <br/>
+ * <pre>
+ * CySession session = new 
CySession.Builder().networkViews(viewList).cytoscapeProperties(cyProps).build();
+ * </pre>
+ * <br/>
+ */
 public final class CySession {
 
        private final Set<CyNetworkView> netViews;
@@ -105,56 +123,130 @@
                private Properties dProps;
                private Map<String, List<File>> pluginFiles; 
 
+               /**
+                * Returns a complete instance of CySession based upon the 
methods
+                * called on this instance of Builder.
+                * @return A fully configured instanced of CySession. 
+                */
                public CySession build() { return new CySession(this); }
 
+               /**
+                * @param views A Set of CyNetworkView objects, presumably all 
networks
+                * that exist in this instance of Cytoscape.
+                * @return An instance of Builder that has at least been 
configured
+                * with the specified network views.
+                */
                public Builder networkViews(final Set<CyNetworkView> views) { 
                        netViews = views; 
                        return this;
                }
 
+               /**
+                * @param t A Set of CyTable objects, presumably all tables
+                * that exist in this instance of Cytoscape.
+                * @return An instance of Builder that has at least been 
configured
+                * with the specified tables.
+                */
        public Builder tables(final Set<CyTable> t) { 
                        tables = t; 
                        return this;
                }
 
+               /**
+                * @param vs A map of CyNetworkViews to the names of the 
VisualStyle
+                * currently applied to that network view, for presumably all 
network views
+                * that exist in this instance of Cytoscape.
+                * @return An instance of Builder that has at least been 
configured
+                * with the specified network view visual style name map.
+                */
        public Builder viewVisualStyleMap(final  Map<CyNetworkView,String> vs) 
{ 
                        vsMap = vs; 
                        return this;
                }
 
+               /**
+                * @param p A Properties object that contains the current 
Cytoscape 
+                * properties.
+                * @return An instance of Builder that has at least been 
configured
+                * with the specified properties.
+                */
        public Builder cytoscapeProperties(final Properties p) { 
                        cyProps = p; 
                        return this;
                }
 
+               /**
+                * @param p A Properties object that contains the current 
VizMap 
+                * properties for all VisualStyles in this instance of 
Cytoscape.
+                * @return An instance of Builder that has at least been 
configured
+                * with the specified properties.
+                */
        public Builder vizmapProperties(final Properties p) { 
                        vProps = p; 
                        return this;
                }
 
+               /**
+                * @param p A Properties object that contains properties 
defining
+                * the current state of the Desktop in Cytoscape.
+                * @return An instance of Builder that has at least been 
configured
+                * with the specified properties.
+                */
        public Builder desktopProperties(final Properties p) { 
                        dProps = p; 
                        return this;
                }
 
+               /**
+                * @param p A map of plugin names to a list of File objects 
that the
+                * given plugin wants stored in the session file.
+                * @return An instance of Builder that has at least been 
configured
+                * with the specified plugin file list map.
+                */
                public Builder pluginFileListMap(final Map<String, List<File>> 
p) { 
                        this.pluginFiles = p; 
                        return this;
                }
        }
 
+       /**
+        * @return A set of all CyNetworkView objects contained in this 
Session. 
+        */
     public Set<CyNetworkView> getNetworkViews() { return netViews; }
 
+       /**
+        * @return A set of all CyTable objects contained in this Session. 
+        */
     public Set<CyTable> getTables() { return tables; }
 
+       /**
+        * @return A map of CyNetworkViews to the names of the VisualStyle
+        * applied to that network view in this session.
+        */
     public Map<CyNetworkView,String> getViewVisualStyleMap() { return vsMap; }
 
+       /**
+        * @return A Propeties object containing all Cytoscape properties 
+        * defined for this session. 
+        */
     public Properties getCytoscapeProperties() { return cyProps; }
 
+       /**
+        * @return A Propeties object containing all VisualStyles defined
+        * for this session.
+        */
     public Properties getVizmapProperties() { return vProps; }
 
+       /**
+        * @return A Propeties object containing all desktop configuration 
properties 
+        * for this session.
+        */
     public Properties getDesktopProperties() { return dProps; }
 
+       /**
+        * @return A map of plugin names to lists of File objects that are 
stored
+        * as part of the session for the specified plugin.
+        */
        public Map<String, List<File>> getPluginFileListMap() { return 
pluginFiles; }
 }
 

Modified: 
core3/session-api/trunk/src/test/java/org/cytoscape/session/CySessionTest.java
===================================================================
--- 
core3/session-api/trunk/src/test/java/org/cytoscape/session/CySessionTest.java  
    2010-10-02 00:14:08 UTC (rev 22135)
+++ 
core3/session-api/trunk/src/test/java/org/cytoscape/session/CySessionTest.java  
    2010-10-02 01:26:10 UTC (rev 22136)
@@ -2,59 +2,242 @@
 
 import static org.junit.Assert.*;
 
+import java.util.*;
+import java.io.File;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.model.CyTable;
 import org.cytoscape.session.CySession;
 import org.junit.Before;
 import org.junit.Test;
+import static org.mockito.Mockito.*;
 
 public class CySessionTest {
 
 
        protected CySession session;
 
-       @Before
-       public void setUp() {
+
+       @Test
+       public void testDefaultGetNetworkViews() {
                session = new CySession.Builder().build();
+               assertNotNull(session);
+               assertNotNull(session.getNetworkViews());
        }
 
        @Test
-       public void testGetNetworkViews() {
+       public void testSetNullNetworkViews() {
+               session = new CySession.Builder().networkViews( null ).build();
                assertNotNull(session);
                assertNotNull(session.getNetworkViews());
+               assertEquals(0,session.getNetworkViews().size());
        }
 
        @Test
-       public void testGetTables() {
+       public void testSetNetworkViews() {
+               CyNetworkView nv1 = mock(CyNetworkView.class); 
+               CyNetworkView nv2 = mock(CyNetworkView.class); 
+
+               Set<CyNetworkView> vs = new HashSet<CyNetworkView>();
+               vs.add( nv1 );
+               vs.add( nv2 );
+
+               session = new CySession.Builder().networkViews( vs ).build();
+
                assertNotNull(session);
+               assertNotNull(session.getNetworkViews());
+               assertEquals(2,session.getNetworkViews().size());
+               assertTrue(session.getNetworkViews().contains( nv1 ));
+               assertTrue(session.getNetworkViews().contains( nv2 ));
+       }
+
+       @Test
+       public void testDefaultGetTables() {
+               session = new CySession.Builder().build();
+               assertNotNull(session);
                assertNotNull(session.getTables());
        }
+
+       @Test
+       public void testSetNullTables() {
+               session = new CySession.Builder().tables( null ).build();
+               assertNotNull(session);
+               assertNotNull(session.getTables());
+               assertEquals(0,session.getTables().size());
+       }
+
+       @Test
+       public void testSetTables() {
+               CyTable t1 = mock(CyTable.class); 
+               CyTable t2 = mock(CyTable.class); 
+
+               Set<CyTable> ts = new HashSet<CyTable>();
+               ts.add( t1 );
+               ts.add( t2 );
+
+               session = new CySession.Builder().tables( ts ).build();
+
+               assertNotNull(session);
+               assertNotNull(session.getTables());
+               assertEquals(2,session.getTables().size());
+               assertTrue(session.getTables().contains( t1 ));
+               assertTrue(session.getTables().contains( t2 ));
+       }
        
        @Test
-       public void testGetViewVisualStyleMap() {
+       public void testDefaultGetViewVisualStyleMap() {
+               session = new CySession.Builder().build();
                assertNotNull(session);
                assertNotNull(session.getViewVisualStyleMap());
        }
+
+       @Test
+       public void testSetNullViewVisualStyleMap() {
+               session = new 
CySession.Builder().viewVisualStyleMap(null).build();
+               assertNotNull(session);
+               assertNotNull(session.getViewVisualStyleMap());
+               assertEquals(0,session.getViewVisualStyleMap().size());
+       }
+
+       @Test
+       public void testSetViewVisualStyleMap() {
+               CyNetworkView nv1 = mock(CyNetworkView.class); 
+               CyNetworkView nv2 = mock(CyNetworkView.class); 
+
+               Map<CyNetworkView,String> vsm = new 
HashMap<CyNetworkView,String>();
+               vsm.put(nv1,"vs1");
+               vsm.put(nv2,"vs2");
+
+               session = new 
CySession.Builder().viewVisualStyleMap(vsm).build();
+               assertNotNull(session);
+               assertNotNull(session.getViewVisualStyleMap());
+               assertEquals(2,session.getViewVisualStyleMap().size());
+               assertTrue(session.getViewVisualStyleMap().containsKey(nv1));
+               assertTrue(session.getViewVisualStyleMap().containsKey(nv2));
+               assertEquals("vs1",session.getViewVisualStyleMap().get(nv1));
+               assertEquals("vs2",session.getViewVisualStyleMap().get(nv2));
+       }
        
        @Test
-       public void testGetCytoscapeProperties() {
+       public void testDefaultGetCytoscapeProperties() {
+               session = new CySession.Builder().build();
                assertNotNull(session);
                assertNotNull(session.getCytoscapeProperties());
        }
 
        @Test
-       public void testGetVizmapProperties() {
+       public void testSetNullCytoscapeProperties() {
+               session = new 
CySession.Builder().cytoscapeProperties(null).build();
                assertNotNull(session);
+               assertNotNull(session.getCytoscapeProperties());
+               assertEquals(0,session.getCytoscapeProperties().size());
+       }
+
+       @Test
+       public void testSetCytoscapeProperties() {
+               session = new 
CySession.Builder().cytoscapeProperties(getFakeProps()).build();
+               assertNotNull(session);
+               checkProps(session.getCytoscapeProperties());
+       }
+
+       @Test
+       public void testDefaultGetVizmapProperties() {
+               session = new CySession.Builder().build();
+               assertNotNull(session);
                assertNotNull(session.getVizmapProperties());
        }
 
        @Test
-       public void testGetDesktopProperties() {
+       public void testSetNullVizmapProperties() {
+               session = new 
CySession.Builder().vizmapProperties(null).build();
                assertNotNull(session);
+               assertNotNull(session.getVizmapProperties());
+               assertEquals(0,session.getVizmapProperties().size());
+       }
+
+       @Test
+       public void testSetVizmapProperties() {
+               session = new 
CySession.Builder().vizmapProperties(getFakeProps()).build();
+               assertNotNull(session);
+               checkProps(session.getVizmapProperties());
+       }
+
+       @Test
+       public void testDefaultGetDesktopProperties() {
+               session = new CySession.Builder().build();
+               assertNotNull(session);
                assertNotNull(session.getDesktopProperties());
        }
 
        @Test
-       public void testGetPluginFileListMap() {
+       public void testSetNullDesktopProperties() {
+               session = new 
CySession.Builder().desktopProperties(null).build();
                assertNotNull(session);
+               assertNotNull(session.getDesktopProperties());
+               assertEquals(0,session.getDesktopProperties().size());
+       }
+
+       @Test
+       public void testSetDesktopProperties() {
+               session = new 
CySession.Builder().desktopProperties(getFakeProps()).build();
+               assertNotNull(session);
+               checkProps(session.getDesktopProperties());
+       }
+
+       @Test
+       public void testDefaultGetPluginFileListMap() {
+               session = new CySession.Builder().build();
+               assertNotNull(session);
                assertNotNull(session.getPluginFileListMap());
        }
+
+       @Test
+       public void testSetNullPluginFileListMap() {
+               session = new 
CySession.Builder().pluginFileListMap(null).build();
+               assertNotNull(session);
+               assertNotNull(session.getPluginFileListMap());
+               assertEquals(0,session.getPluginFileListMap().size());
+       }
+
+       @Test
+       public void testSetPluginFileListMap() {
+               File f1 = new File("f1");
+               File f2 = new File("f2");
+
+               List<File> l1 = new ArrayList<File>();
+               l1.add(f1);
+               l1.add(f2);
+
+               File f3 = new File("f3");
+               File f4 = new File("f4");
+
+               List<File> l2 = new ArrayList<File>();
+               l1.add(f3);
+               l1.add(f4);
+
+               Map<String,List<File>> pflm = new HashMap<String,List<File>>();
+               pflm.put("plugin1",l1);
+               pflm.put("plugin2",l2);
+
+               session = new 
CySession.Builder().pluginFileListMap(pflm).build();
+               assertNotNull(session);
+               assertNotNull(session.getPluginFileListMap());
+               assertEquals(2,session.getPluginFileListMap().size());
+               assertEquals(l1,session.getPluginFileListMap().get("plugin1"));
+               assertEquals(l2,session.getPluginFileListMap().get("plugin2"));
+       }
+
+
+       private void checkProps(Properties p) {
+               assertNotNull(p);
+               assertEquals(2,p.size());
+               assertEquals("value1",p.getProperty("key1"));
+               assertEquals("value2",p.getProperty("key2"));
+       }
+
+       private Properties getFakeProps() {
+               Properties p = new Properties();
+               p.setProperty("key1","value1");
+               p.setProperty("key2","value2");
+               return p;
+       }
 }

-- 
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.

Reply via email to