-
Notifications
You must be signed in to change notification settings - Fork 0
/
gotator_test.go
150 lines (137 loc) · 4.35 KB
/
gotator_test.go
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
package gotator
import (
"encoding/json"
"testing"
)
type newClientTest struct {
url string
accepted bool
}
var newClientCases = []newClientTest{
{ // empty url, shall not be accepted
"",
false,
},
{ // valid url, shall be accepted
"https://www.ncbi.nlm.nih.gov/CBBresearch/Lu/Demo/RESTful/tmTool.cgi",
true,
},
}
func TestNewClient(t *testing.T) {
for _, tc := range newClientCases {
c := new(Client)
c, err := c.NewClient(tc.url)
if err != nil && tc.accepted == true {
t.Fatalf("expected url to be accepted: %v, err: %v", tc.url, err)
}
if err == nil && tc.accepted == false {
t.Fatalf("expected url not to be accepted: %v, err: %v", tc.url, err)
}
}
}
type getAllAnnotationsTest struct {
url string
id string
res []byte
}
var gAACases = []getAllAnnotationsTest{
{ // no id, no result
"https://www.ncbi.nlm.nih.gov/CBBresearch/Lu/Demo/RESTful/tmTool.cgi",
"",
[]byte(""),
}, { // valid id, no result because pubtator did not annotate it yet (as of 2017-10-27)
"https://www.ncbi.nlm.nih.gov/CBBresearch/Lu/Demo/RESTful/tmTool.cgi",
"28366679",
[]byte(""),
}, { // valid id, valid result
"https://www.ncbi.nlm.nih.gov/CBBresearch/Lu/Demo/RESTful/tmTool.cgi",
"19894120",
[]byte(`{
"sourcedb": "PubMed",
"sourceid": "19894120",
"text": "Lipopolysaccharide increases the expression of multidrug resistance-associated protein 1 (MRP1) in RAW 264.7 macrophages. Multidrug resistance-associated protein 1 (MRP-1) is a ubiquitously expressed member of the ATP-binding cassette transporter family. MRP-1 is one of the primary transporters of glutathione and glutathione conjugates. This protein also transports antiretroviral therapeutics, such as HIV-1 protease inhibitors (PI). We hypothesized that inflammatory mediators that activate macrophages would modify the expression and activity of MRP-1 in macrophages. Real-time PCR assays, western blots, and calcein efflux assays were used to show that exposure of macrophage cell line RAW 264.7 to lipopolysaccharide (LPS) increased expression of MRP-1 at the levels of mRNA, protein, and functional activity. Treatment of macrophages with LPS resulted in 2-fold increases of MRP-1 expression or functional activity. LPS-mediated increases in calcein efflux were repressed by the MRP-specific inhibitor MK-571. These results suggest that the effectiveness of HIV-1 PI therapy may be compromised by the presence of opportunistic infections.",
"denotations": [
{
"obj": "Chemical:C059141",
"span": {
"begin": 1010,
"end": 1016
}
},
{
"obj": "Chemical:C007740",
"span": {
"begin": 614,
"end": 621
}
},
{
"obj": "Chemical:D005978",
"span": {
"begin": 315,
"end": 326
}
},
{
"obj": "Chemical:D005978",
"span": {
"begin": 299,
"end": 310
}
},
{
"obj": "Chemical:D000255",
"span": {
"begin": 214,
"end": 217
}
},
{
"obj": "Chemical:CHEBI:16412",
"span": {
"begin": 0,
"end": 18
}
}
]
}`),
}, //{ // TODO: add failing test cases for coverage. right now everything passes.
//"https://www.ncbi.nlm.nih.gov/CBBresearch/Lu/Demo/RESTful/tmTool.cgi",
//"www.gibberish.com", //should make Parse(), NewRequest() or Do() fail
//[]byte(""),
//},
}
func TestGetAllAnnotations(t *testing.T) {
for _, tc := range gAACases {
c := new(Client)
c, _ = c.NewClient(tc.url)
art, err := c.GetAllAnnotations(tc.id)
if err != nil {
t.Logf("got error that's tolerable in some cases for testing: %v, with url: %v", err, tc.url)
}
//log.Printf("article: %v", art)
//if art == nil {
// t.Fatal("expected response, got none")
//}
// test if both are empty, if not test equalness
if len(tc.res) == 0 {
if art != nil {
t.Fatal("tc.res is empty and so should art")
}
} else {
var testArt Article
err = json.Unmarshal(tc.res, &testArt)
if err != nil {
t.Fatalf("test case res isn't valid: %v", tc.res)
}
// TODO DeepEquals seems not to work when order of json objects are different
// so just .Text gets compared right now
//if !reflect.DeepEqual(art, &testArt) {
// t.Fatalf("expected %v, \n got %v", art, &testArt)
//}
if art.Text != testArt.Text {
t.Fatalf("expected same attribute content")
}
}
}
}