List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:org.activiti.crystalball.simulator.PlaybackTest.java
@Test public void testPlaybackRun() throws Exception { System.setProperty("_SIM_DB_PATH", System.getProperty("tempDir", "target") + "/Playback-test"); System.setProperty("liveDB", "target/Playback"); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/PlaybackSimEngine-h2-context.xml"); HistoryService simHistoryService = (HistoryService) appContext.getBean("simHistoryService"); // init identity service IdentityService identityService = (IdentityService) appContext.getBean("simIdentityService"); identityService.saveGroup(identityService.newGroup("Group1")); identityService.saveUser(identityService.newUser("user1")); identityService.createMembership("user1", "Group1"); SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class); RepositoryService simRepositoryService = (RepositoryService) appContext.getBean("simRepositoryService"); // deploy processes simRepositoryService.createDeployment() .addClasspathResource("org/activiti/crystalball/simulator/Playback.bpmn").deploy(); Calendar c = Calendar.getInstance(); c.clear();// ww w .j ava2 s .com c.set(2013, 3, 3); Date startDate = c.getTime(); c.add(Calendar.SECOND, 10); Date finishDate = c.getTime(); // run simulation for 10 seconds simRun.execute(startDate, finishDate); assertEquals(3, simHistoryService.createHistoricProcessInstanceQuery().count()); List<HistoricProcessInstance> processInstances = simHistoryService.createHistoricProcessInstanceQuery() .orderByProcessInstanceStartTime().asc().list(); HistoricProcessInstance processInstance = processInstances.get(0); HistoricVariableInstance variableInstance = simHistoryService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(1); variableInstance = simHistoryService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(2, ((Integer) variableInstance.getValue()).intValue()); processInstance = processInstances.get(2); variableInstance = simHistoryService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()).variableName("x").singleResult(); assertEquals(3, ((Integer) variableInstance.getValue()).intValue()); appContext.close(); }
From source file:net.sf.oval.test.integration.spring.SpringAOPAllianceTest.java
public void testCGLIBProxying() { final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "SpringAOPAllianceTestCGLIBProxy.xml", SpringAOPAllianceTest.class); try {/* w ww . ja v a2 s . co m*/ { final TestServiceWithoutInterface testServiceWithoutInterface = (TestServiceWithoutInterface) ctx .getBean("testServiceWithoutInterface"); try { testServiceWithoutInterface.getSomething(null); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("NOT_NULL", ex.getConstraintViolations()[0].getMessage()); } try { testServiceWithoutInterface.getSomething("123456"); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("MAX_LENGTH", ex.getConstraintViolations()[0].getMessage()); } } { final TestServiceInterface testServiceWithInterface = ctx.getBean("testServiceWithInterface", TestServiceInterface.class); try { testServiceWithInterface.getSomething(null); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("NOT_NULL", ex.getConstraintViolations()[0].getMessage()); } try { testServiceWithInterface.getSomething("123456"); fail(); } catch (final ConstraintsViolatedException ex) { assertEquals("MAX_LENGTH", ex.getConstraintViolations()[0].getMessage()); } } } finally { ctx.close(); } }
From source file:org.drools.container.spring.SpringDroolsTest.java
@Test public void testResourceNameAndDescription() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "org/drools/container/spring/beans.xml"); DroolsResourceAdapter resource = (DroolsResourceAdapter) context.getBean("secureResource"); assertNotNull(resource);/*w w w. j av a 2s .co m*/ InternalResource secureResource = (InternalResource) resource.getDroolsResource(); assertNull(secureResource.getName()); assertNull(secureResource.getDescription()); resource = (DroolsResourceAdapter) context.getBean("resourceWithNameAndDescription"); assertNotNull(resource); InternalResource resourceWithNameAndDescription = (InternalResource) resource.getDroolsResource(); assertEquals("A Name", resourceWithNameAndDescription.getName()); assertEquals("A Description", resourceWithNameAndDescription.getDescription()); }
From source file:com.bt.aloha.fitnesse.InboundMediaCallFixture.java
public InboundMediaCallFixture() { super();//from w w w .j av a 2s. c o m ClassPathXmlApplicationContext inboundApplicationContext = FixtureApplicationContexts.getInstance() .startInboundApplicationContext(); mediaCallBean = (MediaCallBean) inboundApplicationContext.getBean("mediaCallBean"); List<MediaCallListener> list = new ArrayList<MediaCallListener>(); list.add(this); ((MediaCallBeanImpl) mediaCallBean).setMediaCallListeners(list); inboundApplicationContextBeans.getInboundCallLegBean() .addInboundCallLegListener(new InboundAnnouncementCallLegListener()); inboundApplicationContextBeans.getInboundCallLegBean() .addInboundCallLegListener(new InboundPromptAndCollectCallLegListener()); }
From source file:org.springmodules.validation.bean.BeanValidatorIntegrationTests.java
public void testBeanValidator_WithApplicationContext() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "org/springmodules/validation/bean/beanValidator-tests.xml"); Person person = new Person("Uri"); BindException errors = new BindException(person, "person"); Validator validator = (Validator) context.getBean("validator"); validator.validate(person, errors);/*from w w w . j ava 2 s.c om*/ assertTrue(errors.hasGlobalErrors()); assertEquals(1, errors.getGlobalErrorCount()); assertEquals("Person[bad]", errors.getGlobalError().getCode()); }
From source file:com.baidu.cc.spring.ConfigChangeNotiferAnnotationParserTest.java
/** * test annotation parser. by mock class. *//*from w w w .j a v a 2 s.c om*/ @Test public void testAnnotationParserByMock() { ClassPathXmlApplicationContext appContext; appContext = new ClassPathXmlApplicationContext( "classpath:/com/baidu/cc/annotation/applicationContext.xml"); appContext.start(); //get service bean ConfigServerServiceMock configServerService; configServerService = (ConfigServerServiceMock) appContext.getBean("configServerServiceMocker"); Assert.assertNotNull(configServerService); try { Thread.sleep(500L); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } Map<String, String> ret = new HashMap<String, String>(); ret.put(ConfigServerService.TAG_KEY, ConfigServerServiceMock.TEST_TAG_NEW_VALUE); ret.put("key1", "value1"); ret.put("key2", "value22"); ret.put("key3", "value3"); ret.put("xml", "2"); configServerService.setProps(ret); configServerService.setTagValue(ConfigServerServiceMock.TEST_TAG_NEW_VALUE); Assert.assertEquals(ConfigServerServiceMock.TEST_TAG_NEW_VALUE, configServerService.getTagValue()); try { Thread.sleep(3000L); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } // appContext.stop(); }
From source file:org.atomserver.core.EntryURIHelperTest.java
protected void setUp() throws Exception { String[] configs = { "/org/atomserver/spring/propertyConfigurerBeans.xml", "/org/atomserver/spring/databaseBeans.xml", "/org/atomserver/spring/storageBeans.xml", "/org/atomserver/spring/logBeans.xml", "/org/atomserver/spring/abderaBeans.xml" }; ClassPathXmlApplicationContext springFactory = new ClassPathXmlApplicationContext(configs, false); springFactory.setClassLoader(new ConfigurationAwareClassLoader(springFactory.getClassLoader())); springFactory.refresh();/*from w w w.j ava2 s . c o m*/ handler = ((AbstractAtomService) springFactory.getBean("org.atomserver-atomService")).getURIHandler(); serviceContext = (ServiceContext) springFactory.getBean(CONTEXT_NAME); if (serviceContext.getAbdera() == null) { serviceContext.init(new Abdera(), null); } baseURI = handler.getServiceBaseUri(); }
From source file:org.bob.web.applications.smlite.engine.beans.CategoryBeanTest.java
@Test public void testCategoryBeanClass() throws SMLiteEngineException { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); AbstractManager<CategoryBean> cm = (AbstractManager<CategoryBean>) ctx.getBean("categoriesManager"); Set<CategoryBean> categories = new HashSet<>(); categories.add(new CategoryBean("VERDURA", "#5bb800", "Verdura")); categories.add(new CategoryBean("FRUTTA", "#5bb800", "Frutta")); categories.add(new CategoryBean("UOVA E LATTICINI", "#5bb800", "Uova, latte e derivati")); categories.add(new CategoryBean("CARNE", "#5bb800", "Carne e affini")); categories.add(new CategoryBean("PESCE", "#5bb800", "Pesce e affini")); categories.add(new CategoryBean("IGIENE CASA", "#5bb800", "Prodotti di igiene per la casa")); categories.add(new CategoryBean("IGIENE PERSONALE", "#5bb800", "Prodotti per l'igiene personale")); categories.add(new CategoryBean("SURGELATI", "#5bb800", "Surgelati")); categories.add(new CategoryBean("PANE E FARINA", "#5bb800", "Pane, farine, panificati vari")); categories.add(new CategoryBean("DOLCI", "#5bb800", "Dolci freschi e gelati, preparati per dolci")); categories.add(new CategoryBean("PRIMA COLAZIONE", "#5bb800", "Biscotti e cose per la prima colazione")); categories.add(new CategoryBean("BIBITE", "#5bb800", "Succhi, acqua, birre e bibite in generale")); categories.add(// w w w.j a v a2 s. c o m new CategoryBean("ALTRO", "#5bb800", "Articoli di altro genere (insaporitori, olio, aceto, ...)")); try { List<CategoryBean> existingCategories = cm.get(null); for (CategoryBean newCB : categories) { if (!existingCategories.contains(newCB)) { System.out.println( "@@@ TEST: INSERTING category: " + "\n" + " |-- " + newCB.toString() + ". . . "); cm.insert(newCB); } } } catch (SMLiteDAOException ex) { System.out.println("ERROR: " + ex.getMessage() + ". \nFollowing stacktrace: "); } }
From source file:org.bob.web.applications.smlite.engine.beans.CategoryBeanTest.java
@Test @Ignore("Not needed, works fine!") public void testDb() throws SMLiteEngineException { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); AbstractManager<CategoryBean> cm = (AbstractManager<CategoryBean>) ctx.getBean("categoriesManager"); CategoryBean cat = new CategoryBean(-1, "CATEGORIA " + new Date(), "0x000000"); try {/*from w ww .j a va 2 s. c o m*/ System.out.println("@@@ TEST: Adding fake category: " + cat.toString() + " ... "); cat = cm.insert(cat); System.out.println("@@@ TEST: Check inserted category: "); List<CategoryBean> _cat = cm.get(cat); if (_cat == null || _cat.size() != 1) throw new SMLiteEngineException("ERROR: category is null or duplicate!"); System.out.println("@@@ TEST: db says: " + _cat.get(0).toString()); cat.setColor("0xFF00FF"); System.out.println("@@@ TEST: Updating fake category: " + cat.toString() + " ..."); cat = cm.update(cat); System.out.println("@@@ TEST: Check updated category: "); _cat = cm.get(cat); if (_cat == null || _cat.size() != 1) throw new SMLiteEngineException("ERROR: category is null or duplicate!"); System.out.println("@@@ TEST: db says: " + _cat.get(0).toString()); System.out.println("@@@ TEST: deleting fake category . . ."); cm.delete(cat.getId()); } catch (SMLiteDAOException ex) { System.out.println("ERROR: " + ex.getMessage() + ". \nFollowing stacktrace: "); } }
From source file:gr.seab.r2rml.test.ComplianceTests.java
@Test public void testSparqlQuery() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("test-context.xml"); Util util = (Util) context.getBean("util"); Model model = ModelFactory.createDefaultModel(); String modelFilename = "dump1-epersons.rdf"; InputStream isMap = FileManager.get().open(modelFilename); try {/* w w w . j a va 2 s .com*/ model.read(isMap, null, "N3"); } catch (Exception e) { log.error("Error reading model."); System.exit(0); } String query = "SELECT ?x ?z WHERE {?x dc:source ?z} "; LocalResultSet rs = util.sparql(model, query); log.info("found " + String.valueOf(rs.getRows().size())); context.close(); }