]> source.dussan.org Git - sonarqube.git/blob
f1cbe67f43cd13bca30e07f597d1da22029d3bdc
[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 import static org.sonar.server.edition.EditionManagementState.PendingStatus.UNINSTALL_IN_PROGRESS;
39
40 public class StandaloneEditionManagementStateImplTest {
41   private static final License LICENSE_WITHOUT_PLUGINS = new License(randomAlphanumeric(3), Collections.emptyList(), randomAlphanumeric(10));
42
43   @Rule
44   public DbTester dbTester = DbTester.create(System2.INSTANCE);
45   @Rule
46   public ExpectedException expectedException = ExpectedException.none();
47
48   private DbClient dbClient = dbTester.getDbClient();
49   private final StandaloneEditionManagementStateImpl underTest = new StandaloneEditionManagementStateImpl(dbClient);
50
51   @Test
52   public void getCurrentEditionKey_fails_with_ISE_if_start_has_not_been_called() {
53     expectISENotStarted();
54
55     underTest.getCurrentEditionKey();
56   }
57
58   @Test
59   public void getCurrentEditionKey_returns_empty_when_internal_properties_table_is_empty() {
60     underTest.start();
61
62     assertThat(underTest.getCurrentEditionKey()).isEmpty();
63   }
64
65   @Test
66   public void getCurrentEditionKey_returns_value_in_db_for_key_currentEditionKey() {
67     String value = randomAlphanumeric(10);
68     dbTester.properties().insertInternal("currentEditionKey", value);
69     underTest.start();
70
71     assertThat(underTest.getCurrentEditionKey()).contains(value);
72   }
73
74   @Test
75   public void getCurrentEditionKey_returns_empty_when_value_in_db_is_empty_for_key_currentEditionKey() {
76     dbTester.properties().insertEmptyInternal("currentEditionKey");
77     underTest.start();
78
79     assertThat(underTest.getCurrentEditionKey()).isEmpty();
80   }
81
82   @Test
83   public void getPendingInstallationStatus_fails_with_ISE_if_start_has_not_been_called() {
84     expectISENotStarted();
85
86     underTest.getPendingInstallationStatus();
87   }
88
89   @Test
90   public void getPendingInstallationStatus_returns_NONE_when_internal_properties_table_is_empty() {
91     underTest.start();
92
93     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
94   }
95
96   @Test
97   public void getPendingInstallationStatus_returns_value_in_db_for_key_pendingInstallStatus() {
98     PendingStatus value = PendingStatus.values()[new Random().nextInt(PendingStatus.values().length)];
99     dbTester.properties().insertInternal("pendingInstallStatus", value.name());
100     underTest.start();
101
102     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(value);
103   }
104
105   @Test
106   public void getPendingInstallationStatus_returns_NONE_when_value_in_db_is_empty_for_key_pendingInstallStatus() {
107     dbTester.properties().insertEmptyInternal("pendingInstallStatus");
108     underTest.start();
109
110     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
111   }
112
113   @Test
114   public void start_fails_when_value_in_db_for_key_pendingInstallStatus_cannot_be_parsed_to_enum() {
115     String value = randomAlphanumeric(30);
116     dbTester.properties().insertInternal("pendingInstallStatus", value);
117
118     expectedException.expect(IllegalArgumentException.class);
119     expectedException.expectMessage("No enum constant org.sonar.server.edition.EditionManagementState.PendingStatus." + value);
120
121     underTest.start();
122   }
123
124   @Test
125   public void getPendingEditionKey_fails_with_ISE_if_start_has_not_been_called() {
126     expectISENotStarted();
127
128     underTest.getPendingEditionKey();
129   }
130
131   @Test
132   public void getPendingEditionKey_returns_empty_when_internal_properties_table_is_empty() {
133     underTest.start();
134
135     assertThat(underTest.getPendingEditionKey()).isEmpty();
136   }
137
138   @Test
139   public void getPendingEditionKey_returns_value_in_db_for_key_pendingEditionKey() {
140     String value = randomAlphanumeric(10);
141     dbTester.properties().insertInternal("pendingEditionKey", value);
142     underTest.start();
143
144     assertThat(underTest.getPendingEditionKey()).contains(value);
145   }
146
147   @Test
148   public void getPendingEditionKey_returns_empty_when_value_in_db_is_empty_for_key_pendingEditionKey() {
149     dbTester.properties().insertEmptyInternal("pendingEditionKey");
150     underTest.start();
151
152     assertThat(underTest.getPendingEditionKey()).isEmpty();
153   }
154
155   @Test
156   public void getPendingLicense_fails_with_ISE_if_start_has_not_been_called() {
157     expectISENotStarted();
158
159     underTest.getPendingLicense();
160   }
161
162   @Test
163   public void getPendingLicense_returns_empty_when_internal_properties_table_is_empty() {
164     underTest.start();
165
166     assertThat(underTest.getPendingLicense()).isEmpty();
167   }
168
169   @Test
170   public void getPendingLicense_returns_empty_value_in_db_for_key_pendingLicense() {
171     String value = randomAlphanumeric(10);
172     dbTester.properties().insertInternal("pendingLicense", value);
173     underTest.start();
174
175     assertThat(underTest.getPendingLicense()).contains(value);
176   }
177
178   @Test
179   public void getPendingLicense_returns_empty_when_value_in_db_is_empty_for_key_pendingLicense() {
180     dbTester.properties().insertEmptyInternal("pendingLicense");
181     underTest.start();
182
183     assertThat(underTest.getPendingLicense()).isEmpty();
184   }
185
186   @Test
187   public void startAutomaticInstall_fails_with_ISE_if_not_started() {
188     expectISENotStarted();
189
190     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
191   }
192
193   @Test
194   public void startAutomaticInstall_fails_with_NPE_if_license_is_null() {
195     underTest.start();
196
197     expectedException.expect(NullPointerException.class);
198     expectedException.expectMessage("license can't be null");
199
200     underTest.startAutomaticInstall(null);
201   }
202
203   @Test
204   public void startAutomaticInstall_sets_pending_fields_after_start() {
205     underTest.start();
206
207     PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
208
209     assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS);
210     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS);
211     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
212     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
213     assertThat(underTest.getCurrentEditionKey()).isEmpty();
214   }
215
216   @Test
217   public void startAutomaticInstall_sets_pending_fields_after_start_with_existing_currentEditionKey() {
218     String value = randomAlphanumeric(10);
219     dbTester.properties().insertInternal("currentEditionKey", value);
220     underTest.start();
221
222     PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
223
224     assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS);
225     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS);
226     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
227     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
228     assertThat(underTest.getCurrentEditionKey()).contains(value);
229   }
230
231   @Test
232   public void startAutomaticInstall_sets_pending_fields_after_newEditionWithoutInstall() {
233     String value = randomAlphanumeric(10);
234     underTest.start();
235     underTest.newEditionWithoutInstall(value);
236
237     PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
238
239     assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS);
240     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS);
241     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
242     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
243     assertThat(underTest.getCurrentEditionKey()).contains(value);
244   }
245
246   @Test
247   public void startAutomaticInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
248     underTest.start();
249     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
250
251     expectedException.expect(IllegalStateException.class);
252     expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
253
254     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
255   }
256
257   @Test
258   public void startAutomaticInstall_fails_with_ISE_if_called_after_automaticInstallReady() {
259     underTest.start();
260     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
261     underTest.automaticInstallReady();
262
263     expectedException.expect(IllegalStateException.class);
264     expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is AUTOMATIC_READY (should be any of [NONE])");
265
266     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
267   }
268
269   @Test
270   public void startAutomaticInstall_fails_with_ISE_if_called_after_manualInstall() {
271     underTest.start();
272     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
273
274     expectedException.expect(IllegalStateException.class);
275     expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
276
277     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
278   }
279
280   @Test
281   public void uninstall_fails_with_ISE_if_not_started() {
282     expectISENotStarted();
283
284     underTest.uninstall();
285   }
286
287   @Test
288   public void uninstall_resets_fields_after_start_and_install() {
289     String value = randomAlphanumeric(10);
290
291     underTest.start();
292     underTest.newEditionWithoutInstall(value);
293     PendingStatus newStatus = underTest.uninstall();
294
295     assertThat(newStatus).isEqualTo(UNINSTALL_IN_PROGRESS);
296     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(UNINSTALL_IN_PROGRESS);
297     assertThat(underTest.getPendingEditionKey()).isEmpty();
298     assertThat(underTest.getPendingLicense()).isEmpty();
299     assertThat(underTest.getCurrentEditionKey()).isEmpty();
300   }
301
302   @Test
303   public void uninstall_fails_with_ISE_if_called_after_uninstall() {
304     String value = randomAlphanumeric(10);
305     underTest.start();
306     underTest.newEditionWithoutInstall(value);
307     underTest.uninstall();
308
309     expectedException.expect(IllegalStateException.class);
310     expectedException.expectMessage("Can't move to UNINSTALL_IN_PROGRESS when status is UNINSTALL_IN_PROGRESS (should be any of [NONE])");
311
312     underTest.uninstall();
313   }
314
315   @Test
316   public void uninstall_resets_fields_after_newEditionWithoutInstall() {
317     String value = randomAlphanumeric(10);
318     underTest.start();
319     underTest.newEditionWithoutInstall(value);
320
321     PendingStatus newStatus = underTest.uninstall();
322
323     assertThat(newStatus).isEqualTo(UNINSTALL_IN_PROGRESS);
324     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(UNINSTALL_IN_PROGRESS);
325     assertThat(underTest.getPendingEditionKey()).isEmpty();
326     assertThat(underTest.getPendingLicense()).isEmpty();
327     assertThat(underTest.getCurrentEditionKey()).isEmpty();
328   }
329
330   @Test
331   public void uninstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
332     underTest.start();
333     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
334
335     expectedException.expect(IllegalStateException.class);
336     expectedException.expectMessage("Can't move to UNINSTALL_IN_PROGRESS when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
337
338     underTest.uninstall();
339   }
340
341   @Test
342   public void uninstall_fails_with_ISE_if_called_after_automaticInstallReady() {
343     underTest.start();
344     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
345     underTest.automaticInstallReady();
346
347     expectedException.expect(IllegalStateException.class);
348     expectedException.expectMessage("Can't move to UNINSTALL_IN_PROGRESS when status is AUTOMATIC_READY (should be any of [NONE])");
349
350     underTest.uninstall();
351   }
352
353   @Test
354   public void uninstall_fails_with_ISE_if_called_after_manualInstall() {
355     underTest.start();
356     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
357
358     expectedException.expect(IllegalStateException.class);
359     expectedException.expectMessage("Can't move to UNINSTALL_IN_PROGRESS when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
360
361     underTest.uninstall();
362   }
363
364   @Test
365   public void startManualInstall_fails_with_ISE_if_not_started() {
366     expectISENotStarted();
367
368     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
369   }
370
371   @Test
372   public void startManualInstall_fails_with_NPE_if_license_is_null() {
373     underTest.start();
374
375     expectedException.expect(NullPointerException.class);
376     expectedException.expectMessage("license can't be null");
377
378     underTest.startManualInstall(null);
379   }
380
381   @Test
382   public void startManualInstall_sets_pending_fields_after_start() {
383     underTest.start();
384
385     PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
386
387     assertThat(newStatus).isEqualTo(MANUAL_IN_PROGRESS);
388     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(MANUAL_IN_PROGRESS);
389     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
390     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
391     assertThat(underTest.getCurrentEditionKey()).isEmpty();
392   }
393
394   @Test
395   public void startManualInstall_sets_pending_fields_after_start_with_existing_currentEditionKey() {
396     String value = randomAlphanumeric(10);
397     dbTester.properties().insertInternal("currentEditionKey", value);
398     underTest.start();
399
400     PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
401
402     assertThat(newStatus).isEqualTo(MANUAL_IN_PROGRESS);
403     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(MANUAL_IN_PROGRESS);
404     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
405     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
406     assertThat(underTest.getCurrentEditionKey()).contains(value);
407   }
408
409   @Test
410   public void startManualInstall_sets_pending_fields_after_newEditionWithoutInstall() {
411     String value = randomAlphanumeric(10);
412     underTest.start();
413     underTest.newEditionWithoutInstall(value);
414
415     PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
416
417     assertThat(newStatus).isEqualTo(MANUAL_IN_PROGRESS);
418     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(MANUAL_IN_PROGRESS);
419     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
420     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
421     assertThat(underTest.getCurrentEditionKey()).contains(value);
422   }
423
424   @Test
425   public void startManualInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
426     underTest.start();
427     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
428
429     expectedException.expect(IllegalStateException.class);
430     expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
431
432     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
433   }
434
435   @Test
436   public void startManualInstall_fails_with_ISE_if_called_after_automaticInstallReady() {
437     underTest.start();
438     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
439     underTest.automaticInstallReady();
440
441     expectedException.expect(IllegalStateException.class);
442     expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is AUTOMATIC_READY (should be any of [NONE])");
443
444     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
445   }
446
447   @Test
448   public void startManualInstall_fails_with_ISE_if_called_after_manualInstall() {
449     underTest.start();
450     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
451
452     expectedException.expect(IllegalStateException.class);
453     expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
454
455     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
456   }
457
458   @Test
459   public void automaticInstallReady_fails_with_ISE_if_not_started() {
460     expectISENotStarted();
461
462     underTest.automaticInstallReady();
463   }
464
465   @Test
466   public void automaticInstallReady_fails_with_ISE_if_called() {
467     underTest.start();
468
469     expectedException.expect(IllegalStateException.class);
470     expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS])");
471
472     underTest.automaticInstallReady();
473   }
474
475   @Test
476   public void automaticInstallReady_fails_with_ISE_if_called_after_manualInstall() {
477     underTest.start();
478     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
479
480     expectedException.expect(IllegalStateException.class);
481     expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is MANUAL_IN_PROGRESS (should be any of [AUTOMATIC_IN_PROGRESS])");
482
483     underTest.automaticInstallReady();
484   }
485
486   @Test
487   public void automaticInstallReady_after_startAutomaticInstall_changes_status_to_AUTOMATIC_READY_but_does_not_change_editions() {
488     underTest.start();
489     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
490
491     PendingStatus newStatus = underTest.automaticInstallReady();
492
493     assertThat(newStatus).isEqualTo(AUTOMATIC_READY);
494     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_READY);
495     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
496     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
497     assertThat(underTest.getCurrentEditionKey()).isEmpty();
498   }
499
500   @Test
501   public void newEditionWithoutInstall_fails_with_ISE_if_not_started() {
502     expectISENotStarted();
503
504     underTest.newEditionWithoutInstall(randomAlphanumeric(3));
505   }
506
507   @Test
508   public void newEditionWithoutInstall_fails_with_NPE_if_newEditionKey_is_null() {
509     underTest.start();
510
511     expectedException.expect(NullPointerException.class);
512     expectedException.expectMessage("newEditionKey can't be null");
513
514     underTest.newEditionWithoutInstall(null);
515   }
516
517   @Test
518   public void newEditionWithoutInstall_fails_with_IAE_if_newEditionKey_is_empty() {
519     underTest.start();
520
521     expectedException.expect(IllegalArgumentException.class);
522     expectedException.expectMessage("newEditionKey can't be empty");
523
524     underTest.newEditionWithoutInstall("");
525   }
526
527   @Test
528   public void newEditionWithoutInstall_changes_current_edition() {
529     String newEditionKey = randomAlphanumeric(3);
530     underTest.start();
531
532     PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey);
533
534     assertThat(newStatus).isEqualTo(NONE);
535     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
536     assertThat(underTest.getPendingEditionKey()).isEmpty();
537     assertThat(underTest.getPendingLicense()).isEmpty();
538     assertThat(underTest.getCurrentEditionKey()).contains(newEditionKey);
539   }
540
541   @Test
542   public void newEditionWithoutInstall_overwrite_current_edition() {
543     String newEditionKey = randomAlphanumeric(3);
544     underTest.start();
545
546     PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey);
547
548     assertThat(newStatus).isEqualTo(NONE);
549     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
550     assertThat(underTest.getPendingEditionKey()).isEmpty();
551     assertThat(underTest.getPendingLicense()).isEmpty();
552     assertThat(underTest.getCurrentEditionKey()).contains(newEditionKey);
553   }
554
555   @Test
556   public void newEditionWithoutInstall_overwrites_from_previous_newEditionWithoutInstall() {
557     String newEditionKey1 = randomAlphanumeric(3);
558     String newEditionKey2 = randomAlphanumeric(3);
559     underTest.start();
560     underTest.newEditionWithoutInstall(newEditionKey1);
561
562     PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey2);
563
564     assertThat(newStatus).isEqualTo(NONE);
565     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
566     assertThat(underTest.getPendingEditionKey()).isEmpty();
567     assertThat(underTest.getPendingLicense()).isEmpty();
568     assertThat(underTest.getCurrentEditionKey()).contains(newEditionKey2);
569   }
570
571   @Test
572   public void newEditionWithoutInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
573     String newEditionKey = randomAlphanumeric(3);
574     underTest.start();
575     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
576
577     expectedException.expect(IllegalStateException.class);
578     expectedException.expectMessage("Can't move to NONE when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
579
580     underTest.newEditionWithoutInstall(newEditionKey);
581   }
582
583   @Test
584   public void newEditionWithoutInstall_fails_with_ISE_if_called_after_startManualInstall() {
585     String newEditionKey = randomAlphanumeric(3);
586     underTest.start();
587     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
588
589     expectedException.expect(IllegalStateException.class);
590     expectedException.expectMessage("Can't move to NONE when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
591
592     underTest.newEditionWithoutInstall(newEditionKey);
593   }
594
595   @Test
596   public void finalizeInstallation_fails_with_ISE_if_not_started() {
597     expectISENotStarted();
598
599     underTest.finalizeInstallation();
600   }
601
602   @Test
603   public void finalizeInstallation_fails_with_ISE_after_start() {
604     underTest.start();
605
606     expectedException.expect(IllegalStateException.class);
607     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])");
608
609     underTest.finalizeInstallation();
610   }
611
612   @Test
613   public void finalizeInstallation_fails_with_ISE_after_newEditionWithoutInstall() {
614     underTest.start();
615     underTest.newEditionWithoutInstall(randomAlphanumeric(3));
616
617     expectedException.expect(IllegalStateException.class);
618     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])");
619
620     underTest.finalizeInstallation();
621   }
622
623   @Test
624   public void finalizeInstallation_fails_with_ISE_after_startAutomaticInstall() {
625     underTest.start();
626     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
627
628     expectedException.expect(IllegalStateException.class);
629     expectedException.expectMessage("Can't move to NONE when status is AUTOMATIC_IN_PROGRESS (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])");
630
631     underTest.finalizeInstallation();
632   }
633
634   @Test
635   public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_manualInstallationReady() {
636     underTest.start();
637     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
638     underTest.automaticInstallReady();
639
640     PendingStatus newStatus = underTest.finalizeInstallation();
641
642     assertThat(newStatus).isEqualTo(NONE);
643     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
644     assertThat(underTest.getPendingEditionKey()).isEmpty();
645     assertThat(underTest.getPendingLicense()).isEmpty();
646     assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
647   }
648
649   @Test
650   public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_startManualInstall() {
651     underTest.start();
652     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
653
654     PendingStatus newStatus = underTest.finalizeInstallation();
655
656     assertThat(newStatus).isEqualTo(NONE);
657     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
658     assertThat(underTest.getPendingEditionKey()).isEmpty();
659     assertThat(underTest.getPendingLicense()).isEmpty();
660     assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
661   }
662
663   @Test
664   public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_uninstall() {
665     underTest.start();
666     String value = randomAlphanumeric(10);
667     underTest.newEditionWithoutInstall(value);
668     underTest.uninstall();
669
670     PendingStatus newStatus = underTest.finalizeInstallation();
671
672     assertThat(newStatus).isEqualTo(NONE);
673     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
674     assertThat(underTest.getPendingEditionKey()).isEmpty();
675     assertThat(underTest.getPendingLicense()).isEmpty();
676     assertThat(underTest.getCurrentEditionKey()).isEmpty();
677   }
678
679   @Test
680   public void finalizeInstallation_overwrites_current_edition_and_clear_pending_fields_after_startManualInstall() {
681     String value = randomAlphanumeric(10);
682     dbTester.properties().insertInternal("currentEditionKey", value);
683     underTest.start();
684     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
685
686     PendingStatus newStatus = underTest.finalizeInstallation();
687
688     assertThat(newStatus).isEqualTo(NONE);
689     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
690     assertThat(underTest.getPendingEditionKey()).isEmpty();
691     assertThat(underTest.getPendingLicense()).isEmpty();
692     assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
693   }
694
695   @Test
696   public void finalizeInstallation_fails_with_ISE_after_finalizeInstallation() {
697     underTest.start();
698     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
699     underTest.finalizeInstallation();
700
701     expectedException.expect(IllegalStateException.class);
702     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])");
703
704     underTest.finalizeInstallation();
705   }
706
707   private void expectISENotStarted() {
708     expectedException.expect(IllegalStateException.class);
709     expectedException.expectMessage("StandaloneEditionManagementStateImpl is not started");
710   }
711
712 }