List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:org.apache.servicemix.nmr.spring.BundleExtTest.java
public void test() { final long bundleId = 32; BundleExtUrlPostProcessor processor = new BundleExtUrlPostProcessor(); processor.setBundleContext((BundleContext) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { BundleContext.class }, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("getBundle".equals(method.getName())) { return (Bundle) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { Bundle.class }, new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("getBundleId".equals(method.getName())) { return bundleId; } return null; }/*from w ww . j a va 2s . com*/ }); } return null; //To change body of implemented methods use File | Settings | File Templates. } })); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "bundle.xml" }, false); ctx.addBeanFactoryPostProcessor(processor); ctx.refresh(); Object str = ctx.getBean("string"); System.err.println(str); assertNotNull(str); assertEquals("bundle://" + bundleId + "///schema.xsd", str); }
From source file:guru.qas.martini.annotation.StepsAnnotationProcessorTest.java
@Test public void testMultipleGivenRegex() throws NoSuchMethodException { MultipleGivenBean source = new MultipleGivenBean(); ClassPathXmlApplicationContext context = getContext(source); process(context, source);//w ww .j av a2s. c om MultipleGivenBean steps = context.getBean(MultipleGivenBean.class); Class<?> wrapped = AopUtils.getTargetClass(steps); Method method = wrapped.getMethod("doSomething"); Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class); Collection<StepImplementation> givens = givenBeanIndex.values(); Set<String> matches = Sets.newHashSetWithExpectedSize(2); for (StepImplementation given : givens) { Method givenMethod = given.getMethod(); if (givenMethod.equals(method)) { Pattern pattern = given.getPattern(); String regex = pattern.pattern(); matches.add(regex); } } int count = matches.size(); assertEquals(count, 2, "wrong number of GivenStep objects registered for MultipleGivenBean.getMartinis()"); Set<String> expected = Sets.newHashSet("this is regular expression one", "this is regular expression two"); assertEquals(matches, expected, "Steps contain wrong regex Pattern objects"); }
From source file:com.ponysdk.spring.servlet.SpringHttpServlet.java
protected EntryPoint newPonySession(final UIContext ponySession) { if (clientConfigurations.isEmpty()) clientConfigurations.addAll(Arrays.asList("conf/client_application.inc.xml", "client_application.xml")); final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( clientConfigurations.toArray(new String[0])); final EventBus rootEventBus = applicationContext.getBean(EventBus.class); final EntryPoint entryPoint = applicationContext.getBean(EntryPoint.class); final PHistory history = applicationContext.getBean(PHistory.class); ponySession.setRootEventBus(rootEventBus); ponySession.setHistory(history);//from ww w . jav a2s .c o m final Map<String, InitializingActivity> initializingPages = applicationContext .getBeansOfType(InitializingActivity.class); if (initializingPages != null && !initializingPages.isEmpty()) { for (final InitializingActivity p : initializingPages.values()) { p.afterContextInitialized(); } } return entryPoint; }
From source file:org.superbiz.spring.MoviesTest.java
public void test() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("movies.xml"); // Can I lookup the Cineplex EJB via the Spring ApplicationContext Cineplex cineplex = (Cineplex) context.getBean("CineplexImplLocal"); assertNotNull(cineplex);//from www . java 2 s.c o m // Does the Cineplex EJB have a reference to the Theaters Spring bean? List<Theater> theaters = cineplex.getTheaters(); assertNotNull(theaters); assertEquals(2, theaters.size()); Theater theaterOne = theaters.get(0); Theater theaterTwo = theaters.get(1); // Were the Theater Spring beans able to use the // Movies EJB to get references to the Movie JPA objects? List<Movie> theaterOneMovies = theaterOne.getMovies(); assertNotNull(theaterOneMovies); List<Movie> theaterTwoMovies = theaterTwo.getMovies(); assertNotNull(theaterTwoMovies); // The first Theater should have used the Movies EJB // to get a reference to three Movie JPA objects assertEquals(3, theaterOneMovies.size()); assertEquals("Fargo", theaterOneMovies.get(0).getTitle()); assertEquals("Reservoir Dogs", theaterOneMovies.get(1).getTitle()); assertEquals("The Big Lebowski", theaterOneMovies.get(2).getTitle()); // The second Theater should have used the Movies EJB // to get a reference to four Movie JPA objects assertEquals(4, theaterTwoMovies.size()); assertEquals("You, Me and Dupree", theaterTwoMovies.get(0).getTitle()); assertEquals("Wedding Crashers", theaterTwoMovies.get(1).getTitle()); assertEquals("Zoolander", theaterTwoMovies.get(2).getTitle()); assertEquals("Shanghai Noon", theaterTwoMovies.get(3).getTitle()); }
From source file:org.activiti.crystalball.examples.mortages.firstsimulation.TheFirstSimulationTest.java
@Test public void testFirstRun() throws Exception { ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "org/activiti/crystalball/examples/mortages/firstsimulation/mortages-h2-context.xml"); SimulationRun simRun = (SimulationRun) appContext.getBean("simulationRun"); ProcessEngine simProcessEngine = (ProcessEngine) appContext.getBean("simProcessEngine"); simProcessEngine.getRepositoryService().createDeployment() .addClasspathResource("org/activiti/crystalball/examples/mortages/MortageDemo-0.bpmn").deploy(); //// w w w. j av a 2 s. co m // execute simulation run, without end date // simRun.execute(new Date(), null); assertEquals(1, simProcessEngine.getHistoryService().createHistoricProcessInstanceQuery().count()); simProcessEngine.close(); appContext.close(); }
From source file:any.ejbtest.MoviesTest.java
@Test @Ignore/*from w w w. j av a2 s . com*/ public void testInEjbContext() throws Exception { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("/ejb-context.xml"); applicationContext.refresh(); Movies moviesDefault = (Movies) applicationContext.getBean("moviesImpl"); Movies moviesLegacy = (Movies) applicationContext.getBean("moviesImplLegacy"); System.out.println("Default impl: "); for (Movie movie : moviesDefault.getAllMovies()) { System.out.println(movie); } assertEquals("moviesDefault : ", 2, moviesDefault.getAllMovies().size()); System.out.println("legacy impl: "); for (Movie movie : moviesLegacy.getAllMovies()) { System.out.println(movie); } assertEquals("moviesLegacy : ", 1, moviesLegacy.getAllMovies().size()); // start discriminator Movies moviesDiscriminatedInSpring = (Movies) DiscriminatorConfiguration.discriminateUsing( DiscriminatorForMovies.class, MoviesImplWrapper.class, MoviesImplLegacyWrapper.class); //get any spring bean annotated with @Discriminated or default bean Movies moviesBean = moviesDiscriminatedInSpring; //(Movies) applicationContext.getBean("moviesImplWrapper"); for (Movie movie : moviesBean.getAllMovies()) { System.out.println(movie); } assertEquals("moviesImplWrapper : ", 3, moviesBean.getAllMovies().size()); }
From source file:net.xqx.controller.web.CertificateController.java
@RequestMapping("/getcertificate") public String getCertificates(HttpServletRequest request) { String name = request.getParameter("name"); String licenseNo = request.getParameter("licenseNo"); String input = request.getParameter("rand"); String rand = (String) request.getSession().getAttribute("rand"); if (input != null && rand != null) { if (!input.equals(rand)) { request.setAttribute("CodeError1", "???"); return "redirect:zyrcindex.do"; }/*from w w w . j av a2 s. c o m*/ } ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "spring/services.xml" }); CertificateRegService certificateService = (CertificateRegService) context.getBean("certificate"); List<CertificateReg> list = null; try { list = (List<CertificateReg>) certificateService.getCertificates(name, licenseNo); } catch (SOAPFaultException e) { request.setAttribute("error", "??!"); } catch (WebServiceException ex) { request.setAttribute("error", ",???!"); } request.setAttribute("certificateList", list); // Sort hotNewsSort = new Sort(Direction.DESC, "fdjTimes", "ffbTime"); Pageable hotNewsRecPageable = new PageRequest(0, 8, hotNewsSort); List<TNews> hotNewsList = newsDao.getHotNews(hotNewsRecPageable).getContent(); request.setAttribute("hotNewsList", hotNewsList); // ?? Sort recNewsSort = new Sort(Direction.DESC, "fIsRecord", "ffbTime"); Pageable recNewsRecPageable = new PageRequest(0, 8, recNewsSort); List<TNews> recNewsList = newsDao.getNewsRec(recNewsRecPageable).getContent(); request.setAttribute("recNewsList", recNewsList); return "web/certificate/certificateDetail"; }
From source file:org.opencredo.cloud.storage.si.adapter.config.OutboundChannelAdapterParserTest.java
@Test public void testOutboundAdapterLoadWithMinimumSettings() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "OutboundChannelAdapterParserTest-context.xml", this.getClass()); Object bean = context.getBean("outbound-adapter"); assertNotNull("Adapter not found", bean); System.out.println(bean.getClass()); DirectFieldAccessor beanDirect = new DirectFieldAccessor(bean); Object value = beanDirect.getPropertyValue("handler"); assertNotNull("'handler' not found", value); System.out.println(value.getClass()); WritingMessageHandler a = (WritingMessageHandler) value; DirectFieldAccessor adapterDirect = new DirectFieldAccessor(a); assertNotNull("'template' not found", adapterDirect.getPropertyValue("template")); assertEquals(TestPropertiesAccessor.getDefaultContainerName(), adapterDirect.getPropertyValue("containerName")); assertNotNull("'blobNameBuilder' queue not found", adapterDirect.getPropertyValue("blobNameBuilder")); assertTrue(adapterDirect.getPropertyValue("blobNameBuilder") instanceof DefaultBlobNameBuilder); }
From source file:com.opengsn.services.client.NetworkManagerClient.java
public NetworkManagerClient() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "spring/application-context.xml" }); port = (INetworkManager) context.getBean("networkManagerClient"); }
From source file:org.thymeleaf.spring3.resourceresolver.SpringResourceResourceResolverSpring3Test.java
@Test public void testGetResourceAsStream() throws Exception { final String templateLocation = "spring321/view/test.html"; final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:spring321/view/applicationContext.xml"); final SpringResourceResourceResolver resolver = (SpringResourceResourceResolver) context .getBean("springResourceResourceResolver"); final TemplateProcessingParameters parameters = new TemplateProcessingParameters(new Configuration(), "test", new Context()); final InputStream is = resolver.getResourceAsStream(parameters, "classpath:" + templateLocation); final String testResource = ResourceUtils.normalize(ResourceUtils.read(is, "US-ASCII")); final String expected = ResourceUtils .read(ClassLoaderUtils.getClassLoader(SpringResourceResourceResolverSpring3Test.class) .getResourceAsStream(templateLocation), "US-ASCII", true); Assert.assertEquals(expected, testResource); }