GranuleTest.java 7.39 KB
/*
 * This file is a part of EpnTAPClient.
 * This program aims to provide EPN-TAP support for software clients, like CASSIS spectrum analyzer.
 * incompleteGranule.sete 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 LicenincompleteGranule.set as published
 * by the Free Software Foundation, either version 3 of the LicenincompleteGranule.set, or (at your option) any later
 * version. This program is distributed in the hope that it will be uincompleteGranule.setful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOincompleteGranule.set. incompleteGranule.sete the GNU General Public LicenincompleteGranule.set for more details. You should have received a copy of
 * the GNU General Public LicenincompleteGranule.set along with this program. If not, incompleteGranule.sete
 * <http://www.gnu.org/licenincompleteGranule.sets/>.
 */

package eu.omp.irap.vespa.epntapclient.granule;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.junit.Test;

import eu.omp.irap.vespa.votable.votabledata.VoTableDataTest;

/**
 * @author N. Jourdane
 */
public class GranuleTest {

	/** The logger for the class GranuleTest. */
	private static final Logger LOGGER = Logger.getLogger(GranuleTest.class.getName());


	/**
	 * Create a granule for tests purposes. It is planetary data for Uranus, got from an actual ADQL
	 * query, exactly the same content that {@link VoTableDataTest#createDataArray1()}
	 *
	 * @return The granule.
	 */
	public static Granule createGranule1() {
		Date testDate = null;
		try {
			testDate = new SimpleDateFormat("yyyy-mm-dd").parse("2015-08-20");
		} catch (ParseException e) {
			LOGGER.log(Level.WARNING, "Can not parse the test date.", e);
		}

		Granule completeGranule = new Granule("Uranus");
		completeGranule.setGranuleGid("Planet");
		completeGranule.setObsId("7");
		completeGranule.setDataproductType("ca");
		completeGranule.setTargetName("Uranus");
		completeGranule.setTargetClass("planet");
		completeGranule.setTimeMin(Double.NaN);
		completeGranule.setTimeMax(Double.NaN);
		completeGranule.setTimeSamplingStepMin(Double.NaN);
		completeGranule.setTimeSamplingStepMax(Double.NaN);
		completeGranule.setTimeExpMin(Double.NaN);
		completeGranule.setTimeExpMax(Double.NaN);
		completeGranule.setSpectralRangeMin(Double.NaN);
		completeGranule.setSpectralRangeMax(Double.NaN);
		completeGranule.setSpectralResolutionMin(Double.NaN);
		completeGranule.setSpectralResolutionMax(Double.NaN);
		completeGranule.setC1Min(Double.NaN);
		completeGranule.setC1Max(Double.NaN);
		completeGranule.setC2Min(Double.NaN);
		completeGranule.setC2Max(Double.NaN);
		completeGranule.setC3Min(Double.NaN);
		completeGranule.setC3Max(Double.NaN);
		completeGranule.setSRegion("");
		completeGranule.setC1ResolMin(Double.NaN);
		completeGranule.setC1ResolMax(Double.NaN);
		completeGranule.setC2ResolMin(Double.NaN);
		completeGranule.setC2ResolMax(Double.NaN);
		completeGranule.setC3ResolMin(Double.NaN);
		completeGranule.setC3ResolMax(Double.NaN);
		completeGranule.setSpatialFrameType("celestial");
		completeGranule.setIncidenceMin(Double.NaN);
		completeGranule.setIncidenceMax(Double.NaN);
		completeGranule.setEmergenceMin(Double.NaN);
		completeGranule.setEmergenceMax(Double.NaN);
		completeGranule.setPhaseMin(Double.NaN);
		completeGranule.setPhaseMax(Double.NaN);
		completeGranule.setInstrumentHostName("");
		completeGranule.setInstrumentName("");
		completeGranule.setMeasurementType("\"phys.mass\" \"phys.size.radius\"");
		completeGranule.setProcessingLevel(5);
		completeGranule.setCreationDate(testDate);
		completeGranule.setModificationDate(testDate);
		completeGranule.setReleaseDate(testDate);
		completeGranule.setServiceTitle("Planets");
		return completeGranule;
	}

