From 330431b575aef0a67632d1600b6265ac84ac87d5 Mon Sep 17 00:00:00 2001 From: Nathanael Jourdane Date: Fri, 13 May 2016 19:46:40 +0200 Subject: [PATCH] Fix a Junit test and add Javadoc --- src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 107 insertions(+), 29 deletions(-) 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 f75cffc..26388eb 100644 --- a/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java +++ b/src/test/java/eu/omp/irap/vespa/epntapclient/EpnTapConnectionTest.java @@ -29,7 +29,6 @@ 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.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.VOTABLE; @@ -39,37 +38,52 @@ 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 { - System.out.println("getVOResourceTest"); + logger.info("getVOResourceTest"); EpnTapConnection facade = new EpnTapConnection(); - Resource resource = VOResourceCtrl.getVOresource("ivo://cdpp/amda"); + Resource resource = facade.getEPNVOresource(AMDA_IVOID); assertEquals("AMDA", resource.getShortName()); assertEquals("CDPP AMDA DataBase", resource.getTitle()); @@ -77,9 +91,14 @@ public class EpnTapConnectionTest { 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 { - System.out.println("getEPNVOResourcesTest"); + logger.info("getEPNVOResourcesTest"); EpnTapConnection facade = new EpnTapConnection(); List resources = facade.getEPNVOResources(); @@ -103,9 +122,14 @@ public class EpnTapConnectionTest { 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 { - System.out.println("getEPNVOResourcesWithKeywordsTest"); + logger.info("getEPNVOResourcesWithKeywordsTest"); EpnTapConnection facade = new EpnTapConnection(); final List keywords = new ArrayList<>(); @@ -126,12 +150,17 @@ public class EpnTapConnectionTest { // *** 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 { - System.out.println("getEPNServiceTest"); + logger.info("getEPNServiceTest"); EpnTapConnection facade = new EpnTapConnection(); - VOTABLE voTable = facade.getEPNService("ivo://cdpp/amda"); + VOTABLE voTable = facade.getEPNService(AMDA_IVOID); VOTableData data = ServiceCtrl.getVoTableData(voTable); assertEquals(1, data.getNbRows()); @@ -143,16 +172,21 @@ public class EpnTapConnectionTest { 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 { - System.out.println("getEPNServiceWithAttributesTest"); + logger.info("getEPNServiceWithAttributesTest"); EpnTapConnection facade = new EpnTapConnection(); final List attributes = new ArrayList<>(); attributes.add("access_url"); attributes.add("short_name"); - VOTABLE voTable = facade.getEPNService("ivo://cdpp/amda", attributes); + VOTABLE voTable = facade.getEPNService(AMDA_IVOID, attributes); VOTableData data = ServiceCtrl.getVoTableData(voTable); assertEquals(1, data.getNbRows()); @@ -163,59 +197,83 @@ public class EpnTapConnectionTest { 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 { - System.out.println("getEPNServicesTest"); + 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 ivoid not found.", data.isContainingColumnName("short_name")); + assertTrue("Column name short_name not found.", data.isContainingColumnName("short_name")); assertTrue("AMDA ivoid not found.", data.isColumnContainingValue("ivoid", AMDA_IVOID)); Map amda = data.getRowMapByValue("ivoid", AMDA_IVOID); - assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url")); - assertEquals(AMDA_SHORT_NAME, data.getCell(0, "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)}. + * + * @throws CantGetVOTableException Can not get the VOTable corresponding to the service. + */ @Test public void getEPNServicesWithAttributesTest() throws CantGetVOTableException { - System.out.println("getEPNServicesWithAttributesTest"); + logger.info("getEPNServicesWithAttributesTest"); EpnTapConnection facade = new EpnTapConnection(); final List attributes = new ArrayList<>(); attributes.add("access_url"); attributes.add("short_name"); - VOTABLE voTable = facade.getEPNService("ivo://cdpp/amda", attributes); + VOTABLE voTable = facade.getEPNServices(attributes); VOTableData data = ServiceCtrl.getVoTableData(voTable); assertEquals(2, data.getNbColumns()); - assertTrue("Column name ivoid not found.", data.isContainingColumnName("access_url")); - assertTrue("Column name ivoid not found.", data.isContainingColumnName("short_name")); - assertEquals(AMDA_ACCESS_URL, data.getCell(0, "access_url")); - assertEquals(AMDA_SHORT_NAME, data.getCell(0, "short_name")); + 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 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 getEPNServicesWithAttributesAndKeywordsTest() + public void getEPNServicesWithKeywordsAndAttributesTest() throws CantGetVOTableException, VOResourceException { - System.out.println("getEPNServicesWithAttributesAndKeywordsTest"); + logger.info("getEPNServicesWithKeywordsAndAttributesTest"); EpnTapConnection facade = new EpnTapConnection(); + final List keywords = new ArrayList<>(); + keywords.add(AMDA_SUBJECT); + final List attributes = new ArrayList<>(); attributes.add("access_url"); attributes.add("short_name"); - final List keywords = new ArrayList<>(); - keywords.add(AMDA_SUBJECT); - 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")); @@ -229,19 +287,29 @@ public class EpnTapConnectionTest { // *** 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 { - System.out.println("getEPNCoreTableNameTest"); + logger.info("getEPNCoreTableNameTest"); EpnTapConnection facade = new EpnTapConnection(); - String epnCoreTableName = facade.getEPNCoreTableName("ivo://cdpp/amda"); + 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 { - System.out.println("getTAPURLTest"); + logger.info("getTAPURLTest"); EpnTapConnection facade = new EpnTapConnection(); String tapURL = facade.getTAPURL("ivo://cdpp/amda"); @@ -251,9 +319,14 @@ public class EpnTapConnectionTest { // *** 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 { - System.out.println("sendADQLQueryTest"); + logger.info("sendADQLQueryTest"); EpnTapConnection facade = new EpnTapConnection(); List granules = facade.sendADQLQuery(SERVICE_EPNCOREV2_ACCESS_URL, @@ -272,9 +345,14 @@ public class EpnTapConnectionTest { assertEquals(new Integer(5), mars.processingLevel); } + /** + * 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 { - System.out.println("sendADQLQueryWithSchemaNameTest"); + logger.info("sendADQLQueryWithSchemaNameTest"); EpnTapConnection facade = new EpnTapConnection(); List granules = facade.sendQuery(SERVICE_EPNCOREV2_ACCESS_URL, SERVICE_EPNCOREV2_TABLE_NAME, Query.GET_SCENE_FROM_TARGET_AND_TIME_INTERVAL); -- libgit2 0.21.2