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.definitions;
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.bodies.CelestialBodyFactory;
24  import org.orekit.frames.Frame;
25  import org.orekit.frames.FramesFactory;
26  import org.orekit.frames.L2Frame;
27  
28  import java.util.Arrays;
29  
30  
31  public class CenterNameTest {
32  
33      @Test
34      public void testSupportedCenters() {
35          for (final String name : Arrays.asList("SOLAR_SYSTEM_BARYCENTER", "SUN", "MERCURY", "VENUS",
36                                                 "EARTH_MOON", "EARTH", "MOON", "MARS", "JUPITER",
37                                                 "SATURN", "URANUS", "NEPTUNE", "PLUTO")) {
38              Assertions.assertNotNull(CenterName.valueOf(name).getCelestialBody());
39          }
40      }
41  
42      @Test
43      public void testUnupportedCenters() {
44          for (final String name : Arrays.asList("CERES", "SEDNA", "ERIS", "PLANET-9")) {
45              try {
46                  CenterName.valueOf(name);
47                  Assertions.fail("an exception should have been thrown");
48              } catch (IllegalArgumentException iae) {
49                  // expected
50              }
51          }
52      }
53  
54      @Test
55      public void testGuess() {
56          Assertions.assertEquals("SATURN",
57                              CenterName.guessCenter(CelestialBodyFactory.getSaturn().getBodyOrientedFrame()));
58          Assertions.assertEquals("MERCURY",
59                              CenterName.guessCenter(CelestialBodyFactory.getMercury().getInertiallyOrientedFrame()));
60          Assertions.assertEquals("PLANET-X",
61                              CenterName.guessCenter(new ModifiedFrame(FramesFactory.getEME2000(), CelestialBodyFrame.EME2000,
62                                                                       CelestialBodyFactory.getMars(), "PLANET-X")));
63          Assertions.assertEquals("SOLAR SYSTEM BARYCENTER",
64                              CenterName.guessCenter(FramesFactory.getICRF()));
65          Assertions.assertEquals("EARTH",
66                              CenterName.guessCenter(Frame.getRoot()));
67          Assertions.assertEquals("EARTH",
68                              CenterName.guessCenter(FramesFactory.getTOD(true)));
69          Assertions.assertEquals("UNKNOWN",
70                              CenterName.guessCenter(new L2Frame(CelestialBodyFactory.getSun(), CelestialBodyFactory.getEarth())));
71      }
72  
73      @Test
74      public void testMap() {
75          Assertions.assertEquals(CenterName.SATURN,
76                              CenterName.map(CelestialBodyFactory.getSaturn().getBodyOrientedFrame()));
77          Assertions.assertNull(CenterName.map(new L2Frame(CelestialBodyFactory.getSun(), CelestialBodyFactory.getEarth())));
78      }
79  
80      @BeforeEach
81      public void setUp() {
82          Utils.setDataRoot("regular-data");
83      }
84  
85  }