Author: kono
Date: 2012-04-17 16:00:34 -0700 (Tue, 17 Apr 2012)
New Revision: 28871
Added:
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/BasicCyFileFilterTest.java
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/CyFileFilterTest.java
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/DataCategoryTest.java
core3/api/trunk/io-api/src/test/resources/filterTest.xml
Modified:
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java
Log:
refs #865 New test cases had been added to io-api.
Modified:
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java
===================================================================
---
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java
2012-04-17 22:54:35 UTC (rev 28870)
+++
core3/api/trunk/io-api/src/main/java/org/cytoscape/io/BasicCyFileFilter.java
2012-04-17 23:00:34 UTC (rev 28871)
@@ -4,12 +4,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.net.MalformedURLException;
import java.net.URI;
import java.net.URLConnection;
-import java.util.Set;
import java.util.HashSet;
-import javax.swing.filechooser.FileFilter;
+import java.util.Set;
+
import org.cytoscape.io.util.StreamUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,8 +38,7 @@
* @param category The type of data this filter is meant to support.
* @param streamUtil An instance of the StreamUtil service.
*/
- public BasicCyFileFilter(final Set<String> extensions,
- final Set<String> contentTypes, final String
description,
+ public BasicCyFileFilter(final Set<String> extensions, final
Set<String> contentTypes, final String description,
final DataCategory category, StreamUtil streamUtil) {
this.extensions = extensions;
@@ -98,42 +96,13 @@
}
private boolean extensionsMatch(URI uri){
- String extension = getExtension(uri.toString());
- //logger.info("******URI extension is" + extension + "the task
extension is" + this.extensions);
-
+ final String extension = getExtension(uri.toString());
if (extension != null && extensions.contains(extension))
return true;
else
return false;
}
-
-
- /*
- * The content types are not checked anymore since some of
- * readers have similar content types. Hence, the correct reader
- * wasn't picked up.
- */
- private boolean contentTypesMatch(URI uri){
- try {
- final URLConnection connection =
streamUtil.getURLConnection(uri.toURL());
- final String contentType = connection.getContentType();
- //logger.info("******URI content type is" + contentType
+ "the task content type is" + this.contentTypes);
- // Check for matching content type
- if ((contentType != null) &&
contentTypes.contains(contentType)) {
- logger.info("content type matches: " +
contentType);
- return true;
- }else
- return false;
-
-
- } catch (IOException ioe) {
- logger.warn("Caught an exception trying to check
content type",ioe);
- return false;
- }
-
- }
-
/**
* This method always returns false in this particular implementation.
You must extend
* this class and override this method to get alternative behavior.
Ideally this method
@@ -178,6 +147,7 @@
* Returns a human readable description of this class.
* @return a human readable description of this class.
*/
+ @Override
public String toString() {
String s = description + " [category: " + category + "]
[extensions: ";
for ( String ext : extensions )
Added:
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/BasicCyFileFilterTest.java
===================================================================
---
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/BasicCyFileFilterTest.java
(rev 0)
+++
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/BasicCyFileFilterTest.java
2012-04-17 23:00:34 UTC (rev 28871)
@@ -0,0 +1,52 @@
+package org.cytoscape.io;
+
+import static org.junit.Assert.*;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.HashSet;
+
+import org.cytoscape.io.util.StreamUtil;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class BasicCyFileFilterTest extends CyFileFilterTest {
+
+ private static final String XML_EXT = "xml";
+ private static final String XML_CONTENT_TYPE = "xml";
+ private static final String LOCAL_SAMPLE_FILE = "filterTest.xml";
+
+ @Mock
+ private StreamUtil streamUtil;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ extensions = new HashSet<String>();
+ extensions.add(XML_EXT);
+ contentTypes = new HashSet<String>();
+ contentTypes.add(XML_CONTENT_TYPE);
+ description = "test filter";
+ category = DataCategory.NETWORK;
+ final URL fileLocaiton =
this.getClass().getClassLoader().getResource(LOCAL_SAMPLE_FILE);
+ assertNotNull(fileLocaiton);
+ validURI = fileLocaiton.toURI();
+
+ this.filter = new BasicCyFileFilter(extensions, contentTypes,
description, category, streamUtil);
+ }
+
+ @Test @Override
+ public void testAcceptsInputStreamDataCategory() throws Exception {
+ assertNotNull(validURI);
+ assertFalse(filter.accepts(validURI.toURL().openStream(),
category));
+ }
+
+ @Test @Override
+ public void testGetDescription() {
+ assertEquals(description + " (*.xml)", filter.getDescription());
+ }
+
+}
Added:
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/CyFileFilterTest.java
===================================================================
--- core3/api/trunk/io-api/src/test/java/org/cytoscape/io/CyFileFilterTest.java
(rev 0)
+++ core3/api/trunk/io-api/src/test/java/org/cytoscape/io/CyFileFilterTest.java
2012-04-17 23:00:34 UTC (rev 28871)
@@ -0,0 +1,68 @@
+package org.cytoscape.io;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.Set;
+
+import org.junit.Test;
+
+public abstract class CyFileFilterTest {
+
+ protected CyFileFilter filter;
+
+ protected Set<String> extensions;
+ protected Set<String> contentTypes;
+ protected String description;
+ protected DataCategory category;
+
+ protected URI validURI;
+
+ @Test
+ public void testConstructor() throws Exception {
+ assertNotNull(extensions);
+ assertNotNull(contentTypes);
+ assertNotNull(description);
+ assertNotNull(category);
+ assertNotNull(filter);
+ }
+
+ @Test
+ public void testAcceptsURIDataCategory() throws Exception{
+ assertNotNull(validURI);
+ assertTrue(filter.accepts(validURI, category));
+ }
+
+ @Test
+ public void testAcceptsInputStreamDataCategory() throws Exception {
+ assertNotNull(validURI);
+ assertTrue(filter.accepts(validURI.toURL().openStream(),
category));
+ }
+
+ @Test
+ public void testGetExtensions() {
+ assertEquals(extensions, filter.getExtensions());
+ }
+
+ @Test
+ public void testGetContentTypes() {
+ assertEquals(contentTypes, filter.getContentTypes());
+ }
+
+ @Test
+ public abstract void testGetDescription();
+
+ @Test
+ public void testGetDataCategory() {
+ assertEquals(category, filter.getDataCategory());
+ }
+
+ @Test
+ public void testToString() {
+ assertNotNull(filter.toString());
+ }
+}
Added:
core3/api/trunk/io-api/src/test/java/org/cytoscape/io/DataCategoryTest.java
===================================================================
--- core3/api/trunk/io-api/src/test/java/org/cytoscape/io/DataCategoryTest.java
(rev 0)
+++ core3/api/trunk/io-api/src/test/java/org/cytoscape/io/DataCategoryTest.java
2012-04-17 23:00:34 UTC (rev 28871)
@@ -0,0 +1,24 @@
+package org.cytoscape.io;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DataCategoryTest {
+
+ @Test
+ public void testDataCategory() {
+ assertEquals(8, DataCategory.values().length);
+ assertEquals(DataCategory.IMAGE, DataCategory.valueOf("IMAGE"));
+ assertEquals(DataCategory.NETWORK,
DataCategory.valueOf("NETWORK"));
+ assertEquals(DataCategory.PROPERTIES,
DataCategory.valueOf("PROPERTIES"));
+ assertEquals(DataCategory.SCRIPT,
DataCategory.valueOf("SCRIPT"));
+ assertEquals(DataCategory.SESSION,
DataCategory.valueOf("SESSION"));
+ assertEquals(DataCategory.TABLE, DataCategory.valueOf("TABLE"));
+ assertEquals(DataCategory.UNSPECIFIED,
DataCategory.valueOf("UNSPECIFIED"));
+ assertEquals(DataCategory.VIZMAP,
DataCategory.valueOf("VIZMAP"));
+ }
+
+}
Added: core3/api/trunk/io-api/src/test/resources/filterTest.xml
===================================================================
--- core3/api/trunk/io-api/src/test/resources/filterTest.xml
(rev 0)
+++ core3/api/trunk/io-api/src/test/resources/filterTest.xml 2012-04-17
23:00:34 UTC (rev 28871)
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?>
\ No newline at end of file
--
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.