Package org.springframework.beans.factory.config

Examples of org.springframework.beans.factory.config.SimpleMapScope


    mockEmf.createEntityManager();
    emfMc.setReturnValue(mockEm, 1);
    emfMc.replay();

    GenericApplicationContext gac = new GenericApplicationContext();
    SimpleMapScope myScope = new SimpleMapScope();
    gac.getDefaultListableBeanFactory().registerScope("myScope", myScope);
    gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
    gac.registerBeanDefinition("annotationProcessor",
        new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
    RootBeanDefinition bd = new RootBeanDefinition(DefaultPublicPersistenceContextSetter.class);
    bd.setScope("myScope");
    gac.registerBeanDefinition(DefaultPublicPersistenceContextSetter.class.getName(), bd);
    gac.refresh();

    DefaultPublicPersistenceContextSetter bean = (DefaultPublicPersistenceContextSetter) gac.getBean(
        DefaultPublicPersistenceContextSetter.class.getName());
    assertNotNull(bean.em);
    assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean.em));

    SimpleMapScope serialized = (SimpleMapScope) SerializationTestUtils.serializeAndDeserialize(myScope);
    serialized.close();
    assertTrue(DummyInvocationHandler.closed);
    DummyInvocationHandler.closed = false;
    emfMc.verify();
  }
View Full Code Here


  }

  public void testScopedOverride() throws Exception {
    GenericApplicationContext ctx = new GenericApplicationContext();
    new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(new ClassPathResource("scopedOverride.xml", getClass()));
    SimpleMapScope scope = new SimpleMapScope();
    ctx.getBeanFactory().registerScope("request", scope);
    ctx.refresh();

    ITestBean bean = (ITestBean) ctx.getBean("testBean");
    assertEquals("male", bean.getName());
    assertEquals(99, bean.getAge());

    assertTrue(scope.getMap().containsKey("scopedTarget.testBean"));
    assertEquals(TestBean.class, scope.getMap().get("scopedTarget.testBean").getClass());
  }
View Full Code Here

    assertEquals(TestBean.class, scope.getMap().get("scopedTarget.testBean").getClass());
  }

  public void testJdkScopedProxy() throws Exception {
    XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("scopedTestBean.xml", getClass()));
    SimpleMapScope scope = new SimpleMapScope();
    bf.registerScope("request", scope);

    ITestBean bean = (ITestBean) bf.getBean("testBean");
    assertNotNull(bean);
    assertTrue(AopUtils.isJdkDynamicProxy(bean));
    assertTrue(bean instanceof ScopedObject);
    ScopedObject scoped = (ScopedObject) bean;
    assertEquals(TestBean.class, scoped.getTargetObject().getClass());

    assertTrue(scope.getMap().containsKey("testBeanTarget"));
    assertEquals(TestBean.class, scope.getMap().get("testBeanTarget").getClass());
  }
View Full Code Here

    assertEquals(TestBean.class, scope.getMap().get("testBeanTarget").getClass());
  }

  public void testCglibScopedProxy() {
    XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("scopedList.xml", getClass()));
    SimpleMapScope scope = new SimpleMapScope();
    bf.registerScope("request", scope);

    TestBean tb = (TestBean) bf.getBean("testBean");
    assertTrue(AopUtils.isCglibProxy(tb.getFriends()));
    assertTrue(tb.getFriends() instanceof ScopedObject);
    ScopedObject scoped = (ScopedObject) tb.getFriends();
    assertEquals(ArrayList.class, scoped.getTargetObject().getClass());

    assertTrue(scope.getMap().containsKey("scopedTarget.scopedList"));
    assertEquals(ArrayList.class, scope.getMap().get("scopedTarget.scopedList").getClass());
  }
View Full Code Here

public class ComponentScanParserScopedProxyTests extends TestCase {

  public void testDefaultScopedProxy() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
        "org/springframework/context/annotation/scopedProxyDefaultTests.xml");
    context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
    // should not be a proxy
    assertFalse(AopUtils.isAopProxy(bean));
  }
View Full Code Here

  }

  public void testNoScopedProxy() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
        "org/springframework/context/annotation/scopedProxyNoTests.xml");
    context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
    // should not be a proxy
    assertFalse(AopUtils.isAopProxy(bean));
  }
View Full Code Here

  }

  public void testInterfacesScopedProxy() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
        "org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
    context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    // should cast to the interface
    FooService bean = (FooService) context.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertTrue(AopUtils.isJdkDynamicProxy(bean));
  }
View Full Code Here

  }

  public void testTargetClassScopedProxy() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
        "org/springframework/context/annotation/scopedProxyTargetClassTests.xml");
    context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
    // should be a class-based proxy
    assertTrue(AopUtils.isCglibProxy(bean));
  }
View Full Code Here

    mockEmf.createEntityManager();
    emfMc.setReturnValue(mockEm, 1);
    emfMc.replay();

    GenericApplicationContext gac = new GenericApplicationContext();
    SimpleMapScope myScope = new SimpleMapScope();
    gac.getDefaultListableBeanFactory().registerScope("myScope", myScope);
    gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
    gac.registerBeanDefinition("annotationProcessor",
        new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
    RootBeanDefinition bd = new RootBeanDefinition(DefaultPublicPersistenceContextSetter.class);
    bd.setScope("myScope");
    gac.registerBeanDefinition(DefaultPublicPersistenceContextSetter.class.getName(), bd);
    gac.refresh();

    DefaultPublicPersistenceContextSetter bean = (DefaultPublicPersistenceContextSetter) gac.getBean(
        DefaultPublicPersistenceContextSetter.class.getName());
    assertNotNull(bean.em);
    assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean.em));

    SimpleMapScope serialized = (SimpleMapScope) SerializationTestUtils.serializeAndDeserialize(myScope);
    serialized.close();
    assertTrue(DummyInvocationHandler.closed);
    DummyInvocationHandler.closed = false;
    emfMc.verify();
  }
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.config.SimpleMapScope

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.