@Test public void load_application_context_externally() { ServletContext servletContext = mockServletContext(); ConfigurableListableBeanFactory beanFactory = newMock( ConfigurableListableBeanFactory.class); ConfigurableWebApplicationContext ac = newMock(ConfigurableWebApplicationContext.class); Runnable fred = mockRunnable(); Runnable barney = mockRunnable(); Runnable arnold = mockRunnable(); BeanDefinition fredBeanDef = newMock(BeanDefinition.class); BeanDefinition barneyBeanDef = newMock(BeanDefinition.class); BeanDefinition arnoldBeanDef = newMock(BeanDefinition.class); ServiceBuilderResources resources = mockServiceBuilderResources(); train_getInitParameter(servletContext, SpringConstants.USE_EXTERNAL_SPRING_CONTEXT, "true"); train_getAttribute(servletContext, WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac); expect(ac.getBeanFactory()).andReturn(beanFactory); expect(ac.getBeanDefinitionNames()).andReturn(new String[] { "fred", "&barney", "arnold" }); expect(fredBeanDef.isAbstract()).andReturn(false); expect(barneyBeanDef.isAbstract()).andReturn(false); expect(arnoldBeanDef.isAbstract()).andReturn(true); expect(beanFactory.getBeanDefinition("fred")).andReturn(fredBeanDef); expect(beanFactory.getBeanDefinition("&barney")).andReturn(barneyBeanDef); expect(beanFactory.getBeanDefinition("arnold")).andReturn(arnoldBeanDef); replay(); SpringModuleDef moduleDef = new SpringModuleDef(servletContext); ServiceDef serviceDef = moduleDef.getServiceDef(SpringModuleDef.SERVICE_ID); ObjectCreator serviceCreator = serviceDef.createServiceCreator(resources); assertSame(serviceCreator.createObject(), ac); verify(); ServiceDef sd = moduleDef.getServiceDef("ApplicationContext"); assertEquals(sd.getServiceInterface(), ac.getClass()); assertEquals(sd.createServiceCreator(null).toString(), "<ObjectCreator for externally configured Spring ApplicationContext>"); expect((Class)ac.getType("fred")).andReturn(Runnable.class); expect(ac.getBean("fred")).andReturn(fred); sd = moduleDef.getServiceDef("fred"); replay(); assertEquals(sd.getServiceId(), "fred"); assertEquals(sd.getServiceInterface(), Runnable.class); assertEquals(sd.getServiceScope(), ScopeConstants.DEFAULT); assertSame(sd.createServiceCreator(null).createObject(), fred); assertTrue(sd.getMarkers().isEmpty()); assertFalse(sd.isEagerLoad()); assertEquals(sd.createServiceCreator(null).toString(), "ObjectCreator<Spring Bean 'fred'>"); verify(); expect((Class)ac.getType("barney")).andReturn(Runnable.class); expect(ac.getBean("barney")).andReturn(barney); replay(); sd = moduleDef.getServiceDef("barney"); assertSame(sd.createServiceCreator(null).createObject(), barney); assertNull(moduleDef.getServiceDef("arnold")); }
@Override public ServiceDef getServiceDef(String serviceId) { return services.get(serviceId); }
SpringModuleDef implements ModuleDef { @Override public ServiceDef getServiceDef(String serviceId) { return services.get(serviceId); } }
SpringModuleDef implements ModuleDef { @Override public ServiceDef getServiceDef(String serviceId) { return services.get(serviceId); } SpringModuleDef(ServletContext servletContext); }
SpringModuleDef implements ModuleDef { @Override public ServiceDef getServiceDef(String serviceId) { return services.get(serviceId); } SpringModuleDef(ServletContext servletContext); @Override Class getBuilderClass(); @Override Set<ContributionDef> getContributionDefs(); @Override Set<DecoratorDef> getDecoratorDefs(); @Override String getLoggerName(); @Override ServiceDef getServiceDef(String serviceId); @Override Set<String> getServiceIds(); }
SpringModuleDef implements ModuleDef { @Override public ServiceDef getServiceDef(String serviceId) { return services.get(serviceId); } SpringModuleDef(ServletContext servletContext); @Override Class getBuilderClass(); @Override Set<ContributionDef> getContributionDefs(); @Override Set<DecoratorDef> getDecoratorDefs(); @Override String getLoggerName(); @Override ServiceDef getServiceDef(String serviceId); @Override Set<String> getServiceIds();  }