List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:org.apache.cxf.transport.zmq.ZMQDestinationTest.java
@Test public void testConfigurationFromSpring() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] { "/spring/zmq-test-service-config.xml" }); EndpointImpl endpoint = (EndpointImpl) ctx.getBean("helloWorld"); ZMQ.Socket zmqSocket = zmqContext.socket(ZMQ.REQ); zmqSocket.connect("tcp://localhost:" + ZMQ_TEST_PORT); zmqSocket.send(FileUtils/* w ww . j a v a 2 s .c om*/ .readFileToString(new File(getClass().getResource("/samples/soap-request.xml").toURI())).getBytes(), 0); byte[] reply = zmqSocket.recv(0); zmqSocket.close(); endpoint.stop(); XMLAssert.assertXMLEqual( FileUtils.readFileToString(new File(getClass().getResource("/samples/soap-reply.xml").toURI())), new String(reply)); }
From source file:com.thoughtworks.go.helpers.Localhost.java
protected void prepareSampleData(int numberOfPipelines) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath*:WEB-INF/applicationContext-dataLocalAccess.xml"); DataSource dataSource = (DataSource) context.getBean("dataSource"); PipelineSqlMapDao pipelineDao = (PipelineSqlMapDao) context.getBean("pipelineDao"); StageSqlMapDao stageDao = (StageSqlMapDao) context.getBean("stageDao"); JobInstanceDao jobInstanceDao = (JobInstanceDao) context.getBean("buildInstanceDao"); final DatabaseAccessHelper dbHelper = new DatabaseAccessHelper(dataSource); dbHelper.onTearDown();/*from ww w. j a va 2s .c o m*/ dbHelper.onSetUp(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { try { dbHelper.onTearDown(); } catch (Exception e) { } } })); for (int i = 0; i < numberOfPipelines; i++) { for (String pipelineName : pipelineNames) { createCompletedData(pipelineDao, pipelineName); } } createLatestPipelines(dbHelper, jobInstanceDao); }
From source file:com.chevres.rss.restapi.controller.UserController.java
@CrossOrigin @RequestMapping(path = "/user/{username}", method = RequestMethod.PUT) @ResponseBody//from www . j a v a 2s . com public ResponseEntity<String> updateUser(@RequestHeader(value = "User-token") String userToken, @PathVariable String username, @RequestBody User userRequest, BindingResult bindingResult) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); UserDAO userDAO = context.getBean(UserDAO.class); UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class); userUpdateValidator.validate(userRequest, bindingResult); if (bindingResult.hasErrors()) { context.close(); return new ResponseEntity(new ErrorMessageResponse("bad_params"), HttpStatus.BAD_REQUEST); } UserAuth userAuth = userAuthDAO.findByToken(userToken); if (userAuth == null) { context.close(); return new ResponseEntity(new ErrorMessageResponse("invalid_token"), HttpStatus.BAD_REQUEST); } User user = userDAO.findByUsername(username); if (user == null) { context.close(); return new ResponseEntity(HttpStatus.NOT_FOUND); } boolean isAdmin = userDAO.isAdmin(userAuth.getIdUser()); if ((!isAdmin && (userAuth.getIdUser() != user.getId())) || (userRequest.getType() != null && !isAdmin)) { context.close(); return new ResponseEntity(new ErrorMessageResponse("admin_required"), HttpStatus.FORBIDDEN); } if (userDAO.doesExist(userRequest.getUsername()) && !user.getUsername().equalsIgnoreCase(userRequest.getUsername())) { context.close(); return new ResponseEntity(new ErrorMessageResponse("already_exist"), HttpStatus.BAD_REQUEST); } userDAO.updateUser(user, userRequest, isAdmin); context.close(); return new ResponseEntity(new SuccessMessageResponse("success"), HttpStatus.OK); }
From source file:org.brekka.stillingar.example.NestedServiceTest.java
@Test public void testGrabThirdPartyConfig() throws Exception { ClassPathXmlApplicationContext subContext = new ClassPathXmlApplicationContext( new String[] { "org/brekka/stillingar/example/NestedServiceTest-subcontext.xml" }, true, applicationContext);/*from w w w . j a va 2 s . c o m*/ ThirdPartyConfigBean bean = subContext.getBean(ThirdPartyConfigBean.class); assertEquals("localhost", bean.getHost()); writeConfig("localhost.local"); Thread.sleep(1000); assertEquals("localhost.local", bean.getHost()); }
From source file:com.griddynamics.banshun.RegistryBeanTest.java
protected void importValidBeanTest(String configLocation) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(configLocation); assertTrue("have no exports due to laziness", hasNoExports(ctx)); Object proxy = ctx.getBean("early-import"); try {// w w w .jav a2 s.c om proxy.toString(); fail("attempt to invoke proxy without export should lead to exception"); } catch (NoSuchBeanDefinitionException e) { assertEquals("invoke bean without proper export", "just-bean", e.getBeanName()); } // force export ctx.getBean("export-declaration"); assertSame(proxy, ctx.getBean("early-import")); assertFalse("have export ref", hasExport(ctx, "just-bean")); assertEquals("proxies should refer the same bean instance", proxy.toString(), ctx.getBean("late-import").toString()); assertSame("proxies should be the same instance", proxy, ctx.getBean("late-import")); assertTrue("early import gives us a proxy", proxy instanceof Proxy); assertTrue("late import gives us a proxy", ctx.getBean("late-import") instanceof Proxy); }
From source file:org.activiti.crystalball.simulator.SimulatorProcessMonitorTestWithoutProcess.java
@Test public void testProcessRun() throws Throwable { ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/SimEngine-h2-context.xml"); SimulationRun simRun = appContext.getBean(SimulationRun.class); RepositoryService repositoryService = (RepositoryService) appContext.getBean("simRepositoryService"); List<ResultEntity> resultEventList = simRun.execute(new Date(), null); Collection<List<ResultEntity>> unfinishedTaskProcesses = SimulationResultsPostProcessor .groupProcessDefinitionKey(// ww w . j ava 2 s . c o m SimulationResultsPostProcessor.getEventType("unfinished_task", resultEventList)); for (List<ResultEntity> eventList : unfinishedTaskProcesses) { String processDefinitionId = (String) eventList.get(0).getVariable("processDefinitionKey"); List<String> highlightTasks = SimulationResultsPostProcessor.getTaskDefinitionKeys(eventList); Map<String, String> nodeDescription = SimulationResultsPostProcessor.getNodeDescriptions(eventList); File dir = new File(tempDir + "/" + eventList.get(0).getType()); dir.mkdir(); String reportFileName = tempDir + "/" + eventList.get(0).getType() + "/" + processDefinitionId + ".png"; reportGraph(reportFileName, processDefinitionId, highlightTasks, nodeDescription, repositoryService); } appContext.close(); File expected = new File(System.getProperty("baseDir", ".") + "/src/test/resources/org/activiti/crystalball/simulator/SimulatorProcessMonitor-unfinishedTasks-expected.png"); File generated = new File( System.getProperty("tempDir", "target") + "/unfinished_task/threetasksprocess.png"); assertTrue(FileUtils.contentEquals(expected, generated)); }
From source file:com.myjeeva.andromda.demo.service.test.SearchServiceWSITCase.java
/** * Invokes the indexDocument service method on SearchService. * /*w ww . j a v a 2 s. co m*/ * Operation parameters: * documents com.myjeeva.andromda.demo.vo.DocumentVO * Operation return: * indexDocumentResponse java.lang.Boolean */ @Test public void indexDocument() { System.out.println("Starting test: indexDocument for " + this.getName()); // TestCase.setUp and tearDown methods for each individual service method test com.myjeeva.andromda.demo.service.IndexDocumentImpl.indexDocumentSetUp(); // Customize CreateInput method if different default input data is required. com.myjeeva.andromda.demo.service.IndexDocument indexDocumentInput = com.myjeeva.andromda.demo.service.IndexDocumentImpl .indexDocumentCreateInput(); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "cxf-client.xml" }); SearchServiceSEI client = (SearchServiceSEI) context.getBean("SearchServiceClient"); java.lang.Boolean indexDocumentResponse = null; try { indexDocumentResponse = client.indexDocument(indexDocumentInput.getDocuments() // java.util.List<com.myjeeva.andromda.demo.vo.DocumentVO> ); if (indexDocumentResponse == null) { System.out.println("indexDocumentResponse Result was valid and null"); } else { System.out.println(" Result = " + indexDocumentResponse.toString()); } } catch (Exception ex) { System.out.println("SearchService client.indexDocument" + " threw exception " + ex); throw new junit.framework.AssertionFailedError(ex.toString()); } com.myjeeva.andromda.demo.service.IndexDocumentImpl.indexDocumentTearDown(); System.out.println("Finished test for SearchService.indexDocument(documents)"); }
From source file:com.myjeeva.andromda.demo.service.test.SearchServiceWSITCase.java
/** * Invokes the performSearch service method on SearchService. * /*from ww w . j a v a 2s . c o m*/ * Operation parameters: * queryTerm java.lang.String * Operation return: * performSearchResponse com.myjeeva.andromda.demo.vo.SearchResultVO */ @Test public void performSearch() { System.out.println("Starting test: performSearch for " + this.getName()); // TestCase.setUp and tearDown methods for each individual service method test com.myjeeva.andromda.demo.service.PerformSearchImpl.performSearchSetUp(); // Customize CreateInput method if different default input data is required. com.myjeeva.andromda.demo.service.PerformSearch performSearchInput = com.myjeeva.andromda.demo.service.PerformSearchImpl .performSearchCreateInput(); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "cxf-client.xml" }); SearchServiceSEI client = (SearchServiceSEI) context.getBean("SearchServiceClient"); com.myjeeva.andromda.demo.vo.SearchResultVO performSearchResponse = null; try { performSearchResponse = client.performSearch(performSearchInput.getQueryTerm() // java.lang.String ); if (performSearchResponse == null) { System.out.println("performSearchResponse Result was valid and null"); } else { System.out.println(" Result = " + performSearchResponse.toString()); } } catch (Exception ex) { System.out.println("SearchService client.performSearch" + " threw exception " + ex); throw new junit.framework.AssertionFailedError(ex.toString()); } com.myjeeva.andromda.demo.service.PerformSearchImpl.performSearchTearDown(); System.out.println("Finished test for SearchService.performSearch(queryTerm)"); }
From source file:org.alfresco.util.exec.RuntimeExecBeansTest.java
public void testSplitArguments() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(APP_CONTEXT_XML); try {/*from w w w . jav a2 s .c o m*/ RuntimeExec splitExec = (RuntimeExec) ctx.getBean("commandSplitArguments"); assertNotNull(splitExec); String[] splitCommand = splitExec.getCommand(); assertTrue("Command arguments not split into 'dir', '.' and '..' :" + Arrays.deepToString(splitCommand), Arrays.deepEquals(new String[] { "dir", ".", ".." }, splitCommand)); } finally { ctx.close(); } }
From source file:org.alfresco.util.exec.RuntimeExecBeansTest.java
public void testSimpleSuccess() throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(APP_CONTEXT_XML); try {/*from w w w . j a va 2 s . c o m*/ RuntimeExec dirRootExec = (RuntimeExec) ctx.getBean("commandListRootDir"); assertNotNull(dirRootExec); // Execute it dirRootExec.execute(); } finally { ctx.close(); } }