MessageSubscriptionConverter { public MessageSubscriptionImpl convertToMessageSubscription(MessageEventSubscriptionEntity messageEventSubscriptionEntity) { return Optional.of(messageEventSubscriptionEntity) .map(entity -> MessageSubscriptionImpl.builder() .withId(entity.getId()) .withEventName(entity.getEventName()) .withProcessDefinitionId(entity.getProcessDefinitionId()) .withConfiguration(entity.getConfiguration()) .withActivityId(entity.getActivityId()) .withBusinessKey(Optional.ofNullable(entity.getExecution()) .map(DelegateExecution::getProcessInstanceBusinessKey) .orElse(null)) .withCreated(entity.getCreated()) .withExecutionId(entity.getExecutionId()) .withProcessInstanceId(entity.getProcessInstanceId()) .build()) .orElseThrow( () -> new IllegalArgumentException("messageEventSubscriptionEntity must not be null")); }  MessageSubscriptionImpl convertToMessageSubscription(MessageEventSubscriptionEntity messageEventSubscriptionEntity);  }
@Test public void convertShouldReturnBPMNMessage() { MessageEventSubscriptionEntity entity = mock(MessageEventSubscriptionEntity.class); given(entity.getConfiguration()).willReturn("correlationKey"); given(entity.getEventName()).willReturn("messageName"); given(entity.getProcessDefinitionId()).willReturn("procDefId"); given(entity.getProcessInstanceId()).willReturn("procInstId"); MessageSubscriptionImpl messageSubscription = converter.convertToMessageSubscription(entity); assertThat(messageSubscription).isNotNull(); assertThat(messageSubscription.getProcessInstanceId()).isEqualTo("procInstId"); assertThat(messageSubscription.getProcessDefinitionId()).isEqualTo("procDefId"); assertThat(messageSubscription.getConfiguration()).isEqualTo("correlationKey"); assertThat(messageSubscription.getEventName()).isEqualTo("messageName"); }