]> source.dussan.org Git - sonarqube.git/blob
f999efc09e4858e25ebb1cf1991daece40d1a55f
[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 javax.annotation.Nullable;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.ExpectedException;
28 import org.sonar.api.utils.System2;
29 import org.sonar.db.DbClient;
30 import org.sonar.db.DbTester;
31 import org.sonar.server.edition.EditionManagementState.PendingStatus;
32
33 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
34 import static org.assertj.core.api.Assertions.assertThat;
35 import static org.sonar.server.edition.EditionManagementState.PendingStatus.AUTOMATIC_IN_PROGRESS;
36 import static org.sonar.server.edition.EditionManagementState.PendingStatus.AUTOMATIC_READY;
37 import static org.sonar.server.edition.EditionManagementState.PendingStatus.MANUAL_IN_PROGRESS;
38 import static org.sonar.server.edition.EditionManagementState.PendingStatus.NONE;
39 import static org.sonar.server.edition.EditionManagementState.PendingStatus.UNINSTALL_IN_PROGRESS;
40
41 public class StandaloneEditionManagementStateImplTest {
42   private static final License LICENSE_WITHOUT_PLUGINS = new License(randomAlphanumeric(3), Collections.emptyList(), randomAlphanumeric(10));
43
44   @Rule
45   public DbTester dbTester = DbTester.create(System2.INSTANCE);
46   @Rule
47   public ExpectedException expectedException = ExpectedException.none();
48
49   @Nullable
50   private String nullableErrorMessage = new Random().nextBoolean() ? null : randomAlphanumeric(5);
51   private String errorMessage = randomAlphanumeric(5);
52   private DbClient dbClient = dbTester.getDbClient();
53   private final StandaloneEditionManagementStateImpl underTest = new StandaloneEditionManagementStateImpl(dbClient);
54
55   @Test
56   public void getCurrentEditionKey_fails_with_ISE_if_start_has_not_been_called() {
57     expectISENotStarted();
58
59     underTest.getCurrentEditionKey();
60   }
61
62   @Test
63   public void getCurrentEditionKey_returns_empty_when_internal_properties_table_is_empty() {
64     underTest.start();
65
66     assertThat(underTest.getCurrentEditionKey()).isEmpty();
67   }
68
69   @Test
70   public void getCurrentEditionKey_returns_value_in_db_for_key_currentEditionKey() {
71     String value = randomAlphanumeric(10);
72     dbTester.properties().insertInternal("currentEditionKey", value);
73     underTest.start();
74
75     assertThat(underTest.getCurrentEditionKey()).contains(value);
76   }
77
78   @Test
79   public void getCurrentEditionKey_returns_empty_when_value_in_db_is_empty_for_key_currentEditionKey() {
80     dbTester.properties().insertEmptyInternal("currentEditionKey");
81     underTest.start();
82
83     assertThat(underTest.getCurrentEditionKey()).isEmpty();
84   }
85
86   @Test
87   public void getPendingInstallationStatus_fails_with_ISE_if_start_has_not_been_called() {
88     expectISENotStarted();
89
90     underTest.getPendingInstallationStatus();
91   }
92
93   @Test
94   public void getPendingInstallationStatus_returns_NONE_when_internal_properties_table_is_empty() {
95     underTest.start();
96
97     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
98   }
99
100   @Test
101   public void getPendingInstallationStatus_returns_value_in_db_for_key_pendingInstallStatus() {
102     PendingStatus value = PendingStatus.values()[new Random().nextInt(PendingStatus.values().length)];
103     dbTester.properties().insertInternal("pendingInstallStatus", value.name());
104     underTest.start();
105
106     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(value);
107   }
108
109   @Test
110   public void getPendingInstallationStatus_returns_NONE_when_value_in_db_is_empty_for_key_pendingInstallStatus() {
111     dbTester.properties().insertEmptyInternal("pendingInstallStatus");
112     underTest.start();
113
114     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
115   }
116
117   @Test
118   public void start_fails_when_value_in_db_for_key_pendingInstallStatus_cannot_be_parsed_to_enum() {
119     String value = randomAlphanumeric(30);
120     dbTester.properties().insertInternal("pendingInstallStatus", value);
121
122     expectedException.expect(IllegalArgumentException.class);
123     expectedException.expectMessage("No enum constant org.sonar.server.edition.EditionManagementState.PendingStatus." + value);
124
125     underTest.start();
126   }
127
128   @Test
129   public void getPendingEditionKey_fails_with_ISE_if_start_has_not_been_called() {
130     expectISENotStarted();
131
132     underTest.getPendingEditionKey();
133   }
134
135   @Test
136   public void getPendingEditionKey_returns_empty_when_internal_properties_table_is_empty() {
137     underTest.start();
138
139     assertThat(underTest.getPendingEditionKey()).isEmpty();
140   }
141
142   @Test
143   public void getPendingEditionKey_returns_value_in_db_for_key_pendingEditionKey() {
144     String value = randomAlphanumeric(10);
145     dbTester.properties().insertInternal("pendingEditionKey", value);
146     underTest.start();
147
148     assertThat(underTest.getPendingEditionKey()).contains(value);
149   }
150
151   @Test
152   public void getPendingEditionKey_returns_empty_when_value_in_db_is_empty_for_key_pendingEditionKey() {
153     dbTester.properties().insertEmptyInternal("pendingEditionKey");
154     underTest.start();
155
156     assertThat(underTest.getPendingEditionKey()).isEmpty();
157   }
158
159   @Test
160   public void getPendingLicense_fails_with_ISE_if_start_has_not_been_called() {
161     expectISENotStarted();
162
163     underTest.getPendingLicense();
164   }
165
166   @Test
167   public void getPendingLicense_returns_empty_when_internal_properties_table_is_empty() {
168     underTest.start();
169
170     assertThat(underTest.getPendingLicense()).isEmpty();
171   }
172
173   @Test
174   public void getPendingLicense_returns_empty_value_in_db_for_key_pendingLicense() {
175     String value = randomAlphanumeric(10);
176     dbTester.properties().insertInternal("pendingLicense", value);
177     underTest.start();
178
179     assertThat(underTest.getPendingLicense()).contains(value);
180   }
181
182   @Test
183   public void getPendingLicense_returns_empty_when_value_in_db_is_empty_for_key_pendingLicense() {
184     dbTester.properties().insertEmptyInternal("pendingLicense");
185     underTest.start();
186
187     assertThat(underTest.getPendingLicense()).isEmpty();
188   }
189
190   @Test
191   public void getInstallErrorMessage_fails_with_ISE_if_start_has_not_been_called() {
192     expectISENotStarted();
193
194     underTest.getInstallErrorMessage();
195   }
196
197   @Test
198   public void getInstallErrorMessage_returns_empty_when_internal_properties_table_is_empty() {
199     underTest.start();
200
201     assertThat(underTest.getInstallErrorMessage()).isEmpty();
202   }
203
204   @Test
205   public void getInstallErrorMessage_returns_value_in_db_for_key_pendingEditionKey() {
206     String value = randomAlphanumeric(10);
207     dbTester.properties().insertInternal("installError", value);
208     underTest.start();
209
210     assertThat(underTest.getInstallErrorMessage()).contains(value);
211   }
212
213   @Test
214   public void getInstallErrorMessage_returns_empty_when_value_in_db_is_empty_for_key_pendingEditionKey() {
215     dbTester.properties().insertEmptyInternal("installError");
216     underTest.start();
217
218     assertThat(underTest.getInstallErrorMessage()).isEmpty();
219   }
220
221   @Test
222   public void startAutomaticInstall_fails_with_ISE_if_not_started() {
223     expectISENotStarted();
224
225     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
226   }
227
228   @Test
229   public void startAutomaticInstall_fails_with_NPE_if_license_is_null() {
230     underTest.start();
231
232     expectedException.expect(NullPointerException.class);
233     expectedException.expectMessage("license can't be null");
234
235     underTest.startAutomaticInstall(null);
236   }
237
238   @Test
239   public void startAutomaticInstall_sets_pending_fields_after_start() {
240     underTest.start();
241
242     PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
243
244     assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS);
245     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS);
246     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
247     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
248     assertThat(underTest.getCurrentEditionKey()).isEmpty();
249     assertThat(underTest.getInstallErrorMessage()).isEmpty();
250   }
251
252   @Test
253   public void startAutomaticInstall_sets_pending_fields_after_start_with_existing_currentEditionKey() {
254     String value = randomAlphanumeric(10);
255     dbTester.properties().insertInternal("currentEditionKey", value);
256     underTest.start();
257
258     PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
259
260     assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS);
261     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS);
262     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
263     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
264     assertThat(underTest.getCurrentEditionKey()).contains(value);
265     assertThat(underTest.getInstallErrorMessage()).isEmpty();
266   }
267
268   @Test
269   public void startAutomaticInstall_sets_pending_fields_after_newEditionWithoutInstall() {
270     String value = randomAlphanumeric(10);
271     underTest.start();
272     underTest.newEditionWithoutInstall(value);
273
274     PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
275
276     assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS);
277     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS);
278     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
279     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
280     assertThat(underTest.getCurrentEditionKey()).contains(value);
281     assertThat(underTest.getInstallErrorMessage()).isEmpty();
282   }
283
284   @Test
285   public void startAutomaticInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
286     underTest.start();
287     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
288
289     expectedException.expect(IllegalStateException.class);
290     expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
291
292     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
293   }
294
295   @Test
296   public void startAutomaticInstall_fails_with_ISE_if_called_after_automaticInstallReady() {
297     underTest.start();
298     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
299     underTest.automaticInstallReady();
300
301     expectedException.expect(IllegalStateException.class);
302     expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is AUTOMATIC_READY (should be any of [NONE])");
303
304     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
305   }
306
307   @Test
308   public void startAutomaticInstall_fails_with_ISE_if_called_after_manualInstall() {
309     underTest.start();
310     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
311
312     expectedException.expect(IllegalStateException.class);
313     expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
314
315     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
316   }
317
318   @Test
319   public void startAutomaticInstall_fails_with_ISE_if_called_after_uninstall() {
320     underTest.start();
321     underTest.newEditionWithoutInstall("foo");
322     underTest.uninstall();
323
324     expectedException.expect(IllegalStateException.class);
325     expectedException.expectMessage("Can't move to AUTOMATIC_IN_PROGRESS when status is UNINSTALL_IN_PROGRESS (should be any of [NONE])");
326
327     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
328   }
329
330   @Test
331   public void uninstall_fails_with_ISE_if_not_started() {
332     expectISENotStarted();
333
334     underTest.uninstall();
335   }
336
337   @Test
338   public void uninstall_resets_fields_after_start_and_install() {
339     String value = randomAlphanumeric(10);
340
341     underTest.start();
342     underTest.newEditionWithoutInstall(value);
343     PendingStatus newStatus = underTest.uninstall();
344
345     assertThat(newStatus).isEqualTo(UNINSTALL_IN_PROGRESS);
346     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(UNINSTALL_IN_PROGRESS);
347     assertThat(underTest.getPendingEditionKey()).isEmpty();
348     assertThat(underTest.getPendingLicense()).isEmpty();
349     assertThat(underTest.getCurrentEditionKey()).isEmpty();
350   }
351
352   @Test
353   public void uninstall_fails_with_ISE_if_called_after_uninstall() {
354     String value = randomAlphanumeric(10);
355     underTest.start();
356     underTest.newEditionWithoutInstall(value);
357     underTest.uninstall();
358
359     expectedException.expect(IllegalStateException.class);
360     expectedException.expectMessage("Can't move to UNINSTALL_IN_PROGRESS when status is UNINSTALL_IN_PROGRESS (should be any of [NONE])");
361
362     underTest.uninstall();
363   }
364
365   @Test
366   public void uninstall_resets_fields_after_newEditionWithoutInstall() {
367     String value = randomAlphanumeric(10);
368     underTest.start();
369     underTest.newEditionWithoutInstall(value);
370
371     PendingStatus newStatus = underTest.uninstall();
372
373     assertThat(newStatus).isEqualTo(UNINSTALL_IN_PROGRESS);
374     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(UNINSTALL_IN_PROGRESS);
375     assertThat(underTest.getPendingEditionKey()).isEmpty();
376     assertThat(underTest.getPendingLicense()).isEmpty();
377     assertThat(underTest.getCurrentEditionKey()).isEmpty();
378   }
379
380   @Test
381   public void uninstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
382     underTest.start();
383     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
384
385     expectedException.expect(IllegalStateException.class);
386     expectedException.expectMessage("Can't move to UNINSTALL_IN_PROGRESS when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
387
388     underTest.uninstall();
389   }
390
391   @Test
392   public void uninstall_fails_with_ISE_if_called_after_automaticInstallReady() {
393     underTest.start();
394     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
395     underTest.automaticInstallReady();
396
397     expectedException.expect(IllegalStateException.class);
398     expectedException.expectMessage("Can't move to UNINSTALL_IN_PROGRESS when status is AUTOMATIC_READY (should be any of [NONE])");
399
400     underTest.uninstall();
401   }
402
403   @Test
404   public void uninstall_fails_with_ISE_if_called_after_manualInstall() {
405     underTest.start();
406     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
407
408     expectedException.expect(IllegalStateException.class);
409     expectedException.expectMessage("Can't move to UNINSTALL_IN_PROGRESS when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
410
411     underTest.uninstall();
412   }
413
414   @Test
415   public void startAutomaticInstall_succeeds_if_called_after_installFailed_and_clears_errorMessage() {
416     underTest.start();
417     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
418     underTest.installFailed(errorMessage);
419
420     PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
421
422     assertThat(newStatus).isEqualTo(AUTOMATIC_IN_PROGRESS);
423     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_IN_PROGRESS);
424     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
425     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
426     assertThat(underTest.getCurrentEditionKey()).isEmpty();
427     assertThat(underTest.getInstallErrorMessage()).isEmpty();
428   }
429
430   @Test
431   public void startManualInstall_fails_with_ISE_if_not_started() {
432     expectISENotStarted();
433
434     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
435   }
436
437   @Test
438   public void startManualInstall_fails_with_NPE_if_license_is_null() {
439     underTest.start();
440
441     expectedException.expect(NullPointerException.class);
442     expectedException.expectMessage("license can't be null");
443
444     underTest.startManualInstall(null);
445   }
446
447   @Test
448   public void startManualInstall_sets_pending_fields_after_start() {
449     underTest.start();
450
451     PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
452
453     assertThat(newStatus).isEqualTo(MANUAL_IN_PROGRESS);
454     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(MANUAL_IN_PROGRESS);
455     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
456     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
457     assertThat(underTest.getCurrentEditionKey()).isEmpty();
458     assertThat(underTest.getInstallErrorMessage()).isEmpty();
459   }
460
461   @Test
462   public void startManualInstall_sets_pending_fields_after_start_with_existing_currentEditionKey() {
463     String value = randomAlphanumeric(10);
464     dbTester.properties().insertInternal("currentEditionKey", value);
465     underTest.start();
466
467     PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
468
469     assertThat(newStatus).isEqualTo(MANUAL_IN_PROGRESS);
470     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(MANUAL_IN_PROGRESS);
471     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
472     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
473     assertThat(underTest.getCurrentEditionKey()).contains(value);
474     assertThat(underTest.getInstallErrorMessage()).isEmpty();
475   }
476
477   @Test
478   public void startManualInstall_sets_pending_fields_after_newEditionWithoutInstall() {
479     String value = randomAlphanumeric(10);
480     underTest.start();
481     underTest.newEditionWithoutInstall(value);
482
483     PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
484
485     assertThat(newStatus).isEqualTo(MANUAL_IN_PROGRESS);
486     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(MANUAL_IN_PROGRESS);
487     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
488     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
489     assertThat(underTest.getCurrentEditionKey()).contains(value);
490     assertThat(underTest.getInstallErrorMessage()).isEmpty();
491   }
492
493   @Test
494   public void startManualInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
495     underTest.start();
496     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
497
498     expectedException.expect(IllegalStateException.class);
499     expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
500
501     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
502   }
503
504   @Test
505   public void startManualInstall_fails_with_ISE_if_called_after_automaticInstallReady() {
506     underTest.start();
507     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
508     underTest.automaticInstallReady();
509
510     expectedException.expect(IllegalStateException.class);
511     expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is AUTOMATIC_READY (should be any of [NONE])");
512
513     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
514   }
515
516   @Test
517   public void startManualInstall_fails_with_ISE_if_called_after_manualInstall() {
518     underTest.start();
519     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
520
521     expectedException.expect(IllegalStateException.class);
522     expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
523
524     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
525   }
526
527   @Test
528   public void startManualInstall_fails_with_ISE_if_called_after_uninstall() {
529     underTest.start();
530     underTest.newEditionWithoutInstall("foo");
531     underTest.uninstall();
532
533     expectedException.expect(IllegalStateException.class);
534     expectedException.expectMessage("Can't move to MANUAL_IN_PROGRESS when status is UNINSTALL_IN_PROGRESS (should be any of [NONE])");
535
536     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
537   }
538
539   @Test
540   public void startManualInstall_succeeds_if_called_after_installFailed_and_clears_errorMessage() {
541     underTest.start();
542     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
543     underTest.installFailed(errorMessage);
544
545     PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
546
547     assertThat(newStatus).isEqualTo(MANUAL_IN_PROGRESS);
548     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(MANUAL_IN_PROGRESS);
549     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
550     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
551     assertThat(underTest.getCurrentEditionKey()).isEmpty();
552     assertThat(underTest.getInstallErrorMessage()).isEmpty();
553   }
554
555   @Test
556   public void automaticInstallReady_fails_with_ISE_if_not_started() {
557     expectISENotStarted();
558
559     underTest.automaticInstallReady();
560   }
561
562   @Test
563   public void automaticInstallReady_fails_with_ISE_if_called() {
564     underTest.start();
565
566     expectedException.expect(IllegalStateException.class);
567     expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS])");
568
569     underTest.automaticInstallReady();
570   }
571
572   @Test
573   public void automaticInstallReady_fails_with_ISE_if_called_after_manualInstall() {
574     underTest.start();
575     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
576
577     expectedException.expect(IllegalStateException.class);
578     expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is MANUAL_IN_PROGRESS (should be any of [AUTOMATIC_IN_PROGRESS])");
579
580     underTest.automaticInstallReady();
581   }
582
583   @Test
584   public void automaticInstallReady_fails_with_ISE_if_called_after_newEditionWithoutInstall() {
585     underTest.start();
586     underTest.newEditionWithoutInstall("foo");
587
588     expectedException.expect(IllegalStateException.class);
589     expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS])");
590
591     underTest.automaticInstallReady();
592   }
593
594   @Test
595   public void automaticInstallReady_fails_with_ISE_if_called_after_uninstall() {
596     underTest.start();
597     underTest.newEditionWithoutInstall("foo");
598     underTest.uninstall();
599
600     expectedException.expect(IllegalStateException.class);
601     expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is UNINSTALL_IN_PROGRESS (should be any of [AUTOMATIC_IN_PROGRESS])");
602
603     underTest.automaticInstallReady();
604   }
605
606   @Test
607   public void automaticInstallReady_fails_with_ISE_if_called_after_startManualInstall() {
608     underTest.start();
609     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
610
611     expectedException.expect(IllegalStateException.class);
612     expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is MANUAL_IN_PROGRESS (should be any of [AUTOMATIC_IN_PROGRESS])");
613
614     underTest.automaticInstallReady();
615   }
616
617   @Test
618   public void automaticInstallReady_after_startAutomaticInstall_changes_status_to_AUTOMATIC_READY_but_does_not_change_editions() {
619     underTest.start();
620     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
621
622     PendingStatus newStatus = underTest.automaticInstallReady();
623
624     assertThat(newStatus).isEqualTo(AUTOMATIC_READY);
625     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(AUTOMATIC_READY);
626     assertThat(underTest.getPendingEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
627     assertThat(underTest.getPendingLicense()).contains(LICENSE_WITHOUT_PLUGINS.getContent());
628     assertThat(underTest.getCurrentEditionKey()).isEmpty();
629     assertThat(underTest.getInstallErrorMessage()).isEmpty();
630   }
631
632   @Test
633   public void automaticInstallReady_fails_with_ISE_if_called_after_installFailed() {
634     underTest.start();
635     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
636     underTest.installFailed(nullableErrorMessage);
637
638     expectedException.expect(IllegalStateException.class);
639     expectedException.expectMessage("Can't move to AUTOMATIC_READY when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS])");
640
641     underTest.automaticInstallReady();
642   }
643
644   @Test
645   public void newEditionWithoutInstall_fails_with_ISE_if_not_started() {
646     expectISENotStarted();
647
648     underTest.newEditionWithoutInstall(randomAlphanumeric(3));
649   }
650
651   @Test
652   public void newEditionWithoutInstall_fails_with_NPE_if_newEditionKey_is_null() {
653     underTest.start();
654
655     expectedException.expect(NullPointerException.class);
656     expectedException.expectMessage("newEditionKey can't be null");
657
658     underTest.newEditionWithoutInstall(null);
659   }
660
661   @Test
662   public void newEditionWithoutInstall_fails_with_IAE_if_newEditionKey_is_empty() {
663     underTest.start();
664
665     expectedException.expect(IllegalArgumentException.class);
666     expectedException.expectMessage("newEditionKey can't be empty");
667
668     underTest.newEditionWithoutInstall("");
669   }
670
671   @Test
672   public void newEditionWithoutInstall_changes_current_edition() {
673     String newEditionKey = randomAlphanumeric(3);
674     underTest.start();
675
676     PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey);
677
678     assertThat(newStatus).isEqualTo(NONE);
679     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
680     assertThat(underTest.getPendingEditionKey()).isEmpty();
681     assertThat(underTest.getPendingLicense()).isEmpty();
682     assertThat(underTest.getCurrentEditionKey()).contains(newEditionKey);
683     assertThat(underTest.getInstallErrorMessage()).isEmpty();
684   }
685
686   @Test
687   public void newEditionWithoutInstall_overwrite_current_edition() {
688     String newEditionKey = randomAlphanumeric(3);
689     underTest.start();
690
691     PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey);
692
693     assertThat(newStatus).isEqualTo(NONE);
694     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
695     assertThat(underTest.getPendingEditionKey()).isEmpty();
696     assertThat(underTest.getPendingLicense()).isEmpty();
697     assertThat(underTest.getCurrentEditionKey()).contains(newEditionKey);
698     assertThat(underTest.getInstallErrorMessage()).isEmpty();
699   }
700
701   @Test
702   public void newEditionWithoutInstall_overwrites_from_previous_newEditionWithoutInstall() {
703     String newEditionKey1 = randomAlphanumeric(3);
704     String newEditionKey2 = randomAlphanumeric(3);
705     underTest.start();
706     underTest.newEditionWithoutInstall(newEditionKey1);
707
708     PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey2);
709
710     assertThat(newStatus).isEqualTo(NONE);
711     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
712     assertThat(underTest.getPendingEditionKey()).isEmpty();
713     assertThat(underTest.getPendingLicense()).isEmpty();
714     assertThat(underTest.getCurrentEditionKey()).contains(newEditionKey2);
715     assertThat(underTest.getInstallErrorMessage()).isEmpty();
716   }
717
718   @Test
719   public void newEditionWithoutInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
720     String newEditionKey = randomAlphanumeric(3);
721     underTest.start();
722     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
723
724     expectedException.expect(IllegalStateException.class);
725     expectedException.expectMessage("Can't move to NONE when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
726
727     underTest.newEditionWithoutInstall(newEditionKey);
728   }
729
730   @Test
731   public void newEditionWithoutInstall_fails_with_ISE_if_called_after_startManualInstall() {
732     String newEditionKey = randomAlphanumeric(3);
733     underTest.start();
734     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
735
736     expectedException.expect(IllegalStateException.class);
737     expectedException.expectMessage("Can't move to NONE when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
738
739     underTest.newEditionWithoutInstall(newEditionKey);
740   }
741
742   @Test
743   public void newEditionWithoutInstall_fails_with_ISE_if_called_after_uninstall() {
744     String newEditionKey = randomAlphanumeric(3);
745     underTest.start();
746     underTest.newEditionWithoutInstall("foo");
747     underTest.uninstall();
748
749     expectedException.expect(IllegalStateException.class);
750     expectedException.expectMessage("Can't move to NONE when status is UNINSTALL_IN_PROGRESS (should be any of [NONE])");
751
752     underTest.newEditionWithoutInstall(newEditionKey);
753   }
754
755   @Test
756   public void newEditionWithoutInstall_succeeds_if_called_after_installFailed_and_clear_error_message() {
757     String newEditionKey = randomAlphanumeric(3);
758     underTest.start();
759     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
760     underTest.installFailed(errorMessage);
761
762     PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey);
763
764     assertThat(newStatus).isEqualTo(NONE);
765     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
766     assertThat(underTest.getPendingEditionKey()).isEmpty();
767     assertThat(underTest.getPendingLicense()).isEmpty();
768     assertThat(underTest.getCurrentEditionKey()).contains(newEditionKey);
769     assertThat(underTest.getInstallErrorMessage()).isEmpty();
770   }
771
772   @Test
773   public void finalizeInstallation_fails_with_ISE_if_not_started() {
774     expectISENotStarted();
775
776     underTest.finalizeInstallation();
777   }
778
779   @Test
780   public void finalizeInstallation_fails_with_ISE_after_start() {
781     underTest.start();
782
783     expectedException.expect(IllegalStateException.class);
784     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])");
785
786     underTest.finalizeInstallation();
787   }
788
789   @Test
790   public void finalizeInstallation_fails_with_ISE_after_newEditionWithoutInstall() {
791     underTest.start();
792     underTest.newEditionWithoutInstall(randomAlphanumeric(3));
793
794     expectedException.expect(IllegalStateException.class);
795     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])");
796
797     underTest.finalizeInstallation();
798   }
799
800   @Test
801   public void finalizeInstallation_fails_with_ISE_after_startAutomaticInstall() {
802     underTest.start();
803     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
804
805     expectedException.expect(IllegalStateException.class);
806     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])");
807
808     underTest.finalizeInstallation();
809   }
810
811   @Test
812   public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_manualInstallationReady() {
813     underTest.start();
814     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
815     underTest.automaticInstallReady();
816
817     PendingStatus newStatus = underTest.finalizeInstallation();
818
819     assertThat(newStatus).isEqualTo(NONE);
820     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
821     assertThat(underTest.getPendingEditionKey()).isEmpty();
822     assertThat(underTest.getPendingLicense()).isEmpty();
823     assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
824     assertThat(underTest.getInstallErrorMessage()).isEmpty();
825   }
826
827   @Test
828   public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_startManualInstall() {
829     underTest.start();
830     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
831
832     PendingStatus newStatus = underTest.finalizeInstallation();
833
834     assertThat(newStatus).isEqualTo(NONE);
835     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
836     assertThat(underTest.getPendingEditionKey()).isEmpty();
837     assertThat(underTest.getPendingLicense()).isEmpty();
838     assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
839     assertThat(underTest.getInstallErrorMessage()).isEmpty();
840   }
841
842   @Test
843   public void finalizeInstallation_overwrites_current_edition_and_clear_pending_fields_after_startManualInstall() {
844     String value = randomAlphanumeric(10);
845     dbTester.properties().insertInternal("currentEditionKey", value);
846     underTest.start();
847     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
848
849     PendingStatus newStatus = underTest.finalizeInstallation();
850
851     assertThat(newStatus).isEqualTo(NONE);
852     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
853     assertThat(underTest.getPendingEditionKey()).isEmpty();
854     assertThat(underTest.getPendingLicense()).isEmpty();
855     assertThat(underTest.getCurrentEditionKey()).contains(LICENSE_WITHOUT_PLUGINS.getEditionKey());
856     assertThat(underTest.getInstallErrorMessage()).isEmpty();
857   }
858
859   @Test
860   public void finalizeInstallation_fails_with_ISE_after_installFailed() {
861     underTest.start();
862     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
863     underTest.installFailed(nullableErrorMessage);
864
865     expectedException.expect(IllegalStateException.class);
866     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])");
867
868     underTest.finalizeInstallation();
869   }
870
871   @Test
872   public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_uninstall() {
873     underTest.start();
874     String value = randomAlphanumeric(10);
875     underTest.newEditionWithoutInstall(value);
876     underTest.uninstall();
877
878     PendingStatus newStatus = underTest.finalizeInstallation();
879
880     assertThat(newStatus).isEqualTo(NONE);
881     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
882     assertThat(underTest.getPendingEditionKey()).isEmpty();
883     assertThat(underTest.getPendingLicense()).isEmpty();
884     assertThat(underTest.getCurrentEditionKey()).isEmpty();
885   }
886
887   @Test
888   public void finalizeInstallation_fails_with_ISE_after_finalizeInstallation() {
889     underTest.start();
890     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
891     underTest.finalizeInstallation();
892
893     expectedException.expect(IllegalStateException.class);
894     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_READY, MANUAL_IN_PROGRESS, UNINSTALL_IN_PROGRESS])");
895
896     underTest.finalizeInstallation();
897   }
898
899   @Test
900   public void installFailed_fails_with_ISE_if_not_started() {
901     expectISENotStarted();
902
903     underTest.installFailed(nullableErrorMessage);
904   }
905
906   @Test
907   public void installFailed_fails_with_ISE_if_called_after_start() {
908     underTest.start();
909
910     expectedException.expect(IllegalStateException.class);
911     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS, AUTOMATIC_READY, MANUAL_IN_PROGRESS])");
912
913     underTest.installFailed(nullableErrorMessage);
914   }
915
916   @Test
917   public void installFailed_after_manualInstall_changes_status_to_NONE_stores_non_null_error_message_and_clear_pending_fields() {
918     underTest.start();
919     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
920     String errorMessage = randomAlphanumeric(4);
921
922     PendingStatus newStatus = underTest.installFailed(errorMessage);
923
924     assertThat(newStatus).isEqualTo(NONE);
925     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
926     assertThat(underTest.getPendingEditionKey()).isEmpty();
927     assertThat(underTest.getPendingLicense()).isEmpty();
928     assertThat(underTest.getCurrentEditionKey()).isEmpty();
929     assertThat(underTest.getInstallErrorMessage()).contains(errorMessage);
930   }
931
932   @Test
933   public void installFailed_after_manualInstall_changes_status_to_NONE_without_error_message_and_clear_pending_fields() {
934     underTest.start();
935     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
936
937     PendingStatus newStatus = underTest.installFailed(null);
938
939     assertThat(newStatus).isEqualTo(NONE);
940     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
941     assertThat(underTest.getPendingEditionKey()).isEmpty();
942     assertThat(underTest.getPendingLicense()).isEmpty();
943     assertThat(underTest.getCurrentEditionKey()).isEmpty();
944     assertThat(underTest.getInstallErrorMessage()).isEmpty();
945   }
946
947   @Test
948   public void installFailed_after_startAutomaticInstall_changes_status_to_NONE_stores_non_null_error_message_and_clear_pending_fields() {
949     underTest.start();
950     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
951     String errorMessage = randomAlphanumeric(4);
952
953     PendingStatus newStatus = underTest.installFailed(errorMessage);
954
955     assertThat(newStatus).isEqualTo(NONE);
956     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
957     assertThat(underTest.getPendingEditionKey()).isEmpty();
958     assertThat(underTest.getPendingLicense()).isEmpty();
959     assertThat(underTest.getCurrentEditionKey()).isEmpty();
960     assertThat(underTest.getInstallErrorMessage()).contains(errorMessage);
961   }
962
963   @Test
964   public void installFailed_after_startAutomaticInstall_changes_status_to_NONE_without_error_message_and_clear_pending_fields() {
965     underTest.start();
966     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
967
968     PendingStatus newStatus = underTest.installFailed(null);
969
970     assertThat(newStatus).isEqualTo(NONE);
971     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
972     assertThat(underTest.getPendingEditionKey()).isEmpty();
973     assertThat(underTest.getPendingLicense()).isEmpty();
974     assertThat(underTest.getCurrentEditionKey()).isEmpty();
975     assertThat(underTest.getInstallErrorMessage()).isEmpty();
976   }
977
978   @Test
979   public void installFailed_after_startAutomaticInstall_changes_status_to_NONE_stores_non_null_error_message_and_clear_pending_fields_when_current_install_exists() {
980     underTest.start();
981     String currentEdition = "current-edition";
982     underTest.newEditionWithoutInstall(currentEdition);
983     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
984     String errorMessage = randomAlphanumeric(4);
985
986     PendingStatus newStatus = underTest.installFailed(errorMessage);
987
988     assertThat(newStatus).isEqualTo(NONE);
989     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
990     assertThat(underTest.getPendingEditionKey()).isEmpty();
991     assertThat(underTest.getPendingLicense()).isEmpty();
992     assertThat(underTest.getCurrentEditionKey()).contains(currentEdition);
993     assertThat(underTest.getInstallErrorMessage()).contains(errorMessage);
994   }
995
996   @Test
997   public void installFailed_after_startAutomaticInstall_changes_status_to_NONE_without_error_message_and_clear_pending_fields_when_current_install_exists() {
998     underTest.start();
999     String currentEdition = "current-edition";
1000     underTest.newEditionWithoutInstall(currentEdition);
1001     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1002
1003     PendingStatus newStatus = underTest.installFailed(null);
1004
1005     assertThat(newStatus).isEqualTo(NONE);
1006     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
1007     assertThat(underTest.getPendingEditionKey()).isEmpty();
1008     assertThat(underTest.getPendingLicense()).isEmpty();
1009     assertThat(underTest.getCurrentEditionKey()).contains(currentEdition);
1010     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1011   }
1012
1013   @Test
1014   public void installFailed_considers_empty_message_as_no_message() {
1015     underTest.start();
1016     underTest.newEditionWithoutInstall("current-edition");
1017     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1018
1019     underTest.installFailed("");
1020
1021     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1022   }
1023
1024   @Test
1025   public void installFailed_considers_empty_message_after_trim_as_no_message() {
1026     underTest.start();
1027     underTest.newEditionWithoutInstall("current-edition");
1028     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1029
1030     underTest.installFailed("  ");
1031
1032     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1033   }
1034
1035   @Test
1036   public void installFailed_after_automaticInstallReady_changes_status_to_NONE_stores_non_null_error_message_and_clear_pending_fields_when_current_install_exists() {
1037     underTest.start();
1038     String currentEdition = "current-edition";
1039     underTest.newEditionWithoutInstall(currentEdition);
1040     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1041     underTest.automaticInstallReady();
1042     String errorMessage = randomAlphanumeric(4);
1043
1044     PendingStatus newStatus = underTest.installFailed(errorMessage);
1045
1046     assertThat(newStatus).isEqualTo(NONE);
1047     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
1048     assertThat(underTest.getPendingEditionKey()).isEmpty();
1049     assertThat(underTest.getPendingLicense()).isEmpty();
1050     assertThat(underTest.getCurrentEditionKey()).contains(currentEdition);
1051     assertThat(underTest.getInstallErrorMessage()).contains(errorMessage);
1052   }
1053
1054   @Test
1055   public void installFailed_after_automaticInstallReady_changes_status_to_NONE_without_error_message_and_clear_pending_fields_when_current_install_exists() {
1056     underTest.start();
1057     String currentEdition = "current-edition";
1058     underTest.newEditionWithoutInstall(currentEdition);
1059     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1060     underTest.automaticInstallReady();
1061
1062     PendingStatus newStatus = underTest.installFailed(null);
1063
1064     assertThat(newStatus).isEqualTo(NONE);
1065     assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
1066     assertThat(underTest.getPendingEditionKey()).isEmpty();
1067     assertThat(underTest.getPendingLicense()).isEmpty();
1068     assertThat(underTest.getCurrentEditionKey()).contains(currentEdition);
1069     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1070   }
1071
1072   @Test
1073   public void installFailed_fails_with_ISE_after_installFailed() {
1074     underTest.start();
1075     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1076     underTest.installFailed(nullableErrorMessage);
1077
1078     expectedException.expect(IllegalStateException.class);
1079     expectedException.expectMessage("Can't move to NONE when status is NONE (should be any of [AUTOMATIC_IN_PROGRESS, AUTOMATIC_READY, MANUAL_IN_PROGRESS])");
1080
1081     underTest.installFailed(nullableErrorMessage);
1082   }
1083
1084   private void expectISENotStarted() {
1085     expectedException.expect(IllegalStateException.class);
1086     expectedException.expectMessage("StandaloneEditionManagementStateImpl is not started");
1087   }
1088
1089   @Test
1090   public void clearInstallErrorMessage_fails_with_ISE_if_not_started() {
1091     expectISENotStarted();
1092
1093     underTest.clearInstallErrorMessage();
1094   }
1095
1096   @Test
1097   public void clearInstallErrorMessage_succeeds_after_state() {
1098     underTest.start();
1099
1100     underTest.clearInstallErrorMessage();
1101
1102     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1103   }
1104
1105   @Test
1106   public void clearInstallErrorMessage_succeeds_after_manualInstall() {
1107     underTest.start();
1108     underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
1109
1110     underTest.clearInstallErrorMessage();
1111
1112     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1113   }
1114
1115   @Test
1116   public void clearInstallErrorMessage_succeeds_after_automaticInstall() {
1117     underTest.start();
1118     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1119
1120     underTest.clearInstallErrorMessage();
1121
1122     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1123   }
1124
1125   @Test
1126   public void clearInstallErrorMessage_succeeds_after_automaticInstallReady() {
1127     underTest.start();
1128     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1129     underTest.automaticInstallReady();
1130
1131     underTest.clearInstallErrorMessage();
1132
1133     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1134   }
1135
1136   @Test
1137   public void clearInstallErrorMessage_succeeds_after_automaticInstallFailed_and_clears_message() {
1138     underTest.start();
1139     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1140     underTest.installFailed(errorMessage);
1141
1142     underTest.clearInstallErrorMessage();
1143
1144     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1145   }
1146
1147   @Test
1148   public void clearInstallErrorMessage_succeeds_after_automaticInstallFailed_without_message() {
1149     underTest.start();
1150     underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1151     underTest.installFailed(null);
1152
1153     underTest.clearInstallErrorMessage();
1154
1155     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1156   }
1157
1158   @Test
1159   public void clearInstallErrorMessage_succeeds_after_newEditionWithoutInstall() {
1160     underTest.start();
1161     underTest.newEditionWithoutInstall(randomAlphanumeric(4));
1162
1163     underTest.clearInstallErrorMessage();
1164
1165     assertThat(underTest.getInstallErrorMessage()).isEmpty();
1166   }
1167
1168 }