diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/AbstractORCCertificateImporterTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/AbstractORCCertificateImporterTest.java index a6f2a234e45..9660bea8d1b 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/AbstractORCCertificateImporterTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/AbstractORCCertificateImporterTest.java @@ -1,20 +1,15 @@ 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 com.sap.sailing.domain.common.orc.ORCCertificate; -import com.sap.sse.common.Util; public abstract class AbstractORCCertificateImporterTest { @@ -29,27 +24,4 @@ public abstract class AbstractORCCertificateImporterTest { ORCCertificate milan = importer.getCertificateById(expectedCertificateId); assertNotNull(milan); } - - @FailIfNoValidOrcCertificates - protected void testSimpleOnlineFileRead(String rmsOrJsonFormat) throws IOException, ParseException, InterruptedException { - Collection certificates = customIgnoreRule.getAvailableCerts(); - final ORCCertificate cert = certificates.stream().findFirst().get(); - String countryCode = cert.getIssuingCountry().getThreeLetterIOCCode(); - String url = String.format("https://data.orc.org/public/WPub.dll?action=DownRMS&CountryId=%s&ext=%s", countryCode, rmsOrJsonFormat); - ORCCertificatesCollection importer = ORCCertificatesImporter.INSTANCE.read(new URL(url).openStream()); - ORCCertificate someValidCert = null, referenceCert = null; - for (ORCCertificate orcCertificate : certificates) { - someValidCert = importer.getCertificateById(orcCertificate.getId()); - if (someValidCert != null) { - referenceCert = orcCertificate; - break; - } - } - 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(ORCCertificate.NAUTICAL_MILE).asSeconds() > 10); - assertTrue(referenceCert.getLongDistanceSpeedPredictions().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificate.NAUTICAL_MILE).asSeconds() > 10); - } } diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/FailIfNoValidOrcCertificateRule.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/FailIfNoValidOrcCertificateRule.java index 7abc1d12c31..53a9267d08d 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/FailIfNoValidOrcCertificateRule.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/FailIfNoValidOrcCertificateRule.java @@ -3,10 +3,7 @@ package com.sap.sailing.domain.orc; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; import java.util.List; -import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.StreamSupport; @@ -19,6 +16,7 @@ import com.sap.sailing.domain.common.orc.ORCCertificate; import com.sap.sailing.domain.orc.ORCPublicCertificateDatabase.CertificateHandle; import com.sap.sailing.domain.orc.ORCPublicCertificateDatabase.CountryOverview; import com.sap.sailing.domain.orc.impl.ORCPublicCertificateDatabaseImpl; +import com.sap.sse.common.Util; /*** * A IgnoreInvalidOrcCerticatesRule is an implementation of TestRule. This class execution depends on @@ -38,9 +36,39 @@ import com.sap.sailing.domain.orc.impl.ORCPublicCertificateDatabaseImpl; public class FailIfNoValidOrcCertificateRule implements TestRule { private static final Logger logger = Logger.getLogger(FailIfNoValidOrcCertificateRule.class.getName()); - private ORCPublicCertificateDatabase db = new ORCPublicCertificateDatabaseImpl(); + private static final int NUMBER_OF_CERTIFICATES_TO_PROBE = 3; - private List availableCerts; + private static List availableCerts; + private static boolean certificateExists; + + static { + certificateExists = false; + availableCerts = new ArrayList<>(); + final ORCPublicCertificateDatabase db = new ORCPublicCertificateDatabaseImpl(); + CountryOverview countryWithMostValidCertificates; + try { + countryWithMostValidCertificates = StreamSupport + .stream(db.getCountriesWithValidCertificates().spliterator(), /* parallel */ false) + .max((c1, c2) -> c1.getCertCount() - c2.getCertCount()).get(); + Iterable certificateHandles = db.search(countryWithMostValidCertificates.getIssuingCountry(), + countryWithMostValidCertificates.getVPPYear(), null, null, null, null, /* includeInvalid */ false); + final List randomSubset = new ArrayList<>(); + Util.addAll(certificateHandles, randomSubset); + Collections.shuffle(randomSubset); + Iterable orcCertificates = db.getCertificates(randomSubset.subList(0, NUMBER_OF_CERTIFICATES_TO_PROBE)); + orcCertificates.forEach(availableCerts::add); + if (orcCertificates.iterator().hasNext()) { + certificateExists = true; + } + } catch (Exception ex) { + logger.log(Level.WARNING, "Problem trying to fetch certificates tests"); + } + } + + + public FailIfNoValidOrcCertificateRule() { + logger.info("FailIfNoValidOrcCertificateRule created"); + } public Collection getAvailableCerts() { return Collections.unmodifiableCollection(availableCerts); @@ -58,7 +86,6 @@ public class FailIfNoValidOrcCertificateRule implements TestRule { public IgnorableStatement(Statement base, Description description) { this.base = base; this.description = description; - availableCerts = new ArrayList<>(); } /*** @@ -68,36 +95,10 @@ public class FailIfNoValidOrcCertificateRule implements TestRule { */ @Override public void evaluate() throws Throwable { - boolean certificateExists = true; FailIfNoValidOrcCertificates annotation = description.getAnnotation(FailIfNoValidOrcCertificates.class); - if (annotation != null) { - final CountryOverview countryWithMostValidCertificates = StreamSupport - .stream(db.getCountriesWithValidCertificates().spliterator(), /* parallel */ false) - .max((c1, c2) -> c1.getCertCount() - c2.getCertCount()).get(); - certificateExists = false; - try { - Iterable certificateHandles = db.search(countryWithMostValidCertificates.getIssuingCountry(), - countryWithMostValidCertificates.getVPPYear(), null, null, null, null, /* includeInvalid */ false); - final Set firstTen = new HashSet<>(); - int i=0; - final Iterator certificateHandlesIterator = certificateHandles.iterator(); - while (i<10 && certificateHandlesIterator.hasNext()) { - firstTen.add(certificateHandlesIterator.next()); - i++; - } - Iterable orcCertificates = db.getCertificates(firstTen); - orcCertificates.forEach(availableCerts::add); - if (orcCertificates.iterator().hasNext()) { - certificateExists = true; - } - } catch (Exception ex) { - logger.log(Level.WARNING, "Problem trying to fetch certificates for country "+countryWithMostValidCertificates.getIssuingCountry()+ - " and year "+countryWithMostValidCertificates.getVPPYear()); - } - } - if (certificateExists) { + if (annotation == null || certificateExists) { base.evaluate(); - } else { + } else if (annotation != null) { logger.warning("No certificates found. Are we at the beginning of a new year (January)? Then this may be okay. Otherwise, please check what's up!"); } } 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 a8c368b3edd..7d195ab70cc 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 @@ -1,13 +1,18 @@ package com.sap.sailing.domain.orc; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; +import java.util.Collection; import org.json.simple.parser.ParseException; import org.junit.Test; +import com.sap.sailing.domain.common.orc.ORCCertificate; + public class TestORCCertificateImporterJSON extends AbstractORCCertificateImporterTest { - @Test public void testSimpleLocalJSONFileRead() throws IOException, ParseException { testSimpleLocalFileRead("GER2019.json", "GER20041179"); @@ -17,10 +22,14 @@ public class TestORCCertificateImporterJSON extends AbstractORCCertificateImport public void testReadingJSONWithSpecificBins() throws IOException, ParseException { testSimpleLocalFileRead("03600000HUH.json", "03600000HUH"); } - + @FailIfNoValidOrcCertificates @Test - public void testSimpleOnlineJSONFileRead() throws IOException, ParseException, InterruptedException { - testSimpleOnlineFileRead("json"); + public void testSimpleOnlineFileRead() throws IOException, ParseException, InterruptedException { + Collection certificates = customIgnoreRule.getAvailableCerts(); + final ORCCertificate referenceCert = certificates.stream().findFirst().get(); + assertNotNull(referenceCert); + assertTrue(referenceCert.getWindwardLeewardSpeedPrediction().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificate.NAUTICAL_MILE).asSeconds() > 10); + assertTrue(referenceCert.getLongDistanceSpeedPredictions().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificate.NAUTICAL_MILE).asSeconds() > 10); } } diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCCertificateImporterRMS.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCCertificateImporterRMS.java index 5bf52e3b1da..57098b49463 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCCertificateImporterRMS.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCCertificateImporterRMS.java @@ -36,12 +36,6 @@ public class TestORCCertificateImporterRMS extends AbstractORCCertificateImporte assertEquals(500.0, runAllowanceAtTenKnots.asSeconds(), 0.01); } - @FailIfNoValidOrcCertificates - @Test - public void testSimpleOnlineRMSFileRead() throws IOException, ParseException, InterruptedException { - testSimpleOnlineFileRead("rms"); - } - @Test public void testLocalRMSFileReadWithIdenticalSailnumbers() throws IOException, ParseException { // additional test to ensure certificates with same sailnumbers but different ids are equally parsed and saved diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPerformanceCurve.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPerformanceCurve.java index 1ce0414824a..af6a44b3411 100644 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPerformanceCurve.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPerformanceCurve.java @@ -51,7 +51,6 @@ import com.sap.sse.common.impl.DegreeBearingImpl; * @author Daniel Lisunkin {i505543) * */ -@Ignore("Until the blacklisting of eu-west-1 by the ORC database server has been resolved... 2021-01-14") public class TestORCPerformanceCurve { private static final Logger logger = Logger.getLogger(TestORCPerformanceCurve.class.getName()); diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPublicCertificateDatabase.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPublicCertificateDatabase.java index c1d47f851b6..c8f00623666 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPublicCertificateDatabase.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPublicCertificateDatabase.java @@ -152,7 +152,6 @@ public class TestORCPublicCertificateDatabase { @FailIfNoValidOrcCertificates @Test - @Ignore("Until the blacklisting of eu-west-1 by the ORC database server has been resolved... 2021-01-14") public void testGetCertificate() throws Exception { Collection certificates = customIgnoreRule.getAvailableCerts(); final ORCCertificate cert = certificates.stream().findFirst().get(); 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 2bb00db1ae3..2129f9a7b05 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 @@ -80,7 +80,9 @@ public class ORCPublicCertificateDatabaseImpl implements ORCPublicCertificateDat private static final NameValuePair XSLP_PARAM = new BasicNameValuePair(XSLP_PARAM_NAME, XSLP_PARAM_VALUE_LIST_CERT); private static final String SEARCH_URL = "http://data.orc.org/public/WPub.dll"; private static final String COUNTRY_OVERVIEW_URL = SEARCH_URL+"/RMS"; - private static final String SINGLE_CERTIFICATE_DOWNLOAD_URL = "http://data.orc.org/public/WPub.dll?action=DownBoatRMS"; + private static final String SINGLE_CERTIFICATE_DOWNLOAD_URL = SEARCH_URL+"?action=DownBoatRMS"; + // For possible future use: to download all certificates of, e.g., a country in one go, use the following action: + // private static final String MANY_CERTIFICATES_DOWNLOAD_URL = SEARCH_URL+"?action=DownRMS"; private static final String ROOT_ELEMENT = "ROOT"; private static final String DATA_ELEMENT = "DATA"; private static final String ROW_ELEMENT = "ROW";