Search in sources :

Example 1 with MicroservicesResponse

use of org.apache.servicecomb.service.center.client.model.MicroservicesResponse in project java-chassis by ServiceComb.

the class ServiceCenterClientTest method TestGetServiceList.

@Test
public void TestGetServiceList() throws IOException {
    ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setStatusCode(200);
    httpResponse.setMessage("ok");
    MicroservicesResponse microservicesResponse = new MicroservicesResponse();
    List<Microservice> microserviceList = new ArrayList<Microservice>();
    microserviceList.add(new Microservice("Test1"));
    microserviceList.add(new Microservice("Test2"));
    microserviceList.add(new Microservice("Test3"));
    microservicesResponse.setServices(microserviceList);
    ObjectMapper mapper = new ObjectMapper();
    httpResponse.setContent(mapper.writeValueAsString(microservicesResponse));
    Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
    MicroservicesResponse actualMicroservicesResponse = serviceCenterClient.getMicroserviceList();
    Assert.assertNotNull(actualMicroservicesResponse);
    Assert.assertEquals(3, actualMicroservicesResponse.getServices().size());
    Assert.assertEquals("Test1", actualMicroservicesResponse.getServices().get(0).getServiceName());
}
Also used : Microservice(org.apache.servicecomb.service.center.client.model.Microservice) MicroservicesResponse(org.apache.servicecomb.service.center.client.model.MicroservicesResponse) ArrayList(java.util.ArrayList) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)1 Microservice (org.apache.servicecomb.service.center.client.model.Microservice)1 MicroservicesResponse (org.apache.servicecomb.service.center.client.model.MicroservicesResponse)1 Test (org.junit.Test)1