Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.datamodel

File DBRefEntryTest.java

 

Code metrics

0
80
4
1
228
118
4
0.05
20
4
1

Classes

Class Line # Actions
DBRefEntryTest 34 80 4 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.datamodel;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertFalse;
25    import static org.testng.AssertJUnit.assertSame;
26    import static org.testng.AssertJUnit.assertTrue;
27   
28    import jalview.gui.JvOptionPane;
29    import jalview.util.MapList;
30   
31    import org.testng.annotations.BeforeClass;
32    import org.testng.annotations.Test;
33   
 
34    public class DBRefEntryTest
35    {
36   
 
37  1 toggle @BeforeClass(alwaysRun = true)
38    public void setUpJvOptionPane()
39    {
40  1 JvOptionPane.setInteractiveMode(false);
41  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
42    }
43   
44    /**
45    * Tests for the method that compares equality of reference (but not mapping)
46    */
 
47  1 toggle @Test(groups = { "Functional" })
48    public void testEqualRef()
49    {
50  1 DBRefEntry ref1 = new DBRefEntry("UNIPROT", "1", "V71633");
51  1 assertTrue(ref1.equalRef(ref1));
52  1 assertFalse(ref1.equalRef(null));
53   
54    // comparison is not case sensitive
55  1 DBRefEntry ref2 = new DBRefEntry("uniprot", "1", "v71633");
56  1 assertTrue(ref1.equalRef(ref2));
57  1 assertTrue(ref2.equalRef(ref1));
58   
59    // source, version and accessionid must match
60  1 assertFalse(ref1.equalRef(new DBRefEntry("UNIPRO", "1", "V71633")));
61  1 assertFalse(ref1.equalRef(new DBRefEntry("UNIPROT", "2", "V71633")));
62  1 assertFalse(ref1.equalRef(new DBRefEntry("UNIPROT", "1", "V71632")));
63   
64    // presence of or differences in mappings are ignored
65  1 ref1.setMap(new Mapping(new MapList(new int[] { 1, 3 }, new int[] { 1,
66    1 }, 3, 1)));
67  1 assertTrue(ref1.equalRef(ref2));
68  1 assertTrue(ref2.equalRef(ref1));
69  1 ref1.setMap(new Mapping(new MapList(new int[] { 1, 6 }, new int[] { 1,
70    2 }, 3, 1)));
71  1 assertTrue(ref1.equalRef(ref2));
72  1 assertTrue(ref2.equalRef(ref1));
73    }
74   
75    /**
76    * Tests for the method that may update a DBRefEntry from another with a
77    * mapping or 'real' version
78    */
 
79  1 toggle @Test(groups = { "Functional" })
80    public void testUpdateFrom()
81    {
82  1 DBRefEntry ref1 = new DBRefEntry("UNIPROT", "1", "V71633");
83   
84  1 assertFalse(ref1.updateFrom(null));
85   
86    /*
87    * equivalent other dbref
88    */
89  1 DBRefEntry ref2 = new DBRefEntry("uniprot", "1", "v71633");
90  1 assertTrue(ref1.updateFrom(ref2));
91  1 assertEquals("UNIPROT", ref1.getSource()); // unchanged
92  1 assertEquals("V71633", ref1.getAccessionId()); // unchanged
93   
94    /*
95    * ref1 has no mapping, acquires mapping from ref2
96    */
97  1 Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] {
98    1, 1 }, 3, 1));
99  1 ref2.setMap(map);
100  1 assertTrue(ref1.updateFrom(ref2));
101  1 assertSame(map, ref1.getMap()); // null mapping updated
102   
103    /*
104    * ref1 has a mapping, does not acquire mapping from ref2
105    */
106  1 ref2.setMap(new Mapping(map));
107  1 assertTrue(ref1.updateFrom(ref2));
108  1 assertSame(map, ref1.getMap()); // non-null mapping not updated
109   
110    /*
111    * ref2 has a different source, accession or version
112    */
113  1 ref2.setSource("pdb");
114  1 assertFalse(ref1.updateFrom(ref2));
115  1 ref2.setSource(ref1.getSource());
116  1 ref2.setAccessionId("P12345");
117  1 assertFalse(ref1.updateFrom(ref2));
118  1 ref2.setAccessionId(ref1.getAccessionId());
119  1 ref1.setVersion("2");
120  1 assertFalse(ref1.updateFrom(ref2));
121   
122    /*
123    * a non-null version supersedes "0" or "source:0"
124    */
125  1 ref2.setVersion(null);
126  1 assertFalse(ref1.updateFrom(ref2));
127  1 assertEquals("2", ref1.getVersion());
128  1 ref2.setVersion("3");
129  1 ref1.setVersion("0");
130  1 assertTrue(ref1.updateFrom(ref2));
131  1 assertEquals("3", ref1.getVersion());
132  1 ref1.setVersion("UNIPROT:0");
133  1 assertTrue(ref1.updateFrom(ref2));
134  1 assertEquals("3", ref1.getVersion());
135   
136    /*
137    * version "source:n" with n>0 is not superseded
138    */
139  1 ref1.setVersion("UNIPROT:1");
140  1 assertFalse(ref1.updateFrom(ref2));
141  1 assertEquals("UNIPROT:1", ref1.getVersion());
142   
143    /*
144    * version "10" is not superseded
145    */
146  1 ref1.setVersion("10");
147  1 assertFalse(ref1.updateFrom(ref2));
148  1 assertEquals("10", ref1.getVersion());
149    }
150   
 
