Skip to content

Commit

Permalink
Merge pull request #112 from OpenWiseSolutions/bugfix/final-processin…
Browse files Browse the repository at this point in the history
…g-without-response

[OHFJIRA-107] : fixed final message processing of messages without response
  • Loading branch information
sabolm committed Apr 14, 2020
2 parents 4c251fe + 5095802 commit f6e947c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Expand Up @@ -96,7 +96,9 @@ protected void deleteRequestsResponses(final Message message) {
LOG.debug("Will delete request [{}] and response [{}].",
request.getId(),
request.getResponse() != null ? request.getResponse().getId() : null);
requestResponseDao.deleteResponse(request.getResponse());
if (request.getResponse() != null) {
requestResponseDao.deleteResponse(request.getResponse());
}
requestResponseDao.deleteRequest(request);
}
}
Expand Down
Expand Up @@ -19,16 +19,12 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.times;
import static org.junit.Assert.assertThat;

import javax.persistence.TypedQuery;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
import org.mockito.Mockito;
import org.openhubframework.openhub.api.asynch.finalmessage.FinalMessageProcessor;
import org.openhubframework.openhub.api.entity.ExternalCall;
import org.openhubframework.openhub.api.entity.Message;
Expand Down Expand Up @@ -146,6 +142,33 @@ public void test_delete_withAllEntities() {
assertThat(countInTable(Response.class), is(0L));
}

@Test
public void test_delete_withoutResponse() {
final Message message = createAndSaveMessage(
ExternalSystemTestEnum.CRM,
ServiceTestEnum.ACCOUNT,
"testOperation",
"payload");
final Long msgId = message.getId();

Request request = Request.createRequest("jms:test.queue", "join id", "request payload", message);
requestResponseService.insertRequest(request);

// verify data is present
assertThat(messageService.findMessageById(msgId), notNullValue());
assertThat(countInTable(Message.class), is(1L));
assertThat(countInTable(Request.class), is(1L));

// invoke tested
transactionTemplate.execute((TransactionStatus status) -> {
deleteFinalMessageProcessor.processMessage(message);
return null; // without result
});

assertThat(messageService.findMessageById(msgId), nullValue());
assertThat(countInTable(Message.class), is(0L));
assertThat(countInTable(Request.class), is(0L));
}

private long countInTable(Class clazz) {
TypedQuery<Long> query = em.createQuery(
Expand Down

0 comments on commit f6e947c

Please sign in to comment.