EpnTapConnectionTest.java 7.27 KB
/*
 * 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);
	}
}