Example usage for org.springframework.context.support ClassPathXmlApplicationContext getBean

List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context.support ClassPathXmlApplicationContext getBean.

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:org.fusesource.meshkeeper.MeshKeeperFactoryTest.java

public void testFactories() throws Exception {

    // Test out the spring factory..
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("factory-test.xml");
    MeshKeeper mk = (MeshKeeper) context.getBean("mk");
    assertNotNull(mk.registry().getRegistryData(ControlServer.REMOTING_URI_PATH));
    context.destroy();// ww  w  . ja v a  2  s  .  c o m

    // Test out the java factories.
    mk = MeshKeeperFactory.createMeshKeeper("zk:tcp://localhost:2101");
    assertNotNull(mk.registry().getRegistryData(ControlServer.REMOTING_URI_PATH));
    mk.destroy();

    // Test out starting a launcher agent
    mk = MeshKeeperFactory.createMeshKeeper("zk:tcp://localhost:2101");
    LaunchAgent agent = MeshKeeperFactory.createAgent(mk);
    assertNotNull(agent.getAgentId());
    agent.stop();
}

From source file:org.solmix.wmix.web.config.WmixConfigTest.java

@Test
public void test() {
    String location = "org/solmix/wmix/web/config/container.xml";
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(location);
    assertNotNull(ctx);//from   w  ww. ja v  a 2s .  c  o  m
    WmixConfiguration o = (WmixConfiguration) ctx.getBean("wmix-configuration");
    assertNotNull(o);
    assertTrue(o.isProductionMode());
    WmixConfiguration wcf = ctx.getBean(WmixConfiguration.class);
    assertNotNull(wcf);
    assertNotNull(wcf.getProcessor());
    assertNotNull(wcf.getFaultProcessor());

}

From source file:com.chevres.rss.worker.controller.WorkerController.java

@CrossOrigin
@RequestMapping(path = "/worker/refresh/feed/{feedId}", method = RequestMethod.GET)
@ResponseBody//from w  ww.  ja  v  a  2s . com
public ResponseEntity<String> refreshFeed(@RequestHeader(value = "User-token") String userToken,
        @PathVariable int feedId) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
    FeedDAO feedDAO = context.getBean(FeedDAO.class);
    ArticleDAO articleDAO = context.getBean(ArticleDAO.class);
    ArticleStateDAO articleStateDAO = context.getBean(ArticleStateDAO.class);
    UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class);

    UserAuth userAuth = userAuthDAO.findByToken(userToken);
    if (userAuth == null) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("invalid_token"), HttpStatus.BAD_REQUEST);
    }
    Feed feed = feedDAO.findById(userAuth, feedId);
    if (feed == null) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("bad_params"), HttpStatus.BAD_REQUEST);
    }
    FeedUpdater feedUpdater = new FeedUpdater(feedDAO, articleDAO, articleStateDAO);
    if (feedUpdater.updateFeed(feed)) {
        context.close();
        return new ResponseEntity(new SuccessMessageResponse("success"), HttpStatus.OK);
    } else {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("error"), HttpStatus.BAD_REQUEST);
    }
}

From source file:nats.client.spring.NatsFactoryBeanTest.java

@Test
public void natsFactory() throws Exception {
    final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("natsFactoryContext.xml");
    try {/*from www  .  j  a  v  a 2s.  c o m*/
        final Nats nats = context.getBean(Nats.class);
        Assert.assertNotNull(nats);
    } finally {
        context.close();
    }
}

From source file:org.jolokia.jvmagent.spring.JolokiaServerIntegrationTest.java

@Test
public void simple() throws Exception {
    System.setProperty("jolokia.port", "" + EnvTestUtil.getFreePort());
    System.out.println("Port selected: " + System.getProperty("jolokia.port"));
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/spring-jolokia-context.xml");
    SpringJolokiaAgent server = (SpringJolokiaAgent) ctx.getBean("jolokia");
    JolokiaServerConfig cfg = server.getServerConfig();
    assertEquals(cfg.getContextPath(), "/j4p/");

    MBeanServer mbeanServer = (MBeanServer) ctx.getBean("jolokiaMBeanServer");
    assertNotNull(mbeanServer);/*from   w w  w .  ja  v  a2s  .  co m*/
    checkServerAndStop(server);
}

