use of org.springframework.context.MessageSource in project spring-framework by spring-projects.
the class AutoProxyCreatorTests method testCustomAutoProxyCreator.
@Test
public void testCustomAutoProxyCreator() {
StaticApplicationContext sac = new StaticApplicationContext();
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
sac.registerSingleton("noInterfaces", NoInterfaces.class);
sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.class);
sac.registerSingleton("singletonNoInterceptor", TestBean.class);
sac.registerSingleton("singletonToBeProxied", TestBean.class);
sac.registerPrototype("prototypeToBeProxied", TestBean.class);
sac.refresh();
MessageSource messageSource = (MessageSource) sac.getBean("messageSource");
NoInterfaces noInterfaces = (NoInterfaces) sac.getBean("noInterfaces");
ContainerCallbackInterfacesOnly containerCallbackInterfacesOnly = (ContainerCallbackInterfacesOnly) sac.getBean("containerCallbackInterfacesOnly");
ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor");
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied");
assertFalse(AopUtils.isCglibProxy(messageSource));
assertTrue(AopUtils.isCglibProxy(noInterfaces));
assertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly));
assertTrue(AopUtils.isCglibProxy(singletonNoInterceptor));
assertTrue(AopUtils.isCglibProxy(singletonToBeProxied));
assertTrue(AopUtils.isCglibProxy(prototypeToBeProxied));
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
assertEquals(0, tapc.testInterceptor.nrOfInvocations);
singletonNoInterceptor.getName();
assertEquals(0, tapc.testInterceptor.nrOfInvocations);
singletonToBeProxied.getAge();
assertEquals(1, tapc.testInterceptor.nrOfInvocations);
prototypeToBeProxied.getSpouse();
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
}
use of org.springframework.context.MessageSource in project spring-framework by spring-projects.
the class ClassPathBeanDefinitionScannerTests method testBeanAutowiredWithAnnotationConfigEnabled.
@Test
public void testBeanAutowiredWithAnnotationConfigEnabled() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(12, beanCount);
context.refresh();
FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class);
StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
MessageSource ms = (MessageSource) context.getBean("messageSource");
assertTrue(fooService.isInitCalled());
assertEquals("bar", fooService.foo(123));
assertEquals("bar", fooService.lookupFoo(123));
assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory);
assertEquals(2, fooService.listableBeanFactory.size());
assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0));
assertSame(myBf, fooService.listableBeanFactory.get(1));
assertSame(context, fooService.resourceLoader);
assertSame(context, fooService.resourcePatternResolver);
assertSame(context, fooService.eventPublisher);
assertSame(ms, fooService.messageSource);
assertSame(context, fooService.context);
assertEquals(1, fooService.configurableContext.length);
assertSame(context, fooService.configurableContext[0]);
assertSame(context, fooService.genericContext);
}
use of org.springframework.context.MessageSource in project spring-security by spring-projects.
the class JdbcDaoImplTests method setMessageSourceWhenNotNullThenCanGet.
@Test
public void setMessageSourceWhenNotNullThenCanGet() throws Exception {
MessageSource source = mock(MessageSource.class);
JdbcDaoImpl dao = new JdbcDaoImpl();
dao.setMessageSource(source);
String code = "code";
dao.getMessages().getMessage(code);
verify(source).getMessage(eq(code), any(Object[].class), any(Locale.class));
}
use of org.springframework.context.MessageSource in project head by mifos.
the class MessageLookup method getLocalizedMessage.
public static String getLocalizedMessage(String key) {
// nothing found so return the key
String message = key;
PersonnelServiceFacade personnelServiceFacade = ApplicationContextProvider.getBean(PersonnelServiceFacade.class);
MessageSource messageSource = ApplicationContextProvider.getBean(MessageSource.class);
if (personnelServiceFacade != null) {
String value = messageSource.getMessage(key, null, personnelServiceFacade.getUserPreferredLocale());
if (StringUtils.isNotEmpty(message)) {
message = value;
}
}
return message;
}
use of org.springframework.context.MessageSource in project head by mifos.
the class BaseActionForm method getLocalizedMessage.
protected String getLocalizedMessage(String key) {
// nothing found so return the key
String message = key;
PersonnelServiceFacade personnelServiceFacade = ApplicationContextProvider.getBean(PersonnelServiceFacade.class);
MessageSource messageSource = ApplicationContextProvider.getBean(MessageSource.class);
if (personnelServiceFacade != null) {
String value = messageSource.getMessage(key, null, personnelServiceFacade.getUserPreferredLocale());
if (StringUtils.isNotEmpty(message)) {
message = value;
}
}
return message;
}
Aggregations