Skip to content
Snippets Groups Projects
Commit 3caa6ce2 authored by OZGCloud's avatar OZGCloud
Browse files

Merge branch 'master' into OZG-6300-OZG-6417-Zusammarbeit-E2E

parents 4eb633c7 2ffad6fe
Branches
Tags
No related merge requests found
Showing
with 308 additions and 438 deletions
......@@ -45,6 +45,10 @@ export class VorgangSubnavigationE2EComponent {
return cy.getTestElement(this.backIconButton);
}
public back(): void {
this.getBackButton().click();
}
public getAnnehmenIconButton() {
return cy.getTestElement(this.annehmenIconButton);
}
......
......@@ -18,6 +18,9 @@ export class VorgangViewsE2EComponent {
private readonly zuLoeschenViewItem: VorgangViewE2EComponent = new VorgangViewE2EComponent(
'Zu_Loschen',
);
private readonly ungelesenViewItem: VorgangViewE2EComponent = new VorgangViewE2EComponent(
'Ungelesen',
);
private readonly wiedervorlagenViewItem: VorgangViewE2EComponent = new VorgangViewE2EComponent(
'Wiedervorlagen',
);
......@@ -54,6 +57,10 @@ export class VorgangViewsE2EComponent {
return this.zuLoeschenViewItem;
}
public getUngelesen(): VorgangViewE2EComponent {
return this.ungelesenViewItem;
}
public getWiedervorlagen(): VorgangViewE2EComponent {
return this.wiedervorlagenViewItem;
}
......
......@@ -28,7 +28,7 @@ import {
registerLocaleData(localeDe, 'de', localeDeExtra);
//TODO: Jenkins konfigurieren
describe.skip('Upload automatic Bescheid', () => {
describe('Upload automatic Bescheid', () => {
const mainPage: MainPage = new MainPage();
const vorgangList: VorgangListE2EComponent = mainPage.getVorgangList();
......@@ -77,7 +77,7 @@ describe.skip('Upload automatic Bescheid', () => {
dropCollections();
});
describe.skip('Upload automatic Bescheid document', () => {
describe('Upload automatic Bescheid document', () => {
it('should show automatic Bescheid button', () => {
vorgangList.getListItem(bescheidAutomatik.name).getRoot().click();
waitForSpinnerToDisappear();
......
import {
PostfachMailE2EComponent,
PostfachMailListItem,
} from 'apps/alfa-e2e/src/components/postfach/postfach-mail.e2e.component';
import { VorgangSubnavigationE2EComponent } from 'apps/alfa-e2e/src/components/vorgang/vorgang-subnavigation';
import {
VorgangViewE2EComponent,
VorgangViewsE2EComponent,
} from 'apps/alfa-e2e/src/components/vorgang/vorgang-views.e2e.component';
import {
PostfachMailItemE2E,
VorgangAttachedItemClientE2E,
VorgangAttachedItemE2E,
} from 'apps/alfa-e2e/src/model/vorgang-attached-item';
import { VorgangPage } from 'apps/alfa-e2e/src/page-objects/vorgang.po';
import { exist, haveLength } from 'apps/alfa-e2e/src/support/cypress.util';
import {
createPostfachNachrichtAttachedItem,
createPostfachNachrichtReplyItem,
initVorgangAttachedItem,
} from 'apps/alfa-e2e/src/support/vorgang-attached-item-util';
import { VorgangListE2EComponent } from '../../../components/vorgang/vorgang-list.e2e.component';
import { ClientAttributeNameE2E, ClientAttributesE2E, VorgangE2E } from '../../../model/vorgang';
import { MainPage, waitForSpinnerToDisappear } from '../../../page-objects/main.po';
import { dropCollections } from '../../../support/cypress-helper';
import { initUsermanagerUsers, loginAsSabine } from '../../../support/user-util';
import {
buildVorgang,
createHasNewPostfachNachrichtClientAttribute,
createHasPostfachNachrichtClientAttribute,
initVorgaenge,
objectIds,
} from '../../../support/vorgang-util';
describe('Ungelesene Nachrichten', () => {
const mainPage: MainPage = new MainPage();
const vorgangList: VorgangListE2EComponent = mainPage.getVorgangList();
const vorgangPage: VorgangPage = new VorgangPage();
const subnavigation: VorgangSubnavigationE2EComponent = vorgangPage.getSubnavigation();
const views: VorgangViewsE2EComponent = mainPage.getViews();
const ungelesenView: VorgangViewE2EComponent = views.getUngelesen();
const postfachMailContainer: PostfachMailE2EComponent = vorgangPage.getPostfachMailcontainer();
const clientAttributes: ClientAttributesE2E = {
[VorgangAttachedItemClientE2E.OZGCLOUD_NACHRICHTEN_MANAGER]: {
[ClientAttributeNameE2E.HAS_NEW_POSTFACH_NACHRICHT]:
createHasNewPostfachNachrichtClientAttribute(true),
[ClientAttributeNameE2E.HAS_POSTFACH_NACHRICHT]:
createHasPostfachNachrichtClientAttribute(true),
},
};
const vorgangWithReply1: VorgangE2E = {
...buildVorgang(objectIds[0], 'VorgangWithReply'),
clientAttributes,
};
const vorgangWithReply2: VorgangE2E = {
...buildVorgang(objectIds[1], 'VorgangWithReply 2'),
clientAttributes,
};
const postfachMailReply1: PostfachMailItemE2E = createPostfachNachrichtReplyItem();
const postfachMailReply2: PostfachMailItemE2E = createPostfachNachrichtReplyItem();
const postfachNachrichtAttachedItem1: VorgangAttachedItemE2E = {
...createPostfachNachrichtAttachedItem(objectIds[0], vorgangWithReply1._id.$oid),
item: postfachMailReply1,
};
const postfachNachrichtAttachedItem2: VorgangAttachedItemE2E = {
...createPostfachNachrichtAttachedItem(objectIds[1], vorgangWithReply2._id.$oid),
item: postfachMailReply2,
};
before(() => {
initVorgaenge([vorgangWithReply1, vorgangWithReply2]);
initVorgangAttachedItem([postfachNachrichtAttachedItem1]);
initVorgangAttachedItem([postfachNachrichtAttachedItem2]);
initUsermanagerUsers();
loginAsSabine();
waitForSpinnerToDisappear();
exist(vorgangList.getRoot());
});
after(() => {
dropCollections();
});
describe('Show number of unread messages', () => {
it('should show 2 unread messages in filter', () => {
ungelesenView.getRoot().click();
waitForSpinnerToDisappear();
haveLength(vorgangList.getItems(), 2);
});
it('should show 1 unread message after viewing first message', () => {
vorgangList.getListItem(vorgangWithReply1.name).getRoot().click();
waitForSpinnerToDisappear();
const postfachMailItem: PostfachMailListItem = postfachMailContainer.getListItem('Subject');
postfachMailItem.getRoot().click();
waitForSpinnerToDisappear();
subnavigation.back();
subnavigation.back();
haveLength(vorgangList.getItems(), 1);
});
it('should show 0 unread messages after viewing second message', () => {
vorgangList.getListItem(vorgangWithReply2.name).getRoot().click();
waitForSpinnerToDisappear();
const postfachMailItem: PostfachMailListItem = postfachMailContainer.getListItem('Subject');
postfachMailItem.getRoot().click();
waitForSpinnerToDisappear();
subnavigation.back();
subnavigation.back();
haveLength(vorgangList.getItems(), 0);
});
});
});
......@@ -158,6 +158,8 @@ describe('Wiedervorlage erledigen/wiedereroeffnen', () => {
waitforSpinnerToAppear();
waitForSpinnerToDisappear();
wait(1000, 'Wait for async BE to complete');
containClass(wiedervorlageContainer.getStatusDot(), 'erledigt');
contains(
snackBar.getMessage(),
......@@ -199,6 +201,8 @@ describe('Wiedervorlage erledigen/wiedereroeffnen', () => {
waitforSpinnerToAppear();
waitForSpinnerToDisappear();
wait(1000, 'Wait for async BE to complete');
notContainClass(wiedervorlageContainer.getStatusDot(), 'erledigt');
contains(
snackBar.getMessage(),
......@@ -229,6 +233,7 @@ describe('Wiedervorlage erledigen/wiedereroeffnen', () => {
const locatorIconDefault: string = 'wiedervorlage-icon-default';
it('back to vorgang list', () => {
wait(1000, 'Wait for async BE to complete');
vorgangPage.getSubnavigation().getBackButton().click();
waitForSpinnerToDisappear();
});
......@@ -249,6 +254,8 @@ describe('Wiedervorlage erledigen/wiedereroeffnen', () => {
subnavigation.erledigen();
waitForSpinnerToDisappear();
wait(1000, 'Wait for async BE to complete');
subnavigation.navigateBack();
waitForSpinnerToDisappear();
});
......
......@@ -9,6 +9,8 @@ project:
alfa:
env:
overrideSpringProfiles: "oc,e2e,dev"
customList:
ozgcloud_feature_bescheid-wizard: "true"
ingress:
use_staging_cert: true
ozgcloud:
......@@ -20,6 +22,7 @@ alfa:
vorgang_manager:
env:
overrideSpringProfiles: "oc,e2e,dev"
customList:
ozgcloud_bescheid_smart_documents_url: http://smocker:8080/smartdocuments
ozgcloud_bescheid_smart_documents_basic_auth_username: MGM
ozgcloud_bescheid_smart_documents_basic_auth_password: MGM
......
......@@ -26,8 +26,6 @@ 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;
......@@ -76,14 +74,4 @@ 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
......@@ -23,7 +23,6 @@
*/
package de.ozgcloud.alfa.common.command;
import java.util.Calendar;
import java.util.Optional;
import java.util.stream.Stream;
......@@ -43,8 +42,6 @@ import lombok.RequiredArgsConstructor;
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;
private final CommandRemoteService remoteService;
......@@ -114,25 +111,4 @@ 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
......@@ -23,14 +23,6 @@
*/
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);
}
}
......@@ -53,23 +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());
return ResponseEntity.created(linkTo(CommandController.class).slash(doneCommand.getId()).toUri()).build();
return ResponseEntity.created(linkTo(CommandController.class).slash(createdCommand.getId()).toUri()).build();
}
Command createCommand(Wiedervorlage wiedervorlage, CreateCommand command) {
switch (command.getOrder()) {
case LegacyOrder.WIEDERVORLAGE_ERLEDIGEN: {
return service.erledigen(wiedervorlage);
var changed = wiedervorlage.toBuilder().done(true).build();
service.updateNextFrist(wiedervorlage.getVorgangId(), changed);
return service.erledigen(changed);
}
case LegacyOrder.WIEDERVORLAGE_WIEDEREROEFFNEN: {
return service.wiedereroeffnen(wiedervorlage);
var changed = wiedervorlage.toBuilder().done(false).build();
service.updateNextFrist(wiedervorlage.getVorgangId(), changed);
return service.wiedereroeffnen(changed);
}
case LegacyOrder.EDIT_WIEDERVORLAGE: {
return service.editWiedervorlage(updateWiedervorlageByCommand(wiedervorlage, (Wiedervorlage) command.getBody()),
wiedervorlage.getId(),
wiedervorlage.getVersion());
var changed = updateWiedervorlageByCommand(wiedervorlage, (Wiedervorlage) command.getBody());
service.updateNextFrist(wiedervorlage.getVorgangId(), changed);
return service.editWiedervorlage(changed, wiedervorlage.getId(), wiedervorlage.getVersion());
}
default:
throw new TechnicalException("Unsupported order " + command.getOrder());
......@@ -95,10 +98,12 @@ 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());
var wiedervorlage = (Wiedervorlage) command.getBody();
var createdCommand = service.createWiedervorlage(wiedervorlage, vorgangId);
return ResponseEntity.created(linkTo(CommandController.class).slash(doneCommand.getId()).toUri()).build();
service.updateNextFrist(vorgangId, wiedervorlage);
return ResponseEntity.created(linkTo(CommandController.class).slash(createdCommand.getId()).toUri()).build();
}
}
}
\ No newline at end of file
......@@ -33,12 +33,12 @@ import java.util.stream.Stream;
import jakarta.validation.Valid;
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;
......@@ -52,7 +52,6 @@ class WiedervorlageService {
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);
......@@ -73,18 +72,14 @@ class WiedervorlageService {
return remoteService.getById(wiedervorlageId);
}
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);
@Async
public void updateNextFrist(String vorgangId, Wiedervorlage changedOrNewWiedervorlage) {
var persistedWiedervorlagen = findByVorgangId(vorgangId);
var persistedWiedervorlagenExcludingChanged = persistedWiedervorlagen.filter(
wiedervorlage -> !wiedervorlage.getId().equals(changedOrNewWiedervorlage.getId()));
remoteService.updateNextFrist(vorgangId, calculateNextFrist(allWiedervorlagen));
var wiedervorlagen = Stream.concat(persistedWiedervorlagenExcludingChanged, Stream.of(changedOrNewWiedervorlage));
remoteService.updateNextFrist(vorgangId, calculateNextFrist(wiedervorlagen));
}
Optional<LocalDate> calculateNextFrist(Stream<Wiedervorlage> wiedervorlagen) {
......@@ -100,11 +95,11 @@ class WiedervorlageService {
return remoteService.findByVorgangId(vorgangId);
}
Command erledigen(Wiedervorlage wiedervorlage) {
public Command erledigen(Wiedervorlage wiedervorlage) {
return vorgangAttachedItemService.setWiedervorlageDone(wiedervorlage, true);
}
Command wiedereroeffnen(Wiedervorlage wiedervorlage) {
public Command wiedereroeffnen(Wiedervorlage wiedervorlage) {
return vorgangAttachedItemService.setWiedervorlageDone(wiedervorlage, false);
}
......
......@@ -27,7 +27,6 @@ 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;
......@@ -40,7 +39,6 @@ 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;
......@@ -299,99 +297,4 @@ 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
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
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
......@@ -44,13 +44,8 @@ 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;
import de.ozgcloud.alfa.common.user.CurrentUserService;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
import de.ozgcloud.alfa.wiedervorlage.WiedervorlageCommandController.WiedervorlageCommandByVorgangController;
import lombok.SneakyThrows;
......@@ -60,15 +55,10 @@ class WiedervorlageCommandByVorgangControllerTest {
@Spy
@InjectMocks
private WiedervorlageCommandByVorgangController controller;
@Mock
private CommandByRelationController commandByRelationController;
@Mock
private CurrentUserService userService;
@Mock
private WiedervorlageService service;
@Captor
private ArgumentCaptor<CreateCommand> createCommandCaptor;
private MockMvc mockMvc;
@BeforeEach
......@@ -82,15 +72,10 @@ class WiedervorlageCommandByVorgangControllerTest {
@Captor
private ArgumentCaptor<Wiedervorlage> wiedervorlageCaptor;
private Command createCommand;
private Command doneCommand;
@BeforeEach
void mockUserService() {
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);
when(service.createWiedervorlage(any(), any())).thenReturn(CommandTestFactory.create());
}
@Nested
......@@ -105,10 +90,14 @@ class WiedervorlageCommandByVorgangControllerTest {
}
@Test
void shouldUpdateNextFristOnSuccessfullyDoneCommand() {
void shouldCallServiceToUpdateNextFrist() {
doRequest();
verify(service).updateNextFrist(createCommand, VorgangHeaderTestFactory.ID);
verify(service).updateNextFrist(eq(VorgangHeaderTestFactory.ID), wiedervorlageCaptor.capture());
assertThat(wiedervorlageCaptor.getValue())
.usingRecursiveComparison()
.comparingOnlyFields("betreff", "beschreibung", "frist", "attachments")
.isEqualTo(WiedervorlageTestFactory.create());
}
@SneakyThrows
......
......@@ -35,6 +35,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
......@@ -46,7 +48,6 @@ 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.CommandStatus;
import de.ozgcloud.alfa.common.command.CommandTestFactory;
import de.ozgcloud.alfa.common.command.CreateCommand;
import de.ozgcloud.alfa.common.command.LegacyOrder;
......@@ -78,18 +79,15 @@ class WiedervorlageCommandControllerTest {
@Nested
class ControllerMethods {
private Command createCommand;
private Command doneCommand;
@Captor
private ArgumentCaptor<Wiedervorlage> wiedervorlageCaptor;
@BeforeEach
void init() {
when(service.getById(any())).thenReturn(WiedervorlageTestFactory.create());
createCommand = CommandTestFactory.createBuilder()
when(service.editWiedervorlage(any(), any(), anyLong())).thenReturn(CommandTestFactory.createBuilder()
.order(CommandOrder.UPDATE_ATTACHED_ITEM.name())
.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);
.body(WiedervorlageTestFactory.createAsMap()).build());
}
@SneakyThrows
......@@ -101,10 +99,14 @@ class WiedervorlageCommandControllerTest {
}
@Test
void shouldUpdateNextFristOnSuccessfullyDoneCommand() {
void shouldCallServiceUpdateNextFrist() {
doRequest();
verify(service).updateNextFrist(createCommand, VorgangHeaderTestFactory.ID);
verify(service).updateNextFrist(eq(VorgangHeaderTestFactory.ID), wiedervorlageCaptor.capture());
assertThat(wiedervorlageCaptor.getValue())
.usingRecursiveComparison()
.comparingOnlyFields("betreff", "beschreibung", "frist", "attachments")
.isEqualTo(WiedervorlageTestFactory.create());
}
@SneakyThrows
......@@ -152,6 +154,9 @@ class WiedervorlageCommandControllerTest {
@Nested
class TestCreateCommand {
@Captor
private ArgumentCaptor<Wiedervorlage> wiedervorlageArgumentCaptor;
@DisplayName("for order 'erledigen'")
@Nested
class TestOnErledigenOrder {
......@@ -162,6 +167,23 @@ class WiedervorlageCommandControllerTest {
verify(service).erledigen(any(Wiedervorlage.class));
}
@Test
void shouldUpdateNextFrist() {
callCreateCommand(LegacyOrder.WIEDERVORLAGE_ERLEDIGEN);
verify(service).updateNextFrist(eq(VorgangHeaderTestFactory.ID), any(Wiedervorlage.class));
}
@Test
void shouldSetWiedervorlageAsDone() {
callCreateCommand(LegacyOrder.WIEDERVORLAGE_ERLEDIGEN);
verify(service).updateNextFrist(eq(VorgangHeaderTestFactory.ID), wiedervorlageArgumentCaptor.capture());
assertThat(wiedervorlageArgumentCaptor.getValue())
.usingRecursiveComparison()
.isEqualTo(WiedervorlageTestFactory.createBuilder().done(true).build());
}
}
@DisplayName("for order 'wiedereroeffnen'")
......@@ -174,6 +196,23 @@ class WiedervorlageCommandControllerTest {
verify(service).wiedereroeffnen(any(Wiedervorlage.class));
}
@Test
void shouldUpdateNextFrist() {
callCreateCommand(LegacyOrder.WIEDERVORLAGE_WIEDEREROEFFNEN);
verify(service).updateNextFrist(eq(VorgangHeaderTestFactory.ID), any(Wiedervorlage.class));
}
@Test
void shouldSetWiedervorlageAsOpen() {
callCreateCommand(LegacyOrder.WIEDERVORLAGE_WIEDEREROEFFNEN);
verify(service).updateNextFrist(eq(VorgangHeaderTestFactory.ID), wiedervorlageArgumentCaptor.capture());
assertThat(wiedervorlageArgumentCaptor.getValue())
.usingRecursiveComparison()
.isEqualTo(WiedervorlageTestFactory.createBuilder().done(false).build());
}
}
@DisplayName("for order 'edit'")
......@@ -188,6 +227,16 @@ class WiedervorlageCommandControllerTest {
eq(WiedervorlageTestFactory.VERSION));
}
@Test
void shouldUpdateNextFrist() {
var wiedervorlage = WiedervorlageTestFactory.create();
doReturn(wiedervorlage).when(controller).updateWiedervorlageByCommand(any(), any());
callCreateCommand(LegacyOrder.EDIT_WIEDERVORLAGE);
verify(service).updateNextFrist(VorgangHeaderTestFactory.ID, wiedervorlage);
}
@DisplayName("update wiedervorlage by given command")
@Nested
class TestUpdateWiedervorlageByCommand {
......
......@@ -38,7 +38,6 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
......@@ -47,7 +46,6 @@ 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;
......@@ -108,14 +106,14 @@ class WiedervorlageServiceTest {
}
@Test
void shouldSetCreatedAt() {
void shouldSetCreatedAt() throws Exception {
var wiedervorlage = callAddCreated();
assertThat(wiedervorlage.getCreatedAt()).isNotNull().isCloseTo(ZonedDateTime.now(), within(2, ChronoUnit.SECONDS));
}
@Test
void shouldSetCreatedBy() {
void shouldSetCreatedBy() throws Exception {
var wiedervorlage = callAddCreated();
assertThat(wiedervorlage.getCreatedBy()).isEqualTo(UserProfileTestFactory.ID.toString());
......@@ -173,21 +171,33 @@ class WiedervorlageServiceTest {
}
@Nested
class TestDoUpdateNextFrist {
class TestUpdateNextFrist {
@Nested
class ServiceMethod {
private final Wiedervorlage wiedervorlage = WiedervorlageTestFactory.create();
private final Wiedervorlage foundWiedervorlage = WiedervorlageTestFactory.create();
@Captor
private ArgumentCaptor<Stream<Wiedervorlage>> allWiedervorlagen;
@BeforeEach
void mockService() {
when(remoteService.findByVorgangId(any())).thenReturn(Stream.of(WiedervorlageTestFactory.create()));
when(remoteService.findByVorgangId(VorgangHeaderTestFactory.ID)).thenReturn(Stream.of(foundWiedervorlage));
doReturn(Optional.of(WiedervorlageTestFactory.FRIST)).when(service).calculateNextFrist(any());
}
@Test
void shoulDoCalculation() {
void shouldDoCalculation() {
callUpdateNextFrist();
verify(service).calculateNextFrist(ArgumentMatchers.<Stream<Wiedervorlage>>any());
verify(service).calculateNextFrist(any());
}
@Test
void shouldAddWiedervorlageToFoundWiedervorlagen() {
callUpdateNextFrist();
verify(service).calculateNextFrist(allWiedervorlagen.capture());
assertThat(allWiedervorlagen.getValue()).containsExactly(wiedervorlage);
}
@Test
......@@ -199,20 +209,18 @@ class WiedervorlageServiceTest {
@Test
void shouldCallRemoteService() {
doReturn(Optional.of(WiedervorlageTestFactory.FRIST)).when(service).calculateNextFrist(any());
callUpdateNextFrist();
verify(remoteService).updateNextFrist(VorgangHeaderTestFactory.ID, Optional.of(WiedervorlageTestFactory.FRIST));
}
private void callUpdateNextFrist() {
service.doUpdateNextFrist(VorgangHeaderTestFactory.ID);
service.updateNextFrist(VorgangHeaderTestFactory.ID, wiedervorlage);
}
}
@Nested
class Calculation {
class TestCalculateNextFrist {
@Test
void shouldReturnNullOnAllDone() {
......@@ -255,68 +263,3 @@ class WiedervorlageServiceTest {
}
}
}
\ No newline at end of file
@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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment