use of org.apache.servicecomb.config.archaius.sources.ConfigCenterConfigurationSourceImpl.UpdateHandler in project incubator-servicecomb-java-chassis by apache.
the class TestConfigCenterClient method testConnectServer.
@SuppressWarnings("unchecked")
@Test
public void testConnectServer() {
HttpClientRequest request = Mockito.mock(HttpClientRequest.class);
Mockito.when(request.method()).thenReturn(HttpMethod.GET);
Mockito.when(request.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap());
Buffer rsp = Mockito.mock(Buffer.class);
Mockito.when(rsp.toJsonObject()).thenReturn(new JsonObject("{\"instances\":[{\"status\":\"UP\",\"endpoints\":[\"rest:0.0.0.0:30103\"],\"hostName\":\"125292-0.0.0.0\",\"serviceName\":\"configServer\",\"https\":false}]}"));
HttpClientResponse event = Mockito.mock(HttpClientResponse.class);
Mockito.when(event.bodyHandler(Mockito.any(Handler.class))).then(invocation -> {
Handler<Buffer> handler = invocation.getArgumentAt(0, Handler.class);
handler.handle(rsp);
return null;
});
Mockito.when(event.statusCode()).thenReturn(200);
HttpClient httpClient = Mockito.mock(HttpClient.class);
Mockito.when(httpClient.get(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.any(Handler.class))).then(invocation -> {
Handler<HttpClientResponse> handler = invocation.getArgumentAt(3, Handler.class);
handler.handle(event);
return request;
});
new MockUp<HttpClientWithContext>() {
@Mock
public void runOnContext(RunHandler handler) {
handler.run(httpClient);
}
};
new MockUp<MemberDiscovery>() {
@Mock
public void refreshMembers(JsonObject members) {
Assert.assertTrue(members.size() == 1);
}
};
UpdateHandler updateHandler = new ConfigCenterConfigurationSourceImpl().new UpdateHandler();
ConfigCenterClient cc = new ConfigCenterClient(updateHandler);
cc.connectServer();
}
Aggregations