1   /* Copyright 2002-2025 Thales Alenia Space
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.models.earth.ionosphere.nequick;
18  
19  import org.junit.jupiter.api.Assertions;
20  import org.junit.jupiter.api.Test;
21  import org.orekit.data.DataSource;
22  import org.orekit.errors.OrekitException;
23  import org.orekit.errors.OrekitMessages;
24  import org.orekit.time.DateComponents;
25  
26  import java.io.IOException;
27  import java.io.PipedReader;
28  import java.io.StringReader;
29  
30  public class CCIRLoaderTest {
31  
32      @Test
33      public void testAllMonths() {
34          for (int month = 1; month <= 12; month++) {
35              final CCIRLoader loader = new CCIRLoader();
36              loader.loadCCIRCoefficients(new DateComponents(2003, month, 15));
37              Assertions.assertEquals( 2, loader.getF2().length);
38              Assertions.assertEquals(76, loader.getF2()[0].length);
39              Assertions.assertEquals(13, loader.getF2()[0][0].length);
40              Assertions.assertEquals( 2, loader.getFm3().length);
41              Assertions.assertEquals(49, loader.getFm3()[0].length);
42              Assertions.assertEquals( 9, loader.getFm3()[0][0].length);
43          }
44      }
45  
46      @Test
47      public void testNoData() {
48          try {
49              new CCIRLoader().loadData(new DataSource("empty", () -> new StringReader("")));
50              Assertions.fail("an exception should have been thrown");
51          } catch (OrekitException oe) {
52              Assertions.assertEquals(OrekitMessages.NEQUICK_F2_FM3_NOT_LOADED, oe.getSpecifier());
53              Assertions.assertEquals("empty", oe.getParts()[0]);
54          }
55      }
56  
57      @Test
58      public void testIOException() {
59          try {
60              new CCIRLoader().loadData(new DataSource("exception", () -> new PipedReader()));
61              Assertions.fail("an exception should have been thrown");
62          } catch (OrekitException oe) {
63              Assertions.assertEquals(IOException.class, oe.getCause().getClass());
64              Assertions.assertEquals(OrekitMessages.NEQUICK_F2_FM3_NOT_LOADED, oe.getSpecifier());
65              Assertions.assertEquals("exception", oe.getParts()[0]);
66          }
67      }
68  
69      @Test
70      public void testParsingError() {
71          try {
72              new CCIRLoader().
73                  loadData(new DataSource("dummy", () -> new StringReader("\n" +
74                                                                          "  0.52396593E+01 -0.56523629E-01 -0.18704616E-01  0.12128916E-01\n" +
75                                                                          "  0.79412200E-02 -0.10031432E-01  0.21567253E-01 -0.68602669E-02\n" +
76                                                                          "  0.37022347E-02  0.78359321E-02  0.63161589E-02 -0.10695398E-01\n" +
77                                                                          "  0.29390156E-01  not-a-number   -0.28997501E-01  0.10946779E+00\n")));
78              Assertions.fail("an exception should have been thrown");
79          } catch (OrekitException oe) {
80              Assertions.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
81              Assertions.assertEquals(5, (Integer) oe.getParts()[0]);
82              Assertions.assertEquals("dummy", oe.getParts()[1]);
83              Assertions.assertEquals("0.29390156E-01  not-a-number   -0.28997501E-01  0.10946779E+00", oe.getParts()[2]);
84          }
85      }
86  
87  }