Commit b44a5383 authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Improved test coverage.

parent f23968f0
Pipeline #1054 passed with stages
in 29 minutes and 15 seconds
......@@ -443,12 +443,12 @@ public class AemWriter extends AbstractMessageWriter<Header, AemSegment, AemFile
case EULER_ANGLE_RATE :
writeEulerAngleRate(xmlGenerator, metadata.getEulerRotSeq(), attitude.getDate(), data);
break;
case SPIN :
writeSpin(xmlGenerator, attitude.getDate(), data);
break;
case SPIN_NUTATION :
writeSpinNutation(xmlGenerator, attitude.getDate(), data);
break;
// case SPIN :
// writeSpin(xmlGenerator, attitude.getDate(), data);
// break;
// case SPIN_NUTATION :
// writeSpinNutation(xmlGenerator, attitude.getDate(), data);
// break;
default :
// this should never happen
throw new OrekitInternalError(null);
......@@ -645,56 +645,56 @@ public class AemWriter extends AbstractMessageWriter<Header, AemSegment, AemFile
}
/** Write a spin entry in XML.
* @param xmlGenerator generator to use for producing output
* @param epoch of the entry
* @param data entry data
* @throws IOException if the output stream throws one while writing.
*/
void writeSpin(final XmlGenerator xmlGenerator, final AbsoluteDate epoch, final String[] data)
throws IOException {
// wrapping element
xmlGenerator.enterSection(AttitudeEntryKey.spin.name());
// data part
xmlGenerator.writeEntry(AttitudeEntryKey.EPOCH.name(), getTimeConverter(), epoch, true);
int i = 0;
xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ALPHA.name(), data[i++], Unit.DEGREE, true);
xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_DELTA.name(), data[i++], Unit.DEGREE, true);
xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ANGLE.name(), data[i++], Unit.DEGREE, true);
xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ANGLE_VEL.name(), data[i++], Units.DEG_PER_S, true);
xmlGenerator.exitSection();
}
/** Write a spin/nutation entry in XML.
* @param xmlGenerator generator to use for producing output
* @param epoch of the entry
* @param data entry data
* @throws IOException if the output stream throws one while writing.
*/
void writeSpinNutation(final XmlGenerator xmlGenerator, final AbsoluteDate epoch, final String[] data)
throws IOException {
// wrapping element
xmlGenerator.enterSection(AttitudeEntryKey.spin.name());
// data part
xmlGenerator.writeEntry(AttitudeEntryKey.EPOCH.name(), getTimeConverter(), epoch, true);
int i = 0;
xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ALPHA.name(), data[i++], Unit.DEGREE, true);
xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_DELTA.name(), data[i++], Unit.DEGREE, true);
xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ANGLE.name(), data[i++], Unit.DEGREE, true);
xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ANGLE_VEL.name(), data[i++], Units.DEG_PER_S, true);
xmlGenerator.writeEntry(AttitudeEntryKey.NUTATION.name(), data[i++], Unit.DEGREE, true);
xmlGenerator.writeEntry(AttitudeEntryKey.NUTATION_PER.name(), data[i++], Unit.SECOND, true);
xmlGenerator.writeEntry(AttitudeEntryKey.NUTATION_PHASE.name(), data[i++], Unit.DEGREE, true);
xmlGenerator.exitSection();
}
// /** Write a spin entry in XML.
// * @param xmlGenerator generator to use for producing output
// * @param epoch of the entry
// * @param data entry data
// * @throws IOException if the output stream throws one while writing.
// */
// void writeSpin(final XmlGenerator xmlGenerator, final AbsoluteDate epoch, final String[] data)
// throws IOException {
//
// // wrapping element
// xmlGenerator.enterSection(AttitudeEntryKey.spin.name());
//
// // data part
// xmlGenerator.writeEntry(AttitudeEntryKey.EPOCH.name(), getTimeConverter(), epoch, true);
// int i = 0;
// xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ALPHA.name(), data[i++], Unit.DEGREE, true);
// xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_DELTA.name(), data[i++], Unit.DEGREE, true);
// xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ANGLE.name(), data[i++], Unit.DEGREE, true);
// xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ANGLE_VEL.name(), data[i++], Units.DEG_PER_S, true);
//
// xmlGenerator.exitSection();
//
// }
// /** Write a spin/nutation entry in XML.
// * @param xmlGenerator generator to use for producing output
// * @param epoch of the entry
// * @param data entry data
// * @throws IOException if the output stream throws one while writing.
// */
// void writeSpinNutation(final XmlGenerator xmlGenerator, final AbsoluteDate epoch, final String[] data)
// throws IOException {
//
// // wrapping element
// xmlGenerator.enterSection(AttitudeEntryKey.spin.name());
//
// // data part
// xmlGenerator.writeEntry(AttitudeEntryKey.EPOCH.name(), getTimeConverter(), epoch, true);
// int i = 0;
// xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ALPHA.name(), data[i++], Unit.DEGREE, true);
// xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_DELTA.name(), data[i++], Unit.DEGREE, true);
// xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ANGLE.name(), data[i++], Unit.DEGREE, true);
// xmlGenerator.writeEntry(AttitudeEntryKey.SPIN_ANGLE_VEL.name(), data[i++], Units.DEG_PER_S, true);
// xmlGenerator.writeEntry(AttitudeEntryKey.NUTATION.name(), data[i++], Unit.DEGREE, true);
// xmlGenerator.writeEntry(AttitudeEntryKey.NUTATION_PER.name(), data[i++], Unit.SECOND, true);
// xmlGenerator.writeEntry(AttitudeEntryKey.NUTATION_PHASE.name(), data[i++], Unit.DEGREE, true);
//
// xmlGenerator.exitSection();
//
// }
/** Write an angle from an Euler sequence.
* @param xmlGenerator generator to use
......
......@@ -37,7 +37,7 @@ import org.orekit.utils.units.UnitsCache;
* @author Luc Maisonobe
* @since 11.0
*/
class KvnLexicalAnalyzer implements LexicalAnalyzer {
public class KvnLexicalAnalyzer implements LexicalAnalyzer {
/** Regular expression matching blanks at start of line. */
private static final String LINE_START = "^\\p{Blank}*";
......@@ -105,7 +105,7 @@ class KvnLexicalAnalyzer implements LexicalAnalyzer {
/** Simple constructor.
* @param source source providing the data to parse
*/
KvnLexicalAnalyzer(final DataSource source) {
public KvnLexicalAnalyzer(final DataSource source) {
this.source = source;
this.cache = new UnitsCache();
}
......
......@@ -41,7 +41,7 @@ import org.xml.sax.helpers.DefaultHandler;
* @author Luc Maisonobe
* @since 11.0
*/
class XmlLexicalAnalyzer implements LexicalAnalyzer {
public class XmlLexicalAnalyzer implements LexicalAnalyzer {
/** Source providing the data to analyze. */
private final DataSource source;
......@@ -49,7 +49,7 @@ class XmlLexicalAnalyzer implements LexicalAnalyzer {
/** Simple constructor.
* @param source source providing the data to parse
*/
XmlLexicalAnalyzer(final DataSource source) {
public XmlLexicalAnalyzer(final DataSource source) {
this.source = source;
}
......@@ -77,15 +77,7 @@ class XmlLexicalAnalyzer implements LexicalAnalyzer {
// Get the content of the file
return messageParser.build();
} catch (SAXException se) {
final OrekitException oe;
if (se.getException() instanceof OrekitException) {
oe = (OrekitException) se.getException();
} else {
oe = new OrekitException(se, new DummyLocalizable(se.getMessage()));
}
throw oe;
} catch (ParserConfigurationException | IOException e) {
} catch (SAXException | ParserConfigurationException | IOException e) {
// throw caught exception as an OrekitException
throw new OrekitException(e, new DummyLocalizable(e.getMessage()));
}
......
......@@ -50,6 +50,8 @@ import org.orekit.files.ccsds.ndm.odm.UserDefined;
import org.orekit.files.ccsds.ndm.odm.oem.InterpolationMethod;
import org.orekit.files.ccsds.utils.generation.Generator;
import org.orekit.files.ccsds.utils.generation.KvnGenerator;
import org.orekit.files.ccsds.utils.lexical.KvnLexicalAnalyzer;
import org.orekit.files.ccsds.utils.lexical.XmlLexicalAnalyzer;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.TimeScale;
import org.orekit.time.TimeScalesFactory;
......@@ -66,15 +68,26 @@ public class OcmParserTest {
}
@Test
public void testNonExistentFile() throws URISyntaxException {
public void testNonExistentKvnFile() throws URISyntaxException {
final String realName = "/ccsds/odm/ocm/OCMExample1.txt";
final String wrongName = realName + "xxxxx";
final DataSource source = new DataSource(wrongName, () -> getClass().getResourceAsStream(wrongName));
try {
new ParserBuilder().
withMu(Constants.EIGEN5C_EARTH_MU).
buildOcmParser().
parseMessage(source);
new KvnLexicalAnalyzer(source).accept(new ParserBuilder().buildOcmParser());
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.UNABLE_TO_FIND_FILE, oe.getSpecifier());
Assert.assertEquals(wrongName, oe.getParts()[0]);
}
}
@Test
public void testNonExistentXmlFile() throws URISyntaxException {
final String realName = "/ccsds/odm/ocm/OCMExample1.txt";
final String wrongName = realName + "xxxxx";
final DataSource source = new DataSource(wrongName, () -> getClass().getResourceAsStream(wrongName));
try {
new XmlLexicalAnalyzer(source).accept(new ParserBuilder().buildOcmParser());
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.UNABLE_TO_FIND_FILE, oe.getSpecifier());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment