Skip to content

Commit

Permalink
chore: remove app_message_name
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoesle committed Jan 4, 2024
1 parent 6fdca06 commit c081f40
Show file tree
Hide file tree
Showing 39 changed files with 96 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
public class AbstractStreamingIntegrationDelegate {
private final EngineDataMapper engineDataMapper;

private final static VariableFactory<String> MESSAGE_NAME = stringVariable("app_message_name");
private final static VariableFactory<String> TYPE_NAME = stringVariable("app_type_name");
private final static VariableFactory<String> TOPIC_NAME = stringVariable("app_topic_name");
private final static VariableFactory<String> RESPONSELESS = stringVariable("app_responseless");
private final static List<String> filterVariables = List.of(
MESSAGE_NAME.getName(),
TYPE_NAME.getName(),
TOPIC_NAME.getName(),
RESPONSELESS.getName()
Expand All @@ -44,7 +42,6 @@ protected Message<Map<String, Object>> mapMessage(final DelegateExecution delega
.setHeader(STREAM_SEND_TO_DESTINATION, TOPIC_NAME.from(delegateExecution).get())
.setHeader(TYPE, TYPE_NAME.from(delegateExecution).get())
.setHeader(DIGIWF_PROCESS_INSTANCE_ID, delegateExecution.getProcessInstanceId());
MESSAGE_NAME.from(delegateExecution).getOptional().ifPresent(name -> builder.setHeader(DIGIWF_MESSAGE_NAME, name));
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ public class StreamingHeaders {
public static final String DIGIWF_PROCESS_INSTANCE_ID = "digiwf.processinstanceid";
public static final String STREAM_SEND_TO_DESTINATION = "spring.cloud.stream.sendto.destination";
public static final String TYPE = "type";
public static final String DIGIWF_MESSAGE_NAME = "digiwf.messagename";

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ public class IntegrationOutAdapter implements IntegrationOutPort {
@Override
public void correlateProcessMessage(@NonNull MessageHeaders headers, Map<String, Object> payload) {
final String processInstanceId = Objects.requireNonNull(headers.get(MessageConstants.DIGIWF_PROCESS_INSTANCE_ID)).toString();
final String messageName = Objects.requireNonNull(headers.get(MessageConstants.DIGIWF_MESSAGE_NAME)).toString();
if (payload == null) {
payload = new HashMap<>();
}
this.processApi.correlateMessage(processInstanceId, messageName, payload);
this.processApi.correlateMessage(processInstanceId, payload);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.util.Map;

import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_MESSAGE_NAME;
import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_PROCESS_INSTANCE_ID;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -248,7 +247,7 @@ public T getPayload() {

@Override
public MessageHeaders getHeaders() {
return new MessageHeaders(Map.of(DIGIWF_PROCESS_INSTANCE_ID, "exampleProcessInstanceId", DIGIWF_MESSAGE_NAME, "messageName"));
return new MessageHeaders(Map.of(DIGIWF_PROCESS_INSTANCE_ID, "exampleProcessInstanceId"));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import java.util.Map;

import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_MESSAGE_NAME;
import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_PROCESS_INSTANCE_ID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
Expand All @@ -26,8 +25,7 @@ class IntegrationOutAdapterTest {
private final IntegrationOutPort integrationOutAdapter = new IntegrationOutAdapter(processApi, errorApi);

private final MessageHeaders messageHeaders = new MessageHeaders(Map.of(
DIGIWF_PROCESS_INSTANCE_ID, "processInstanceId",
DIGIWF_MESSAGE_NAME, "messageName"
DIGIWF_PROCESS_INSTANCE_ID, "processInstanceId"
));

@Test
Expand All @@ -37,12 +35,10 @@ void testCorrelateProcessMessage() {
integrationOutAdapter.correlateProcessMessage(messageHeaders, payload);

final ArgumentCaptor<String> processInstanceIdCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<String> messageNameCaptor = ArgumentCaptor.forClass(String.class);
final ArgumentCaptor<Map<String, Object>> payloadCaptor = ArgumentCaptor.forClass(Map.class);
verify(processApi).correlateMessage(processInstanceIdCaptor.capture(), messageNameCaptor.capture(), payloadCaptor.capture());
verify(processApi).correlateMessage(processInstanceIdCaptor.capture(), payloadCaptor.capture());

assertThat(processInstanceIdCaptor.getValue()).isEqualTo(messageHeaders.get(DIGIWF_PROCESS_INSTANCE_ID));
assertThat(messageNameCaptor.getValue()).isEqualTo(messageHeaders.get(DIGIWF_MESSAGE_NAME));
assertThat(payloadCaptor.getValue()).isEqualTo(payload);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ public class IntegrationOutAdapter implements IntegrationOutPort {
@Override
public void correlateProcessMessage(@NonNull MessageHeaders headers, Map<String, Object> payload) {
final String processInstanceId = Objects.requireNonNull(headers.get(MessageConstants.DIGIWF_PROCESS_INSTANCE_ID)).toString();
final String messageName = Objects.requireNonNull(headers.get(MessageConstants.DIGIWF_MESSAGE_NAME)).toString();
if (payload == null) {
payload = new HashMap<>();
}
this.processApi.correlateMessage(processInstanceId, messageName, payload);
this.processApi.correlateMessage(processInstanceId, payload);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
import de.muenchen.oss.digiwf.message.process.api.ErrorApi;
import de.muenchen.oss.digiwf.message.process.api.error.BpmnError;
import de.muenchen.oss.digiwf.message.process.api.error.IncidentError;
import jakarta.validation.ValidationException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

import jakarta.validation.ValidationException;
import java.util.function.Consumer;

import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_MESSAGE_NAME;
import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_PROCESS_INSTANCE_ID;

@Slf4j
Expand All @@ -43,7 +42,6 @@ public Consumer<Message<GenerateDocument>> cosysIntegration() {
log.debug("Generate document request: {}", document);
this.documentUseCase.createDocument(
message.getHeaders().get(DIGIWF_PROCESS_INSTANCE_ID, String.class),
message.getHeaders().get(DIGIWF_MESSAGE_NAME, String.class),
document);
} catch (final BpmnError bpmnError) {
this.errorApi.handleBpmnError(message.getHeaders(), bpmnError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class ProcessAdapter implements CorrelateMessagePort {
private final ProcessApi processApi;

@Override
public void correlateMessage(final String processInstanceId, final String messageName, final Map<String, Object> message) {
this.processApi.correlateMessage(processInstanceId, messageName, message);
public void correlateMessage(final String processInstanceId, final Map<String, Object> message) {
this.processApi.correlateMessage(processInstanceId, message);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package de.muenchen.oss.digiwf.cosys.integration.application.port.in;

import de.muenchen.oss.digiwf.cosys.integration.model.GenerateDocument;

import jakarta.validation.Valid;

public interface CreateDocument {

void createDocument(final String processInstanceIde, final String messageName, @Valid final GenerateDocument generateDocument);
void createDocument(final String processInstanceIde, @Valid final GenerateDocument generateDocument);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

public interface CorrelateMessagePort {

void correlateMessage(final String processInstanceId, final String messageName, final Map<String, Object> message);
void correlateMessage(final String processInstanceId, final Map<String, Object> message);

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package de.muenchen.oss.digiwf.cosys.integration.application.usecase;

import de.muenchen.oss.digiwf.cosys.integration.application.port.in.CreateDocument;
import de.muenchen.oss.digiwf.cosys.integration.model.GenerateDocument;
import de.muenchen.oss.digiwf.cosys.integration.application.port.out.CorrelateMessagePort;
import de.muenchen.oss.digiwf.cosys.integration.application.port.out.GenerateDocumentPort;
import de.muenchen.oss.digiwf.cosys.integration.application.port.out.SaveFileToStoragePort;
import de.muenchen.oss.digiwf.cosys.integration.model.GenerateDocument;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import jakarta.validation.Valid;

import java.util.HashMap;
import java.util.Map;

Expand All @@ -29,13 +28,13 @@ public class CreateDocumentUseCase implements CreateDocument {
* @param generateDocument Data for generating documents
*/
@Override
public void createDocument(final String processInstanceIde, final String messageName, @Valid final GenerateDocument generateDocument) {
public void createDocument(final String processInstanceIde, @Valid final GenerateDocument generateDocument) {
final byte[] data = this.generateDocumentPort.generateCosysDocument(generateDocument).block();
this.saveFileToStoragePort.saveDocumentInStorage(generateDocument, data);

final Map<String, Object> correlatePayload = new HashMap<>();
correlatePayload.put("status", true);
this.correlateMessagePort.correlateMessage(processInstanceIde,messageName,correlatePayload);
this.correlateMessagePort.correlateMessage(processInstanceIde, correlatePayload);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package de.muenchen.oss.digiwf.cosys.integration.adapter.in;

import de.muenchen.oss.digiwf.cosys.integration.application.port.in.CreateDocument;
import de.muenchen.oss.digiwf.cosys.integration.model.GenerateDocument;
import de.muenchen.oss.digiwf.cosys.integration.model.DocumentStorageUrl;
import de.muenchen.oss.digiwf.cosys.integration.model.GenerateDocument;
import de.muenchen.oss.digiwf.message.process.api.ErrorApi;
import de.muenchen.oss.digiwf.message.process.api.error.BpmnError;
import de.muenchen.oss.digiwf.message.process.api.error.IncidentError;
import jakarta.validation.ValidationException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;

import jakarta.validation.ValidationException;
import java.util.List;
import java.util.Map;

import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_MESSAGE_NAME;
import static de.muenchen.oss.digiwf.message.common.MessageConstants.DIGIWF_PROCESS_INSTANCE_ID;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*;

class MessageProcessorTest {
Expand All @@ -35,7 +34,7 @@ class MessageProcessorTest {
private List<DocumentStorageUrl> listOfURls = List.of(documentStorageUrl);
private final GenerateDocument generateDocument = new GenerateDocument("Client", "Role", "guid", null, listOfURls);

private final MessageHeaders messageHeaders = new MessageHeaders(Map.of(DIGIWF_PROCESS_INSTANCE_ID, this.processInstanceId, DIGIWF_MESSAGE_NAME, "messageName"));
private final MessageHeaders messageHeaders = new MessageHeaders(Map.of(DIGIWF_PROCESS_INSTANCE_ID, this.processInstanceId));

@BeforeEach
void setup() {
Expand All @@ -56,13 +55,13 @@ public MessageHeaders getHeaders() {
@Test
void cosysIntegrationCreateDocumentSuccessfully() {
messageProcessor.cosysIntegration().accept(this.message);
verify(createDocumentMock).createDocument(processInstanceId,"messageName", generateDocument);
verify(createDocumentMock).createDocument(processInstanceId, generateDocument);
verifyNoMoreInteractions(createDocumentMock);
}

@Test
void cosysIntegrationHandlesValidationException() {
doThrow(new ValidationException("ValidationException")).when(createDocumentMock).createDocument(any(),any(),any());
doThrow(new ValidationException("ValidationException")).when(createDocumentMock).createDocument(any(),any());
messageProcessor.cosysIntegration().accept(this.message);
final ArgumentCaptor<Map> messageHeaderArgumentCaptor = ArgumentCaptor.forClass(Map.class);
verify(errorApiMock).handleBpmnError(messageHeaderArgumentCaptor.capture(), any(BpmnError.class));
Expand All @@ -72,7 +71,7 @@ void cosysIntegrationHandlesValidationException() {

@Test
void cosysIntegrationHandlesBpmnError() {
doThrow(new BpmnError("S3_FILE_SAVE_ERROR","BpmnErrorCode")).when(createDocumentMock).createDocument(any(),any(),any());
doThrow(new BpmnError("S3_FILE_SAVE_ERROR","BpmnErrorCode")).when(createDocumentMock).createDocument(any(),any());
messageProcessor.cosysIntegration().accept(this.message);
final ArgumentCaptor<Map> messageHeaderArgumentCaptor = ArgumentCaptor.forClass(Map.class);
verify(errorApiMock).handleBpmnError(messageHeaderArgumentCaptor.capture(), any(BpmnError.class));
Expand All @@ -82,7 +81,7 @@ void cosysIntegrationHandlesBpmnError() {

@Test
void cosysIntegrationIncidentError() {
doThrow(new IncidentError("IncidentError")).when(createDocumentMock).createDocument(any(),any(),any());
doThrow(new IncidentError("IncidentError")).when(createDocumentMock).createDocument(any(),any());
messageProcessor.cosysIntegration().accept(this.message);
final ArgumentCaptor<Map> messageHeaderArgumentCaptor = ArgumentCaptor.forClass(Map.class);
verify(errorApiMock).handleIncident(messageHeaderArgumentCaptor.capture(), any(IncidentError.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import java.util.HashMap;
import java.util.Map;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.*;


class ProcessAdapterTest {
Expand All @@ -20,12 +18,11 @@ void correlateMessage() {
final ProcessAdapter processAdapter = new ProcessAdapter(processApi);

final String processInstanceId = "processInstanceId";
final String messageName = "messageName";
final Map<String, Object> message = new HashMap<>();

processAdapter.correlateMessage(processInstanceId,messageName,message);
processAdapter.correlateMessage(processInstanceId, message);

verify(processApi).correlateMessage(processInstanceId,messageName,message);
verify(processApi).correlateMessage(processInstanceId, message);
verifyNoMoreInteractions(processApi);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public ResponseEntity<byte[]> testCreateCosysDocument() {
public void testEventBus(final @RequestBody DocumentStorageUrl body) {
this.messageApi.sendMessage(body, Map.of(
MessageConstants.TYPE, "createDocumentFromEventBus",
MessageConstants.DIGIWF_PROCESS_INSTANCE_ID, "processInstanceId",
MessageConstants.DIGIWF_MESSAGE_NAME, "testCosysIntegration"
MessageConstants.DIGIWF_PROCESS_INSTANCE_ID, "processInstanceId"
), "dwf-cosys-local-01");
}

Expand Down
Loading

0 comments on commit c081f40

Please sign in to comment.