Skip to content
Snippets Groups Projects
Commit 8128d49b authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'OZG-6666 Nachrichten: Event wenn eine Antwort empfangen...

Merge pull request 'OZG-6666 Nachrichten: Event wenn eine Antwort empfangen wurde' (#32) from OZG-6666-Nachrichten-Event-Antwort-empfangen into master

Reviewed-on: https://git.ozg-sh.de/ozgcloud-app/nachrichten-manager/pulls/32


Reviewed-by: default avatarOZGCloud <ozgcloud@mgm-tp.com>
parents c5322c27 fb74bf74
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,7 @@
<jaxb-maven-plugin.version>3.0.1</jaxb-maven-plugin.version>
<ozg-info-manager-interface.version>0.1.0-SNAPSHOT</ozg-info-manager-interface.version>
<bayernid-proxy-interface.version>0.1.0</bayernid-proxy-interface.version>
<vorgang-manager.version>2.8.0</vorgang-manager.version>
<vorgang-manager.version>2.15.0-SNAPSHOT</vorgang-manager.version>
<muk-postfach.version>0.1.0-SNAPSHOT</muk-postfach.version>
<ozgcloud-starter.version>0.10.0</ozgcloud-starter.version>
</properties>
......@@ -214,6 +214,13 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.ozgcloud.command</groupId>
<artifactId>command-manager</artifactId>
<version>${vorgang-manager.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
......@@ -33,25 +33,34 @@ import java.util.function.Predicate;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandCreatedEvent;
import de.ozgcloud.command.PostfachNachrichtReceivedEvent;
import de.ozgcloud.command.VorgangAttachedItemCreatedEvent;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht.Direction;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
@Component
@Log4j2
@RequiredArgsConstructor
public class PostfachEventListener {
private static final String IS_SEND_POSTFACH_NACHRICHT_COMMAND = "{T(de.ozgcloud.nachrichten.postfach.PostfachEventListener).IS_SEND_POSTFACH_NACHRICHT.test(event.getSource())}";
public static final Predicate<Command> IS_SEND_POSTFACH_NACHRICHT = command -> command.getOrder().equals("SEND_POSTFACH_NACHRICHT");
@Autowired
private PostfachService service;
public static final Predicate<Command> IS_SEND_POSTFACH_NACHRICHT = command -> StringUtils.equals(command.getOrder(), "SEND_POSTFACH_NACHRICHT");
public static final String KEY_ITEM_NAME = "itemName";
public static final Predicate<Command> IS_INCOMING_POSTFACH_NACHRICHT_CREATED = command ->
StringUtils.equals(command.getOrder(), "CREATE_ATTACHED_ITEM")
&& StringUtils.equals(MapUtils.getString(command.getBodyObject(), KEY_ITEM_NAME), AttachedItemRemoteService.ITEM_NAME)
&& StringUtils.equals(MapUtils.getString(command.getBodyObject(), PostfachNachricht.FIELD_DIRECTION), "IN");
private static final String IS_INCOMING_POSTFACH_NACHRICHT_ITEM_CREATED_CONDITION =
"{T(de.ozgcloud.nachrichten.postfach.PostfachEventListener).IS_INCOMING_POSTFACH_NACHRICHT_CREATED.test(event.getCommand())}";
private final PostfachService service;
private final ApplicationEventPublisher publisher;
@EventListener(condition = IS_SEND_POSTFACH_NACHRICHT_COMMAND)
public void sendPostfachNachricht(CommandCreatedEvent event) {
......@@ -122,4 +131,9 @@ public class PostfachEventListener {
return List.of(object.toString());
}
}
@EventListener(condition = IS_INCOMING_POSTFACH_NACHRICHT_ITEM_CREATED_CONDITION)
public void onIncomingPostfachNachrichtItemCreated(VorgangAttachedItemCreatedEvent event) {
publisher.publishEvent(new PostfachNachrichtReceivedEvent(event.getCommand(), event.getCreatedResource()));
}
}
\ No newline at end of file
......@@ -41,9 +41,12 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.context.ApplicationEventPublisher;
import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandCreatedEvent;
import de.ozgcloud.command.PostfachNachrichtReceivedEvent;
import de.ozgcloud.command.VorgangAttachedItemCreatedEvent;
import de.ozgcloud.nachrichten.postfach.PostfachNachricht.Direction;
import de.ozgcloud.nachrichten.postfach.osi.MessageTestFactory;
......@@ -56,6 +59,8 @@ class PostfachEventListenerTest {
private PostfachService service;
@Mock
private Command command;
@Mock
private ApplicationEventPublisher publisher;
@Captor
private ArgumentCaptor<PostfachNachricht> nachrichtCaptor;
......@@ -213,4 +218,32 @@ class PostfachEventListenerTest {
assertThat(list).isEmpty();
}
}
@DisplayName("On create incoming nachricht item")
@Nested
class TestOnCreateIncomingPostfachNachrichtItem {
private static final String CREATED_RESOURCE = "created-resource";
@Captor
public ArgumentCaptor<PostfachNachrichtReceivedEvent> eventCaptor;
@Mock
private VorgangAttachedItemCreatedEvent vorgangAttachedItemCreatedEvent;
@BeforeEach
void init() {
when(vorgangAttachedItemCreatedEvent.getCommand()).thenReturn(command);
when(vorgangAttachedItemCreatedEvent.getCreatedResource()).thenReturn(CREATED_RESOURCE);
}
@Test
void shouldPublishPostfachNachrichtReceivedEvent() {
listener.onIncomingPostfachNachrichtItemCreated(vorgangAttachedItemCreatedEvent);
verify(publisher).publishEvent(eventCaptor.capture());
assertThat(eventCaptor.getValue()).satisfies(event -> {
assertThat(event.getSource()).isSameAs(command);
assertThat(event.getNachrichtId()).isEqualTo(CREATED_RESOURCE);
});
}
}
}
\ 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