Package org.springframework.tests.context

Examples of org.springframework.tests.context.SimpleMapScope


    DummyInvocationHandler ih = new DummyInvocationHandler();
    Object mockEm = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {EntityManager.class}, ih);
    given(mockEmf.createEntityManager()).willReturn((EntityManager) mockEm);

    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;
  }
View Full Code Here


  @Test
  public void testSingletonScopedFactoryMethod() {
    GenericApplicationContext context = new GenericApplicationContext();
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);

    context.getBeanFactory().registerScope("request", new SimpleMapScope());

    scanner.scan(BASE_PACKAGE);
    context.registerBeanDefinition("clientBean", new RootBeanDefinition(QualifiedClientBean.class));
    context.refresh();
View Full Code Here

TOP

Related Classes of org.springframework.tests.context.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.