1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.data.AbstractFilesLoaderTest;
24 import org.orekit.errors.OrekitException;
25 import org.orekit.errors.OrekitMessages;
26 import org.orekit.time.AbsoluteDate;
27 import org.orekit.time.ChronologicalComparator;
28 import org.orekit.time.TimeScalesFactory;
29 import org.orekit.utils.IERSConventions;
30 import org.xml.sax.SAXException;
31
32 import java.net.MalformedURLException;
33 import java.util.Collections;
34 import java.util.SortedSet;
35 import java.util.TreeSet;
36
37
38 public class EopXmlLoaderTest extends AbstractFilesLoaderTest {
39
40 private static final ChronologicalComparator COMP = new ChronologicalComparator();
41
42 @Test
43 public void testExternalResourcesAreIgnoredIssue368() {
44
45 setRoot("external-resources");
46 IERSConventions.NutationCorrectionConverter converter =
47 IERSConventions.IERS_1996.getNutationCorrectionConverter();
48 SortedSet<EOPEntry> history = new TreeSet<>(new ChronologicalComparator());
49 EopXmlLoader loader =
50 new EopXmlLoader("^finals2000A\\..*\\.xml$", manager, () -> utc);
51
52
53 try {
54 loader.fillHistory(converter, history);
55
56
57 Assertions.fail("Expected Exception");
58 } catch (OrekitException e) {
59
60
61 MatcherAssert.assertThat(e.getCause(),
62 CoreMatchers.instanceOf(MalformedURLException.class));
63 }
64
65
66 Assertions.assertEquals(0, history.size());
67 }
68
69 @Test
70 public void testInconsistentDate() {
71 setRoot("eop-xml");
72 IERSConventions.NutationCorrectionConverter converter =
73 IERSConventions.IERS_1996.getNutationCorrectionConverter();
74 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
75 try {
76 new EopXmlLoader("^inconsistent-date\\.xml$", manager, () -> utc).fillHistory(converter, history);
77 Assertions.fail("an exception should have been thrown");
78 } catch (OrekitException oe) {
79 Assertions.assertEquals(OrekitMessages.INCONSISTENT_DATES_IN_IERS_FILE, oe.getSpecifier());
80 }
81 }
82
83 @Test
84 public void testMalformedXml() {
85 setRoot("eop-xml");
86 IERSConventions.NutationCorrectionConverter converter =
87 IERSConventions.IERS_1996.getNutationCorrectionConverter();
88 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
89 try {
90 new EopXmlLoader("^malformed\\.xml$", manager, () -> utc).fillHistory(converter, history);
91 Assertions.fail("an exception should have been thrown");
92 } catch (OrekitException oe) {
93 Assertions.assertTrue(oe.getCause() instanceof SAXException);
94 }
95 }
96
97 @Test
98 public void testStartDateDaily1980() {
99 setRoot("eop-xml");
100 IERSConventions.NutationCorrectionConverter converter =
101 IERSConventions.IERS_1996.getNutationCorrectionConverter();
102 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
103 new EopXmlLoader("^finals\\.daily\\.xml$", manager, () -> utc).fillHistory(converter, history);
104 Assertions.assertEquals(new AbsoluteDate(2010, 7, 1, TimeScalesFactory.getUTC()),
105 new EOPHistory(IERSConventions.IERS_1996, EOPHistory.DEFAULT_INTERPOLATION_DEGREE,
106 history, true).getStartDate());
107 }
108
109 @Test
110 public void testEndDateDaily1980() {
111 setRoot("eop-xml");
112 IERSConventions.NutationCorrectionConverter converter =
113 IERSConventions.IERS_1996.getNutationCorrectionConverter();
114 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
115 new EopXmlLoader("^finals\\.daily\\.xml$", manager, () -> utc).fillHistory(converter, history);
116 Assertions.assertEquals(new AbsoluteDate(2010, 11, 8, TimeScalesFactory.getUTC()),
117 new EOPHistory(IERSConventions.IERS_1996, EOPHistory.DEFAULT_INTERPOLATION_DEGREE,
118 history, true).getEndDate());
119 }
120
121 @Test
122 public void testStartDateDaily2000() {
123 setRoot("eop-xml");
124 IERSConventions.NutationCorrectionConverter converter =
125 IERSConventions.IERS_2003.getNutationCorrectionConverter();
126 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
127 new EopXmlLoader("^finals2000A\\.daily\\.xml$", manager, () -> utc).fillHistory(converter, history);
128 Assertions.assertEquals(new AbsoluteDate(2010, 5, 11, TimeScalesFactory.getUTC()),
129 Collections.min(history, COMP).getDate());
130 }
131
132 @Test
133 public void testEndDateDaily2000() {
134 setRoot("eop-xml");
135 IERSConventions.NutationCorrectionConverter converter =
136 IERSConventions.IERS_2003.getNutationCorrectionConverter();
137 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
138 new EopXmlLoader("^finals2000A\\.daily\\.xml$", manager, () -> utc).fillHistory(converter, history);
139 Assertions.assertEquals(new AbsoluteDate(2010, 11, 5, TimeScalesFactory.getUTC()),
140 Collections.max(history, COMP).getDate());
141 }
142
143 @Test
144 public void testBulletinA() {
145 setRoot("eop-xml");
146 IERSConventions.NutationCorrectionConverter converter =
147 IERSConventions.IERS_2003.getNutationCorrectionConverter();
148 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
149 new EopXmlLoader("^bulletina-xxxiii-037\\.xml$", manager, () -> utc).fillHistory(converter, history);
150 Assertions.assertEquals(new AbsoluteDate(2021, 9, 10, TimeScalesFactory.getUTC()),
151 Collections.max(history, COMP).getDate());
152 }
153
154 @Test
155 public void testBulletinB() {
156 setRoot("eop-xml");
157 IERSConventions.NutationCorrectionConverter converter =
158 IERSConventions.IERS_2003.getNutationCorrectionConverter();
159 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
160 new EopXmlLoader("^bulletinb-421\\.xml$", manager, () -> utc).fillHistory(converter, history);
161 Assertions.assertEquals(new AbsoluteDate(2023, 3, 1, TimeScalesFactory.getUTC()),
162 Collections.max(history, COMP).getDate());
163 }
164
165 @Test
166 public void testEOPC04() {
167 setRoot("eop-xml");
168 IERSConventions.NutationCorrectionConverter converter =
169 IERSConventions.IERS_2003.getNutationCorrectionConverter();
170 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
171 new EopXmlLoader("^eopc04_20\\.2022-now\\.xml$", manager, () -> utc).fillHistory(converter, history);
172 Assertions.assertEquals(new AbsoluteDate(2023, 8, 28, TimeScalesFactory.getUTC()),
173 Collections.max(history, COMP).getDate());
174 }
175
176 @Test
177 public void testStartDateFinals1980() {
178 setRoot("compressed-data");
179 IERSConventions.NutationCorrectionConverter converter =
180 IERSConventions.IERS_1996.getNutationCorrectionConverter();
181 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
182 new EopXmlLoader("^finals\\.1999\\.xml$", manager, () -> utc).fillHistory(converter, history);
183 Assertions.assertEquals(new AbsoluteDate(1999, 1, 1, TimeScalesFactory.getUTC()),
184 new EOPHistory(IERSConventions.IERS_1996, EOPHistory.DEFAULT_INTERPOLATION_DEGREE,
185 history, true).getStartDate());
186 }
187
188 @Test
189 public void testEndDateFinals1980() {
190 setRoot("compressed-data");
191 IERSConventions.NutationCorrectionConverter converter =
192 IERSConventions.IERS_1996.getNutationCorrectionConverter();
193 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
194 new EopXmlLoader("^finals\\.1999\\.xml$", manager, () -> utc).fillHistory(converter, history);
195 Assertions.assertEquals(new AbsoluteDate(1999, 12, 31, TimeScalesFactory.getUTC()),
196 new EOPHistory(IERSConventions.IERS_1996, EOPHistory.DEFAULT_INTERPOLATION_DEGREE,
197 history, true).getEndDate());
198 }
199
200 @Test
201 public void testStartDateFinals2000() {
202 setRoot("regular-data");
203 IERSConventions.NutationCorrectionConverter converter =
204 IERSConventions.IERS_2003.getNutationCorrectionConverter();
205 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
206 new EopXmlLoader("^finals2000A\\.2002\\.xml$", manager, () -> utc).fillHistory(converter, history);
207 Assertions.assertEquals(new AbsoluteDate(2002, 1, 1, TimeScalesFactory.getUTC()),
208 new EOPHistory(IERSConventions.IERS_2003, EOPHistory.DEFAULT_INTERPOLATION_DEGREE,
209 history, true).getStartDate());
210 }
211
212 @Test
213 public void testEndDateFinals2000() {
214 setRoot("regular-data");
215 IERSConventions.NutationCorrectionConverter converter =
216 IERSConventions.IERS_2003.getNutationCorrectionConverter();
217 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
218 new EopXmlLoader("^finals2000A\\.2002\\.xml$", manager, () -> utc).fillHistory(converter, history);
219 Assertions.assertEquals(new AbsoluteDate(2002, 12, 31, TimeScalesFactory.getUTC()),
220 new EOPHistory(IERSConventions.IERS_2003, EOPHistory.DEFAULT_INTERPOLATION_DEGREE,
221 history, true).getEndDate());
222 }
223
224 @Test
225 public void testIssue139() {
226 setRoot("zipped-data");
227 IERSConventions.NutationCorrectionConverter converter =
228 IERSConventions.IERS_1996.getNutationCorrectionConverter();
229 SortedSet<EOPEntry> history = new TreeSet<EOPEntry>(new ChronologicalComparator());
230 new EopXmlLoader("^finals\\.daily\\.xml$", manager, () -> utc).fillHistory(converter, history);
231 Assertions.assertEquals(new AbsoluteDate(2010, 7, 1, TimeScalesFactory.getUTC()),
232 new EOPHistory(IERSConventions.IERS_1996, EOPHistory.DEFAULT_INTERPOLATION_DEGREE,
233 history, true).getStartDate());
234 }
235
236 }