Search in sources :

Example 1 with MicroserviceMetaManager

use of org.apache.servicecomb.core.definition.MicroserviceMetaManager in project incubator-servicecomb-java-chassis by apache.

the class TestConsumerSchemaFactory method init.

@BeforeClass
public static void init() {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    RegistryUtils.setServiceRegistry(serviceRegistry);
    SchemaListenerManager schemaListenerManager = new SchemaListenerManager();
    schemaListenerManager.setSchemaListenerList(Arrays.asList(schemaListener));
    MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
    SchemaLoader schemaLoader = new SchemaLoader() {

        @Override
        public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
        }
    };
    CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
    ReflectUtils.setField(consumerSchemaFactory, "schemaListenerManager", schemaListenerManager);
    ReflectUtils.setField(consumerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
    ReflectUtils.setField(consumerSchemaFactory, "schemaLoader", schemaLoader);
    ReflectUtils.setField(consumerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
    SchemaMeta schemaMeta = new UnitTestMeta().getOrCreateSchemaMeta(TestConsumerSchemaFactoryImpl.class);
    String content = UnitTestSwaggerUtils.pretty(schemaMeta.getSwagger());
    Microservice microservice = new Microservice();
    microservice.setAppId("app");
    microservice.setServiceId("0");
    microservice.setServiceName("ms");
    microservice.setVersion("1.0.0");
    microservice.addSchema("schema", content);
    serviceRegistry.getServiceRegistryClient().registerMicroservice(microservice);
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setServiceId("0");
    instance.setInstanceId("0");
    serviceRegistry.getServiceRegistryClient().registerMicroserviceInstance(instance);
}
Also used : MicroserviceMetaManager(org.apache.servicecomb.core.definition.MicroserviceMetaManager) SchemaLoader(org.apache.servicecomb.core.definition.loader.SchemaLoader) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) UnitTestMeta(org.apache.servicecomb.core.unittest.UnitTestMeta) CompositeSwaggerGeneratorContext(org.apache.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) SchemaListenerManager(org.apache.servicecomb.core.definition.loader.SchemaListenerManager) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) BeforeClass(org.junit.BeforeClass)

Example 2 with MicroserviceMetaManager

use of org.apache.servicecomb.core.definition.MicroserviceMetaManager in project incubator-servicecomb-java-chassis by apache.

the class TestSchemaListenerManager method testInitializationListener.

@Test
public void testInitializationListener() {
    SchemaListener listener = new SchemaListener() {

        @Override
        public void onSchemaLoaded(SchemaMeta... schemaMetas) {
            Assert.assertEquals(1, schemaMetas.length);
            Assert.assertEquals("test", schemaMetas[0].getSchemaId());
        }
    };
    SchemaListenerManager mgr = new SchemaListenerManager();
    mgr.setSchemaListenerList(Arrays.asList(listener));
    mgr.setMicroserviceMetaManager(new MicroserviceMetaManager());
    mgr.notifySchemaListener(schemaMeta);
}
Also used : MicroserviceMetaManager(org.apache.servicecomb.core.definition.MicroserviceMetaManager) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) Test(org.junit.Test)

Example 3 with MicroserviceMetaManager

use of org.apache.servicecomb.core.definition.MicroserviceMetaManager in project incubator-servicecomb-java-chassis by apache.

the class TestProducerSchemaFactory method init.

