Search in sources :

Example 1 with BeanUtils

use of org.apache.servicecomb.foundation.common.utils.BeanUtils 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

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 MicroserviceMetaManager (org.apache.servicecomb.core.definition.MicroserviceMetaManager)1 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 SchemaLoader (org.apache.servicecomb.core.definition.loader.SchemaLoader)1 ExecutorManager (org.apache.servicecomb.core.executor.ExecutorManager)1 ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)1 UnitTestMeta (org.apache.servicecomb.core.unittest.UnitTestMeta)1 BeanUtils (org.apache.servicecomb.foundation.common.utils.BeanUtils)1 ReflectUtils (org.apache.servicecomb.foundation.common.utils.ReflectUtils)1 RegistryUtils (org.apache.servicecomb.serviceregistry.RegistryUtils)1 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)1 ServiceRegistryFactory (org.apache.servicecomb.serviceregistry.registry.ServiceRegistryFactory)1