1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
*/
package org.biojava.ontology;
import junit.framework.TestCase;
import org.biojava.utils.ChangeVetoException;
/**
* Tests for Ontology.
*
* @author Thomas Down
* @author Matthew Pocock
* @author Moses Hohman
* @since 1.4
*/
public class OntologyTest extends TestCase {
private String name;
private String description;
private Ontology onto;
private Term animal;
private Term fish;
private Term mammal;
private Term human;
private Term isa;
private Triple fish_isa_animal;
private Triple mammal_isa_animal;
private Triple human_isa_mammal;
protected void setUp() throws Exception {
name = "Tester";
description = "Our Description";
onto = OntoTools.getDefaultFactory().createOntology(name, description);
isa = onto.importTerm(OntoTools.IS_A, null);
animal = onto.createTerm("Animal", "An animal");
fish = onto.createTerm("Fish", "A swimming, cold-blooded thingy");
mammal = onto.createTerm("Mammal", "A milk-producing quadraped");
human = onto.createTerm("Human", "Us");
fish_isa_animal = onto.createTriple(fish, animal, isa, null, null);
mammal_isa_animal = onto.createTriple(mammal, animal, isa, null, null);
human_isa_mammal = onto.createTriple(human, mammal, isa, null, null);
}
// basic properties
public void testName() {
assertEquals(onto.getName(), name);
}
public void testDescription() {
assertEquals(onto.getDescription(), description);
}
//terms
public void testTermsSize() {
assertEquals(8, onto.getTerms().size());
}
public void testTermsContainAnimal() {
assertTrue(onto.getTerms().contains(animal));
}
public void testTermsContainFish() {
assertTrue(onto.getTerms().contains(fish));
}
public void testTermsContainMammal() {
assertTrue(onto.getTerms().contains(mammal));
}
public void testTermsContainHuman() {
assertTrue(onto.getTerms().contains(human));
}
//terms by name
public void testGetAnimalByName() {
assertEquals(animal, onto.getTerm("Animal"));
}
// triples
public void testGetAllTriplesSize() {
assertEquals(3, onto.getTriples(null, null, null).size());
}
public void testGetAllTriplesContainsFishIsaAnimal() {
assertTrue(onto.getTriples(null, null, null).contains(fish_isa_animal));
}
public void testGetAllTriplesContainsMammalIsaAnimal() {
assertTrue(onto.getTriples(null, null, null).contains(mammal_isa_animal));
}
public void testGetAllTriplesContainsHumanIsaMammal() {
assertTrue(onto.getTriples(null, null, null).contains(human_isa_mammal));
}
// triple searching
public void testTripleSearchingByObject() {
assertEquals(2, onto.getTriples(null, animal, null).size());
assertEquals(1, onto.getTriples(null, mammal, null).size());
assertEquals(0, onto.getTriples(null, human, null).size());
}
public void testTripleSearchBySubject() {
assertEquals(1, onto.getTriples(onto.getTerm("Human"), null, null).size());
}
public void testTripleSearchingByRelation() {
assertEquals(3, onto.getTriples(null, null, isa).size());
}
public void testTripleSearchingWithAllTerms() {
assertEquals(1, onto.getTriples(human, mammal, isa).size());
assertEquals(0, onto.getTriples(human, animal, isa).size());
}
public void testTripleSearchForSameTermWithDifferentCriteria() {
assertEquals(onto.getTriples(human, null, isa), onto.getTriples(null, mammal, isa));
}
public void testCannotCreateDuplicateTerm() throws ChangeVetoException {
try {
onto.createTerm("Human", "Us");
fail("should have thrown an AlreadyExistsException");
} catch (AlreadyExistsException expected) {
}
}
public void testCannotCreateTripleTermWithForeignSubject() throws OntologyException, ChangeVetoException {
try {
Ontology onto2 = OntoTools.getDefaultFactory().createOntology("other", "");
onto.createTriple(onto2.createTerm("foreign term", ""), human, isa, null, null);
fail("Should have thrown an IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
}
public void testCannotCreateTripleTermWithForeignObject() throws OntologyException, ChangeVetoException {
try {
Ontology onto2 = OntoTools.getDefaultFactory().createOntology("other", "");
onto.createTriple(fish, onto2.createTerm("foreign term", ""), isa, null, null);
fail("Should have thrown an IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
}
public void testCannotCreateTripleTermWithForeignRelation() throws OntologyException, ChangeVetoException {
try {
Ontology onto2 = OntoTools.getDefaultFactory().createOntology("other", "");
onto.createTriple(human, fish, onto2.createTerm("wants a", ""), null, null);
fail("Should have thrown an IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
}
}
|