2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.datamodel;
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;
28 import jalview.util.MapList;
30 import org.testng.annotations.Test;
32 public class DBRefEntryTest
36 * Tests for the method that compares equality of reference (but not mapping)
38 @Test(groups = { "Functional" })
39 public void testEqualRef()
41 DBRefEntry ref1 = new DBRefEntry("UNIPROT", "1", "V71633");
42 assertTrue(ref1.equalRef(ref1));
43 assertFalse(ref1.equalRef(null));
45 // comparison is not case sensitive
46 DBRefEntry ref2 = new DBRefEntry("uniprot", "1", "v71633");
47 assertTrue(ref1.equalRef(ref2));
48 assertTrue(ref2.equalRef(ref1));
50 // source, version and accessionid must match
51 assertFalse(ref1.equalRef(new DBRefEntry("UNIPRO", "1", "V71633")));
52 assertFalse(ref1.equalRef(new DBRefEntry("UNIPROT", "2", "V71633")));
53 assertFalse(ref1.equalRef(new DBRefEntry("UNIPROT", "1", "V71632")));
55 // presence of or differences in mappings are ignored
56 ref1.setMap(new Mapping(new MapList(new int[] { 1, 3 }, new int[] { 1,
58 assertTrue(ref1.equalRef(ref2));
59 assertTrue(ref2.equalRef(ref1));
60 ref1.setMap(new Mapping(new MapList(new int[] { 1, 6 }, new int[] { 1,
62 assertTrue(ref1.equalRef(ref2));
63 assertTrue(ref2.equalRef(ref1));
67 * Tests for the method that may update a DBRefEntry from another with a
68 * mapping or 'real' version
70 @Test(groups = { "Functional" })
71 public void testUpdateFrom()
73 DBRefEntry ref1 = new DBRefEntry("UNIPROT", "1", "V71633");
75 assertFalse(ref1.updateFrom(null));
78 * equivalent other dbref
80 DBRefEntry ref2 = new DBRefEntry("uniprot", "1", "v71633");
81 assertTrue(ref1.updateFrom(ref2));
82 assertEquals("UNIPROT", ref1.getSource()); // unchanged
83 assertEquals("V71633", ref1.getAccessionId()); // unchanged
86 * ref1 has no mapping, acquires mapping from ref2
88 Mapping map = new Mapping(new MapList(new int[] { 1, 3 }, new int[] {
91 assertTrue(ref1.updateFrom(ref2));
92 assertSame(map, ref1.getMap()); // null mapping updated
95 * ref1 has a mapping, does not acquire mapping from ref2
97 ref2.setMap(new Mapping(map));
98 assertTrue(ref1.updateFrom(ref2));
99 assertSame(map, ref1.getMap()); // non-null mapping not updated
102 * ref2 has a different source, accession or version
104 ref2.setSource("pdb");
105 assertFalse(ref1.updateFrom(ref2));
106 ref2.setSource(ref1.getSource());
107 ref2.setAccessionId("P12345");
108 assertFalse(ref1.updateFrom(ref2));
109 ref2.setAccessionId(ref1.getAccessionId());
110 ref1.setVersion("2");
111 assertFalse(ref1.updateFrom(ref2));
114 * a non-null version supersedes "0" or "source:0"
116 ref2.setVersion(null);
117 assertFalse(ref1.updateFrom(ref2));
118 assertEquals("2", ref1.getVersion());
119 ref2.setVersion("3");
120 ref1.setVersion("0");
121 assertTrue(ref1.updateFrom(ref2));
122 assertEquals("3", ref1.getVersion());
123 ref1.setVersion("UNIPROT:0");
124 assertTrue(ref1.updateFrom(ref2));
125 assertEquals("3", ref1.getVersion());
128 * version "source:n" with n>0 is not superseded
130 ref1.setVersion("UNIPROT:1");
131 assertFalse(ref1.updateFrom(ref2));
132 assertEquals("UNIPROT:1", ref1.getVersion());
135 * version "10" is not superseded
137 ref1.setVersion("10");
138 assertFalse(ref1.updateFrom(ref2));
139 assertEquals("10", ref1.getVersion());