Search in sources :

Example 1 with SchemaLoader

use of org.apache.servicecomb.core.definition.loader.SchemaLoader 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 SchemaLoader

use of org.apache.servicecomb.core.definition.loader.SchemaLoader 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)

Aggregations

MicroserviceMetaManager (org.apache.servicecomb.core.definition.MicroserviceMetaManager)2 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)2 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 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 ExecutorManager (org.apache.servicecomb.core.executor.ExecutorManager)1 ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)1 BeanUtils (org.apache.servicecomb.foundation.common.utils.BeanUtils)1