@@ -41,6 +41,7 @@ public void setup() throws Exception {
41
41
42
42
public void testLicenseAllowsSyntheticSource () {
43
43
MockLicenseState licenseState = MockLicenseState .createMock ();
44
+ when (licenseState .copyCurrentLicenseState ()).thenReturn (licenseState );
44
45
when (licenseState .isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE ))).thenReturn (true );
45
46
licenseService .setLicenseState (licenseState );
46
47
licenseService .setLicenseService (mockLicenseService );
@@ -53,6 +54,7 @@ public void testLicenseAllowsSyntheticSource() {
53
54
54
55
public void testLicenseAllowsSyntheticSourceTemplateValidation () {
55
56
MockLicenseState licenseState = MockLicenseState .createMock ();
57
+ when (licenseState .copyCurrentLicenseState ()).thenReturn (licenseState );
56
58
when (licenseState .isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE ))).thenReturn (true );
57
59
licenseService .setLicenseState (licenseState );
58
60
licenseService .setLicenseService (mockLicenseService );
@@ -65,6 +67,7 @@ public void testLicenseAllowsSyntheticSourceTemplateValidation() {
65
67
66
68
public void testDefaultDisallow () {
67
69
MockLicenseState licenseState = MockLicenseState .createMock ();
70
+ when (licenseState .copyCurrentLicenseState ()).thenReturn (licenseState );
68
71
when (licenseState .isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE ))).thenReturn (false );
69
72
licenseService .setLicenseState (licenseState );
70
73
licenseService .setLicenseService (mockLicenseService );
@@ -77,6 +80,7 @@ public void testDefaultDisallow() {
77
80
78
81
public void testFallback () {
79
82
MockLicenseState licenseState = MockLicenseState .createMock ();
83
+ when (licenseState .copyCurrentLicenseState ()).thenReturn (licenseState );
80
84
when (licenseState .isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE ))).thenReturn (true );
81
85
licenseService .setLicenseState (licenseState );
82
86
licenseService .setLicenseService (mockLicenseService );
@@ -95,6 +99,7 @@ public void testGoldOrPlatinumLicense() throws Exception {
95
99
when (mockLicenseService .getLicense ()).thenReturn (license );
96
100
97
101
MockLicenseState licenseState = MockLicenseState .createMock ();
102
+ when (licenseState .copyCurrentLicenseState ()).thenReturn (licenseState );
98
103
when (licenseState .getOperationMode ()).thenReturn (license .operationMode ());
99
104
when (licenseState .isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE_LEGACY ))).thenReturn (true );
100
105
licenseService .setLicenseState (licenseState );
@@ -103,6 +108,8 @@ public void testGoldOrPlatinumLicense() throws Exception {
103
108
"legacy licensed usage is allowed, so not fallback to stored source" ,
104
109
licenseService .fallbackToStoredSource (false , true )
105
110
);
111
+ Mockito .verify (licenseState , Mockito .times (1 )).isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE ));
112
+ Mockito .verify (licenseState , Mockito .times (1 )).isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE_LEGACY ));
106
113
Mockito .verify (licenseState , Mockito .times (1 )).featureUsed (any ());
107
114
}
108
115
@@ -112,6 +119,7 @@ public void testGoldOrPlatinumLicenseLegacyLicenseNotAllowed() throws Exception
112
119
when (mockLicenseService .getLicense ()).thenReturn (license );
113
120
114
121
MockLicenseState licenseState = MockLicenseState .createMock ();
122
+ when (licenseState .copyCurrentLicenseState ()).thenReturn (licenseState );
115
123
when (licenseState .getOperationMode ()).thenReturn (license .operationMode ());
116
124
when (licenseState .isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE ))).thenReturn (false );
117
125
licenseService .setLicenseState (licenseState );
@@ -125,14 +133,16 @@ public void testGoldOrPlatinumLicenseLegacyLicenseNotAllowed() throws Exception
125
133
}
126
134
127
135
public void testGoldOrPlatinumLicenseBeyondCutoffDate () throws Exception {
128
- long start = LocalDateTime .of (2025 , 1 , 1 , 0 , 0 ).toInstant (ZoneOffset .UTC ).toEpochMilli ();
136
+ long start = LocalDateTime .of (2025 , 2 , 5 , 0 , 0 ).toInstant (ZoneOffset .UTC ).toEpochMilli ();
129
137
License license = createGoldOrPlatinumLicense (start );
130
138
mockLicenseService = mock (LicenseService .class );
131
139
when (mockLicenseService .getLicense ()).thenReturn (license );
132
140
133
141
MockLicenseState licenseState = MockLicenseState .createMock ();
142
+ when (licenseState .copyCurrentLicenseState ()).thenReturn (licenseState );
134
143
when (licenseState .getOperationMode ()).thenReturn (license .operationMode ());
135
144
when (licenseState .isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE ))).thenReturn (false );
145
+ when (licenseState .isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE_LEGACY ))).thenReturn (true );
136
146
licenseService .setLicenseState (licenseState );
137
147
licenseService .setLicenseService (mockLicenseService );
138
148
assertTrue ("beyond cutoff date, so fallback to stored source" , licenseService .fallbackToStoredSource (false , true ));
@@ -143,19 +153,21 @@ public void testGoldOrPlatinumLicenseBeyondCutoffDate() throws Exception {
143
153
public void testGoldOrPlatinumLicenseCustomCutoffDate () throws Exception {
144
154
licenseService = new SyntheticSourceLicenseService (Settings .EMPTY , "2025-01-02T00:00" );
145
155
146
- long start = LocalDateTime .of (2025 , 1 , 1 , 0 , 0 ).toInstant (ZoneOffset .UTC ).toEpochMilli ();
156
+ long start = LocalDateTime .of (2025 , 1 , 3 , 0 , 0 ).toInstant (ZoneOffset .UTC ).toEpochMilli ();
147
157
License license = createGoldOrPlatinumLicense (start );
148
158
mockLicenseService = mock (LicenseService .class );
149
159
when (mockLicenseService .getLicense ()).thenReturn (license );
150
160
151
161
MockLicenseState licenseState = MockLicenseState .createMock ();
162
+ when (licenseState .copyCurrentLicenseState ()).thenReturn (licenseState );
152
163
when (licenseState .getOperationMode ()).thenReturn (license .operationMode ());
164
+ when (licenseState .isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE ))).thenReturn (false );
153
165
when (licenseState .isAllowed (same (SyntheticSourceLicenseService .SYNTHETIC_SOURCE_FEATURE_LEGACY ))).thenReturn (true );
154
166
licenseService .setLicenseState (licenseState );
155
167
licenseService .setLicenseService (mockLicenseService );
156
- assertFalse ("custom cutoff date, so fallback to stored source" , licenseService .fallbackToStoredSource (false , true ));
157
- Mockito .verify (licenseState , Mockito .times (1 )).featureUsed ( any ( ));
158
- Mockito .verify (licenseState , Mockito .times ( 1 )).isAllowed ( same ( SyntheticSourceLicenseService . SYNTHETIC_SOURCE_FEATURE_LEGACY ));
168
+ assertTrue ("custom cutoff date, so fallback to stored source" , licenseService .fallbackToStoredSource (false , true ));
169
+ Mockito .verify (licenseState , Mockito .times (1 )).isAllowed ( same ( SyntheticSourceLicenseService . SYNTHETIC_SOURCE_FEATURE ));
170
+ Mockito .verify (licenseState , Mockito .never ( )).featureUsed ( any ( ));
159
171
}
160
172
161
173
static License createEnterpriseLicense () throws Exception {
0 commit comments