Package org.springframework.beans

Examples of org.springframework.beans.DerivedTestBean


    list.add("myBeanName");
    RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
    bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    bd.getConstructorArgumentValues().addGenericArgumentValue(list);
    lbf.registerBeanDefinition("test", bd);
    DerivedTestBean tb = (DerivedTestBean) lbf.getBean("test");
    assertEquals("myName", tb.getName());
    assertEquals("myBeanName", tb.getBeanName());
    DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
    assertTrue(tb != tb2);
    assertEquals("myName", tb2.getName());
    assertEquals("myBeanName", tb2.getBeanName());
  }
View Full Code Here


    RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
    bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
    bd.setFactoryMethodName("create");
    bd.getConstructorArgumentValues().addGenericArgumentValue(list);
    lbf.registerBeanDefinition("test", bd);
    DerivedTestBean tb = (DerivedTestBean) lbf.getBean("test");
    assertEquals("myName", tb.getName());
    assertEquals("myBeanName", tb.getBeanName());
    DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
    assertTrue(tb != tb2);
    assertEquals("myName", tb2.getName());
    assertEquals("myBeanName", tb2.getBeanName());
  }
View Full Code Here

  }

  public void testDisposableBean() {
    DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry();

    DerivedTestBean tb = new DerivedTestBean();
    beanRegistry.registerSingleton("tb", tb);
    beanRegistry.registerDisposableBean("tb", tb);
    assertSame(tb, beanRegistry.getSingleton("tb"));

    assertSame(tb, beanRegistry.getSingleton("tb"));
    assertEquals(1, beanRegistry.getSingletonCount());
    assertEquals(1, beanRegistry.getSingletonNames().length);
    assertTrue(Arrays.asList(beanRegistry.getSingletonNames()).contains("tb"));
    assertFalse(tb.wasDestroyed());

    beanRegistry.destroySingletons();
    assertEquals(0, beanRegistry.getSingletonCount());
    assertEquals(0, beanRegistry.getSingletonNames().length);
    assertTrue(tb.wasDestroyed());
  }
View Full Code Here

    assertEquals(6, inner1.getAge());

    assertNotNull(hasInnerBeans.getFriends());
    Object[] friends = hasInnerBeans.getFriends().toArray();
    assertEquals(3, friends.length);
    DerivedTestBean inner2 = (DerivedTestBean) friends[0];
    assertEquals("inner2", inner2.getName());
    assertTrue(inner2.getBeanName().startsWith(DerivedTestBean.class.getName()));
    assertFalse(xbf.containsBean("innerBean#1"));
    assertNotNull(inner2);
    assertEquals(7, inner2.getAge());
    TestBean innerFactory = (TestBean) friends[1];
    assertEquals(DummyFactory.SINGLETON_NAME, innerFactory.getName());
    TestBean inner5 = (TestBean) friends[2];
    assertEquals("innerBean#2", inner5.getBeanName());

    assertNotNull(hasInnerBeans.getSomeMap());
    assertEquals(2, hasInnerBeans.getSomeMap().size());
    TestBean inner3 = (TestBean) hasInnerBeans.getSomeMap().get("someKey");
    assertEquals("Jenny", inner3.getName());
    assertEquals(30, inner3.getAge());
    TestBean inner4 = (TestBean) hasInnerBeans.getSomeMap().get("someOtherKey");
    assertEquals("inner4", inner4.getName());
    assertEquals(9, inner4.getAge());

    TestBean hasInnerBeansForConstructor = (TestBean) xbf.getBean("hasInnerBeansForConstructor");
    TestBean innerForConstructor = (TestBean) hasInnerBeansForConstructor.getSpouse();
    assertNotNull(innerForConstructor);
    assertEquals("innerBean#3", innerForConstructor.getBeanName());
    assertEquals("inner1", innerForConstructor.getName());
    assertEquals(6, innerForConstructor.getAge());

    xbf.destroySingletons();
    assertTrue(inner1.wasDestroyed());
    assertTrue(inner2.wasDestroyed());
    assertTrue(innerFactory.getName() == null);
    assertTrue(inner5.wasDestroyed());
  }
