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);
}
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));
}
Aggregations