3 import static org.testng.AssertJUnit.assertEquals;
5 import jalview.datamodel.SequenceFeature;
7 import java.util.Hashtable;
10 import org.testng.annotations.Test;
12 public class SequenceAnnotationReportTest
14 @Test(groups = "Functional")
15 public void testAppendFeature_disulfideBond()
17 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
18 StringBuffer sb = new StringBuffer();
20 SequenceFeature sf = new SequenceFeature("disulfide bond", "desc", 1,
23 // residuePos == 2 does not match start or end of feature, nothing done:
24 sar.appendFeature(sb, 2, null, sf);
25 assertEquals("123456", sb.toString());
27 // residuePos == 1 matches start of feature, text appended (but no <br>)
28 // feature score is not included
29 sar.appendFeature(sb, 1, null, sf);
30 assertEquals("123456disulfide bond 1:3", sb.toString());
32 // residuePos == 3 matches end of feature, text appended
33 // <br> is prefixed once sb.length() > 6
34 sar.appendFeature(sb, 3, null, sf);
35 assertEquals("123456disulfide bond 1:3<br>disulfide bond 1:3",
39 @Test(groups = "Functional")
40 public void testAppendFeature_status()
42 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
43 StringBuffer sb = new StringBuffer();
44 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
46 sf.setStatus("Confirmed");
48 sar.appendFeature(sb, 1, null, sf);
49 assertEquals("METAL 1 3; Fe2-S; (Confirmed)", sb.toString());
52 @Test(groups = "Functional")
53 public void testAppendFeature_withScore()
55 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
56 StringBuffer sb = new StringBuffer();
57 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
60 Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
61 sar.appendFeature(sb, 1, minmax, sf);
63 * map has no entry for this feature type - score is not shown:
65 assertEquals("METAL 1 3; Fe2-S", sb.toString());
68 * map has entry for this feature type - score is shown:
70 minmax.put("METAL", new float[][] { { 0f, 1f }, null });
71 sar.appendFeature(sb, 1, minmax, sf);
72 // <br> is appended to a buffer > 6 in length
73 assertEquals("METAL 1 3; Fe2-S<br>METAL 1 3; Fe2-S Score=1.3",
77 * map has min == max for this feature type - score is not shown:
79 minmax.put("METAL", new float[][] { { 2f, 2f }, null });
81 sar.appendFeature(sb, 1, minmax, sf);
82 assertEquals("METAL 1 3; Fe2-S", sb.toString());
85 @Test(groups = "Functional")
86 public void testAppendFeature_noScore()
88 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
89 StringBuffer sb = new StringBuffer();
90 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
93 sar.appendFeature(sb, 1, null, sf);
94 assertEquals("METAL 1 3; Fe2-S", sb.toString());
97 @Test(groups = "Functional")
98 public void testAppendFeature_clinicalSignificance()
100 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
101 StringBuffer sb = new StringBuffer();
102 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3,
104 sf.setValue("clinical_significance", "Benign");
106 sar.appendFeature(sb, 1, null, sf);
107 assertEquals("METAL 1 3; Fe2-S; Benign", sb.toString());
110 @Test(groups = "Functional")
111 public void testAppendFeature_withScoreStatusClinicalSignificance()
113 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
114 StringBuffer sb = new StringBuffer();
115 SequenceFeature sf = new SequenceFeature("METAL", "Fe2-S", 1, 3, 1.3f,
117 sf.setStatus("Confirmed");
118 sf.setValue("clinical_significance", "Benign");
119 Map<String, float[][]> minmax = new Hashtable<String, float[][]>();
120 minmax.put("METAL", new float[][] { { 0f, 1f }, null });
121 sar.appendFeature(sb, 1, minmax, sf);
123 assertEquals("METAL 1 3; Fe2-S Score=1.3; (Confirmed); Benign",
127 @Test(groups = "Functional")
128 public void testAppendFeature_DescEqualsType()
130 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
131 StringBuffer sb = new StringBuffer();
132 SequenceFeature sf = new SequenceFeature("METAL", "METAL", 1, 3,
135 // description is not included if it duplicates type:
136 sar.appendFeature(sb, 1, null, sf);
137 assertEquals("METAL 1 3", sb.toString());
140 sf.setDescription("Metal");
141 // test is case-sensitive:
142 sar.appendFeature(sb, 1, null, sf);
143 assertEquals("METAL 1 3; Metal", sb.toString());
146 @Test(groups = "Functional")
147 public void testAppendFeature_stripHtml()
149 SequenceAnnotationReport sar = new SequenceAnnotationReport(null);
150 StringBuffer sb = new StringBuffer();
151 SequenceFeature sf = new SequenceFeature("METAL",
152 "<html><body>hello<em>world</em></body></html>", 1, 3,
155 sar.appendFeature(sb, 1, null, sf);
156 // !! strips off </body> but not <body> ??
157 assertEquals("METAL 1 3; <body>hello<em>world</em>",
161 sf.setDescription("<br>&kHD>6");
162 sar.appendFeature(sb, 1, null, sf);
163 // if no <html> tag, html-encodes > and < (only):
164 assertEquals("METAL 1 3; <br>&kHD>6", sb.toString());