in ORCPublicCertificateDatabaseImpl use JSON certificates instead of RMS to align IDs

This commit is contained in:
Axel Uhl committed 2020-03-10 00:29:00 +01:00
1 parent 11e3921ef7
commit 4ae024ac3d
2 files changed
+19 -21

No files matched your search

@@ -2,16 +2,21 @@ package com.sap.sailing.domain.orc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;
import org.json.simple.parser.ParseException;
import org.junit.Rule;
import org.junit.Test;
import com.sap.sailing.domain.common.orc.ORCCertificate;
import com.sap.sailing.domain.common.orc.impl.ORCCertificateImpl;
import com.sap.sse.common.Util;
public class TestORCCertificateImporterJSON {
@@ -30,32 +35,25 @@ public class TestORCCertificateImporterJSON {
@IgnoreInvalidOrcCertificates
@Test
public void testSimpleOnlineJSONFileRead() throws IOException, ParseException {
public void testSimpleOnlineJSONFileRead() throws IOException, ParseException, InterruptedException {
Collection<ORCCertificate> certificates = customIgnoreRule.getAvailableCerts();
final ORCCertificate cert = certificates.stream().findFirst().get();
String countryCode = cert.getId().substring(0, 3);
String url = String.format("https://data.orc.org/public/WPub.dll?action=DownRMS&CountryId=%s&ext=json", countryCode);
String url = String.format("https://data.orc.org/public/WPub.dll?action=DownBoatRMS&CountryId=%s&ext=json", countryCode);
ORCCertificatesCollection importer = ORCCertificatesImporter.INSTANCE.read(new URL(url).openStream());
ORCCertificate swan = null, refernceCert = null;
ORCCertificate someValidCert = null, referenceCert = null;
for (ORCCertificate orcCertificate : certificates) {
swan = importer.getCertificateById(orcCertificate.getId());
if (swan != null) {
refernceCert = orcCertificate;
someValidCert = importer.getCertificateById(orcCertificate.getId());
if (someValidCert != null) {
referenceCert = orcCertificate;
break;
}
}
assertNotNull(swan);
assertNotNull(refernceCert);
assertEquals(refernceCert.getGPHInSecondsToTheMile(), swan .getGPHInSecondsToTheMile(), 0.0000001);
// assertEquals(
// refernceCert.getWindwardLeewardSpeedPrediction().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(),
// swan.getWindwardLeewardSpeedPrediction().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(),
// 0.1);
// assertEquals(
// refernceCert.getLongDistanceSpeedPredictions().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(),
// swan.getLongDistanceSpeedPredictions().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(),
// 0.1);
assertNotNull("None of the certificates "+String.join(", ", Util.map(certificates, c->c.toString()))+
" was found when importing the country document from "+url, someValidCert);
assertNotNull(referenceCert);
assertEquals(referenceCert.getGPHInSecondsToTheMile(), someValidCert.getGPHInSecondsToTheMile(), 0.0000001);
assertTrue(referenceCert.getWindwardLeewardSpeedPrediction().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds() > 10);
assertTrue(referenceCert.getLongDistanceSpeedPredictions().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds() > 10);
}
}
@@ -406,10 +406,10 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat
@Override
public ORCCertificate getCertificate(String referenceNumber) throws Exception {
final HttpClient client = new SystemDefaultHttpClient();
final HttpGet getRequest = new HttpGet("http://data.orc.org/public/WPub.dll?action=DownBoatRMS&RefNo="+referenceNumber);
final HttpGet getRequest = new HttpGet("http://data.orc.org/public/WPub.dll?action=DownBoatRMS&ext=json&RefNo="+referenceNumber);
addAuthorizationHeader(getRequest);
logger.fine("Obtaining certificate for reference number "+referenceNumber);
final Iterable<ORCCertificate> certificates = new ORCCertificatesRmsImporter().read(client.execute(getRequest).getEntity().getContent())
final Iterable<ORCCertificate> certificates = new ORCCertificatesJsonImporter().read(client.execute(getRequest).getEntity().getContent())
.getCertificates();
final ORCCertificate result;
if (certificates.iterator().hasNext()) {