use of cn.taketoday.context.ApplicationContext in project today-infrastructure by TAKETODAY.
the class ConversionServiceDeducerTests method getConversionServiceWhenHasQualifiedConverterBeansContainsCustomizedApplicationService.
@Test
void getConversionServiceWhenHasQualifiedConverterBeansContainsCustomizedApplicationService() {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(CustomConverterConfiguration.class);
ConversionServiceDeducer deducer = new ConversionServiceDeducer(applicationContext);
List<ConversionService> conversionServices = deducer.getConversionServices();
assertThat(conversionServices).hasSize(1);
assertThat(conversionServices.get(0)).isNotSameAs(ApplicationConversionService.getSharedInstance());
assertThat(conversionServices.get(0).canConvert(InputStream.class, OutputStream.class)).isTrue();
}
use of cn.taketoday.context.ApplicationContext in project today-infrastructure by TAKETODAY.
the class ConversionServiceDeducerTests method getConversionServicesWhenHasConversionServiceBeanContainsOnlyBean.
@Test
void getConversionServicesWhenHasConversionServiceBeanContainsOnlyBean() {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(CustomConverterServiceConfiguration.class);
ConversionServiceDeducer deducer = new ConversionServiceDeducer(applicationContext);
TestApplicationConversionService expected = applicationContext.getBean(TestApplicationConversionService.class);
assertThat(deducer.getConversionServices()).containsExactly(expected);
}
use of cn.taketoday.context.ApplicationContext in project today-infrastructure by TAKETODAY.
the class ClassPathBeanDefinitionScannerScopeIntegrationTests method requestScopeWithProxiedTargetClass.
@Test
void requestScopeWithProxiedTargetClass() {
RequestContextHolder.set(oldRequestAttributes);
ApplicationContext context = createContext(TARGET_CLASS);
IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
// should be a class-based proxy
assertThat(AopUtils.isCglibProxy(bean)).isTrue();
boolean condition = bean instanceof RequestScopedTestBean;
assertThat(condition).isTrue();
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
bean.setName(MODIFIED_NAME);
RequestContextHolder.set(newRequestAttributes);
// this is a proxy so it should be reset to default
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
RequestContextHolder.set(oldRequestAttributes);
assertThat(bean.getName()).isEqualTo(MODIFIED_NAME);
}
use of cn.taketoday.context.ApplicationContext in project today-infrastructure by TAKETODAY.
the class ClassPathBeanDefinitionScannerScopeIntegrationTests method sessionScopeWithNoProxy.
@Test
void sessionScopeWithNoProxy() {
RequestContextHolder.set(oldRequestAttributesWithSession);
ApplicationContext context = createContext(NO);
ScopedTestBean bean = (ScopedTestBean) context.getBean("session");
// should not be a proxy
assertThat(AopUtils.isAopProxy(bean)).isFalse();
assertThat(bean.getName()).isEqualTo(DEFAULT_NAME);
bean.setName(MODIFIED_NAME);
RequestContextHolder.set(newRequestAttributesWithSession);
// not a proxy so this should not have changed
assertThat(bean.getName()).isEqualTo(MODIFIED_NAME);
// but a newly retrieved bean should have the default name
ScopedTestBean bean2 = (ScopedTestBean) context.getBean("session");
assertThat(bean2.getName()).isEqualTo(DEFAULT_NAME);
}
use of cn.taketoday.context.ApplicationContext in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesBindExceptionTests method createFromBeanHasDetails.
@Test
void createFromBeanHasDetails() {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Example.class);
ConfigurationPropertiesBean bean = ConfigurationPropertiesBean.get(applicationContext, applicationContext.getBean(Example.class), "example");
ConfigurationPropertiesBindException exception = new ConfigurationPropertiesBindException(bean, new IllegalStateException());
assertThat(exception.getNestedMessage()).isEqualTo("Error creating bean with name 'example': " + "Could not bind properties to 'ConfigurationPropertiesBindExceptionTests.Example' : " + "prefix=, ignoreInvalidFields=false, ignoreUnknownFields=true; " + "Nested exception is java.lang.IllegalStateException");
assertThat(exception.getBeanType()).isEqualTo(Example.class);
assertThat(exception.getBeanName()).isEqualTo("example");
assertThat(exception.getAnnotation()).isInstanceOf(ConfigurationProperties.class);
assertThat(exception.getCause()).isInstanceOf(IllegalStateException.class);
}
Aggregations