Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void setup() throws Exception {

public void testLicenseAllowsSyntheticSource() {
MockLicenseState licenseState = MockLicenseState.createMock();
when(licenseState.copyCurrentLicenseState()).thenReturn(licenseState);
when(licenseState.isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE))).thenReturn(true);
licenseService.setLicenseState(licenseState);
licenseService.setLicenseService(mockLicenseService);
Expand All @@ -53,6 +54,7 @@ public void testLicenseAllowsSyntheticSource() {

public void testLicenseAllowsSyntheticSourceTemplateValidation() {
MockLicenseState licenseState = MockLicenseState.createMock();
when(licenseState.copyCurrentLicenseState()).thenReturn(licenseState);
when(licenseState.isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE))).thenReturn(true);
licenseService.setLicenseState(licenseState);
licenseService.setLicenseService(mockLicenseService);
Expand All @@ -65,6 +67,7 @@ public void testLicenseAllowsSyntheticSourceTemplateValidation() {

public void testDefaultDisallow() {
MockLicenseState licenseState = MockLicenseState.createMock();
when(licenseState.copyCurrentLicenseState()).thenReturn(licenseState);
when(licenseState.isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE))).thenReturn(false);
licenseService.setLicenseState(licenseState);
licenseService.setLicenseService(mockLicenseService);
Expand All @@ -77,6 +80,7 @@ public void testDefaultDisallow() {

public void testFallback() {
MockLicenseState licenseState = MockLicenseState.createMock();
when(licenseState.copyCurrentLicenseState()).thenReturn(licenseState);
when(licenseState.isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE))).thenReturn(true);
licenseService.setLicenseState(licenseState);
licenseService.setLicenseService(mockLicenseService);
Expand All @@ -95,6 +99,7 @@ public void testGoldOrPlatinumLicense() throws Exception {
when(mockLicenseService.getLicense()).thenReturn(license);

MockLicenseState licenseState = MockLicenseState.createMock();
when(licenseState.copyCurrentLicenseState()).thenReturn(licenseState);
when(licenseState.getOperationMode()).thenReturn(license.operationMode());
when(licenseState.isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE_LEGACY))).thenReturn(true);
licenseService.setLicenseState(licenseState);
Expand All @@ -103,6 +108,8 @@ public void testGoldOrPlatinumLicense() throws Exception {
"legacy licensed usage is allowed, so not fallback to stored source",
licenseService.fallbackToStoredSource(false, true)
);
Mockito.verify(licenseState, Mockito.times(1)).isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE));
Mockito.verify(licenseState, Mockito.times(1)).isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE_LEGACY));
Mockito.verify(licenseState, Mockito.times(1)).featureUsed(any());
}

Expand All @@ -112,6 +119,7 @@ public void testGoldOrPlatinumLicenseLegacyLicenseNotAllowed() throws Exception
when(mockLicenseService.getLicense()).thenReturn(license);

MockLicenseState licenseState = MockLicenseState.createMock();
when(licenseState.copyCurrentLicenseState()).thenReturn(licenseState);
when(licenseState.getOperationMode()).thenReturn(license.operationMode());
when(licenseState.isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE))).thenReturn(false);
licenseService.setLicenseState(licenseState);
Expand All @@ -125,14 +133,16 @@ public void testGoldOrPlatinumLicenseLegacyLicenseNotAllowed() throws Exception
}

public void testGoldOrPlatinumLicenseBeyondCutoffDate() throws Exception {
long start = LocalDateTime.of(2025, 1, 1, 0, 0).toInstant(ZoneOffset.UTC).toEpochMilli();
long start = LocalDateTime.of(2025, 2, 5, 0, 0).toInstant(ZoneOffset.UTC).toEpochMilli();
License license = createGoldOrPlatinumLicense(start);
mockLicenseService = mock(LicenseService.class);
when(mockLicenseService.getLicense()).thenReturn(license);

MockLicenseState licenseState = MockLicenseState.createMock();
when(licenseState.copyCurrentLicenseState()).thenReturn(licenseState);
when(licenseState.getOperationMode()).thenReturn(license.operationMode());
when(licenseState.isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE))).thenReturn(false);
when(licenseState.isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE_LEGACY))).thenReturn(true);
licenseService.setLicenseState(licenseState);
licenseService.setLicenseService(mockLicenseService);
assertTrue("beyond cutoff date, so fallback to stored source", licenseService.fallbackToStoredSource(false, true));
Expand All @@ -143,19 +153,21 @@ public void testGoldOrPlatinumLicenseBeyondCutoffDate() throws Exception {
public void testGoldOrPlatinumLicenseCustomCutoffDate() throws Exception {
licenseService = new SyntheticSourceLicenseService(Settings.EMPTY, "2025-01-02T00:00");

long start = LocalDateTime.of(2025, 1, 1, 0, 0).toInstant(ZoneOffset.UTC).toEpochMilli();
long start = LocalDateTime.of(2025, 1, 3, 0, 0).toInstant(ZoneOffset.UTC).toEpochMilli();
License license = createGoldOrPlatinumLicense(start);
mockLicenseService = mock(LicenseService.class);
when(mockLicenseService.getLicense()).thenReturn(license);

MockLicenseState licenseState = MockLicenseState.createMock();
when(licenseState.copyCurrentLicenseState()).thenReturn(licenseState);
when(licenseState.getOperationMode()).thenReturn(license.operationMode());
when(licenseState.isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE))).thenReturn(false);
when(licenseState.isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE_LEGACY))).thenReturn(true);
licenseService.setLicenseState(licenseState);
licenseService.setLicenseService(mockLicenseService);
assertFalse("custom cutoff date, so fallback to stored source", licenseService.fallbackToStoredSource(false, true));
Mockito.verify(licenseState, Mockito.times(1)).featureUsed(any());
Mockito.verify(licenseState, Mockito.times(1)).isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE_LEGACY));
assertTrue("custom cutoff date, so fallback to stored source", licenseService.fallbackToStoredSource(false, true));
Mockito.verify(licenseState, Mockito.times(1)).isAllowed(same(SyntheticSourceLicenseService.SYNTHETIC_SOURCE_FEATURE));
Mockito.verify(licenseState, Mockito.never()).featureUsed(any());
}

static License createEnterpriseLicense() throws Exception {
Expand Down