Project

General

Profile

1
package eu.dnetlib.data.transform.xml;
2

    
3
import java.util.List;
4

    
5
import eu.dnetlib.data.transform.xml.OpenTrialsXsltFunctions.JsonProv;
6
import org.junit.After;
7
import org.junit.Before;
8
import org.junit.Test;
9

    
10
import static org.junit.Assert.assertEquals;
11

    
12
/**
13
 * OpenTrialsXsltFunctions Tester.
14
 *
15
 */
16
public class OpenTrialsXsltFunctionsTest {
17

    
18
	private String jsonProv = "[{\"url\" : \"http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT00378508\", \"sourceID\" : \"77eb42c5-0ec7-4e31-963a-5736b66f2d26\", \"sourceName\" : \"ictrp\"},{\"url\" : \"https://www.clinicaltrials.gov/ct2/show/NCT00378508?lup_e=02%2F04%2F2016&lup_s=01%2F01%2F2001&rank=175075&resultsxml=true\", \"sourceID\" : \"b389497c-0833-432b-a09b-930526b7b4d4\", \"sourceName\" : \"nct\"}]";
19
	private String jsonProvWithNull = "[{\"url\" : \"\", \"sourceID\" : \"77eb42c5-0ec7-4e31-963a-5736b66f2d26\", \"sourceName\" : \"ictrp\"},{\"url\" : \"https://www.clinicaltrials.gov/ct2/show/NCT00378508?lup_e=02%2F04%2F2016&lup_s=01%2F01%2F2001&rank=175075&resultsxml=true\", \"sourceID\" : \"b389497c-0833-432b-a09b-930526b7b4d4\", \"sourceName\" : \"nct\"}]";
20
	private String jidentifiers = "{112683,NCT00920439}";
21

    
22

    
23
	private String jsonRecord = "[{\"source_id\" : \"nct\", \"source_url\" : \"https://clinicaltrials.gov/ct2/show/NCT02321059\", \"is_primary\" : true},{\"source_id\" : \"ictrp\", \"source_url\" : \"http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT02321059\", \"is_primary\" : false}]";
24
	private String jsonRecordNull = "[{\"source_id\" : \"nct\", \"source_url\" : \"https://clinicaltrials.gov/ct2/show/NCT02321059\"},{\"source_id\" : \"ictrp\", \"source_url\" : \"http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT02321059\", \"is_primary\" : false}]";
25
	private String jsonRecordVoid = "[{\"source_id\" : \"\", \"source_url\" : \"\", \"is_primary\" : \"\"}]";
26
	private String jsonRecondPrimary = "[{\"source_id\" : \"nct\", \"source_url\" : \"https://clinicaltrials.gov/ct2/show/NCT02321059\", \"is_primary\" : false},{\"source_id\" : \"ictrp\", \"source_url\" : \"http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT02321059\", \"is_primary\" : false}]";
27

    
28
	private String jsonPeopleVoid ="[{\"person_name\" : null, \"person_id\" : null, \"person_role\" : null}]";
29
	private String jsonPeopleOne = "[{\"person_name\" : \"Henk Verheul, M.D., PhD\", \"person_id\" : \"116438e9-f8b1-46e5-a1f8-20f851cab73c\", \"person_role\" : \"principal_investigator\"}]";
30
	private String jsonPeopleMore = "[{\"person_name\" : \"Henk Verheul, M.D., PhD\", \"person_id\" : \"116438e9-f8b1-46e5-a1f8-20f851cab73c\", \"person_role\" : \"principal_investigator\"},{\"person_name\" : \"Miriam Pippolippo Baglioni, PhD\", \"person_id\" : \"fake\", \"person_role\" : \"principal_investigator\"}]";
31

    
32
	private String jsonOrganizationVoid = "[{\"organization_name\" : null, \"organization_id\" : null, \"organization_role\" : null}]";
33
	private String jsonOrganizationOne = "[{\"organization_name\" : \"Södertälje sjukhus AB\", \"organization_id\" : \"15f0d004-b82b-408c-8605-38a57352468d\", \"organization_role\" : \"sponsor\"}]";
34
	private String jsonOrganizationMore = "[{\"organization_name\" : \"Södertälje sjukhus AB\", \"organization_id\" : \"15f0d004-b82b-408c-8605-38a57352468d\", \"organization_role\" : \"sponsor\"},{\"organization_name\" : \"Miriam Baglioni AB\", \"organization_id\" : \"fake\", \"organization_role\" : \"primary_sponsor\"}]";
35

    
36
	private String jsonLocationVoid = "[{\"location_name\" : null}]";
37
	private String jsonLocationOne = "[{\"location_name\" : \"China\"]";
38
	private String jsonLocationMore = "[{\"location_name\" : \"China\"},{\"location_name\" : \"North Korea\"}]";
39

    
40
	@Before
41
	public void before() throws Exception {
42
	}
43

    
44
	@After
45
	public void after() throws Exception {
46
	}
47

    
48
	/**
49
	 * Method: getProvs(String jsonProvList)
50
	 */
51
	@Test
52
	public void testGetProvs() throws Exception {
53
		List<JsonProv> list = OpenTrialsXsltFunctions.getProvs(jsonProv);
54
		assertEquals(2, list.size());
55
	}
56

    
57
	/**
58
	 * Method: getMainIdentifierURL(String jsonProvList)
59
	 */
60
	@Test
61
	public void testGetMainIdentifierURL() throws Exception {
62
		String url = OpenTrialsXsltFunctions.getMainIdentifierURL(jsonProv);
63
		assertEquals( "http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT00378508", url );
64
		url = OpenTrialsXsltFunctions.getMainIdentifierURL(jsonProvWithNull);
65
		assertEquals("https://www.clinicaltrials.gov/ct2/show/NCT00378508?lup_e=02%2F04%2F2016&lup_s=01%2F01%2F2001&rank=175075&resultsxml=true", url);
66
	}
67

    
68
	@Test
69
	public void testGetPrimaryRecordUrl(){
70
		String url = OpenTrialsXsltFunctions.getPrimaryRecordUrl(jsonRecord);
71
		assertEquals("https://clinicaltrials.gov/ct2/show/NCT02321059", url);
72
	}
73

    
74
	@Test
75
	public void testGetPrimaryRecordID(){
76
		String id = OpenTrialsXsltFunctions.getPrimaryRecordIdentifier(jsonRecord);
77
		assertEquals("nct", id);
78
	}
79

    
80
	@Test
81
	public void testGetPrimaryRecordUrlNull(){
82
		String url = OpenTrialsXsltFunctions.getPrimaryRecordUrl(jsonRecordNull);
83
		assertEquals("https://clinicaltrials.gov/ct2/show/NCT02321059", url);
84
	}
85

    
86
	@Test
87
	public void testGetPrimaryRecordUrlVoid(){
88
		String url = OpenTrialsXsltFunctions.getPrimaryRecordUrl(jsonRecordVoid);
89
		assertEquals("", url);
90
	}
91

    
92
	@Test
93
	public void testGetPrimaryRecordUrlNoPrimary(){
94
		String url = OpenTrialsXsltFunctions.getPrimaryRecordUrl(jsonRecondPrimary);
95
		assertEquals("https://clinicaltrials.gov/ct2/show/NCT02321059", url);
96
	}
97
	@Test
98
	public void testGetPrimaryRecordIDNoPrimary(){
99
		String id = OpenTrialsXsltFunctions.getPrimaryRecordIdentifier(jsonRecondPrimary);
100
		assertEquals("nct", id);
101
	}
102
	@Test
103
	public void testGetPrincipalInvestigatorsVoid(){
104
		String url = OpenTrialsXsltFunctions.getPrincipalInvestigators(jsonPeopleVoid);
105
		assertEquals("",url);
106
	}
107

    
108

    
109
	@Test
110
	public void testGetPrincipalInvestigatorsOne(){
111
		String url = OpenTrialsXsltFunctions.getPrincipalInvestigators(jsonPeopleOne);
112
		assertEquals("Verheul, Henk", url);
113
	}
114

    
115
	@Test
116
	public void testGetPrincipalInvestigatorsMore(){
117
		String url = OpenTrialsXsltFunctions.getPrincipalInvestigators(jsonPeopleMore);
118
		assertEquals("Verheul, Henk@@Baglioni, Miriam Pippolippo", url);
119
	}
120

    
121

    
122

    
123
	@Test
124
	public void testgGetTrialOrganizationsVoid(){
125
		String url = OpenTrialsXsltFunctions.getTrialOrganizations(jsonOrganizationVoid);
126
		assertEquals("",url);
127
	}
128

    
129

    
130
	@Test
131
	public void testgGetTrialOrganizationsOne(){
132
		String url = OpenTrialsXsltFunctions.getTrialOrganizations(jsonOrganizationOne);
133
		assertEquals("Södertälje sjukhus AB@sponsor", url);
134
	}
135

    
136
	@Test
137
	public void testgGetTrialOrganizationsMore(){
138
		String url = OpenTrialsXsltFunctions.getTrialOrganizations(jsonOrganizationMore);
139
		assertEquals("Södertälje sjukhus AB@sponsor@@Miriam Baglioni AB@sponsor", url);
140
	}
141

    
142
	@Test
143
	public void testgGetTrialLocationsVoid(){
144
		String url = OpenTrialsXsltFunctions.getTrialLocations(jsonLocationVoid);
145
		assertEquals("",url);
146
	}
147

    
148

    
149
	@Test
150
	public void testgGetTrialLocationsOne(){
151
		String url = OpenTrialsXsltFunctions.getTrialLocations(jsonLocationOne);
152
		assertEquals("China", url);
153
	}
154

    
155
	@Test
156
	public void testgGetTrialLocationsMore(){
157
		String url = OpenTrialsXsltFunctions.getTrialLocations(jsonLocationMore);
158
		assertEquals("China@@North Korea", url);
159
	}
160

    
161
	@Test
162
	public void testGetNotPrimaryRecordUrlPrimary(){
163
		String url = OpenTrialsXsltFunctions.getNotPrimaryRecordUrl(jsonRecondPrimary);
164
		assertEquals("http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT02321059", url);
165
	}
166

    
167
	@Test
168
	public void testGetNotPrimaryRecordUrlVoid(){
169
		String url = OpenTrialsXsltFunctions.getNotPrimaryRecordUrl(jsonRecordVoid);
170
		assertEquals("", url);
171
	}
172

    
173
	@Test
174
	public void testGetNotPrimaryRecordUrl(){
175
		String url = OpenTrialsXsltFunctions.getNotPrimaryRecordUrl(jsonRecord);
176
		assertEquals("http://apps.who.int/trialsearch/Trial3.aspx?trialid=NCT02321059", url);
177
	}
178

    
179

    
180
} 
    (1-1/1)