Refine search
@Test @SuppressWarnings("resource") public void testWithDependencyChecking() { ApplicationContext ctx = new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass()); ctx.getBean("testBean"); }
@Before public void setup() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); highPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("highPrecedenceAspect"); lowPrecedenceAspect = (PrecedenceTestAspect) ctx.getBean("lowPrecedenceAspect"); highPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("highPrecedenceSpringAdvice"); lowPrecedenceSpringAdvice = (SimpleSpringBeforeAdvice) ctx.getBean("lowPrecedenceSpringAdvice"); testBean = (ITestBean) ctx.getBean("testBean"); }
@Test public void testNoScopedProxy() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "org/springframework/context/annotation/scopedProxyNoTests.xml"); context.getBeanFactory().registerScope("myScope", new SimpleMapScope()); ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean"); // should not be a proxy assertFalse(AopUtils.isAopProxy(bean)); context.close(); }
/** * In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before * launch the application */ public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-provider.xml"); context.start(); System.in.read(); } }
/** * In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before * launch the application */ public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml"); context.start(); DemoService demoService = context.getBean("demoService", DemoService.class); String hello = demoService.sayHello("world"); System.out.println("result: " + hello); } }
@Test public void staticScriptWithNullReturnValue() { ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass()); assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfig")); ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerWithConfig"); messenger.setMessage(null); assertNull(messenger.getMessage()); assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger)); }
@Test public void testJsr223FromTagWithInterface() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("groovy-with-xsd-jsr223.xml", getClass()); assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithInterface")); Messenger messenger = (Messenger) ctx.getBean("messengerWithInterface"); assertFalse(AopUtils.isAopProxy(messenger)); }
@Before public void setup() { this.context = new ClassPathXmlApplicationContext( "scheduledTasksContext.xml", ScheduledTasksBeanDefinitionParserTests.class); this.registrar = this.context.getBeansOfType( ScheduledTaskRegistrar.class).values().iterator().next(); this.testBean = this.context.getBean("testBean"); }
@Test public void testChildWithProxy() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD); ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext( new String[] {CHILD_WITH_PROXY_CONTEXT}, ctx); assertTrue(AopUtils.isAopProxy(child.getBean("assemblerOne"))); assertTrue(AopUtils.isAopProxy(child.getBean("assemblerTwo"))); ctx.close(); }
@Test public void staticWithScriptReturningInstance() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass()); assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstance")); Messenger messenger = (Messenger) ctx.getBean("messengerInstance"); String desiredMessage = "Hello World!"; assertEquals("Message is incorrect", desiredMessage, messenger.getMessage()); assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger)); ctx.close(); assertNull(messenger.getMessage()); }
@Test public void testContextWithClassNameThatContainsPlaceholder() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CLASS_WITH_PLACEHOLDER_CONTEXT, getClass()); assertTrue(ctx.containsBean("someMessageSource")); assertTrue(ctx.getBean("someMessageSource") instanceof StaticMessageSource); ctx.close(); }
@Test public void testSingleConfigLocation() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(FQ_SIMPLE_CONTEXT); assertTrue(ctx.containsBean("someMessageSource")); ctx.close(); }
/** * Return a bean factory with attributes and EnterpriseServices configured. */ protected BeanFactory getBeanFactory() throws IOException { return new ClassPathXmlApplicationContext(DEFAULT_CONTEXT, CLASS); }
@Test public void customAnnotationUsedForBothComponentScanAndQualifier() { ClassPathXmlApplicationContext context = loadContext("customAnnotationUsedForBothComponentScanAndQualifierTests.xml"); KustomAnnotationAutowiredBean testBean = (KustomAnnotationAutowiredBean) context.getBean("testBean"); assertNotNull(testBean.getDependency()); context.close(); }
@Test public void testCustomBeanNameGenerator() { ApplicationContext context = new ClassPathXmlApplicationContext( "org/springframework/context/annotation/customNameGeneratorTests.xml"); assertTrue(context.containsBean("testing.fooServiceImpl")); }
@Test public void testFactoryBeanAndApplicationListener() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CONTEXT_WILDCARD); ctx.getBeanFactory().registerSingleton("manualFBAAL", new FactoryBeanAndApplicationListener()); assertEquals(2, ctx.getBeansOfType(ApplicationListener.class).size()); ctx.close(); }
@Test public void testWithBeanNameAutoProxyCreator() { ClassPathXmlApplicationContext bf = newContext("withBeanNameAutoProxyCreator.xml"); ITestBean tb = (ITestBean) bf.getBean("adrian"); assertEquals(68, tb.getAge()); }
@Test public void aspectjTypeFilter() { ClassPathXmlApplicationContext context = loadContext("aspectjTypeFilterTests.xml"); assertTrue(context.containsBean("fooServiceImpl")); assertTrue(context.containsBean("stubFooDao")); assertFalse(context.containsBean("scopedProxyTestBean")); context.close(); }
@After public void after() { if (enabled != null) { System.setProperty("ENABLED", enabled); } else { System.clearProperty("ENABLED"); } if (context != null) { context.close(); } }