Search in sources :

Example 36 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

the class ServiceCenterClientTest method TestGetServiceMessage.

@Test
public void TestGetServiceMessage() throws IOException {
    ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setStatusCode(200);
    httpResponse.setMessage("ok");
    String responseString = "{\n" + "  \"service\": {\n" + "      \"serviceId\": \"111111\",\n" + "      \"environment\": \"string\",\n" + "      \"appId\": \"string\",\n" + "      \"serviceName\": \"string\",\n" + "      \"version\": \"string\",\n" + "      \"description\": \"string\",\n" + "      \"level\": \"string\",\n" + "      \"registerBy\": \"string\",\n" + "      \"schemas\": [\n" + "        \"string\"\n" + "      ],\n" + "      \"status\": \"UP\",\n" + "      \"timestamp\": \"string\",\n" + "      \"modTimestamp\": \"string\",\n" + "      \"framework\": {\n" + "        \"name\": \"string\",\n" + "        \"version\": \"string\"\n" + "      },\n" + "      \"paths\": [\n" + "        {\n" + "          \"Path\": \"string\",\n" + "          \"Property\": {\n" + "            \"additionalProp1\": \"string\",\n" + "            \"additionalProp2\": \"string\",\n" + "            \"additionalProp3\": \"string\"\n" + "          }\n" + "        }\n" + "      ],\n" + "      \"properties\": {\n" + "        \"additionalProp1\": \"string\",\n" + "        \"additionalProp2\": \"string\",\n" + "        \"additionalProp3\": \"string\"\n" + "      }\n" + "    }\n" + "}";
    httpResponse.setContent(responseString);
    Mockito.when(serviceCenterRawClient.getHttpRequest("/registry/microservices/111111", null, null)).thenReturn(httpResponse);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
    Microservice microservices = serviceCenterClient.getMicroserviceByServiceId("111111");
    Assert.assertNotNull(microservices);
    Assert.assertEquals("111111", microservices.getServiceId());
}
Also used : Microservice(org.apache.servicecomb.service.center.client.model.Microservice) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) Test(org.junit.Test)

Example 37 with HttpResponse

use of org.apache.servicecomb.http.client.common.HttpResponse in project java-chassis by ServiceComb.

the class ServiceCenterClientTest method TestRegisterServiceInstance.

@Test
public void TestRegisterServiceInstance() throws IOException {
    ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setStatusCode(200);
    httpResponse.setMessage("ok");
    httpResponse.setContent("{\"instanceId\": \"111111\"}");
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setInstanceId("111111");
    instance.setServiceId("222222");
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
    Mockito.when(serviceCenterRawClient.postHttpRequest("/registry/microservices/222222/instances", null, mapper.writeValueAsString(instance))).thenReturn(httpResponse);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
    RegisteredMicroserviceInstanceResponse actualResponse = serviceCenterClient.registerMicroserviceInstance(instance);
    Assert.assertNotNull(actualResponse);
    Assert.assertEquals("111111", actualResponse.getInstanceId());
}
Also used : RegisteredMicroserviceInstanceResponse(org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceInstanceResponse) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) MicroserviceInstance(org.apache.servicecomb.service.center.client.model.MicroserviceInstance) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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