Package org.springframework.context.support

Examples of org.springframework.context.support.StaticApplicationContext


        assertNull(helper.getStrategy(IMyBean.class));
    }

    @Test
    public void one() {
        StaticApplicationContext applicationContext = new StaticApplicationContext();
        applicationContext.registerSingleton("myBean", MyBean.class);

        MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
        assertNotNull(helper.getStrategy(IMyBean.class));
    }
View Full Code Here


        assertNotNull(helper.getStrategy(IMyBean.class));
    }

    @Test(expected = BeanInitializationException.class)
    public void many() {
        StaticApplicationContext applicationContext = new StaticApplicationContext();
        applicationContext.registerSingleton("myBean1", MyBean.class);
        applicationContext.registerSingleton("myBean2", MyBean.class);

        MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
        helper.getStrategy(IMyBean.class);
    }
View Full Code Here

        helper.getStrategy(IMyBean.class);
    }
   
    @Test
    public void noneWithDefault() {
        StaticApplicationContext applicationContext = new StaticApplicationContext();


        MockStrategiesHelper helper = new MockStrategiesHelper(applicationContext);
        assertNotNull(helper.getStrategy(IMyBean.class, MyBean.class));
    }
View Full Code Here

        jettyContext.addServlet(new ServletHolder(new EchoServlet()), "/");
        jettyServer.start();
        WebServiceConnection connection = null;
        try {

            StaticApplicationContext appContext = new StaticApplicationContext();
            appContext.registerSingleton("messageSender", HttpComponentsMessageSender.class);
            appContext.refresh();

            HttpComponentsMessageSender messageSender = appContext
                    .getBean("messageSender", HttpComponentsMessageSender.class);
            connection = messageSender.createConnection(new URI("http://localhost:" + port));

            connection.send(new SaajSoapMessage(messageFactory.createMessage()));
            connection.receive(new SaajSoapMessageFactory(messageFactory));

            appContext.close();
        }
        finally {
            if (connection != null) {
                try {
                    connection.close();
View Full Code Here

        jettyContext.addServlet(new ServletHolder(new EchoServlet()), "/");
        jettyServer.start();
        WebServiceConnection connection = null;
        try {

            StaticApplicationContext appContext = new StaticApplicationContext();
            appContext.registerSingleton("messageSender", CommonsHttpMessageSender.class);
            appContext.refresh();

            CommonsHttpMessageSender messageSender = appContext
                    .getBean("messageSender", CommonsHttpMessageSender.class);
            connection = messageSender.createConnection(new URI("http://localhost:" + port));

            appContext.close();

            connection.send(new SaajSoapMessage(messageFactory.createMessage()));
            connection.receive(new SaajSoapMessageFactory(messageFactory));
        }
        finally {
View Full Code Here

        Properties strategies = new Properties();
        strategies.put(Strategy.class.getName(),
                StrategyImpl.class.getName() + "," + ContextAwareStrategyImpl.class.getName());
        DefaultStrategiesHelper helper = new DefaultStrategiesHelper(strategies);

        StaticApplicationContext applicationContext = new StaticApplicationContext();
        applicationContext.registerSingleton("strategy1", StrategyImpl.class);
        applicationContext.registerSingleton("strategy2", ContextAwareStrategyImpl.class);

        List<Strategy> result = helper.getDefaultStrategies(Strategy.class, applicationContext);
        Assert.assertNotNull("No result", result);
        Assert.assertEquals("Invalid amount of strategies", 2, result.size());
        Assert.assertTrue("Result not a Strategy implementation", result.get(0) != null);
View Full Code Here

    public void testGetDefaultStrategy() throws Exception {
        Properties strategies = new Properties();
        strategies.put(Strategy.class.getName(), StrategyImpl.class.getName());
        DefaultStrategiesHelper helper = new DefaultStrategiesHelper(strategies);

        StaticApplicationContext applicationContext = new StaticApplicationContext();
        applicationContext.registerSingleton("strategy1", StrategyImpl.class);
        applicationContext.registerSingleton("strategy2", ContextAwareStrategyImpl.class);

        Object result = helper.getDefaultStrategy(Strategy.class, applicationContext);
        Assert.assertNotNull("No result", result);
        Assert.assertTrue("Result not a Strategy implementation", result instanceof Strategy);
        Assert.assertTrue("Result not a StrategyImpl implementation", result instanceof StrategyImpl);
View Full Code Here

        Properties strategies = new Properties();
        strategies.put(Strategy.class.getName(),
                StrategyImpl.class.getName() + "," + ContextAwareStrategyImpl.class.getName());
        DefaultStrategiesHelper helper = new DefaultStrategiesHelper(strategies);

        StaticApplicationContext applicationContext = new StaticApplicationContext();
        applicationContext.registerSingleton("strategy1", StrategyImpl.class);
        applicationContext.registerSingleton("strategy2", ContextAwareStrategyImpl.class);

        try {
            helper.getDefaultStrategy(Strategy.class, applicationContext);
            Assert.fail("Expected BeanInitializationException");
        }
View Full Code Here

*/
public class SpringBeanFactoryTest {

  @Test
  public void newInstance() throws Exception {
    StaticApplicationContext oContext = new StaticApplicationContext();
    String oClassName = MyAction.class.getName();
    oContext.registerSingleton(oClassName, MyAction.class);
   
    SpringBeanFactory oFactory = new SpringBeanFactory();
    oFactory.setApplicationContext(oContext);
    Object oActual = oFactory.newInstance(MyAction.class, oClassName);
    assertNotNull(oActual);
View Full Code Here

* @since 02.10.2003
*/
public class PropertyResourceConfigurerTests extends TestCase {

  public void testPropertyOverrideConfigurer() {
    StaticApplicationContext ac = new StaticApplicationContext();
    ac.registerSingleton("tb1", TestBean.class);
    ac.registerSingleton("tb2", TestBean.class);
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "tb1.age=99\ntb2.name=test");
    ac.registerSingleton("configurer1", PropertyOverrideConfigurer.class, pvs);
    pvs = new MutablePropertyValues();
    pvs.addPropertyValue("properties", "tb2.age=99\ntb2.name=test2");
    pvs.addPropertyValue("order", "0");
    ac.registerSingleton("configurer2", PropertyOverrideConfigurer.class, pvs);
    ac.refresh();
    TestBean tb1 = (TestBean) ac.getBean("tb1");
    TestBean tb2 = (TestBean) ac.getBean("tb2");
    assertEquals(99, tb1.getAge());
    assertEquals(99, tb2.getAge());
    assertEquals(null, tb1.getName());
    assertEquals("test", tb2.getName());
  }
View Full Code Here

TOP

Related Classes of org.springframework.context.support.StaticApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.