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