View Full Code Here

    assertEquals(6, inner1.getAge());

    assertNotNull(hasInnerBeans.getFriends());
    Object[] friends = hasInnerBeans.getFriends().toArray();
    assertEquals(3, friends.length);
    DerivedTestBean inner2 = (DerivedTestBean) friends[0];
    assertEquals("inner2", inner2.getName());
    assertTrue(inner2.getBeanName().startsWith(DerivedTestBean.class.getName()));
    assertNotNull(inner2);
    assertEquals(7, inner2.getAge());
    TestBean innerFactory = (TestBean) friends[1];
    assertEquals(DummyFactory.SINGLETON_NAME, innerFactory.getName());
    TestBean inner5 = (TestBean) friends[2];
    assertEquals("innerBean", inner5.getBeanName());
  }
View Full Code Here

  public void testInheritanceWithDifferentClass() throws Exception {
    XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
    XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
    assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass"));
    DerivedTestBean inherits = (DerivedTestBean) child.getBean("inheritsWithDifferentClass");
    // Name property value is overridden
    assertTrue(inherits.getName().equals("override"));
    // Age property is inherited from bean in parent factory
    assertTrue(inherits.getAge() == 1);
    assertTrue(inherits.wasInitialized());
  }
View Full Code Here

  public void testInheritanceWithClass() throws Exception {
    XmlBeanFactory parent = new XmlBeanFactory(new ClassPathResource("parent.xml", getClass()));
    XmlBeanFactory child = new XmlBeanFactory(new ClassPathResource("child.xml", getClass()), parent);
    assertEquals(DerivedTestBean.class, child.getType("inheritsWithClass"));
    DerivedTestBean inherits = (DerivedTestBean) child.getBean("inheritsWithClass");
    // Name property value is overridden
    assertTrue(inherits.getName().equals("override"));
    // Age property is inherited from bean in parent factory
    assertTrue(inherits.getAge() == 1);
    assertTrue(inherits.wasInitialized());
  }
View Full Code Here

    assertEquals("java/lang/reflect/a/b/c/d.xml",
        ClassUtils.addResourcePathToPackagePath(Proxy.class, "a/b/c/d.xml"));
  }

  public void testGetAllInterfaces() {
    DerivedTestBean testBean = new DerivedTestBean();
    List ifcs = Arrays.asList(ClassUtils.getAllInterfaces(testBean));
    assertEquals("Correct number of interfaces", 7, ifcs.size());
    assertTrue("Contains Serializable", ifcs.contains(Serializable.class));
    assertTrue("Contains ITestBean", ifcs.contains(ITestBean.class));
    assertTrue("Contains IOther", ifcs.contains(IOther.class));
View Full Code Here

    }
  }

  public void testDestructionAtRequestCompletion() throws Exception {
    String name = "requestScopedDisposableObject";
    DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name);
    assertTrue(AopUtils.isCglibProxy(bean));

    MockHttpServletRequest request = new MockHttpServletRequest();
    ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(requestAttributes);

    try {
      assertNull(request.getAttribute("scopedTarget." + name));
      assertEquals("scoped", bean.getName());
      assertNotNull(request.getAttribute("scopedTarget." + name));
      assertEquals(DerivedTestBean.class, request.getAttribute("scopedTarget." + name).getClass());
      assertEquals("scoped", ((TestBean) request.getAttribute("scopedTarget." + name)).getName());
      assertSame(bean, this.beanFactory.getBean(name));
View Full Code Here

    RequestContextHolder.setRequestAttributes(requestAttributes);

    try {
      String name = "requestScopedDisposableObject";
      assertNull(request.getAttribute(name));
      DerivedTestBean bean = (DerivedTestBean) this.beanFactory.getBean(name);
      assertSame(bean, request.getAttribute(name));
      assertSame(bean, this.beanFactory.getBean(name));

      requestAttributes.requestCompleted();
      assertTrue(bean.wasDestroyed());
    }
    finally {
      RequestContextHolder.setRequestAttributes(null);
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.beans.DerivedTestBean

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.