package uk.ac.ebi.quickgo.ontology.traversal;

import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

/**
 * Validate that ontology relationships are retrieved correctly.
 *
 * Created 20/05/16
 * @author Edd
 */
public class OntologyRelationTypeTest {
    @Test
    public void validRelationshipsCanBeRetrieved() {
        for (OntologyRelationType relation : OntologyRelationType.values()) {
            OntologyRelationType relationRetrieved = OntologyRelationType.getByShortName(relation.getShortName());
            assertThat(relationRetrieved, is(relation));
        }
    }

    @Test(expected = IllegalArgumentException.class)
    public void invalidRelationshipCausesIllegalArgumentException() {
        OntologyRelationType.getByShortName("THIS_DOES_NOT_EXIST");
    }
}
@@ -51,22 +51,223 @@
 ort 
-org.junit.Test
+java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.List;%0Aimport org.junit.Test;%0Aimport org.junit.experimental.runners.Enclosed;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.Parameterized
 ;%0A%0Ai
@@ -357,16 +357,91 @@
 hers.is;
+%0Aimport static uk.ac.ebi.quickgo.ontology.traversal.OntologyRelationType.*;
 %0A%0A/**%0A *
@@ -545,16 +545,41 @@
 Edd%0A */%0A
+@RunWith(Enclosed.class)%0A
 public c
@@ -610,16 +610,149 @@
 eTest %7B%0A
+    /**%0A     * Tests the ability to lookup relationships based on their short names%0A     */%0A    public static class LookupTest %7B%0A    
     @Tes
@@ -753,16 +753,20 @@
   @Test%0A
+    
     publ
@@ -818,16 +818,20 @@
         
+    
 for (Ont
@@ -888,24 +888,28 @@
 values()) %7B%0A
+    
             
@@ -1023,16 +1023,20 @@
         
+ 
+   
 assertTh
@@ -1084,17 +1084,29 @@
     
+    
 %7D%0A    
+ 
-%7D%0A%0A
+   %7D%0A%0A    
     
@@ -1154,24 +1154,28 @@
 .class)%0A    
+  
+  
 public void 
@@ -1228,32 +1228,36 @@
 ion() %7B%0A        
+    
 OntologyRelation
@@ -1300,15 +1300,2025 @@
 XIST%22);%0A
+        %7D%0A    %7D%0A%0A    /**%0A     * Tests all combinations of relationship transitivity according to%0A     * QuickGO's interpretation of ontology relationship transitivity rules%0A     */%0A    @RunWith(Parameterized.class)%0A    public static class RelationshipTransitivityTests %7B%0A        private final boolean startHasJoinedRelationType;%0A        private final OntologyRelationType joiningRelation;%0A        private final OntologyRelationType startRelation;%0A%0A        public RelationshipTransitivityTests(OntologyRelationType startRelation, OntologyRelationType%0A                joiningRelation, boolean startHasJoinedRelationType) %7B%0A            this.startRelation = startRelation;%0A            this.joiningRelation = joiningRelation;%0A            this.startHasJoinedRelationType = startHasJoinedRelationType;%0A        %7D%0A%0A        @Parameterized.Parameters(name = %22%7Bindex%7D: %7B0%7D.hasTransitiveType(%7B1%7D) = %7B2%7D%22)%0A        public static Collection%3CObject%5B%5D%3E data() %7B%0A            List%3CObject%5B%5D%3E testCaseParameters = new ArrayList%3C%3E();%0A%0A            for (OntologyRelationType startType : OntologyRelationType.values()) %7B%0A                for (OntologyRelationType joiningType : OntologyRelationType.values()) %7B%0A                    boolean hasTransitiveType = false;%0A                    if (joiningType == UNDEFINED%0A                            %7C%7C startType == IDENTITY%0A                            %7C%7C joiningType == startType%0A                            %7C%7C joiningType == REGULATES &&%0A                            (startType == POSITIVE_REGULATES %7C%7C startType == NEGATIVE_REGULATES)) %7B%0A                        hasTransitiveType = true;%0A                    %7D%0A                    testCaseParameters.add(new Object%5B%5D%7BstartType, joiningType, hasTransitiveType%7D);%0A                %7D%0A            %7D%0A%0A            return testCaseParameters;%0A        %7D%0A%0A        @Test%0A        public void testRelationshipTransitivity() %7B%0A            assertThat(this.startRelation.hasTransitiveType(this.joiningRelation), is(this.startHasJoinedRelationType));%0A        %7D%0A
     %7D%0A%7D

test exhaustively all combinations of relationshiptypes according to the relationship transitivity rules