|
22 | 22 | import org.springframework.test.web.servlet.MockMvc; |
23 | 23 |
|
24 | 24 | import java.util.List; |
| 25 | +import java.util.Set; |
25 | 26 |
|
26 | 27 | import static org.hamcrest.Matchers.equalTo; |
27 | 28 | import static org.mockito.Mockito.when; |
@@ -81,6 +82,53 @@ void getAll_withoutParameters_returnsAllTopics() throws Exception { |
81 | 82 | .andExpect(jsonPath("$.topics[1].tenant", equalTo(topics.get(1).getTenant()))); |
82 | 83 | } |
83 | 84 |
|
| 85 | + @Test |
| 86 | + void getAll_withProducer_returnsSpecifiyTopic() throws Exception { |
| 87 | + |
| 88 | + List<String> tenants = List.of("tenant1", "tenant2"); |
| 89 | + List<String> namespaces = List.of("tenant1/namespace1", "tenant2/namespace1"); |
| 90 | + |
| 91 | + TopicDto topicDto = TopicDto.create("persistent://tenant1/namespace1/topic1", topicStats); |
| 92 | + topicDto.setProducers(List.of("Producer")); |
| 93 | + List<TopicDto> topics = List.of(topicDto); |
| 94 | + |
| 95 | + when(tenantService.getAllNames()).thenReturn(tenants); |
| 96 | + when(namespaceService.getNamespaceNamesForTenants(tenants)).thenReturn(namespaces); |
| 97 | + when(topicService.getAllForNamespaces(namespaces)).thenReturn(topics); |
| 98 | + when(topicService.getTopicForProducer(topics, "Producer")).thenReturn(topics); |
| 99 | + |
| 100 | + |
| 101 | + mockMvc.perform(get("/topic/all?producer=Producer") |
| 102 | + .contentType(MediaType.APPLICATION_JSON)) |
| 103 | + .andExpect(status().isOk()) |
| 104 | + .andExpect(jsonPath("$.topics[0].name", equalTo(topics.get(0).getName()))) |
| 105 | + .andExpect(jsonPath("$.topics[0].namespace", equalTo(topics.get(0).getNamespace()))) |
| 106 | + .andExpect(jsonPath("$.topics[0].tenant", equalTo(topics.get(0).getTenant()))); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + void getAll_withSubscription_returnsSpecifiyTopic() throws Exception { |
| 111 | + |
| 112 | + List<String> tenants = List.of("tenant1", "tenant2"); |
| 113 | + List<String> namespaces = List.of("tenant1/namespace1", "tenant2/namespace1"); |
| 114 | + |
| 115 | + TopicDto topicDto = TopicDto.create("persistent://tenant1/namespace1/topic1", topicStats); |
| 116 | + topicDto.setSubscriptions(Set.of("Subscription")); |
| 117 | + List<TopicDto> topics = List.of(topicDto); |
| 118 | + |
| 119 | + when(tenantService.getAllNames()).thenReturn(tenants); |
| 120 | + when(namespaceService.getNamespaceNamesForTenants(tenants)).thenReturn(namespaces); |
| 121 | + when(topicService.getAllForNamespaces(namespaces)).thenReturn(topics); |
| 122 | + when(topicService.getAllForSubscriptions(topics, List.of("Subscription"))).thenReturn(topics); |
| 123 | + |
| 124 | + |
| 125 | + mockMvc.perform(get("/topic/all?subscriptions=Subscription") |
| 126 | + .contentType(MediaType.APPLICATION_JSON)) |
| 127 | + .andExpect(status().isOk()) |
| 128 | + .andExpect(jsonPath("$.topics[0].name", equalTo(topics.get(0).getName()))) |
| 129 | + .andExpect(jsonPath("$.topics[0].namespace", equalTo(topics.get(0).getNamespace()))) |
| 130 | + .andExpect(jsonPath("$.topics[0].tenant", equalTo(topics.get(0).getTenant()))); |
| 131 | + } |
84 | 132 | @Test |
85 | 133 | void getAll_withTenants_returnsAllTopicsForTenants() throws Exception { |
86 | 134 |
|
|
0 commit comments