Commit 330431b575aef0a67632d1600b6265ac84ac87d5
1 parent
fb920d7f
Exists in
master
Fix a Junit test and add Javadoc
Showing
1 changed file
with
107 additions
and
29 deletions
Show diff stats
src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java
... | ... | @@ -29,7 +29,6 @@ import org.junit.Test; |
29 | 29 | |
30 | 30 | import eu.omp.irap.vespa.epntapclient.granule.Granule; |
31 | 31 | import eu.omp.irap.vespa.epntapclient.service.ServiceCtrl; |
32 | -import eu.omp.irap.vespa.epntapclient.voresource.VOResourceCtrl; | |
33 | 32 | import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException; |
34 | 33 | import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; |
35 | 34 | import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; |
... | ... | @@ -39,37 +38,52 @@ import eu.omp.irap.vespa.votable.votabledata.VOTableData; |
39 | 38 | /** |
40 | 39 | * @author N. Jourdane |
41 | 40 | */ |
41 | +@SuppressWarnings("static-method") | |
42 | 42 | public class EpnTapConnectionTest { |
43 | 43 | |
44 | 44 | /** The logger for the class Main. */ |
45 | 45 | private static final Logger logger = Logger.getLogger(EpnTapConnectionTest.class.getName()); |
46 | 46 | |
47 | + /** The AMDA ivoid, for testing purposes. */ | |
47 | 48 | private static final String AMDA_IVOID = "ivo://cdpp/amda"; |
48 | 49 | |
50 | + /** The AMDA short name (to compare with the returned value), for testing purposes. */ | |
49 | 51 | private static final String AMDA_SHORT_NAME = "AMDA"; |
50 | 52 | |
53 | + /** The AMDA access URL, for testing purposes. */ | |
51 | 54 | private static final String AMDA_ACCESS_URL = "http://cdpp-epntap.cesr.fr/__system__/tap/run/tap"; |
52 | 55 | |
56 | + /** A subject associated with the AMDA service, for testing purposes. */ | |
53 | 57 | private static final String AMDA_SUBJECT = "Space plasmas"; |
54 | 58 | |
59 | + /** The API ivoid, for testing purposes. */ | |
55 | 60 | private static final String APIS_IVOID = "ivo://vopdc.obspm/lesia/apis/epn"; |
56 | 61 | |
62 | + /** The APIS short name (to compare with the returned value), for testing purposes. */ | |
57 | 63 | private static final String APIS_SHORT_NAME = "APIS"; |
58 | 64 | |
65 | + /** The URL access of a service implementing the EpnCorev2, for testing purposes. */ | |
59 | 66 | private static final String SERVICE_EPNCOREV2_ACCESS_URL = "http://voparis-tap-planeto.obspm.fr/__system__/tap/run/tap"; |
60 | 67 | |
68 | + /** A query to send to a service implementing the EpnCorev2, for testing purposes */ | |
61 | 69 | private static final String SERVICE_EPNCOREV2_QUERY = "SELECT * FROM planets.epn_core"; |
62 | 70 | |
71 | + /** The table name of a service implementing the EpnCorev2, for testing purposes. */ | |
63 | 72 | private static final String SERVICE_EPNCOREV2_TABLE_NAME = "planets.epn_core"; |
64 | 73 | // *** VOResources *** |
65 | 74 | |
66 | 75 | |
76 | + /** | |
77 | + * Unit test for the class {@link EpnTapConnection#getEPNVOresource(String)}. | |
78 | + * | |
79 | + * @throws VOResourceException Can not get the VOresource. | |
80 | + */ | |
67 | 81 | @Test |
68 | 82 | public void getVOResourceTest() throws VOResourceException { |
69 | - System.out.println("getVOResourceTest"); | |
83 | + logger.info("getVOResourceTest"); | |
70 | 84 | EpnTapConnection facade = new EpnTapConnection(); |
71 | 85 | |
72 | - Resource resource = VOResourceCtrl.getVOresource("ivo://cdpp/amda"); | |
86 | + Resource resource = facade.getEPNVOresource(AMDA_IVOID); | |
73 | 87 | |
74 | 88 | assertEquals("AMDA", resource.getShortName()); |
75 | 89 | assertEquals("CDPP AMDA DataBase", resource.getTitle()); |
... | ... | @@ -77,9 +91,14 @@ public class EpnTapConnectionTest { |
77 | 91 | resource.getCuration().getCreator().get(0).getName().getValue()); |
78 | 92 | } |
79 | 93 | |
94 | + /** | |
95 | + * Unit test for the class {@link EpnTapConnection#getEPNVOResources()}. | |
96 | + * | |
97 | + * @throws VOResourceException Can not get the VOresource. | |
98 | + */ | |
80 | 99 | @Test |
81 | 100 | public void getEPNVOResourcesTest() throws VOResourceException { |
82 | - System.out.println("getEPNVOResourcesTest"); | |
101 | + logger.info("getEPNVOResourcesTest"); | |
83 | 102 | EpnTapConnection facade = new EpnTapConnection(); |
84 | 103 | |
85 | 104 | List<Resource> resources = facade.getEPNVOResources(); |
... | ... | @@ -103,9 +122,14 @@ public class EpnTapConnectionTest { |
103 | 122 | assertEquals(APIS_SHORT_NAME, apis.getShortName()); |
104 | 123 | } |
105 | 124 | |
125 | + /** | |
126 | + * Unit test for the class {@link EpnTapConnection#getEPNVOResources(List)}. | |
127 | + * | |
128 | + * @throws VOResourceException Can not get the VOresource. | |
129 | + */ | |
106 | 130 | @Test |
107 | 131 | public void getEPNVOResourcesWithKeywordsTest() throws VOResourceException { |
108 | - System.out.println("getEPNVOResourcesWithKeywordsTest"); | |
132 | + logger.info("getEPNVOResourcesWithKeywordsTest"); | |
109 | 133 | EpnTapConnection facade = new EpnTapConnection(); |
110 | 134 | |
111 | 135 | final List<String> keywords = new ArrayList<>(); |
... | ... | @@ -126,12 +150,17 @@ public class EpnTapConnectionTest { |
126 | 150 | |
127 | 151 | // *** Services *** |
128 | 152 | |
153 | + /** | |
154 | + * Unit test for the class {@link EpnTapConnection#getEPNService(String)}. | |
155 | + * | |
156 | + * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. | |
157 | + */ | |
129 | 158 | @Test |
130 | 159 | public void getEPNServiceTest() throws CantGetVOTableException { |
131 | - System.out.println("getEPNServiceTest"); | |
160 | + logger.info("getEPNServiceTest"); | |
132 | 161 | EpnTapConnection facade = new EpnTapConnection(); |
133 | 162 | |
134 | - VOTABLE voTable = facade.getEPNService("ivo://cdpp/amda"); | |
163 | + VOTABLE voTable = facade.getEPNService(AMDA_IVOID); | |
135 | 164 | VOTableData data = ServiceCtrl.getVoTableData(voTable); |
136 | 165 | |
137 | 166 | assertEquals(1, data.getNbRows()); |
... | ... | @@ -143,16 +172,21 @@ public class EpnTapConnectionTest { |
143 | 172 | assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name")); |
144 | 173 | } |
145 | 174 | |
175 | + /** | |
176 | + * Unit test for the class {@link EpnTapConnection#getEPNService(String, List)}. | |
177 | + * | |
178 | + * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. | |
179 | + */ | |
146 | 180 | @Test |
147 | 181 | public void getEPNServiceWithAttributesTest() throws CantGetVOTableException { |
148 | - System.out.println("getEPNServiceWithAttributesTest"); | |
182 | + logger.info("getEPNServiceWithAttributesTest"); | |
149 | 183 | EpnTapConnection facade = new EpnTapConnection(); |
150 | 184 | |
151 | 185 | final List<String> attributes = new ArrayList<>(); |
152 | 186 | attributes.add("access_url"); |
153 | 187 | attributes.add("short_name"); |
154 | 188 | |
155 | - VOTABLE voTable = facade.getEPNService("ivo://cdpp/amda", attributes); | |
189 | + VOTABLE voTable = facade.getEPNService(AMDA_IVOID, attributes); | |
156 | 190 | VOTableData data = ServiceCtrl.getVoTableData(voTable); |
157 | 191 | |
158 | 192 | assertEquals(1, data.getNbRows()); |
... | ... | @@ -163,59 +197,83 @@ public class EpnTapConnectionTest { |
163 | 197 | assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name")); |
164 | 198 | } |
165 | 199 | |
200 | + /** | |
201 | + * Unit test for the class {@link EpnTapConnection#getEPNServices()}. | |
202 | + * | |
203 | + * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. | |
204 | + */ | |
166 | 205 | @Test |
167 | 206 | public void getEPNServicesTest() throws CantGetVOTableException { |
168 | - System.out.println("getEPNServicesTest"); | |
207 | + logger.info("getEPNServicesTest"); | |
169 | 208 | EpnTapConnection facade = new EpnTapConnection(); |
170 | 209 | |
171 | 210 | VOTABLE voTable = facade.getEPNServices(); |
172 | 211 | VOTableData data = ServiceCtrl.getVoTableData(voTable); |
173 | 212 | int nbServices = data.getNbRows(); |
174 | 213 | assertTrue(nbServices + " โ [13;20].", nbServices >= 13 && nbServices <= 20); |
175 | - assertTrue("Column name ivoid not found.", data.isContainingColumnName("short_name")); | |
214 | + assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name")); | |
176 | 215 | assertTrue("AMDA ivoid not found.", data.isColumnContainingValue("ivoid", AMDA_IVOID)); |
177 | 216 | Map<String, Object> amda = data.getRowMapByValue("ivoid", AMDA_IVOID); |
178 | - assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url")); | |
179 | - assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name")); | |
217 | + | |
218 | + assertEquals(AMDA_ACCESS_URL, amda.get("access_url")); | |
219 | + assertEquals(AMDA_SHORT_NAME, amda.get("short_name")); | |
180 | 220 | } |
181 | 221 | |
222 | + /** | |
223 | + * Unit test for the class {@link EpnTapConnection#getEPNServices(List)}. | |
224 | + * | |
225 | + * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. | |
226 | + */ | |
182 | 227 | @Test |
183 | 228 | public void getEPNServicesWithAttributesTest() |
184 | 229 | throws CantGetVOTableException { |
185 | - System.out.println("getEPNServicesWithAttributesTest"); | |
230 | + logger.info("getEPNServicesWithAttributesTest"); | |
186 | 231 | EpnTapConnection facade = new EpnTapConnection(); |
187 | 232 | |
188 | 233 | final List<String> attributes = new ArrayList<>(); |
189 | 234 | attributes.add("access_url"); |
190 | 235 | attributes.add("short_name"); |
191 | 236 | |
192 | - VOTABLE voTable = facade.getEPNService("ivo://cdpp/amda", attributes); | |
237 | + VOTABLE voTable = facade.getEPNServices(attributes); | |
193 | 238 | VOTableData data = ServiceCtrl.getVoTableData(voTable); |
194 | 239 | |
195 | 240 | assertEquals(2, data.getNbColumns()); |
196 | - assertTrue("Column name ivoid not found.", data.isContainingColumnName("access_url")); | |
197 | - assertTrue("Column name ivoid not found.", data.isContainingColumnName("short_name")); | |
198 | - assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url")); | |
199 | - assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name")); | |
241 | + assertTrue("Column name access_url not found.", data.isContainingColumnName("access_url")); | |
242 | + assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name")); | |
243 | + assertTrue("AMDA short_name not found.", | |
244 | + data.isColumnContainingValue("short_name", AMDA_SHORT_NAME)); | |
245 | + assertTrue("AMDA access_url not found.", | |
246 | + data.isColumnContainingValue("access_url", AMDA_ACCESS_URL)); | |
247 | + | |
248 | + Map<String, Object> amda = data.getRowMapByValue("short_name", AMDA_SHORT_NAME); | |
249 | + assertEquals(AMDA_ACCESS_URL, amda.get("access_url")); | |
250 | + assertEquals(AMDA_SHORT_NAME, amda.get("short_name")); | |
200 | 251 | } |
201 | 252 | |
253 | + /** | |
254 | + * Unit test for the class {@link EpnTapConnection#getEPNServices(List, List)}. | |
255 | + * | |
256 | + * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. | |
257 | + * @throws VOResourceException Can not get the VOresource. | |
258 | + */ | |
202 | 259 | @Test |
203 | - public void getEPNServicesWithAttributesAndKeywordsTest() | |
260 | + public void getEPNServicesWithKeywordsAndAttributesTest() | |
204 | 261 | throws CantGetVOTableException, VOResourceException { |
205 | - System.out.println("getEPNServicesWithAttributesAndKeywordsTest"); | |
262 | + logger.info("getEPNServicesWithKeywordsAndAttributesTest"); | |
206 | 263 | EpnTapConnection facade = new EpnTapConnection(); |
207 | 264 | |
265 | + final List<String> keywords = new ArrayList<>(); | |
266 | + keywords.add(AMDA_SUBJECT); | |
267 | + | |
208 | 268 | final List<String> attributes = new ArrayList<>(); |
209 | 269 | attributes.add("access_url"); |
210 | 270 | attributes.add("short_name"); |
211 | 271 | |
212 | - final List<String> keywords = new ArrayList<>(); | |
213 | - keywords.add(AMDA_SUBJECT); | |
214 | - | |
215 | 272 | VOTABLE voTable = facade.getEPNServices(keywords, attributes); |
216 | 273 | VOTableData data = ServiceCtrl.getVoTableData(voTable); |
217 | 274 | |
218 | 275 | assertEquals(3, data.getNbColumns()); |
276 | + assertEquals(1, data.getNbRows()); | |
219 | 277 | // TODO: Should be return only 2 columns, because keywords do not contains res_subject. |
220 | 278 | assertTrue("Column name access_url not found.", data.isContainingColumnName("access_url")); |
221 | 279 | assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name")); |
... | ... | @@ -229,19 +287,29 @@ public class EpnTapConnectionTest { |
229 | 287 | |
230 | 288 | // *** Getters *** |
231 | 289 | |
290 | + /** | |
291 | + * Unit test for the class {@link EpnTapConnection#getEPNCoreTableName(String)}. | |
292 | + * | |
293 | + * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. | |
294 | + */ | |
232 | 295 | @Test |
233 | 296 | public void getEPNCoreTableNameTest() throws CantGetVOTableException { |
234 | - System.out.println("getEPNCoreTableNameTest"); | |
297 | + logger.info("getEPNCoreTableNameTest"); | |
235 | 298 | EpnTapConnection facade = new EpnTapConnection(); |
236 | 299 | |
237 | - String epnCoreTableName = facade.getEPNCoreTableName("ivo://cdpp/amda"); | |
300 | + String epnCoreTableName = facade.getEPNCoreTableName(AMDA_IVOID); | |
238 | 301 | |
239 | 302 | assertEquals("amdadb.epn_core", epnCoreTableName); |
240 | 303 | } |
241 | 304 | |
305 | + /** | |
306 | + * Unit test for the class {@link EpnTapConnection#getTAPURL(String)}. | |
307 | + * | |
308 | + * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. | |
309 | + */ | |
242 | 310 | @Test |
243 | 311 | public void getTAPURLTest() throws CantGetVOTableException { |
244 | - System.out.println("getTAPURLTest"); | |
312 | + logger.info("getTAPURLTest"); | |
245 | 313 | EpnTapConnection facade = new EpnTapConnection(); |
246 | 314 | |
247 | 315 | String tapURL = facade.getTAPURL("ivo://cdpp/amda"); |
... | ... | @@ -251,9 +319,14 @@ public class EpnTapConnectionTest { |
251 | 319 | |
252 | 320 | // *** Queries *** |
253 | 321 | |
322 | + /** | |
323 | + * Unit test for the class {@link EpnTapConnection#sendADQLQuery(String, String)}. | |
324 | + * | |
325 | + * @throws CantGetVOTableException Can not get the VOTable resulting the query. | |
326 | + */ | |
254 | 327 | @Test |
255 | 328 | public void sendADQLQueryTest() throws CantGetVOTableException { |
256 | - System.out.println("sendADQLQueryTest"); | |
329 | + logger.info("sendADQLQueryTest"); | |
257 | 330 | EpnTapConnection facade = new EpnTapConnection(); |
258 | 331 | |
259 | 332 | List<Granule> granules = facade.sendADQLQuery(SERVICE_EPNCOREV2_ACCESS_URL, |
... | ... | @@ -272,9 +345,14 @@ public class EpnTapConnectionTest { |
272 | 345 | assertEquals(new Integer(5), mars.processingLevel); |
273 | 346 | } |
274 | 347 | |
348 | + /** | |
349 | + * Unit test for the class {@link EpnTapConnection#sendQuery(String, String, Query)}. | |
350 | + * | |
351 | + * @throws CantGetVOTableException Can not get the VOTable resulting the query. | |
352 | + */ | |
275 | 353 | @Test |
276 | 354 | public void sendADQLQueryWithSchemaNameTest() throws CantGetVOTableException { |
277 | - System.out.println("sendADQLQueryWithSchemaNameTest"); | |
355 | + logger.info("sendADQLQueryWithSchemaNameTest"); | |
278 | 356 | EpnTapConnection facade = new EpnTapConnection(); |
279 | 357 | List<Granule> granules = facade.sendQuery(SERVICE_EPNCOREV2_ACCESS_URL, |
280 | 358 | SERVICE_EPNCOREV2_TABLE_NAME, Query.GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL); | ... | ... |