Refine search
@Before public void setup() { ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); this.cacheManager = context.getBean("cacheManager", CacheManager.class); this.anotherCacheManager = context.getBean("anotherCacheManager", CacheManager.class); this.simpleService = context.getBean(SimpleService.class); }
@Test public void beanMethodThroughAopProxy() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(Config.class); ctx.register(AnnotationAwareAspectJAutoProxyCreator.class); ctx.register(TestAdvisor.class); ctx.refresh(); ctx.getBean("testBean", TestBean.class); }
@Test public void txManagerIsResolvedOnInvocationOfTransactionalMethod() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( EnableTxConfig.class, TxManagerConfig.class); TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class); // invoke a transactional method, causing the PlatformTransactionManager bean to be resolved. bean.findAllFoos(); ctx.close(); }
@Test public void importNonXmlResource() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportNonXmlResourceConfig.class); assertTrue(ctx.containsBean("propertiesDeclaredBean")); ctx.close(); }
@Test public void withInnerClassAndLambdaExpression() { ApplicationContext ctx = new AnnotationConfigApplicationContext(Application.class, CountingAspect.class); ctx.getBeansOfType(Runnable.class).forEach((k, v) -> v.run()); // TODO: returns just 1 as of AspectJ 1.9 beta 3, not detecting the applicable lambda expression anymore // assertEquals(2, ctx.getBean(CountingAspect.class).count); }
@Test public void importWithPlaceholder() throws Exception { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); PropertySource<?> propertySource = new MapPropertySource("test", Collections.<String, Object> singletonMap("test", "springframework")); ctx.getEnvironment().getPropertySources().addFirst(propertySource); ctx.register(ImportXmlConfig.class); ctx.refresh(); assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean")); ctx.close(); }
@Test public void importXml() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class); assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean")); assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean")); TestBean tb = ctx.getBean("javaDeclaredBean", TestBean.class); assertEquals("myName", tb.getName()); ctx.close(); }
@Test public void transactionProxyIsCreated() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( EnableTxConfig.class, TxManagerConfig.class); TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class); assertTrue("testBean is not a proxy", AopUtils.isAopProxy(bean)); Map<?,?> services = ctx.getBeansWithAnnotation(Service.class); assertTrue("Stereotype annotation not visible", services.containsKey("testBean")); ctx.close(); }
@Test public void importXmlWithOtherConfigurationClass() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithConfigurationClass.class); assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean")); assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean")); TestBean tb = ctx.getBean("javaDeclaredBean", TestBean.class); assertEquals("myName", tb.getName()); ctx.close(); }
@Test public void transactionProxyIsCreatedWithEnableOnSuperclass() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( InheritedEnableTxConfig.class, TxManagerConfig.class); TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class); assertTrue("testBean is not a proxy", AopUtils.isAopProxy(bean)); Map<?,?> services = ctx.getBeansWithAnnotation(Service.class); assertTrue("Stereotype annotation not visible", services.containsKey("testBean")); ctx.close(); }
@Test public void importXmlIsInheritedFromSuperclassDeclarations() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FirstLevelSubConfig.class); assertTrue(ctx.containsBean("xmlDeclaredBean")); ctx.close(); }
@Test public void testNullArgumentThroughBeanMethodCall() { ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanArgumentConfigWithNull.class); ctx.getBean("aFoo"); }
@Test public void withMultipleAnnotationIncludeFilters1() throws IOException, ClassNotFoundException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ComponentScanWithMultipleAnnotationIncludeFilters1.class); ctx.refresh(); ctx.getBean(DefaultNamedComponent.class); // @CustomStereotype-annotated ctx.getBean(MessageBean.class); // @CustomComponent-annotated }
@Test public void txManagerIsResolvedCorrectlyWhenMultipleManagersArePresent() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( EnableTxConfig.class, MultiTxManagerConfig.class); TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class); // invoke a transactional method, causing the PlatformTransactionManager bean to be resolved. bean.findAllFoos(); ctx.close(); }
@Test public void importXmlIsMergedFromSuperclassDeclarations() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SecondLevelSubConfig.class); assertTrue("failed to pick up second-level-declared XML bean", ctx.containsBean("secondLevelXmlDeclaredBean")); assertTrue("failed to pick up parent-declared XML bean", ctx.containsBean("xmlDeclaredBean")); ctx.close(); }
@Test(expected = BeanDefinitionStoreException.class) public void testNameClashBetweenConfigurationClassAndBean() { ApplicationContext ctx = new AnnotationConfigApplicationContext(MyTestBean.class); ctx.getBean("myTestBean", TestBean.class); }
@Test public void withMultipleAnnotationIncludeFilters2() throws IOException, ClassNotFoundException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ComponentScanWithMultipleAnnotationIncludeFilters2.class); ctx.refresh(); ctx.getBean(DefaultNamedComponent.class); // @CustomStereotype-annotated ctx.getBean(MessageBean.class); // @CustomComponent-annotated }
@Test public void importXmlWithAutowiredConfig() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlAutowiredConfig.class); String name = ctx.getBean("xmlBeanName", String.class); assertThat(name, equalTo("xml.declared")); ctx.close(); }
@Test public void testInjectionPointMatchForNarrowTargetReturnType() { ApplicationContext ctx = new AnnotationConfigApplicationContext(FooBarConfiguration.class); assertSame(ctx.getBean(BarImpl.class), ctx.getBean(FooImpl.class).bar); }
@Test public void spr12233() throws Exception { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(PropertySourcesPlaceholderConfigurer.class); ctx.register(ImportConfiguration.class); ctx.refresh(); ctx.close(); }