|
27 | 27 | import com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo;
|
28 | 28 | import com.alibaba.nacos.naming.core.v2.pojo.Service;
|
29 | 29 | import com.alibaba.nacos.naming.misc.UtilsAndCommons;
|
| 30 | +import com.alibaba.nacos.naming.pojo.Subscriber; |
30 | 31 | import com.fasterxml.jackson.databind.JsonNode;
|
31 | 32 | import org.junit.jupiter.api.BeforeEach;
|
32 | 33 | import org.junit.jupiter.api.Test;
|
|
47 | 48 |
|
48 | 49 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
49 | 50 | import static org.mockito.ArgumentMatchers.anyString;
|
| 51 | +import static org.mockito.Mockito.mock; |
50 | 52 | import static org.mockito.Mockito.when;
|
51 | 53 |
|
52 | 54 | @ExtendWith(MockitoExtension.class)
|
@@ -142,4 +144,30 @@ void testGetPublishedClientList() throws Exception {
|
142 | 144 | .param("groupName", baseTestKey).param("serviceName", baseTestKey).param("ip", "127.0.0.1").param("port", "8848");
|
143 | 145 | mockmvc.perform(mockHttpServletRequestBuilder).andExpect(MockMvcResultMatchers.jsonPath("$.data.length()").value(1));
|
144 | 146 | }
|
| 147 | + |
| 148 | + @Test |
| 149 | + void testGetSubscribeClientList() throws Exception { |
| 150 | + String baseTestKey = "nacos-getSubScribedClientList-test"; |
| 151 | + // ip port match |
| 152 | + Service service = Service.newService(baseTestKey, baseTestKey, baseTestKey); |
| 153 | + when(clientServiceIndexesManager.getAllClientsSubscribeService(service)).thenReturn(Arrays.asList("test")); |
| 154 | + when(clientManager.getClient("test")).thenReturn(ipPortBasedClient); |
| 155 | + Subscriber subscriber = mock(Subscriber.class); |
| 156 | + when(subscriber.getIp()).thenReturn("127.0.0.1"); |
| 157 | + when(subscriber.getPort()).thenReturn(8848); |
| 158 | + ipPortBasedClient.addServiceSubscriber(service, subscriber); |
| 159 | + MockHttpServletRequestBuilder mockHttpServletRequestBuilder = MockMvcRequestBuilders.get(URL + "/service/subscriber/list") |
| 160 | + .param("namespaceId", baseTestKey).param("groupName", baseTestKey).param("serviceName", baseTestKey) |
| 161 | + .param("ip", "127.0.0.1").param("port", "8848"); |
| 162 | + mockmvc.perform(mockHttpServletRequestBuilder).andExpect(MockMvcResultMatchers.jsonPath("$.data.length()").value(1)); |
| 163 | + // ip port not match |
| 164 | + mockHttpServletRequestBuilder = MockMvcRequestBuilders.get(URL + "/service/subscriber/list") |
| 165 | + .param("namespaceId", baseTestKey).param("groupName", baseTestKey).param("serviceName", baseTestKey) |
| 166 | + .param("ip", "127.0.0.1").param("port", "8849"); |
| 167 | + mockmvc.perform(mockHttpServletRequestBuilder).andExpect(MockMvcResultMatchers.jsonPath("$.data.length()").value(0)); |
| 168 | + // ip port is null |
| 169 | + mockHttpServletRequestBuilder = MockMvcRequestBuilders.get(URL + "/service/subscriber/list") |
| 170 | + .param("namespaceId", baseTestKey).param("groupName", baseTestKey).param("serviceName", baseTestKey); |
| 171 | + mockmvc.perform(mockHttpServletRequestBuilder).andExpect(MockMvcResultMatchers.jsonPath("$.data.length()").value(1)); |
| 172 | + } |
145 | 173 | }
|
0 commit comments