Commit 35daa117abf2d8e2f37c7002e5020defd5f4a486

Authored by Nathanael Jourdane
1 parent 5d00d3ff
Exists in master

Improve JUnits tests fix some errors to make them works.

src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java
@@ -19,22 +19,18 @@ package eu.omp.irap.vespa.epntapclient; @@ -19,22 +19,18 @@ package eu.omp.irap.vespa.epntapclient;
19 import java.text.ParseException; 19 import java.text.ParseException;
20 import java.util.ArrayList; 20 import java.util.ArrayList;
21 import java.util.List; 21 import java.util.List;
22 -import java.util.Map;  
23 import java.util.logging.Logger; 22 import java.util.logging.Logger;
24 23
25 import eu.omp.irap.vespa.epntapclient.granule.Granule; 24 import eu.omp.irap.vespa.epntapclient.granule.Granule;
26 import eu.omp.irap.vespa.epntapclient.granule.GranuleCtrl; 25 import eu.omp.irap.vespa.epntapclient.granule.GranuleCtrl;
27 import eu.omp.irap.vespa.epntapclient.service.Queries; 26 import eu.omp.irap.vespa.epntapclient.service.Queries;
28 -import eu.omp.irap.vespa.epntapclient.service.Service;  
29 import eu.omp.irap.vespa.epntapclient.service.ServiceCore; 27 import eu.omp.irap.vespa.epntapclient.service.ServiceCore;
30 import eu.omp.irap.vespa.epntapclient.service.ServiceCtrl; 28 import eu.omp.irap.vespa.epntapclient.service.ServiceCtrl;
31 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceCtrl; 29 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceCtrl;
32 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException; 30 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException;
33 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; 31 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
34 import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; 32 import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
35 -import eu.omp.irap.vespa.votable.Consts;  
36 import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; 33 import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
37 -import eu.omp.irap.vespa.votable.controller.VOTableController;  
38 import eu.omp.irap.vespa.votable.utils.StringJoiner; 34 import eu.omp.irap.vespa.votable.utils.StringJoiner;
39 import eu.omp.irap.vespa.votable.votabledata.VOTableData; 35 import eu.omp.irap.vespa.votable.votabledata.VOTableData;
40 36
@@ -58,122 +54,74 @@ public class EpnTapConnection implements EpnTapInterface { @@ -58,122 +54,74 @@ public class EpnTapConnection implements EpnTapInterface {
58 54
59 @Override 55 @Override
60 public List<Resource> getEPNVOResources() throws VOResourceException { 56 public List<Resource> getEPNVOResources() throws VOResourceException {
61 - return VOResourceCtrl.getVOResources(ServiceCore.EPNCORE); 57 + List<String> ivoids = VOResourceCtrl.getVOResources(ServiceCore.EPNCORE);
  58 + return VOResourceCtrl.getVOResources(ivoids);
62 } 59 }
63 60
64 @Override 61 @Override
65 - public List<Resource> getEPNVOResources(Map<String, String> keywords) 62 + public List<Resource> getEPNVOResources(List<String> keywords)
66 throws VOResourceException { 63 throws VOResourceException {
67 - return VOResourceCtrl.getVOResources(ServiceCore.EPNCORE, keywords); 64 + List<String> ivoids = VOResourceCtrl.getVOResources(ServiceCore.EPNCORE, keywords);
  65 + return VOResourceCtrl.getVOResources(ivoids);
68 } 66 }
69 67
70 // *** Service *** 68 // *** Service ***
71 69
72 - public Service _getEPNService(String ivoid) throws CantGetVOTableException {  
73 - return ServiceCtrl.getServiceFromIvoid(ivoid);  
74 - }  
75 -  
76 @Override 70 @Override
77 public VOTABLE getEPNService(String ivoid) throws CantGetVOTableException { 71 public VOTABLE getEPNService(String ivoid) throws CantGetVOTableException {
78 - String query = String.format(Queries.GET_TAP_SERVICES_WHERE_IVOID, ivoid);  
79 - VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);  
80 - ctrl.readTable();  
81 - return ctrl.getVOTable(); 72 + String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_IVOID, ivoid);
  73 + return ServiceCtrl.getVoTable(query);
82 } 74 }
83 75
84 @Override 76 @Override
85 public VOTABLE getEPNService(String ivoid, List<String> attributes) 77 public VOTABLE getEPNService(String ivoid, List<String> attributes)
86 throws CantGetVOTableException { 78 throws CantGetVOTableException {
87 - // TODO: optimiser le nombre de requêtes  
88 - String tableName = getEPNCoreTableName(ivoid);  
89 - String query = String.format(Queries.SELECT_FROM, StringJoiner.join(attributes), tableName);  
90 - VOTableController ctrl = new VOTableController(getTAPURL(ivoid), query);  
91 - ctrl.readTable();  
92 - return ctrl.getVOTable(); 79 + String select = StringJoiner.join(attributes);
  80 + String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_IVOID, select, ivoid);
  81 + return ServiceCtrl.getVoTable(query);
93 } 82 }
94 83
95 // *** Services *** 84 // *** Services ***
96 85
97 @Override 86 @Override
98 - public List<VOTABLE> getEPNServices() throws VOResourceException {  
99 - List<VOTABLE> voTables = new ArrayList<>();  
100 - List<String> ivoids = VOResourceCtrl.getIvoidResources(ServiceCore.EPNCORE);  
101 - // TODO: optimiser le nombre de requêtes  
102 - for (String ivoid : ivoids) {  
103 - try {  
104 - String query = String.format(Queries.SELECT_ALL, getEPNCoreTableName(ivoid));  
105 - VOTableController ctrl = new VOTableController(getTAPURL(ivoid), query);  
106 - ctrl.readTable();  
107 - voTables.add(ctrl.getVOTable());  
108 - } catch (CantGetVOTableException e) {  
109 - logger.info("Can not get the service " + ivoid + ", skipping...");  
110 - }  
111 - }  
112 - return voTables; 87 + public VOTABLE getEPNServices() throws CantGetVOTableException {
  88 + String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE,
  89 + ServiceCore.EPNCORE);
  90 + return ServiceCtrl.getVoTable(query);
113 } 91 }
114 92
115 @Override 93 @Override
116 - public List<VOTABLE> getEPNServices(List<String> attributes)  
117 - throws CantGetVOTableException, VOResourceException {  
118 - List<VOTABLE> voTables = new ArrayList<>();  
119 - List<String> ivoids = VOResourceCtrl.getIvoidResources(ServiceCore.EPNCORE);  
120 - // TODO: optimiser le nombre de requêtes  
121 - for (String ivoid : ivoids) {  
122 - try {  
123 - String tableName = getEPNCoreTableName(ivoid);  
124 - String query = String.format(Queries.SELECT_FROM, StringJoiner.join(attributes),  
125 - tableName);  
126 - VOTableController ctrl = new VOTableController(getTAPURL(ivoid), query);  
127 - ctrl.readTable();  
128 - voTables.add(ctrl.getVOTable());  
129 - } catch (CantGetVOTableException e) {  
130 - logger.info("Can not get the service " + ivoid + ", skipping...");  
131 - }  
132 - }  
133 - return voTables; 94 + public VOTABLE getEPNServices(List<String> attributes) throws CantGetVOTableException {
  95 + String select = StringJoiner.join(attributes);
  96 + String query = String.format(Queries.SELECT_TAP_SERVICES, select);
  97 + return ServiceCtrl.getVoTable(query);
134 } 98 }
135 99
136 @Override 100 @Override
137 - public List<VOTABLE> getEPNServices(Map<String, String> keywords, List<String> attributes)  
138 - throws CantGetVOTableException, VOResourceException {  
139 - List<VOTABLE> voTables = new ArrayList<>();  
140 - List<String> ivoids = VOResourceCtrl.getIvoidResources(ServiceCore.EPNCORE, keywords);  
141 - // TODO: optimiser le nombre de requêtes  
142 - for (String ivoid : ivoids) {  
143 - try {  
144 - String tableName = getEPNCoreTableName(ivoid);  
145 - String query = String.format(Queries.SELECT_FROM, StringJoiner.join(attributes),  
146 - tableName);  
147 - VOTableController ctrl = new VOTableController(getTAPURL(ivoid), query);  
148 - ctrl.readTable();  
149 - voTables.add(ctrl.getVOTable());  
150 - } catch (CantGetVOTableException e) {  
151 - logger.info("Can not get the service " + ivoid + ", skipping...");  
152 - } 101 + public VOTABLE getEPNServices(List<String> keywords, List<String> attributes)
  102 + throws CantGetVOTableException {
  103 + attributes.add("res_subject");
  104 + String select = StringJoiner.join(attributes);
  105 + List<String> whereList = new ArrayList<>();
  106 + for (String keyword : keywords) {
  107 + whereList.add("res_subject = '" + keyword + "'");
153 } 108 }
154 - return voTables; 109 + String where = StringJoiner.join(whereList, " OR ");
  110 + String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_SUBJECT, select, where);
  111 + // TODO: move this code to a new class in ServiceCtrl()
  112 + return ServiceCtrl.getVoTable(query);
155 } 113 }
156 114
157 // *** Getters *** 115 // *** Getters ***
158 116
159 @Override 117 @Override
160 - public String getEPNCoreTableName(String ivoid)  
161 - throws CantGetVOTableException {  
162 - String query = String.format(Queries.GET_TAP_SERVICES_SELECT_WHERE_IVOID, "table_name",  
163 - ivoid);  
164 - VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);  
165 - ctrl.readTable();  
166 - return (String) ctrl.getVOTableData().getCell(0, 0); 118 + public String getEPNCoreTableName(String ivoid) throws CantGetVOTableException {
  119 + return (String) ServiceCtrl.getParameter(ivoid, "table_name");
167 } 120 }
168 121
169 @Override 122 @Override
170 - public String getTAPURL(String ivoid)  
171 - throws CantGetVOTableException {  
172 - String query = String.format(Queries.GET_TAP_SERVICES_SELECT_WHERE_IVOID, "access_url",  
173 - ivoid);  
174 - VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);  
175 - ctrl.readTable();  
176 - return (String) ctrl.getVOTableData().getCell(0, 0); 123 + public String getTAPURL(String ivoid) throws CantGetVOTableException {
  124 + return (String) ServiceCtrl.getParameter(ivoid, "access_url");
177 } 125 }
178 126
179 // *** Queries *** 127 // *** Queries ***
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapController.java
@@ -52,7 +52,7 @@ public class EpnTapController { @@ -52,7 +52,7 @@ public class EpnTapController {
52 * Method constructor, which initialize servicesController, resultsController and mainView. 52 * Method constructor, which initialize servicesController, resultsController and mainView.
53 */ 53 */
54 public EpnTapController() { 54 public EpnTapController() {
55 - String query = String.format(Queries.GET_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE); 55 + String query = String.format(Queries.SELECT_ALL_TAP_SERVICES_WHERE_CORE, ServiceCore.EPNCORE);
56 servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query); 56 servicesCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
57 } 57 }
58 58
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapInterface.java
@@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
17 package eu.omp.irap.vespa.epntapclient; 17 package eu.omp.irap.vespa.epntapclient;
18 18
19 import java.util.List; 19 import java.util.List;
20 -import java.util.Map;  
21 20
22 import eu.omp.irap.vespa.epntapclient.granule.Granule; 21 import eu.omp.irap.vespa.epntapclient.granule.Granule;
23 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException; 22 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException;
@@ -44,7 +43,7 @@ public interface EpnTapInterface { @@ -44,7 +43,7 @@ public interface EpnTapInterface {
44 * Returns a set of VOREsource elements (one per EPN-TAP service corresponding to the keywords). 43 * Returns a set of VOREsource elements (one per EPN-TAP service corresponding to the keywords).
45 * The way keywords are defined is still to be defined. 44 * The way keywords are defined is still to be defined.
46 */ 45 */
47 - public List<Resource> getEPNVOResources(Map<String, String> keywords) 46 + public List<Resource> getEPNVOResources(List<String> keywords)
48 throws VOResourceException; 47 throws VOResourceException;
49 48
50 // *** Service *** 49 // *** Service ***
@@ -53,6 +52,8 @@ public interface EpnTapInterface { @@ -53,6 +52,8 @@ public interface EpnTapInterface {
53 * returns a VOTable containing the attributes of the corresponding service (from a predefined 52 * returns a VOTable containing the attributes of the corresponding service (from a predefined
54 * list) 53 * list)
55 * 54 *
  55 + * @throws VOResourceException
  56 + * @throws CantGetVOTableException
56 * @throws IllegalAccessException 57 * @throws IllegalAccessException
57 * @throws CantGetXMLException 58 * @throws CantGetXMLException
58 * @throws CantDisplayVOTableException 59 * @throws CantDisplayVOTableException
@@ -63,6 +64,8 @@ public interface EpnTapInterface { @@ -63,6 +64,8 @@ public interface EpnTapInterface {
63 * returns a VOTable containing the attributes of the corresponding service (from the list of 64 * returns a VOTable containing the attributes of the corresponding service (from the list of
64 * attributes) 65 * attributes)
65 * 66 *
  67 + * @throws VOResourceException
  68 + * @throws CantGetVOTableException
66 * @throws CantGetXMLException 69 * @throws CantGetXMLException
67 * @throws CantDisplayVOTableException 70 * @throws CantDisplayVOTableException
68 */ 71 */
@@ -78,7 +81,7 @@ public interface EpnTapInterface { @@ -78,7 +81,7 @@ public interface EpnTapInterface {
78 * @throws CantGetXMLException 81 * @throws CantGetXMLException
79 * @throws CantDisplayVOTableException 82 * @throws CantDisplayVOTableException
80 */ 83 */
81 - public List<VOTABLE> getEPNServices() throws CantGetVOTableException, VOResourceException; 84 + public VOTABLE getEPNServices() throws CantGetVOTableException;
82 85
83 /** 86 /**
84 * returns a VOTable containing the list of EPN-TAP services and their attributes (from the list 87 * returns a VOTable containing the list of EPN-TAP services and their attributes (from the list
@@ -87,8 +90,7 @@ public interface EpnTapInterface { @@ -87,8 +90,7 @@ public interface EpnTapInterface {
87 * @throws CantGetXMLException 90 * @throws CantGetXMLException
88 * @throws CantDisplayVOTableException 91 * @throws CantDisplayVOTableException
89 */ 92 */
90 - public List<VOTABLE> getEPNServices(List<String> attributes)  
91 - throws CantGetVOTableException, VOResourceException; 93 + public VOTABLE getEPNServices(List<String> attributes) throws CantGetVOTableException;
92 94
93 /** 95 /**
94 * returns a VOTable containing the list of EPN-TAP services corresponding to the keywords and 96 * returns a VOTable containing the list of EPN-TAP services corresponding to the keywords and
@@ -97,8 +99,8 @@ public interface EpnTapInterface { @@ -97,8 +99,8 @@ public interface EpnTapInterface {
97 * @throws CantGetXMLException 99 * @throws CantGetXMLException
98 * @throws CantDisplayVOTableException 100 * @throws CantDisplayVOTableException
99 */ 101 */
100 - public List<VOTABLE> getEPNServices(Map<String, String> keywords, List<String> attributes)  
101 - throws CantGetVOTableException, VOResourceException; 102 + public VOTABLE getEPNServices(List<String> keywords, List<String> attributes)
  103 + throws CantGetVOTableException;
102 104
103 // *** Getters *** 105 // *** Getters ***
104 106
src/main/java/eu/omp/irap/vespa/epntapclient/granule/GranuleCtrl.java
@@ -117,7 +117,7 @@ public class GranuleCtrl { @@ -117,7 +117,7 @@ public class GranuleCtrl {
117 } 117 }
118 118
119 public static boolean isV2(VOTableData data) { 119 public static boolean isV2(VOTableData data) {
120 - return !data.containsColumn("index"); 120 + return !data.isContainingColumnName("index");
121 } 121 }
122 122
123 public List<Granule> getGranulesFromVOTable() throws ParseException { 123 public List<Granule> getGranulesFromVOTable() throws ParseException {
src/main/java/eu/omp/irap/vespa/epntapclient/service/Queries.java
@@ -29,7 +29,7 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner; @@ -29,7 +29,7 @@ import eu.omp.irap.vespa.votable.utils.StringJoiner;
29 */ 29 */
30 public final class Queries { 30 public final class Queries {
31 31
32 - private static final String SELECT = "SELECT short_name, res_title AS schema_title, " 32 + private static final String SELECT = "SELECT DISTINCT short_name, res_title, "
33 + "table_name, schema_name, ivoid, access_url "; 33 + "table_name, schema_name, ivoid, access_url ";
34 34
35 private static final String FROM = "FROM rr.resource " 35 private static final String FROM = "FROM rr.resource "
@@ -49,32 +49,39 @@ public final class Queries { @@ -49,32 +49,39 @@ public final class Queries {
49 //@noformat 49 //@noformat
50 50
51 /** Query to get all TAP services. */ 51 /** Query to get all TAP services. */
52 - public static final String GET_TAP_SERVICES = 52 + public static final String SELECT_ALL_TAP_SERVICES =
53 Queries.SELECT + Queries.FROM + Queries.WHERE_TAP + Queries.ORDER_BY; 53 Queries.SELECT + Queries.FROM + Queries.WHERE_TAP + Queries.ORDER_BY;
54 54
55 /** Query to get TAP services which implement the specified core. */ 55 /** Query to get TAP services which implement the specified core. */
56 - public static final String GET_TAP_SERVICES_WHERE_CORE = 56 + public static final String SELECT_ALL_TAP_SERVICES_WHERE_CORE =
57 Queries.SELECT + Queries.FROM + Queries.WHERE_TAP 57 Queries.SELECT + Queries.FROM + Queries.WHERE_TAP
58 + "AND 1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/%s%%') " 58 + "AND 1=ivo_nocasematch(detail_value, 'ivo://vopdc.obspm/std/%s%%') "
59 + Queries.ORDER_BY; 59 + Queries.ORDER_BY;
60 60
61 /** Query to get the TAP service with the specified ivoid. */ 61 /** Query to get the TAP service with the specified ivoid. */
62 - public static final String GET_TAP_SERVICES_WHERE_IVOID = 62 + public static final String SELECT_ALL_TAP_SERVICES_WHERE_IVOID =
63 Queries.SELECT + Queries.FROM + Queries.WHERE_TAP 63 Queries.SELECT + Queries.FROM + Queries.WHERE_TAP
64 + "AND ivoid = '%s'"; 64 + "AND ivoid = '%s'";
65 65
66 - public static final String GET_TAP_SERVICES_SELECT_WHERE_IVOID =  
67 - "SELECT %s " + Queries.FROM + Queries.WHERE_TAP 66 + public static final String SELECT_TAP_SERVICES_WHERE_IVOID =
  67 + "SELECT DISTINCT %s " + Queries.FROM + Queries.WHERE_TAP
68 + "AND ivoid = '%s'"; 68 + "AND ivoid = '%s'";
69 69
  70 + public static final String SELECT_TAP_SERVICES =
  71 + "SELECT DISTINCT %s " + Queries.FROM + Queries.WHERE_TAP;
  72 +
  73 + public static final String SELECT_TAP_SERVICES_WHERE_SUBJECT =
  74 + "SELECT DISTINCT %s " + Queries.FROM + "NATURAL JOIN rr.res_subject "
  75 + + Queries.WHERE_TAP + "AND (%s)";
  76 +
70 public static final String SELECT_FROM = 77 public static final String SELECT_FROM =
71 - "SELECT %s FROM %s"; 78 + "SELECT DISTINCT %s FROM %s";
72 79
73 public static final String SELECT_ALL = 80 public static final String SELECT_ALL =
74 - "SELECT * FROM %s";  
75 - 81 + "SELECT DISTINCT * FROM %s";
76 //@format 82 //@format
77 83
  84 +
78 /** Constructor to hide the implicit public one. */ 85 /** Constructor to hide the implicit public one. */
79 private Queries() { 86 private Queries() {
80 } 87 }
src/main/java/eu/omp/irap/vespa/epntapclient/service/ServiceCtrl.java
@@ -19,6 +19,7 @@ package eu.omp.irap.vespa.epntapclient.service; @@ -19,6 +19,7 @@ package eu.omp.irap.vespa.epntapclient.service;
19 import java.text.SimpleDateFormat; 19 import java.text.SimpleDateFormat;
20 import java.util.ArrayList; 20 import java.util.ArrayList;
21 import java.util.List; 21 import java.util.List;
  22 +import java.util.Map;
22 import java.util.logging.Logger; 23 import java.util.logging.Logger;
23 24
24 import javax.xml.datatype.XMLGregorianCalendar; 25 import javax.xml.datatype.XMLGregorianCalendar;
@@ -27,11 +28,14 @@ import eu.omp.irap.vespa.epntapclient.voresource.model.ContentLevel; @@ -27,11 +28,14 @@ import eu.omp.irap.vespa.epntapclient.voresource.model.ContentLevel;
27 import eu.omp.irap.vespa.epntapclient.voresource.model.Creator; 28 import eu.omp.irap.vespa.epntapclient.voresource.model.Creator;
28 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; 29 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
29 import eu.omp.irap.vespa.epntapclient.voresource.model.Type; 30 import eu.omp.irap.vespa.epntapclient.voresource.model.Type;
  31 +import eu.omp.irap.vespa.epntapclient.votable.model.Table;
  32 +import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
30 import eu.omp.irap.vespa.votable.Consts; 33 import eu.omp.irap.vespa.votable.Consts;
31 import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; 34 import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
32 import eu.omp.irap.vespa.votable.controller.VOTableController; 35 import eu.omp.irap.vespa.votable.controller.VOTableController;
33 import eu.omp.irap.vespa.votable.utils.StringJoiner; 36 import eu.omp.irap.vespa.votable.utils.StringJoiner;
34 import eu.omp.irap.vespa.votable.votabledata.VOTableData; 37 import eu.omp.irap.vespa.votable.votabledata.VOTableData;
  38 +import eu.omp.irap.vespa.votable.votabledata.VOTableDataParser;
35 39
36 /** 40 /**
37 * @author N. Jourdane 41 * @author N. Jourdane
@@ -44,7 +48,7 @@ public class ServiceCtrl { @@ -44,7 +48,7 @@ public class ServiceCtrl {
44 public static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss"; 48 public static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss";
45 49
46 50
47 - public final static Service getServiceFromResource(Resource resource) { 51 + public final static Service getService(Resource resource) {
48 Service service = new Service(resource.getIdentifier()); 52 Service service = new Service(resource.getIdentifier());
49 service.setTitle(resource.getTitle()); 53 service.setTitle(resource.getTitle());
50 service.setShortName(resource.getShortName()); 54 service.setShortName(resource.getShortName());
@@ -71,7 +75,7 @@ public class ServiceCtrl { @@ -71,7 +75,7 @@ public class ServiceCtrl {
71 return service; 75 return service;
72 } 76 }
73 77
74 - public final static List<Service> getServicesFromVOTableData(VOTableData data) { 78 + public static final List<Service> getServices(VOTableData data) {
75 List<Service> services = new ArrayList<>(); 79 List<Service> services = new ArrayList<>();
76 for (int i = 0; i < data.getNbRows(); i++) { 80 for (int i = 0; i < data.getNbRows(); i++) {
77 Service service = new Service((String) data.getCell(i, "ivoid")); 81 Service service = new Service((String) data.getCell(i, "ivoid"));
@@ -90,13 +94,40 @@ public class ServiceCtrl { @@ -90,13 +94,40 @@ public class ServiceCtrl {
90 return services; 94 return services;
91 } 95 }
92 96
93 - public static Service getServiceFromIvoid(String ivoid) throws CantGetVOTableException {  
94 - // TODO: utiliser Resource plutôt que VOTable  
95 - String query = String.format(Queries.GET_TAP_SERVICES_WHERE_IVOID, ivoid);  
96 - VOTableController ctrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);  
97 - ctrl.readTable();  
98 - List<Service> services = ServiceCtrl.getServicesFromVOTableData(ctrl.getVOTableData());  
99 - return services.get(0); 97 + public static VOTableData getVoTableData(String query) throws CantGetVOTableException {
  98 + return getVoTableData(getVoTable(query));
  99 + }
  100 +
  101 + public static VOTableData getVoTableData(VOTABLE voTable) throws CantGetVOTableException {
  102 + VOTableController.checkVOTable(voTable);
  103 +
  104 + Table table = (Table) voTable.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0);
  105 + VOTableDataParser dataParser = new VOTableDataParser(table);
  106 + dataParser.parseData();
  107 + return dataParser.getData();
  108 + }
  109 +
  110 + public static VOTABLE getVoTable(String query) throws CantGetVOTableException {
  111 + VOTableController voTableCtrl = new VOTableController(Consts.DEFAULT_REGISTRY_URL, query);
  112 + voTableCtrl.readTable();
  113 + return voTableCtrl.getVOTable();
  114 + }
  115 +
  116 + public static Map<String, Object> getParameters(String ivoid, String parameters)
  117 + throws CantGetVOTableException {
  118 + String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_IVOID, parameters, ivoid);
  119 + return getVoTableData(query).getRowMap(0);
  120 + }
  121 +
  122 + public static Map<String, Object> getParameters(String ivoid, List<String> parameters)
  123 + throws CantGetVOTableException {
  124 + return getParameters(ivoid, StringJoiner.join(parameters));
  125 + }
  126 +
  127 + public static Object getParameter(String ivoid, String parameters)
  128 + throws CantGetVOTableException {
  129 + String query = String.format(Queries.SELECT_TAP_SERVICES_WHERE_IVOID, parameters, ivoid);
  130 + return getVoTableData(query).getCell(0, 0);
100 } 131 }
101 132
102 private static String XMLDateToString(XMLGregorianCalendar date) { 133 private static String XMLDateToString(XMLGregorianCalendar date) {
src/main/java/eu/omp/irap/vespa/epntapclient/voresource/VOResourceCtrl.java
@@ -53,7 +53,7 @@ public class VOResourceCtrl { @@ -53,7 +53,7 @@ public class VOResourceCtrl {
53 53
54 private static final String GET_VORESOURCE_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources.xml"; 54 private static final String GET_VORESOURCE_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources.xml";
55 55
56 - private static final String GET_IVOID_RESOURCES_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources/search"; 56 + private static final String GET_JSONRESOURCES_URL = "http://voparis-registry.obspm.fr/vo/ivoa/1/voresources/search";
57 57
58 private static final int MAX_VORESOURCES = 100; 58 private static final int MAX_VORESOURCES = 100;
59 59
@@ -67,37 +67,31 @@ public class VOResourceCtrl { @@ -67,37 +67,31 @@ public class VOResourceCtrl {
67 private static final String NAMESPACE_TR = "http://www.ivoa.net/xml/VODataService/v1.1"; 67 private static final String NAMESPACE_TR = "http://www.ivoa.net/xml/VODataService/v1.1";
68 68
69 69
70 - public static List<Resource> getVOResources(ServiceCore type, Map<String, String> keywords)  
71 - throws VOResourceException {  
72 - List<String> ivoids = VOResourceCtrl.getIvoidResources(type, keywords);  
73 - return VOResourceCtrl.getVOResourcesFromIvoids(ivoids);  
74 - }  
75 -  
76 - public static List<Resource> getVOResources(ServiceCore type) throws VOResourceException {  
77 - List<String> ivoids = VOResourceCtrl.getIvoidResources(type);  
78 - return VOResourceCtrl.getVOResourcesFromIvoids(ivoids);  
79 - } 70 + public static List<String> getVOResources(ServiceCore type) throws VOResourceException {
  71 + List<String> ivoidResources;
  72 + Map<String, String> parameters = new HashMap();
80 73
81 - public static List<String> getIvoidResources(ServiceCore type) throws VOResourceException {  
82 - return VOResourceCtrl.getIvoidResources(type, new HashMap()); 74 + parameters.put("keywords", "datamodel:\"EpnCore\"");
  75 + parameters.put("max", String.valueOf(MAX_VORESOURCES));
  76 + String query = Network.buildQuery(GET_JSONRESOURCES_URL, parameters);
  77 + try {
  78 + ivoidResources = parseIvoidResources(Network.readJson(query));
  79 + } catch (CantSendQueryException e) {
  80 + throw new CantGetVOResourceException(GET_VORESOURCE_URL, e);
  81 + }
  82 + logger.info("Got resources: " + StringJoiner.join(ivoidResources));
  83 + return ivoidResources;
83 } 84 }
84 85
85 - public static List<String> getIvoidResources(ServiceCore type, Map<String, String> keywords) 86 + public static List<String> getVOResources(ServiceCore type, List<String> keywords)
86 throws CantGetVOResourceException { 87 throws CantGetVOResourceException {
87 List<String> ivoidResources; 88 List<String> ivoidResources;
88 -  
89 - keywords.put("datamodel", type.toString());  
90 - // standardid="ivo://ivoa.net/std/TAP" is not necessary  
91 -  
92 - StringJoiner keywordJoiner = new StringJoiner(" ");  
93 - for (Map.Entry<String, String> keyword : keywords.entrySet()) {  
94 - keywordJoiner.add(keyword.getKey().toLowerCase() + ":\"" + keyword.getValue() + "\"");  
95 - }  
96 -  
97 Map<String, String> parameters = new HashMap(); 89 Map<String, String> parameters = new HashMap();
98 - parameters.put("keywords", keywordJoiner.toString());  
99 - parameters.put("max", String.valueOf(VOResourceCtrl.MAX_VORESOURCES));  
100 - String query = Network.buildQuery(GET_IVOID_RESOURCES_URL, parameters); 90 + String subjects = StringJoiner.join(keywords);
  91 + parameters.put("keywords", "datamodel:\"EpnCore\" subjects:\"" + subjects + "\"");
  92 + parameters.put("max", String.valueOf(MAX_VORESOURCES));
  93 +
  94 + String query = Network.buildQuery(GET_JSONRESOURCES_URL, parameters);
101 try { 95 try {
102 ivoidResources = parseIvoidResources(Network.readJson(query)); 96 ivoidResources = parseIvoidResources(Network.readJson(query));
103 } catch (CantSendQueryException e) { 97 } catch (CantSendQueryException e) {
@@ -113,13 +107,13 @@ public class VOResourceCtrl { @@ -113,13 +107,13 @@ public class VOResourceCtrl {
113 String voResourcePath; 107 String voResourcePath;
114 108
115 try { 109 try {
116 - VOResourceCtrl.logger.info("Trying to get VOResource '" + identifier + "'...");  
117 - String query = Network.buildQuery(VOResourceCtrl.GET_VORESOURCE_URL, parameters); 110 + logger.info("Trying to get VOResource '" + identifier + "'...");
  111 + String query = Network.buildQuery(GET_VORESOURCE_URL, parameters);
118 voResourcePath = Network.saveQuery(query); 112 voResourcePath = Network.saveQuery(query);
119 } catch (CantSendQueryException e) { 113 } catch (CantSendQueryException e) {
120 - throw new CantGetVOResourceException(VOResourceCtrl.GET_VORESOURCE_URL, e); 114 + throw new CantGetVOResourceException(GET_VORESOURCE_URL, e);
121 } 115 }
122 - VOResourceCtrl.logger.info("VOResource downloaded in " + voResourcePath); 116 + logger.info("VOResource downloaded in " + voResourcePath);
123 117
124 try { 118 try {
125 changeNamespaces(voResourcePath); 119 changeNamespaces(voResourcePath);
@@ -140,7 +134,6 @@ public class VOResourceCtrl { @@ -140,7 +134,6 @@ public class VOResourceCtrl {
140 } catch (JAXBException e) { 134 } catch (JAXBException e) {
141 throw new VOResourceIsNotValidException(voResourcePath, e); 135 throw new VOResourceIsNotValidException(voResourcePath, e);
142 } 136 }
143 -  
144 return voResource; 137 return voResource;
145 } 138 }
146 139
@@ -152,11 +145,11 @@ public class VOResourceCtrl { @@ -152,11 +145,11 @@ public class VOResourceCtrl {
152 XMLUtils.changeRootAttributes(voResourcePath, attributes); 145 XMLUtils.changeRootAttributes(voResourcePath, attributes);
153 } 146 }
154 147
155 - public static List<Resource> getVOResourcesFromIvoids(List<String> ivoidResources) 148 + public static List<Resource> getVOResources(List<String> ivoidResources)
156 throws VOResourceException { 149 throws VOResourceException {
157 List<Resource> resources = new ArrayList<>(); 150 List<Resource> resources = new ArrayList<>();
158 for (String ivoid : ivoidResources) { 151 for (String ivoid : ivoidResources) {
159 - resources.add(VOResourceCtrl.getVOresource(ivoid)); 152 + resources.add(getVOresource(ivoid));
160 } 153 }
161 return resources; 154 return resources;
162 } 155 }
src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java
@@ -18,9 +18,9 @@ package eu.omp.irap.vespa.epntapclient; @@ -18,9 +18,9 @@ package eu.omp.irap.vespa.epntapclient;
18 18
19 import static org.junit.Assert.assertEquals; 19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotNull; 20 import static org.junit.Assert.assertNotNull;
  21 +import static org.junit.Assert.assertTrue;
21 22
22 import java.util.ArrayList; 23 import java.util.ArrayList;
23 -import java.util.HashMap;  
24 import java.util.List; 24 import java.util.List;
25 import java.util.Map; 25 import java.util.Map;
26 import java.util.logging.Logger; 26 import java.util.logging.Logger;
@@ -28,13 +28,13 @@ import java.util.logging.Logger; @@ -28,13 +28,13 @@ import java.util.logging.Logger;
28 import org.junit.Test; 28 import org.junit.Test;
29 29
30 import eu.omp.irap.vespa.epntapclient.granule.Granule; 30 import eu.omp.irap.vespa.epntapclient.granule.Granule;
  31 +import eu.omp.irap.vespa.epntapclient.service.ServiceCtrl;
31 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceCtrl; 32 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceCtrl;
32 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException; 33 import eu.omp.irap.vespa.epntapclient.voresource.VOResourceException;
33 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource; 34 import eu.omp.irap.vespa.epntapclient.voresource.model.Resource;
34 -import eu.omp.irap.vespa.epntapclient.votable.model.Field;  
35 -import eu.omp.irap.vespa.epntapclient.votable.model.Table;  
36 import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; 35 import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE;
37 import eu.omp.irap.vespa.votable.controller.CantGetVOTableException; 36 import eu.omp.irap.vespa.votable.controller.CantGetVOTableException;
  37 +import eu.omp.irap.vespa.votable.votabledata.VOTableData;
38 38
39 /** 39 /**
40 * @author N. Jourdane 40 * @author N. Jourdane
@@ -44,10 +44,26 @@ public class EpnTapConnectionTest { @@ -44,10 +44,26 @@ public class EpnTapConnectionTest {
44 /** The logger for the class Main. */ 44 /** The logger for the class Main. */
45 private static final Logger logger = Logger.getLogger(EpnTapConnectionTest.class.getName()); 45 private static final Logger logger = Logger.getLogger(EpnTapConnectionTest.class.getName());
46 46
  47 + private static final String AMDA_IVOID = "ivo://cdpp/amda";
  48 +
  49 + private static final String AMDA_SHORT_NAME = "AMDA";
  50 +
  51 + private static final String AMDA_ACCESS_URL = "http://cdpp-epntap.cesr.fr/__system__/tap/run/tap";
  52 +
  53 + private static final String AMDA_SUBJECT = "Space plasmas";
  54 +
  55 + private static final String APIS_IVOID = "ivo://vopdc.obspm/lesia/apis/epn";
  56 +
  57 + private static final String APIS_SHORT_NAME = "APIS";
  58 +
  59 + // *** VOResources ***
  60 +
47 61
48 @Test 62 @Test
49 public void getVOResourceTest() throws VOResourceException { 63 public void getVOResourceTest() throws VOResourceException {
  64 + System.out.println("getVOResourceTest");
50 EpnTapConnection facade = new EpnTapConnection(); 65 EpnTapConnection facade = new EpnTapConnection();
  66 +
51 Resource resource = VOResourceCtrl.getVOresource("ivo://cdpp/amda"); 67 Resource resource = VOResourceCtrl.getVOresource("ivo://cdpp/amda");
52 68
53 assertEquals("AMDA", resource.getShortName()); 69 assertEquals("AMDA", resource.getShortName());
@@ -58,118 +74,189 @@ public class EpnTapConnectionTest { @@ -58,118 +74,189 @@ public class EpnTapConnectionTest {
58 74
59 @Test 75 @Test
60 public void getEPNVOResourcesTest() throws VOResourceException { 76 public void getEPNVOResourcesTest() throws VOResourceException {
  77 + System.out.println("getEPNVOResourcesTest");
61 EpnTapConnection facade = new EpnTapConnection(); 78 EpnTapConnection facade = new EpnTapConnection();
  79 +
62 List<Resource> resources = facade.getEPNVOResources(); 80 List<Resource> resources = facade.getEPNVOResources();
63 81
64 - assertEquals(13, resources.size());  
65 - for (Resource r : resources) {  
66 - assertNotNull(r); 82 + int nbResources = resources.size();
  83 + assertTrue(nbResources + " ∉ [13;20]", nbResources >= 13 && nbResources <= 20);
  84 +
  85 + Resource amda = null;
  86 + Resource apis = null;
  87 + for (Resource resource : resources) {
  88 + if (AMDA_IVOID.equals(resource.getIdentifier())) {
  89 + amda = resource;
  90 + }
  91 + if (APIS_IVOID.equals(resource.getIdentifier())) {
  92 + apis = resource;
  93 + }
67 } 94 }
  95 + assertNotNull("AMDA resource should be present.", amda);
  96 + assertNotNull("APIS resource should be present.", apis);
  97 + assertEquals(AMDA_SHORT_NAME, amda.getShortName());
  98 + assertEquals(APIS_SHORT_NAME, apis.getShortName());
68 } 99 }
69 100
70 @Test 101 @Test
71 public void getEPNVOResourcesWithKeywordsTest() throws VOResourceException { 102 public void getEPNVOResourcesWithKeywordsTest() throws VOResourceException {
  103 + System.out.println("getEPNVOResourcesWithKeywordsTest");
72 EpnTapConnection facade = new EpnTapConnection(); 104 EpnTapConnection facade = new EpnTapConnection();
73 - final Map<String, String> keywords = new HashMap<>();  
74 - keywords.put("shortName", "IKS");  
75 - List<Resource> resources = facade.getEPNVOResources();  
76 105
77 - assertEquals(2, resources.size()); 106 + final List<String> keywords = new ArrayList<>();
  107 + keywords.add(AMDA_SUBJECT);
  108 + List<Resource> resources = facade.getEPNVOResources(keywords);
  109 +
  110 + assertEquals(resources.size(), 1);
  111 +
  112 + Resource amda = null;
  113 + for (Resource resource : resources) {
  114 + System.out.println(resource.getIdentifier());
  115 + if (AMDA_IVOID.equals(resource.getIdentifier())) {
  116 + amda = resource;
  117 + }
  118 + }
  119 + assertNotNull("AMDA resource should be present.", amda);
78 } 120 }
79 121
  122 + // *** Services ***
  123 +
80 @Test 124 @Test
81 public void getEPNServiceTest() throws CantGetVOTableException { 125 public void getEPNServiceTest() throws CantGetVOTableException {
  126 + System.out.println("getEPNServiceTest");
82 EpnTapConnection facade = new EpnTapConnection(); 127 EpnTapConnection facade = new EpnTapConnection();
83 128
84 - VOTABLE epnService = facade.getEPNService("ivo://cdpp/amda");  
85 - Table table = (Table) epnService.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0);  
86 - String firstInfoVal = epnService.getRESOURCE().get(0).getINFO().get(0).getValueAttribute();  
87 - String firstFieldName = ((Field) table.getFIELDOrPARAMOrGROUP().get(0)).getID(); 129 + VOTABLE voTable = facade.getEPNService("ivo://cdpp/amda");
  130 + VOTableData data = ServiceCtrl.getVoTableData(voTable);
88 131
89 - assertEquals("http://gavo.aip.de", firstInfoVal);  
90 - assertEquals("short_name", firstFieldName); 132 + assertEquals(1, data.getNbRows());
  133 + assertTrue("Column name ivoid not found.", data.isContainingColumnName("ivoid"));
  134 + assertTrue("Column name short_name not found.", data.isContainingColumnName("access_url"));
  135 + assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name"));
  136 + assertEquals(AMDA_IVOID, data.getCell(0, "ivoid"));
  137 + assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url"));
  138 + assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name"));
91 } 139 }
92 140
93 @Test 141 @Test
94 public void getEPNServiceWithAttributesTest() throws CantGetVOTableException { 142 public void getEPNServiceWithAttributesTest() throws CantGetVOTableException {
  143 + System.out.println("getEPNServiceWithAttributesTest");
95 EpnTapConnection facade = new EpnTapConnection(); 144 EpnTapConnection facade = new EpnTapConnection();
96 145
97 - final List<String> serviceAttributes = new ArrayList<>();  
98 - serviceAttributes.add("target_name");  
99 - serviceAttributes.add("time_min");  
100 - serviceAttributes.add("time_max"); 146 + final List<String> attributes = new ArrayList<>();
  147 + attributes.add("access_url");
  148 + attributes.add("short_name");
101 149
102 - VOTABLE epnService = facade.getEPNService("ivo://cdpp/amda", serviceAttributes);  
103 - Table table = (Table) epnService.getRESOURCE().get(0).getLINKAndTABLEOrRESOURCE().get(0);  
104 - String firstInfoVal = epnService.getRESOURCE().get(0).getINFO().get(0).getValueAttribute();  
105 - String firstFieldName = ((Field) table.getFIELDOrPARAMOrGROUP().get(0)).getID(); 150 + VOTABLE voTable = facade.getEPNService("ivo://cdpp/amda", attributes);
  151 + VOTableData data = ServiceCtrl.getVoTableData(voTable);
106 152
107 - assertEquals("http://cdpp-epntap.cesr.fr", firstInfoVal);  
108 - assertEquals("short_name", firstFieldName); 153 + assertEquals(1, data.getNbRows());
  154 + assertEquals(2, data.getNbColumns());
  155 + assertTrue("Column name short_name not found.", data.isContainingColumnName("access_url"));
  156 + assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name"));
  157 + assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url"));
  158 + assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name"));
109 } 159 }
110 160
111 @Test 161 @Test
112 - public void getEPNServicesTest() throws VOResourceException { 162 + public void getEPNServicesTest() throws CantGetVOTableException {
  163 + System.out.println("getEPNServicesTest");
113 EpnTapConnection facade = new EpnTapConnection(); 164 EpnTapConnection facade = new EpnTapConnection();
114 - List<VOTABLE> voTables = facade.getEPNServices();  
115 - assertEquals(11, voTables.size()); 165 +
  166 + VOTABLE voTable = facade.getEPNServices();
  167 + VOTableData data = ServiceCtrl.getVoTableData(voTable);
  168 + int nbServices = data.getNbRows();
  169 + assertTrue(nbServices + " ∉ [13;20].", nbServices >= 13 && nbServices <= 20);
  170 + assertTrue("Column name ivoid not found.", data.isContainingColumnName("short_name"));
  171 + assertTrue("AMDA ivoid not found.", data.isColumnContainingValue("ivoid", AMDA_IVOID));
  172 + Map<String, Object> amda = data.getRowMapByValue("ivoid", AMDA_IVOID);
  173 + assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url"));
  174 + assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name"));
116 } 175 }
117 176
118 @Test 177 @Test
119 public void getEPNServicesWithAttributesTest() 178 public void getEPNServicesWithAttributesTest()
120 - throws VOResourceException, CantGetVOTableException {  
121 - final List<String> serviceAttributes = new ArrayList<>();  
122 - serviceAttributes.add("target_name");  
123 - serviceAttributes.add("time_min");  
124 - serviceAttributes.add("time_max");  
125 - 179 + throws CantGetVOTableException {
  180 + System.out.println("getEPNServicesWithAttributesTest");
126 EpnTapConnection facade = new EpnTapConnection(); 181 EpnTapConnection facade = new EpnTapConnection();
127 - List<VOTABLE> voTables = facade.getEPNServices(serviceAttributes);  
128 - String firstInfoVal = voTables.get(0).getRESOURCE().get(0).getINFO().get(0)  
129 - .getValueAttribute();  
130 182
131 - assertEquals("http://gavo.aip.de", firstInfoVal); 183 + final List<String> attributes = new ArrayList<>();
  184 + attributes.add("access_url");
  185 + attributes.add("short_name");
  186 +
  187 + VOTABLE voTable = facade.getEPNService("ivo://cdpp/amda", attributes);
  188 + VOTableData data = ServiceCtrl.getVoTableData(voTable);
  189 +
  190 + assertEquals(2, data.getNbColumns());
  191 + assertTrue("Column name ivoid not found.", data.isContainingColumnName("access_url"));
  192 + assertTrue("Column name ivoid not found.", data.isContainingColumnName("short_name"));
  193 + assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url"));
  194 + assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name"));
132 } 195 }
133 196
134 @Test 197 @Test
135 public void getEPNServicesWithAttributesAndKeywordsTest() 198 public void getEPNServicesWithAttributesAndKeywordsTest()
136 throws CantGetVOTableException, VOResourceException { 199 throws CantGetVOTableException, VOResourceException {
137 - final List<String> serviceAttributes = new ArrayList<>();  
138 - serviceAttributes.add("target_name");  
139 - serviceAttributes.add("time_min");  
140 - serviceAttributes.add("time_max");  
141 -  
142 - final Map<String, String> keywords = new HashMap<>();  
143 - keywords.put("shortName", "IKS");  
144 - 200 + System.out.println("getEPNServicesWithAttributesAndKeywordsTest");
145 EpnTapConnection facade = new EpnTapConnection(); 201 EpnTapConnection facade = new EpnTapConnection();
146 - List<VOTABLE> voTables = facade.getEPNServices(keywords, serviceAttributes);  
147 - String firstInfoVal = voTables.get(0).getRESOURCE().get(0).getINFO().get(0)  
148 - .getValueAttribute();  
149 - assertEquals("http://gavo.aip.de", firstInfoVal); 202 +
  203 + final List<String> attributes = new ArrayList<>();
  204 + attributes.add("access_url");
  205 + attributes.add("short_name");
  206 +
  207 + final List<String> keywords = new ArrayList<>();
  208 + keywords.add(AMDA_SUBJECT);
  209 +
  210 + VOTABLE voTable = facade.getEPNServices(keywords, attributes);
  211 + VOTableData data = ServiceCtrl.getVoTableData(voTable);
  212 +
  213 + assertEquals(3, data.getNbColumns());
  214 + // TODO: Should be return only 2 columns, because keywords do not contains res_subject.
  215 + assertTrue("Column name access_url not found.", data.isContainingColumnName("access_url"));
  216 + assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name"));
  217 + assertTrue("AMDA short_name not found.",
  218 + data.isColumnContainingValue("short_name", AMDA_SHORT_NAME));
  219 + assertTrue("AMDA access_url not found.",
  220 + data.isColumnContainingValue("access_url", AMDA_ACCESS_URL));
  221 + assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name"));
  222 + assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url"));
150 } 223 }
151 224
  225 + // *** Getters ***
  226 +
152 @Test 227 @Test
153 public void getEPNCoreTableNameTest() throws CantGetVOTableException { 228 public void getEPNCoreTableNameTest() throws CantGetVOTableException {
  229 + System.out.println("getEPNCoreTableNameTest");
154 EpnTapConnection facade = new EpnTapConnection(); 230 EpnTapConnection facade = new EpnTapConnection();
  231 +
155 String epnCoreTableName = facade.getEPNCoreTableName("ivo://cdpp/amda"); 232 String epnCoreTableName = facade.getEPNCoreTableName("ivo://cdpp/amda");
156 - assertEquals("?", epnCoreTableName); 233 +
  234 + assertEquals("amdadb.epn_core", epnCoreTableName);
157 } 235 }
158 236
159 @Test 237 @Test
160 public void getTAPURLTest() throws CantGetVOTableException { 238 public void getTAPURLTest() throws CantGetVOTableException {
  239 + System.out.println("getTAPURLTest");
161 EpnTapConnection facade = new EpnTapConnection(); 240 EpnTapConnection facade = new EpnTapConnection();
  241 +
162 String tapURL = facade.getTAPURL("ivo://cdpp/amda"); 242 String tapURL = facade.getTAPURL("ivo://cdpp/amda");
  243 +
163 assertEquals("http://cdpp-epntap.cesr.fr/__system__/tap/run/tap", tapURL); 244 assertEquals("http://cdpp-epntap.cesr.fr/__system__/tap/run/tap", tapURL);
164 } 245 }
165 246
  247 + // *** Queries ***
  248 +
166 @Test 249 @Test
167 public void sendADQLQueryTest() throws CantGetVOTableException { 250 public void sendADQLQueryTest() throws CantGetVOTableException {
  251 + System.out.println("sendADQLQueryTest");
168 EpnTapConnection facade = new EpnTapConnection(); 252 EpnTapConnection facade = new EpnTapConnection();
  253 +
169 String tapURL = "http://voparis-tap-planeto.obspm.fr/__system__/tap/run/tap"; 254 String tapURL = "http://voparis-tap-planeto.obspm.fr/__system__/tap/run/tap";
170 String query = "SELECT TOP 1 * FROM planets.epn_core"; 255 String query = "SELECT TOP 1 * FROM planets.epn_core";
171 List<Granule> granules = facade.sendADQLQuery(tapURL, query); 256 List<Granule> granules = facade.sendADQLQuery(tapURL, query);
172 257
  258 + assertNotNull("Granules list not returned.", granules);
  259 + assertTrue("No granules returned.", granules.size() > 0);
173 assertEquals("?", granules.get(0).granuleUid); 260 assertEquals("?", granules.get(0).granuleUid);
174 assertEquals("?", granules.get(0).timeMin); 261 assertEquals("?", granules.get(0).timeMin);
175 assertEquals("?", granules.get(0).processingLevel); 262 assertEquals("?", granules.get(0).processingLevel);
@@ -178,12 +265,15 @@ public class EpnTapConnectionTest { @@ -178,12 +265,15 @@ public class EpnTapConnectionTest {
178 265
179 @Test 266 @Test
180 public void sendADQLQueryWithSchemaNameTest() throws CantGetVOTableException { 267 public void sendADQLQueryWithSchemaNameTest() throws CantGetVOTableException {
  268 + System.out.println("sendADQLQueryWithSchemaNameTest");
181 EpnTapConnection facade = new EpnTapConnection(); 269 EpnTapConnection facade = new EpnTapConnection();
182 String tapURL = "http://voparis-tap-planeto.obspm.fr/__system__/tap/run/tap"; 270 String tapURL = "http://voparis-tap-planeto.obspm.fr/__system__/tap/run/tap";
183 String schemaName = "amdadb.epn_core"; 271 String schemaName = "amdadb.epn_core";
184 String query = "SELECT TOP 1 * FROM planets.epn_core"; 272 String query = "SELECT TOP 1 * FROM planets.epn_core";
185 List<Granule> granules = facade.sendQuery(tapURL, schemaName, query); 273 List<Granule> granules = facade.sendQuery(tapURL, schemaName, query);
186 274
  275 + assertNotNull("Granules list not returned.", granules);
  276 + assertTrue("No granules returned.", granules.size() > 0);
187 assertEquals("?", granules.get(0).granuleUid); 277 assertEquals("?", granules.get(0).granuleUid);
188 assertEquals("?", granules.get(0).timeMin); 278 assertEquals("?", granules.get(0).timeMin);
189 assertEquals("?", granules.get(0).processingLevel); 279 assertEquals("?", granules.get(0).processingLevel);