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.gnss.metric.ntrip;
18  
19  import org.hipparchus.util.FastMath;
20  import org.junit.jupiter.api.Assertions;
21  import org.junit.jupiter.api.Test;
22  
23  public class CasterRecordTest {
24  
25      private static String PRODUCTS   = "CAS;products.igs-ip.net;2101;PRODUCTS;BKG;0;DEU;50.12;8.69;0.0.0.0;0;http://products.igs-ip.net/home";
26      private static String RTCM_NTRIP = "CAS;rtcm-ntrip.org;2101;NtripInfoCaster;BKG;0;DEU;50.12;8.69;0.0.0.0;0;http://www.rtcm-ntrip.org/home";
27  
28      @Test
29      public void testPRODUCTS() {
30          final CasterRecord cas = new CasterRecord(PRODUCTS);
31          Assertions.assertEquals(RecordType.CAS,                    cas.getRecordType());
32          Assertions.assertEquals("products.igs-ip.net",             cas.getHostOrIPAddress());
33          Assertions.assertEquals(2101,                              cas.getPort());
34          Assertions.assertEquals("PRODUCTS",                        cas.getSourceIdentifier());
35          Assertions.assertEquals("BKG",                             cas.getOperator());
36          Assertions.assertEquals(false,                             cas.canReceiveNMEA());
37          Assertions.assertEquals("DEU",                             cas.getCountry());
38          Assertions.assertEquals(50.12,                             FastMath.toDegrees(cas.getLatitude()),  1.0e-15);
39          Assertions.assertEquals( 8.69,                             FastMath.toDegrees(cas.getLongitude()), 1.0e-15);
40          Assertions.assertEquals("0.0.0.0",                         cas.getFallbackHostOrIPAddress());
41          Assertions.assertEquals(0,                                 cas.getFallbackPort());
42          Assertions.assertEquals("http://products.igs-ip.net/home", cas.getMisc());
43      }
44  
45      @Test
46      public void testRTCM_NTRIP() {
47          final CasterRecord cas = new CasterRecord(RTCM_NTRIP);
48          Assertions.assertEquals(RecordType.CAS,                    cas.getRecordType());
49          Assertions.assertEquals("rtcm-ntrip.org",                  cas.getHostOrIPAddress());
50          Assertions.assertEquals(2101,                              cas.getPort());
51          Assertions.assertEquals("NtripInfoCaster",                 cas.getSourceIdentifier());
52          Assertions.assertEquals("BKG",                             cas.getOperator());
53          Assertions.assertEquals(false,                             cas.canReceiveNMEA());
54          Assertions.assertEquals("DEU",                             cas.getCountry());
55          Assertions.assertEquals(50.12,                             FastMath.toDegrees(cas.getLatitude()),  1.0e-15);
56          Assertions.assertEquals( 8.69,                             FastMath.toDegrees(cas.getLongitude()), 1.0e-15);
57          Assertions.assertEquals("0.0.0.0",                         cas.getFallbackHostOrIPAddress());
58          Assertions.assertEquals(0,                                 cas.getFallbackPort());
59          Assertions.assertEquals("http://www.rtcm-ntrip.org/home",  cas.getMisc());
60      }
61  
62      @Test
63      public void testReceiveNMEA() {
64          final CasterRecord cas = new CasterRecord(PRODUCTS.replace(";BKG;0;DEU;", ";BKG;1;DEU;"));
65          Assertions.assertTrue(cas.canReceiveNMEA());
66      }
67  
68      @Test
69      public void testEmbeddedSemiColon() {
70          final CasterRecord cas = new CasterRecord(PRODUCTS.replace("http://products.igs-ip.net/home", "aa\";\"bb\";\"cc"));
71          Assertions.assertEquals("aa;bb;cc", cas.getMisc());
72      }
73  
74  }