	/**
	 * Create a granule for tests purposes. It is planetary data for Neptune, got from an actual
	 * query, exactly the same content that {@link VoTableDataTest#createDataArray2()}
	 *
	 * @return The granule.
	 */
	public static Granule createGranule2() {
		Date testDate = null;
		try {
			testDate = new SimpleDateFormat("yyyy-mm-dd").parse("2015-08-20");
		} catch (ParseException e) {
			LOGGER.log(Level.WARNING, "Can not parse the test date.", e);
		}

		Granule completeGranule = new Granule("Neptune");
		completeGranule.setGranuleGid("Planet");
		completeGranule.setObsId("8");
		completeGranule.setDataproductType("ca");
		completeGranule.setTargetName("Neptune");
		completeGranule.setTargetClass("planet");
		completeGranule.setTimeMin(Double.NaN);
		completeGranule.setTimeMax(Double.NaN);
		completeGranule.setTimeSamplingStepMin(Double.NaN);
		completeGranule.setTimeSamplingStepMax(Double.NaN);
		completeGranule.setTimeExpMin(Double.NaN);
		completeGranule.setTimeExpMax(Double.NaN);
		completeGranule.setSpectralRangeMin(Double.NaN);
		completeGranule.setSpectralRangeMax(Double.NaN);
		completeGranule.setSpectralResolutionMin(Double.NaN);
		completeGranule.setSpectralResolutionMax(Double.NaN);
		completeGranule.setC1Min(Double.NaN);
		completeGranule.setC1Max(Double.NaN);
		completeGranule.setC2Min(Double.NaN);
		completeGranule.setC2Max(Double.NaN);
		completeGranule.setC3Min(Double.NaN);
		completeGranule.setC3Max(Double.NaN);
		completeGranule.setSRegion("");
		completeGranule.setC1ResolMin(Double.NaN);
		completeGranule.setC1ResolMax(Double.NaN);
		completeGranule.setC2ResolMin(Double.NaN);
		completeGranule.setC2ResolMax(Double.NaN);
		completeGranule.setC3ResolMin(Double.NaN);
		completeGranule.setC3ResolMax(Double.NaN);
		completeGranule.setSpatialFrameType("celestial");
		completeGranule.setIncidenceMin(Double.NaN);
		completeGranule.setIncidenceMax(Double.NaN);
		completeGranule.setEmergenceMin(Double.NaN);
		completeGranule.setEmergenceMax(Double.NaN);
		completeGranule.setPhaseMin(Double.NaN);
		completeGranule.setPhaseMax(Double.NaN);
		completeGranule.setInstrumentHostName("");
		completeGranule.setInstrumentName("");
		completeGranule.setMeasurementType("\"phys.mass\" \"phys.size.radius\"");
		completeGranule.setProcessingLevel(5);
		completeGranule.setCreationDate(testDate);
		completeGranule.setModificationDate(testDate);
		completeGranule.setReleaseDate(testDate);
		completeGranule.setServiceTitle("Planets");
		return completeGranule;
	}

	/**
	 * Create an incomplete granule without many mandatory parameters, which is forbidden.
	 *
	 * @return the granule.
	 */
	public static Granule createIncompleteGranule() {
		Granule incompleteGranule = new Granule("Mercury");
		incompleteGranule.setGranuleGid("Planet");
		return incompleteGranule;
	}

	/**
	 * Test if the incomplete granule appears like not valid.
	 */
	@SuppressWarnings("static-method") // Otherwise JUnit doesn't work.
	@Test
	public void isNotValidTest() {
		assertFalse("The incomplete granule is valid.", createIncompleteGranule().isValid());
	}

	/**
	 * Test if a complete granule appears like valid.
	 */
	@SuppressWarnings("static-method") // Otherwise JUnit doesn't work.
	@Test
	public void isValidTest() {
		assertTrue("The complete granule is not valid.", createGranule1().isValid());
	}

}