]> source.dussan.org Git - sonarqube.git/blob
e657f951f0d4dbbe9cc6ae5c6d4cbf7b553e6445
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2017 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 package org.sonar.server.edition;
21
22 import java.util.Collections;
23 import java.util.Random;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.ExpectedException;
27 import org.sonar.api.utils.System2;
28 import org.sonar.db.DbClient;
29 import org.sonar.db.DbTester;
30 import org.sonar.server.edition.EditionManagementState.PendingStatus;
31
32 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
33 import static org.assertj.core.api.Assertions.assertThat;
34 import static org.sonar.server.edition.EditionManagementState.PendingStatus.AUTOMATIC_IN_PROGRESS;
35 import static org.sonar.server.edition.EditionManagementState.PendingStatus.AUTOMATIC_READY;
36 import static org.sonar.server.edition.EditionManagementState.PendingStatus.MANUAL_IN_PROGRESS;
37 import static org.sonar.server.edition.EditionManagementState.PendingStatus.NONE;
38
39 public class StandaloneEditionManagementStateImplTest {
40   private static final License LICENSE_WITHOUT_PLUGINS = new License(randomAlphanumeric(3), Collections.emptyList(), randomAlphanumeric(10));
41
42   @Rule
43   public DbTester dbTester = DbTester.create(System2.INSTANCE);
44   @Rule
45   public ExpectedException expectedException = ExpectedException.none();
46
47   private DbClient dbClient = dbTester.getDbClient();
48   private final StandaloneEditionManagementStateImpl underTest = new StandaloneEditionManagementStateImpl(dbClient);
49
50   @Test
51   public void getCurrentEditionKey_fails_with_ISE_if_start_has_not_been_called() {
52     expectISENotStarted();
53
54     underTest.getCurrentEditionKey();
55   }
56
57   @Test
58   public void getCurrentEditionKey_returns_empty_when_internal_properties_table_is_empty() {
59     underTest.start();
60
61     assertThat(underTest.getCurrentEditionKey()).isEmpty();
62   }
63
64   @Test
65   public void getCurrentEditionKey_returns_value_in_db_for_key_currentEditionKey() {
66     String value = randomAlphanumeric(10);
67     dbTester.properties().insertInternal("currentEditionKey", value);
68     underTest.start();
69
70     assertThat(underTest.getCurrentEditionKey()).contains(value);
71   }
72
73   @Test
74   public void getCurrentEditionKey_returns_empty_when_value_in_db_is_empty_for_key_currentEditionKey() {
75     dbTester.properties().insertEmptyInternal("currentEditionKey");
76     underTest.start();
77
78     assertThat(underTest.getCurrentEditionKey()).isEmpty();
79   }
80
81   @Test
82   public void getPendingInstallationStatus_fails_with_ISE_if_start_has_not_been_called() {
83     expectISENotStarted();
84
85     underTest.getPendingInstallationStatus();
86   }
87
88   @Test
89   public void getPendingInstallationStatus_returns_NONE_when_internal_properties_table_is_empty() {
90     underTest.start();
91
92     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
93   }
94
95   @Test
96   public void getPendingInstallationStatus_returns_value_in_db_for_key_pendingInstallStatus() {
97     PendingStatus value = PendingStatus.values()[new Random().nextInt(PendingStatus.values().length)];
98     dbTester.properties().insertInternal("pendingInstallStatus", value.name());
99     underTest.start();
100
101     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(value);
102   }
103
104   @Test
105   public void getPendingInstallationStatus_returns_NONE_when_value_in_db_is_empty_for_key_pendingInstallStatus() {
106     dbTester.properties().insertEmptyInternal("pendingInstallStatus");
107     underTest.start();
108
109     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
110   }
111
112   @Test
113   public void start_fails_when_value_in_db_for_key_pendingInstallStatus_cannot_be_parsed_to_enum() {
114     String value = randomAlphanumeric(30);
115     dbTester.properties().insertInternal("pendingInstallStatus", value);
116
117     expectedException.expect(IllegalArgumentException.class);
118     expectedException.expectMessage("No enum constant org.sonar.server.edition.EditionManagementState.PendingStatus." + value);
119
120     underTest.start();
121   }
122
123   @Test
124   public void getPendingEditionKey_fails_with_ISE_if_start_has_not_been_called() {
125     expectISENotStarted();
126
127     underTest.getPendingEditionKey();
128   }
129
130   @Test
131   public void getPendingEditionKey_returns_empty_when_internal_properties_table_is_empty() {
132     underTest.start();
133
134     assertThat(underTest.getPendingEditionKey()).isEmpty();
135   }
136
137   @Test
138   public void getPendingEditionKey_returns_value_in_db_for_key_pendingEditionKey() {
139     String value = randomAlphanumeric(10);
140     dbTester.properties().insertInternal("pendingEditionKey", value);
141     underTest.start();
142
143     assertThat(underTest.getPendingEditionKey()).contains(value);
144   }
145
146   @Test
147   public void getPendingEditionKey_returns_empty_when_value_in_db_is_empty_for_key_pendingEditionKey() {
148     dbTester.properties().insertEmptyInternal("pendingEditionKey");
149     underTest.start();
150
151     assertThat(underTest.getPendingEditionKey()).isEmpty();
152   }
153
154   @Test
155   public void getPendingLicense_fails_with_ISE_if_start_has_not_been_called() {
156     expectISENotStarted();
157
158     underTest.getPendingLicense();
159   }
160
161   @Test
162   public void getPendingLicense_returns_empty_when_internal_properties_table_is_empty() {
163     underTest.start();
164
165     assertThat(underTest.getPendingLicense()).isEmpty();
166   }
167
168   @Test
169   public void getPendingLicense_returns_empty_value_in_db_for_key_pendingLicense() {
170     String value = randomAlphanumeric(10);
171     dbTester.properties().insertInternal("pendingLicense", value);
172     underTest.start();
173
174     assertThat(underTest.getPendingLicense()).contains(value);
175   }
176
177   @Test
178   public void getPendingLicense_returns_empty_when_value_in_db_is_empty_for_key_pendingLicense() {
179     dbTester.properties().insertEmptyInternal("pendingLicense");
180     underTest.start();
181
182     assertThat(underTest.getPendingLicense()).isEmpty();
183   }
184
185   @Test
186   public void startAutomaticInstall_fails_with_ISE_if_not_started() {
187     expectISENotStarted();
188
189     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
190   }
191
192   @Test
193   public void startAutomaticInstall_fails_with_NPE_if_license_is_null() {
194     underTest.start();
195
196     expectedException.expect(NullPointerException.class);
197     expectedException.expectMessage("license can't be null");
198
199     underTest.startAutomaticInstall(null);
200   }
201
202   @Test
203   public void startAutomaticInstall_sets_pending_fields_after_start() {
204     underTest.start();
205
206     PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
207
208     assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS);
209     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS);
210     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
211     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
212     assertThat(underTest.getCurrentEditionKey()).isEmpty();
213   }
214
215   @Test
216   public void startAutomaticInstall_sets_pending_fields_after_start_with_existing_currentEditionKey() {
217     String value = randomAlphanumeric(10);
218     dbTester.properties().insertInternal("currentEditionKey", value);
219     underTest.start();
220
221     PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
222
223     assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS);
224     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS);
225     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
226     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
227     assertThat(underTest.getCurrentEditionKey()).contains(value);
228   }
229
230   @Test
231   public void startAutomaticInstall_sets_pending_fields_after_newEditionWithoutInstall() {
232     String value = randomAlphanumeric(10);
233     underTest.start();
234     underTest.newEditionWithoutInstall(value);
235
236     PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
237
238     assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS);
239     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS);
240     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
241     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
242     assertThat(underTest.getCurrentEditionKey()).contains(value);
243   }
244
245   @Test
246   public void startAutomaticInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
247     underTest.start();
248     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
249
250     expectedException.expect(IllegalStateException.class);
251     expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
252
253     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
254   }
255
256   @Test
257   public void startAutomaticInstall_fails_with_ISE_if_called_after_automaticInstallReady() {
258     underTest.start();
259     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
260     underTest.automaticInstallReady();
261
262     expectedException.expect(IllegalStateException.class);
263     expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is AUTOMATIC_READY (should be any of [NONE])");
264
265     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
266   }
267
268   @Test
269   public void startAutomaticInstall_fails_with_ISE_if_called_after_manualInstall() {
270     underTest.start();
271     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
272
273     expectedException.expect(IllegalStateException.class);
274     expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
275
276     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
277   }
278
279   @Test
280   public void startManualInstall_fails_with_ISE_if_not_started() {
281     expectISENotStarted();
282
283     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
284   }
285
286   @Test
287   public void startManualInstall_fails_with_NPE_if_license_is_null() {
288     underTest.start();
289
290     expectedException.expect(NullPointerException.class);
291     expectedException.expectMessage("license can't be null");
292
293     underTest.startManualInstall(null);
294   }
295
296   @Test
297   public void startManualInstall_sets_pending_fields_after_start() {
298     underTest.start();
299
300     PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
301
302     assertThat(newStatus).isEqualTo(MANUAL_IN_PROGRESS);
303     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(MANUAL_IN_PROGRESS);
304     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
305     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
306     assertThat(underTest.getCurrentEditionKey()).isEmpty();
307   }
308
309   @Test
310   public void startManualInstall_sets_pending_fields_after_start_with_existing_currentEditionKey() {
311     String value = randomAlphanumeric(10);
312     dbTester.properties().insertInternal("currentEditionKey", value);
313     underTest.start();
314
315     PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
316
317     assertThat(newStatus).isEqualTo(MANUAL_IN_PROGRESS);
318     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(MANUAL_IN_PROGRESS);
319     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
320     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
321     assertThat(underTest.getCurrentEditionKey()).contains(value);
322   }
323
324   @Test
325   public void startManualInstall_sets_pending_fields_after_newEditionWithoutInstall() {
326     String value = randomAlphanumeric(10);
327     underTest.start();
328     underTest.newEditionWithoutInstall(value);
329
330     PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
331
332     assertThat(newStatus).isEqualTo(MANUAL_IN_PROGRESS);
333     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(MANUAL_IN_PROGRESS);
334     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
335     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
336     assertThat(underTest.getCurrentEditionKey()).contains(value);
337   }
338
339   @Test
340   public void startManualInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
341     underTest.start();
342     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
343
344     expectedException.expect(IllegalStateException.class);
345     expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
346
347     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
348   }
349
350   @Test
351   public void startManualInstall_fails_with_ISE_if_called_after_automaticInstallReady() {
352     underTest.start();
353     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
354     underTest.automaticInstallReady();
355
356     expectedException.expect(IllegalStateException.class);
357     expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is AUTOMATIC_READY (should be any of [NONE])");
358
359     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
360   }
361
362   @Test
363   public void startManualInstall_fails_with_ISE_if_called_after_manualInstall() {
364     underTest.start();
365     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
366
367     expectedException.expect(IllegalStateException.class);
368     expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
369
370     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
371   }
372
373   @Test
374   public void automaticInstallReady_fails_with_ISE_if_not_started() {
375     expectISENotStarted();
376
377     underTest.automaticInstallReady();
378   }
379
380   @Test
381   public void automaticInstallReady_fails_with_ISE_if_called() {
382     underTest.start();
383
384     expectedException.expect(IllegalStateException.class);
385     expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS])");
386
387     underTest.automaticInstallReady();
388   }
389
390   @Test
391   public void automaticInstallReady_fails_with_ISE_if_called_after_manualInstall() {
392     underTest.start();
393     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
394
395     expectedException.expect(IllegalStateException.class);
396     expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is MANUAL_IN_PROGRESS (should be any of [AUTOMATIC_IN_PROGRESS])");
397
398     underTest.automaticInstallReady();
399   }
400
401   @Test
402   public void automaticInstallReady_after_startAutomaticInstall_changes_status_to_AUTOMATIC_READY_but_does_not_change_editions() {
403     underTest.start();
404     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
405
406     PendingStatus newStatus = underTest.automaticInstallReady();
407
408     assertThat(newStatus).isEqualTo(AUTOMATIC_READY);
409     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_READY);
410     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
411     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
412     assertThat(underTest.getCurrentEditionKey()).isEmpty();
413   }
414
415   @Test
416   public void newEditionWithoutInstall_fails_with_ISE_if_not_started() {
417     expectISENotStarted();
418
419     underTest.newEditionWithoutInstall(randomAlphanumeric(3));
420   }
421
422   @Test
423   public void newEditionWithoutInstall_fails_with_NPE_if_newEditionKey_is_null() {
424     underTest.start();
425
426     expectedException.expect(NullPointerException.class);
427     expectedException.expectMessage("newEditionKey can't be null");
428
429     underTest.newEditionWithoutInstall(null);
430   }
431
432   @Test
433   public void newEditionWithoutInstall_fails_with_IAE_if_newEditionKey_is_empty() {
434     underTest.start();
435
436     expectedException.expect(IllegalArgumentException.class);
437     expectedException.expectMessage("newEditionKey can't be empty");
438
439     underTest.newEditionWithoutInstall("");
440   }
441
442   @Test
443   public void newEditionWithoutInstall_changes_current_edition() {
444     String newEditionKey = randomAlphanumeric(3);
445     underTest.start();
446
447     PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey);
448
449     assertThat(newStatus).isEqualTo(NONE);
450     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
451     assertThat(underTest.getPendingEditionKey()).isEmpty();
452     assertThat(underTest.getPendingLicense()).isEmpty();
453     assertThat(underTest.getCurrentEditionKey()).contains(newEditionKey);
454   }
455
456   @Test
457   public void newEditionWithoutInstall_overwrite_current_edition() {
458     String newEditionKey = randomAlphanumeric(3);
459     underTest.start();
460
461     PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey);
462
463     assertThat(newStatus).isEqualTo(NONE);
464     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
465     assertThat(underTest.getPendingEditionKey()).isEmpty();
466     assertThat(underTest.getPendingLicense()).isEmpty();
467     assertThat(underTest.getCurrentEditionKey()).contains(newEditionKey);
468   }
469
470   @Test
471   public void newEditionWithoutInstall_overwrites_from_previous_newEditionWithoutInstall() {
472     String newEditionKey1 = randomAlphanumeric(3);
473     String newEditionKey2 = randomAlphanumeric(3);
474     underTest.start();
475     underTest.newEditionWithoutInstall(newEditionKey1);
476
477     PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey2);
478
479     assertThat(newStatus).isEqualTo(NONE);
480     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
481     assertThat(underTest.getPendingEditionKey()).isEmpty();
482     assertThat(underTest.getPendingLicense()).isEmpty();
483     assertThat(underTest.getCurrentEditionKey()).contains(newEditionKey2);
484   }
485
486   @Test
487   public void newEditionWithoutInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
488     String newEditionKey = randomAlphanumeric(3);
489     underTest.start();
490     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
491
492     expectedException.expect(IllegalStateException.class);
493     expectedException.expectMessage("Can't move to NONE when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
494
495     underTest.newEditionWithoutInstall(newEditionKey);
496   }
497
498   @Test
499   public void newEditionWithoutInstall_fails_with_ISE_if_called_after_startManualInstall() {
500     String newEditionKey = randomAlphanumeric(3);
501     underTest.start();
502     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
503
504     expectedException.expect(IllegalStateException.class);
505     expectedException.expectMessage("Can't move to NONE when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
506
507     underTest.newEditionWithoutInstall(newEditionKey);
508   }
509
510   @Test
511   public void finalizeInstallation_fails_with_ISE_if_not_started() {
512     expectISENotStarted();
513
514     underTest.finalizeInstallation();
515   }
516
517   @Test
518   public void finalizeInstallation_fails_with_ISE_after_start() {
519     underTest.start();
520
521     expectedException.expect(IllegalStateException.class);
522     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS])");
523
524     underTest.finalizeInstallation();
525   }
526
527   @Test
528   public void finalizeInstallation_fails_with_ISE_after_newEditionWithoutInstall() {
529     underTest.start();
530     underTest.newEditionWithoutInstall(randomAlphanumeric(3));
531
532     expectedException.expect(IllegalStateException.class);
533     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS])");
534
535     underTest.finalizeInstallation();
536   }
537
538   @Test
539   public void finalizeInstallation_fails_with_ISE_after_startAutomaticInstall() {
540     underTest.start();
541     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
542
543     expectedException.expect(IllegalStateException.class);
544     expectedException.expectMessage("Can't move to NONE when status is AUTOMATIC_IN_PROGRESS (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS])");
545
546     underTest.finalizeInstallation();
547   }
548
549   @Test
550   public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_manualInstallationReady() {
551     underTest.start();
552     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
553     underTest.automaticInstallReady();
554
555     PendingStatus newStatus = underTest.finalizeInstallation();
556
557     assertThat(newStatus).isEqualTo(NONE);
558     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
559     assertThat(underTest.getPendingEditionKey()).isEmpty();
560     assertThat(underTest.getPendingLicense()).isEmpty();
561     assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
562   }
563
564   @Test
565   public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_startManualInstall() {
566     underTest.start();
567     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
568
569     PendingStatus newStatus = underTest.finalizeInstallation();
570
571     assertThat(newStatus).isEqualTo(NONE);
572     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
573     assertThat(underTest.getPendingEditionKey()).isEmpty();
574     assertThat(underTest.getPendingLicense()).isEmpty();
575     assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
576   }
577
578   @Test
579   public void finalizeInstallation_overwrites_current_edition_and_clear_pending_fields_after_startManualInstall() {
580     String value = randomAlphanumeric(10);
581     dbTester.properties().insertInternal("currentEditionKey", value);
582     underTest.start();
583     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
584
585     PendingStatus newStatus = underTest.finalizeInstallation();
586
587     assertThat(newStatus).isEqualTo(NONE);
588     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
589     assertThat(underTest.getPendingEditionKey()).isEmpty();
590     assertThat(underTest.getPendingLicense()).isEmpty();
591     assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
592   }
593
594   @Test
595   public void finalizeInstallation_fails_with_ISE_after_finalizeInstallation() {
596     underTest.start();
597     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
598     underTest.finalizeInstallation();
599
600     expectedException.expect(IllegalStateException.class);
601     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS])");
602
603     underTest.finalizeInstallation();
604   }
605
606   private void expectISENotStarted() {
607     expectedException.expect(IllegalStateException.class);
608     expectedException.expectMessage("StandaloneEditionManagementStateImpl is not started");
609   }
610
611 }