151  1 toggle @Test(groups = { "Functional" })
152    public void testIsPrimaryCandidate()
153    {
154  1 DBRefEntry dbr = new DBRefEntry(DBRefSource.UNIPROT, "", "Q12345");
155  1 assertTrue(dbr.isPrimaryCandidate());
156   
157    /*
158    * 1:1 mapping - ok
159    */
160  1 dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 1, 3 }, 1,
161    1));
162  1 assertTrue(dbr.isPrimaryCandidate());
163   
164    /*
165    * 1:1 mapping of identical split ranges - not ok
166    */
167  1 dbr.setMap(new Mapping(null, new int[] { 1, 3, 6, 9 }, new int[] { 1,
168    3, 6, 9 }, 1, 1));
169  1 assertFalse(dbr.isPrimaryCandidate());
170   
171    /*
172    * 1:1 mapping of different ranges - not ok
173    */
174  1 dbr.setMap(new Mapping(null, new int[] { 1, 4 }, new int[] { 2, 5 }, 1,
175    1));
176  1 assertFalse(dbr.isPrimaryCandidate());
177   
178    /*
179    * 1:1 mapping of 'isoform' ranges - not ok
180    */
181  1 dbr.setMap(new Mapping(null, new int[] { 1, 2, 6, 9 }, new int[] { 1,
182    3, 7, 9 }, 1, 1));
183  1 assertFalse(dbr.isPrimaryCandidate());
184  1 dbr.setMap(null);
185  1 assertTrue(dbr.isPrimaryCandidate());
186   
187    /*
188    * Version string is prefixed with another dbref source string (fail)
189    */
190  1 dbr.setVersion(DBRefSource.EMBL + ":0");
191  1 assertFalse(dbr.isPrimaryCandidate());
192   
193    /*
194    * Version string is alphanumeric
195    */
196  1 dbr.setVersion("0.1.b");
197  1 assertTrue(dbr.isPrimaryCandidate());
198   
199    /*
200    * null version string can't be primary ref
201    */
202  1 dbr.setVersion(null);
203  1 assertFalse(dbr.isPrimaryCandidate());
204  1 dbr.setVersion("");
205  1 assertTrue(dbr.isPrimaryCandidate());
206   
207    /*
208    * 1:1 mapping and sequenceRef (fail)
209    */
210  1 dbr.setMap(new Mapping(new Sequence("foo", "ASDF"), new int[] { 1, 3 },
211    new int[] { 1, 3 }, 1, 1));
212  1 assertFalse(dbr.isPrimaryCandidate());
213   
214    /*
215    * 1:3 mapping (fail)
216    */
217  1 dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 1, 3 }, 1,
218    3));
219  1 assertFalse(dbr.isPrimaryCandidate());
220   
221    /*
222    * 2:2 mapping with shift (expected fail, but maybe use case for a pass)
223    */
224  1 dbr.setMap(new Mapping(null, new int[] { 1, 4 }, new int[] { 1, 4 }, 2,
225    2));
226  1 assertFalse(dbr.isPrimaryCandidate());
227    }
228    }