Skip to content

Commit

Permalink
fixed failing test. added test
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsilaghi committed Nov 27, 2024
1 parent ae1c3e3 commit 5490786
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 5490786

Please sign in to comment.