EpnTapConnectionTest.java
7.27 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
/*
* 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 java.util.ArrayList;
import java.util.HashMap;
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.voresource.VOResourceCtrl;
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.Field;
import eu.omp.irap.vespa.epntapclient.votable.model.Table;
import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
/**
* @author N. Jourdane
*/
public class EpnTapConnectionTest {
/** The logger for the class Main. */
private static final Logger logger = Logger.getLogger(EpnTapConnectionTest.class.getName());
@Test
public void getVOResourceTest() throws VOResourceException {
EpnTapConnection facade = new EpnTapConnection();
Resource resource = VOResourceCtrl.getVOresource("ivo://cdpp/amda");
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());
}
@Test
public void getEPNVOResourcesTest() throws VOResourceException {
EpnTapConnection facade = new EpnTapConnection();
List<Resource> resources = facade.getEPNVOResources();
assertEquals(13, resources.size());
for (Resource r : resources) {
assertNotNull(r);
}
}
@Test
public void getEPNVOResourcesWithKeywordsTest() throws VOResourceException {
EpnTapConnection facade = new EpnTapConnection();
final Map<String, String> keywords = new HashMap<>();
keywords.put("shortName", "IKS");
List<Resource> resources = facade.getEPNVOResources();
assertEquals(2, resources.size());
}
@Test
public void getEPNServiceTest() throws CantGetVOTableException {
EpnTapConnection facade = new EpnTapConnection();
VOTABLE epnService = facade.getEPNService("ivo://cdpp/amda");
Table table = (Table) epnService.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0);
String firstInfoVal = epnService.getRESOURCE().get(0).getINFO().get(0).getValueAttribute();
String firstFieldName = ((Field) table.getFIELDOrPARAMOrGROUP().get(0)).getID();
assertEquals("http://gavo.aip.de", firstInfoVal);
assertEquals("short_name", firstFieldName);
}
@Test
public void getEPNServiceWithAttributesTest() throws CantGetVOTableException {
EpnTapConnection facade = new EpnTapConnection();
final List<String> serviceAttributes = new ArrayList<>();
serviceAttributes.add("target_name");
serviceAttributes.add("time_min");
serviceAttributes.add("time_max");
VOTABLE epnService = facade.getEPNService("ivo://cdpp/amda", serviceAttributes);
Table table = (Table) epnService.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0);
String firstInfoVal = epnService.getRESOURCE().get(0).getINFO().get(0).getValueAttribute();
String firstFieldName = ((Field) table.getFIELDOrPARAMOrGROUP().get(0)).getID();
assertEquals("http://cdpp-epntap.cesr.fr", firstInfoVal);
assertEquals("short_name", firstFieldName);
}
@Test
public void getEPNServicesTest() throws VOResourceException {
EpnTapConnection facade = new EpnTapConnection();
List<VOTABLE> voTables = facade.getEPNServices();
assertEquals(11, voTables.size());
}
@Test
public void getEPNServicesWithAttributesTest()
throws VOResourceException, CantGetVOTableException {
final List<String> serviceAttributes = new ArrayList<>();
serviceAttributes.add("target_name");
serviceAttributes.add("time_min");
serviceAttributes.add("time_max");
EpnTapConnection facade = new EpnTapConnection();
List<VOTABLE> voTables = facade.getEPNServices(serviceAttributes);
String firstInfoVal = voTables.get(0).getRESOURCE().get(0).getINFO().get(0)
.getValueAttribute();
assertEquals("http://gavo.aip.de", firstInfoVal);
}
@Test
public void getEPNServicesWithAttributesAndKeywordsTest()
throws CantGetVOTableException, VOResourceException {
final List<String> serviceAttributes = new ArrayList<>();
serviceAttributes.add("target_name");
serviceAttributes.add("time_min");
serviceAttributes.add("time_max");
final Map<String, String> keywords = new HashMap<>();
keywords.put("shortName", "IKS");
EpnTapConnection facade = new EpnTapConnection();
List<VOTABLE> voTables = facade.getEPNServices(keywords, serviceAttributes);
String firstInfoVal = voTables.get(0).getRESOURCE().get(0).getINFO().get(0)
.getValueAttribute();
assertEquals("http://gavo.aip.de", firstInfoVal);
}
@Test
public void getEPNCoreTableNameTest() throws CantGetVOTableException {
EpnTapConnection facade = new EpnTapConnection();
String epnCoreTableName = facade.getEPNCoreTableName("ivo://cdpp/amda");
assertEquals("?", epnCoreTableName);
}
@Test
public void getTAPURLTest() throws CantGetVOTableException {
EpnTapConnection facade = new EpnTapConnection();
String tapURL = facade.getTAPURL("ivo://cdpp/amda");
assertEquals("http://cdpp-epntap.cesr.fr/__system__/tap/run/tap", tapURL);
}
@Test
public void sendADQLQueryTest() throws CantGetVOTableException {
EpnTapConnection facade = new EpnTapConnection();
String tapURL = "http://voparis-tap-planeto.obspm.fr/__system__/tap/run/tap";
String query = "SELECT TOP 1 * FROM planets.epn_core";
List<Granule> granules = facade.sendADQLQuery(tapURL, query);
assertEquals("?", granules.get(0).granuleUid);
assertEquals("?", granules.get(0).timeMin);
assertEquals("?", granules.get(0).processingLevel);
assertEquals("?", granules.get(0).creationDate);
}
@Test
public void sendADQLQueryWithSchemaNameTest() throws CantGetVOTableException {
EpnTapConnection facade = new EpnTapConnection();
String tapURL = "http://voparis-tap-planeto.obspm.fr/__system__/tap/run/tap";
String schemaName = "amdadb.epn_core";
String query = "SELECT TOP 1 * FROM planets.epn_core";
List<Granule> granules = facade.sendQuery(tapURL, schemaName, query);
assertEquals("?", granules.get(0).granuleUid);
assertEquals("?", granules.get(0).timeMin);
assertEquals("?", granules.get(0).processingLevel);
assertEquals("?", granules.get(0).creationDate);
}
}