From source file:org.jolokia.jvmagent.spring.JolokiaServerIntegrationTest.java

@Test
public void withPlainBean() throws Exception {
    System.setProperty("jolokia.port", "" + EnvTestUtil.getFreePort());
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/spring-jolokia-plain-beans.xml");
    SpringJolokiaAgent server = (SpringJolokiaAgent) ctx.getBean("jolokia");
    JolokiaServerConfig cfg = server.getServerConfig();
    assertEquals(cfg.getContextPath(), "/jolokia/");
    checkServerAndStop(server);// www .j a va2 s.c om
}

From source file:org.aksw.gerbil.web.config.DatabaseConfig.java

/**
 * @return the database bean/*w ww.j  a  v  a  2s.co  m*/
 */
@Bean
public ExperimentDAO experimentDAO() {
    LOGGER.debug("Setting up database.");
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "/spring/database/database-context.xml");
    ExperimentDAO database = context.getBean(ExperimentDAO.class);
    database.initialize();
    context.close();
    return database;
}

From source file:org.jolokia.support.spring.JolokiaServerIntegrationTest.java

@Test
public void simple() throws Exception {
    System.setProperty("jolokia.port", "" + EnvTestUtil.getFreePort());
    System.out.println("Port selected: " + System.getProperty("jolokia.port"));
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/spring-jolokia-context.xml");
    SpringJolokiaAgent server = (SpringJolokiaAgent) ctx.getBean("jolokia");
    JolokiaServerConfig cfg = server.getServerConfig();
    assertEquals(cfg.getContextPath(), "/j4p/");

    MBeanServer mbeanServer = (MBeanServer) ctx.getBean("jolokiaMBeanServer");
    assertNotNull(mbeanServer);//from   ww  w  . j  a va 2  s .  c  om
    //Thread.sleep(1000 * 3600);
    checkServerAndStop(server);
}

From source file:org.mule.ibeans.spring.IBeansContextFactoryBeanTestCase.java

public void testContext() throws Exception {
    ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
            new String[] { "test-applicationContext.xml" });

    IBeansContext ctx = (IBeansContext) appContext.getBean("ibeansContext");
    assertNotNull(ctx);/*  ww w  . j a va 2  s  .com*/

    //Test Spring injection
    DummyBean1 bean1 = (DummyBean1) appContext.getBean("test1");
    assertNotNull(bean1);
    assertNotNull(bean1.getIBeansContext());

    //Test Mule annotations in Spring
    DummyBean2 bean2 = (DummyBean2) appContext.getBean("test2");
    assertNotNull(bean2);
    assertNotNull(bean2.getIBeansContext());
    assertNotNull(bean2.getDummy());
}

From source file:nz.co.senanque.madura.configuration.ConfigSetupTest.java

@Test
public void testSpringConfig() throws Exception {

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            getConfigLocations());// w  w  w  . j  a  v a  2  s  . c  o m
    Object hs1 = applicationContext.getBean("component.sourcedir");
    assertTrue("mysourcedir".equals(hs1.toString()));
    Object hs2 = applicationContext.getBean("component1.sourcedir");
    System.out.println(hs2.toString());
    assertTrue("mysourcedir".equals(hs2.toString()));

    URL url = (URL) applicationContext.getBean("myurl");
    assertTrue("http://localhost:8080/jjj".equals(url.toString()));
    System.out.println(url.toString());

    Configuration configuration = (Configuration) applicationContext.getBean("configuration");
    Object doc = applicationContext.getBean("test1");
    MyTestBean myTestBean = (MyTestBean) applicationContext.getBean("test2");
    assertTrue(myTestBean.getA().equals("XYZ"));
    myTestBean.setA("12345");
    assertTrue(myTestBean.getA().equals("12345"));
    List sampleList = (List) applicationContext.getBean("sampleList");
    assertEquals(2, sampleList.size());
    applicationContext.refresh();

    //        ManagedReloadingStrategy reloadingStrategy = (ManagedReloadingStrategy)applicationContext.getBean("reloadingStrategy");
    //        reloadingStrategy.refresh();
    MyTestBean myTestBean1 = (MyTestBean) applicationContext.getBean("test2");
    assertTrue(myTestBean1.getA().equals("XYZ"));

}