Search in sources :

Example 31 with HttpResponse

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());
}
Also used : MicroserviceInstancesResponse(org.apache.servicecomb.service.center.client.model.MicroserviceInstancesResponse) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) Test(org.junit.Test)

Example 32 with HttpResponse

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);
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) Test(org.junit.Test)

Example 33 with HttpResponse

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);
}
Also used : HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) SchemaInfo(org.apache.servicecomb.service.center.client.model.SchemaInfo) Test(org.junit.Test)

Example 34 with HttpResponse

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);
}
Also used : HeartbeatsRequest(org.apache.servicecomb.service.center.client.model.HeartbeatsRequest) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) InstancesRequest(org.apache.servicecomb.service.center.client.model.InstancesRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 35 with HttpResponse

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());
}
Also used : HttpTransport(org.apache.servicecomb.http.client.common.HttpTransport) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Aggregations

HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)37 IOException (java.io.IOException)21 OperationException (org.apache.servicecomb.service.center.client.exception.OperationException)19 Test (org.junit.Test)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Microservice (org.apache.servicecomb.service.center.client.model.Microservice)4 HttpRequest (org.apache.servicecomb.http.client.common.HttpRequest)3 MicroserviceInstancesResponse (org.apache.servicecomb.service.center.client.model.MicroserviceInstancesResponse)3 RegisteredMicroserviceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse)3 HashMap (java.util.HashMap)2 MicroserviceInstance (org.apache.servicecomb.service.center.client.model.MicroserviceInstance)2 RegisteredMicroserviceInstanceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceInstanceResponse)2 SchemaInfo (org.apache.servicecomb.service.center.client.model.SchemaInfo)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 EventBus (com.google.common.eventbus.EventBus)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 OperationException (org.apache.servicecomb.config.center.client.exception.OperationException)1