-
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.
- Loading branch information
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/recom/property/RECOMSecurityProperties.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
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
74 changes: 74 additions & 0 deletions
74
src/test/java/com/recom/service/messagebus/MessageLongPollObserverTest.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,74 @@ | ||
package com.recom.service.messagebus; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.recom.configuration.AsyncConfiguration; | ||
import com.recom.dto.map.Point2DDto; | ||
import com.recom.model.message.MessageContainer; | ||
import com.recom.model.message.MessageType; | ||
import com.recom.model.message.OneMessage; | ||
import com.recom.observer.Subject; | ||
import com.recom.observer.Subjective; | ||
import com.recom.persistence.message.MessagePersistenceLayer; | ||
import com.recom.property.RECOMAsyncProperties; | ||
import com.recom.service.provider.StaticObjectMapperProvider; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.core.task.AsyncTaskExecutor; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; | ||
|
||
import java.io.IOException; | ||
import java.math.BigDecimal; | ||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class MessageLongPollObserverTest { | ||
|
||
@Mock | ||
private AsyncTaskExecutor asyncTaskExecutor; | ||
@Mock | ||
private MessagePersistenceLayer messagePersistenceLayer; | ||
private MessageLongPollObserver observer; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
asyncTaskExecutor = mock(AsyncTaskExecutor.class); | ||
messagePersistenceLayer = mock(MessagePersistenceLayer.class); | ||
observer = MessageLongPollObserver.builder() | ||
.timeout(10000L) // Set a reasonable timeout value | ||
.asyncTaskExecutor(asyncTaskExecutor) | ||
.messagePersistenceLayer(messagePersistenceLayer) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void testScheduleTestResponse() throws InterruptedException, IOException { | ||
// Arrange | ||
final ObjectMapper objectMapper = new ObjectMapper(); | ||
final StaticObjectMapperProvider staticObjectMapperProvider = new StaticObjectMapperProvider(objectMapper); | ||
staticObjectMapperProvider.postConstruct(); | ||
|
||
final RECOMAsyncProperties properties = RECOMAsyncProperties.builder() | ||
.corePoolSize(1) | ||
.maxPoolSize(1) | ||
.build(); | ||
|
||
// Act | ||
observer.scheduleTestResponse("TestMap", Duration.ofMillis(5), new Subject<>(), new AsyncConfiguration(properties)); | ||
|
||
// Assert | ||
// Sleep for a duration longer than the scheduled task to complete | ||
Thread.sleep(200); | ||
verify(messagePersistenceLayer, times(1)).saveAll(anyList()); | ||
} | ||
|
||
} |