|
11 | 11 | import org.springframework.beans.factory.annotation.Autowired; |
12 | 12 | import org.springframework.boot.test.context.SpringBootTest; |
13 | 13 |
|
| 14 | +import java.time.Duration; |
| 15 | +import java.time.Instant; |
14 | 16 | import java.util.ArrayList; |
15 | 17 | import java.util.List; |
16 | 18 |
|
@@ -257,15 +259,50 @@ void testSubscribeTopicWithInvalidLimit() throws HieroException { |
257 | 259 | final TopicId topicId = topicClient.createTopic(); |
258 | 260 | hieroTestUtils.waitForMirrorNodeRecords(); |
259 | 261 |
|
260 | | - final IllegalArgumentException e = Assertions.assertThrows(IllegalArgumentException.class, () -> topicClient.subscribeTopic( |
261 | | - topicId, (message) -> {/**/}, limit |
262 | | - )); |
| 262 | + final IllegalArgumentException e = Assertions.assertThrows( |
| 263 | + IllegalArgumentException.class, |
| 264 | + () -> topicClient.subscribeTopic(topicId, (message) -> {/**/}, limit) |
| 265 | + ); |
263 | 266 |
|
264 | 267 | Assertions.assertEquals(msg, e.getMessage()); |
265 | 268 | } |
266 | 269 |
|
267 | 270 | @Test |
268 | | - void testSubscribeTopicWithStartAndEndTime() { |
269 | | - //TODO |
| 271 | + void testSubscribeTopicWithStartAndEndTime() throws HieroException { |
| 272 | + final TopicId topicId = topicClient.createTopic(); |
| 273 | + hieroTestUtils.waitForMirrorNodeRecords(); |
| 274 | + final Instant start = Instant.now().plus(Duration.ofMinutes(10)); |
| 275 | + final Instant end = Instant.now().plus(Duration.ofDays(2)); |
| 276 | + final SubscriptionHandle handler = Assertions.assertDoesNotThrow( |
| 277 | + () -> topicClient.subscribeTopic(topicId, (message) -> {}, start, end) |
| 278 | + ); |
| 279 | + |
| 280 | + Assertions.assertNotNull(handler); |
| 281 | + } |
| 282 | + |
| 283 | + @Test |
| 284 | + void testSubscribeTopicWithStartAndEndTimeWithInvalidParams() throws HieroException { |
| 285 | + final TopicId topicId = topicClient.createTopic(); |
| 286 | + // Start time before Current time |
| 287 | + final Instant invalidStart = Instant.now().minus(Duration.ofMinutes(10)); |
| 288 | + final Instant end = Instant.now().plus(Duration.ofDays(2)); |
| 289 | + |
| 290 | + final IllegalArgumentException e1 = Assertions.assertThrows( |
| 291 | + IllegalArgumentException.class, |
| 292 | + () -> topicClient.subscribeTopic(topicId, (message) -> {}, invalidStart, end) |
| 293 | + ); |
| 294 | + |
| 295 | + Assertions.assertEquals("startTime must be greater than currentTime", e1.getMessage()); |
| 296 | + |
| 297 | + // End time before than Start time |
| 298 | + final Instant start = Instant.now().plus(Duration.ofMinutes(10)); |
| 299 | + final Instant invalidEnd = start.minus(Duration.ofMinutes(1)); |
| 300 | + |
| 301 | + final IllegalArgumentException e2 = Assertions.assertThrows( |
| 302 | + IllegalArgumentException.class, |
| 303 | + () -> topicClient.subscribeTopic(topicId, (message) -> {}, start, invalidEnd) |
| 304 | + ); |
| 305 | + |
| 306 | + Assertions.assertEquals("endTime must be greater than starTime", e2.getMessage()); |
270 | 307 | } |
271 | 308 | } |
0 commit comments