Skip to content
Snippets Groups Projects
Commit 0597fa29 authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Improved test coverage.

parent a05828e0
No related branches found
No related tags found
No related merge requests found
Showing
with 181 additions and 7 deletions
......@@ -217,6 +217,13 @@ public class NtripClient {
}
}
/** Get proxy.
* @return proxy to use
*/
public Proxy getProxy() {
return proxy;
}
/** Set GPS fix data to send as NMEA sentence to Ntrip caster if required.
* @param hour hour of the fix (UTC time)
* @param minute minute of the fix (UTC time)
......
......@@ -23,6 +23,7 @@ import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.hamcrest.CoreMatchers;
......@@ -45,6 +46,7 @@ import org.orekit.frames.FramesFactory;
import org.orekit.time.AbsoluteDate;
import org.orekit.time.TimeScale;
import org.orekit.time.TimeScalesFactory;
import org.orekit.utils.Constants;
/**
* Test class for CCSDS Tracking Data Message parsing.<p>
......@@ -470,6 +472,19 @@ public class TdmParserTest {
}
}
@Test
public void testMissingPArticipants() {
final String name = "/ccsds/tdm/xml/TDM-missing-participants.xml";
final DataSource source = new DataSource(name, () -> TdmParserTest.class.getResourceAsStream(name));
try {
new ParserBuilder().withRangeUnitsConverter(null).buildTdmParser().parseMessage(source);
Assert.fail("An exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY, oe.getSpecifier());
Assert.assertEquals(TdmMetadataKey.PARTICIPANT_1, oe.getParts()[0]);
}
}
@Test
public void testInconsistentDataLineKeyValue() {
// Inconsistent data line in KeyValue file (3 fields after keyword instead of 2)
......@@ -561,6 +576,19 @@ public class TdmParserTest {
final List<String> dataComment = new ArrayList<String>();
dataComment.add("This is a data comment");
Assert.assertEquals(dataComment, file.getSegments().get(0).getData().getComments());
// check so global setters that are not used by parser (it uses successive add instead)
metadata.setParticipants(Collections.singletonMap(12, "p12"));
Assert.assertNull(metadata.getParticipants().get(1));
Assert.assertEquals("p12", metadata.getParticipants().get(12));
metadata.setTransmitDelays(Collections.singletonMap(12, 1.25));
Assert.assertNull(metadata.getTransmitDelays().get(1));
Assert.assertEquals(1.25, metadata.getTransmitDelays().get(12).doubleValue(), 1.0e-15);
metadata.setReceiveDelays(Collections.singletonMap(12, 2.5));
Assert.assertNull(metadata.getReceiveDelays().get(1));
Assert.assertEquals(2.5, metadata.getReceiveDelays().get(12).doubleValue(), 1.0e-15);
}
/**
......@@ -590,11 +618,13 @@ public class TdmParserTest {
Assert.assertEquals(IntegrationReference.START, metadata.getIntegrationRef());
Assert.assertEquals(RangeMode.COHERENT, metadata.getRangeMode());
Assert.assertEquals(2.0e+26, metadata.getRawRangeModulus(), 0.0);
Assert.assertEquals(2.0e+26, metadata.getRangeModulus(new IdentityConverter()), 0.0);
Assert.assertEquals(RangeUnits.RU, metadata.getRangeUnits());
Assert.assertEquals(7.7e-5, metadata.getTransmitDelays().get(1), 0.0);
Assert.assertEquals(0.0, metadata.getTransmitDelays().get(2), 0.0);
Assert.assertEquals(7.7e-5, metadata.getReceiveDelays().get(1), 0.0);
Assert.assertEquals(0.0, metadata.getReceiveDelays().get(2), 0.0);
Assert.assertEquals(46.7741, metadata.getCorrectionRange(new IdentityConverter()), 0.0);
Assert.assertEquals(46.7741, metadata.getRawCorrectionRange(), 0.0);
Assert.assertEquals(CorrectionApplied.YES, metadata.getCorrectionsApplied());
final List<String> metaDataComment = new ArrayList<String>();
......@@ -666,9 +696,13 @@ public class TdmParserTest {
Assert.assertEquals(1.0, metadata.getIntegrationInterval(), 0.0);
Assert.assertEquals(IntegrationReference.MIDDLE, metadata.getIntegrationRef());
Assert.assertEquals(RangeMode.CONSTANT, metadata.getRangeMode());
Assert.assertEquals(0.0, metadata.getRawRangeModulus(), 0.0);
Assert.assertEquals(1.0, metadata.getRawRangeModulus(), 0.0);
Assert.assertEquals(1000.0, metadata.getRangeModulus(new IdentityConverter()), 0.0);
Assert.assertEquals(RangeUnits.km, metadata.getRangeUnits());
Assert.assertEquals(AngleType.AZEL, metadata.getAngleType());
Assert.assertEquals(2.0, metadata.getRawCorrectionRange(), 0.0);
Assert.assertEquals(2000.0, metadata.getCorrectionRange(new IdentityConverter()), 0.0);
Assert.assertEquals(CorrectionApplied.YES, metadata.getCorrectionsApplied());
// Data
final List<Observation> observations = file.getSegments().get(0).getData().getObservations();
......@@ -772,8 +806,14 @@ public class TdmParserTest {
Assert.assertArrayEquals(new int[] { 1, 2, 1 }, metadata2.getPath());
Assert.assertEquals(1.0, metadata2.getIntegrationInterval(), 0.0);
Assert.assertEquals(IntegrationReference.END, metadata2.getIntegrationRef());
Assert.assertEquals(1.0e7, metadata2.getRawRangeModulus(), 0.0);
Assert.assertEquals(1.0e7 * Constants.SPEED_OF_LIGHT, metadata2.getRangeModulus(new IdentityConverter()), 0.0);
Assert.assertEquals(RangeUnits.s, metadata2.getRangeUnits());
Assert.assertEquals(AngleType.AZEL, metadata2.getAngleType());
Assert.assertEquals(DataQuality.RAW, metadata2.getDataQuality());
Assert.assertEquals(2.0, metadata2.getRawCorrectionRange(), 0.0);
Assert.assertEquals(2.0 * Constants.SPEED_OF_LIGHT, metadata2.getCorrectionRange(new IdentityConverter()), 0.0);
Assert.assertEquals(CorrectionApplied.YES, metadata2.getCorrectionsApplied());
final List<String> metaDataComment2 = new ArrayList<String>();
metaDataComment2.add("This is a meta-data comment");
Assert.assertEquals(metaDataComment2, metadata2.getComments());
......@@ -790,9 +830,9 @@ public class TdmParserTest {
"2007-08-29T07:00:02.000", "2007-08-29T07:00:02.000", "2007-08-29T07:00:02.000", "2007-08-29T07:00:02.000",
"2007-08-29T13:00:02.000", "2007-08-29T13:00:02.000", "2007-08-29T13:00:02.000", "2007-08-29T13:00:02.000"};
final double[] values2 = {4.00165248953670E+04, -885.640091, FastMath.toRadians(99.53204250), FastMath.toRadians(1.26724167),
3.57238793591890E+04, -1510.223139, FastMath.toRadians(103.33061750), FastMath.toRadians(4.77875278),
3.48156855860090E+04, 1504.082291, FastMath.toRadians(243.73365222), FastMath.toRadians(8.78254167)};
final double[] values2 = {4.00165248953670E+04 * Constants.SPEED_OF_LIGHT, -885.640091, FastMath.toRadians(99.53204250), FastMath.toRadians(1.26724167),
3.57238793591890E+04 * Constants.SPEED_OF_LIGHT, -1510.223139, FastMath.toRadians(103.33061750), FastMath.toRadians(4.77875278),
3.48156855860090E+04 * Constants.SPEED_OF_LIGHT, 1504.082291, FastMath.toRadians(243.73365222), FastMath.toRadians(8.78254167)};
// Check consistency
for (int i = 0; i < keywords2.length; i++) {
Assert.assertEquals(keywords2[i], observations2.get(i).getType().name());
......
......@@ -17,6 +17,7 @@
package org.orekit.gnss.metric.ntrip;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URISyntaxException;
import java.nio.file.Paths;
......@@ -28,6 +29,15 @@ import org.orekit.errors.OrekitMessages;
public class NtripClientTest {
@Test
public void testProxy() {
NtripClient client = new NtripClient("ntrip.example.org", NtripClient.DEFAULT_PORT);
client.setProxy(Proxy.Type.SOCKS, "localhost", 1080);
Assert.assertEquals(Proxy.Type.SOCKS, client.getProxy().type());
Assert.assertEquals("localhost", ((InetSocketAddress) client.getProxy().address()).getHostName());
Assert.assertEquals(1080, ((InetSocketAddress) client.getProxy().address()).getPort());
}
@Test
public void testUnknownProxy() {
final String nonExistant = "socks.invalid";
......@@ -147,6 +157,7 @@ public class NtripClientTest {
Assert.assertEquals( 2, table.getCasters().size());
Assert.assertEquals( 2, table.getNetworks().size());
Assert.assertEquals(42, table.getDataStreams().size());
Assert.assertSame(table, client.getSourceTable());
}
@Test
......@@ -251,7 +262,7 @@ public class NtripClientTest {
}
@Test
public void testAuthentication() {
public void testAuthenticationStream() {
DummyServer server = prepareServer("/gnss/ntrip/sourcetable-products.igs-ip.net.txt",
"/gnss/ntrip/requires-basic-authentication.txt");
server.run();
......@@ -272,6 +283,71 @@ public class NtripClientTest {
}
}
@Test
public void testAuthenticationCaster() {
DummyServer server = prepareServer("/gnss/ntrip/requires-basic-authentication.txt");
server.run();
NtripClient client = new NtripClient("localhost", server.getServerPort());
client.setTimeout(100);
try {
client.getSourceTable();
try {
Thread.sleep(400);
} catch (InterruptedException ie) {
// ignored
}
client.stopStreaming(100);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.FAILED_AUTHENTICATION, oe.getSpecifier());
Assert.assertEquals("caster", oe.getParts()[0]);
}
}
@Test
public void testForbiddenRequest() {
DummyServer server = prepareServer("/gnss/ntrip/forbidden-request.txt");
server.run();
NtripClient client = new NtripClient("localhost", server.getServerPort());
client.setTimeout(100);
try {
client.getSourceTable();
try {
Thread.sleep(400);
} catch (InterruptedException ie) {
// ignored
}
client.stopStreaming(100);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.CONNECTION_ERROR, oe.getSpecifier());
Assert.assertEquals("localhost", oe.getParts()[0]);
Assert.assertEquals("Forbidden", oe.getParts()[1]);
}
}
@Test
public void testMissingFlags() {
DummyServer server = prepareServer("/gnss/ntrip/missing-flags.txt");
server.run();
NtripClient client = new NtripClient("localhost", server.getServerPort());
client.setTimeout(100);
try {
client.getSourceTable();
try {
Thread.sleep(400);
} catch (InterruptedException ie) {
// ignored
}
client.stopStreaming(100);
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.MISSING_HEADER, oe.getSpecifier());
Assert.assertEquals("localhost", oe.getParts()[0]);
Assert.assertEquals("Ntrip-Flags", oe.getParts()[1]);
}
}
private DummyServer prepareServer(String... names) {
DummyServer server = null;
try {
......
......@@ -15,9 +15,11 @@ META_START
INTEGRATION_INTERVAL = 1.0
INTEGRATION_REF = MIDDLE
RANGE_MODE = CONSTANT
RANGE_MODULUS = 0
RANGE_MODULUS = 1
RANGE_UNITS = km
ANGLE_TYPE = AZEL
CORRECTION_RANGE = 2.0
CORRECTIONS_APPLIED = YES
META_STOP
DATA_START
COMMENT This is a data comment
......
......@@ -44,8 +44,11 @@ META_START
INTEGRATION_REF = END
RANGE_MODE = CONSTANT
RANGE_MODULUS = 1.000000E+07
RANGE_UNITS = s
ANGLE_TYPE = AZEL
DATA_QUALITY = RAW
CORRECTION_RANGE = 2.0
CORRECTIONS_APPLIED = YES
META_STOP
DATA_START
COMMENT This is a data comment
......
<?xml version="1.0" encoding="UTF-8"?>
<tdm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="fdsxml-1.0-master.xsd"
id="CCSDS_TDM_VERS" version="1.0">
<header>
<CREATION_DATE>2005-06-10T15:45:00.000</CREATION_DATE>
<ORIGINATOR>NASA/JPL</ORIGINATOR>
</header>
<body>
<segment>
<metadata>
<TIME_SYSTEM>UTC</TIME_SYSTEM>
<START_TIME>2005-05-22T12:00:00.000</START_TIME>
<STOP_TIME>2005-05-25T12:00:00.000</STOP_TIME>
</metadata>
<data>
<observation>
<EPOCH>2005-05-22T12:00:00.000</EPOCH>
<CLOCK_BIAS>-1.782E-6</CLOCK_BIAS>
</observation>
</data>
</segment>
</body>
</tdm>
......@@ -22,8 +22,11 @@
<INTEGRATION_INTERVAL>1.0</INTEGRATION_INTERVAL>
<INTEGRATION_REF>MIDDLE</INTEGRATION_REF>
<RANGE_MODE>CONSTANT</RANGE_MODE>
<RANGE_MODULUS>1</RANGE_MODULUS>
<RANGE_UNITS>km</RANGE_UNITS>
<ANGLE_TYPE>AZEL</ANGLE_TYPE>
<CORRECTION_RANGE>2.0</CORRECTION_RANGE>
<CORRECTIONS_APPLIED>YES</CORRECTIONS_APPLIED>
</metadata>
<data>
<COMMENT>This is a data comment</COMMENT>
......
......@@ -77,8 +77,11 @@
<INTEGRATION_REF>END</INTEGRATION_REF>
<RANGE_MODE>CONSTANT</RANGE_MODE>
<RANGE_MODULUS>1.0E7</RANGE_MODULUS>
<RANGE_UNITS>s</RANGE_UNITS>
<ANGLE_TYPE>AZEL</ANGLE_TYPE>
<DATA_QUALITY>RAW</DATA_QUALITY>
<CORRECTION_RANGE>2.0</CORRECTION_RANGE>
<CORRECTIONS_APPLIED>YES</CORRECTIONS_APPLIED>
</metadata>
<data>
<COMMENT>This is a data comment</COMMENT>
......
HTTP/1.1 403 Forbidden
WWW-Authenticate: Basic realm="/RTCM3EPH01"
Date: Wed, 06 Feb 2019 13:46:04 GMT
Connection: close
HTTP/1.1 200 OK
Ntrip-Version: Ntrip/2.0
Server: NTRIP BKG Caster 2.0.36/2.0
Date: Tue, 26 Nov 2019 12:12:11 GMT
Connection: close
Content-Type: gnss/sourcetable
Content-Length: 120
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
ENDSOURCETABLE
......@@ -5,12 +5,14 @@ Server: NTRIP BKG Caster/2.0.34
Date: Tue, 29 Jan 2019 16:40:58 GMT
Connection: close
Content-Type: gnss/sourcetable
Content-Length: 6552
Content-Length: 6558
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
CAS;rtcm-ntrip.org;2101;NtripInfoCaster;BKG;0;DEU;50.12;8.69;0.0.0.0;0;http://www.rtcm-ntrip.org/home
NET;IGS;IGS;B;N;https://igs.bkg.bund.de/root_ftp/NTRIP/streams/streamlist_igs-ip.htm;https://igs.bkg.bund.de:443/root_ftp/IGS/station/rnxskl/;http://register.rtcm-ntrip.org;none
NET;MISC;BKG;B;N;http://igs.bkg.bund.de/root_ftp/NTRIP/streams/streamlist_igs-ip.htm;https://igs.bkg.bund.de:443/root_ftp/MISC/station/rnxskl/;http://register.rtcm-ntrip.org;none
STR;CLK00;BRDC_CoM_ITRF;RTCM 3.1;1057(60),1058(5),1059(5);0;GPS;MISC;DEU;50.09;8.66;0;1;RTNet;none;B;N;1000;BKG
STR;CLK01;BRDC_CoM_ITRF;RTCM 3.1;1057(60),1058(5),1059(5),1063(60),1064(5);0;GPS+GLO;MISC;DEU;50.09;8.66;0;1;RTNet;none;B;N;1400;BKG
STR;CLK10;BRDC_APC_ITRF;RTCM 3.1;1057(60),1058(5),1059(5);0;GPS;MISC;DEU;50.09;8.66;0;1;RTNet;none;B;N;1000;BKG
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment