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());
}
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());
}
Aggregations