Package org.springframework.tests.sample.beans

Examples of org.springframework.tests.sample.beans.ITestBean


    // Register the advisor auto proxy creator with subclass
    childAc.registerBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class.getName(), new RootBeanDefinition(
        AnnotationAwareAspectJAutoProxyCreator.class));
    childAc.refresh();

    ITestBean beanFromChildContextThatShouldBeWeaved = (ITestBean) childAc.getBean("adrian2");
    //testAspectsAndAdvisorAreApplied(childAc, (ITestBean) ac.getBean("adrian"));
    doTestAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved);
  }
View Full Code Here


  @Test
  public void testPerThisAspect() {
    ClassPathXmlApplicationContext bf = newContext("perthis.xml");

    ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
    assertTrue(AopUtils.isAopProxy(adrian1));

    assertEquals(0, adrian1.getAge());
    assertEquals(1, adrian1.getAge());

    ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
    assertNotSame(adrian1, adrian2);
    assertTrue(AopUtils.isAopProxy(adrian1));
    assertEquals(0, adrian2.getAge());
    assertEquals(1, adrian2.getAge());
    assertEquals(2, adrian2.getAge());
    assertEquals(3, adrian2.getAge());
    assertEquals(2, adrian1.getAge());
  }
View Full Code Here

  @Test
  public void testPerTargetAspect() throws SecurityException, NoSuchMethodException {
    ClassPathXmlApplicationContext bf = newContext("pertarget.xml");

    ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
    assertTrue(AopUtils.isAopProxy(adrian1));

    // Does not trigger advice or count
    int explicitlySetAge = 25;
    adrian1.setAge(explicitlySetAge);

    assertEquals("Setter does not initiate advice", explicitlySetAge, adrian1.getAge());
    // Fire aspect

    AspectMetadata am = new AspectMetadata(PerTargetAspect.class, "someBean");
    assertTrue(am.getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));

    adrian1.getSpouse();

    assertEquals("Advice has now been instantiated", 0, adrian1.getAge());
    adrian1.setAge(11);
    assertEquals("Any int setter increments", 2, adrian1.getAge());
    adrian1.setName("Adrian");
    //assertEquals("Any other setter does not increment", 2, adrian1.getAge());

    ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
    assertNotSame(adrian1, adrian2);
    assertTrue(AopUtils.isAopProxy(adrian1));
    assertEquals(34, adrian2.getAge());
    adrian2.getSpouse();
    assertEquals("Aspect now fired", 0, adrian2.getAge());
    assertEquals(1, adrian2.getAge());
    assertEquals(2, adrian2.getAge());
    assertEquals(3, adrian1.getAge());
  }
View Full Code Here

    sac.registerSingleton("autowiredIndexedTestBean", IndexedTestBean.class);

    sac.refresh();

    MessageSource messageSource = (MessageSource) sac.getBean("messageSource");
    ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
    assertFalse(Proxy.isProxyClass(messageSource.getClass()));
    assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass()));
    assertTrue(Proxy.isProxyClass(singletonToBeProxied.getSpouse().getClass()));

    // test whether autowiring succeeded with auto proxy creation
    assertEquals(sac.getBean("autowiredIndexedTestBean"), singletonToBeProxied.getNestedIndexedBean());

    TestInterceptor ti = (TestInterceptor) sac.getBean("testInterceptor");
    // already 2: getSpouse + getNestedIndexedBean calls above
    assertEquals(2, ti.nrOfInvocations);
    singletonToBeProxied.getName();
    singletonToBeProxied.getSpouse().getName();
    assertEquals(5, ti.nrOfInvocations);

    ITestBean tb = (ITestBean) sac.getBean("singletonFactoryToBeProxied");
    assertTrue(AopUtils.isJdkDynamicProxy(tb));
    assertEquals(5, ti.nrOfInvocations);
    tb.getAge();
    assertEquals(6, ti.nrOfInvocations);

    ITestBean tb2 = (ITestBean) sac.getBean("singletonFactoryToBeProxied");
    assertSame(tb, tb2);
    assertEquals(6, ti.nrOfInvocations);
    tb2.getAge();
    assertEquals(7, ti.nrOfInvocations);
  }
