diff --git a/alfa-client/apps/alfa-e2e/src/e2e/main-tests/wiedervorlage/wiedervorlage.erledigen.cy.ts b/alfa-client/apps/alfa-e2e/src/e2e/main-tests/wiedervorlage/wiedervorlage.erledigen.cy.ts index c71173e2ac474729c22c9a89894e0ffb0e3a660b..b20cea9b1d2b31d36db3535b7526a8032f1b88ed 100644 --- a/alfa-client/apps/alfa-e2e/src/e2e/main-tests/wiedervorlage/wiedervorlage.erledigen.cy.ts +++ b/alfa-client/apps/alfa-e2e/src/e2e/main-tests/wiedervorlage/wiedervorlage.erledigen.cy.ts @@ -33,7 +33,7 @@ import { WiedervorlageInVorgangE2EComponent } from '../../../components/wiedervo import { WiedervorlageE2EComponent } from '../../../components/wiedervorlage/wiedervorlage-page.e2e.component'; import { WiedervorlageSubnavigationE2EComponent } from '../../../components/wiedervorlage/wiedervorlage-subnavigation'; import { WiedervorlagenInVorgangE2EComponent } from '../../../components/wiedervorlage/wiedervorlagen-in-vorgang.e2e.component'; -import { VorgangE2E } from '../../../model/vorgang'; +import { ClientAttributeNameE2E, VorgangE2E } from '../../../model/vorgang'; import { WiedervorlageE2E } from '../../../model/wiedervorlage'; import { MainPage, @@ -51,12 +51,20 @@ import { notExist, } from '../../../support/cypress.util'; import { loginAsSabine } from '../../../support/user-util'; -import { createVorgang, initVorgang, objectIds } from '../../../support/vorgang-util'; +import { + createAlfaClientAttributes, + createNextWiedervorlageFristClientAttribute, + createVorgang, + initVorgang, + objectIds, +} from '../../../support/vorgang-util'; import { createWiedervorlageAttachedItem, createWiedervorlageItem, } from '../../../support/wiedervorlage-util'; +const wiedervorlageItemFixture: WiedervorlageE2E = require('../../../fixtures/wiedervorlage/wiedervorlage.json'); + describe('Wiedervorlage erledigen/wiedereroeffnen', () => { const mainPage: MainPage = new MainPage(); @@ -76,7 +84,13 @@ describe('Wiedervorlage erledigen/wiedereroeffnen', () => { const wiedervorlageContainer: WiedervorlageE2EComponent = wiedervorlagePage.getWiedervorlageContainer(); - const vorgang: VorgangE2E = createVorgang(); + const vorgang: VorgangE2E = { + ...createVorgang(), + clientAttributes: createAlfaClientAttributes( + ClientAttributeNameE2E.NEXT_WIEDERVORLAGE_FRIST, + createNextWiedervorlageFristClientAttribute(wiedervorlageItemFixture.frist), + ), + }; const wiedervorlageZumErledigen: WiedervorlageE2E = { ...createWiedervorlageItem('WiedervorlageZumErledigen'), @@ -144,8 +158,6 @@ describe('Wiedervorlage erledigen/wiedereroeffnen', () => { waitforSpinnerToAppear(); waitForSpinnerToDisappear(); - wait(1000, 'Wait for async BE to complete'); - containClass(wiedervorlageContainer.getStatusDot(), 'erledigt'); contains( snackBar.getMessage(), @@ -187,8 +199,6 @@ describe('Wiedervorlage erledigen/wiedereroeffnen', () => { waitforSpinnerToAppear(); waitForSpinnerToDisappear(); - wait(1000, 'Wait for async BE to complete'); - notContainClass(wiedervorlageContainer.getStatusDot(), 'erledigt'); contains( snackBar.getMessage(), @@ -219,7 +229,6 @@ describe('Wiedervorlage erledigen/wiedereroeffnen', () => { const locatorIconDefault: string = 'wiedervorlage-icon-default'; it('back to vorgang list', () => { - wait(3000, 'Wait for async BE to complete'); vorgangPage.getSubnavigation().getBackButton().click(); waitForSpinnerToDisappear(); }); @@ -240,8 +249,6 @@ describe('Wiedervorlage erledigen/wiedereroeffnen', () => { subnavigation.erledigen(); waitForSpinnerToDisappear(); - wait(3000, 'Wait for async BE to complete'); - subnavigation.navigateBack(); waitForSpinnerToDisappear(); }); diff --git a/alfa-client/libs/binary-file/src/lib/vertical-binary-file-list/vertical-binary-file-list.component.html b/alfa-client/libs/binary-file/src/lib/vertical-binary-file-list/vertical-binary-file-list.component.html index 5771196b1704561cc2d4c54894c0312d03991170..1dc4313e5e3710b0c1550043dd4c1fa4f6e3d04d 100644 --- a/alfa-client/libs/binary-file/src/lib/vertical-binary-file-list/vertical-binary-file-list.component.html +++ b/alfa-client/libs/binary-file/src/lib/vertical-binary-file-list/vertical-binary-file-list.component.html @@ -34,6 +34,7 @@ data-test-id="file-list-header" > <alfa-download-archive-file-button-container + *ngIf="archiveDownloadUri" data-test-class="download-archive-file-button" [downloadUri]="archiveDownloadUri" action-buttons diff --git a/alfa-client/libs/binary-file/src/lib/vertical-binary-file-list/vertical-binary-file-list.component.spec.ts b/alfa-client/libs/binary-file/src/lib/vertical-binary-file-list/vertical-binary-file-list.component.spec.ts index 612c8f644c70f2283e1d5608a59816e78da62803..f0ec5b2c573b721bfd18afefde63750a310a0310 100644 --- a/alfa-client/libs/binary-file/src/lib/vertical-binary-file-list/vertical-binary-file-list.component.spec.ts +++ b/alfa-client/libs/binary-file/src/lib/vertical-binary-file-list/vertical-binary-file-list.component.spec.ts @@ -137,6 +137,10 @@ describe('VerticalBinaryFileListComponent', () => { }); describe('download archive button', () => { + beforeEach(() => { + component.title = 'Test title'; + }); + const downloadUri: ResourceUri = faker.internet.url(); it('should be visible if uri exists', () => { diff --git a/alfa-client/package.json b/alfa-client/package.json index 8dc2364f58bb67444d25979f3fd75136efdac63e..730267babe4d51dff0fb89982e5edf16f65f0631 100644 --- a/alfa-client/package.json +++ b/alfa-client/package.json @@ -1,6 +1,6 @@ { "name": "alfa", - "version": "0.7.0-SNAPSHOT", + "version": "0.8.0-SNAPSHOT", "license": "MIT", "scripts": { "start": "nx run alfa:serve --port 4300 --disable-host-check", diff --git a/alfa-client/pom.xml b/alfa-client/pom.xml index 31c038a64e63e52771d87ecb1085e907e9af2cb8..b36055f368b4404644459bb3f3816469ba738293 100644 --- a/alfa-client/pom.xml +++ b/alfa-client/pom.xml @@ -29,7 +29,7 @@ <parent> <groupId>de.ozgcloud.alfa</groupId> <artifactId>alfa</artifactId> - <version>2.11.0-SNAPSHOT</version> + <version>2.12.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> diff --git a/alfa-server/pom.xml b/alfa-server/pom.xml index 5124be2c496ebd8623a1445b16fdcb0a2074c4f0..e157390eee8d5e6722072745abd75cb760f831ec 100644 --- a/alfa-server/pom.xml +++ b/alfa-server/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>de.ozgcloud.alfa</groupId> <artifactId>alfa</artifactId> - <version>2.11.0-SNAPSHOT</version> + <version>2.12.0-SNAPSHOT</version> </parent> <artifactId>alfa-server</artifactId> diff --git a/alfa-service/pom.xml b/alfa-service/pom.xml index f2e9a4141f8dc1c75e3769a1671b1ca511714d8c..4d4e6c9ae8b0eca82e0af3bf544e12e11dc7fa15 100644 --- a/alfa-service/pom.xml +++ b/alfa-service/pom.xml @@ -31,7 +31,7 @@ <parent> <groupId>de.ozgcloud.alfa</groupId> <artifactId>alfa</artifactId> - <version>2.11.0-SNAPSHOT</version> + <version>2.12.0-SNAPSHOT</version> </parent> <artifactId>alfa-service</artifactId> diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/Command.java b/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/Command.java index 9e862c4756eb06bfa8aa47591b7d390de442d865..1a5d2ac5fda7dc714f9f2b13514dc22705159219 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/Command.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/Command.java @@ -26,6 +26,8 @@ package de.ozgcloud.alfa.common.command; import java.time.ZonedDateTime; import java.util.Map; +import org.apache.commons.lang3.StringUtils; + import com.fasterxml.jackson.annotation.JsonIgnore; import de.ozgcloud.alfa.common.LinkedUserProfileResource; @@ -74,4 +76,14 @@ public class Command { public CommandOrder getCommandOrder() { return CommandOrder.fromOrder(order); } + + @JsonIgnore + public boolean isFinishedSuccessfully() { + return status == CommandStatus.FINISHED && StringUtils.isEmpty(errorMessage); + } + + @JsonIgnore + public boolean isNotDone() { + return status.isNotDone(); + } } \ No newline at end of file diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/CommandService.java b/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/CommandService.java index 777ad9b7689d27e87f460276f96ffbd46d99ffe3..da98c4e572fda1d5c7175040bd88eace508555f6 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/CommandService.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/CommandService.java @@ -23,27 +23,30 @@ */ package de.ozgcloud.alfa.common.command; +import java.util.Calendar; import java.util.Optional; import java.util.stream.Stream; import jakarta.validation.Valid; import org.apache.commons.collections.MapUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import de.ozgcloud.alfa.loeschanforderung.DeleteLoeschAnforderung; import lombok.NonNull; +import lombok.RequiredArgsConstructor; +@RequiredArgsConstructor @Validated @Service public class CommandService { static final long NO_RELATION_VERSION = -1; + private static final int WAIT_TIME_MS = 500; + private static final int COMMAND_REQUEST_THRESHOLD_MILLIS = 10000; - @Autowired - private CommandRemoteService remoteService; + private final CommandRemoteService remoteService; /** * @deprecated use {@link #createCommand(CreateCommand)} instead @@ -111,4 +114,25 @@ public class CommandService { return remoteService.findCommands(vorgangId, Optional.of(CommandStatus.FINISHED), Optional.empty()); } + public Command waitUntilDone(Command commandToWaitFor) { + var command = commandToWaitFor; + var calendar = Calendar.getInstance(); + var timeout = calendar.getTimeInMillis() + COMMAND_REQUEST_THRESHOLD_MILLIS; + while (command.isNotDone() && calendar.getTimeInMillis() < timeout) { + synchronized (this) { + try { + wait(WAIT_TIME_MS); + command = reloadCommand(command.getId()); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + } + } + return command; + } + + public Command reloadCommand(String commandId) { + return remoteService.getCommand(commandId); + } + } \ No newline at end of file diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/CommandStatus.java b/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/CommandStatus.java index 285ebdaae3817652aa5c80b1d9817628fd044e6c..548107b825bca6aaed64a50f6f24611c9d7a8174 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/CommandStatus.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/common/command/CommandStatus.java @@ -23,6 +23,14 @@ */ package de.ozgcloud.alfa.common.command; +import java.util.Set; + public enum CommandStatus { PENDING, FINISHED, ERROR, REVOKE_PENDING, REVOKED; + + private static final Set<CommandStatus> FINAL_STATES = Set.of(FINISHED, ERROR, REVOKED); + + public boolean isNotDone() { + return !FINAL_STATES.contains(this); + } } diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandController.java b/alfa-service/src/main/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandController.java index d621a01dd99a332de8fe0dd6b2b754ccdc9a351a..2cc413979da3622e47fc9d0d5677b804f001cf23 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandController.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandController.java @@ -53,27 +53,26 @@ public class WiedervorlageCommandController { @PathVariable long wiedervorlageVersion) { var wiedervorlage = service.getById(wiedervorlageId); var createdCommand = createCommand(wiedervorlage, command); + var doneCommand = service.updateNextFrist(createdCommand, wiedervorlage.getVorgangId()); - service.updateNextFrist(wiedervorlage.getVorgangId()); - - return ResponseEntity.created(linkTo(CommandController.class).slash(createdCommand.getId()).toUri()).build(); + return ResponseEntity.created(linkTo(CommandController.class).slash(doneCommand.getId()).toUri()).build(); } Command createCommand(Wiedervorlage wiedervorlage, CreateCommand command) { switch (command.getOrder()) { - case LegacyOrder.WIEDERVORLAGE_ERLEDIGEN: { - return service.erledigen(wiedervorlage); - } - case LegacyOrder.WIEDERVORLAGE_WIEDEREROEFFNEN: { - return service.wiedereroeffnen(wiedervorlage); - } - case LegacyOrder.EDIT_WIEDERVORLAGE: { - return service.editWiedervorlage(updateWiedervorlageByCommand(wiedervorlage, (Wiedervorlage) command.getBody()), - wiedervorlage.getId(), - wiedervorlage.getVersion()); - } - default: - throw new TechnicalException("Unsupported order " + command.getOrder()); + case LegacyOrder.WIEDERVORLAGE_ERLEDIGEN: { + return service.erledigen(wiedervorlage); + } + case LegacyOrder.WIEDERVORLAGE_WIEDEREROEFFNEN: { + return service.wiedereroeffnen(wiedervorlage); + } + case LegacyOrder.EDIT_WIEDERVORLAGE: { + return service.editWiedervorlage(updateWiedervorlageByCommand(wiedervorlage, (Wiedervorlage) command.getBody()), + wiedervorlage.getId(), + wiedervorlage.getVersion()); + } + default: + throw new TechnicalException("Unsupported order " + command.getOrder()); } } @@ -97,10 +96,9 @@ public class WiedervorlageCommandController { @PostMapping public ResponseEntity<Void> createWiedervorlage(@RequestBody CreateCommand command, @PathVariable String vorgangId) { var createdCommand = service.createWiedervorlage((Wiedervorlage) command.getBody(), vorgangId); + var doneCommand = service.updateNextFrist(createdCommand, createdCommand.getVorgangId()); - service.updateNextFrist(vorgangId); - - return ResponseEntity.created(linkTo(CommandController.class).slash(createdCommand.getId()).toUri()).build(); + return ResponseEntity.created(linkTo(CommandController.class).slash(doneCommand.getId()).toUri()).build(); } } } \ No newline at end of file diff --git a/alfa-service/src/main/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageService.java b/alfa-service/src/main/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageService.java index 660aeefbe8e6a5d1425fd04d4d3b9cedee1a6e8a..28f4795c3695c12aa76981ebcb01c2f807fbbbde 100644 --- a/alfa-service/src/main/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageService.java +++ b/alfa-service/src/main/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageService.java @@ -33,27 +33,26 @@ import java.util.stream.Stream; import jakarta.validation.Valid; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import de.ozgcloud.alfa.common.attacheditem.VorgangAttachedItemService; import de.ozgcloud.alfa.common.command.Command; +import de.ozgcloud.alfa.common.command.CommandService; import de.ozgcloud.alfa.common.user.CurrentUserService; +import lombok.RequiredArgsConstructor; +@RequiredArgsConstructor @Validated @Service class WiedervorlageService { private static final Predicate<Wiedervorlage> IS_NOT_DONE = wiedervorlage -> !wiedervorlage.isDone(); - @Autowired - private WiedervorlageRemoteService remoteService; - @Autowired - private VorgangAttachedItemService vorgangAttachedItemService; - @Autowired - private CurrentUserService currentUserService; + private final WiedervorlageRemoteService remoteService; + private final VorgangAttachedItemService vorgangAttachedItemService; + private final CurrentUserService currentUserService; + private final CommandService commandService; public Command createWiedervorlage(@Valid Wiedervorlage wiedervorlage, String vorgangId) { return vorgangAttachedItemService.createNewWiedervorlage(addCreated(wiedervorlage), vorgangId); @@ -74,8 +73,15 @@ class WiedervorlageService { return remoteService.getById(wiedervorlageId); } - @Async - public void updateNextFrist(String vorgangId) { + public Command updateNextFrist(Command command, String vorgangId) { + var doneCommand = commandService.waitUntilDone(command); + if (doneCommand.isFinishedSuccessfully()) { + doUpdateNextFrist(vorgangId); + } + return doneCommand; + } + + void doUpdateNextFrist(String vorgangId) { var allWiedervorlagen = findByVorgangId(vorgangId); remoteService.updateNextFrist(vorgangId, calculateNextFrist(allWiedervorlagen)); diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/common/command/CommandServiceTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/common/command/CommandServiceTest.java index 95b37ba1901cbd62a954642ee61d4daf09fe4954..2bf962ce6cb343babed90d058cbe4549f6acb1b5 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/common/command/CommandServiceTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/common/command/CommandServiceTest.java @@ -27,6 +27,7 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import java.util.Calendar; import java.util.Map; import java.util.Optional; import java.util.UUID; @@ -39,6 +40,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.MockedStatic; import org.mockito.Spy; import de.ozgcloud.alfa.loeschanforderung.DeleteLoeschAnforderung; @@ -297,4 +299,99 @@ class CommandServiceTest { verify(remoteService).findCommands(VorgangHeaderTestFactory.ID, Optional.of(CommandStatus.FINISHED), Optional.empty()); } } + + @Nested + class TestWaitUntilDone { + + private final Command pendingCommand = CommandTestFactory.createBuilder().status(CommandStatus.PENDING).build(); + private final Command finishedCommand = pendingCommand.toBuilder().status(CommandStatus.FINISHED).build(); + + @Nested + class OnFinishedCommand { + + @Test + void shouldReturnFinishedCommand() { + var resultCommand = service.waitUntilDone(finishedCommand); + + assertThat(resultCommand).isEqualTo(finishedCommand); + } + + @Test + void shouldNotReloadCommand() { + service.waitUntilDone(finishedCommand); + + verify(service, never()).reloadCommand(any()); + } + } + + @Nested + class OnPendingCommand { + + @BeforeEach + void setUp() { + doReturn(finishedCommand).when(service).reloadCommand(pendingCommand.getId()); + } + + @Test + void shouldReloadCommand() { + service.waitUntilDone(pendingCommand); + + verify(service).reloadCommand(pendingCommand.getId()); + } + + @Test + void shouldReturnDoneCommand() { + var resultCommand = service.waitUntilDone(pendingCommand); + + assertThat(resultCommand).isEqualTo(finishedCommand); + } + } + + @Nested + class OnTimeoutExceeded { + + @Mock + private Calendar calendar; + + @Test + void shouldReturnPendingCommand() { + try (MockedStatic<Calendar> calendarMockedStatic = mockStatic(Calendar.class)) { + calendarMockedStatic.when(Calendar::getInstance).thenReturn(calendar); + when(calendar.getTimeInMillis()).thenReturn(0L, 15000L); + + var resultCommand = service.waitUntilDone(pendingCommand); + + assertThat(resultCommand).isEqualTo(pendingCommand); + } + } + + @Test + void shouldReloadPendingCommand() { + doReturn(pendingCommand).when(service).reloadCommand(pendingCommand.getId()); + + try (MockedStatic<Calendar> calendarMockedStatic = mockStatic(Calendar.class)) { + calendarMockedStatic.when(Calendar::getInstance).thenReturn(calendar); + when(calendar.getTimeInMillis()).thenReturn(0L, 0L, 15000L); + + service.waitUntilDone(pendingCommand); + + verify(service).reloadCommand(pendingCommand.getId()); + } + } + + @Test + void shouldReturnPendingCommandAfterReload() { + doReturn(pendingCommand).when(service).reloadCommand(pendingCommand.getId()); + + try (MockedStatic<Calendar> calendarMockedStatic = mockStatic(Calendar.class)) { + calendarMockedStatic.when(Calendar::getInstance).thenReturn(calendar); + when(calendar.getTimeInMillis()).thenReturn(0L, 0L, 15000L); + + var resultCommand = service.waitUntilDone(pendingCommand); + + assertThat(resultCommand).isEqualTo(pendingCommand); + } + } + } + } } \ No newline at end of file diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/common/command/CommandStatusTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/common/command/CommandStatusTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f91dc7028af4ca954d1dfc9fae1e70affbdcc066 --- /dev/null +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/common/command/CommandStatusTest.java @@ -0,0 +1,34 @@ +package de.ozgcloud.alfa.common.command; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.EnumSource.Mode; + +class CommandStatusTest { + + @Nested + class TestIsNotDone { + + @ParameterizedTest + @EnumSource(names = { "PENDING", "REVOKE_PENDING" }) + void shouldReturnTrue(CommandStatus status) { + var istNotDone = status.isNotDone(); + + assertThat(istNotDone).isTrue(); + + } + + @ParameterizedTest + @EnumSource(names = { "PENDING", "REVOKE_PENDING" }, mode = Mode.EXCLUDE) + void shouldReturnFalse(CommandStatus status) { + var istNotDone = status.isNotDone(); + + assertThat(istNotDone).isFalse(); + } + + } + +} \ No newline at end of file diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/common/command/CommandTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/common/command/CommandTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c838d402226703a6133dc5f8a65b79e7d911373e --- /dev/null +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/common/command/CommandTest.java @@ -0,0 +1,84 @@ +package de.ozgcloud.alfa.common.command; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.EnumSource.Mode; +import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.Mock; + +import com.thedeanda.lorem.LoremIpsum; + +class CommandTest { + + @Nested + class TestIsFinishedSuccessfully { + + @Test + void shouldReturnTrue() { + var command = CommandTestFactory.createBuilder().status(CommandStatus.FINISHED).build(); + + var isDoneSuccessfully = command.isFinishedSuccessfully(); + + assertThat(isDoneSuccessfully).isTrue(); + } + + @ParameterizedTest + @EnumSource(names = "FINISHED", mode = Mode.EXCLUDE) + void shouldReturnFalseOnStatusNotFinished(CommandStatus commandStatus) { + var command = CommandTestFactory.createBuilder().status(commandStatus).build(); + + var isDoneSuccessfully = command.isFinishedSuccessfully(); + + assertThat(isDoneSuccessfully).isFalse(); + } + + @ParameterizedTest + @EnumSource + void shouldReturnFalseOnErrorMessage(CommandStatus commandStatus) { + var command = CommandTestFactory.createBuilder().status(commandStatus).errorMessage(LoremIpsum.getInstance().getWords(1)).build(); + + var isDoneSuccessfully = command.isFinishedSuccessfully(); + + assertThat(isDoneSuccessfully).isFalse(); + } + + } + + @Nested + class TestIsNotDone { + + @Mock + private CommandStatus commandStatus; + private Command command; + + @BeforeEach + void setUp() { + command = CommandTestFactory.createBuilder().status(commandStatus).build(); + } + + @Test + void shouldCallIsNotDone() { + command.isNotDone(); + + verify(commandStatus).isNotDone(); + } + + @ParameterizedTest + @ValueSource(booleans = { true, false }) + void shouldReturnIsNotDone(boolean isNotDone) { + when(commandStatus.isNotDone()).thenReturn(isNotDone); + + var result = command.isNotDone(); + + assertThat(result).isEqualTo(isNotDone); + } + + } + +} \ No newline at end of file diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandByVorgangControllerTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandByVorgangControllerTest.java index 74d31babe720c7877812b0422b00cb1d76b377c2..ef4a43f95f4ed8458d9be2f37bb190e32bd87e84 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandByVorgangControllerTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandByVorgangControllerTest.java @@ -44,7 +44,9 @@ import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import de.ozgcloud.alfa.common.binaryfile.BinaryFileTestFactory; +import de.ozgcloud.alfa.common.command.Command; import de.ozgcloud.alfa.common.command.CommandController.CommandByRelationController; +import de.ozgcloud.alfa.common.command.CommandStatus; import de.ozgcloud.alfa.common.command.CommandTestFactory; import de.ozgcloud.alfa.common.command.CreateCommand; import de.ozgcloud.alfa.common.command.LegacyOrder; @@ -80,10 +82,15 @@ class WiedervorlageCommandByVorgangControllerTest { @Captor private ArgumentCaptor<Wiedervorlage> wiedervorlageCaptor; + private Command createCommand; + private Command doneCommand; @BeforeEach void mockUserService() { - when(service.createWiedervorlage(any(), any())).thenReturn(CommandTestFactory.create()); + createCommand = CommandTestFactory.create(); + doneCommand = createCommand.toBuilder().status(CommandStatus.FINISHED).build(); + when(service.createWiedervorlage(any(), any())).thenReturn(createCommand); + when(service.updateNextFrist(createCommand, VorgangHeaderTestFactory.ID)).thenReturn(doneCommand); } @Nested @@ -98,10 +105,10 @@ class WiedervorlageCommandByVorgangControllerTest { } @Test - void shouldCallServiceToUpdateNextFrist() { + void shouldUpdateNextFristOnSuccessfullyDoneCommand() { doRequest(); - verify(service).updateNextFrist(VorgangHeaderTestFactory.ID); + verify(service).updateNextFrist(createCommand, VorgangHeaderTestFactory.ID); } @SneakyThrows @@ -115,8 +122,8 @@ class WiedervorlageCommandByVorgangControllerTest { @SneakyThrows private ResultActions doRequest() { return mockMvc.perform( - post(WiedervorlageCommandByVorgangController.WIEDERVORLAGE_COMMANDS_BY_VORGANG, - VorgangHeaderTestFactory.ID) + post(WiedervorlageCommandByVorgangController.WIEDERVORLAGE_COMMANDS_BY_VORGANG, + VorgangHeaderTestFactory.ID) .content(createRequestContent()) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().is2xxSuccessful()); diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandControllerTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandControllerTest.java index 74bc2df86a8f6f8d98dc1fe34365654ef44c2e0e..198f7a00535cfc7dbcc73c53fa65f3d826a2225d 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandControllerTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageCommandControllerTest.java @@ -46,7 +46,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import de.ozgcloud.alfa.common.binaryfile.FileId; import de.ozgcloud.alfa.common.command.Command; import de.ozgcloud.alfa.common.command.CommandOrder; -import de.ozgcloud.alfa.common.command.CommandService; +import de.ozgcloud.alfa.common.command.CommandStatus; import de.ozgcloud.alfa.common.command.CommandTestFactory; import de.ozgcloud.alfa.common.command.CreateCommand; import de.ozgcloud.alfa.common.command.LegacyOrder; @@ -60,8 +60,6 @@ class WiedervorlageCommandControllerTest { @InjectMocks private WiedervorlageCommandController controller; @Mock - private CommandService commandService; - @Mock private WiedervorlageService service; private MockMvc mockMvc; @@ -80,12 +78,18 @@ class WiedervorlageCommandControllerTest { @Nested class ControllerMethods { + private Command createCommand; + private Command doneCommand; + @BeforeEach void init() { when(service.getById(any())).thenReturn(WiedervorlageTestFactory.create()); - when(service.editWiedervorlage(any(), any(), anyLong())).thenReturn(CommandTestFactory.createBuilder() + createCommand = CommandTestFactory.createBuilder() .order(CommandOrder.UPDATE_ATTACHED_ITEM.name()) - .body(WiedervorlageTestFactory.createAsMap()).build()); + .body(WiedervorlageTestFactory.createAsMap()).build(); + doneCommand = createCommand.toBuilder().status(CommandStatus.FINISHED).build(); + when(service.editWiedervorlage(any(), any(), anyLong())).thenReturn(createCommand); + when(service.updateNextFrist(createCommand, VorgangHeaderTestFactory.ID)).thenReturn(doneCommand); } @SneakyThrows @@ -97,10 +101,10 @@ class WiedervorlageCommandControllerTest { } @Test - void shouldCallServiceUpdateNextFrist() { + void shouldUpdateNextFristOnSuccessfullyDoneCommand() { doRequest(); - verify(service).updateNextFrist(VorgangHeaderTestFactory.ID); + verify(service).updateNextFrist(createCommand, VorgangHeaderTestFactory.ID); } @SneakyThrows @@ -129,8 +133,8 @@ class WiedervorlageCommandControllerTest { @SneakyThrows private ResultActions doRequest() { return mockMvc.perform( - post(WiedervorlageCommandController.WIEDERVORLAGE_COMMANDS, WiedervorlageTestFactory.ID, WiedervorlageTestFactory.VERSION) - .content(createRequestContent()).contentType(MediaType.APPLICATION_JSON)) + post(WiedervorlageCommandController.WIEDERVORLAGE_COMMANDS, WiedervorlageTestFactory.ID, WiedervorlageTestFactory.VERSION) + .content(createRequestContent()).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().is2xxSuccessful()); } diff --git a/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageServiceTest.java b/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageServiceTest.java index 3af67e13526b1f213bcbd417e2c5b2a45ae78a85..ae7f2e55675bd0ee63bb76f7a1b175b3bec39534 100644 --- a/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageServiceTest.java +++ b/alfa-service/src/test/java/de/ozgcloud/alfa/wiedervorlage/WiedervorlageServiceTest.java @@ -47,6 +47,7 @@ import org.mockito.Spy; import de.ozgcloud.alfa.common.attacheditem.VorgangAttachedItemService; import de.ozgcloud.alfa.common.command.Command; import de.ozgcloud.alfa.common.command.CommandService; +import de.ozgcloud.alfa.common.command.CommandStatus; import de.ozgcloud.alfa.common.command.CommandTestFactory; import de.ozgcloud.alfa.common.user.CurrentUserService; import de.ozgcloud.alfa.common.user.UserProfileTestFactory; @@ -107,14 +108,14 @@ class WiedervorlageServiceTest { } @Test - void shouldSetCreatedAt() throws Exception { + void shouldSetCreatedAt() { var wiedervorlage = callAddCreated(); assertThat(wiedervorlage.getCreatedAt()).isNotNull().isCloseTo(ZonedDateTime.now(), within(2, ChronoUnit.SECONDS)); } @Test - void shouldSetCreatedBy() throws Exception { + void shouldSetCreatedBy() { var wiedervorlage = callAddCreated(); assertThat(wiedervorlage.getCreatedBy()).isEqualTo(UserProfileTestFactory.ID.toString()); @@ -172,7 +173,7 @@ class WiedervorlageServiceTest { } @Nested - class TestUpdateNextFrist { + class TestDoUpdateNextFrist { @Nested class ServiceMethod { @@ -206,7 +207,7 @@ class WiedervorlageServiceTest { } private void callUpdateNextFrist() { - service.updateNextFrist(VorgangHeaderTestFactory.ID); + service.doUpdateNextFrist(VorgangHeaderTestFactory.ID); } } @@ -254,4 +255,68 @@ class WiedervorlageServiceTest { } } } + + @Nested + class TestUpdateNextFrist { + + @Test + void shouldWaitUntilCommandDone() { + var pendingCommand = CommandTestFactory.createBuilder().status(CommandStatus.PENDING).build(); + var command = CommandTestFactory.create(); + when(commandService.waitUntilDone(command)).thenReturn(pendingCommand); + + service.updateNextFrist(command, VorgangHeaderTestFactory.ID); + + verify(commandService).waitUntilDone(command); + } + + @Test + void shouldReturnDoneCommand() { + var doneCommand = CommandTestFactory.createBuilder().status(CommandStatus.FINISHED).build(); + var command = CommandTestFactory.create(); + when(commandService.waitUntilDone(command)).thenReturn(doneCommand); + + var result = service.updateNextFrist(command, VorgangHeaderTestFactory.ID); + + assertThat(result).isEqualTo(doneCommand); + } + + @Nested + class OnDoneSuccessfullyCommand { + private final Command command = CommandTestFactory.create(); + private final Command doneCommand = CommandTestFactory.createBuilder().status(CommandStatus.FINISHED).build(); + + @BeforeEach + void setUp() { + when(commandService.waitUntilDone(command)).thenReturn(doneCommand); + } + + @Test + void shouldUpdateNextFrist() { + service.updateNextFrist(command, VorgangHeaderTestFactory.ID); + + verify(service).doUpdateNextFrist(VorgangHeaderTestFactory.ID); + } + } + + @Nested + class OnNotDoneSuccessfullyCommand { + private final Command command = CommandTestFactory.create(); + private final Command pendingCommand = CommandTestFactory.createBuilder().status(CommandStatus.PENDING).build(); + + @BeforeEach + void setUp() { + when(commandService.waitUntilDone(command)).thenReturn(pendingCommand); + } + + @Test + void shouldNotUpdateNextFrist() { + service.updateNextFrist(command, VorgangHeaderTestFactory.ID); + + verify(service, never()).doUpdateNextFrist(VorgangHeaderTestFactory.ID); + } + } + + } + } \ No newline at end of file diff --git a/alfa-xdomea/pom.xml b/alfa-xdomea/pom.xml index 6f92cd2bc38e598b1dc2ab97a546ab4c331c7139..c141f0be18aa411909614eadcb8a85bc679f4837 100644 --- a/alfa-xdomea/pom.xml +++ b/alfa-xdomea/pom.xml @@ -31,7 +31,7 @@ <parent> <groupId>de.ozgcloud.alfa</groupId> <artifactId>alfa</artifactId> - <version>2.11.0-SNAPSHOT</version> + <version>2.12.0-SNAPSHOT</version> </parent> <artifactId>alfa-xdomea</artifactId> diff --git a/pom.xml b/pom.xml index ea6bebe8fdc2895b04b480132d6034a1366d89b8..334f0fbc2c8cf186962349557be289bcb2724de3 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ <groupId>de.ozgcloud.alfa</groupId> <artifactId>alfa</artifactId> - <version>2.11.0-SNAPSHOT</version> + <version>2.12.0-SNAPSHOT</version> <name>Alfa Parent</name> <packaging>pom</packaging>