Search in sources :

Example 51 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestServiceRegistryClientImpl method getAggregatedMicroservice.

@Test
public void getAggregatedMicroservice() {
    String microserviceId = "msId";
    new MockUp<RestClientUtil>() {

        @Mock
        void httpDo(RequestContext requestContext, Handler<RestResponse> responseHandler) {
            Holder<GetServiceResponse> holder = Deencapsulation.getField(responseHandler, "arg$4");
            holder.value = Json.decodeValue("{\"service\":{\"serviceId\":\"serviceId\",\"framework\":null" + ",\"registerBy\":null,\"environment\":null,\"appId\":\"appId\",\"serviceName\":null," + "\"alias\":null,\"version\":null,\"description\":null,\"level\":null,\"schemas\":[]," + "\"paths\":[],\"status\":\"UP\",\"properties\":{},\"intance\":null}}", GetServiceResponse.class);
            RequestParam requestParam = requestContext.getParams();
            Assert.assertEquals("global=true", requestParam.getQueryParams());
        }
    };
    Microservice aggregatedMicroservice = oClient.getAggregatedMicroservice(microserviceId);
    Assert.assertEquals("serviceId", aggregatedMicroservice.getServiceId());
    Assert.assertEquals("appId", aggregatedMicroservice.getAppId());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) GetServiceResponse(org.apache.servicecomb.serviceregistry.api.response.GetServiceResponse) Handler(io.vertx.core.Handler) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 52 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestServiceRegistryClientImpl method testPrivateMethodCreateHttpClientOptions.

@Test
public void testPrivateMethodCreateHttpClientOptions() {
    ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_APPLICATION, "app");
    ArchaiusUtils.setProperty(BootStrapProperties.CONFIG_SERVICE_NAME, "ms");
    MicroserviceFactory microserviceFactory = new MicroserviceFactory();
    Microservice microservice = microserviceFactory.create();
    oClient.registerMicroservice(microservice);
    oClient.registerMicroserviceInstance(microservice.getInstance());
    try {
        oClient.init();
        HttpClientOptions httpClientOptions = Deencapsulation.invoke(oClient, "createHttpClientOptions");
        Assert.assertNotNull(httpClientOptions);
        Assert.assertEquals(80, httpClientOptions.getDefaultPort());
    } catch (Exception e) {
        Assert.assertNotNull(e);
    }
    ArchaiusUtils.resetConfig();
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) HttpClientOptions(io.vertx.core.http.HttpClientOptions) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) Test(org.junit.Test)

Example 53 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class LocalServiceRegistryClientImplTest method testLoadSchemaIdsFromRegistryFile.

@Test
public void testLoadSchemaIdsFromRegistryFile() {
    Microservice microservice = registryClient.getMicroservice("002");
    Assert.assertThat(microservice.getSchemas().size(), Is.is(1));
    Assert.assertTrue(microservice.getSchemas().contains("hello"));
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 54 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class LocalServiceRegistryClientImplTest method getMicroserviceId_fixVersion.

@Test
public void getMicroserviceId_fixVersion() {
    Microservice v1 = mockRegisterMicroservice(appId, microserviceName, "1.0.0");
    mockRegisterMicroservice(appId, microserviceName, "2.0.0");
    String serviceId = registryClient.getMicroserviceId(appId, microserviceName, "1.0.0", "");
    Assert.assertEquals(v1.getServiceId(), serviceId);
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 55 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestConsumers method deleteWhenCreateMicroserviceVersion.

@Test
public void deleteWhenCreateMicroserviceVersion() {
    new MockUp<DiscoveryManager>() {

        @Mock
        public Microservice getMicroservice(String microserviceId) {
            return null;
        }
    };
    try (LogCollector collector = new LogCollector()) {
        appManager.getOrCreateMicroserviceVersionRule(appId, serviceName, versionRule);
        Assert.assertEquals(0, microserviceManager.getVersionsByName().size());
        Assert.assertThat(collector.getEvents().stream().filter(e -> e.getThrowableInformation() != null).map(e -> e.getThrowableInformation().getThrowable().getMessage()).toArray(), Matchers.hasItemInArray("failed to query by microserviceId '002' from ServiceCenter."));
    }
}
Also used : LogCollector(org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector) Arrays(java.util.Arrays) LogCollector(org.apache.servicecomb.foundation.test.scaffolding.log.LogCollector) MockUp(mockit.MockUp) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) MicroserviceKey(org.apache.servicecomb.registry.api.MicroserviceKey) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) DiscoveryManager(org.apache.servicecomb.registry.DiscoveryManager) MicroserviceInstanceChangedEvent(org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent) MicroserviceVersion(org.apache.servicecomb.registry.consumer.MicroserviceVersion) After(org.junit.After) MicroserviceVersions(org.apache.servicecomb.registry.consumer.MicroserviceVersions) Mock(mockit.Mock) RegistrationManager(org.apache.servicecomb.registry.RegistrationManager) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) Assert(org.junit.Assert) Before(org.junit.Before) MockUp(mockit.MockUp) Test(org.junit.Test)

Aggregations

Microservice (org.apache.servicecomb.registry.api.registry.Microservice)86 Test (org.junit.Test)53 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)20 Expectations (mockit.Expectations)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 GetSchemaResponse (org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse)10 Holder (org.apache.servicecomb.serviceregistry.client.http.Holder)10 HashMap (java.util.HashMap)9 MicroserviceFactory (org.apache.servicecomb.registry.api.registry.MicroserviceFactory)9 Swagger (io.swagger.models.Swagger)8 Before (org.junit.Before)8 MockUp (mockit.MockUp)6 Configuration (org.apache.commons.configuration.Configuration)6 AccessController (org.apache.servicecomb.authentication.provider.AccessController)6 Subscribe (com.google.common.eventbus.Subscribe)5 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)5 EventBus (com.google.common.eventbus.EventBus)4 Version (org.apache.servicecomb.foundation.common.Version)4 HashSet (java.util.HashSet)3