Commit 9c79cc6f authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Improve test coverage.

parent afeb0706
Pipeline #1050 failed with stages
in 18 minutes and 6 seconds
......@@ -16,8 +16,6 @@
*/
package org.orekit.files.ccsds.ndm.adm.apm;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitMessages;
import org.orekit.files.ccsds.definitions.Units;
import org.orekit.files.ccsds.utils.ContextBinding;
import org.orekit.files.ccsds.utils.lexical.ParseToken;
......@@ -43,17 +41,7 @@ public enum ApmQuaternionKey {
Q_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),
/** Second reference frame entry. */
Q_FRAME_B((token, context, container) -> {
if (token.getType() == TokenType.ENTRY) {
if (container.getEndpoints().getFrameA() == null) {
throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, Q_FRAME_A.name());
}
final boolean aIsSpaceraftBody = container.getEndpoints().getFrameA().asSpacecraftBodyFrame() != null;
return token.processAsFrame(container.getEndpoints()::setFrameB, context,
aIsSpaceraftBody, aIsSpaceraftBody, !aIsSpaceraftBody);
}
return true;
}),
Q_FRAME_B((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameB, context, true, true, true)),
/** Rotation direction entry. */
Q_DIR((token, context, container) -> {
......
......@@ -130,13 +130,8 @@ class RapidDataAndPredictionXMLLoader extends AbstractEopLoader
return history;
} catch (SAXException se) {
if (se.getCause() instanceof OrekitException) {
throw (OrekitException) se.getCause();
}
throw new OrekitException(se, LocalizedCoreFormats.SIMPLE_MESSAGE, se.getMessage());
} catch (ParserConfigurationException pce) {
throw new OrekitException(pce, LocalizedCoreFormats.SIMPLE_MESSAGE, pce.getMessage());
} catch (SAXException | ParserConfigurationException e) {
throw new OrekitException(e, LocalizedCoreFormats.SIMPLE_MESSAGE, e.getMessage());
}
}
......@@ -301,16 +296,11 @@ class RapidDataAndPredictionXMLLoader extends AbstractEopLoader
/** {@inheritDoc} */
@Override
public void endElement(final String uri, final String localName, final String qName)
throws SAXException {
try {
if (content == DataFileContent.DAILY) {
endDailyElement(qName);
} else if (content == DataFileContent.FINAL) {
endFinalElement(qName);
}
} catch (OrekitException oe) {
throw new SAXException(oe);
public void endElement(final String uri, final String localName, final String qName) {
if (content == DataFileContent.DAILY) {
endDailyElement(qName);
} else if (content == DataFileContent.FINAL) {
endFinalElement(qName);
}
}
......
......@@ -1153,8 +1153,7 @@ public class NRLMSISE00 implements Atmosphere {
final Frame frame) {
// check if data are available :
if (date.compareTo(inputParams.getMaxDate()) > 0 ||
date.compareTo(inputParams.getMinDate()) < 0) {
if (!date.isBetweenOrEqualTo(inputParams.getMinDate(), inputParams.getMaxDate())) {
throw new OrekitException(OrekitMessages.NO_SOLAR_ACTIVITY_AT_DATE,
date, inputParams.getMinDate(), inputParams.getMaxDate());
}
......
......@@ -31,7 +31,6 @@ import org.hipparchus.util.MathUtils;
import org.orekit.annotation.DefaultDataContext;
import org.orekit.data.DataContext;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitInternalError;
import org.orekit.errors.OrekitMessages;
import org.orekit.orbits.EquinoctialOrbit;
import org.orekit.orbits.KeplerianOrbit;
......@@ -703,11 +702,7 @@ public class TLE implements TimeStamped, Serializable {
* @return string representation of this TLE set
*/
public String toString() {
try {
return getLine1() + System.getProperty("line.separator") + getLine2();
} catch (OrekitException oe) {
throw new OrekitInternalError(oe);
}
return getLine1() + System.getProperty("line.separator") + getLine2();
}
/**
......
......@@ -51,6 +51,7 @@ import org.orekit.time.AbsoluteDate;
import org.orekit.time.TimeScalesFactory;
import org.orekit.utils.IERSConventions;
import org.orekit.utils.PVCoordinates;
import org.orekit.utils.PVCoordinatesProvider;
import org.orekit.utils.TimeStampedPVCoordinates;
public class APMParserTest {
......@@ -759,11 +760,11 @@ public class APMParserTest {
Assert.assertEquals(new AbsoluteDate(2021, 1, 1, 0, 0, 0.0, TimeScalesFactory.getTDB()),
segment.getData().getQuaternionBlock().getEpoch());
final PVCoordinatesProvider prov = (date, frame) -> new TimeStampedPVCoordinates(date,
new PVCoordinates(new Vector3D( 1.234e7, -0.567e7, 9.876e6),
new Vector3D(-0.772e4, 5.002e4, 4.892e2)));
try {
file.getAttitude(FramesFactory.getEME2000(),
(date, frame) -> new TimeStampedPVCoordinates(date,
new PVCoordinates(new Vector3D( 1.234e7, -0.567e7, 9.876e6),
new Vector3D(-0.772e4, 5.002e4, 4.892e2))));
file.getAttitude(FramesFactory.getEME2000(), prov);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.UNSUPPORTED_LOCAL_ORBITAL_FRAME, oe.getSpecifier());
......@@ -909,6 +910,54 @@ public class APMParserTest {
}
}
@Test
public void testMissingTwoSpacecraftFrames() throws URISyntaxException {
final String name = "/ccsds/adm/apm/APM-two-spacecraft-frames.txt";
try {
final DataSource source = new DataSource(name, () -> getClass().getResourceAsStream(name));
new ParserBuilder().
withMissionReferenceDate(AbsoluteDate.J2000_EPOCH).
buildApmParser().
parseMessage(source);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.CCSDS_INVALID_FRAME, oe.getSpecifier());
Assert.assertEquals("INSTRUMENT_2", oe.getParts()[0]);
}
}
@Test
public void testNoSpacecraftFrames() throws URISyntaxException {
final String name = "/ccsds/adm/apm/APM-no-spacecraft-frames.txt";
try {
final DataSource source = new DataSource(name, () -> getClass().getResourceAsStream(name));
new ParserBuilder().
withMissionReferenceDate(AbsoluteDate.J2000_EPOCH).
buildApmParser().
parseMessage(source);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.CCSDS_INVALID_FRAME, oe.getSpecifier());
Assert.assertEquals("EME2000", oe.getParts()[0]);
}
}
@Test
public void testMissingFrame() throws URISyntaxException {
final String name = "/ccsds/adm/apm/APM-missing-frame.txt";
try {
final DataSource source = new DataSource(name, () -> getClass().getResourceAsStream(name));
new ParserBuilder().
withMissionReferenceDate(AbsoluteDate.J2000_EPOCH).
buildApmParser().
parseMessage(source);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, oe.getSpecifier());
Assert.assertEquals("Q_FRAME_A", oe.getParts()[0]);
}
}
@Test
public void testMissingQuaternionComponent() throws URISyntaxException {
final String name = "/ccsds/adm/apm/APM-missing-quaternion-component.txt";
......
......@@ -28,10 +28,12 @@ import org.junit.Assert;
import org.junit.Test;
import org.orekit.data.AbstractFilesLoaderTest;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitMessages;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.ChronologicalComparator;
import org.orekit.time.TimeScalesFactory;
import org.orekit.utils.IERSConventions;
import org.xml.sax.SAXException;
public class RapidDataAndPredictionXMLLoaderTest extends AbstractFilesLoaderTest {
......@@ -65,6 +67,34 @@ public class RapidDataAndPredictionXMLLoaderTest extends AbstractFilesLoaderTest
Assert.assertEquals(0, history.size());
}
@Test
public void testInconsistentDate() {
setRoot("rapid-data-xml");
IERSConventions.NutationCorrectionConverter converter =
IERSConventions.IERS_1996.getNutationCorrectionConverter();
SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
try {
new RapidDataAndPredictionXMLLoader("^inconsistent-date\\.xml$", manager, () -> utc).fillHistory(converter, history);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.INCONSISTENT_DATES_IN_IERS_FILE, oe.getSpecifier());
}
}
@Test
public void testMalformedXml() {
setRoot("rapid-data-xml");
IERSConventions.NutationCorrectionConverter converter =
IERSConventions.IERS_1996.getNutationCorrectionConverter();
SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
try {
new RapidDataAndPredictionXMLLoader("^malformed\\.xml$", manager, () -> utc).fillHistory(converter, history);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertTrue(oe.getCause() instanceof SAXException);
}
}
@Test
public void testStartDateDaily1980() {
setRoot("rapid-data-xml");
......
......@@ -42,6 +42,7 @@ import org.orekit.bodies.CelestialBodyFactory;
import org.orekit.bodies.GeodeticPoint;
import org.orekit.bodies.OneAxisEllipsoid;
import org.orekit.errors.OrekitException;
import org.orekit.errors.OrekitMessages;
import org.orekit.frames.Frame;
import org.orekit.frames.FramesFactory;
import org.orekit.time.AbsoluteDate;
......@@ -216,6 +217,13 @@ public class NRLMSISE00Test {
final Vector3D pos = earth.transform(point);
// Run
try {
atm.getDensity(date.shiftedBy(2 * Constants.JULIAN_YEAR), pos, itrf);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.NO_SOLAR_ACTIVITY_AT_DATE, oe.getSpecifier());
}
final double rho = atm.getDensity(date, pos, itrf);
final double lst = 29000. / 3600. - 70. / 15.;
final double[] ap = {4., 100., 100., 100., 100., 100., 100.};
......@@ -269,6 +277,13 @@ public class NRLMSISE00Test {
Field<Decimal64> field = Decimal64Field.getInstance();
// Run
try {
atm.getDensity(date.shiftedBy(2 * Constants.JULIAN_YEAR), pos, itrf);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.NO_SOLAR_ACTIVITY_AT_DATE, oe.getSpecifier());
}
final double rho = atm.getDensity(date, pos, itrf);
final Decimal64 rho64 = atm.getDensity(new FieldAbsoluteDate<>(field, date),
new FieldVector3D<>(field.getOne(), pos),
......
......@@ -470,7 +470,8 @@ public class TLETest {
"2 27421 98.7490 199.5121 0001333 133.9522 226.1918 14.26113993 62");
TLE tleB = new TLE("1 27421U 02021A 02124.48976499 -.00021470 00000-0 -89879-2 0 20",
"2 27421 98.7490 199.5121 0001333 133.9522 226.1918 14.26113993 62");
Assert.assertTrue(tleA.equals(tleB));
Assert.assertEquals(tleA, tleB);
Assert.assertEquals(tleA, tleA);
}
@Test
......@@ -479,7 +480,8 @@ public class TLETest {
"2 27421 98.7490 199.5121 0001333 133.9522 226.1918 14.26113993 62");
TLE tleB = new TLE("1 05555U 71086J 12026.96078249 -.00000004 00001-9 01234-9 0 9082",
"2 05555 74.0161 228.9750 0075476 328.9888 30.6709 12.26882470804545");
Assert.assertFalse(tleA.equals(tleB));
Assert.assertNotEquals(tleA, tleB);
Assert.assertNotEquals(tleA, tleA.getLine1());
}
@Test
......
CCSDS_APM_VERS = 1.0
CREATION_DATE = 2004-02-14T19:23:57
ORIGINATOR = JPL
OBJECT_NAME = MARS SPIRIT
OBJECT_ID = 2004-003A
CENTER_NAME = EARTH
TIME_SYSTEM = UTC
EPOCH = 2004-02-14T14:28:15.1172
Q_FRAME_B = ITRF-97
Q_DIR = A2B
Q1 = 0.03123
Q2 = 0.78543
Q3 = 0.39158
QC = 0.47832
CCSDS_APM_VERS = 1.0
CREATION_DATE = 2004-02-14T19:23:57
ORIGINATOR = JPL
OBJECT_NAME = MARS SPIRIT
OBJECT_ID = 2004-003A
CENTER_NAME = EARTH
TIME_SYSTEM = UTC
EPOCH = 2004-02-14T14:28:15.1172
Q_FRAME_A = GCRF
Q_FRAME_B = EME2000
Q_DIR = A2B
Q1 = 0.03123
Q2 = 0.78543
Q3 = 0.39158
QC = 0.47832
CCSDS_APM_VERS = 1.0
CREATION_DATE = 2004-02-14T19:23:57
ORIGINATOR = JPL
OBJECT_NAME = MARS SPIRIT
OBJECT_ID = 2004-003A
CENTER_NAME = EARTH
TIME_SYSTEM = UTC
EPOCH = 2004-02-14T14:28:15.1172
Q_FRAME_A = ACTUATOR_A
Q_FRAME_B = INSTRUMENT_2
Q_DIR = A2B
Q1 = 0.03123
Q2 = 0.78543
Q3 = 0.39158
QC = 0.47832
<!-- This file has been manually truncated for test purposes -->
<!-- It contains only a subset of a real IERS data file -->
<!-- It is not even continuous as it includes months-long holes -->
<EOP xmlns="http://www.iers.org/2003/schema/eop">
<version>
<product>finals.daily (IAU1980)</product>
<date>2010-05-12</date>
<volume>IAU1980</volume>
<number>---</number>
</version>
<metaFileName />
<headerLine>
<headerLineDate>
<sYear>Year</sYear>
<sMonth>Month</sMonth>
<sDay>Day</sDay>
<sTime>Time</sTime>
<sMJD>MJD</sMJD>
</headerLineDate>
<headerLineEOP>
<product source="BulletinA">
<sX>X</sX>
<ssigma_X>sigma_X</ssigma_X>
<sY>Y</sY>
<ssigma_Y>sigma_Y</ssigma_Y>
<sUT1-UTC>UT1-UTC</sUT1-UTC>
<ssigma_UT1-UTC>sigma_UT1-UTC</ssigma_UT1-UTC>
<sLOD>LOD</sLOD>
<ssigma_LOD>sigma_LOD</ssigma_LOD>
<sdPsi>dPsi</sdPsi>
<ssigma_dPsi>sigma_dPsi</ssigma_dPsi>
<sdEpsilon>dEpsilon</sdEpsilon>
<ssigma_dEpsilon>sigma_dEpsilon</ssigma_dEpsilon>
</product>
<product source="BulletinB">
<sX>X</sX>
<sY>Y</sY>
<sUT1-UTC>UT1-UTC</sUT1-UTC>
<sdPsi>dPsi</sdPsi>
<sdEpsilon>dEpsilon</sdEpsilon>
</product>
</headerLineEOP>
<headerLineUnits>
<product source="BulletinA">
<X>arcsec</X>
<sigma_X>arcsec</sigma_X>
<Y>arcsec</Y>
<sigma_Y>arcsec</sigma_Y>
<UT1-UTC>sec</UT1-UTC>
<sigma_UT1-UTC>sec</sigma_UT1-UTC>
<LOD>msec</LOD>
<sigma_LOD>msec</sigma_LOD>
<dPsi>marcsec</dPsi>
<sigma_dPsi>marcsec</sigma_dPsi>
<dEpsilon>marcsec</dEpsilon>
<sigma_dEpsilon>marcsec</sigma_dEpsilon>
</product>
<product source="BulletinB">
<X>arcsec</X>
<Y>arcsec</Y>
<UT1-UTC>sec</UT1-UTC>
<dPsi>marcsec</dPsi>
<dEpsilon>marcsec</dEpsilon>
</product>
</headerLineUnits>
</headerLine>
<data product="finals.daily (IAU1980)"
source="BulletinA BulletinB">
<timeSeries>
<time>
<dateYear>2010</dateYear>
<dateMonth>07</dateMonth>
<dateDay>01</dateDay>
<MJD>55378</MJD>
</time>
<dataEOP>
<pole source="BulletinA" type="final">
<X>0.060729</X>
<sigma_X>0.000093</sigma_X>
<Y>0.483215</Y>
<sigma_Y>0.000042</sigma_Y>
</pole>
<UT source="BulletinA" type="final">
<UT1-UTC>-0.0568654</UT1-UTC>
<sigma_UT1-UTC>0.0000065</sigma_UT1-UTC>
<LOD>-0.0551</LOD>
<sigma_LOD>0.0045</sigma_LOD>
</UT>
<nutation source="BulletinA" type="final">
<dPsi>-67.373</dPsi>
<sigma_dPsi>0.204</sigma_dPsi>
<dEpsilon>-9.678</dEpsilon>
<sigma_dEpsilon>0.102</sigma_dEpsilon>
</nutation>
<pole source="BulletinB" type="final">
<X>0.060783</X>
<Y>0.483197</Y>
</pole>
<UT source="BulletinB" type="final">
<UT1-UTC>-0.0568663</UT1-UTC>
</UT>
<nutation source="BulletinB" type="final">
<dPsi>-67.364</dPsi>
<dEpsilon>-9.740</dEpsilon>
</nutation>
</dataEOP>
</timeSeries>
<timeSeries>
<time>
<dateYear>2010</dateYear>
<dateMonth>07</dateMonth>
<dateDay>02</dateDay>
<MJD>65379</MJD>
</time>
<dataEOP>
<pole source="BulletinA" type="final">
<X>0.064760</X>
<sigma_X>0.000092</sigma_X>
<Y>0.483590</Y>
<sigma_Y>0.000042</sigma_Y>
</pole>
<UT source="BulletinA" type="final">
<UT1-UTC>-0.0568341</UT1-UTC>
<sigma_UT1-UTC>0.0000063</sigma_UT1-UTC>
<LOD>0.0067</LOD>
<sigma_LOD>0.0051</sigma_LOD>
</UT>
<nutation source="BulletinA" type="final">
<dPsi>-67.654</dPsi>
<sigma_dPsi>0.204</sigma_dPsi>
<dEpsilon>-9.803</dEpsilon>
<sigma_dEpsilon>0.102</sigma_dEpsilon>
</nutation>
<pole source="BulletinB" type="final">
<X />
<Y />
</pole>
<UT source="BulletinB" type="final">
<UT1-UTC />
</UT>
<nutation source="BulletinB" type="final">
<dPsi />
<dEpsilon />
</nutation>
</dataEOP>
</timeSeries>
</data>
</EOP>
<!-- This file has been manually truncated for test purposes -->
<!-- It contains only a subset of a real IERS data file -->
<!-- It is not even continuous as it includes months-long holes -->
<EOP xmlns="http://www.iers.org/2003/schema/eop">
<version>
<product>finals.daily (IAU1980)</product>
<date>2010-05-12</date>
<volume>IAU1980</volume>
<number>---</number>
</version>
<metaFileName />
<headerLine>
<headerLineDate>
<sYear>Year</sYear>
<sMonth>Month</sMonth>
<sDay>Day</sDay>
<sTime>Time</sTime>
<sMJD>MJD</sMJD>
</headerLineDate>
<headerLineEOP>
<product source="BulletinA">
<sX>X</sX>
<ssigma_X>sigma_X</ssigma_X>
<sY>Y</sY>
<ssigma_Y>sigma_Y</ssigma_Y>
<sUT1-UTC>UT1-UTC</sUT1-UTC>
<ssigma_UT1-UTC>sigma_UT1-UTC</ssigma_UT1-UTC>
<sLOD>LOD</sLOD>
<ssigma_LOD>sigma_LOD</ssigma_LOD>
<sdPsi>dPsi</sdPsi>
<ssigma_dPsi>sigma_dPsi</ssigma_dPsi>
<sdEpsilon>dEpsilon</sdEpsilon>
<ssigma_dEpsilon>sigma_dEpsilon</ssigma_dEpsilon>
</product>
<product source="BulletinB">
<sX>X</sX>
<sY>Y</sY>
<sUT1-UTC>UT1-UTC</sUT1-UTC>
<sdPsi>dPsi</sdPsi>
<sdEpsilon>dEpsilon</sdEpsilon>
</product>
</headerLineEOP>
<headerLineUnits>
<product source="BulletinA">
<X>arcsec</X>
<sigma_X>arcsec</sigma_X>
<Y>arcsec</Y>
<sigma_Y>arcsec</sigma_Y>
<UT1-UTC>sec</UT1-UTC>
<sigma_UT1-UTC>sec</sigma_UT1-UTC>
<LOD>msec</LOD>
<sigma_LOD>msec</sigma_LOD>
<dPsi>marcsec</dPsi>
<sigma_dPsi>marcsec</sigma_dPsi>
<dEpsilon>marcsec</dEpsilon>
<sigma_dEpsilon>marcsec</sigma_dEpsilon>
</product>
<product source="BulletinB">
<X>arcsec</X>
<Y>arcsec</Y>
<UT1-UTC>sec</UT1-UTC>
<dPsi>marcsec</dPsi>
<dEpsilon>marcsec</dEpsilon>
</product>
</headerLineUnits>
</headerLine>
<data product="finals.daily (IAU1980)"
source="BulletinA BulletinB">
<timeSeries>
<time>
<dateYear>2010</dateYear>
<dateMonth>07</dateMonth>
<dateDay>01</dateDay>
<MJD>55378</MJD>
</time>
<dataEOP>
<pole source="BulletinA" type="final">
<X>0.060729</X>
<sigma_X>0.000093</sigma_X>
<Y>0.483215</Y>
<sigma_Y>0.000042</sigma_Y>
</pole>
<UT source="BulletinA" type="final">
<UT1-UTC>-0.0568654</UT1-UTC>
<sigma_UT1-UTC>0.0000065</sigma_UT1-UTC>
<LOD>-0.0551</LOD>
<sigma_LOD>0.0045</sigma_LOD>
</UT>
<nutation source="BulletinA" type="final">
<dPsi>-67.373</dPsi>
<sigma_dPsi>0.204</sigma_dPsi>
<dEpsilon>-9.678</dEpsilon>
<sigma_dEpsilon>0.102</sigma_dEpsilon>
</nutation>
<pole source="BulletinB" type="final">
<X>0.060783</X>
<Y>0.483197</Y>