Search in sources :

Example 1 with SchemaListenerManager

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

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

the class TestCseApplicationListener method testCseApplicationListenerNormal.

@Test
public void testCseApplicationListenerNormal(@Injectable ContextRefreshedEvent event, @Injectable AbstractApplicationContext context, @Injectable ProducerProviderManager producerProviderManager, @Injectable ConsumerProviderManager consumerProviderManager, @Injectable TransportManager transportManager, @Mocked RegistryUtils ru) {
    Map<String, BootListener> listeners = new HashMap<>();
    BootListener listener = Mockito.mock(BootListener.class);
    listeners.put("test", listener);
    SchemaListenerManager schemaListenerManager = Mockito.mock(SchemaListenerManager.class);
    MicroserviceInstance microserviceInstance = Mockito.mock(MicroserviceInstance.class);
    new Expectations() {

        {
            context.getBeansOfType(BootListener.class);
            result = listeners;
        }
    };
    new Expectations(RegistryUtils.class) {

        {
            RegistryUtils.init();
            RegistryUtils.getInstanceCacheManager();
            RegistryUtils.run();
            RegistryUtils.getMicroserviceInstance();
            result = microserviceInstance;
        }
    };
    Mockito.when(microserviceInstance.getInstanceId()).thenReturn("testInstanceId");
    CseApplicationListener cal = new CseApplicationListener();
    Deencapsulation.setField(cal, "schemaListenerManager", schemaListenerManager);
    cal.setInitEventClass(ContextRefreshedEvent.class);
    cal.setApplicationContext(context);
    ReflectUtils.setField(cal, "producerProviderManager", producerProviderManager);
    ReflectUtils.setField(cal, "consumerProviderManager", consumerProviderManager);
    ReflectUtils.setField(cal, "transportManager", transportManager);
    cal.onApplicationEvent(event);
    EventManager.post(Mockito.mock(MicroserviceInstanceRegisterTask.class));
    verify(schemaListenerManager).notifySchemaListener();
    verify(listener, times(10)).onBootEvent(Mockito.any(BootEvent.class));
}
Also used : Expectations(mockit.Expectations) HashMap(java.util.HashMap) BootEvent(org.apache.servicecomb.core.BootListener.BootEvent) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) SchemaListenerManager(org.apache.servicecomb.core.definition.loader.SchemaListenerManager) MicroserviceInstanceRegisterTask(org.apache.servicecomb.serviceregistry.task.MicroserviceInstanceRegisterTask) Test(org.junit.Test)

Aggregations

SchemaListenerManager (org.apache.servicecomb.core.definition.loader.SchemaListenerManager)2 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)2 HashMap (java.util.HashMap)1 Expectations (mockit.Expectations)1 BootEvent (org.apache.servicecomb.core.BootListener.BootEvent)1 MicroserviceMetaManager (org.apache.servicecomb.core.definition.MicroserviceMetaManager)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 SchemaLoader (org.apache.servicecomb.core.definition.loader.SchemaLoader)1 UnitTestMeta (org.apache.servicecomb.core.unittest.UnitTestMeta)1 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)1 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)1 MicroserviceInstanceRegisterTask (org.apache.servicecomb.serviceregistry.task.MicroserviceInstanceRegisterTask)1 CompositeSwaggerGeneratorContext (org.apache.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1