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.hamcrest.CoreMatchers;
20  import org.hamcrest.MatcherAssert;
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.Test;
23  import org.orekit.Utils;
24  import org.orekit.errors.OrekitException;
25  import org.orekit.errors.OrekitMessages;
26  
27  /**
28   * Unit tests for {@link ITRFVersionLoader}.
29   *
30   * @author Evan Ward
31   */
32  public class ITRFVersionLoaderTest {
33  
34      /** Check loading regular file. */
35      @Test
36      public void testVersion() {
37          // setup
38          Utils.setDataRoot("regular-data");
39          ItrfVersionProvider loader =
40                  new ITRFVersionLoader(ITRFVersionLoader.SUPPORTED_NAMES);
41  
42          // action + verify
43          MatcherAssert.assertThat(loader.getConfiguration("eopc04_05.00", 0).getVersion(),
44                  CoreMatchers.is(ITRFVersion.ITRF_2005));
45          MatcherAssert.assertThat(loader.getConfiguration("eopc04_05_IAU2000.00", 0).getVersion(),
46                  CoreMatchers.is(ITRFVersion.ITRF_2005));
47          MatcherAssert.assertThat(loader.getConfiguration("eopc04_08.00", 0).getVersion(),
48                  CoreMatchers.is(ITRFVersion.ITRF_2008));
49          MatcherAssert.assertThat(loader.getConfiguration("eopc04_08_IAU2000.00", 0).getVersion(),
50                  CoreMatchers.is(ITRFVersion.ITRF_2008));
51          MatcherAssert.assertThat(loader.getConfiguration("eopc04_14.00", 0).getVersion(),
52                  CoreMatchers.is(ITRFVersion.ITRF_2014));
53          MatcherAssert.assertThat(loader.getConfiguration("eopc04_14_IAU2000.00", 0).getVersion(),
54                  CoreMatchers.is(ITRFVersion.ITRF_2014));
55  
56          MatcherAssert.assertThat(
57                  loader.getConfiguration("bulletina-xi-001.txt", 54000).getVersion(),
58                  CoreMatchers.is(ITRFVersion.ITRF_2000));
59          MatcherAssert.assertThat(
60                  loader.getConfiguration("bulletina-xxi-001.txt", 55555).getVersion(),
61                  CoreMatchers.is(ITRFVersion.ITRF_2005));
62          MatcherAssert.assertThat(
63                  loader.getConfiguration("bulletina-xxvi-001.txt", 57777).getVersion(),
64                  CoreMatchers.is(ITRFVersion.ITRF_2008));
65          MatcherAssert.assertThat(
66                  loader.getConfiguration("bulletina-xxxi-001.txt", 58484).getVersion(),
67                  CoreMatchers.is(ITRFVersion.ITRF_2014));
68  
69          MatcherAssert.assertThat(
70                  loader.getConfiguration("bulletinb_IAU1980-123.txt", 0).getVersion(),
71                  CoreMatchers.is(ITRFVersion.ITRF_2005));
72          MatcherAssert.assertThat(
73                  loader.getConfiguration("bulletinb_IAU2000-123.txt", 0).getVersion(),
74                  CoreMatchers.is(ITRFVersion.ITRF_2005));
75  
76          MatcherAssert.assertThat(
77                  loader.getConfiguration("bulletinb-123.txt", 55555).getVersion(),
78                  CoreMatchers.is(ITRFVersion.ITRF_2005));
79          MatcherAssert.assertThat(
80                  loader.getConfiguration("bulletinb.123", 55555).getVersion(),
81                  CoreMatchers.is(ITRFVersion.ITRF_2005));
82          MatcherAssert.assertThat(
83                  loader.getConfiguration("bulletinb-123.txt", 57777).getVersion(),
84                  CoreMatchers.is(ITRFVersion.ITRF_2008));
85          MatcherAssert.assertThat(
86                  loader.getConfiguration("bulletinb.123", 57777).getVersion(),
87                  CoreMatchers.is(ITRFVersion.ITRF_2008));
88          MatcherAssert.assertThat(
89                  loader.getConfiguration("bulletinb-123.txt", 58484).getVersion(),
90                  CoreMatchers.is(ITRFVersion.ITRF_2014));
91          MatcherAssert.assertThat(
92                  loader.getConfiguration("bulletinb.123", 58484).getVersion(),
93                  CoreMatchers.is(ITRFVersion.ITRF_2014));
94  
95          MatcherAssert.assertThat(loader.getConfiguration("finals.all", 0).getVersion(),
96                  CoreMatchers.is(ITRFVersion.ITRF_2000));
97          MatcherAssert.assertThat(loader.getConfiguration("finals2000A.all", 0).getVersion(),
98                  CoreMatchers.is(ITRFVersion.ITRF_2000));
99          MatcherAssert.assertThat(loader.getConfiguration("finals.all", 55555).getVersion(),
100                 CoreMatchers.is(ITRFVersion.ITRF_2005));
101         MatcherAssert.assertThat(loader.getConfiguration("finals2000A.all", 55555).getVersion(),
102                 CoreMatchers.is(ITRFVersion.ITRF_2005));
103         MatcherAssert.assertThat(loader.getConfiguration("finals.all", 57777).getVersion(),
104                 CoreMatchers.is(ITRFVersion.ITRF_2008));
105         MatcherAssert.assertThat(loader.getConfiguration("finals2000A.all", 57777).getVersion(),
106                 CoreMatchers.is(ITRFVersion.ITRF_2008));
107         MatcherAssert.assertThat(loader.getConfiguration("finals.all", 58484).getVersion(),
108                 CoreMatchers.is(ITRFVersion.ITRF_2014));
109         MatcherAssert.assertThat(loader.getConfiguration("finals2000A.all", 58484).getVersion(),
110                 CoreMatchers.is(ITRFVersion.ITRF_2014));
111     }
112 
113     /** Check using file names generated by other loaders. */
114     @Test
115     public void testLoaders() {
116         // setup
117         Utils.setDataRoot("regular-data");
118         ItrfVersionProvider loader =
119                 new ITRFVersionLoader(ITRFVersionLoader.SUPPORTED_NAMES);
120 
121         MatcherAssert.assertThat(loader.getConfiguration("/finals.all", 55555).getVersion(),
122                 CoreMatchers.is(ITRFVersion.ITRF_2005));
123         MatcherAssert.assertThat(loader.getConfiguration("\\finals.all", 55555).getVersion(),
124                 CoreMatchers.is(ITRFVersion.ITRF_2005));
125         MatcherAssert.assertThat(
126                 loader .getConfiguration(
127                                 "https://user@example.com:port/path/finals.all?a=b#c",
128                                 55555)
129                         .getVersion(),
130                 CoreMatchers.is(ITRFVersion.ITRF_2005));
131         MatcherAssert.assertThat(
132                 loader.getConfiguration("a.zip!/finals.all", 55555).getVersion(),
133                 CoreMatchers.is(ITRFVersion.ITRF_2005));
134     }
135 
136     /** Check that using the old format throws a helpful exception. */
137     @Test
138     public void testOldFormat() {
139         Utils.setDataRoot("obsolete-data");
140         try {
141             new ITRFVersionLoader(ITRFVersionLoader.SUPPORTED_NAMES);
142             Assertions.fail("Expected Exception");
143         } catch (OrekitException e) {
144             Assertions.assertEquals(e.getSpecifier(), OrekitMessages.ITRF_VERSIONS_PREFIX_ONLY);
145         }
146     }
147 
148 }