|
1 | 1 | package org.sterl.spring.persistent_tasks.history.api; |
2 | 2 |
|
3 | | -import static org.junit.jupiter.api.Assertions.*; |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import java.time.OffsetDateTime; |
4 | 6 |
|
5 | 7 | import org.junit.jupiter.api.BeforeEach; |
6 | 8 | import org.junit.jupiter.api.Test; |
7 | | -import org.springframework.beans.factory.annotation.Autowired; |
8 | 9 | import org.springframework.boot.test.web.server.LocalServerPort; |
| 10 | +import org.springframework.http.HttpMethod; |
9 | 11 | import org.springframework.web.client.RestTemplate; |
10 | 12 | import org.sterl.spring.persistent_tasks.AbstractSpringTest; |
11 | | -import org.sterl.spring.persistent_tasks.trigger.repository.RunningTriggerRepository; |
| 13 | +import org.sterl.spring.persistent_tasks.api.TaskId; |
| 14 | + |
| 15 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 16 | +import com.fasterxml.jackson.databind.JsonMappingException; |
12 | 17 |
|
13 | 18 | class TriggerHistoryResourceTest extends AbstractSpringTest { |
14 | 19 |
|
15 | 20 | @LocalServerPort |
16 | 21 | private int port; |
17 | | - @Autowired |
18 | | - private RunningTriggerRepository triggerRepository; |
19 | 22 | private String baseUrl; |
20 | 23 | private final RestTemplate template = new RestTemplate(); |
21 | 24 |
|
22 | 25 | @BeforeEach |
23 | 26 | void setupRest() { |
24 | | - baseUrl = "http://localhost:" + port + "/spring-tasks-api"; |
| 27 | + baseUrl = "http://localhost:" + port + "/spring-tasks-api/"; |
25 | 28 | } |
26 | 29 |
|
27 | 30 | @Test |
28 | | - void test() { |
29 | | - fail("Not yet implemented"); |
| 31 | + void testGroupSearch() throws JsonMappingException, JsonProcessingException { |
| 32 | + TaskId<String> taskId = taskService.replace("foo", c -> asserts.info("foo")); |
| 33 | + triggerService.queue(taskId.newTrigger().id("1").correlationId("a1").tag("tag1").build()); |
| 34 | + triggerService.queue(taskId.newTrigger().id("2").correlationId("a1").tag("tag1").build()); |
| 35 | + triggerService.queue(taskId.newTrigger().id("3").correlationId("a1").tag("tag2").build()); |
| 36 | + |
| 37 | + // WHEN |
| 38 | + persistentTaskTestService.runAllDueTrigger(OffsetDateTime.now().plusMinutes(1)); |
| 39 | + var result = template.exchange( |
| 40 | + baseUrl + TriggerHistoryResource.PATH_GROUP + "?tag=tag1", |
| 41 | + HttpMethod.GET, |
| 42 | + null, |
| 43 | + String.class); |
| 44 | + |
| 45 | + assertThat(result.getBody()).contains("\"count\":2"); |
| 46 | + assertThat(result.getBody()).contains("\"groupByValue\":\"a1\""); |
30 | 47 | } |
31 | 48 |
|
32 | 49 | } |
0 commit comments