mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-15 06:49:56 +00:00
Merge branch 'master' into bug4811-with-bug5288
This commit is contained in:
commit
c0aed54cbc
7 files changed
+51
-75
No files matched your search
-28
@@ -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<ORCCertificate> 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);
|
||||
}
|
||||
}
|
||||
+35
-34
@@ -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<ORCCertificate> availableCerts;
|
||||
private static List<ORCCertificate> 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<CertificateHandle> certificateHandles = db.search(countryWithMostValidCertificates.getIssuingCountry(),
|
||||
countryWithMostValidCertificates.getVPPYear(), null, null, null, null, /* includeInvalid */ false);
|
||||
final List<CertificateHandle> randomSubset = new ArrayList<>();
|
||||
Util.addAll(certificateHandles, randomSubset);
|
||||
Collections.shuffle(randomSubset);
|
||||
Iterable<ORCCertificate> 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<ORCCertificate> 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<CertificateHandle> certificateHandles = db.search(countryWithMostValidCertificates.getIssuingCountry(),
|
||||
countryWithMostValidCertificates.getVPPYear(), null, null, null, null, /* includeInvalid */ false);
|
||||
final Set<CertificateHandle> firstTen = new HashSet<>();
|
||||
int i=0;
|
||||
final Iterator<CertificateHandle> certificateHandlesIterator = certificateHandles.iterator();
|
||||
while (i<10 && certificateHandlesIterator.hasNext()) {
|
||||
firstTen.add(certificateHandlesIterator.next());
|
||||
i++;
|
||||
}
|
||||
Iterable<ORCCertificate> 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!");
|
||||
}
|
||||
}
|
||||
|
||||
+13
-4
@@ -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<ORCCertificate> 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);
|
||||
}
|
||||
}
|
||||
-6
@@ -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
|
||||
|
||||
-1
@@ -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());
|
||||
|
||||
|
||||
-1
@@ -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<ORCCertificate> certificates = customIgnoreRule.getAvailableCerts();
|
||||
final ORCCertificate cert = certificates.stream().findFirst().get();
|
||||
|
||||
+3
-1
@@ -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";
|
||||
|
||||
Reference in new issue
Block a user