use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.
the class ServiceCenterClientTest method TestGetServiceInstanceList.
@Test
public void TestGetServiceInstanceList() 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" + " \"timestamp\": \"333333\",\n" + " \"modTimestamp\": \"4444444\"\n" + " }\n" + " ]\n" + "}";
httpResponse.setContent(responseString);
Mockito.when(serviceCenterRawClient.getHttpRequest("/registry/microservices/222222/instances", null, null)).thenReturn(httpResponse);
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
MicroserviceInstancesResponse serviceCenterInstances = serviceCenterClient.getMicroserviceInstanceList("222222");
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 TestUpdateServicesInstanceStatus.
@Test
public void TestUpdateServicesInstanceStatus() throws IOException {
ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatusCode(200);
httpResponse.setMessage("ok");
Mockito.when(serviceCenterRawClient.putHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
Boolean result = serviceCenterClient.updateMicroserviceInstanceStatus("111", "222", MicroserviceInstanceStatus.UP);
Assert.assertNotNull(result);
Assert.assertEquals(true, result);
}
use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.
the class ServiceCenterClientTest method TestUpdateServiceSchema.
@Test
public void TestUpdateServiceSchema() throws IOException {
ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatusCode(200);
httpResponse.setMessage("ok");
Mockito.when(serviceCenterRawClient.putHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
boolean result = serviceCenterClient.updateServiceSchemaContext("111", new SchemaInfo());
Assert.assertNotNull(result);
Assert.assertEquals(true, result);
}
use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.
the class ServiceCenterClientTest method TestSendHeartBeats.
@Test
public void TestSendHeartBeats() throws IOException {
ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatusCode(200);
httpResponse.setMessage("ok");
HeartbeatsRequest heartbeatsRequest = new HeartbeatsRequest("001", "1001");
heartbeatsRequest.addInstances(new InstancesRequest("002", "1002"));
ObjectMapper mapper = new ObjectMapper();
Mockito.when(serviceCenterRawClient.putHttpRequest("/registry/microservices/111/instances/222/heartbeat", null, null)).thenReturn(httpResponse);
Mockito.when(serviceCenterRawClient.putHttpRequest("/registry/heartbeats", null, mapper.writeValueAsString(heartbeatsRequest))).thenReturn(httpResponse);
ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
serviceCenterClient.sendHeartBeats(heartbeatsRequest);
}
use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.
the class ServiceCenterRawClientTest method TestDefaultParameter.
@Test
public void TestDefaultParameter() throws IOException {
HttpTransport httpTransport = Mockito.mock(HttpTransport.class);
AddressManager addressManager = new AddressManager(PROJECT_NAME, Arrays.asList("http://127.0.0.1:30100"), new EventBus());
ServiceCenterRawClient client = new ServiceCenterRawClient.Builder().setHttpTransport(httpTransport).setAddressManager(addressManager).setTenantName(TENANT_NAME).build();
HttpResponse httpResponse = new HttpResponse();
httpResponse.setStatusCode(200);
httpResponse.setContent("ok");
Mockito.when(httpTransport.doRequest(Mockito.any())).thenReturn(httpResponse);
HttpResponse actualGetResponse = client.getHttpRequest(null, null, null);
HttpResponse actualPostResponse = client.postHttpRequest(null, null, null);
HttpResponse actualPutResponse = client.putHttpRequest(null, null, null);
HttpResponse actualDeleteResponse = client.putHttpRequest(null, null, null);
Assert.assertNotNull(actualGetResponse);
Assert.assertEquals("ok", actualGetResponse.getContent());
Assert.assertNotNull(actualPostResponse);
Assert.assertEquals("ok", actualPostResponse.getContent());
Assert.assertNotNull(actualPutResponse);
Assert.assertEquals("ok", actualPutResponse.getContent());
Assert.assertNotNull(actualDeleteResponse);
Assert.assertEquals("ok", actualDeleteResponse.getContent());
}
Aggregations