Search in sources :

Example 1 with RegisteredMicroserviceInstanceResponse

use of org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceInstanceResponse 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

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)1 MicroserviceInstance (org.apache.servicecomb.service.center.client.model.MicroserviceInstance)1 RegisteredMicroserviceInstanceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceInstanceResponse)1 Test (org.junit.Test)1