*
- * The {@link WithID} interface is to be implemented such that a {@link String} is produced as the ID that contains the
- * concatenation (without intermediate white space) of the {@code NatAuth}, the {@code CertNo} and the {@code BIN}
- * fields, as provided as single fields in the JSON representation, and as provided in the concatenated form in the
- * {@code NATCERTN.FILE_ID} column in the RMS format.
+ * The {@link WithID} interface is to be implemented based on the {@link #getReferenceNumber()} which is unique across the
+ * ORC world-wide certificate database. Note that the {@link #getBoatKey()} consisting of the {@link #getFileId()} and the
+ * {@link #getIssuingCountry()} field values is a unique key for the boat to which the certificate belongs.
*
*
* The certificate contains time allowances (or, conversely, speed predictions) for a combination of true wind speeds
@@ -64,13 +64,28 @@ public interface ORCCertificate extends WithID, Serializable {
Bearing[] ALLOWANCES_TRUE_WIND_ANGLES = { new DegreeBearingImpl(52), new DegreeBearingImpl(60),
new DegreeBearingImpl(75), new DegreeBearingImpl(90), new DegreeBearingImpl(110),
new DegreeBearingImpl(120), new DegreeBearingImpl(135), new DegreeBearingImpl(150) };
+
/**
- * As the ID of an ORC certificate we use the concatenation (without intermediate white space) of the
- * {@code NatAuth}, the {@code CertNo} and the {@code BIN} fields, as provided as single fields in the JSON
- * representation
+ * We use the {@link #getReferenceNumber() reference number ("RefNo")} as the ID of a certificate document.
+ * It is unique for all of ORC's certificates issued world-wide.
*/
@Override
String getId();
+
+ String getReferenceNumber();
+
+ /**
+ * Technically, at ORC a certificate's boat is identified by a "file ID" as returned by this method, together
+ * with the {@link #getIssuingCountry() issuing country} which together makes this a unique boat key. For each
+ * such boat key there is at most one valid certificate at a time.
+ */
+ String getFileId();
+
+ /**
+ * The country whose authority issued this certificate. Together with the {@link #getFileId() file ID} this makes for a
+ * unique key of the boat to which this certifiate belongs.
+ */
+ CountryCode getIssuingCountry();
/**
* Returns the sailnumber of the {@link Competitor} which this certificate belongs to.
diff --git a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/orc/impl/ORCCertificateImpl.java b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/orc/impl/ORCCertificateImpl.java
index 8f6f857b189..fbd04432a79 100755
--- a/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/orc/impl/ORCCertificateImpl.java
+++ b/java/com.sap.sailing.domain.common/src/com/sap/sailing/domain/common/orc/impl/ORCCertificateImpl.java
@@ -6,6 +6,7 @@ import java.util.Map;
import com.sap.sailing.domain.common.impl.NauticalMileDistance;
import com.sap.sailing.domain.common.orc.ORCCertificate;
import com.sap.sse.common.Bearing;
+import com.sap.sse.common.CountryCode;
import com.sap.sse.common.Distance;
import com.sap.sse.common.Duration;
import com.sap.sse.common.Speed;
@@ -24,7 +25,7 @@ import com.sap.sse.common.Util;
public class ORCCertificateImpl implements ORCCertificate {
private static final long serialVersionUID = 8725162998514202782L;
- private final String idConsistingOfNatAuthCertNoAndBIN;
+ private final String referenceNumber;
public final static Distance NAUTICAL_MILE = new NauticalMileDistance(1);
@@ -35,7 +36,9 @@ public class ORCCertificateImpl implements ORCCertificate {
private final Duration gph;
private final Double cdl;
private final TimePoint issueDate;
-
+ private final String fileId;
+ private final CountryCode issuingCountry;
+
/**
* The "core" of the certificate for performance curve scoring; the values in the map tell how fast the boat
* described by this certificate is expected to sail for the true wind speed (TWS) provided by the key, and the true
@@ -111,11 +114,13 @@ public class ORCCertificateImpl implements ORCCertificate {
* {@link ORCCertificate#ALLOWANCES_TRUE_WIND_ANGLES}.
*/
public ORCCertificateImpl(Speed[] allowancesTrueWindSpeeds, Bearing[] allowancesTrueWindAngles,
- String idConsistingOfNatAuthCertNoAndBIN, String sailnumber, String boatName, String boatClassName,
- Distance length, Duration gph, Double cdl, TimePoint issueDate,
+ String referenceNumber, String fileId, String sailnumber, String boatName,
+ String boatClassName, Distance length, Duration gph, Double cdl,
+ TimePoint issueDate, CountryCode issuingCountry,
Map> velocityPredictionsPerTrueWindSpeedAndAngle, Map beatAngles,
Map beatVMGPredictionPerTrueWindSpeed, Map beatAllowancePerTrueWindSpeed,
- Map runAngles, Map runVMGPredictionPerTrueWindSpeed,
+ Map runAngles,
+ Map runVMGPredictionPerTrueWindSpeed,
Map runAllowancePerTrueWindSpeed,
Map windwardLeewardSpeedPredictionsPerTrueWindSpeed,
Map longDistanceSpeedPredictionsPerTrueWindSpeed,
@@ -123,7 +128,9 @@ public class ORCCertificateImpl implements ORCCertificate {
Map nonSpinnakerSpeedPredictionsPerTrueWindSpeed) {
this.allowancesTrueWindAngles = allowancesTrueWindAngles;
this.allowancesTrueWindSpeeds = allowancesTrueWindSpeeds;
- this.idConsistingOfNatAuthCertNoAndBIN = idConsistingOfNatAuthCertNoAndBIN;
+ this.referenceNumber = referenceNumber;
+ this.fileId = fileId;
+ this.issuingCountry = issuingCountry;
this.sailNumber = sailnumber;
this.boatName = boatName;
this.boatClassName = boatClassName;
@@ -150,21 +157,23 @@ public class ORCCertificateImpl implements ORCCertificate {
* {@link ORCCertificate#ALLOWANCES_TRUE_WIND_ANGLES}, respectively, for the matrix of time allowances
* or, conversely, the speed predictions.
*/
- public ORCCertificateImpl(String idConsistingOfNatAuthCertNoAndBIN,
- String sailnumber, String boatName, String boatClassName,
- Distance length, Duration gph,
- Double cdl, TimePoint issueDate,
- Map> velocityPredictionsPerTrueWindSpeedAndAngle,
+ public ORCCertificateImpl(String referenceNumber,
+ String fileId, String sailnumber, String boatName,
+ String boatClassName, Distance length,
+ Duration gph, Double cdl,
+ TimePoint issueDate,
+ CountryCode issuingCountry, Map> velocityPredictionsPerTrueWindSpeedAndAngle,
Map beatAngles, Map beatVMGPredictionPerTrueWindSpeed,
- Map beatAllowancePerTrueWindSpeed, Map runAngles,
+ Map beatAllowancePerTrueWindSpeed,
+ Map runAngles,
Map runVMGPredictionPerTrueWindSpeed,
Map runAllowancePerTrueWindSpeed,
Map windwardLeewardSpeedPredictionsPerTrueWindSpeed,
Map longDistanceSpeedPredictionsPerTrueWindSpeed,
Map circularRandomSpeedPredictionsPerTrueWindSpeed,
Map nonSpinnakerSpeedPredictionsPerTrueWindSpeed) {
- this(ALLOWANCES_TRUE_WIND_SPEEDS, ALLOWANCES_TRUE_WIND_ANGLES, idConsistingOfNatAuthCertNoAndBIN, sailnumber,
- boatName, boatClassName, length, gph, cdl, issueDate, velocityPredictionsPerTrueWindSpeedAndAngle,
+ this(ALLOWANCES_TRUE_WIND_SPEEDS, ALLOWANCES_TRUE_WIND_ANGLES, referenceNumber, fileId, sailnumber, boatName,
+ boatClassName, length, gph, cdl, issueDate, issuingCountry, velocityPredictionsPerTrueWindSpeedAndAngle,
beatAngles, beatVMGPredictionPerTrueWindSpeed, beatAllowancePerTrueWindSpeed, runAngles,
runVMGPredictionPerTrueWindSpeed, runAllowancePerTrueWindSpeed,
windwardLeewardSpeedPredictionsPerTrueWindSpeed, longDistanceSpeedPredictionsPerTrueWindSpeed,
@@ -173,7 +182,22 @@ public class ORCCertificateImpl implements ORCCertificate {
@Override
public String getId() {
- return idConsistingOfNatAuthCertNoAndBIN;
+ return getReferenceNumber();
+ }
+
+ @Override
+ public String getReferenceNumber() {
+ return referenceNumber;
+ }
+
+ @Override
+ public String getFileId() {
+ return fileId;
+ }
+
+ @Override
+ public CountryCode getIssuingCountry() {
+ return issuingCountry;
}
@Override
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
new file mode 100755
index 00000000000..7038ac4cade
--- /dev/null
+++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/AbstractORCCertificateImporterTest.java
@@ -0,0 +1,56 @@
+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.sailing.domain.common.orc.impl.ORCCertificateImpl;
+import com.sap.sse.common.Util;
+
+
+public abstract class AbstractORCCertificateImporterTest {
+ protected static final String RESOURCES = "resources/orc/";
+
+ @Rule
+ public FailIfNoValidOrcCertificateRule customIgnoreRule = new FailIfNoValidOrcCertificateRule();
+
+ protected void testSimpleLocalFileRead(String fileName, String expectedCertificateId) throws IOException, ParseException {
+ File fileGER = new File(RESOURCES + fileName);
+ ORCCertificatesCollection importer = ORCCertificatesImporter.INSTANCE.read(new FileInputStream(fileGER));
+ 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(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.test/src/com/sap/sailing/domain/orc/FailIfNoValidOrcCertificateRule.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/FailIfNoValidOrcCertificateRule.java
new file mode 100644
index 00000000000..3c0ab7f42fa
--- /dev/null
+++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/FailIfNoValidOrcCertificateRule.java
@@ -0,0 +1,91 @@
+package com.sap.sailing.domain.orc;
+
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import com.sap.sailing.domain.common.orc.ORCCertificate;
+import com.sap.sailing.domain.orc.ORCPublicCertificateDatabase.CertificateHandle;
+import com.sap.sailing.domain.orc.impl.ORCPublicCertificateDatabaseImpl;
+import com.sap.sse.common.CountryCode;
+import com.sap.sse.common.CountryCodeFactory;
+
+/***
+ * A IgnoreInvalidOrcCerticatesRule is an implementation of TestRule. This class execution depends on
+ * {@link FailIfNoValidOrcCertificates} annotation on any method in a test class containing
+ * {@link org.junit.rules.TestRule} annotation with current class implementation. When any test class added
+ * {@link FailIfNoValidOrcCertificateRule} rule then before executing all of it's test method, Junit will execute the
+ * evaluate() method of {@link FailIfNoValidOrcCertificateRule} class. This method first check whether the current test
+ * method contains the {@link FailIfNoValidOrcCertificates} annotation, if yes then it will check for any certificate
+ * available to parse on ORC Website. If at least one certificate is available then this method continues execution of
+ * the current test method; otherwise it will let the test fail because the searching for certificates may be broken, or
+ * the unlikely corner case applies where temporarily at the beginning of a new calendar year no valid certificate
+ * exists at all in the ORC database.
+ *
+ * @author Usman Ali
+ *
+ */
+
+public class FailIfNoValidOrcCertificateRule implements TestRule {
+ private ORCPublicCertificateDatabase db = new ORCPublicCertificateDatabaseImpl();
+
+ private List availableCerts;
+
+ public Collection getAvailableCerts() {
+ return Collections.unmodifiableCollection(availableCerts);
+ }
+
+ @Override
+ public Statement apply(Statement base, Description description) {
+ return new IgnorableStatement(base, description);
+ }
+
+ private class IgnorableStatement extends Statement {
+ private final Statement base;
+ private final Description description;
+
+ public IgnorableStatement(Statement base, Description description) {
+ this.base = base;
+ this.description = description;
+ availableCerts = new ArrayList<>();
+ }
+
+ /***
+ * This method executes for every test case having {@link TestRule} annotation of
+ * {@link FailIfNoValidOrcCertificateRule} class. Assume statement at the end of this method evaluates whether
+ * the test method will execute or be ignored.
+ */
+ @Override
+ public void evaluate() throws Throwable {
+ boolean certificateExists = true;
+ FailIfNoValidOrcCertificates annotation = description.getAnnotation(FailIfNoValidOrcCertificates.class);
+ if (annotation != null) {
+ int year = LocalDate.now().getYear();
+ certificateExists = false;
+ for (CountryCode cc : CountryCodeFactory.INSTANCE.getAll()) {
+ try {
+ Iterable certificateHandles = db.search(cc, year, null, null, null, null, /* includeInvalid */ false);
+ Iterable orcCertificates = db.getCertificates(certificateHandles);
+ orcCertificates.forEach(availableCerts::add);
+ if (orcCertificates.iterator().hasNext()) {
+ certificateExists = true;
+ break;
+ }
+ } catch (Exception ex) {
+ // Exceptions are ignored because we are searching for any countries orc certificate's
+ // availability.
+ }
+ }
+ }
+ Assert.assertTrue(certificateExists);
+ base.evaluate();
+ }
+ }
+}
\ No newline at end of file
diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/FailIfNoValidOrcCertificates.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/FailIfNoValidOrcCertificates.java
new file mode 100644
index 00000000000..01400ab60d0
--- /dev/null
+++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/FailIfNoValidOrcCertificates.java
@@ -0,0 +1,23 @@
+package com.sap.sailing.domain.orc;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/***
+ * A IgnoreInvalidOrcCerticates is a annotation which is used to identify whether we need to execute the
+ * {@link FailIfNoValidOrcCertificateRule} for that particular test case. i.e. you can find
+ * the usage of {@link FailIfNoValidOrcCertificates} in
+ * {@link TestORCPublicCertificateDatabase} class.
+ *
+ * @author Usman Ali
+ *
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.TYPE, ElementType.METHOD })
+@Inherited
+public @interface FailIfNoValidOrcCertificates {
+
+}
\ No newline at end of file
diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/ORCPerformanceCurveRankingTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/ORCPerformanceCurveRankingTest.java
index c3b91e2c6a0..454511b92fe 100755
--- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/ORCPerformanceCurveRankingTest.java
+++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/ORCPerformanceCurveRankingTest.java
@@ -128,7 +128,7 @@ public class ORCPerformanceCurveRankingTest extends OnlineTracTracBasedTest {
final Boat boat = getTrackedRace().getRace().getBoatOfCompetitor(competitor);
ORCCertificate certificate;
if (boat.getSailID().equals("Air is blue")) {
- certificate = certificates.getCertificateById("ITA52521I5252");
+ certificate = certificates.getCertificateById("ITA00052727");
} else {
certificate = certificates.getCertificateById(boat.getSailID());
if (certificate == null) {
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 d6b290ed8b4..224447d1736 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,45 +1,21 @@
package com.sap.sailing.domain.orc;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.net.URL;
import org.json.simple.parser.ParseException;
-import org.junit.Ignore;
import org.junit.Test;
-import com.sap.sailing.domain.common.orc.ORCCertificate;
-import com.sap.sailing.domain.common.orc.impl.ORCCertificateImpl;
-
-public class TestORCCertificateImporterJSON {
- private static final String RESOURCES = "resources/orc/";
+public class TestORCCertificateImporterJSON extends AbstractORCCertificateImporterTest {
@Test
public void testSimpleLocalJSONFileRead() throws IOException, ParseException {
- File fileGER = new File(RESOURCES + "GER2019.json");
- ORCCertificatesCollection importer = ORCCertificatesImporter.INSTANCE.read(new FileInputStream(fileGER));
- ORCCertificate milan = importer.getCertificateById("GER166844GER7323");
- assertNotNull(milan);
+ testSimpleLocalFileRead("GER2019.json", "GER20041179");
}
- @Ignore("Certificate used for testing no longer valid after 2019")
+ @FailIfNoValidOrcCertificates
@Test
- public void testSimpleOnlineJSONFileRead() throws IOException, ParseException {
- ORCCertificatesCollection importer = ORCCertificatesImporter.INSTANCE.read(new URL("https://data.orc.org/public/WPub.dll?action=DownRMS&CountryId=GER&ext=json").openStream());
- ORCCertificate swan = importer.getCertificateById("GER140849GER5335");
- ORCCertificate moana = importer.getCertificateById("GER140772GER5549");
- assertNotNull(swan);
- assertNotNull(moana);
- assertEquals(539.1, swan .getGPHInSecondsToTheMile(), 0.0000001);
- assertEquals(490.4, moana.getGPHInSecondsToTheMile(), 0.0000001);
- assertEquals(862.2, swan .getWindwardLeewardSpeedPrediction().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(), 0.1);
- assertEquals(788.2, moana.getWindwardLeewardSpeedPrediction().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(), 0.1);
- assertEquals(861.0, swan .getLongDistanceSpeedPredictions().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(), 0.1);
- assertEquals(787.2, moana.getLongDistanceSpeedPredictions().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(), 0.1);
+ public void testSimpleOnlineJSONFileRead() throws IOException, ParseException, InterruptedException {
+ testSimpleOnlineFileRead("json");
}
}
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 c4f4620dcfd..6eadd5ddb2b 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
@@ -1,51 +1,32 @@
package com.sap.sailing.domain.orc;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
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.Ignore;
import org.junit.Test;
-import com.sap.sailing.domain.common.orc.ORCCertificate;
-import com.sap.sailing.domain.common.orc.impl.ORCCertificateImpl;
-
-public class TestORCCertificateImporterRMS {
+public class TestORCCertificateImporterRMS extends AbstractORCCertificateImporterTest {
private static final String RESOURCES = "resources/orc/";
-
+
@Test
public void testSimpleLocalRMSFileRead() throws IOException, ParseException {
- File fileGER = new File(RESOURCES + "GER2019.rms");
- ORCCertificatesCollection certificates = ORCCertificatesImporter.INSTANCE.read(new FileInputStream(fileGER));
- ORCCertificate milan = certificates.getCertificateById("GER166844GER7323");
- assertNotNull(milan);
+ testSimpleLocalFileRead("GER2019.rms", "GER20041179");
}
- @Ignore("Certificate used for testing no longer valid after 2019")
+ @FailIfNoValidOrcCertificates
@Test
- public void testSimpleOnlineRMSFileRead() throws IOException, ParseException {
- ORCCertificatesCollection certificates = ORCCertificatesImporter.INSTANCE.read(new URL("https://data.orc.org/public/WPub.dll?action=DownRMS&CountryId=GER&ext=rms").openStream());
- ORCCertificate swan = certificates.getCertificateById("GER140849GER5335");
- ORCCertificate moana = certificates.getCertificateById("GER140772GER5549");
- assertNotNull(swan);
- assertNotNull(moana);
- assertEquals(539.1, swan .getGPHInSecondsToTheMile(), 0.0000001);
- assertEquals(490.4, moana.getGPHInSecondsToTheMile(), 0.0000001);
- assertEquals(862.2, swan .getWindwardLeewardSpeedPrediction().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(), 0.1);
- assertEquals(788.2, moana.getWindwardLeewardSpeedPrediction().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(), 0.1);
- assertEquals(861.0, swan .getLongDistanceSpeedPredictions().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(), 0.1);
- assertEquals(787.2, moana.getLongDistanceSpeedPredictions().get(ORCCertificate.ALLOWANCES_TRUE_WIND_SPEEDS[0]).getDuration(ORCCertificateImpl.NAUTICAL_MILE).asSeconds(), 0.1);
+ 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
+ // additional test to ensure certificates with same sailnumbers but different ids are equally parsed and saved
File file = new File(RESOURCES + "multipleIdenticalSailnumbers.rms");
ORCCertificatesCollection certificates = ORCCertificatesImporter.INSTANCE.read(new FileInputStream(file));
assertEquals(14, ((Collection>) (certificates.getCertificateIds())).size());
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 636fc8c0e63..0a40971425b 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
@@ -17,7 +17,6 @@ import org.apache.commons.math.MaxIterationsExceededException;
import org.json.simple.parser.ParseException;
import org.junit.Assert;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
@@ -46,7 +45,6 @@ import com.sap.sse.common.impl.DegreeBearingImpl;
*
*/
public class TestORCPerformanceCurve {
-
// set true to see all the differences i
private final boolean collectErrors = true;
@@ -56,6 +54,9 @@ public class TestORCPerformanceCurve {
private static ORCCertificatesCollection importerOnline;
private static final String RESOURCES = "resources/orc/";
+
+ @Rule
+ public FailIfNoValidOrcCertificateRule customFailRule = new FailIfNoValidOrcCertificateRule();
@Rule
public ErrorCollector collector = new ErrorCollector();
@@ -97,36 +98,36 @@ public class TestORCPerformanceCurve {
File fileWithSpecificBins = new File(RESOURCES + "newFormatCertificate.json");
importerWithSpecificBins = new ORCCertificatesJsonImporter().read(new FileInputStream(fileWithSpecificBins));
// Online File:
- importerOnline = new ORCCertificatesJsonImporter().read(new URL("https://data.orc.org/public/WPub.dll?action=DownRMS&CountryId=GER&ext=json").openStream());
+ importerOnline = new ORCCertificatesJsonImporter().read(new URL("https://data.orc.org/public/WPub.dll?action=DownBoatRMS&CountryId=GER&ext=json").openStream());
}
@Test
public void testLagrangeInterpolation60() throws FunctionEvaluationException {
- ORCCertificate certificate = importerLocal.getCertificateById("GER140772GER5549");
+ ORCCertificate certificate = importerLocal.getCertificateById("GER20040783");
testAllowancePerLeg(certificate, 60.0, 498.4);
}
@Test
public void testLagrangeInterpolation62_5() throws FunctionEvaluationException {
- ORCCertificate certificate = importerLocal.getCertificateById("GER140772GER5549");
+ ORCCertificate certificate = importerLocal.getCertificateById("GER20040783");
testAllowancePerLeg(certificate, 62.5, 492.2, 425.0, 403.6, 393.1, 386.7, 382.6, 371.4);
}
@Test
public void testLagrangeInterpolation98_3() throws FunctionEvaluationException {
- ORCCertificate certificate = importerLocal.getCertificateById("GER140772GER5549");
+ ORCCertificate certificate = importerLocal.getCertificateById("GER20040783");
testAllowancePerLeg(certificate, 98.3, 483.6, 418.7, 394.8, 377.9, 360.2, 345.0, 321.7);
}
@Test
public void testLagrangeInterpolation120() throws FunctionEvaluationException {
- ORCCertificate certificate = importerLocal.getCertificateById("GER140772GER5549");
+ ORCCertificate certificate = importerLocal.getCertificateById("GER20040783");
testAllowancePerLeg(certificate, 120.0, 506);
}
@Test
public void testLagrangeInterpolation138_7() throws FunctionEvaluationException {
- ORCCertificate certificate = importerLocal.getCertificateById("GER140772GER5549");
+ ORCCertificate certificate = importerLocal.getCertificateById("GER20040783");
testAllowancePerLeg(certificate, 138.7, 588.1, 468.4, 413.8, 382.6, 355.1, 326.4, 275.4);
}
@@ -141,7 +142,7 @@ public class TestORCPerformanceCurve {
@Test
public void testSimpleConstructedCourse() throws FunctionEvaluationException {
- ORCCertificate certificate = (ORCCertificate) importerLocal.getCertificateById("GER140772GER5549");
+ ORCCertificate certificate = (ORCCertificate) importerLocal.getCertificateById("GER20040783");
List legs = new ArrayList<>();
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(1.0), new DegreeBearingImpl(0)));
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(1.0), new DegreeBearingImpl(30)));
@@ -164,7 +165,7 @@ public class TestORCPerformanceCurve {
@Test
public void testPerformanceCurveInversion() throws MaxIterationsExceededException, FunctionEvaluationException {
Double accuracy = 0.1;
- ORCCertificate certificate = (ORCCertificate) importerLocal.getCertificateById("GER140772GER5549");
+ ORCCertificate certificate = (ORCCertificate) importerLocal.getCertificateById("GER20040783");
ORCPerformanceCurveImpl performanceCurve = (ORCPerformanceCurveImpl) new ORCPerformanceCurveImpl(certificate, alturaCourse);
testBackwardForward(accuracy, performanceCurve, 11.5);
testBackwardForward(accuracy, performanceCurve, 17.23);
@@ -193,12 +194,12 @@ public class TestORCPerformanceCurve {
@Test
public void testImpliedWind() throws MaxIterationsExceededException, FunctionEvaluationException {
double accuracy = 0.0001;
- ORCCertificate certificateMoana = importerLocal.getCertificateById("GER140772GER5549");
- ORCCertificate certificateMilan = importerLocal.getCertificateById("GER166844GER7323");
- ORCCertificate certificateTutima = importerLocal.getCertificateById("GER140618GER5609");
- ORCCertificate certificateBank = importerLocal.getCertificateById("GER140755GER5555");
- ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER141411GER6300");
- ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER141432GER5564");
+ ORCCertificate certificateMoana = importerLocal.getCertificateById("GER20040783");
+ ORCCertificate certificateMilan = importerLocal.getCertificateById("GER20041179");
+ ORCCertificate certificateTutima = importerLocal.getCertificateById("GER30010194");
+ ORCCertificate certificateBank = importerLocal.getCertificateById("GER20040647");
+ ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER30010167");
+ ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER20040632");
ORCPerformanceCurve performanceCurveMoana = new ORCPerformanceCurveImpl(certificateMoana, alturaCourse);
ORCPerformanceCurve performanceCurveMilan = new ORCPerformanceCurveImpl(certificateMilan, alturaCourse);
ORCPerformanceCurve performanceCurveTutima = new ORCPerformanceCurveImpl(certificateTutima, alturaCourse);
@@ -230,12 +231,12 @@ public class TestORCPerformanceCurve {
@Test
public void testAllowances() throws FunctionEvaluationException {
double accuracy = 0.00001;
- ORCCertificate certificateMoana = importerLocal.getCertificateById("GER140772GER5549");
- ORCCertificate certificateMilan = importerLocal.getCertificateById("GER166844GER7323");
- ORCCertificate certificateTutima = importerLocal.getCertificateById("GER140618GER5609");
- ORCCertificate certificateBank = importerLocal.getCertificateById("GER140755GER5555");
- ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER141411GER6300");
- ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER141432GER5564");
+ ORCCertificate certificateMoana = importerLocal.getCertificateById("GER20040783");
+ ORCCertificate certificateMilan = importerLocal.getCertificateById("GER20041179");
+ ORCCertificate certificateTutima = importerLocal.getCertificateById("GER30010194");
+ ORCCertificate certificateBank = importerLocal.getCertificateById("GER20040647");
+ ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER30010167");
+ ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER20040632");
ORCPerformanceCurve performanceCurveMoana = new ORCPerformanceCurveImpl(certificateMoana, alturaCourse);
ORCPerformanceCurve performanceCurveMilan = new ORCPerformanceCurveImpl(certificateMilan, alturaCourse);
ORCPerformanceCurve performanceCurveTutima = new ORCPerformanceCurveImpl(certificateTutima, alturaCourse);
@@ -253,7 +254,7 @@ public class TestORCPerformanceCurve {
/**
* Tests to make sure, that the structure of the certificate files didn't change and performance curves can be built
*/
- @Ignore("Certificate used for testing no longer valid after 2019")
+ @FailIfNoValidOrcCertificates
@Test
public void testOnlineImport() throws FunctionEvaluationException {
assertFalse(Util.isEmpty(importerOnline.getCertificateIds()));
@@ -267,7 +268,7 @@ public class TestORCPerformanceCurve {
final double highAccuracy = 0.01;
final double allowanceAccuracy = 0.1;
final Distance ONE_NAUTICAL_MILE = new NauticalMileDistance(1.0);
- final ORCCertificate certificateWithSpecificBins = importerWithSpecificBins.getCertificateById("GRA00073GR317");
+ final ORCCertificate certificateWithSpecificBins = importerWithSpecificBins.getCertificateById("N/A");
for (final Bearing twa : certificateWithSpecificBins.getTrueWindAngles()) {
final ORCPerformanceCurveCourse singleLegOneMileCourseWithTwa = createSingleLegCourseWithTwa(twa);
final ORCPerformanceCurve performanceCurveSpecificBins = new ORCPerformanceCurveImpl(certificateWithSpecificBins, singleLegOneMileCourseWithTwa);
@@ -298,13 +299,13 @@ public class TestORCPerformanceCurve {
ORCPerformanceCurveCourse complexCourse = new ORCPerformanceCurveCourseImpl(list);
final double accuracy = 0.0001;
- ORCCertificate certificateMoana = importerLocal.getCertificateById("GER140772GER5549");
- ORCCertificate certificateMilan = importerLocal.getCertificateById("GER166844GER7323");
- ORCCertificate certificateTutima = importerLocal.getCertificateById("GER140618GER5609");
- ORCCertificate certificateBank = importerLocal.getCertificateById("GER140755GER5555");
- ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER141411GER6300");
- ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER141432GER5564");
- ORCCertificate certificateWithSpecificBins=importerWithSpecificBins.getCertificateById("GRA00073GR317");
+ ORCCertificate certificateMoana = importerLocal.getCertificateById("GER20040783");
+ ORCCertificate certificateMilan = importerLocal.getCertificateById("GER20041179");
+ ORCCertificate certificateTutima = importerLocal.getCertificateById("GER30010194");
+ ORCCertificate certificateBank = importerLocal.getCertificateById("GER20040647");
+ ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER30010167");
+ ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER20040632");
+ ORCCertificate certificateWithSpecificBins=importerWithSpecificBins.getCertificateById("N/A");
ORCPerformanceCurve performanceCurveMoana = new ORCPerformanceCurveImpl(certificateMoana, complexCourse);
ORCPerformanceCurve performanceCurveMilan = new ORCPerformanceCurveImpl(certificateMilan, complexCourse);
ORCPerformanceCurve performanceCurveTutima = new ORCPerformanceCurveImpl(certificateTutima, complexCourse);
@@ -333,13 +334,13 @@ public class TestORCPerformanceCurve {
ORCPerformanceCurveCourse complexCourse = new ORCPerformanceCurveCourseImpl(list);
double accuracy = 0.00001;
- ORCCertificate certificateMoana = importerLocal.getCertificateById("GER140772GER5549");
- ORCCertificate certificateMilan = importerLocal.getCertificateById("GER166844GER7323");
- ORCCertificate certificateTutima = importerLocal.getCertificateById("GER140618GER5609");
- ORCCertificate certificateBank = importerLocal.getCertificateById("GER140755GER5555");
- ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER141411GER6300");
- ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER141432GER5564");
- ORCCertificate certificateWithSpecificBins=importerWithSpecificBins.getCertificateById("GRA00073GR317");
+ ORCCertificate certificateMoana = importerLocal.getCertificateById("GER20040783");
+ ORCCertificate certificateMilan = importerLocal.getCertificateById("GER20041179");
+ ORCCertificate certificateTutima = importerLocal.getCertificateById("GER30010194");
+ ORCCertificate certificateBank = importerLocal.getCertificateById("GER20040647");
+ ORCCertificate certificateHaspa = importerLocal.getCertificateById("GER30010167");
+ ORCCertificate certificateHalbtrocken = importerLocal.getCertificateById("GER20040632");
+ ORCCertificate certificateWithSpecificBins=importerWithSpecificBins.getCertificateById("N/A");
ORCPerformanceCurve performanceCurveMoana = new ORCPerformanceCurveImpl(certificateMoana, complexCourse);
ORCPerformanceCurve performanceCurveMilan = new ORCPerformanceCurveImpl(certificateMilan, complexCourse);
ORCPerformanceCurve performanceCurveTutima = new ORCPerformanceCurveImpl(certificateTutima, complexCourse);
diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPerformanceCurveCourse.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPerformanceCurveCourse.java
index d79d62eb7c8..6bb1d30f9ac 100644
--- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPerformanceCurveCourse.java
+++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/orc/TestORCPerformanceCurveCourse.java
@@ -25,7 +25,6 @@ import com.sap.sse.common.Util;
import com.sap.sse.common.impl.DegreeBearingImpl;
public class TestORCPerformanceCurveCourse {
-
@Test
public void testSubcourseOfSimpleORCCourse() {
double accuracy = 0.000000001;
@@ -36,23 +35,18 @@ public class TestORCPerformanceCurveCourse {
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(1), new DegreeBearingImpl(180)));
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(1), new DegreeBearingImpl(0)));
ORCPerformanceCurveCourse course = new ORCPerformanceCurveCourseImpl(legs);
-
// case 0: no leg finished, 40.0% of current leg
ORCPerformanceCurveCourse subcourse0 = course.subcourse(0, 0.4);
assertEquals(0.4, subcourse0.getTotalLength().getNauticalMiles(), accuracy);
-
// case 1: first leg finished, 0.0% of current leg
ORCPerformanceCurveCourse subcourse1 = course.subcourse(1, 0);
assertEquals(1, subcourse1.getTotalLength().getNauticalMiles(), accuracy);
-
// case 2: first leg finished, 12.5% of current leg
ORCPerformanceCurveCourse subcourse2 = course.subcourse(1, 0.125);
assertEquals(1.125, subcourse2.getTotalLength().getNauticalMiles(), accuracy);
-
// special case: didn't start, equals to no legs finished and 0.0% of current leg
ORCPerformanceCurveCourse subcourseSpecial1 = course.subcourse(0, 0);
assertEquals(0, subcourseSpecial1.getTotalLength().getNauticalMiles(), accuracy);
-
// special case: number of finished legs is higher then number of actual legs
ORCPerformanceCurveCourse subcourseSpecial2 = course.subcourse(10,0);
assertEquals(5, subcourseSpecial2.getTotalLength().getNauticalMiles(), accuracy);
@@ -68,23 +62,18 @@ public class TestORCPerformanceCurveCourse {
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(10.23), new DegreeBearingImpl(180)));
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(2.57), new DegreeBearingImpl(0)));
ORCPerformanceCurveCourse course = new ORCPerformanceCurveCourseImpl(legs);
-
// case 0: no leg finished, 40.0% of current leg
ORCPerformanceCurveCourse subcourse0 = course.subcourse(0, 0.4);
assertEquals(1.512, subcourse0.getTotalLength().getNauticalMiles(), accuracy);
-
// case 1: first leg finished, 0.0% of current leg
ORCPerformanceCurveCourse subcourse1 = course.subcourse(1, 0);
assertEquals(3.78, subcourse1.getTotalLength().getNauticalMiles(), accuracy);
-
// case 2: first leg finished, 12.5% of current leg
ORCPerformanceCurveCourse subcourse2 = course.subcourse(1, 0.125);
assertEquals(3.96125, subcourse2.getTotalLength().getNauticalMiles(), accuracy);
-
// special case: didn't start, equals to no legs finished and 0.0% of current leg
ORCPerformanceCurveCourse subcourseSpecial1 = course.subcourse(0, 0);
assertEquals(0, subcourseSpecial1.getTotalLength().getNauticalMiles(), accuracy);
-
// special case: number of finished legs is higher then number of actual legs
ORCPerformanceCurveCourse subcourseSpecial2 = course.subcourse(10,0);
assertEquals(23.03, subcourseSpecial2.getTotalLength().getNauticalMiles(), accuracy);
@@ -99,26 +88,21 @@ public class TestORCPerformanceCurveCourse {
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(3), ORCPerformanceCurveLegTypes.CIRCULAR_RANDOM));
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(4), new DegreeBearingImpl(0)));
ORCPerformanceCurveCourse course = new ORCPerformanceCurveCourseImpl(legs);
-
// case 0: no leg finished, 40.0% of current leg
ORCPerformanceCurveCourse subcourse0 = course.subcourse(0, 0.4);
assertEquals(0.4, subcourse0.getTotalLength().getNauticalMiles(), accuracy);
-
// case 1: first leg finished, 0.0% of current leg
ORCPerformanceCurveCourse subcourse1 = course.subcourse(1, 0);
assertEquals(1, subcourse1.getTotalLength().getNauticalMiles(), accuracy);
-
// case 2: first leg finished, 12.5% of current leg
ORCPerformanceCurveCourse subcourse2 = course.subcourse(1, 0.125);
assertEquals(1.25, subcourse2.getTotalLength().getNauticalMiles(), accuracy);
assertEquals(ORCPerformanceCurveLegTypes.LONG_DISTANCE, Util.last(subcourse2.getLegs()).getType());
assertEquals(0, subcourse2.getLegs().iterator().next().getTwa().getDegrees(), accuracy);
-
// special case: didn't start, equals to no legs finished and 0.0% of current leg
ORCPerformanceCurveCourse subcourseSpecial1 = course.subcourse(0, 0);
assertEquals(0, subcourseSpecial1.getTotalLength().getNauticalMiles(), accuracy);
assertEquals(1, Util.size(subcourseSpecial1.getLegs()));
-
// special case: number of finished legs is higher then number of actual legs
ORCPerformanceCurveCourse subcourseSpecial2 = course.subcourse(10, 0);
assertEquals(10, subcourseSpecial2.getTotalLength().getNauticalMiles(), accuracy);
@@ -135,11 +119,9 @@ public class TestORCPerformanceCurveCourse {
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(1), new DegreeBearingImpl(0)));
legs.add(new ORCPerformanceCurveLegImpl(new NauticalMileDistance(2), new DegreeBearingImpl(0)));
ORCPerformanceCurveCourse course = new ORCPerformanceCurveCourseImpl(legs);
-
// case 0: no leg finished, 40.0% of current leg
ORCPerformanceCurveCourse subcourse0 = course.subcourse(0, 0.4);
assertEquals(0.4, subcourse0.getTotalLength().getNauticalMiles(), accuracy);
-
// case 1: first leg finished, 0.0% of current leg
ORCPerformanceCurveCourse subcourse1 = subcourse0.subcourse(0, 0.1);
assertEquals(0.04, subcourse1.getTotalLength().getNauticalMiles(), accuracy);
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 78f2d0bdec0..4290490fe5f 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
@@ -2,33 +2,93 @@ package com.sap.sailing.domain.orc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import java.util.Set;
-import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
+import java.util.logging.Logger;
+import org.junit.Assert;
import org.junit.Before;
-import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import com.sap.sailing.domain.base.impl.BoatClassImpl;
-import com.sap.sailing.domain.common.BoatClassMasterdata;
import com.sap.sailing.domain.common.orc.ORCCertificate;
import com.sap.sailing.domain.orc.ORCPublicCertificateDatabase.CertificateHandle;
import com.sap.sailing.domain.orc.impl.ORCPublicCertificateDatabaseImpl;
import com.sap.sse.common.Util;
public class TestORCPublicCertificateDatabase {
+ private static final Logger logger = Logger.getLogger(TestORCPublicCertificateDatabase.class.getName());
+
private ORCPublicCertificateDatabase db;
+ private Map dateComparisonMap = new LinkedHashMap();
+ private List dateFailureCases = Arrays.asList("2019-02-21T10:44GMT+2","2019-02-21T10:38+0800","2019-02-21T10:38+08:00",
+ "2019-02-21T10:38-08","2019-02-21T10:38Z","2019-02-21T10z","2019-02-21T10:38z");
+
+ @Rule
+ public FailIfNoValidOrcCertificateRule customIgnoreRule = new FailIfNoValidOrcCertificateRule();
@Before
public void setUp() {
db = new ORCPublicCertificateDatabaseImpl();
+ /**
+ * By default GregorianCalendar month starts from 0 as January and so on. In below cases 1 specifies the date
+ * month as February.
+ */
+ dateComparisonMap.put("2019-02-21T10:38:59Z", Date.from(ZonedDateTime.parse("2019-02-21T10:38:59Z").toInstant()));
+ // dateComparisonMap.put("2019-02-21T12:00:00.000GMT+2", Date.from(ZonedDateTime.of(2019, 2, 21, 10, 38, 59, 0, ZoneId.systemDefault()).toInstant()));
+ // // dateComparisonMap.put("2019-02-21T15:00:00.000 GMT-2", Date.from(ZonedDateTime.of(2019, 2, 21, 10, 38, 59, 0, ZoneId.systemDefault()).toInstant()));
+ dateComparisonMap.put("2019-02-21T10:38:55.000-0800",
+ Date.from(ZonedDateTime.parse("2019-02-21T10:38:55.000-0800", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")).toInstant())
+ );
+ dateComparisonMap.put(
+ "2019-02-21T10:38:32.000+08:00",
+ Date.from(ZonedDateTime.parse("2019-02-21T10:38:32.000+08:00").toInstant())
+ );
+ dateComparisonMap.put(
+ "2019-02-21T10:38:09.000-06",
+ Date.from(ZonedDateTime.parse("2019-02-21T10:38:09.000-06", DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSx")).toInstant())
+ );
+ dateComparisonMap.put(
+ "2019-02-21T10:38:22.000Z",
+ Date.from(ZonedDateTime.parse("2019-02-21T10:38:22.000Z").toInstant())
+ );
+ dateComparisonMap.put(
+ "2019-02-21T10:38:00.000z",
+ Date.from(ZonedDateTime.parse("2019-02-21T10:38:00.000z").toInstant())
+ );
+ dateComparisonMap.put(
+ "2019-02-21T10:38:46z",
+ Date.from(ZonedDateTime.parse("2019-02-21T10:38:46z").toInstant())
+ );
+ dateComparisonMap.put(
+ "2019-02-21T10:38:17",
+ Date.from(LocalDateTime.parse("2019-02-21T10:38:17").toInstant(ZoneOffset.UTC))
+ );
+ dateComparisonMap.put(
+ "2019-02-21T10:38:33.000",
+ Date.from(LocalDateTime.parse("2019-02-21T10:38:33.000").toInstant(ZoneOffset.UTC))
+ );
}
@Test
@@ -36,7 +96,7 @@ public class TestORCPublicCertificateDatabase {
final String referenceNumber = "FRA00013881";
final Iterable result = db.search(/* country */ null, /* yearOfIssuance */ null,
/* referenceNumber */ referenceNumber, /* yachtName */ null, /* sailNumber */ null,
- /* boatClassName */ null);
+ /* boatClassName */ null, /* includeInvalid */ true);
assertEquals(1, Util.size(result));
assertSoulmate(referenceNumber, result.iterator().next());
}
@@ -46,7 +106,7 @@ public class TestORCPublicCertificateDatabase {
final String referenceNumber = "FRA00013881";
final Iterable result = db.search(/* country */ null, /* yearOfIssuance */ 2019,
/* referenceNumber */ null, /* yachtName */ "Soulmate", /* sailNumber */ "DEN- 13",
- /* boatClassName */ null);
+ /* boatClassName */ null, /* includeInvalid */ true);
assertEquals(1, Util.size(result));
assertSoulmate(referenceNumber, result.iterator().next());
}
@@ -56,7 +116,7 @@ public class TestORCPublicCertificateDatabase {
final String referenceNumber = "FRA00013881";
final Iterable result = db.search(/* country */ null, /* yearOfIssuance */ null,
/* referenceNumber */ null, /* yachtName */ "Soulmate", /* sailNumber */ null,
- /* boatClassName */ null);
+ /* boatClassName */ null, /* includeInvalid */ true);
assertTrue(Util.size(result)>1);
boolean found = false;
for (final CertificateHandle handle : result) {
@@ -75,42 +135,86 @@ public class TestORCPublicCertificateDatabase {
assertSoulmate(referenceNumber, result);
}
- // TODO this test will probably break 2021 when 2020 certificates will no longer be returned as valid...
@Test
- public void testGetCertificate() throws Exception {
- final String referenceNumber = "03360000CE8";
+ public void testCertificateUpdate() throws Exception {
+ final String referenceNumber = "FRA00013881";
+ final CertificateHandle oldHandle = db.getCertificateHandle(referenceNumber);
+ final ORCCertificate result = db.searchForUpdate(oldHandle);
+ if (result != null) {
+ assertEquals(oldHandle.getFileId(), result.getFileId());
+ assertEquals(oldHandle.getIssuingCountry(), result.getIssuingCountry());
+ assertFalse(oldHandle.getIssueDate().after(result.getIssueDate()));
+ } else {
+ logger.warning("Couldn't find an update to certificate with reference number "+referenceNumber+
+ " anymore. Consider updating this test case to using a different certificate that still has a valid update.");
+ }
+ }
+
+ @FailIfNoValidOrcCertificates
+ @Test
+ public void testGetCertificate() throws Exception {
+ Collection certificates = customIgnoreRule.getAvailableCerts();
+ final ORCCertificate cert = certificates.stream().findFirst().get();
+ Iterable certHandles = db.search(null, LocalDate.now().getYear(), null, cert.getBoatName(),
+ cert.getSailNumber(), /*
+ * boat class name; could be set to cert.getBoatClassName() but there are
+ * deviations in ORC DBs and query API, so leaving null:
+ */ null, /* includeInvalid */ false);
+ Optional certificateHandle = Optional.ofNullable(certHandles.iterator().hasNext() ? certHandles.iterator().next() : null);
+ assertTrue("No certificate found for handle "+certificateHandle+
+ " extracted from certificates "+certificates, certificateHandle.isPresent());
+ final String referenceNumber = certificateHandle.get().getReferenceNumber();
final CertificateHandle handle = db.getCertificateHandle(referenceNumber);
final ORCCertificate result = db.getCertificate(referenceNumber);
+ assertNotNull("Unable to load certificate for reference number "+referenceNumber+" from handle "+certificateHandle);
assertEquals(handle.getGPH(), result.getGPH().asSeconds(), 0.00001);
- assertTrue(handle.getIssueDate().until(result.getIssueDate()).abs().asSeconds() < 10);
+ // Use some tolerance as we found differences as much as 5s between the dxtDate in the handle coming from the XML search result
+ // and the IssueDate field in the JSON. Both suggest to report millisecond accuracy, but dxtDate always seems to have the
+ // milliseconds as "000" explaining many sub-second differences. But in some cases differences were significantly bigger.
+ assertEquals("Issue dates of certificate with reference number "+referenceNumber+
+ " varies between current year result handle ("+handle.getIssueDate()+") and certificate ("+
+ result.getIssueDate()+").", handle.getIssueDate().asMillis(), result.getIssueDate().asMillis(), 10000.0);
assertEquals(handle.getSailNumber(), result.getSailNumber());
}
- @Ignore("Certificate used for testing no longer valid after 2019")
+ @FailIfNoValidOrcCertificates
@Test
public void testParallelFuzzySearch() throws InterruptedException, ExecutionException {
- final Future> soulmateCertificatesFuture = db.search("Soulmate", "DEN13", new BoatClassImpl("ORC", BoatClassMasterdata.ORC));
- final Future> amarettoCertificatesFuture = db.search("Amaretto", "NED 6101", new BoatClassImpl("Beneteau First 40.7", /* starts upwind */ true));
- final Set soulmateCertificates = soulmateCertificatesFuture.get();
- final Set amarettoCertificates = amarettoCertificatesFuture.get();
- assertFoundYear(soulmateCertificates, 2019);
- assertFoundYear(amarettoCertificates, 2019);
+ int year = LocalDate.now().getYear();
+ ArrayList>> futures = new ArrayList>>();
+ boolean isYearFound = false;
+ for (ORCCertificate orcCertificate : customIgnoreRule.getAvailableCerts()) {
+ futures.add(db.search(orcCertificate.getBoatName(), orcCertificate.getSailNumber(),
+ new BoatClassImpl(orcCertificate.getBoatClassName(), true)));
+ }
+ for (Future> futureResult : futures) {
+ isYearFound = isYearFound || assertFoundYear(futureResult.get(), year);
+ }
+ assertTrue(isYearFound);
+ }
+
+ @Test
+ public void testParseDateSuccessCases() {
+ for (String date : dateComparisonMap.keySet()) {
+ Date convertedDate = db.parseDate(date);
+ assertEquals(convertedDate, dateComparisonMap.get(date));
+ }
+ }
+
+ @Test(expected = DateTimeParseException.class)
+ public void testShould() throws Exception {
+ for (String dateString : dateFailureCases) {
+ db.parseDate(dateString);
+ Assert.fail(dateString + " is parsable");
+ }
}
- private void assertFoundYear(final Set certificates, int year) {
- boolean foundYear = false;
- for (final ORCCertificate certificate : certificates) {
- if (certificate.getIssueDate() != null) {
- final GregorianCalendar cal = new GregorianCalendar();
- cal.setTimeZone(TimeZone.getTimeZone("UTC"));
- cal.setTimeInMillis(certificate.getIssueDate().asMillis());
- if (cal.get(Calendar.YEAR) == year) {
- foundYear = true;
- break;
- }
- }
- }
- assertTrue(foundYear);
+ private boolean assertFoundYear(final Set certificates, int year) {
+ return certificates.stream().map(cert -> {
+ LocalDate certDate = Instant.ofEpochMilli(cert.getIssueDate().asMillis()).atOffset(ZoneOffset.UTC)
+ .toLocalDate();
+ return certDate.getYear();
+ }).anyMatch(cy -> cy == year);
}
private void assertSoulmate(final String referenceNumber, CertificateHandle handle) {
diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/ORCPublicCertificateDatabase.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/ORCPublicCertificateDatabase.java
index dd717b8b94e..cc77e5fde0a 100755
--- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/ORCPublicCertificateDatabase.java
+++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/ORCPublicCertificateDatabase.java
@@ -1,6 +1,8 @@
package com.sap.sailing.domain.orc;
+import java.time.format.DateTimeParseException;
import java.util.Arrays;
+import java.util.Date;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Future;
@@ -15,8 +17,14 @@ import com.sap.sse.common.Util;
/**
* An interface to {@code data.orc.org}, mostly the search functionality at
* {@code https://data.orc.org/public/WPub.dll?action=SrchCert&xslp=scert.php}. It can search for certificates by a
- * number of criteria, among them the issuing country, sail number, ORC reference number, or boat name.
- * <p>
+ * number of criteria, among them the issuing country, sail number, ORC reference number, or boat name. Those search
+ * results are represented as {@link CertificateHandle} objects. Such handles can also be obtained for certificates that
+ * are not currently valid. See the {@code includeInvalid} parameter of the
+ * {@link #search(CountryCode, Integer, String, String, String, String, boolean)} method. However, handles for
+ * {@link CertificateHandle#isValid() invalid} certificates cannot be resolved into {@link ORCCertificate} objects
+ * through {@link #getCertificates(Iterable)} or {@link #getCertificates(CertificateHandle...)} because the database
+ * returns full certificates only if they are valid.
+ *
*
* As the web site emits XML documents as search results, those can be parsed and turned into handles to certificates.
* An example output (excerpt):
@@ -78,8 +86,8 @@ import com.sap.sse.common.Util;
</DATA>
*
*
- * This also shows that some query results do not provide a valid link to a downloadable copy of the certificate. Those are
- * automatically removed from the results here.
+ * This also shows that some query results do not provide a valid link to a downloadable copy of the certificate. Those
+ * are automatically removed from the results here.
*
* @author Axel Uhl (D043530)
*
@@ -95,6 +103,7 @@ public interface ORCPublicCertificateDatabase {
*/
public interface CertificateHandle {
CountryCode getIssuingCountry();
+ String getFileId();
Double getGPH();
String getSSSID();
UUID getDatInGID();
@@ -109,6 +118,7 @@ public interface ORCPublicCertificateDatabase {
Integer getCertType();
Boolean isOd();
Boolean isProvisional();
+ Boolean isValid();
}
/**
@@ -117,10 +127,18 @@ public interface ORCPublicCertificateDatabase {
* {@code boatClassName} parameters.
*
*
- * @return an always valid, never {@code null} object which may be {@link Util#isEmpty() empty}.
+ * @param includeInvalid
+ * If {@code true}, handles may have {@link CertificateHandle#isValid()}{@code == false}, meaning that
+ * such a handle cannot be resolved to a {@link ORCCertificate} using any of
+ * {@link #getCertificate(String)}, {@link #getCertificates(Iterable)} and
+ * {@link #getCertificates(CertificateHandle...)}. If {@code false}, only valid certificate handles
+ * will be returned that should all be resolvable into an {@link ORCCertificate} with any of the methods
+ * listed above.
+ *
+ * @return never {@code null}; an object which may be {@link Util#isEmpty() empty}.
*/
Iterable search(CountryCode country, Integer yearOfIssuance, String referenceNumber,
- String yachtName, String sailNumber, String boatClassName) throws Exception;
+ String yachtName, String sailNumber, String boatClassName, boolean includeInvalid) throws Exception;
default Iterable getCertificates(Iterable handles) throws Exception {
return Util.map(handles, handle->{
@@ -137,9 +155,13 @@ public interface ORCPublicCertificateDatabase {
}
default CertificateHandle getCertificateHandle(String referenceNumber) throws Exception {
- return search(null, null, referenceNumber, null, null, null).iterator().next();
+ return search(null, null, referenceNumber, null, null, null, /* includeInvalid */ true).iterator().next();
}
+ ORCCertificate searchForUpdate(ORCCertificate certificate) throws Exception;
+
+ ORCCertificate searchForUpdate(CertificateHandle certificate) throws Exception;
+
ORCCertificate getCertificate(String referenceNumber) throws Exception;
/**
@@ -166,4 +188,6 @@ public interface ORCPublicCertificateDatabase {
* parameters.
*/
Future> search(String yachtName, String sailNumber, BoatClass boatClass);
+
+ Date parseDate(final String dateString) throws DateTimeParseException;
}
diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/AbstractORCCertificatesCollection.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/AbstractORCCertificatesCollection.java
index 55036c0e5c0..0b55f443368 100755
--- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/AbstractORCCertificatesCollection.java
+++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/AbstractORCCertificatesCollection.java
@@ -24,6 +24,10 @@ public abstract class AbstractORCCertificatesCollection implements ORCCertificat
}
return null;
}
+
+ protected String canonicalizeId(String certificateId) {
+ return certificateId.replaceAll(" ", "").replaceAll("\t", "");
+ }
@Override
public Iterable getCertificates() {
diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCCertificatesCollectionJSON.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCCertificatesCollectionJSON.java
index 800fb6cd15c..cb6422916b4 100755
--- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCCertificatesCollectionJSON.java
+++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/orc/impl/ORCCertificatesCollectionJSON.java
@@ -21,6 +21,7 @@ import com.sap.sailing.domain.common.impl.MeterDistance;
import com.sap.sailing.domain.common.orc.ORCCertificate;
import com.sap.sailing.domain.common.orc.impl.ORCCertificateImpl;
import com.sap.sse.common.Bearing;
+import com.sap.sse.common.CountryCodeFactory;
import com.sap.sse.common.Distance;
import com.sap.sse.common.Duration;
import com.sap.sse.common.Speed;
@@ -52,16 +53,15 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
private static final String YACHT_NAME = "YachtName";
private static final String LOA = "LOA";
private static final String SAIL_NO = "SailNo";
- private static final String CERT_NO = "CertNo";
private static final String BIN = "BIN";
private static final String NAT_AUTH = "NatAuth";
+ private static final String REFERENCE_NUMBER = "RefNo";
private static final String RUN = "Run";
private static final String BEAT = "Beat";
private static final String WINDWARD_LEEWARD = "WL";
private static final String LONG_DISTANCE = "OC";
private static final String CIRCULAR_RANDOM = "CR";
private static final String NON_SPINNAKER = "NS";
- private static final String EMPTY_CERT_NO = " ";
private static final String WIND_SPEEDS = "WindSpeeds";
/**
@@ -70,6 +70,9 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
*/
private static final Pattern twaPattern = Pattern.compile("R(\\d+(\\.\\d+)?)");
+ /**
+ * Keys are canonicalized through {@link #canonicalizeId(String)}).
+ */
private Map certificateJsonObjectsByCertificateId;
/**
@@ -79,7 +82,7 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
public ORCCertificatesCollectionJSON(Iterable data) {
this.certificateJsonObjectsByCertificateId = new HashMap<>();
for (final JSONObject o : data) {
- if (this.certificateJsonObjectsByCertificateId.put(getId(o), o) != null) {
+ if (this.certificateJsonObjectsByCertificateId.put(canonicalizeId(getId(o)), o) != null) {
throw new IllegalArgumentException("Certificate ID in collection not unique: " + getId(o));
}
}
@@ -88,9 +91,17 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
/**
* Returns an {@link ORCCertificateImpl} object for a given {@link String} key. If there is no map value for the
* given key, the method returns {@link null}.
+ *
+ * @param certificateId
+ * internally, the ID is "canonicalized" by removing all whitespace from it, so, e.g., "FIN11826L11826"
+ * is considered equivalent to "FIN11826 L11826". This helps iron out some subtle differences in how RMS
+ * files, JSON files and XML-based search results represent certificate IDs.
*/
@Override
public ORCCertificate getCertificateById(String certificateId) {
+ String refNo = null;
+ String natAuth = null;
+ String fileId = null;
String boatName = null;
String boatclass = null;
Distance length = null;
@@ -105,165 +116,171 @@ public class ORCCertificatesCollectionJSON extends AbstractORCCertificatesCollec
final Map trueWindSpeedMap = new TreeMap(); // Using TreeMap implementation to save the TrueWindSpeed
// so that it first sorts the entries as well as avoids duplicates
final Map trueWindAngleMap = new TreeMap(); // Same like trueWindSpeedMap
- final JSONObject object = certificateJsonObjectsByCertificateId.get(certificateId);
+ final JSONObject object = certificateJsonObjectsByCertificateId.get(canonicalizeId(certificateId));
+ final ORCCertificate result;
if (object == null) {
- // TODO Throw Exception for certificate by id not found. InvalidArgumentException?
- return null;
- }
- String sailNumber = null;
- for (Entry