diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCCertificateImporterJSON.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCCertificateImporterJSON.java index e5d69283856..66a3819d76d 100644 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCCertificateImporterJSON.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCCertificateImporterJSON.java @@ -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 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); } } diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCPublicCertificateDatabaseImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCPublicCertificateDatabaseImpl.java index bf8cb03c4f3..ac642fc5e6f 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCPublicCertificateDatabaseImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCPublicCertificateDatabaseImpl.java @@ -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 certificates = new ORCCertificatesRmsImporter().read(client.execute(getRequest).getEntity().getContent()) + final Iterable certificates = new ORCCertificatesJsonImporter().read(client.execute(getRequest).getEntity().getContent()) .getCertificates(); final ORCCertificate result; if (certificates.iterator().hasNext()) {