View Full Code Here

    sac.registerSingleton("singletonFactoryToBeProxied", DummyFactory.class);

    sac.refresh();

    ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
    assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass()));

    TestInterceptor ti = (TestInterceptor) sac.getBean("testInterceptor");
    int initialNr = ti.nrOfInvocations;
    singletonToBeProxied.getName();
    assertEquals(initialNr + 1, ti.nrOfInvocations);

    FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
    assertTrue(Proxy.isProxyClass(factory.getClass()));
    TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
View Full Code Here

    MessageSource messageSource = (MessageSource) sac.getBean("messageSource");
    NoInterfaces noInterfaces = (NoInterfaces) sac.getBean("noInterfaces");
    ContainerCallbackInterfacesOnly containerCallbackInterfacesOnly =
        (ContainerCallbackInterfacesOnly) sac.getBean("containerCallbackInterfacesOnly");
    ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor");
    ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
    ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied");
    assertFalse(AopUtils.isCglibProxy(messageSource));
    assertTrue(AopUtils.isCglibProxy(noInterfaces));
    assertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly));
    assertTrue(AopUtils.isCglibProxy(singletonNoInterceptor));
    assertTrue(AopUtils.isCglibProxy(singletonToBeProxied));
    assertTrue(AopUtils.isCglibProxy(prototypeToBeProxied));

    TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
    assertEquals(0, tapc.testInterceptor.nrOfInvocations);
    singletonNoInterceptor.getName();
    assertEquals(0, tapc.testInterceptor.nrOfInvocations);
    singletonToBeProxied.getAge();
    assertEquals(1, tapc.testInterceptor.nrOfInvocations);
    prototypeToBeProxied.getSpouse();
    assertEquals(2, tapc.testInterceptor.nrOfInvocations);
  }
View Full Code Here

  private void doTestTwoAdviceAspectWith(String location) {
    ClassPathXmlApplicationContext bf = newContext(location);

    boolean aspectSingleton = bf.isSingleton("aspect");
    ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
    testPrototype(adrian1, 0);
    ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
    assertNotSame(adrian1, adrian2);
    testPrototype(adrian2, aspectSingleton ? 2 : 0);
  }
View Full Code Here

  @Test
  public void testAdviceUsingJoinPoint() {
    ClassPathXmlApplicationContext bf = newContext("usesJoinPointAspect.xml");

    ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
    adrian1.getAge();
    AdviceUsingThisJoinPoint aspectInstance = (AdviceUsingThisJoinPoint) bf.getBean("aspect");
    //(AdviceUsingThisJoinPoint) Aspects.aspectOf(AdviceUsingThisJoinPoint.class);
    //assertEquals("method-execution(int TestBean.getAge())",aspectInstance.getLastMethodEntered());
    assertTrue(aspectInstance.getLastMethodEntered().indexOf("TestBean.getAge())") != 0);
  }
View Full Code Here

    MessageSource messageSource = (MessageSource) sac.getBean("messageSource");
    NoInterfaces noInterfaces = (NoInterfaces) sac.getBean("noInterfaces");
    ContainerCallbackInterfacesOnly containerCallbackInterfacesOnly =
        (ContainerCallbackInterfacesOnly) sac.getBean("containerCallbackInterfacesOnly");
    ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor");
    ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
    ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied");
    assertFalse(AopUtils.isCglibProxy(messageSource));
    assertTrue(AopUtils.isCglibProxy(noInterfaces));
    assertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly));
    assertFalse(AopUtils.isCglibProxy(singletonNoInterceptor));
    assertFalse(AopUtils.isCglibProxy(singletonToBeProxied));
    assertFalse(AopUtils.isCglibProxy(prototypeToBeProxied));

    TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
    assertEquals(0, tapc.testInterceptor.nrOfInvocations);
    singletonNoInterceptor.getName();
    assertEquals(0, tapc.testInterceptor.nrOfInvocations);
    singletonToBeProxied.getAge();
    assertEquals(1, tapc.testInterceptor.nrOfInvocations);
    prototypeToBeProxied.getSpouse();
    assertEquals(2, tapc.testInterceptor.nrOfInvocations);
  }
View Full Code Here

  @Test
  public void testIncludeMechanism() {
    ClassPathXmlApplicationContext bf = newContext("usesInclude.xml");

    ITestBean adrian = (ITestBean) bf.getBean("adrian");
    assertTrue(AopUtils.isAopProxy(adrian));
    assertEquals(68, adrian.getAge());
  }
View Full Code Here

TOP

Related Classes of org.springframework.tests.sample.beans.ITestBean

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.