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.frames;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.Test;
21  import org.orekit.data.ClasspathCrawler;
22  import org.orekit.data.DataProvidersManager;
23  import org.orekit.errors.OrekitException;
24  import org.orekit.errors.OrekitMessages;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.time.LazyLoadedTimeScales;
27  import org.orekit.time.TimeScales;
28  import org.orekit.utils.Constants;
29  import org.orekit.utils.IERSConventions;
30  
31  /**
32   * Unit tests for {@link LazyLoadedFrames}.
33   *
34   * @author Evan Ward
35   * @see FramesFactoryTest
36   */
37  public class LazyLoadedFramesTest {
38  
39      /**
40       * Before 10.1 calling {@link FramesFactory#addDefaultEOP1980HistoryLoaders(String,
41       * String, String, String, String)} before leap seconds were available worked just
42       * fine. Ensure this class is capable of the same behavior.
43       */
44      @Test
45      public void testAddLoadersWithoutUtc() {
46          // setup
47          DataProvidersManager manager = new DataProvidersManager();
48          // prevent adding other providers
49          manager.addProvider(new ClasspathCrawler("no-data/dummy.txt"));
50          LazyLoadedEop eop = new LazyLoadedEop(manager);
51          TimeScales timeScales = new LazyLoadedTimeScales(eop);
52          LazyLoadedFrames frames = new LazyLoadedFrames(eop, timeScales, null);
53  
54          // actions
55          frames.addDefaultEOP1980HistoryLoaders(null, null, null, null, null, null);
56          frames.addDefaultEOP2000HistoryLoaders(null, null, null, null, null, null);
57          frames.addEOPHistoryLoader(IERSConventions.IERS_2010, null);
58  
59          // verify: no exceptions thrown
60      }
61  
62      @Test
63      public void testInterpolationDegreeEffect() {
64          DataProvidersManager manager = new DataProvidersManager();
65          manager.addProvider(new ClasspathCrawler("regular-data/UTC-TAI.history"));
66          manager.addProvider(new ClasspathCrawler("regular-data/Earth-orientation-parameters/yearly/eopc04_08_IAU2000.03"));
67          LazyLoadedEop eop03 = new LazyLoadedEop(manager);
68          eop03.setInterpolationDegree(3);
69          EOPHistory history03 = eop03.getEOPHistory(IERSConventions.IERS_2010, false, new LazyLoadedTimeScales(eop03));
70          LazyLoadedEop eop07 = new LazyLoadedEop(manager);
71          eop07.setInterpolationDegree(7);
72          EOPHistory history07 = eop07.getEOPHistory(IERSConventions.IERS_2010, false, new LazyLoadedTimeScales(eop07));
73          final AbsoluteDate date = history03.getStartDate().shiftedBy(3.125 * Constants.JULIAN_DAY);
74          Assertions.assertEquals(-0.290422121, history03.getUT1MinusUTC(date), 1.0e-9);
75          Assertions.assertEquals(-0.290421707, history07.getUT1MinusUTC(date), 1.0e-9);
76      }
77  
78      @Test
79      public void testWrongInterpolationDegree() {
80          DataProvidersManager manager = new DataProvidersManager();
81          manager.addProvider(new ClasspathCrawler("regular-data/UTC-TAI.history"));
82          LazyLoadedEop eop = new LazyLoadedEop(manager);
83          eop.setInterpolationDegree(4);
84          LazyLoadedTimeScales ts = new LazyLoadedTimeScales(eop);
85          try {
86              eop.getEOPHistory(IERSConventions.IERS_2010, false, ts);
87              Assertions.fail("an exception should have been thrown");
88          } catch (OrekitException oe) {
89              Assertions.assertEquals(OrekitMessages.WRONG_EOP_INTERPOLATION_DEGREE, oe.getSpecifier());
90              Assertions.assertEquals(4, ((Integer) oe.getParts()[0]).intValue());
91          }
92      }
93  
94  }