Skip to content
Snippets Groups Projects
Commit 381fe698 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5988 set clientAttribute when send_bescheid command executed

parent 94bca7e7
No related branches found
No related tags found
No related merge requests found
...@@ -46,6 +46,7 @@ import de.ozgcloud.bescheid.nachricht.NachrichtService; ...@@ -46,6 +46,7 @@ import de.ozgcloud.bescheid.nachricht.NachrichtService;
import de.ozgcloud.bescheid.vorgang.VorgangId; import de.ozgcloud.bescheid.vorgang.VorgangId;
import de.ozgcloud.command.Command; import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandCreatedEvent; import de.ozgcloud.command.CommandCreatedEvent;
import de.ozgcloud.command.CommandExecutedEvent;
import de.ozgcloud.command.CommandFailedEvent; import de.ozgcloud.command.CommandFailedEvent;
import de.ozgcloud.common.errorhandling.TechnicalException; import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.document.BescheidDocumentCreatedEvent; import de.ozgcloud.document.BescheidDocumentCreatedEvent;
...@@ -165,7 +166,7 @@ class BescheidEventListener { ...@@ -165,7 +166,7 @@ class BescheidEventListener {
void doSendBescheid(Command command) { void doSendBescheid(Command command) {
var bescheidItem = attachedItemService.getItem(command.getRelationId()); var bescheidItem = attachedItemService.getItem(command.getRelationId());
if (SendBy.MANUAL.hasValue(bescheidItem.getItem().get(Bescheid.FIELD_SEND_BY))) { if (SendBy.MANUAL.hasValue(bescheidItem.getItem().get(Bescheid.FIELD_SEND_BY))) {
service.sendBescheidManually(bescheidItem, command.getRelationVersion()); service.sendBescheidManually(bescheidItem, command);
} else if (SendBy.NACHRICHT.hasValue(bescheidItem.getItem().get(Bescheid.FIELD_SEND_BY))) { } else if (SendBy.NACHRICHT.hasValue(bescheidItem.getItem().get(Bescheid.FIELD_SEND_BY))) {
service.sendBescheidPostfachMail(bescheidItem, command); service.sendBescheidPostfachMail(bescheidItem, command);
} else { } else {
...@@ -190,6 +191,15 @@ class BescheidEventListener { ...@@ -190,6 +191,15 @@ class BescheidEventListener {
return builder.build(); return builder.build();
} }
@EventListener(condition = IS_SEND_BESCHEID)
public void onBescheidSent(CommandExecutedEvent event) {
runWithSecurityContext(event.getCommand(), this::setAntragBewilligung);
}
void setAntragBewilligung(Command command) {
service.setAntragBewilligung(attachedItemService.getItem(command.getRelationId()));
}
void runWithSecurityContext(Command command, Consumer<Command> commandExecutor) { void runWithSecurityContext(Command command, Consumer<Command> commandExecutor) {
SecurityContext prevContext = null; SecurityContext prevContext = null;
try { try {
......
...@@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test; ...@@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import de.ozgcloud.apilib.common.command.OzgCloudCommandService; import de.ozgcloud.apilib.common.command.OzgCloudCommandService;
...@@ -19,14 +20,19 @@ import de.ozgcloud.bescheid.common.user.UserProfile; ...@@ -19,14 +20,19 @@ import de.ozgcloud.bescheid.common.user.UserProfile;
import de.ozgcloud.bescheid.common.user.UserProfileService; import de.ozgcloud.bescheid.common.user.UserProfileService;
import de.ozgcloud.command.Command; import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandCreatedEventTestFactory; import de.ozgcloud.command.CommandCreatedEventTestFactory;
import de.ozgcloud.command.CommandExecutedEvent;
import de.ozgcloud.command.CommandTestFactory; import de.ozgcloud.command.CommandTestFactory;
import de.ozgcloud.common.test.ITCase; import de.ozgcloud.common.test.ITCase;
@ITCase @ITCase
class BescheidEventListenerITCase { class BescheidEventListenerITCase {
private static final Command COMMAND_WITH_OTHER_ORDER = CommandTestFactory.createBuilder().order("OTHER").build();
@Autowired @Autowired
private ApplicationEventPublisher publisher; private ApplicationEventPublisher publisher;
@SpyBean
private BescheidEventListener listener;
@Autowired @Autowired
private BescheidFeatureProperties bescheidFeatureProperties; private BescheidFeatureProperties bescheidFeatureProperties;
...@@ -70,7 +76,7 @@ class BescheidEventListenerITCase { ...@@ -70,7 +76,7 @@ class BescheidEventListenerITCase {
@Test @Test
void shouldNotReactOnOtherOrder() { void shouldNotReactOnOtherOrder() {
publisher.publishEvent(CommandCreatedEventTestFactory.withCommand(CommandTestFactory.createBuilder().order("OTHER").build())); publisher.publishEvent(CommandCreatedEventTestFactory.withCommand(COMMAND_WITH_OTHER_ORDER));
verifyNoInteractions(service); verifyNoInteractions(service);
} }
...@@ -90,7 +96,7 @@ class BescheidEventListenerITCase { ...@@ -90,7 +96,7 @@ class BescheidEventListenerITCase {
@Test @Test
void shouldNotReactOnOtherOrder() { void shouldNotReactOnOtherOrder() {
publisher.publishEvent(CommandCreatedEventTestFactory.withCommand(CommandTestFactory.createBuilder().order("OTHER").build())); publisher.publishEvent(CommandCreatedEventTestFactory.withCommand(COMMAND_WITH_OTHER_ORDER));
verifyNoInteractions(attachedItemService); verifyNoInteractions(attachedItemService);
} }
...@@ -110,9 +116,29 @@ class BescheidEventListenerITCase { ...@@ -110,9 +116,29 @@ class BescheidEventListenerITCase {
@Test @Test
void shouldNotReactOnOtherOrder() { void shouldNotReactOnOtherOrder() {
publisher.publishEvent(CommandCreatedEventTestFactory.withCommand(CommandTestFactory.createBuilder().order("OTHER").build())); publisher.publishEvent(CommandCreatedEventTestFactory.withCommand(COMMAND_WITH_OTHER_ORDER));
verifyNoInteractions(attachedItemService); verifyNoInteractions(attachedItemService);
} }
} }
@Nested
class TestBescheidSent {
private static final Command COMMAND = CommandTestFactory.createBuilder().order(BescheidEventListener.SEND_BESCHEID_ORDER).build();
@Test
void shouldCallMethod() {
publisher.publishEvent(new CommandExecutedEvent(COMMAND));
verify(listener).setAntragBewilligung(COMMAND);
}
@Test
void shouldNotReactOnOtherOrder() {
publisher.publishEvent(new CommandExecutedEvent(COMMAND_WITH_OTHER_ORDER));
verifyNoInteractions(listener);
}
}
} }
...@@ -35,6 +35,7 @@ import de.ozgcloud.bescheid.common.user.UserProfileTestFactory; ...@@ -35,6 +35,7 @@ import de.ozgcloud.bescheid.common.user.UserProfileTestFactory;
import de.ozgcloud.bescheid.nachricht.NachrichtService; import de.ozgcloud.bescheid.nachricht.NachrichtService;
import de.ozgcloud.command.Command; import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandCreatedEventTestFactory; import de.ozgcloud.command.CommandCreatedEventTestFactory;
import de.ozgcloud.command.CommandExecutedEvent;
import de.ozgcloud.command.CommandFailedEvent; import de.ozgcloud.command.CommandFailedEvent;
import de.ozgcloud.command.CommandTestFactory; import de.ozgcloud.command.CommandTestFactory;
import de.ozgcloud.common.errorhandling.TechnicalException; import de.ozgcloud.common.errorhandling.TechnicalException;
...@@ -551,8 +552,8 @@ class BescheidEventListenerTest { ...@@ -551,8 +552,8 @@ class BescheidEventListenerTest {
void shouldCallSendBescheid() { void shouldCallSendBescheid() {
listener.doSendBescheid(COMMAND); listener.doSendBescheid(COMMAND);
verify(service).sendBescheidManually(bescheidItem, AttachedItemTestFactory.VERSION); verify(service).sendBescheidManually(bescheidItem, COMMAND);
verify(service, never()).sendBescheidPostfachMail(any(), anyLong()); verify(service, never()).sendBescheidPostfachMail(any(), any());
} }
@Test @Test
...@@ -585,8 +586,8 @@ class BescheidEventListenerTest { ...@@ -585,8 +586,8 @@ class BescheidEventListenerTest {
void shouldCallBescheidService() { void shouldCallBescheidService() {
listener.doSendBescheid(COMMAND); listener.doSendBescheid(COMMAND);
verify(service).sendBescheidPostfachMail(bescheidItem, AttachedItemTestFactory.VERSION); verify(service).sendBescheidPostfachMail(bescheidItem, COMMAND);
verify(service, never()).sendBescheidManually(any(), anyLong()); verify(service, never()).sendBescheidManually(any(), any());
} }
@Test @Test
...@@ -599,6 +600,49 @@ class BescheidEventListenerTest { ...@@ -599,6 +600,49 @@ class BescheidEventListenerTest {
} }
} }
@Nested
class TestOnBescheidSent {
private static final Command COMMAND = CommandTestFactory.create();
@Test
void shouldCallRunWithSecurityContext() {
listener.onBescheidSent(new CommandExecutedEvent(COMMAND));
verify(listener).runWithSecurityContext(eq(COMMAND), any());
}
@Test
void shouldExecuteSetAntragBewilligung() {
listener.onBescheidSent(new CommandExecutedEvent(COMMAND));
verify(listener).setAntragBewilligung(COMMAND);
}
}
@Nested
class TestSetAntragBewilligung {
private static final Command COMMAND = CommandTestFactory.create();
@Test
void shouldCallGetItem() {
listener.setAntragBewilligung(COMMAND);
verify(attachedItemService).getItem(CommandTestFactory.RELATION_ID);
}
@Test
void shouldCallSetAntragBewilligung() {
var item = AttachedItemTestFactory.createBescheid();
when(attachedItemService.getItem(any())).thenReturn(item);
listener.setAntragBewilligung(COMMAND);
verify(service).setAntragBewilligung(item);
}
}
@Nested @Nested
class TestRunWithSecurityContext { class TestRunWithSecurityContext {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment