forked from mosip/esignet-signup
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added testcases for websocket channel interceptor
Signed-off-by: Sachin Rana <[email protected]>
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
signup-service/src/test/java/io/mosip/signup/util/WebSocketChannelInterceptorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.mosip.signup.util; | ||
|
||
import io.mosip.signup.dto.IdentityVerificationTransaction; | ||
import io.mosip.signup.exception.SignUpException; | ||
import io.mosip.signup.services.CacheUtilService; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.messaging.Message; | ||
import org.springframework.messaging.MessageChannel; | ||
import org.springframework.messaging.simp.stomp.StompCommand; | ||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; | ||
import org.springframework.messaging.support.MessageBuilder; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class WebSocketChannelInterceptorTest { | ||
|
||
@InjectMocks | ||
private WebSocketChannelInterceptor channelInterceptor; | ||
|
||
@Mock | ||
private CacheUtilService cacheUtilService; | ||
|
||
@Test | ||
public void websocketSubscribe_withValidSlotId_thenPass() { | ||
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.SUBSCRIBE); | ||
headerAccessor.setDestination("/topic/slotid"); | ||
Message<?> message = MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders()); | ||
Mockito.when(cacheUtilService.getVerifiedSlotTransaction(Mockito.anyString())).thenReturn(new IdentityVerificationTransaction()); | ||
|
||
Assertions.assertDoesNotThrow(() -> channelInterceptor.preSend(message, new MessageChannel() { | ||
@Override | ||
public boolean send(Message<?> message, long l) { | ||
return false; | ||
} | ||
})); | ||
} | ||
|
||
@Test | ||
public void websocketSubscribe_withInvalidSlotId_thenThrow() { | ||
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(StompCommand.SUBSCRIBE); | ||
headerAccessor.setDestination("/topic/slotid"); | ||
Message<?> message = MessageBuilder.createMessage(new byte[0], headerAccessor.getMessageHeaders()); | ||
Mockito.when(cacheUtilService.getVerifiedSlotTransaction(Mockito.anyString())).thenReturn(null); | ||
|
||
Assertions.assertThrows(SignUpException.class, () -> channelInterceptor.preSend(message, new MessageChannel() { | ||
@Override | ||
public boolean send(Message<?> message, long l) { | ||
return false; | ||
} | ||
})); | ||
} | ||
} |