3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.server.edition;
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;
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;
41 public class StandaloneEditionManagementStateImplTest {
42 private static final License LICENSE_WITHOUT_PLUGINS = new License(randomAlphanumeric(3), Collections.emptyList(), randomAlphanumeric(10));
45 public DbTester dbTester = DbTester.create(System2.INSTANCE);
47 public ExpectedException expectedException = ExpectedException.none();
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);
56 public void getCurrentEditionKey_fails_with_ISE_if_start_has_not_been_called() {
57 expectISENotStarted();
59 underTest.getCurrentEditionKey();
63 public void getCurrentEditionKey_returns_empty_when_internal_properties_table_is_empty() {
66 assertThat(underTest.getCurrentEditionKey()).isEmpty();
70 public void getCurrentEditionKey_returns_value_in_db_for_key_currentEditionKey() {
71 String value = randomAlphanumeric(10);
72 dbTester.properties().insertInternal("currentEditionKey", value);
75 assertThat(underTest.getCurrentEditionKey()).contains(value);
79 public void getCurrentEditionKey_returns_empty_when_value_in_db_is_empty_for_key_currentEditionKey() {
80 dbTester.properties().insertEmptyInternal("currentEditionKey");
83 assertThat(underTest.getCurrentEditionKey()).isEmpty();
87 public void getPendingInstallationStatus_fails_with_ISE_if_start_has_not_been_called() {
88 expectISENotStarted();
90 underTest.getPendingInstallationStatus();
94 public void getPendingInstallationStatus_returns_NONE_when_internal_properties_table_is_empty() {
97 assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
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());
106 assertThat(underTest.getPendingInstallationStatus()).isEqualTo(value);
110 public void getPendingInstallationStatus_returns_NONE_when_value_in_db_is_empty_for_key_pendingInstallStatus() {
111 dbTester.properties().insertEmptyInternal("pendingInstallStatus");
114 assertThat(underTest.getPendingInstallationStatus()).isEqualTo(NONE);
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);
122 expectedException.expect(IllegalArgumentException.class);
123 expectedException.expectMessage("No enum constant org.sonar.server.edition.EditionManagementState.PendingStatus." + value);
129 public void getPendingEditionKey_fails_with_ISE_if_start_has_not_been_called() {
130 expectISENotStarted();
132 underTest.getPendingEditionKey();
136 public void getPendingEditionKey_returns_empty_when_internal_properties_table_is_empty() {
139 assertThat(underTest.getPendingEditionKey()).isEmpty();
143 public void getPendingEditionKey_returns_value_in_db_for_key_pendingEditionKey() {
144 String value = randomAlphanumeric(10);
145 dbTester.properties().insertInternal("pendingEditionKey", value);
148 assertThat(underTest.getPendingEditionKey()).contains(value);
152 public void getPendingEditionKey_returns_empty_when_value_in_db_is_empty_for_key_pendingEditionKey() {
153 dbTester.properties().insertEmptyInternal("pendingEditionKey");
156 assertThat(underTest.getPendingEditionKey()).isEmpty();
160 public void getPendingLicense_fails_with_ISE_if_start_has_not_been_called() {
161 expectISENotStarted();
163 underTest.getPendingLicense();
167 public void getPendingLicense_returns_empty_when_internal_properties_table_is_empty() {
170 assertThat(underTest.getPendingLicense()).isEmpty();
174 public void getPendingLicense_returns_empty_value_in_db_for_key_pendingLicense() {
175 String value = randomAlphanumeric(10);
176 dbTester.properties().insertInternal("pendingLicense", value);
179 assertThat(underTest.getPendingLicense()).contains(value);
183 public void getPendingLicense_returns_empty_when_value_in_db_is_empty_for_key_pendingLicense() {
184 dbTester.properties().insertEmptyInternal("pendingLicense");
187 assertThat(underTest.getPendingLicense()).isEmpty();
191 public void getInstallErrorMessage_fails_with_ISE_if_start_has_not_been_called() {
192 expectISENotStarted();
194 underTest.getInstallErrorMessage();
198 public void getInstallErrorMessage_returns_empty_when_internal_properties_table_is_empty() {
201 assertThat(underTest.getInstallErrorMessage()).isEmpty();
205 public void getInstallErrorMessage_returns_value_in_db_for_key_pendingEditionKey() {
206 String value = randomAlphanumeric(10);
207 dbTester.properties().insertInternal("installError", value);
210 assertThat(underTest.getInstallErrorMessage()).contains(value);
214 public void getInstallErrorMessage_returns_empty_when_value_in_db_is_empty_for_key_pendingEditionKey() {
215 dbTester.properties().insertEmptyInternal("installError");
218 assertThat(underTest.getInstallErrorMessage()).isEmpty();
222 public void startAutomaticInstall_fails_with_ISE_if_not_started() {
223 expectISENotStarted();
225 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
229 public void startAutomaticInstall_fails_with_NPE_if_license_is_null() {
232 expectedException.expect(NullPointerException.class);
233 expectedException.expectMessage("license can't be null");
235 underTest.startAutomaticInstall(null);
239 public void startAutomaticInstall_sets_pending_fields_after_start() {
242 PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
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();
253 public void startAutomaticInstall_sets_pending_fields_after_start_with_existing_currentEditionKey() {
254 String value = randomAlphanumeric(10);
255 dbTester.properties().insertInternal("currentEditionKey", value);
258 PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
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();
269 public void startAutomaticInstall_sets_pending_fields_after_newEditionWithoutInstall() {
270 String value = randomAlphanumeric(10);
272 underTest.newEditionWithoutInstall(value);
274 PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
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();
285 public void startAutomaticInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
287 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
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])");
292 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
296 public void startAutomaticInstall_fails_with_ISE_if_called_after_automaticInstallReady() {
298 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
299 underTest.automaticInstallReady();
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])");
304 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
308 public void startAutomaticInstall_fails_with_ISE_if_called_after_manualInstall() {
310 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
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])");
315 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
319 public void startAutomaticInstall_fails_with_ISE_if_called_after_uninstall() {
321 underTest.newEditionWithoutInstall("foo");
322 underTest.uninstall();
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])");
327 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
331 public void uninstall_fails_with_ISE_if_not_started() {
332 expectISENotStarted();
334 underTest.uninstall();
338 public void uninstall_resets_fields_after_start_and_install() {
339 String value = randomAlphanumeric(10);
342 underTest.newEditionWithoutInstall(value);
343 PendingStatus newStatus = underTest.uninstall();
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();
353 public void uninstall_fails_with_ISE_if_called_after_uninstall() {
354 String value = randomAlphanumeric(10);
356 underTest.newEditionWithoutInstall(value);
357 underTest.uninstall();
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])");
362 underTest.uninstall();
366 public void uninstall_resets_fields_after_newEditionWithoutInstall() {
367 String value = randomAlphanumeric(10);
369 underTest.newEditionWithoutInstall(value);
371 PendingStatus newStatus = underTest.uninstall();
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();
381 public void uninstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
383 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
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])");
388 underTest.uninstall();
392 public void uninstall_fails_with_ISE_if_called_after_automaticInstallReady() {
394 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
395 underTest.automaticInstallReady();
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])");
400 underTest.uninstall();
404 public void uninstall_fails_with_ISE_if_called_after_manualInstall() {
406 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
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])");
411 underTest.uninstall();
415 public void startAutomaticInstall_succeeds_if_called_after_installFailed_and_clears_errorMessage() {
417 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
418 underTest.installFailed(errorMessage);
420 PendingStatus newStatus = underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
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();
431 public void startManualInstall_fails_with_ISE_if_not_started() {
432 expectISENotStarted();
434 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
438 public void startManualInstall_fails_with_NPE_if_license_is_null() {
441 expectedException.expect(NullPointerException.class);
442 expectedException.expectMessage("license can't be null");
444 underTest.startManualInstall(null);
448 public void startManualInstall_sets_pending_fields_after_start() {
451 PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
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();
462 public void startManualInstall_sets_pending_fields_after_start_with_existing_currentEditionKey() {
463 String value = randomAlphanumeric(10);
464 dbTester.properties().insertInternal("currentEditionKey", value);
467 PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
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();
478 public void startManualInstall_sets_pending_fields_after_newEditionWithoutInstall() {
479 String value = randomAlphanumeric(10);
481 underTest.newEditionWithoutInstall(value);
483 PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
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();
494 public void startManualInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
496 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
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])");
501 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
505 public void startManualInstall_fails_with_ISE_if_called_after_automaticInstallReady() {
507 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
508 underTest.automaticInstallReady();
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])");
513 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
517 public void startManualInstall_fails_with_ISE_if_called_after_manualInstall() {
519 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
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])");
524 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
528 public void startManualInstall_fails_with_ISE_if_called_after_uninstall() {
530 underTest.newEditionWithoutInstall("foo");
531 underTest.uninstall();
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])");
536 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
540 public void startManualInstall_succeeds_if_called_after_installFailed_and_clears_errorMessage() {
542 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
543 underTest.installFailed(errorMessage);
545 PendingStatus newStatus = underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
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();
556 public void automaticInstallReady_fails_with_ISE_if_not_started() {
557 expectISENotStarted();
559 underTest.automaticInstallReady();
563 public void automaticInstallReady_fails_with_ISE_if_called() {
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])");
569 underTest.automaticInstallReady();
573 public void automaticInstallReady_fails_with_ISE_if_called_after_manualInstall() {
575 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
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])");
580 underTest.automaticInstallReady();
584 public void automaticInstallReady_fails_with_ISE_if_called_after_newEditionWithoutInstall() {
586 underTest.newEditionWithoutInstall("foo");
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])");
591 underTest.automaticInstallReady();
595 public void automaticInstallReady_fails_with_ISE_if_called_after_uninstall() {
597 underTest.newEditionWithoutInstall("foo");
598 underTest.uninstall();
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])");
603 underTest.automaticInstallReady();
607 public void automaticInstallReady_fails_with_ISE_if_called_after_startManualInstall() {
609 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
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])");
614 underTest.automaticInstallReady();
618 public void automaticInstallReady_after_startAutomaticInstall_changes_status_to_AUTOMATIC_READY_but_does_not_change_editions() {
620 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
622 PendingStatus newStatus = underTest.automaticInstallReady();
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();
633 public void automaticInstallReady_fails_with_ISE_if_called_after_installFailed() {
635 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
636 underTest.installFailed(nullableErrorMessage);
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])");
641 underTest.automaticInstallReady();
645 public void newEditionWithoutInstall_fails_with_ISE_if_not_started() {
646 expectISENotStarted();
648 underTest.newEditionWithoutInstall(randomAlphanumeric(3));
652 public void newEditionWithoutInstall_fails_with_NPE_if_newEditionKey_is_null() {
655 expectedException.expect(NullPointerException.class);
656 expectedException.expectMessage("newEditionKey can't be null");
658 underTest.newEditionWithoutInstall(null);
662 public void newEditionWithoutInstall_fails_with_IAE_if_newEditionKey_is_empty() {
665 expectedException.expect(IllegalArgumentException.class);
666 expectedException.expectMessage("newEditionKey can't be empty");
668 underTest.newEditionWithoutInstall("");
672 public void newEditionWithoutInstall_changes_current_edition() {
673 String newEditionKey = randomAlphanumeric(3);
676 PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey);
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();
687 public void newEditionWithoutInstall_overwrite_current_edition() {
688 String newEditionKey = randomAlphanumeric(3);
691 PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey);
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();
702 public void newEditionWithoutInstall_overwrites_from_previous_newEditionWithoutInstall() {
703 String newEditionKey1 = randomAlphanumeric(3);
704 String newEditionKey2 = randomAlphanumeric(3);
706 underTest.newEditionWithoutInstall(newEditionKey1);
708 PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey2);
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();
719 public void newEditionWithoutInstall_fails_with_ISE_if_called_after_startAutomaticInstall() {
720 String newEditionKey = randomAlphanumeric(3);
722 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
724 expectedException.expect(IllegalStateException.class);
725 expectedException.expectMessage("Can't move to NONE when status is AUTOMATIC_IN_PROGRESS (should be any of [NONE])");
727 underTest.newEditionWithoutInstall(newEditionKey);
731 public void newEditionWithoutInstall_fails_with_ISE_if_called_after_startManualInstall() {
732 String newEditionKey = randomAlphanumeric(3);
734 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
736 expectedException.expect(IllegalStateException.class);
737 expectedException.expectMessage("Can't move to NONE when status is MANUAL_IN_PROGRESS (should be any of [NONE])");
739 underTest.newEditionWithoutInstall(newEditionKey);
743 public void newEditionWithoutInstall_fails_with_ISE_if_called_after_uninstall() {
744 String newEditionKey = randomAlphanumeric(3);
746 underTest.newEditionWithoutInstall("foo");
747 underTest.uninstall();
749 expectedException.expect(IllegalStateException.class);
750 expectedException.expectMessage("Can't move to NONE when status is UNINSTALL_IN_PROGRESS (should be any of [NONE])");
752 underTest.newEditionWithoutInstall(newEditionKey);
756 public void newEditionWithoutInstall_succeeds_if_called_after_installFailed_and_clear_error_message() {
757 String newEditionKey = randomAlphanumeric(3);
759 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
760 underTest.installFailed(errorMessage);
762 PendingStatus newStatus = underTest.newEditionWithoutInstall(newEditionKey);
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();
773 public void finalizeInstallation_fails_with_ISE_if_not_started() {
774 expectISENotStarted();
776 underTest.finalizeInstallation();
780 public void finalizeInstallation_fails_with_ISE_after_start() {
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])");
786 underTest.finalizeInstallation();
790 public void finalizeInstallation_fails_with_ISE_after_newEditionWithoutInstall() {
792 underTest.newEditionWithoutInstall(randomAlphanumeric(3));
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])");
797 underTest.finalizeInstallation();
801 public void finalizeInstallation_fails_with_ISE_after_startAutomaticInstall() {
803 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
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])");
808 underTest.finalizeInstallation();
812 public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_manualInstallationReady() {
814 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
815 underTest.automaticInstallReady();
817 PendingStatus newStatus = underTest.finalizeInstallation();
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();
828 public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_startManualInstall() {
830 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
832 PendingStatus newStatus = underTest.finalizeInstallation();
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();
843 public void finalizeInstallation_overwrites_current_edition_and_clear_pending_fields_after_startManualInstall() {
844 String value = randomAlphanumeric(10);
845 dbTester.properties().insertInternal("currentEditionKey", value);
847 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
849 PendingStatus newStatus = underTest.finalizeInstallation();
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();
860 public void finalizeInstallation_fails_with_ISE_after_installFailed() {
862 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
863 underTest.installFailed(nullableErrorMessage);
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])");
868 underTest.finalizeInstallation();
872 public void finalizeInstallation_set_new_edition_and_clear_pending_fields_after_uninstall() {
874 String value = randomAlphanumeric(10);
875 underTest.newEditionWithoutInstall(value);
876 underTest.uninstall();
878 PendingStatus newStatus = underTest.finalizeInstallation();
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();
888 public void finalizeInstallation_fails_with_ISE_after_finalizeInstallation() {
890 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
891 underTest.finalizeInstallation();
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])");
896 underTest.finalizeInstallation();
900 public void installFailed_fails_with_ISE_if_not_started() {
901 expectISENotStarted();
903 underTest.installFailed(nullableErrorMessage);
907 public void installFailed_fails_with_ISE_if_called_after_start() {
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])");
913 underTest.installFailed(nullableErrorMessage);
917 public void installFailed_after_manualInstall_changes_status_to_NONE_stores_non_null_error_message_and_clear_pending_fields() {
919 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
920 String errorMessage = randomAlphanumeric(4);
922 PendingStatus newStatus = underTest.installFailed(errorMessage);
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);
933 public void installFailed_after_manualInstall_changes_status_to_NONE_without_error_message_and_clear_pending_fields() {
935 underTest.startManualInstall(LICENSE_WITHOUT_PLUGINS);
937 PendingStatus newStatus = underTest.installFailed(null);
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();
948 public void installFailed_after_startAutomaticInstall_changes_status_to_NONE_stores_non_null_error_message_and_clear_pending_fields() {
950 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
951 String errorMessage = randomAlphanumeric(4);
953 PendingStatus newStatus = underTest.installFailed(errorMessage);
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);
964 public void installFailed_after_startAutomaticInstall_changes_status_to_NONE_without_error_message_and_clear_pending_fields() {
966 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
968 PendingStatus newStatus = underTest.installFailed(null);
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();
979 public void installFailed_after_startAutomaticInstall_changes_status_to_NONE_stores_non_null_error_message_and_clear_pending_fields_when_current_install_exists() {
981 String currentEdition = "current-edition";
982 underTest.newEditionWithoutInstall(currentEdition);
983 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
984 String errorMessage = randomAlphanumeric(4);
986 PendingStatus newStatus = underTest.installFailed(errorMessage);
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);
997 public void installFailed_after_startAutomaticInstall_changes_status_to_NONE_without_error_message_and_clear_pending_fields_when_current_install_exists() {
999 String currentEdition = "current-edition";
1000 underTest.newEditionWithoutInstall(currentEdition);
1001 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1003 PendingStatus newStatus = underTest.installFailed(null);
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();
1014 public void installFailed_considers_empty_message_as_no_message() {
1016 underTest.newEditionWithoutInstall("current-edition");
1017 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1019 underTest.installFailed("");
1021 assertThat(underTest.getInstallErrorMessage()).isEmpty();
1025 public void installFailed_considers_empty_message_after_trim_as_no_message() {
1027 underTest.newEditionWithoutInstall("current-edition");
1028 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1030 underTest.installFailed(" ");
1032 assertThat(underTest.getInstallErrorMessage()).isEmpty();
1036 public void installFailed_after_automaticInstallReady_changes_status_to_NONE_stores_non_null_error_message_and_clear_pending_fields_when_current_install_exists() {
1038 String currentEdition = "current-edition";
1039 underTest.newEditionWithoutInstall(currentEdition);
1040 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1041 underTest.automaticInstallReady();
1042 String errorMessage = randomAlphanumeric(4);
1044 PendingStatus newStatus = underTest.installFailed(errorMessage);
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);
1055 public void installFailed_after_automaticInstallReady_changes_status_to_NONE_without_error_message_and_clear_pending_fields_when_current_install_exists() {
1057 String currentEdition = "current-edition";
1058 underTest.newEditionWithoutInstall(currentEdition);
1059 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1060 underTest.automaticInstallReady();
1062 PendingStatus newStatus = underTest.installFailed(null);
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();
1073 public void installFailed_after_installFailed() {
1075 underTest.startAutomaticInstall(LICENSE_WITHOUT_PLUGINS);
1076 underTest.installFailed(nullableErrorMessage);
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])");
1081 underTest.installFailed(nullableErrorMessage);
1084 private void expectISENotStarted() {
1085 expectedException.expect(IllegalStateException.class);
1086 expectedException.expectMessage("StandaloneEditionManagementStateImpl is not started");