Revision: 920
http://obo.svn.sourceforge.net/obo/?rev=920&view=rev
Author: mgibson
Date: 2007-09-19 11:32:56 -0700 (Wed, 19 Sep 2007)
Log Message:
-----------
moved test classes from separate test dirctory (with same package name)
into the actual packages themselves -
as the separate test directory was totally screwing up eclipse
this just means test classes will intermingle with regular classes
no biggie
Added Paths:
-----------
phenote/trunk/src/java/phenote/UnitTests.java
phenote/trunk/src/java/phenote/gui/TestPhenote.java
phenote/trunk/src/java/phenote/util/FileUtilTest.java
phenote/trunk/src/java/phenote/util/TermLinkComparatorTest.java
Removed Paths:
-------------
phenote/trunk/src/java/test/phenote/UnitTests.java
phenote/trunk/src/java/test/phenote/gui/TestPhenote.java
phenote/trunk/src/java/test/phenote/util/FileUtilTest.java
phenote/trunk/src/java/test/phenote/util/TermLinkComparatorTest.java
Copied: phenote/trunk/src/java/phenote/UnitTests.java (from rev 919, phenote/trunk/src/java/test/phenote/UnitTests.java)
===================================================================
--- phenote/trunk/src/java/phenote/UnitTests.java (rev 0)
+++ phenote/trunk/src/java/phenote/UnitTests.java 2007-09-19 18:32:56 UTC (rev 920)
@@ -0,0 +1,26 @@
+package phenote;
+
+import junit.framework.TestSuite;
+import junit.framework.JUnit4TestAdapter;
+import junit.textui.TestRunner;
+import phenote.util.FileUtilTest;
+import phenote.gui.TestPhenote;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * This is the master unit test class that runs all registered unit tests (suite).
+ * Add your new unit test here if it is ready to be included in regular builds.
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ FileUtilTest.class,
+ TestPhenote.class
+ })
+
+public class UnitTests {
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(UnitTests.class);
+ }
+}
Copied: phenote/trunk/src/java/phenote/gui/TestPhenote.java (from rev 919, phenote/trunk/src/java/test/phenote/gui/TestPhenote.java)
===================================================================
--- phenote/trunk/src/java/phenote/gui/TestPhenote.java (rev 0)
+++ phenote/trunk/src/java/phenote/gui/TestPhenote.java 2007-09-19 18:32:56 UTC (rev 920)
@@ -0,0 +1,298 @@
+package phenote.gui;
+
+// move to main package??
+
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.ClipboardOwner;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.KeyEvent;
+import java.util.Calendar;
+import javax.swing.JList;
+import javax.swing.event.HyperlinkEvent;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull; // wierd
+import static org.junit.Assert.assertTrue;
+
+import phenote.datamodel.CharacterI;
+import phenote.datamodel.CharacterListI;
+import phenote.dataadapter.CharacterListManager;
+import phenote.dataadapter.fly.FlyCharacter;
+import phenote.dataadapter.fly.FlyCharList;
+import phenote.dataadapter.fly.FlyCharListTransferable;
+import phenote.dataadapter.fly.FlybaseDataAdapter;
+import phenote.util.HtmlUtil;
+import phenote.main.Phenote;
+import phenote.gui.field.FieldPanel;
+import phenote.gui.field.SearchParamPanel;
+import phenote.gui.field.AbstractAutoCompList;
+
+// making same package as phenotes giving us access to package methods!
+
+// dont need to subclass TestCase - does tests thgough annotations (1.5)
+public class TestPhenote {
+
+ // dont have handle on instance - have to do statics - wierd
+ private static Phenote phenote;
+ private static FieldPanel fieldPanel;
+ private static SearchParamPanel searchParamPanel;
+ private static AbstractAutoCompList entityComboBox;
+ private static AbstractAutoCompList qualityComboBox;
+ private static TermInfo termInfo;
+ private static CharacterTablePanel characterTablePanel;
+
+ /** @BeforeClass says to run this once before all the tests */
+ @BeforeClass public static void init() {
+ System.out.println("Initializing Phenote...");
+ Phenote.main(null);
+ // so the gui actually needs a little time to do layout on gui thread
+ // or else ACB.doComp() showPopup causes a hang - wierd!
+// System.out.println("sleeping...");
+// try {Thread.currentThread().sleep(5000); } // millis
+// catch (InterruptedException e) { System.out.println(e); }
+// System.out.println("^^^done sleeping - is gui ready?");
+ phenote = Phenote.getPhenote();
+ fieldPanel = phenote.getFieldPanel();
+ searchParamPanel = fieldPanel.getSearchParamPanel();
+ entityComboBox = fieldPanel.getEntityComboBox();
+ entityComboBox.setTestMode(true); // turns off popup, hanging bug only in test
+ qualityComboBox = fieldPanel.getQualityComboBox();
+ qualityComboBox.setTestMode(true);
+ termInfo = phenote.getTermInfo();
+ characterTablePanel = phenote.getCharacterTablePanel();
+ }
+
+ /** @Test is an annotation defined in Test - Test looks for Test methods */
+ @Test public void test() {
+ //selectionPopupTest(); not done proper
+ compListSelectionTest();
+ displayTermInfoOnCompMouseOverTest();
+ comboTermSelectionGoesToTableTest();
+ //synonymDupTest(); -- uses pase searchParamPanel
+ termInfoSelectTermTest();
+ //attributeInQualityCompletionTest(); --> need 3 keystrokes 'ttr'
+ //backspaceInComboBoxTest(); cant sim backspace.....
+ //flyDataAdapterTest(); out of date its now doing phenoxml - soon will be syntax
+ }
+
+ private void displayTermInfoOnCompMouseOverTest() {
+ System.out.println("Testing comp list mouse over term info...");
+ // "he" should have plenty of completion terms associated, heart, head...
+ boolean doCompletion = true;
+ System.out.println("set entity text to hea");
+ //entityComboBox.setText("hea",doCompletion);
+ // already have list from l from previous test - for some reason 2nd l doesnt jibe
+ // even though there are lots of quality terms with 'll' ???
+ //qualityComboBox.simulateLKeyStroke(); // just does 'l'
+ System.out.println("set text - getting 3rd term");
+ //JList entityJList = entityComboBox.getJList();
+ // pick 3rd item
+ //String thirdTerm = (String)entityJList.getModel().getElementAt(2);
+ //String thirdTerm = getEntityThirdAutoTerm();
+ String thirdTerm = getQualityThirdAutoTerm();
+ assertNotNull("3rd term from quality combo shouldnt be null",thirdTerm);
+ //entityJList.setSelectedIndex(2);
+ //entityComboBox.doMouseOver(2); // 2 is 3rd - 0 indexing
+ qualityComboBox.doMouseOver(2);
+
+ //String info = termInfo.getText();
+ // gets text in term field part where name is displayed
+ String info = termInfo.getTermFieldText();
+ //String properInfoPrefix = "Term: "+thirdTerm;
+ // this doesnt work anymore with mtml stuff in there...
+ //boolean isInfoProper = info.startsWith(properInfoPrefix);
+ boolean isInfoProper = info.contains(thirdTerm);
+
+ String msg = "term info should contain '"+thirdTerm
+ +"' not getting mouseover but its ["+info+"]";
+ assertTrue(msg,isInfoProper);
+ System.out.println("Completion mouse over term info test succeeded!");
+ }
+
+ private String getEntityThirdAutoTerm() {
+ return entityComboBox.getJComboBox().getModel().getElementAt(2).toString();
+ }
+
+ private String getQualityThirdAutoTerm() {
+ assertNotNull(qualityComboBox.getJComboBox().getModel());
+ assertNotNull("3rd term from quality combo shouldnt be null",
+ qualityComboBox.getJComboBox().getModel().getElementAt(2));
+ return qualityComboBox.getJComboBox().getModel().getElementAt(2).toString();
+ }
+
+ private String getQualityTerm(int index) {
+ assertNotNull(qualityComboBox.getJComboBox().getModel());
+ assertNotNull(index+" term from quality combo shouldnt be null",
+ qualityComboBox.getJComboBox().getModel().getElementAt(index));
+ return qualityComboBox.getJComboBox().getModel().getElementAt(index).toString();
+ }
+
+ /** Selecting item in entity combo box should cause that item to appear in
+ table in entity column */
+ private void comboTermSelectionGoesToTableTest() {
+ // selecting item should make it go in table...
+ System.out.println("Selecting 3rd entity item");
+ qualityComboBox.getJComboBox().setSelectedIndex(2); // 2 is 3rd
+ String selectedQualityTerm = getQualityThirdAutoTerm();
+ CharacterI selPheno = characterTablePanel.getSelectedCharacter();
+ String tableQuality = selPheno.getQuality().getName(); // oboclass
+ assertEquals(selectedQualityTerm,tableQuality);
+ System.out.println("term to table test passed, selected quality term "
+ +selectedQualityTerm+" quality in table "+tableQuality+"\n");
+ }
+
+ /** Test that attributes are being filtered out of quality term completion list */
+ private void attributeInQualityCompletionTest() {
+ boolean doCompletion = true;
+ System.out.println("Testing quality for attribute filtering");
+ // need to do this with key strokes now - set text doesnt work
+ // need at least 3 key strokes 'ttr' for attributes - i seem to have problems
+ // getting more than one key stroke in - hmmmmm
+ qualityComboBox.setText("attribute",doCompletion);
+ int count = qualityComboBox.getJComboBox().getItemCount();
+ String m = "Attributes are not being filtered out of Quality completion "+
+ "There are "+count+" terms with 'attribute'";
+ System.out.println("There are "+count+" attributes in comp list");
+ assertTrue(m,count == 0);
+ }
+
+ // cant get null pointer to fly - gotta love testing guis
+ /** theres a null pointer on selcting item for 1st time, not sure i can replicate
+ this is an awful test - assumes lacking physical part is the 2nd indexed
+ L term in quality
+ ontology - assumes theres a quality ontology */
+ private void compListSelectionTest() {
+ //qualityComboBox.setText("larg",true);
+ qualityComboBox.simulateLKeyStroke();
+ qualityComboBox.getJComboBox().setSelectedIndex(2);
+ // this is admittedly presumptious of quality
+ assertEquals("lacking physical part",qualityComboBox.getText());
+ System.out.println("comp list sel ok "+qualityComboBox.getText());
+ }
+
+ /** After term selected in comp list popup should not come up - this doesnt actually
+ test this - the popup does go away with setSelInd - only with mouse click it
+ sometimes doesnt - need simulated mouse click! */
+ private void selectionPopupTest() {
+ qualityComboBox.setText("larg",true);
+ qualityComboBox.getJComboBox().setSelectedIndex(2);
+ assertFalse(qualityComboBox.getJComboBox().isPopupVisible());
+ }
+
+ /** with searching on synonyms hit bug where terms come in more than once if have
+ 2 syns */
+ private void synonymDupTest() {
+ qualityComboBox.setText("");
+ // searchParamPanel not used anymore - need to set in menu
+ //searchParamPanel.setTermSearch(false);
+ //searchParamPanel.setSynonymSearch(true);
+ SearchParams.inst().setParam(SearchFilterType.TERM,false);
+ SearchParams.inst().setParam(SearchFilterType.SYN,true);
+ simulateAQualityKeyStroke();
+ String first = getQualityTerm(0);
+ String second = getQualityTerm(1);
+ assertFalse(first.equals(second));
+ }
+
+ // utlimatley need to do mouse click on term - how to do that???
+ private void termInfoSelectTermTest() {
+ simulatePhenoteHyperlinkUpdate();
+ String m = "term info hyper link test fail, term info should have body tone val "
+ +" term info: "+termInfo.getTermFieldText();
+ // how to make this test not so pato specific??
+ assertTrue(m,termInfo.getTermFieldText().contains("body tone value"));
+ }
+
+ private void simulatePhenoteHyperlinkUpdate() {
+ HyperlinkEvent.EventType type = HyperlinkEvent.EventType.ACTIVATED;
+ // 0000732 -> "BodyToneValue"
+ String desc = HtmlUtil.makePhenoIdLink("PATO:0000732");
+ HyperlinkEvent e = new HyperlinkEvent(termInfo,type,null,desc);
+ termInfo.simulateHyperlinkEvent(e);
+ }
+
+ private void simulateAQualityKeyStroke() {
+ simulateQualityKeyStroke(KeyEvent.VK_A,'a');
+ }
+
+ private void simulateQualityKeyStroke(int keyCode, char c) {
+ qualityComboBox.simulateKeyStroke(keyCode,c);
+ }
+
+ private void flyDataAdapterTest() {
+ CharacterListI cl = characterTablePanel.getCharacterList();
+ characterTablePanel.pressCommitButtonTest();
+ DataFlavor charListFlavor = FlyCharListTransferable.getCharListDataFlavor();
+ try {
+ Object o = getClipboard().getData(charListFlavor);
+ String m = "Failure: clipboard transferrable is not a FlyCharList "+o;
+ assertTrue(m,o instanceof FlyCharList);
+ FlyCharList fcl = (FlyCharList)o;
+ CharacterListI clipboardCharList = fcl.getCharacterList();
+ //assertEquals(clipboardCharList,cl); // its a clone???
+ assertTrue(clipboardCharList.equals(cl));
+
+ // simulate proforma - grab strings and recreate char list & shove in clipboard
+ // & load it up
+ FlyCharList newFlyCharList = new FlyCharList();
+ for (FlyCharacter fc : fcl.getFlyCharList()) {
+ FlyCharacter fcNew = new FlyCharacter(fc.getGenotype(),fc.getEVString());
+ newFlyCharList.addFlyChar(fcNew);
+ }
+ Transferable tr = new FlyCharListTransferable(newFlyCharList);
+ ClipboardOwner clipboardOwner = FlybaseDataAdapter.getClipboardOwner();
+ getClipboard().setContents(tr,clipboardOwner);
+
+ MenuManager.inst().getFileMenu().clickLoad();
+ CharacterListI newCL = CharacterListManager.inst().getCharacterList();
+ //assertEquals(cl,newCL); == NOT .equals()
+ assertTrue(cl.equals(newCL));
+ }
+ catch (Exception e) {
+ System.out.println("FAILURE: Exception thrown "+e);
+ e.printStackTrace();
+ }
+ }
+
+// // put in CharList class?
+// private boolean charListEquals(CharacterListI c1, CharacterListI c2) {
+// if (c1.size() != c2.size()) return false;
+// for (int i=0; i<c1.size(); i++) {
+// if (!c1.get(i).equals(c2,get(i)))
+// return false;
+// }
+// return true;
+// }
+
+ private Clipboard getClipboard() {
+ Toolkit t = Toolkit.getDefaultToolkit();
+ return t.getSystemClipboard();
+ }
+
+
+ // I cant find a way to simulate a backspace in jcombobox - very frustrating!!
+// /** there is/was a bug where delete/backspace was not triggering a new
+// completion list */
+// private void backspaceInComboBoxTest() {
+// boolean doCompletion = true;
+// qualityComboBox.clear();
+// qualityComboBox.setText("larg",doCompletion);
+// int preBackspaceCount = qualityComboBox.getItemCount();
+
+// // simulate backspace/delete key
+// KeyEvent ke = new KeyEvent(qualityComboBox,KeyEvent.VK_DELETE,Calendar.getInstance().getTimeInMillis(),0,KeyEvent.VK_UNDEFINED,KeyEvent.CHAR_UNDEFINED);
+// //qualityComboBox.processKeyEvent(ke);
+// qualityComboBox.getEditor().getEditorComponent().processKeyEvent(ke);
+
+// String postDelText = qualityComboBox.getText();
+// int postBackspaceCount = qualityComboBox.getItemCount();
+// System.out.println("post text "+postDelText+" pre count "+preBackspaceCount+" post count "+postBackspaceCount);
+// assertTrue(preBackspaceCount != postBackspaceCount);
+// }
+
+}
Copied: phenote/trunk/src/java/phenote/util/FileUtilTest.java (from rev 919, phenote/trunk/src/java/test/phenote/util/FileUtilTest.java)
===================================================================
--- phenote/trunk/src/java/phenote/util/FileUtilTest.java (rev 0)
+++ phenote/trunk/src/java/phenote/util/FileUtilTest.java 2007-09-19 18:32:56 UTC (rev 920)
@@ -0,0 +1,126 @@
+package phenote.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.junit.After;
+import org.junit.Before;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Unit test class for FileUtil.
+ */
+public class FileUtilTest {
+
+ private static final File testArchiveDir = new File("src" + FileUtil.FILE_SEPARATOR +
+ "java" + FileUtil.FILE_SEPARATOR +
+ "test", "test-archive-dir");
+ private static final File testLoadDirectory = new File("src" + FileUtil.FILE_SEPARATOR +
+ "java" + FileUtil.FILE_SEPARATOR +
+ "test", "test-load-dir");
+ private File testLoadFile;
+ private File testPurgeFile;
+
+ @Before
+ public void setUp() {
+ setTestDirectories();
+ }
+
+ @After
+ public void tearDown() {
+ cleanupTestFilesStructure();
+ }
+
+ /**
+ * Create a single file and archive it. Make sure it moved into the archive directory.
+ */
+ @Test
+ public void archiveFile() {
+ File archivedFile = FileUtil.archiveFile(testLoadFile, testArchiveDir);
+ File[] files = testArchiveDir.listFiles();
+ assertEquals("Number of files", 1, files.length);
+ assertEquals("File Name", archivedFile.getName(), files[0].getName());
+ assertTrue("Original File still exists", testLoadFile.exists());
+ }
+
+ /**
+ * Create a single file and archive it. Make sure it moved into the archive directory.
+ * Sleep for a second and then archive another file and then purge the first file while the
+ * second file does not get purged.
+ */
+ @Test
+ public void purgeArchiveFile() {
+ File archivedFile = FileUtil.archiveFile(testLoadFile, testArchiveDir);
+ File[] files = testArchiveDir.listFiles();
+ assertEquals("Number of files", 1, files.length);
+ assertEquals("File Name", archivedFile.getName(), files[0].getName());
+ assertTrue("Original File still exists", testLoadFile.exists());
+
+ // create the second file and wait a second before archiving it.
+ testPurgeFile = new File(testLoadDirectory, "test-file-two.txt");
+ try {
+ Thread.sleep(1000);
+ testPurgeFile.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+
+ archivedFile = FileUtil.archiveFile(testPurgeFile, testArchiveDir);
+ files = testArchiveDir.listFiles();
+ assertEquals("Number of files", 2, files.length);
+ FileUtil.purgeArchiveDirectory(testArchiveDir, 990);
+
+ files = testArchiveDir.listFiles();
+ assertEquals("Number of files", 1, files.length);
+ assertEquals("File Name", archivedFile.getName(), files[0].getName());
+
+ }
+
+ @Test
+ public void pureFilename() {
+ String fileNameOnly = "filenameAlpha.txt";
+ String filename = FileUtil.FILE_SEPARATOR + "dire" + FileUtil.FILE_SEPARATOR + fileNameOnly;
+ String pureFilename = FileUtil.getPureFileName(filename);
+ assertEquals("Pure File Name", fileNameOnly, pureFilename);
+
+ fileNameOnly = "";
+ pureFilename = FileUtil.getPureFileName(fileNameOnly);
+ assertEquals("Pure File Name", fileNameOnly, pureFilename);
+ }
+
+
+ /**
+ * Create the test directories before the tests are run.
+ */
+ private void setTestDirectories() {
+ testLoadDirectory.mkdir();
+
+ testLoadFile = new File(testLoadDirectory, "test-file-one.txt");
+ testPurgeFile = new File(testLoadDirectory, "test-file-two.txt");
+ try {
+ testLoadFile.createNewFile();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Remove test directories after the tests are done.
+ */
+ private void cleanupTestFilesStructure() {
+ testLoadFile.delete();
+ testPurgeFile.delete();
+ testLoadDirectory.delete();
+ File[] files = testArchiveDir.listFiles();
+ if (files != null)
+ for (File file : files) {
+ file.delete();
+ }
+ testArchiveDir.delete();
+ }
+
+}
Copied: phenote/trunk/src/java/phenote/util/TermLinkComparatorTest.java (from rev 919, phenote/trunk/src/java/test/phenote/util/TermLinkComparatorTest.java)
===================================================================
--- phenote/trunk/src/java/phenote/util/TermLinkComparatorTest.java (rev 0)
+++ phenote/trunk/src/java/phenote/util/TermLinkComparatorTest.java 2007-09-19 18:32:56 UTC (rev 920)
@@ -0,0 +1,90 @@
+package phenote.util;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.geneontology.oboedit.datamodel.Link;
+import org.geneontology.oboedit.datamodel.OBOProperty;
+import org.geneontology.oboedit.datamodel.impl.InstancePropertyValue;
+import org.geneontology.oboedit.datamodel.impl.OBOPropertyImpl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Unit test class for FileUtil.
+ */
+public class TermLinkComparatorTest extends TestCase {
+
+ public static void main(String args[]) {
+ TestRunner.run(TermLinkComparatorTest.suite());
+ }
+
+ public static Test suite() {
+ return new TestSuite(TermLinkComparatorTest.class);
+ }
+
+ /**
+ * Create a single file and archive it. Make sure it moved into the archive directory.
+ */
+ public void testIS_A_Before_PART_Of() {
+ List<InstancePropertyValue> links = new ArrayList<InstancePropertyValue>();
+ links.add(getLinkUnknownOne());
+ links.add(getLinkUnknownTwo());
+ links.add(getLinkDevelops_From());
+ links.add(getLinkPart_Of());
+ links.add(getLinkIS_A());
+
+ Collections.sort(links, new TermLinkComparator());
+
+ Link link = (Link) links.get(0);
+ assertEquals("IS a first", "is_a", link.getType().getName());
+ link = (Link) links.get(1);
+ assertEquals("Part of is second", "part of", link.getType().getName());
+ link = (Link) links.get(2);
+ assertEquals("Part of is second", "develops from", link.getType().getName());
+ link = (Link) links.get(3);
+ assertEquals("IS a first", "Unknown A", link.getType().getName());
+ link = (Link) links.get(4);
+ assertEquals("IS a first", "Unknown B", link.getType().getName());
+
+ }
+
+ private InstancePropertyValue getLinkIS_A(){
+ InstancePropertyValue link = new InstancePropertyValue();
+ OBOProperty prop = new OBOPropertyImpl(TermLinkComparator.RelationshipEnum.IS_A.getName());
+ link.setType(prop);
+ return link;
+ }
+
+ private InstancePropertyValue getLinkPart_Of(){
+ InstancePropertyValue link = new InstancePropertyValue();
+ OBOProperty prop = new OBOPropertyImpl(TermLinkComparator.RelationshipEnum.PART_OF.getName());
+ link.setType(prop);
+ return link;
+ }
+
+ private InstancePropertyValue getLinkDevelops_From(){
+ InstancePropertyValue link = new InstancePropertyValue();
+ OBOProperty prop = new OBOPropertyImpl(TermLinkComparator.RelationshipEnum.DEVELOPS_FROM.getName());
+ link.setType(prop);
+ return link;
+ }
+
+ private InstancePropertyValue getLinkUnknownOne(){
+ InstancePropertyValue link = new InstancePropertyValue();
+ OBOProperty prop = new OBOPropertyImpl("Unknown B");
+ link.setType(prop);
+ return link;
+ }
+
+ private InstancePropertyValue getLinkUnknownTwo(){
+ InstancePropertyValue link = new InstancePropertyValue();
+ OBOProperty prop = new OBOPropertyImpl("Unknown A");
+ link.setType(prop);
+ return link;
+ }
+
+}
Deleted: phenote/trunk/src/java/test/phenote/UnitTests.java
===================================================================
--- phenote/trunk/src/java/test/phenote/UnitTests.java 2007-09-18 17:46:08 UTC (rev 919)
+++ phenote/trunk/src/java/test/phenote/UnitTests.java 2007-09-19 18:32:56 UTC (rev 920)
@@ -1,26 +0,0 @@
-package phenote;
-
-import junit.framework.TestSuite;
-import junit.framework.JUnit4TestAdapter;
-import junit.textui.TestRunner;
-import phenote.util.FileUtilTest;
-import phenote.gui.TestPhenote;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * This is the master unit test class that runs all registered unit tests (suite).
- * Add your new unit test here if it is ready to be included in regular builds.
- */
-@...)
-@...({
- FileUtilTest.class,
- TestPhenote.class
- })
-
-public class UnitTests {
-
- public static junit.framework.Test suite() {
- return new JUnit4TestAdapter(UnitTests.class);
- }
-}
Deleted: phenote/trunk/src/java/test/phenote/gui/TestPhenote.java
===================================================================
--- phenote/trunk/src/java/test/phenote/gui/TestPhenote.java 2007-09-18 17:46:08 UTC (rev 919)
+++ phenote/trunk/src/java/test/phenote/gui/TestPhenote.java 2007-09-19 18:32:56 UTC (rev 920)
@@ -1,298 +0,0 @@
-package phenote.gui;
-
-// move to main package??
-
-import java.awt.Toolkit;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.ClipboardOwner;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.Transferable;
-import java.awt.event.KeyEvent;
-import java.util.Calendar;
-import javax.swing.JList;
-import javax.swing.event.HyperlinkEvent;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull; // wierd
-import static org.junit.Assert.assertTrue;
-
-import phenote.datamodel.CharacterI;
-import phenote.datamodel.CharacterListI;
-import phenote.dataadapter.CharacterListManager;
-import phenote.dataadapter.fly.FlyCharacter;
-import phenote.dataadapter.fly.FlyCharList;
-import phenote.dataadapter.fly.FlyCharListTransferable;
-import phenote.dataadapter.fly.FlybaseDataAdapter;
-import phenote.util.HtmlUtil;
-import phenote.main.Phenote;
-import phenote.gui.field.FieldPanel;
-import phenote.gui.field.SearchParamPanel;
-import phenote.gui.field.AbstractAutoCompList;
-
-// making same package as phenotes giving us access to package methods!
-
-// dont need to subclass TestCase - does tests thgough annotations (1.5)
-public class TestPhenote {
-
- // dont have handle on instance - have to do statics - wierd
- private static Phenote phenote;
- private static FieldPanel fieldPanel;
- private static SearchParamPanel searchParamPanel;
- private static AbstractAutoCompList entityComboBox;
- private static AbstractAutoCompList qualityComboBox;
- private static TermInfo termInfo;
- private static CharacterTablePanel characterTablePanel;
-
- /** @BeforeClass says to run this once before all the tests */
- @BeforeClass public static void init() {
- System.out.println("Initializing Phenote...");
- Phenote.main(null);
- // so the gui actually needs a little time to do layout on gui thread
- // or else ACB.doComp() showPopup causes a hang - wierd!
-// System.out.println("sleeping...");
-// try {Thread.currentThread().sleep(5000); } // millis
-// catch (InterruptedException e) { System.out.println(e); }
-// System.out.println("^^^done sleeping - is gui ready?");
- phenote = Phenote.getPhenote();
- fieldPanel = phenote.getFieldPanel();
- searchParamPanel = fieldPanel.getSearchParamPanel();
- entityComboBox = fieldPanel.getEntityComboBox();
- entityComboBox.setTestMode(true); // turns off popup, hanging bug only in test
- qualityComboBox = fieldPanel.getQualityComboBox();
- qualityComboBox.setTestMode(true);
- termInfo = phenote.getTermInfo();
- characterTablePanel = phenote.getCharacterTablePanel();
- }
-
- /** @Test is an annotation defined in Test - Test looks for Test methods */
- @Test public void test() {
- //selectionPopupTest(); not done proper
- compListSelectionTest();
- displayTermInfoOnCompMouseOverTest();
- comboTermSelectionGoesToTableTest();
- //synonymDupTest(); -- uses pase searchParamPanel
- termInfoSelectTermTest();
- //attributeInQualityCompletionTest(); --> need 3 keystrokes 'ttr'
- //backspaceInComboBoxTest(); cant sim backspace.....
- //flyDataAdapterTest(); out of date its now doing phenoxml - soon will be syntax
- }
-
- private void displayTermInfoOnCompMouseOverTest() {
- System.out.println("Testing comp list mouse over term info...");
- // "he" should have plenty of completion terms associated, heart, head...
- boolean doCompletion = true;
- System.out.println("set entity text to hea");
- //entityComboBox.setText("hea",doCompletion);
- // already have list from l from previous test - for some reason 2nd l doesnt jibe
- // even though there are lots of quality terms with 'll' ???
- //qualityComboBox.simulateLKeyStroke(); // just does 'l'
- System.out.println("set text - getting 3rd term");
- //JList entityJList = entityComboBox.getJList();
- // pick 3rd item
- //String thirdTerm = (String)entityJList.getModel().getElementAt(2);
- //String thirdTerm = getEntityThirdAutoTerm();
- String thirdTerm = getQualityThirdAutoTerm();
- assertNotNull("3rd term from quality combo shouldnt be null",thirdTerm);
- //entityJList.setSelectedIndex(2);
- //entityComboBox.doMouseOver(2); // 2 is 3rd - 0 indexing
- qualityComboBox.doMouseOver(2);
-
- //String info = termInfo.getText();
- // gets text in term field part where name is displayed
- String info = termInfo.getTermFieldText();
- //String properInfoPrefix = "Term: "+thirdTerm;
- // this doesnt work anymore with mtml stuff in there...
- //boolean isInfoProper = info.startsWith(properInfoPrefix);
- boolean isInfoProper = info.contains(thirdTerm);
-
- String msg = "term info should contain '"+thirdTerm
- +"' not getting mouseover but its ["+info+"]";
- assertTrue(msg,isInfoProper);
- System.out.println("Completion mouse over term info test succeeded!");
- }
-
- private String getEntityThirdAutoTerm() {
- return entityComboBox.getJComboBox().getModel().getElementAt(2).toString();
- }
-
- private String getQualityThirdAutoTerm() {
- assertNotNull(qualityComboBox.getJComboBox().getModel());
- assertNotNull("3rd term from quality combo shouldnt be null",
- qualityComboBox.getJComboBox().getModel().getElementAt(2));
- return qualityComboBox.getJComboBox().getModel().getElementAt(2).toString();
- }
-
- private String getQualityTerm(int index) {
- assertNotNull(qualityComboBox.getJComboBox().getModel());
- assertNotNull(index+" term from quality combo shouldnt be null",
- qualityComboBox.getJComboBox().getModel().getElementAt(index));
- return qualityComboBox.getJComboBox().getModel().getElementAt(index).toString();
- }
-
- /** Selecting item in entity combo box should cause that item to appear in
- table in entity column */
- private void comboTermSelectionGoesToTableTest() {
- // selecting item should make it go in table...
- System.out.println("Selecting 3rd entity item");
- qualityComboBox.getJComboBox().setSelectedIndex(2); // 2 is 3rd
- String selectedQualityTerm = getQualityThirdAutoTerm();
- CharacterI selPheno = characterTablePanel.getSelectedCharacter();
- String tableQuality = selPheno.getQuality().getName(); // oboclass
- assertEquals(selectedQualityTerm,tableQuality);
- System.out.println("term to table test passed, selected quality term "
- +selectedQualityTerm+" quality in table "+tableQuality+"\n");
- }
-
- /** Test that attributes are being filtered out of quality term completion list */
- private void attributeInQualityCompletionTest() {
- boolean doCompletion = true;
- System.out.println("Testing quality for attribute filtering");
- // need to do this with key strokes now - set text doesnt work
- // need at least 3 key strokes 'ttr' for attributes - i seem to have problems
- // getting more than one key stroke in - hmmmmm
- qualityComboBox.setText("attribute",doCompletion);
- int count = qualityComboBox.getJComboBox().getItemCount();
- String m = "Attributes are not being filtered out of Quality completion "+
- "There are "+count+" terms with 'attribute'";
- System.out.println("There are "+count+" attributes in comp list");
- assertTrue(m,count == 0);
- }
-
- // cant get null pointer to fly - gotta love testing guis
- /** theres a null pointer on selcting item for 1st time, not sure i can replicate
- this is an awful test - assumes lacking physical part is the 2nd indexed
- L term in quality
- ontology - assumes theres a quality ontology */
- private void compListSelectionTest() {
- //qualityComboBox.setText("larg",true);
- qualityComboBox.simulateLKeyStroke();
- qualityComboBox.getJComboBox().setSelectedIndex(2);
- // this is admittedly presumptious of quality
- assertEquals("lacking physical part",qualityComboBox.getText());
- System.out.println("comp list sel ok "+qualityComboBox.getText());
- }
-
- /** After term selected in comp list popup should not come up - this doesnt actually
- test this - the popup does go away with setSelInd - only with mouse click it
- sometimes doesnt - need simulated mouse click! */
- private void selectionPopupTest() {
- qualityComboBox.setText("larg",true);
- qualityComboBox.getJComboBox().setSelectedIndex(2);
- assertFalse(qualityComboBox.getJComboBox().isPopupVisible());
- }
-
- /** with searching on synonyms hit bug where terms come in more than once if have
- 2 syns */
- private void synonymDupTest() {
- qualityComboBox.setText("");
- // searchParamPanel not used anymore - need to set in menu
- //searchParamPanel.setTermSearch(false);
- //searchParamPanel.setSynonymSearch(true);
- SearchParams.inst().setParam(SearchFilterType.TERM,false);
- SearchParams.inst().setParam(SearchFilterType.SYN,true);
- simulateAQualityKeyStroke();
- String first = getQualityTerm(0);
- String second = getQualityTerm(1);
- assertFalse(first.equals(second));
- }
-
- // utlimatley need to do mouse click on term - how to do that???
- private void termInfoSelectTermTest() {
- simulatePhenoteHyperlinkUpdate();
- String m = "term info hyper link test fail, term info should have body tone val "
- +" term info: "+termInfo.getTermFieldText();
- // how to make this test not so pato specific??
- assertTrue(m,termInfo.getTermFieldText().contains("body tone value"));
- }
-
- private void simulatePhenoteHyperlinkUpdate() {
- HyperlinkEvent.EventType type = HyperlinkEvent.EventType.ACTIVATED;
- // 0000732 -> "BodyToneValue"
- String desc = HtmlUtil.makePhenoIdLink("PATO:0000732");
- HyperlinkEvent e = new HyperlinkEvent(termInfo,type,null,desc);
- termInfo.simulateHyperlinkEvent(e);
- }
-
- private void simulateAQualityKeyStroke() {
- simulateQualityKeyStroke(KeyEvent.VK_A,'a');
- }
-
- private void simulateQualityKeyStroke(int keyCode, char c) {
- qualityComboBox.simulateKeyStroke(keyCode,c);
- }
-
- private void flyDataAdapterTest() {
- CharacterListI cl = characterTablePanel.getCharacterList();
- characterTablePanel.pressCommitButtonTest();
- DataFlavor charListFlavor = FlyCharListTransferable.getCharListDataFlavor();
- try {
- Object o = getClipboard().getData(charListFlavor);
- String m = "Failure: clipboard transferrable is not a FlyCharList "+o;
- assertTrue(m,o instanceof FlyCharList);
- FlyCharList fcl = (FlyCharList)o;
- CharacterListI clipboardCharList = fcl.getCharacterList();
- //assertEquals(clipboardCharList,cl); // its a clone???
- assertTrue(clipboardCharList.equals(cl));
-
- // simulate proforma - grab strings and recreate char list & shove in clipboard
- // & load it up
- FlyCharList newFlyCharList = new FlyCharList();
- for (FlyCharacter fc : fcl.getFlyCharList()) {
- FlyCharacter fcNew = new FlyCharacter(fc.getGenotype(),fc.getEVString());
- newFlyCharList.addFlyChar(fcNew);
- }
- Transferable tr = new FlyCharListTransferable(newFlyCharList);
- ClipboardOwner clipboardOwner = FlybaseDataAdapter.getClipboardOwner();
- getClipboard().setContents(tr,clipboardOwner);
-
- MenuManager.inst().getFileMenu().clickLoad();
- CharacterListI newCL = CharacterListManager.inst().getCharacterList();
- //assertEquals(cl,newCL); == NOT .equals()
- assertTrue(cl.equals(newCL));
- }
- catch (Exception e) {
- System.out.println("FAILURE: Exception thrown "+e);
- e.printStackTrace();
- }
- }
-
-// // put in CharList class?
-// private boolean charListEquals(CharacterListI c1, CharacterListI c2) {
-// if (c1.size() != c2.size()) return false;
-// for (int i=0; i<c1.size(); i++) {
-// if (!c1.get(i).equals(c2,get(i)))
-// return false;
-// }
-// return true;
-// }
-
- private Clipboard getClipboard() {
- Toolkit t = Toolkit.getDefaultToolkit();
- return t.getSystemClipboard();
- }
-
-
- // I cant find a way to simulate a backspace in jcombobox - very frustrating!!
-// /** there is/was a bug where delete/backspace was not triggering a new
-// completion list */
-// private void backspaceInComboBoxTest() {
-// boolean doCompletion = true;
-// qualityComboBox.clear();
-// qualityComboBox.setText("larg",doCompletion);
-// int preBackspaceCount = qualityComboBox.getItemCount();
-
-// // simulate backspace/delete key
-// KeyEvent ke = new KeyEvent(qualityComboBox,KeyEvent.VK_DELETE,Calendar.getInstance().getTimeInMillis(),0,KeyEvent.VK_UNDEFINED,KeyEvent.CHAR_UNDEFINED);
-// //qualityComboBox.processKeyEvent(ke);
-// qualityComboBox.getEditor().getEditorComponent().processKeyEvent(ke);
-
-// String postDelText = qualityComboBox.getText();
-// int postBackspaceCount = qualityComboBox.getItemCount();
-// System.out.println("post text "+postDelText+" pre count "+preBackspaceCount+" post count "+postBackspaceCount);
-// assertTrue(preBackspaceCount != postBackspaceCount);
-// }
-
-}
Deleted: phenote/trunk/src/java/test/phenote/util/FileUtilTest.java
===================================================================
--- phenote/trunk/src/java/test/phenote/util/FileUtilTest.java 2007-09-18 17:46:08 UTC (rev 919)
+++ phenote/trunk/src/java/test/phenote/util/FileUtilTest.java 2007-09-19 18:32:56 UTC (rev 920)
@@ -1,126 +0,0 @@
-package phenote.util;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-import org.junit.After;
-import org.junit.Before;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Unit test class for FileUtil.
- */
-public class FileUtilTest {
-
- private static final File testArchiveDir = new File("src" + FileUtil.FILE_SEPARATOR +
- "java" + FileUtil.FILE_SEPARATOR +
- "test", "test-archive-dir");
- private static final File testLoadDirectory = new File("src" + FileUtil.FILE_SEPARATOR +
- "java" + FileUtil.FILE_SEPARATOR +
- "test", "test-load-dir");
- private File testLoadFile;
- private File testPurgeFile;
-
- @Before
- public void setUp() {
- setTestDirectories();
- }
-
- @After
- public void tearDown() {
- cleanupTestFilesStructure();
- }
-
- /**
- * Create a single file and archive it. Make sure it moved into the archive directory.
- */
- @Test
- public void archiveFile() {
- File archivedFile = FileUtil.archiveFile(testLoadFile, testArchiveDir);
- File[] files = testArchiveDir.listFiles();
- assertEquals("Number of files", 1, files.length);
- assertEquals("File Name", archivedFile.getName(), files[0].getName());
- assertTrue("Original File still exists", testLoadFile.exists());
- }
-
- /**
- * Create a single file and archive it. Make sure it moved into the archive directory.
- * Sleep for a second and then archive another file and then purge the first file while the
- * second file does not get purged.
- */
- @Test
- public void purgeArchiveFile() {
- File archivedFile = FileUtil.archiveFile(testLoadFile, testArchiveDir);
- File[] files = testArchiveDir.listFiles();
- assertEquals("Number of files", 1, files.length);
- assertEquals("File Name", archivedFile.getName(), files[0].getName());
- assertTrue("Original File still exists", testLoadFile.exists());
-
- // create the second file and wait a second before archiving it.
- testPurgeFile = new File(testLoadDirectory, "test-file-two.txt");
- try {
- Thread.sleep(1000);
- testPurgeFile.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
-
- archivedFile = FileUtil.archiveFile(testPurgeFile, testArchiveDir);
- files = testArchiveDir.listFiles();
- assertEquals("Number of files", 2, files.length);
- FileUtil.purgeArchiveDirectory(testArchiveDir, 990);
-
- files = testArchiveDir.listFiles();
- assertEquals("Number of files", 1, files.length);
- assertEquals("File Name", archivedFile.getName(), files[0].getName());
-
- }
-
- @Test
- public void pureFilename() {
- String fileNameOnly = "filenameAlpha.txt";
- String filename = FileUtil.FILE_SEPARATOR + "dire" + FileUtil.FILE_SEPARATOR + fileNameOnly;
- String pureFilename = FileUtil.getPureFileName(filename);
- assertEquals("Pure File Name", fileNameOnly, pureFilename);
-
- fileNameOnly = "";
- pureFilename = FileUtil.getPureFileName(fileNameOnly);
- assertEquals("Pure File Name", fileNameOnly, pureFilename);
- }
-
-
- /**
- * Create the test directories before the tests are run.
- */
- private void setTestDirectories() {
- testLoadDirectory.mkdir();
-
- testLoadFile = new File(testLoadDirectory, "test-file-one.txt");
- testPurgeFile = new File(testLoadDirectory, "test-file-two.txt");
- try {
- testLoadFile.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Remove test directories after the tests are done.
- */
- private void cleanupTestFilesStructure() {
- testLoadFile.delete();
- testPurgeFile.delete();
- testLoadDirectory.delete();
- File[] files = testArchiveDir.listFiles();
- if (files != null)
- for (File file : files) {
- file.delete();
- }
- testArchiveDir.delete();
- }
-
-}
Deleted: phenote/trunk/src/java/test/phenote/util/TermLinkComparatorTest.java
===================================================================
--- phenote/trunk/src/java/test/phenote/util/TermLinkComparatorTest.java 2007-09-18 17:46:08 UTC (rev 919)
+++ phenote/trunk/src/java/test/phenote/util/TermLinkComparatorTest.java 2007-09-19 18:32:56 UTC (rev 920)
@@ -1,90 +0,0 @@
-package phenote.util;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-import org.geneontology.oboedit.datamodel.Link;
-import org.geneontology.oboedit.datamodel.OBOProperty;
-import org.geneontology.oboedit.datamodel.impl.InstancePropertyValue;
-import org.geneontology.oboedit.datamodel.impl.OBOPropertyImpl;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Unit test class for FileUtil.
- */
-public class TermLinkComparatorTest extends TestCase {
-
- public static void main(String args[]) {
- TestRunner.run(TermLinkComparatorTest.suite());
- }
-
- public static Test suite() {
- return new TestSuite(TermLinkComparatorTest.class);
- }
-
- /**
- * Create a single file and archive it. Make sure it moved into the archive directory.
- */
- public void testIS_A_Before_PART_Of() {
- List<InstancePropertyValue> links = new ArrayList<InstancePropertyValue>();
- links.add(getLinkUnknownOne());
- links.add(getLinkUnknownTwo());
- links.add(getLinkDevelops_From());
- links.add(getLinkPart_Of());
- links.add(getLinkIS_A());
-
- Collections.sort(links, new TermLinkComparator());
-
- Link link = (Link) links.get(0);
- assertEquals("IS a first", "is_a", link.getType().getName());
- link = (Link) links.get(1);
- assertEquals("Part of is second", "part of", link.getType().getName());
- link = (Link) links.get(2);
- assertEquals("Part of is second", "develops from", link.getType().getName());
- link = (Link) links.get(3);
- assertEquals("IS a first", "Unknown A", link.getType().getName());
- link = (Link) links.get(4);
- assertEquals("IS a first", "Unknown B", link.getType().getName());
-
- }
-
- private InstancePropertyValue getLinkIS_A(){
- InstancePropertyValue link = new InstancePropertyValue();
- OBOProperty prop = new OBOPropertyImpl(TermLinkComparator.RelationshipEnum.IS_A.getName());
- link.setType(prop);
- return link;
- }
-
- private InstancePropertyValue getLinkPart_Of(){
- InstancePropertyValue link = new InstancePropertyValue();
- OBOProperty prop = new OBOPropertyImpl(TermLinkComparator.RelationshipEnum.PART_OF.getName());
- link.setType(prop);
- return link;
- }
-
- private InstancePropertyValue getLinkDevelops_From(){
- InstancePropertyValue link = new InstancePropertyValue();
- OBOProperty prop = new OBOPropertyImpl(TermLinkComparator.RelationshipEnum.DEVELOPS_FROM.getName());
- link.setType(prop);
- return link;
- }
-
- private InstancePropertyValue getLinkUnknownOne(){
- InstancePropertyValue link = new InstancePropertyValue();
- OBOProperty prop = new OBOPropertyImpl("Unknown B");
- link.setType(prop);
- return link;
- }
-
- private InstancePropertyValue getLinkUnknownTwo(){
- InstancePropertyValue link = new InstancePropertyValue();
- OBOProperty prop = new OBOPropertyImpl("Unknown A");
- link.setType(prop);
- return link;
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|