List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:com.bt.aloha.fitnesse.FixtureApplicationContexts.java
private void cancelTerminationTimers(ClassPathXmlApplicationContext applicationContext) { CallCollection callCollection = (CallCollection) applicationContext.getBean("callCollection"); ConferenceCollection conferenceCollection = (ConferenceCollection) applicationContext .getBean("conferenceCollection"); ScheduledExecutorServiceMaxCallDurationScheduler callTerminator = (ScheduledExecutorServiceMaxCallDurationScheduler) applicationContext .getBean("maxCallDurationScheduler"); ScheduledExecutorServiceMaxConferenceDurationScheduler conferenceTerminator = (ScheduledExecutorServiceMaxConferenceDurationScheduler) applicationContext .getBean("maxConferenceDurationScheduler"); ConcurrentMap<String, CallInfo> calls = callCollection.getAll(); for (CallInfo callInfo : calls.values()) callTerminator.cancelTerminateCall(callInfo); ConcurrentMap<String, ConferenceInfo> conferences = conferenceCollection.getAll(); for (ConferenceInfo conferenceInfo : conferences.values()) conferenceTerminator.cancelTerminateConference(conferenceInfo); }
From source file:org.bpmscript.endtoend.LoanBrokerTest.java
License:asdf
public void testLoanBroker() throws Exception { final int total = 10; final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/org/bpmscript/endtoend/spring.xml"); try {/*from w w w.j av a 2 s .c o m*/ final IMessageSender bus = (IMessageSender) context.getBean("bus"); final BpmScriptEngine engine = (BpmScriptEngine) context.getBean("engine"); final IVersionedDefinitionManager processManager = (IVersionedDefinitionManager) context .getBean("versionedDefinitionManager"); String source = StreamService.DEFAULT_INSTANCE .getResourceAsString("/org/bpmscript/endtoend/loanbroker.js"); String id = engine.validate(new JavascriptProcessDefinition("loanBroker", source)); processManager.createDefinition(id, new JavascriptProcessDefinition("loanBroker", source)); IBenchmarkPrinter.STDOUT.print(new Benchmark().execute(total, new IBenchmarkCallback() { public void execute(int count) throws Exception { InvocationMessage message = new InvocationMessage(); message.setArgs(null, "loanBroker", "requestBestRate", new Object[] { new LoanRequest("asdf", 1, 1000) }); message.setReplyTo("recording"); bus.send("bpmscript-first", message); } }, new IWaitForCallback() { public void call() throws Exception { RecordingAdapter recorder = (RecordingAdapter) context.getBean("recording"); BlockingQueue<IInternalMessage> internalMessages = recorder.getMessages(); for (int i = 0; i < total; i++) { Object result = internalMessages.poll(2, TimeUnit.SECONDS); assertNotNull(result); } } }, false)); } finally { context.destroy(); } log.info("done"); }
From source file:org.bpmscript.endtoend.JavaLoanBrokerTest.java
License:asdf
public void testLoanBroker() throws Exception { final int total = 10; final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "/org/bpmscript/endtoend/spring.xml"); try {//from w w w. j av a 2 s . c o m final IMessageSender bus = (IMessageSender) context.getBean("bus"); final IVersionedDefinitionManager processManager = (IVersionedDefinitionManager) context .getBean("versionedDefinitionManager"); processManager.createDefinition("id", new JavaProcessDefinition("loanBroker", LoanBrokerProcess.class.getName())); IBenchmarkPrinter.STDOUT.print(new Benchmark().execute(total, new IBenchmarkCallback() { public void execute(int count) throws Exception { InvocationMessage message = new InvocationMessage(); message.setArgs(null, "loanBroker", "requestBestRate", new Object[] { new LoanRequest("asdf", 1, 1000) }); message.setReplyTo("recording"); bus.send("bpmscript-first", message); log.debug("sent message"); } }, new IWaitForCallback() { public void call() throws Exception { RecordingAdapter recorder = (RecordingAdapter) context.getBean("recording"); BlockingQueue<IInternalMessage> internalMessages = recorder.getMessages(); for (int i = 0; i < total; i++) { Object result = internalMessages.poll(total, TimeUnit.SECONDS); assertNotNull(result); if (result instanceof ExceptionMessage) { ExceptionMessage exceptionMessage = (ExceptionMessage) result; log.error(exceptionMessage.getThrowable(), exceptionMessage.getThrowable()); fail(exceptionMessage.getThrowable().getMessage()); } } } }, false)); } finally { context.destroy(); } log.info("done"); }
From source file:ch.ralscha.extdirectspring.util.MethodInfoCacheTest.java
@Test public void testFindMethodWithAnnotation() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/testApplicationContextB.xml"); MethodInfoCache methodInfoCache = context.getBean(MethodInfoCache.class); MethodInfo methodBInfo = methodInfoCache.get("springManagedBean", "methodB"); Method methodBWithAnnotation = MethodInfo.findMethodWithAnnotation(methodBInfo.getMethod(), ExtDirectMethod.class); assertThat(methodBWithAnnotation).isEqualTo(methodBInfo.getMethod()); MethodInfo methodSubBInfo = methodInfoCache.get("springManagedSubBean", "methodB"); methodBWithAnnotation = MethodInfo.findMethodWithAnnotation(methodSubBInfo.getMethod(), ExtDirectMethod.class); assertThat(methodSubBInfo.getMethod().equals(methodBWithAnnotation)).isFalse(); assertThat(methodBInfo.getMethod().equals(methodBWithAnnotation)).isTrue(); context.close();/*from w w w . j a v a 2 s . c o m*/ }
From source file:de.uniwue.dmir.heatmap.SpringTest.java
public void testHeatmap() throws IOException { ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "spring/applicationContext.xml"); @SuppressWarnings("unchecked") IGeoDatasource<SimpleGeoPoint<String>> geoDataSource = appContext.getBean(IGeoDatasource.class); List<SimpleGeoPoint<String>> points = geoDataSource .getData(new GeoBoundingBox(new GeoCoordinates(10, 10), new GeoCoordinates(100, 100))); for (int i = 0; i < 10; i++) { System.out.println(points.get(i)); }/*from w w w.java2 s. c om*/ appContext.close(); }
From source file:ch.ralscha.extdirectspring.util.MethodInfoCacheTest.java
@Test public void testFindMethodAndInvoke() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/testApplicationContextB.xml"); MethodInfoCache methodInfoCache = context.getBean(MethodInfoCache.class); MethodInfo infoB = methodInfoCache.get("springManagedBean", "methodB"); assertThat((Boolean) ExtDirectSpringUtil.invoke(context, "springManagedBean", infoB, null)).isFalse(); assertThat((Boolean) ExtDirectSpringUtil.invoke(context, "springManagedBean", infoB, null)).isFalse(); MethodInfo infoSum = methodInfoCache.get("springManagedBean", "sum"); assertThat(ExtDirectSpringUtil.invoke(context, "springManagedBean", infoSum, new Object[] { 1, 2 })) .isEqualTo(Integer.valueOf(3)); assertThat(ExtDirectSpringUtil.invoke(context, "springManagedBean", infoSum, new Object[] { 6, 3 })) .isEqualTo(Integer.valueOf(9)); assertThat(methodInfoCache.get("springManagedBean", "methodC")).isNull(); context.close();/*ww w. ja v a2s. co m*/ }
From source file:com.ryantenney.metrics.spring.RegistryTest.java
@Test public void testDefaultRegistries() { ClassPathXmlApplicationContext ctx = null; try {/*from ww w . j a va 2 s . co m*/ ctx = new ClassPathXmlApplicationContext("classpath:default-registries.xml"); Assert.assertNotNull("Should have a MetricRegistry bean.", ctx.getBean(MetricRegistry.class)); Assert.assertNotNull("Should have a HealthCheckRegistry bean.", ctx.getBean(HealthCheckRegistry.class)); } finally { if (ctx != null) { ctx.close(); } } }
From source file:org.apache.ibatis.submitted.foreach.Issue67Test.java
/** * This test uses Spring./*w w w. ja va2 s. co m*/ */ @Test public void testWithSpring() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:org/apache/ibatis/submitted/foreach/applicationContext.xml"); Mapper mapper = (Mapper) context.getBean("mapper"); assertNotNull(mapper); execQuery(mapper); context.close(); }
From source file:guru.qas.martini.annotation.StepsAnnotationProcessorTest.java
@Test public void testPostProcessAfterInitialization() throws IOException, NoSuchMethodException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); TestSteps steps = context.getBean(TestSteps.class); Class<?> wrapped = AopUtils.getTargetClass(steps); Method method = wrapped.getMethod("anotherStep", String.class); Map<String, StepImplementation> givenBeanIndex = context.getBeansOfType(StepImplementation.class); Collection<StepImplementation> givens = givenBeanIndex.values(); List<StepImplementation> matches = Lists.newArrayList(); for (StepImplementation given : givens) { Method givenMethod = given.getMethod(); if (givenMethod.equals(method)) { matches.add(given);// w w w .jav a2 s. c om } } int count = matches.size(); assertEquals(count, 1, "wrong number of GivenStep objects registered for TestSteps.anotherStep()"); StepImplementation match = matches.get(0); Pattern pattern = match.getPattern(); Matcher matcher = pattern.matcher("another \"(.+)\" here"); assertTrue(matcher.find(), "expected Pattern to match Gherkin regular expression"); assertEquals(matcher.groupCount(), 1, "wrong number of parameters captured for TestSteps.anotherStep()"); }