1   /* Copyright 2002-2025 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.files.ccsds.ndm;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.BeforeEach;
21  import org.junit.jupiter.api.Test;
22  import org.orekit.Utils;
23  import org.orekit.data.DataSource;
24  import org.orekit.errors.OrekitException;
25  import org.orekit.errors.OrekitMessages;
26  import org.orekit.files.ccsds.ndm.adm.apm.Apm;
27  import org.orekit.files.ccsds.ndm.odm.ocm.Ocm;
28  import org.orekit.files.ccsds.ndm.odm.opm.Opm;
29  
30  /**
31   * Test class for CCSDS Navigation Data Message parsing.<p>
32   * @author Luc Maisonobe
33   */
34  public class NdmParserTest {
35  
36      @BeforeEach
37      public void setUp() {
38          Utils.setDataRoot("regular-data");
39      }
40  
41      @Test
42      public void testNoKvn() {
43          // setup
44          final String name = "/ccsds/ndm/wrong-format.txt";
45          final DataSource source = new DataSource(name, () -> NdmParserTest.class.getResourceAsStream(name));
46  
47          try {
48              // action
49              new ParserBuilder().buildNdmParser().parseMessage(source);
50  
51              // verify
52              Assertions.fail("Expected Exception");
53          } catch (OrekitException oe) {
54             Assertions.assertEquals(OrekitMessages.UNSUPPORTED_FILE_FORMAT, oe.getSpecifier());
55          }
56      }
57  
58      @Test
59      public void testEmpty() {
60          final String name = "/ccsds/ndm/empty.xml";
61          final DataSource source = new DataSource(name, () -> NdmParserTest.class.getResourceAsStream(name));
62          final Ndm ndm = new ParserBuilder().buildNdmParser().parseMessage(source);
63          Assertions.assertTrue(ndm.getComments().isEmpty());
64          Assertions.assertTrue(ndm.getConstituents().isEmpty());
65      }
66  
67      @Test
68      public void testOpm() {
69          final String name = "/ccsds/ndm/NDM-opm.xml";
70          final DataSource source = new DataSource(name, () -> NdmParserTest.class.getResourceAsStream(name));
71          final Ndm ndm = new ParserBuilder().buildNdmParser().parseMessage(source);
72          Assertions.assertEquals(1, ndm.getComments().size());
73          Assertions.assertEquals("NDM with only one constituent: an OPM", ndm.getComments().get(0));
74          Assertions.assertEquals(1, ndm.getConstituents().size());
75          Opm opm = (Opm) ndm.getConstituents().get(0);
76          Assertions.assertEquals("OSPREY 5", opm.getMetadata().getObjectName());
77          Assertions.assertEquals(3000.0, opm.getData().getSpacecraftParametersBlock().getMass(), 1.0e-10);
78      }
79  
80      @Test
81      public void testOpmApm() {
82          final String name = "/ccsds/ndm/NDM-ocm-apm.xml";
83          final DataSource source = new DataSource(name, () -> NdmParserTest.class.getResourceAsStream(name));
84          final Ndm ndm = new ParserBuilder().buildNdmParser().parseMessage(source);
85          Assertions.assertEquals(1, ndm.getComments().size());
86          Assertions.assertEquals("NDM with two constituents: an OCM and an APM", ndm.getComments().get(0));
87          Assertions.assertEquals(2, ndm.getConstituents().size());
88          Ocm ocm = (Ocm) ndm.getConstituents().get(0);
89          Assertions.assertEquals("1998-999A", ocm.getMetadata().getInternationalDesignator());
90          Assertions.assertEquals("WGS-84", ocm.getData().getUserDefinedBlock().getParameters().get("EARTH_MODEL"));
91          Apm apm = (Apm) ndm.getConstituents().get(1);
92          Assertions.assertEquals("MARS SPIRIT", apm.getMetadata().getObjectName());
93          Assertions.assertEquals("INSTRUMENT_A", apm.getData().getQuaternionBlock().getEndpoints().getFrameA().getName());
94      }
95  
96  }