diff --git a/src/main/java/edu/stanford/protege/webprotege/ipc/impl/RabbitMQEventHandlerWrapper.java b/src/main/java/edu/stanford/protege/webprotege/ipc/impl/RabbitMQEventHandlerWrapper.java index 2e41a07..ba58b20 100644 --- a/src/main/java/edu/stanford/protege/webprotege/ipc/impl/RabbitMQEventHandlerWrapper.java +++ b/src/main/java/edu/stanford/protege/webprotege/ipc/impl/RabbitMQEventHandlerWrapper.java @@ -42,7 +42,7 @@ public void onMessage(Message message) { var accessToken = String.valueOf(message.getMessageProperties().getHeaders().get(ACCESS_TOKEN)); var userId = (String) message.getMessageProperties().getHeaders().get(USER_ID); - if(accessToken != null && !accessToken.isEmpty()){ + if(accessToken != null && !accessToken.isEmpty() && !"null".equalsIgnoreCase(accessToken)){ ExecutionContext executionContext = new ExecutionContext(UserId.valueOf(userId), accessToken); eventHandler.handleEvent(event, executionContext); } else { diff --git a/src/test/java/edu/stanford/protege/webprotege/ipc/EventHandleWrapperTest.java b/src/test/java/edu/stanford/protege/webprotege/ipc/EventHandleWrapperTest.java index 66027f6..55aa54f 100644 --- a/src/test/java/edu/stanford/protege/webprotege/ipc/EventHandleWrapperTest.java +++ b/src/test/java/edu/stanford/protege/webprotege/ipc/EventHandleWrapperTest.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import edu.stanford.protege.webprotege.common.UserId; import edu.stanford.protege.webprotege.ipc.impl.RabbitMQEventHandlerWrapper; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.BeforeEach; @@ -55,6 +56,19 @@ public void GIVEN_eventOnDummyChannel_WHEN_handleEvent_THEN_correctHandlerIsCall verify(dummyEventHandler, times(1)).handleEvent(any()); } + @Test + public void GIVEN_eventOnDummyChannelWithExecutionContext_WHEN_handleEvent_THEN_methodWithExecutionContextIsUsed() throws JsonProcessingException { + TestEvent testEvent = new TestEvent("1", "2"); + Message message = MessageBuilder.withBody(new ObjectMapper().writeValueAsBytes(testEvent)).build(); + message.getMessageProperties().setHeaders(new HashMap<>()); + message.getMessageProperties().getHeaders().put(Headers.ACCESS_TOKEN, "testJwt"); + message.getMessageProperties().getHeaders().put(Headers.USER_ID, "dummy-test-user"); + + eventHandler.onMessage(message); + + verify(dummyEventHandler, times(0)).handleEvent(any(), eq(new ExecutionContext(UserId.valueOf("dummy-test-user"), "testJwt"))); + } + @Test public void GIVEN_eventOnDifferentChannel_WHEN_handleEvent_THEN_noHandleIsCalled() throws JsonProcessingException { TestEvent testEvent = new TestEvent("1", "2");