Skip to content

Commit 0f07e51

Browse files
committed
added test for subscribeTopic with start and end time
Signed-off-by: Manish Dait <[email protected]>
1 parent 98b24c5 commit 0f07e51

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

hiero-enterprise-spring/src/test/java/com/openelements/hiero/spring/test/TopicClientTest.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.springframework.beans.factory.annotation.Autowired;
1212
import org.springframework.boot.test.context.SpringBootTest;
1313

14+
import java.time.Duration;
15+
import java.time.Instant;
1416
import java.util.ArrayList;
1517
import java.util.List;
1618

@@ -257,15 +259,50 @@ void testSubscribeTopicWithInvalidLimit() throws HieroException {
257259
final TopicId topicId = topicClient.createTopic();
258260
hieroTestUtils.waitForMirrorNodeRecords();
259261

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+
);
263266

264267
Assertions.assertEquals(msg, e.getMessage());
265268
}
266269

267270
@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());
270307
}
271308
}

0 commit comments

Comments
 (0)