Search in sources :

Example 11 with Microservice

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

the class ServiceCenterClientTest method TestRegistryService.

@Test
public void TestRegistryService() throws IOException {
    ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setStatusCode(200);
    httpResponse.setMessage("ok");
    httpResponse.setContent("{\"serviceId\": \"111111\"}");
    Microservice microservice = new Microservice();
    microservice.setServiceName("Test");
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
    Mockito.when(serviceCenterRawClient.postHttpRequest("/registry/microservices", null, objectMapper.writeValueAsString(microservice))).thenReturn(httpResponse);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
    RegisteredMicroserviceResponse actualResponse = serviceCenterClient.registerMicroservice(microservice);
    Assert.assertNotNull(actualResponse);
    Assert.assertEquals("111111", actualResponse.getServiceId());
}
Also used : Microservice(org.apache.servicecomb.service.center.client.model.Microservice) RegisteredMicroserviceResponse(org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 12 with Microservice

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

the class ServiceCenterClientTest method TestQueryServiceId.

@Test
public void TestQueryServiceId() throws IOException {
    ServiceCenterRawClient serviceCenterRawClient = Mockito.mock(ServiceCenterRawClient.class);
    HttpResponse httpResponse = new HttpResponse();
    httpResponse.setStatusCode(200);
    httpResponse.setMessage("ok");
    httpResponse.setContent("{\"serviceId\": \"111111\"}");
    Mockito.when(serviceCenterRawClient.getHttpRequest(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(httpResponse);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(serviceCenterRawClient);
    Microservice microservice = new Microservice("Test111");
    RegisteredMicroserviceResponse actualServiceId = serviceCenterClient.queryServiceId(microservice);
    Assert.assertNotNull(actualServiceId);
    Assert.assertEquals("111111", actualServiceId.getServiceId());
}
Also used : Microservice(org.apache.servicecomb.service.center.client.model.Microservice) RegisteredMicroserviceResponse(org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse) HttpResponse(org.apache.servicecomb.http.client.common.HttpResponse) Test(org.junit.Test)

Aggregations

Microservice (org.apache.servicecomb.service.center.client.model.Microservice)12 HttpResponse (org.apache.servicecomb.http.client.common.HttpResponse)8 Test (org.junit.Test)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ArrayList (java.util.ArrayList)4 RegisteredMicroserviceResponse (org.apache.servicecomb.service.center.client.model.RegisteredMicroserviceResponse)4 EventBus (com.google.common.eventbus.EventBus)2 SimpleEventBus (org.apache.servicecomb.foundation.common.event.SimpleEventBus)2 DefaultRequestAuthHeaderProvider (org.apache.servicecomb.http.client.auth.DefaultRequestAuthHeaderProvider)2 SSLProperties (org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties)2 AddressManager (org.apache.servicecomb.service.center.client.AddressManager)2 HeartBeatEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.HeartBeatEvent)2 MicroserviceInstanceRegistrationEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.MicroserviceInstanceRegistrationEvent)2 MicroserviceRegistrationEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.MicroserviceRegistrationEvent)2 SchemaRegistrationEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.SchemaRegistrationEvent)2 ServiceCenterClient (org.apache.servicecomb.service.center.client.ServiceCenterClient)2 ServiceCenterDiscovery (org.apache.servicecomb.service.center.client.ServiceCenterDiscovery)2 SubscriptionKey (org.apache.servicecomb.service.center.client.ServiceCenterDiscovery.SubscriptionKey)2 ServiceCenterRegistration (org.apache.servicecomb.service.center.client.ServiceCenterRegistration)2 MicroserviceInstance (org.apache.servicecomb.service.center.client.model.MicroserviceInstance)2