d2190c62b1fd28b0ffead867422a0bab9dbd3b34
java/com.sap.sailing.windestimation.test/src/com/sap/sailing/windestimation/integration/IncrementalMstManeuverGraphGeneratorTest.java
| ... | ... | @@ -8,6 +8,9 @@ import java.net.MalformedURLException; |
| 8 | 8 | import java.net.URI; |
| 9 | 9 | import java.net.URISyntaxException; |
| 10 | 10 | import java.net.URL; |
| 11 | +import java.nio.charset.StandardCharsets; |
|
| 12 | +import java.security.MessageDigest; |
|
| 13 | +import java.security.NoSuchAlgorithmException; |
|
| 11 | 14 | import java.text.SimpleDateFormat; |
| 12 | 15 | import java.util.ArrayList; |
| 13 | 16 | import java.util.GregorianCalendar; |
| ... | ... | @@ -16,6 +19,7 @@ import java.util.Optional; |
| 16 | 19 | import java.util.Set; |
| 17 | 20 | import java.util.TimeZone; |
| 18 | 21 | import java.util.TreeSet; |
| 22 | +import java.util.logging.Logger; |
|
| 19 | 23 | |
| 20 | 24 | import org.json.simple.parser.ParseException; |
| 21 | 25 | import org.junit.jupiter.api.BeforeEach; |
| ... | ... | @@ -54,6 +58,7 @@ import com.sap.sse.common.impl.MillisecondsTimePoint; |
| 54 | 58 | * |
| 55 | 59 | */ |
| 56 | 60 | public class IncrementalMstManeuverGraphGeneratorTest extends OnlineTracTracBasedTest { |
| 61 | + private static final Logger logger = Logger.getLogger(IncrementalMstManeuverGraphGeneratorTest.class.getName()); |
|
| 57 | 62 | |
| 58 | 63 | protected final SimpleDateFormat dateFormat; |
| 59 | 64 | private ClassPathReadOnlyModelStoreImpl modelStore; |
| ... | ... | @@ -81,7 +86,7 @@ public class IncrementalMstManeuverGraphGeneratorTest extends OnlineTracTracBase |
| 81 | 86 | } |
| 82 | 87 | |
| 83 | 88 | @Test |
| 84 | - public void testIncrementalMstManeuverGraphGenerator() throws ClassNotFoundException, IOException, ParseException, InterruptedException { |
|
| 89 | + public void testIncrementalMstManeuverGraphGenerator() throws ClassNotFoundException, IOException, ParseException, InterruptedException, NoSuchAlgorithmException { |
|
| 85 | 90 | final GaussianBasedTwdTransitionDistributionCache gaussianBasedTwdTransitionDistributionCache = new GaussianBasedTwdTransitionDistributionCache( |
| 86 | 91 | modelStore, /* preload all models */ false, Long.MAX_VALUE); |
| 87 | 92 | final DistanceAndDurationAwareWindTransitionProbabilitiesCalculator transitionProbabilitiesCalculator = new DistanceAndDurationAwareWindTransitionProbabilitiesCalculator( |
| ... | ... | @@ -92,13 +97,38 @@ public class IncrementalMstManeuverGraphGeneratorTest extends OnlineTracTracBase |
| 92 | 97 | "Wind estimation models are empty"); |
| 93 | 98 | final DynamicTrackedRaceImpl trackedRace = getTrackedRace(); |
| 94 | 99 | final ReplicablePolarService polarDataService; |
| 95 | - final Optional<String> polardataBearerToken = Optional.ofNullable(Optional.ofNullable(System.getProperty("polardata.source.bearertoken")).orElse(System.getenv("POLAR_DATA_BEARER_TOKEN"))); |
|
| 96 | - if (polardataBearerToken.isPresent()) { |
|
| 100 | + String polarDataBearerToken = System.getProperty("polardata.source.bearertoken"); |
|
| 101 | + if (polarDataBearerToken == null) { |
|
| 102 | + logger.info("Couldn't find polardata.source.bearertoken system property, trying environment variable POLAR_DATA_BEARER_TOKEN"); |
|
| 103 | + polarDataBearerToken = System.getenv("POLAR_DATA_BEARER_TOKEN"); |
|
| 104 | + if (polarDataBearerToken == null) { |
|
| 105 | + logger.warning("Couldn't find POLAR_DATA_BEARER_TOKEN environment variable either, polar data service will not be available"); |
|
| 106 | + } else { |
|
| 107 | + final byte[] digest = MessageDigest.getInstance("SHA-256").digest(polarDataBearerToken.getBytes(StandardCharsets.UTF_8)); |
|
| 108 | + final StringBuilder hexString = new StringBuilder(); |
|
| 109 | + for (byte b : digest) { |
|
| 110 | + String hex = Integer.toHexString(0xff & b); |
|
| 111 | + if (hex.length() == 1) { |
|
| 112 | + hexString.append('0'); |
|
| 113 | + } |
|
| 114 | + hexString.append(hex); |
|
| 115 | + } |
|
| 116 | + logger.info("Found POLAR_DATA_BEARER_TOKEN environment variable, length "+polarDataBearerToken.length() |
|
| 117 | + +", SHA256 hash "+hexString.toString() |
|
| 118 | + +"; polar data service will be available"); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + logger.info("Found polardata.source.bearertoken system property, polar data service will be available"); |
|
| 122 | + } |
|
| 123 | + final Optional<String> polardataBearerTokenOptional = Optional.ofNullable(polarDataBearerToken); |
|
| 124 | + if (polardataBearerTokenOptional.isPresent()) { |
|
| 97 | 125 | polarDataService = new PolarDataServiceImpl(); |
| 98 | 126 | final com.sap.sailing.domain.tractracadapter.DomainFactory domainFactoryImpl = getDomainFactory(); |
| 99 | 127 | final DomainFactory baseDomainFactory = domainFactoryImpl.getBaseDomainFactory(); |
| 100 | 128 | polarDataService.registerDomainFactory(baseDomainFactory); |
| 101 | - new PolarDataClient(Optional.ofNullable(System.getenv("POLAR_DATA_BASE_URL")).orElse("https://sapsailing.com"), polarDataService, polardataBearerToken).updatePolarDataRegressions(); |
|
| 129 | + new PolarDataClient( |
|
| 130 | + Optional.ofNullable(System.getenv("POLAR_DATA_BASE_URL")).orElse("https://sapsailing.com"), |
|
| 131 | + polarDataService, polardataBearerTokenOptional).updatePolarDataRegressions(); |
|
| 102 | 132 | } else { |
| 103 | 133 | polarDataService = null; |
| 104 | 134 | } |