use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.
the class ServiceCenterClient method sendHeartBeats.
@Override
public void sendHeartBeats(HeartbeatsRequest heartbeatsRequest) {
try {
HttpResponse response = httpClient.putHttpRequest("/registry/heartbeats", null, HttpUtils.serialize(heartbeatsRequest));
if (response.getStatusCode() == HttpStatus.SC_OK) {
return;
}
sendUnAuthorizedEvent(response);
throw new OperationException("heartbeats fails, statusCode = " + response.getStatusCode() + "; message = " + response.getMessage() + "; content = " + response.getContent());
} catch (IOException e) {
throw new OperationException("heartbeats fails ", e);
}
}
use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.
the class ServiceCenterClientTest method TestGetServiceSchemasContext.
@Test
public void TestGetServiceSchemasContext() throws IOException {
ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatusCode(200);
httpResponse.setMessage("ok");
String responseString = "{\n" + " \"schema\": \"test context\"\n" + "}";
httpResponse.setContent(responseString);
Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
String schemaContext = serviceCenterClient.getServiceSchemaContext("111", "222");
Assert.assertNotNull(schemaContext);
Assert.assertEquals("test context", schemaContext);
}
use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.
the class ServiceCenterClientTest method TestGetServiceCenterInstances.
@Test
public void TestGetServiceCenterInstances() throws IOException {
ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatusCode(200);
httpResponse.setMessage("ok");
String responseString = "{\n" + " \"instances\": [\n" + " {\n" + " \"instanceId\": \"111111\",\n" + " \"serviceId\": \"222222\",\n" + " \"version\": \"1.0\",\n" + " \"hostName\": \"Test\",\n" + " \"endpoints\": [\n" + " \"string\"\n" + " ],\n" + " \"status\": \"UP\",\n" + " \"properties\": {\n" + " \"additionalProp1\": \"string\",\n" + " \"additionalProp2\": \"string\",\n" + " \"additionalProp3\": \"string\"\n" + " },\n" + " \"healthCheck\": {\n" + " \"mode\": \"push\",\n" + " \"port\": \"0\",\n" + " \"interval\": \"0\",\n" + " \"times\": \"0\"\n" + " },\n" + " \"dataCenterInfo\": {\n" + " \"name\": \"string\",\n" + " \"region\": \"string\",\n" + " \"availableZone\": \"string\"\n" + " },\n" + " \"timestamp\": \"333333\",\n" + " \"modTimestamp\": \"4444444\"\n" + " }\n" + " ]\n" + "}";
httpResponse.setContent(responseString);
Mockito.when(serviceCenterRawClient.getHttpRequest("/registry/health", null, null)).thenReturn(httpResponse);
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
MicroserviceInstancesResponse serviceCenterInstances = serviceCenterClient.getServiceCenterInstances();
Assert.assertNotNull(serviceCenterInstances);
Assert.assertEquals(1, serviceCenterInstances.getInstances().size());
Assert.assertEquals("111111", serviceCenterInstances.getInstances().get(0).getInstanceId());
Assert.assertEquals("222222", serviceCenterInstances.getInstances().get(0).getServiceId());
}
use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.
the class ServiceCenterClientTest method TestGetServiceSchemas.
@Test
public void TestGetServiceSchemas() throws IOException {
ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatusCode(200);
httpResponse.setMessage("ok");
String responseString = "{\n" + " \"schemas\": [\n" + " {\n" + " \"schemaId\": \"111111\",\n" + " \"schema\": \"test\",\n" + " \"summary\": \"test\"\n" + " }\n" + " ]\n" + "}";
httpResponse.setContent(responseString);
Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
List<SchemaInfo> schemaResponse = serviceCenterClient.getServiceSchemasList("111", false);
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(mapper.writeValueAsString(schemaResponse));
Assert.assertNotNull(jsonNode);
Assert.assertEquals("111111", jsonNode.get(0).get("schemaId").textValue());
Assert.assertEquals("test", jsonNode.get(0).get("schema").textValue());
}
use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.
the class ServiceCenterClientTest method TestQueryServiceId.
@Test
public void TestQueryServiceId() throws IOException {
ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatusCode(200);
httpResponse.setMessage("ok");
httpResponse.setContent("{\"serviceId\": \"111111\"}");
Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
Microservice microservice = new Microservice("Test111");
RegisteredMicroserviceResponse actualServiceId = serviceCenterClient.queryServiceId(microservice);
Assert.assertNotNull(actualServiceId);
Assert.assertEquals("111111", actualServiceId.getServiceId());
}
Aggregations