|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | +package org.elasticsearch.license; |
| 7 | + |
| 8 | + |
| 9 | +import org.elasticsearch.bootstrap.JavaVersion; |
| 10 | +import org.elasticsearch.test.ESTestCase; |
| 11 | + |
| 12 | +import java.time.LocalDate; |
| 13 | +import java.time.ZoneOffset; |
| 14 | + |
| 15 | +import static org.hamcrest.Matchers.startsWith; |
| 16 | + |
| 17 | +/** |
| 18 | + * Due to changes in JDK9 where locale data is used from CLDR, the licence message will differ in jdk 8 and jdk9+ |
| 19 | + * https://openjdk.java.net/jeps/252 |
| 20 | + */ |
| 21 | +public class LicenseServiceTests extends ESTestCase { |
| 22 | + |
| 23 | + public void testLogExpirationWarningOnJdk9AndNewer() { |
| 24 | + assumeTrue("this is for JDK9+", JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0); |
| 25 | + |
| 26 | + long time = LocalDate.of(2018, 11, 15).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli(); |
| 27 | + final boolean expired = randomBoolean(); |
| 28 | + final String message = LicenseService.buildExpirationMessage(time, expired).toString(); |
| 29 | + if (expired) { |
| 30 | + assertThat(message, startsWith("LICENSE [EXPIRED] ON [THU, NOV 15, 2018].\n")); |
| 31 | + } else { |
| 32 | + assertThat(message, startsWith("License [will expire] on [Thu, Nov 15, 2018].\n")); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + public void testLogExpirationWarningOnJdk8() { |
| 37 | + assumeTrue("this is for JDK8 only", JavaVersion.current().equals(JavaVersion.parse("8"))); |
| 38 | + |
| 39 | + long time = LocalDate.of(2018, 11, 15).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli(); |
| 40 | + final boolean expired = randomBoolean(); |
| 41 | + final String message = LicenseService.buildExpirationMessage(time, expired).toString(); |
| 42 | + if (expired) { |
| 43 | + assertThat(message, startsWith("LICENSE [EXPIRED] ON [THURSDAY, NOVEMBER 15, 2018].\n")); |
| 44 | + } else { |
| 45 | + assertThat(message, startsWith("License [will expire] on [Thursday, November 15, 2018].\n")); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments