EpnTapConnectionTest.java
13.8 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
* This file is a part of EpnTAPClient.
* This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
* See draft specifications: https://voparis-confluence.obspm.fr/pages/viewpage.action?pageId=559861
* Copyright (C) 2016 Institut de Recherche en Astrophysique et Planétologie.
*
* This program is free software: you can
* redistribute it and/or modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version. This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details. You should have received a copy of
* the GNU General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
package eu.omp.irap.vespa.epntapclient;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.junit.Test;
import eu.omp.irap.vespa.epntapclient.granule.Granule;
import eu.omp.irap.vespa.epntapclient.service.ServiceCtrl;
import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException;
import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
import eu.omp.irap.vespa.votable.votabledata.VOTableData;
/**
* @author N. Jourdane
*/
@SuppressWarnings("static-method")
public class EpnTapConnectionTest {
/** The logger for the class Main. */
private static final Logger LOGGER = Logger.getLogger(EpnTapConnectionTest.class.getName());
/** The AMDA ivoid, for testing purposes. */
private static final String AMDA_IVOID = "ivo://cdpp/amda";
/** The AMDA short name (to compare with the returned value), for testing purposes. */
private static final String AMDA_SHORT_NAME = "AMDA";
/** The AMDA access URL, for testing purposes. */
private static final String AMDA_ACCESS_URL = "http://cdpp-epntap.cesr.fr/__system__/tap/run/tap";
/** A subject associated with the AMDA service, for testing purposes. */
private static final String AMDA_SUBJECT = "Space plasmas";
/** The API ivoid, for testing purposes. */
private static final String APIS_IVOID = "ivo://vopdc.obspm/lesia/apis/epn";
/** The APIS short name (to compare with the returned value), for testing purposes. */
private static final String APIS_SHORT_NAME = "APIS";
/** The URL access of a service implementing the EpnCorev2, for testing purposes. */
private static final String SERVICE_EPNCOREV2_ACCESS_URL = "http://voparis-tap-planeto.obspm.fr/__system__/tap/run/tap";
/** A query to send to a service implementing the EpnCorev2, for testing purposes */
private static final String SERVICE_EPNCOREV2_QUERY = "SELECT * FROM planets.epn_core";
/** The table name of a service implementing the EpnCorev2, for testing purposes. */
private static final String SERVICE_EPNCOREV2_TABLE_NAME = "planets.epn_core";
// *** VOResources ***
/**
* Unit test for the class {@link EpnTapConnection#getEPNVOresource(String)}.
*
* @throws VOResourceException Can not get the VOresource.
*/
@Test
public void getVOResourceTest() throws VOResourceException {
LOGGER.info("getVOResourceTest");
EpnTapConnection facade = new EpnTapConnection();
Resource resource = facade.getEPNVOresource(AMDA_IVOID);
assertEquals("AMDA", resource.getShortName());
assertEquals("CDPP AMDA DataBase", resource.getTitle());
assertEquals("Centre de Données de la Physique des Plasmas",
resource.getCuration().getCreator().get(0).getName().getValue());
}
/**
* Unit test for the class {@link EpnTapConnection#getEPNVOResources()}.
*
* @throws VOResourceException Can not get the VOresource.
*/
@Test
public void getEPNVOResourcesTest() throws VOResourceException {
LOGGER.info("getEPNVOResourcesTest");
EpnTapConnection facade = new EpnTapConnection();
List<Resource> resources = facade.getEPNVOResources();
int nbResources = resources.size();
assertTrue(nbResources + " ∉ [13;20]", nbResources >= 13 && nbResources <= 20);
Resource amda = null;
Resource apis = null;
for (Resource resource : resources) {
if (AMDA_IVOID.equals(resource.getIdentifier())) {
amda = resource;
}
if (APIS_IVOID.equals(resource.getIdentifier())) {
apis = resource;
}
}
assertNotNull("AMDA resource should be present.", amda);
assertNotNull("APIS resource should be present.", apis);
assertEquals(AMDA_SHORT_NAME, amda.getShortName());
assertEquals(APIS_SHORT_NAME, apis.getShortName());
}
/**
* Unit test for the class {@link EpnTapConnection#getEPNVOResources(List)}.
*
* @throws VOResourceException Can not get the VOresource.
*/
@Test
public void getEPNVOResourcesWithKeywordsTest() throws VOResourceException {
LOGGER.info("getEPNVOResourcesWithKeywordsTest");
EpnTapConnection facade = new EpnTapConnection();
final List<String> keywords = new ArrayList<>();
keywords.add(AMDA_SUBJECT);
List<Resource> resources = facade.getEPNVOResources(keywords);
assertEquals(resources.size(), 1);
Resource amda = null;
for (Resource resource : resources) {
if (AMDA_IVOID.equals(resource.getIdentifier())) {
amda = resource;
}
}
assertNotNull("AMDA resource should be present.", amda);
}
// *** Services ***
/**
* Unit test for the class {@link EpnTapConnection#getEPNService(String)}.
*
* @throws CantGetVOTableException Can not get the VOTable corresponding to the service.
*/
@Test
public void getEPNServiceTest() throws CantGetVOTableException {
LOGGER.info("getEPNServiceTest");
EpnTapConnection facade = new EpnTapConnection();
VOTABLE voTable = facade.getEPNService(AMDA_IVOID);
VOTableData data = ServiceCtrl.getVoTableData(voTable);
assertEquals(1, data.getNbRows());
assertTrue("Column name ivoid not found.", data.isContainingColumnName("ivoid"));
assertTrue("Column name short_name not found.", data.isContainingColumnName("access_url"));
assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name"));
assertEquals(AMDA_IVOID, data.getCell(0, "ivoid"));
assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url"));
assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name"));
}
/**
* Unit test for the class {@link EpnTapConnection#getEPNService(String, List)}.
*
* @throws CantGetVOTableException Can not get the VOTable corresponding to the service.
*/
@Test
public void getEPNServiceWithAttributesTest() throws CantGetVOTableException {
LOGGER.info("getEPNServiceWithAttributesTest");
EpnTapConnection facade = new EpnTapConnection();
final List<String> attributes = new ArrayList<>();
attributes.add("access_url");
attributes.add("short_name");
VOTABLE voTable = facade.getEPNService(AMDA_IVOID, attributes);
VOTableData data = ServiceCtrl.getVoTableData(voTable);
assertEquals(1, data.getNbRows());
assertEquals(2, data.getNbColumns());
assertTrue("Column name short_name not found.", data.isContainingColumnName("access_url"));
assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name"));
assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url"));
assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name"));
}
/**
* Unit test for the class {@link EpnTapConnection#getEPNServices()}.
*
* @throws CantGetVOTableException Can not get the VOTable corresponding to the service.
*/
@Test
public void getEPNServicesTest() throws CantGetVOTableException {
LOGGER.info("getEPNServicesTest");
EpnTapConnection facade = new EpnTapConnection();
VOTABLE voTable = facade.getEPNServices();
VOTableData data = ServiceCtrl.getVoTableData(voTable);
int nbServices = data.getNbRows();
assertTrue(nbServices + " ∉ [13;20].", nbServices >= 13 && nbServices <= 20);
assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name"));
assertTrue("AMDA ivoid not found.", data.isColumnContainingValue("ivoid", AMDA_IVOID));
Map<String, Object> amda = data.getRowMapByValue("ivoid", AMDA_IVOID);
assertEquals(AMDA_ACCESS_URL, amda.get("access_url"));
assertEquals(AMDA_SHORT_NAME, amda.get("short_name"));
}
/**
* Unit test for the class {@link EpnTapConnection#getEPNServices(List)}.
*
* @throws CantGetVOTableException Can not get the VOTable corresponding to the service.
*/
@Test
public void getEPNServicesWithAttributesTest()
throws CantGetVOTableException {
LOGGER.info("getEPNServicesWithAttributesTest");
EpnTapConnection facade = new EpnTapConnection();
final List<String> attributes = new ArrayList<>();
attributes.add("access_url");
attributes.add("short_name");
VOTABLE voTable = facade.getEPNServices(attributes);
VOTableData data = ServiceCtrl.getVoTableData(voTable);
assertEquals(2, data.getNbColumns());
assertTrue("Column name access_url not found.", data.isContainingColumnName("access_url"));
assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name"));
assertTrue("AMDA short_name not found.",
data.isColumnContainingValue("short_name", AMDA_SHORT_NAME));
assertTrue("AMDA access_url not found.",
data.isColumnContainingValue("access_url", AMDA_ACCESS_URL));
Map<String, Object> amda = data.getRowMapByValue("short_name", AMDA_SHORT_NAME);
assertEquals(AMDA_ACCESS_URL, amda.get("access_url"));
assertEquals(AMDA_SHORT_NAME, amda.get("short_name"));
}
/**
* Unit test for the class {@link EpnTapConnection#getEPNServices(List, List)}.
*
* @throws CantGetVOTableException Can not get the VOTable corresponding to the service.
* @throws VOResourceException Can not get the VOresource.
*/
@Test
public void getEPNServicesWithKeywordsAndAttributesTest()
throws CantGetVOTableException, VOResourceException {
LOGGER.info("getEPNServicesWithKeywordsAndAttributesTest");
EpnTapConnection facade = new EpnTapConnection();
final List<String> keywords = new ArrayList<>();
keywords.add(AMDA_SUBJECT);
final List<String> attributes = new ArrayList<>();
attributes.add("access_url");
attributes.add("short_name");
VOTABLE voTable = facade.getEPNServices(keywords, attributes);
VOTableData data = ServiceCtrl.getVoTableData(voTable);
assertEquals(3, data.getNbColumns());
assertEquals(1, data.getNbRows());
// TODO: Should be return only 2 columns, because keywords do not contains res_subject.
assertTrue("Column name access_url not found.", data.isContainingColumnName("access_url"));
assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name"));
assertTrue("AMDA short_name not found.",
data.isColumnContainingValue("short_name", AMDA_SHORT_NAME));
assertTrue("AMDA access_url not found.",
data.isColumnContainingValue("access_url", AMDA_ACCESS_URL));
assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name"));
assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url"));
}
// *** Getters ***
/**
* Unit test for the class {@link EpnTapConnection#getEPNCoreTableName(String)}.
*
* @throws CantGetVOTableException Can not get the VOTable corresponding to the service.
*/
@Test
public void getEPNCoreTableNameTest() throws CantGetVOTableException {
LOGGER.info("getEPNCoreTableNameTest");
EpnTapConnection facade = new EpnTapConnection();
String epnCoreTableName = facade.getEPNCoreTableName(AMDA_IVOID);
assertEquals("amdadb.epn_core", epnCoreTableName);
}
/**
* Unit test for the class {@link EpnTapConnection#getTAPURL(String)}.
*
* @throws CantGetVOTableException Can not get the VOTable corresponding to the service.
*/
@Test
public void getTAPURLTest() throws CantGetVOTableException {
LOGGER.info("getTAPURLTest");
EpnTapConnection facade = new EpnTapConnection();
String tapURL = facade.getTAPURL("ivo://cdpp/amda");
assertEquals("http://cdpp-epntap.cesr.fr/__system__/tap/run/tap", tapURL);
}
// *** Queries ***
/**
* Unit test for the class {@link EpnTapConnection#sendADQLQuery(String, String)}.
*
* @throws CantGetVOTableException Can not get the VOTable resulting the query.
*/
@Test
public void sendADQLQueryTest() throws CantGetVOTableException {
LOGGER.info("sendADQLQueryTest");
EpnTapConnection facade = new EpnTapConnection();
List<Granule> granules = facade.sendADQLQuery(SERVICE_EPNCOREV2_ACCESS_URL,
SERVICE_EPNCOREV2_QUERY);
assertNotNull("Granules list not returned.", granules);
assertEquals(8, granules.size());
Granule mars = null;
for (Granule granule : granules) {
if ("Mars".equals(granule.getGranuleUid())) {
mars = granule;
}
}
assertNotNull("granule 'Mars' is not found.", mars);
assertEquals("4", mars.getObsId());
assertEquals(new Integer(5), mars.getProcessingLevel());
}
/**
* Unit test for the class {@link EpnTapConnection#sendQuery(String, String, Query)}.
*
* @throws CantGetVOTableException Can not get the VOTable resulting the query.
*/
@Test
public void sendADQLQueryWithSchemaNameTest() throws CantGetVOTableException {
LOGGER.info("sendADQLQueryWithSchemaNameTest");
EpnTapConnection facade = new EpnTapConnection();
List<Granule> granules = facade.sendQuery(SERVICE_EPNCOREV2_ACCESS_URL,
SERVICE_EPNCOREV2_TABLE_NAME, Query.GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL);
assertNotNull("Granules list not returned.", granules);
assertEquals(8, granules.size());
Granule mars = null;
for (Granule granule : granules) {
if ("Mars".equals(granule.getGranuleUid())) {
mars = granule;
}
}
assertNotNull("granule 'Mars' is not found.", mars);
assertEquals("4", mars.getObsId());
assertEquals(new Integer(5), mars.getProcessingLevel());
}
}