Skip to content
Snippets Groups Projects
Commit 1f3010d5 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5681 adjust tests

parent f1de5afb
No related branches found
No related tags found
No related merge requests found
...@@ -85,8 +85,7 @@ public class NachrichtService { ...@@ -85,8 +85,7 @@ public class NachrichtService {
} }
public void sendNachricht(Bescheid bescheid) { public void sendNachricht(Bescheid bescheid) {
var commandToCreate = buildSendBescheidCommand(bescheid); commandService.createAndWaitUntilDone(buildSendBescheidCommand(bescheid));
commandService.createAndWaitUntilDone(commandToCreate);
} }
OzgCloudCommand buildSendBescheidCommand(Bescheid bescheid) { OzgCloudCommand buildSendBescheidCommand(Bescheid bescheid) {
......
...@@ -52,9 +52,9 @@ public class DocumentService { ...@@ -52,9 +52,9 @@ public class DocumentService {
public static final String DOCUMENT_TYPE = "BESCHEID"; public static final String DOCUMENT_TYPE = "BESCHEID";
static final String CREATE_ATTACHED_ITEM_ORDER = "CREATE_ATTACHED_ITEM"; static final String CREATE_ATTACHED_ITEM_ORDER = "CREATE_ATTACHED_ITEM";
static final String FIELD_DOCUMENT_TYPE = "type"; public static final String FIELD_DOCUMENT_TYPE = "type";
static final String FIELD_DOCUMENT_FILE = "documentFile"; public static final String FIELD_DOCUMENT_FILE = "documentFile";
static final String FIELD_NACHRICHT_TEXT = "nachrichtText"; public static final String FIELD_NACHRICHT_TEXT = "nachrichtText";
private final AttachedItemService attachedItemService; private final AttachedItemService attachedItemService;
private final OzgCloudCommandService commandService; private final OzgCloudCommandService commandService;
......
...@@ -29,6 +29,7 @@ import static org.awaitility.Awaitility.*; ...@@ -29,6 +29,7 @@ import static org.awaitility.Awaitility.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
...@@ -60,6 +61,7 @@ import de.ozgcloud.command.CommandStatus; ...@@ -60,6 +61,7 @@ import de.ozgcloud.command.CommandStatus;
import de.ozgcloud.common.test.DataITCase; import de.ozgcloud.common.test.DataITCase;
import de.ozgcloud.document.BescheidDocumentCreatedEvent; import de.ozgcloud.document.BescheidDocumentCreatedEvent;
import de.ozgcloud.document.Document; import de.ozgcloud.document.Document;
import de.ozgcloud.document.DocumentService;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht; import de.ozgcloud.nachrichten.postfach.PostfachNachricht;
import de.ozgcloud.nachrichten.postfach.PostfachRemoteService; import de.ozgcloud.nachrichten.postfach.PostfachRemoteService;
import de.ozgcloud.vorgang.VorgangManagerServerApplication; import de.ozgcloud.vorgang.VorgangManagerServerApplication;
...@@ -263,16 +265,20 @@ class BescheidEventListenerITCase { ...@@ -263,16 +265,20 @@ class BescheidEventListenerITCase {
@Captor @Captor
private ArgumentCaptor<PostfachNachricht> postfachNachrichtCaptor; private ArgumentCaptor<PostfachNachricht> postfachNachrichtCaptor;
private String vorgangId;
private VorgangAttachedItem bescheidItem;
@BeforeEach @BeforeEach
void init() { void init() {
when(userProfile.getId()).thenReturn(UserId.from("user-id")); when(userProfile.getId()).thenReturn(UserId.from("user-id"));
when(callContextUser.getUserId()).thenReturn(Optional.of("user-id"));
vorgangId = mongoOperations.save(VorgangTestFactory.createBuilder().id(null).build()).getId();
var documentFileId = mongoOperations.save(createBescheidDocumentAttachedItem(vorgangId)).getId();
bescheidItem = mongoOperations.save(createBescheidAttachedItemWithDocument(vorgangId, documentFileId));
} }
@Test @Test
void shouldSuccessfullyCompleteCommand() { void shouldSuccessfullyCompleteCommand() {
var vorgangId = mongoOperations.save(VorgangTestFactory.createBuilder().id(null).build()).getId();
var bescheidItem = mongoOperations.save(createBescheidAttachedItemWithDocument(vorgangId));
commandService.createCommand(buildCreateCommandRequest(vorgangId, bescheidItem)); commandService.createCommand(buildCreateCommandRequest(vorgangId, bescheidItem));
await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> { await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> {
...@@ -283,12 +289,9 @@ class BescheidEventListenerITCase { ...@@ -283,12 +289,9 @@ class BescheidEventListenerITCase {
@Test @Test
void shouldSetBescheidStatusToSent() { void shouldSetBescheidStatusToSent() {
var vorgangId = mongoOperations.save(VorgangTestFactory.createBuilder().id(null).build()).getId();
var bescheidItem = mongoOperations.save(createBescheidAttachedItemWithDocument(vorgangId));
eventPublisher.publishEvent(buildCommandCreatedEvent(vorgangId, bescheidItem)); eventPublisher.publishEvent(buildCommandCreatedEvent(vorgangId, bescheidItem));
await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> { await().atMost(1, TimeUnit.SECONDS).untilAsserted(() -> {
verify(bescheiTestEventListener).onBescheidSentEvent(bescheidSentEventCaptor.capture()); verify(bescheiTestEventListener).onBescheidSentEvent(bescheidSentEventCaptor.capture());
assertThat(loadBescheid(bescheidItem.getId()).getItem()).containsEntry(Bescheid.FIELD_STATUS, Bescheid.Status.SENT.name()); assertThat(loadBescheid(bescheidItem.getId()).getItem()).containsEntry(Bescheid.FIELD_STATUS, Bescheid.Status.SENT.name());
}); });
...@@ -296,9 +299,6 @@ class BescheidEventListenerITCase { ...@@ -296,9 +299,6 @@ class BescheidEventListenerITCase {
@Test @Test
void shouldSetVorgangStatusToBeschieden() { void shouldSetVorgangStatusToBeschieden() {
var vorgangId = mongoOperations.save(VorgangTestFactory.createBuilder().id(null).build()).getId();
var bescheidItem = mongoOperations.save(createBescheidAttachedItemWithDocument(vorgangId));
commandService.createCommand(buildCreateCommandRequest(vorgangId, bescheidItem)); commandService.createCommand(buildCreateCommandRequest(vorgangId, bescheidItem));
await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> { await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> {
...@@ -310,9 +310,6 @@ class BescheidEventListenerITCase { ...@@ -310,9 +310,6 @@ class BescheidEventListenerITCase {
@Test @Test
void shouldSendPostfachNachricht() { void shouldSendPostfachNachricht() {
var vorgangId = mongoOperations.save(VorgangTestFactory.createBuilder().id(null).build()).getId();
var bescheidItem = mongoOperations.save(createBescheidAttachedItemWithDocument(vorgangId));
commandService.createCommand(buildCreateCommandRequest(vorgangId, bescheidItem)); commandService.createCommand(buildCreateCommandRequest(vorgangId, bescheidItem));
await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> { await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> {
...@@ -326,9 +323,6 @@ class BescheidEventListenerITCase { ...@@ -326,9 +323,6 @@ class BescheidEventListenerITCase {
@Test @Test
void shouldSetClientAttribute() { void shouldSetClientAttribute() {
var vorgangId = mongoOperations.save(VorgangTestFactory.createBuilder().id(null).build()).getId();
var bescheidItem = mongoOperations.save(createBescheidAttachedItemWithDocument(vorgangId));
commandService.createCommand(buildCreateCommandRequest(vorgangId, bescheidItem)); commandService.createCommand(buildCreateCommandRequest(vorgangId, bescheidItem));
await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> { await().atMost(60, TimeUnit.SECONDS).untilAsserted(() -> {
...@@ -340,7 +334,7 @@ class BescheidEventListenerITCase { ...@@ -340,7 +334,7 @@ class BescheidEventListenerITCase {
}); });
} }
private VorgangAttachedItem createBescheidAttachedItemWithDocument(String vorgangId) { private VorgangAttachedItem createBescheidAttachedItemWithDocument(String vorgangId, String bescheidDocumentId) {
return VorgangAttachedItemTestFactory.createBuilder() return VorgangAttachedItemTestFactory.createBuilder()
.id(null) .id(null)
.version(0L) .version(0L)
...@@ -350,12 +344,25 @@ class BescheidEventListenerITCase { ...@@ -350,12 +344,25 @@ class BescheidEventListenerITCase {
Bescheid.FIELD_STATUS, Bescheid.Status.DRAFT.name(), Bescheid.FIELD_STATUS, Bescheid.Status.DRAFT.name(),
Bescheid.FIELD_SEND_BY, Bescheid.SendBy.NACHRICHT.name(), Bescheid.FIELD_SEND_BY, Bescheid.SendBy.NACHRICHT.name(),
Bescheid.FIELD_BEWILLIGT, true, Bescheid.FIELD_BEWILLIGT, true,
Bescheid.FIELD_BESCHEID_DOCUMENT, "documentId", Bescheid.FIELD_BESCHEID_DOCUMENT, bescheidDocumentId,
Bescheid.FIELD_NACHRICHT_SUBJECT, NACHRICHT_SUBJECT, Bescheid.FIELD_NACHRICHT_SUBJECT, NACHRICHT_SUBJECT,
Bescheid.FIELD_NACHRICHT_TEXT, NACHRICHT_TEXT)) Bescheid.FIELD_NACHRICHT_TEXT, NACHRICHT_TEXT))
.build(); .build();
} }
private VorgangAttachedItem createBescheidDocumentAttachedItem(String vorgangId) {
return VorgangAttachedItemTestFactory.createBuilder()
.id(null)
.version(0L)
.vorgangId(vorgangId)
.itemName(DocumentService.DOCUMENT_ITEM_NAME)
.item(Map.of(
DocumentService.FIELD_DOCUMENT_TYPE, DocumentService.DOCUMENT_TYPE,
DocumentService.FIELD_DOCUMENT_FILE, "documentId",
DocumentService.FIELD_NACHRICHT_TEXT, "nachrichtText"))
.build();
}
private CommandCreatedEvent buildCommandCreatedEvent(String vorgangId, VorgangAttachedItem bescheidItem) { private CommandCreatedEvent buildCommandCreatedEvent(String vorgangId, VorgangAttachedItem bescheidItem) {
var command = CommandTestFactory.createBuilder() var command = CommandTestFactory.createBuilder()
.vorgangId(vorgangId) .vorgangId(vorgangId)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment