Package org.springframework.tests.context

Examples of org.springframework.tests.context.SimpleMapScope


  @Test
  public void testScopedOverride() throws Exception {
    GenericApplicationContext ctx = new GenericApplicationContext();
    new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(OVERRIDE_CONTEXT);
    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


  @Test
  public void testJdkScopedProxy() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(TESTBEAN_CONTEXT);
    bf.setSerializationId("X");
    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());
    bean.setAge(101);

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

    ITestBean deserialized = (ITestBean) SerializationTestUtils.serializeAndDeserialize(bean);
    assertNotNull(deserialized);
    assertTrue(AopUtils.isJdkDynamicProxy(deserialized));
    assertEquals(101, bean.getAge());
View Full Code Here

  @Test
  public void testCglibScopedProxy() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(LIST_CONTEXT);
    bf.setSerializationId("Y");
    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());
    tb.getFriends().add("myFriend");

    assertTrue(scope.getMap().containsKey("scopedTarget.scopedList"));
    assertEquals(ArrayList.class, scope.getMap().get("scopedTarget.scopedList").getClass());

    ArrayList<?> deserialized = (ArrayList<?>) SerializationTestUtils.serializeAndDeserialize(tb.getFriends());
    assertNotNull(deserialized);
    assertTrue(AopUtils.isCglibProxy(deserialized));
    assertTrue(deserialized.contains("myFriend"));
View Full Code Here

  @Test
  public void withScopedProxy() throws IOException, ClassNotFoundException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxy.class);
    ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ctx.refresh();
    // should cast to the interface
    FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
View Full Code Here

  @Test
  public void withScopedProxyThroughRegex() throws IOException, ClassNotFoundException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxyThroughRegex.class);
    ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ctx.refresh();
    // should cast to the interface
    FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
View Full Code Here

  @Test
  public void withScopedProxyThroughAspectJPattern() throws IOException, ClassNotFoundException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(ComponentScanWithScopedProxyThroughAspectJPattern.class);
    ctx.getBeanFactory().registerScope("myScope", new SimpleMapScope());
    ctx.refresh();
    // should cast to the interface
    FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
    // should be dynamic proxy
    assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
View Full Code Here

  @Test
  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

  @Test
  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

  @Test
  public void testInterfacesScopedProxy() throws Exception {
    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));
    // test serializability
View Full Code Here

  @Test
  public void testTargetClassScopedProxy() throws Exception {
    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));
    // test serializability
    assertEquals("bar", bean.foo(1));
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.