Search in sources :

Example 1 with MicroserviceMetaManager

use of io.servicecomb.core.definition.MicroserviceMetaManager in project java-chassis by ServiceComb.

the class TestProducerSchemaFactory method init.

@BeforeClass
public static void init() {
    ProducerResponseMapperFactory responseMapperFactory = new ProducerResponseMapperFactory();
    responseMapperFactory.setMapperList(Arrays.asList(new ProducerResponseSame()));
    ProducerArgumentsMapperFactory producerArgsMapperFactory = new ProducerArgumentsMapperFactory();
    MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
    SchemaLoader schemaLoader = new SchemaLoader() {

        @Override
        public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
        }
    };
    CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
    ReflectUtils.setField(producerSchemaFactory, "producerArgsMapperFactory", producerArgsMapperFactory);
    ReflectUtils.setField(producerSchemaFactory, "responseMapperFactory", responseMapperFactory);
    ReflectUtils.setField(producerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
    ReflectUtils.setField(producerSchemaFactory, "schemaLoader", schemaLoader);
    ReflectUtils.setField(producerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
    BeanUtils.setContext(Mockito.mock(ApplicationContext.class));
    UnitTestMeta.init();
    schemaMeta = producerSchemaFactory.getOrCreateProducerSchema("app:ms", "schema", TestProducerSchemaFactoryImpl.class, new TestProducerSchemaFactoryImpl());
}
Also used : MicroserviceMetaManager(io.servicecomb.core.definition.MicroserviceMetaManager) SchemaLoader(io.servicecomb.core.definition.loader.SchemaLoader) ApplicationContext(org.springframework.context.ApplicationContext) ProducerArgumentsMapperFactory(io.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperFactory) ProducerResponseMapperFactory(io.servicecomb.swagger.invocation.response.producer.ProducerResponseMapperFactory) ProducerResponseSame(io.servicecomb.swagger.invocation.response.producer.ProducerResponseSame) CompositeSwaggerGeneratorContext(io.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext) BeforeClass(org.junit.BeforeClass)

Example 2 with MicroserviceMetaManager

use of io.servicecomb.core.definition.MicroserviceMetaManager in project java-chassis by ServiceComb.

the class TestDefinition method testMicroserviceMetaManager.

@Test
public void testMicroserviceMetaManager() throws Exception {
    MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
    microserviceMetaManager.getOrCreateMicroserviceMeta("testname");
    Assert.assertEquals("microservice meta manager", microserviceMetaManager.getName());
    Assert.assertEquals("Not allow regsiter repeat data, name=%s, key=%s", microserviceMetaManager.getRegisterErrorFmt());
    Assert.assertEquals(0, microserviceMetaManager.getAllSchemaMeta("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(io.servicecomb.core.definition.MicroserviceMetaManager) Swagger(io.swagger.models.Swagger) Info(io.swagger.models.Info) Test(org.junit.Test)

Example 3 with MicroserviceMetaManager

use of io.servicecomb.core.definition.MicroserviceMetaManager in project java-chassis by ServiceComb.

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(io.servicecomb.core.definition.MicroserviceMetaManager) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) Test(org.junit.Test)

Example 4 with MicroserviceMetaManager

use of io.servicecomb.core.definition.MicroserviceMetaManager in project java-chassis by ServiceComb.

the class TestConsumerSchemaFactory method init.

@BeforeClass
public static void init() {
    ReflectUtils.setField(RegistryClientFactory.class, null, "registryClient", registryClient);
    SchemaListenerManager schemaListenerManager = new SchemaListenerManager();
    schemaListenerManager.setSchemaListenerList(Arrays.asList(schemaListener));
    ConsumerResponseMapperFactory responseMapperFactory = new ConsumerResponseMapperFactory();
    responseMapperFactory.setMapperList(Arrays.asList(new ConsumerResponseSame()));
    ConsumerArgumentsMapperFactory consumerArgsMapperFactory = new ConsumerArgumentsMapperFactory();
    MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
    SchemaLoader schemaLoader = new SchemaLoader();
    CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
    ReflectUtils.setField(consumerSchemaFactory, "schemaListenerManager", schemaListenerManager);
    ReflectUtils.setField(consumerSchemaFactory, "consumerArgsMapperFactory", consumerArgsMapperFactory);
    ReflectUtils.setField(consumerSchemaFactory, "responseMapperFactory", responseMapperFactory);
    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());
    Mockito.when(registryClient.getMicroserviceId("app", "ms", "latest")).thenReturn("0");
    Mockito.when(registryClient.getSchema("0", "schema")).thenReturn(content);
    Microservice microservice = new Microservice();
    microservice.setAppId("app");
    microservice.setServiceId("0");
    microservice.addSchema("schema", content);
    Mockito.when(registryClient.getMicroservice("0")).thenReturn(microservice);
}
Also used : ConsumerResponseSame(io.servicecomb.swagger.invocation.response.consumer.ConsumerResponseSame) MicroserviceMetaManager(io.servicecomb.core.definition.MicroserviceMetaManager) SchemaLoader(io.servicecomb.core.definition.loader.SchemaLoader) Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) UnitTestMeta(io.servicecomb.core.unittest.UnitTestMeta) CompositeSwaggerGeneratorContext(io.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) SchemaListenerManager(io.servicecomb.core.definition.loader.SchemaListenerManager) ConsumerResponseMapperFactory(io.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapperFactory) ConsumerArgumentsMapperFactory(io.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapperFactory) BeforeClass(org.junit.BeforeClass)

Aggregations

MicroserviceMetaManager (io.servicecomb.core.definition.MicroserviceMetaManager)4 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)2 SchemaLoader (io.servicecomb.core.definition.loader.SchemaLoader)2 CompositeSwaggerGeneratorContext (io.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 SchemaListenerManager (io.servicecomb.core.definition.loader.SchemaListenerManager)1 UnitTestMeta (io.servicecomb.core.unittest.UnitTestMeta)1 Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)1 ConsumerArgumentsMapperFactory (io.servicecomb.swagger.invocation.arguments.consumer.ConsumerArgumentsMapperFactory)1 ProducerArgumentsMapperFactory (io.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperFactory)1 ConsumerResponseMapperFactory (io.servicecomb.swagger.invocation.response.consumer.ConsumerResponseMapperFactory)1 ConsumerResponseSame (io.servicecomb.swagger.invocation.response.consumer.ConsumerResponseSame)1 ProducerResponseMapperFactory (io.servicecomb.swagger.invocation.response.producer.ProducerResponseMapperFactory)1 ProducerResponseSame (io.servicecomb.swagger.invocation.response.producer.ProducerResponseSame)1 Info (io.swagger.models.Info)1 Swagger (io.swagger.models.Swagger)1 ApplicationContext (org.springframework.context.ApplicationContext)1