From 99642cfe08fb13b9e72099dd65c01103e7ee71b1 Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Thu, 12 May 2016 13:12:52 +0200 Subject: [PATCH] Improve unit test for ADQL queries. --- src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java | 8 +++++--- src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java | 50 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java index acfb001..39acf20 100644 --- a/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java +++ b/src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapConnection.java @@ -31,6 +31,7 @@ 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.controller.VOTableController; import eu.omp.irap.vespa.votable.utils.StringJoiner; import eu.omp.irap.vespa.votable.votabledata.VOTableData; @@ -129,9 +130,10 @@ public class EpnTapConnection implements EpnTapInterface { @Override public List sendADQLQuery(String tapURL, String adqlQuery) throws CantGetVOTableException { - EpnTapController epnTapCtrl = new EpnTapController(); - epnTapCtrl.sendQuery(adqlQuery, tapURL); - VOTableData data = epnTapCtrl.getResultsController().getVOTableData(); + VOTableController voTableCtrl = new VOTableController(tapURL, adqlQuery); + voTableCtrl.readTable(); + VOTableData data = voTableCtrl.getVOTableData(); + List granules; try { GranuleCtrl gc = new GranuleCtrl(data); diff --git a/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java b/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java index f363dd1..c885d70 100644 --- a/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java +++ b/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.logging.Logger; @@ -56,6 +57,11 @@ public class EpnTapConnectionTest { private static final String APIS_SHORT_NAME = "APIS"; + private static final String SERVICE_EPNCOREV2_ACCESS_URL = "http://voparis-tap-planeto.obspm.fr/__system__/tap/run/tap"; + + private static final String SERVICE_EPNCOREV2_QUERY = "SELECT * FROM planets.epn_core"; + + private static final String SERVICE_EPNCOREV2_TABLE_NAME = "planets.epn_core"; // *** VOResources *** @@ -251,32 +257,42 @@ public class EpnTapConnectionTest { System.out.println("sendADQLQueryTest"); 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 granules = facade.sendADQLQuery(tapURL, query); + List granules = facade.sendADQLQuery(SERVICE_EPNCOREV2_ACCESS_URL, + SERVICE_EPNCOREV2_QUERY); assertNotNull("Granules list not returned.", granules); - assertTrue("No granules returned.", granules.size() > 0); - assertEquals("?", granules.get(0).granuleUid); - assertEquals("?", granules.get(0).timeMin); - assertEquals("?", granules.get(0).processingLevel); - assertEquals("?", granules.get(0).creationDate); + assertEquals(8, granules.size()); + Granule mars = null; + for (Granule granule : granules) { + if ("Mars".equals(granule.granuleUid)) { + mars = granule; + } + } + assertNotNull("granule 'Mars' is not found.", mars); + assertEquals("4", mars.obsId); + assertEquals(new Integer(5), mars.processingLevel); + assertEquals(mars.creationDate, new Date(2015, 8, 20)); } @Test public void sendADQLQueryWithSchemaNameTest() throws CantGetVOTableException { System.out.println("sendADQLQueryWithSchemaNameTest"); 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 granules = facade.sendQuery(tapURL, schemaName, query); + List granules = facade.sendQuery(SERVICE_EPNCOREV2_ACCESS_URL, + SERVICE_EPNCOREV2_TABLE_NAME, SERVICE_EPNCOREV2_QUERY); assertNotNull("Granules list not returned.", granules); - assertTrue("No granules returned.", granules.size() > 0); - assertEquals("?", granules.get(0).granuleUid); - assertEquals("?", granules.get(0).timeMin); - assertEquals("?", granules.get(0).processingLevel); - assertEquals("?", granules.get(0).creationDate); + assertEquals(8, granules.size()); + Granule mars = null; + for (Granule granule : granules) { + if ("Mars".equals(granule.granuleUid)) { + mars = granule; + } + } + assertNotNull("granule 'Mars' is not found.", mars); + assertEquals(mars.obsId, 4); + assertEquals((int) mars.processingLevel, 5); + assertEquals(mars.creationDate, "2015-08-20"); + } } -- libgit2 0.21.2