@BeforeClass
public static void init() {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    RegistryUtils.setServiceRegistry(serviceRegistry);
    ConverterMgr converterMgr = new ConverterMgr();
    ProducerArgumentsMapperFactory producerArgsMapperFactory = new ProducerArgumentsMapperFactory();
    producerArgsMapperFactory.setConverterMgr(converterMgr);
    MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
    SchemaLoader schemaLoader = new SchemaLoader() {

        @Override
        public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
        }
    };
    CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
    producerSchemaFactory.setSwaggerEnv(swaggerEnv);
    ReflectUtils.setField(producerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
    ReflectUtils.setField(producerSchemaFactory, "schemaLoader", schemaLoader);
    ReflectUtils.setField(producerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
    Executor reactiveExecutor = new ReactiveExecutor();
    Executor normalExecutor = (cmd) -> {
    };
    new MockUp<BeanUtils>() {

        @SuppressWarnings("unchecked")
        @Mock
        <T> T getBean(String name) {
            if (ExecutorManager.EXECUTOR_REACTIVE.equals(name)) {
                return (T) reactiveExecutor;
            }
            return (T) normalExecutor;
        }
    };
    // ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
    // BeanUtils.setContext(applicationContext);
    // Mockito.when(applicationContext.getBean(ExecutorManager.EXECUTOR_REACTIVE)).thenReturn(new ReactiveExecutor());
    UnitTestMeta.init();
    schemaMeta = producerSchemaFactory.getOrCreateProducerSchema("app:ms", "schema", TestProducerSchemaFactoryImpl.class, new TestProducerSchemaFactoryImpl());
}
Also used : BeanUtils(org.apache.servicecomb.foundation.common.utils.BeanUtils) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) ExecutorManager(org.apache.servicecomb.core.executor.ExecutorManager) BeforeClass(org.junit.BeforeClass) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) RegistryUtils(org.apache.servicecomb.serviceregistry.RegistryUtils) BootstrapNormal(org.apache.servicecomb.swagger.engine.bootstrap.BootstrapNormal) SchemaLoader(org.apache.servicecomb.core.definition.loader.SchemaLoader) CompletableFuture(java.util.concurrent.CompletableFuture) ProducerArgumentsMapperFactory(org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperFactory) Mock(mockit.Mock) Response(org.apache.servicecomb.swagger.invocation.Response) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) AfterClass(org.junit.AfterClass) MockUp(mockit.MockUp) Executor(java.util.concurrent.Executor) Const(org.apache.servicecomb.core.Const) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) ReflectUtils(org.apache.servicecomb.foundation.common.utils.ReflectUtils) MicroserviceMetaManager(org.apache.servicecomb.core.definition.MicroserviceMetaManager) CompositeSwaggerGeneratorContext(org.apache.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext) Invocation(org.apache.servicecomb.core.Invocation) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation) ConverterMgr(org.apache.servicecomb.swagger.invocation.converter.ConverterMgr) ServiceRegistryFactory(org.apache.servicecomb.serviceregistry.registry.ServiceRegistryFactory) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) Holder(javax.xml.ws.Holder) Endpoint(org.apache.servicecomb.core.Endpoint) UnitTestMeta(org.apache.servicecomb.core.unittest.UnitTestMeta) Assert(org.junit.Assert) MicroserviceMetaManager(org.apache.servicecomb.core.definition.MicroserviceMetaManager) SchemaLoader(org.apache.servicecomb.core.definition.loader.SchemaLoader) ProducerArgumentsMapperFactory(org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperFactory) CompositeSwaggerGeneratorContext(org.apache.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) MockUp(mockit.MockUp) ConverterMgr(org.apache.servicecomb.swagger.invocation.converter.ConverterMgr) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) Executor(java.util.concurrent.Executor) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) BeforeClass(org.junit.BeforeClass)

Example 4 with MicroserviceMetaManager

use of org.apache.servicecomb.core.definition.MicroserviceMetaManager in project incubator-servicecomb-java-chassis by apache.

the class TestDefinition method testMicroserviceMetaManager.

@Test
public void testMicroserviceMetaManager() throws Exception {
    MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
    microserviceMetaManager.getOrCreateMicroserviceMeta("app:testname");
    Assert.assertEquals("microservice meta manager", microserviceMetaManager.getName());
    Assert.assertEquals("Not allow register repeat data, name=%s, key=%s", microserviceMetaManager.getRegisterErrorFmt());
    Assert.assertEquals(0, microserviceMetaManager.getAllSchemaMeta("app:testname").size());
    Swagger oSwagger = new Swagger();
    Info oInfo = new Info();
    oInfo.setVendorExtension("x-java-interface", "java.lang.String");
    oSwagger.setInfo(oInfo);
    Assert.assertEquals("java.lang.String", (ClassUtils.getJavaInterface(oSwagger)).getName());
    oInfo.setVendorExtension("x-java-class", "java.lang.String");
}
Also used : MicroserviceMetaManager(org.apache.servicecomb.core.definition.MicroserviceMetaManager) Swagger(io.swagger.models.Swagger) Info(io.swagger.models.Info) Test(org.junit.Test)

Aggregations

MicroserviceMetaManager (org.apache.servicecomb.core.definition.MicroserviceMetaManager)4 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)3 Test (org.junit.Test)3 SchemaLoader (org.apache.servicecomb.core.definition.loader.SchemaLoader)2 UnitTestMeta (org.apache.servicecomb.core.unittest.UnitTestMeta)2 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)2 CompositeSwaggerGeneratorContext (org.apache.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext)2 BeforeClass (org.junit.BeforeClass)2 Info (io.swagger.models.Info)1 Swagger (io.swagger.models.Swagger)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Executor (java.util.concurrent.Executor)1 Holder (javax.xml.ws.Holder)1 Mock (mockit.Mock)1 MockUp (mockit.MockUp)1 Const (org.apache.servicecomb.core.Const)1 Endpoint (org.apache.servicecomb.core.Endpoint)1 Invocation (org.apache.servicecomb.core.Invocation)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 SchemaListenerManager (org.apache.servicecomb.core.definition.loader.SchemaListenerManager)1