Package org.springframework.beans

Examples of org.springframework.beans.ITestBean


    };
    pc.addAdvice(tii);
    pc.setTarget(expectedTarget);
    AopProxy aop = createAopProxy(pc);

    ITestBean tb = (ITestBean) aop.getProxy();
    tb.getName();
    // Not safe to trap invocation
    //assertTrue(tii.invocation == target.invocation);
 
    //assertTrue(target.invocation.getProxy() == tb);
View Full Code Here


        super(name);
    }

    public void testAdvisorAdapterRegistrationManagerNotPresentInContext() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withoutBPPContext.xml");
        ITestBean tb = (ITestBean) ctx.getBean("testBean");
    // just invoke any method to see if advice fired
        try {
      tb.getName();
      fail("Should throw UnknownAdviceTypeException");
    }
    catch (UnknownAdviceTypeException ex) {
            // expected
      assertEquals(0, getAdviceImpl(tb).getInvocationCounter());
View Full Code Here

    }
  }

  public void testAdvisorAdapterRegistrationManagerPresentInContext() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/adapter/withBPPContext.xml");
    ITestBean tb = (ITestBean) ctx.getBean("testBean");
    // just invoke any method to see if advice fired
    try {
      tb.getName();
      assertEquals(1, getAdviceImpl(tb).getInvocationCounter());
    }
    catch (UnknownAdviceTypeException ex) {
      fail("Should not throw UnknownAdviceTypeException");
    }
View Full Code Here

    ProxyFactory pc = new ProxyFactory(new Class[] {ITestBean.class});
    NopInterceptor di = new NopInterceptor();
    TestStaticPointcutAdvice sp = new TestStaticPointcutAdvice(di, "getAge");
    pc.addAdvisor(sp);
    pc.setTarget(tb);
    ITestBean it = (ITestBean) createProxy(pc);
    assertEquals(di.getCount(), 0);
    int age = it.getAge();
    assertEquals(di.getCount(), 1);
    it.setAge(11);
    assertEquals(it.getAge(), 11);
    assertEquals(di.getCount(), 2);
  }
View Full Code Here

      public boolean matches(Method m, Class targetClass) {
        return "haveBirthday".equals(m.getName());
      }
    };
    pc.addAdvisor(advisor);
    ITestBean it = (ITestBean) createProxy(pc);

    final int age = 20;
    it.setAge(age);
    assertEquals(age, it.getAge());
    // Should return the age before the third, AOP-induced birthday
    assertEquals(age + 2, it.haveBirthday());
    // Return the final age produced by 3 birthdays
    assertEquals(age + 3, it.getAge());
  }
View Full Code Here

    NameSaver saver = new NameSaver();

    pc.addAdvisor(new DefaultPointcutAdvisor(Pointcuts.SETTERS, nameReverter));
    pc.addAdvisor(new DefaultPointcutAdvisor(Pointcuts.SETTERS, saver));
    ITestBean it = (ITestBean) createProxy(pc);

    String name1 = "tony";
    String name2 = "gordon";

    tb.setName(name1);
    assertEquals(name1, tb.getName());

    it.setName(name2);
    // NameReverter saved it back
    assertEquals(name1, it.getName());
    assertEquals(2, saver.names.size());
    assertEquals(name2, saver.names.get(0));
    assertEquals(name1, saver.names.get(1));
  }
View Full Code Here

  public void testProxyIsBoundBeforeTargetSourceInvoked() {
    final TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new DebugInterceptor());
    pf.setExposeProxy(true);
    final ITestBean proxy = (ITestBean) createProxy(pf);
    Advised config = (Advised) proxy;
    // This class just checks proxy is bound before getTarget() call
    config.setTargetSource(new TargetSource() {
      public Class getTargetClass() {
        return TestBean.class;
      }

      public boolean isStatic() {
        return false;
      }

      public Object getTarget() throws Exception {
        assertEquals(proxy, AopContext.currentProxy());
        return target;
      }

      public void releaseTarget(Object target) throws Exception {       
      }     
    });
   
    // Just test anything: it will fail if context wasn't found
    assertEquals(0, proxy.getAge());
  }
View Full Code Here

    target.setAge(80);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvisor(matchesNoArgs);
    assertEquals("Advisor was added", matchesNoArgs, pf.getAdvisors()[1]);
    ITestBean proxied = (ITestBean) createProxy(pf);
    assertEquals(0, cba.getCalls());
    assertEquals(0, cba.getCalls("getAge"));
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(1, cba.getCalls());
    assertEquals(1, cba.getCalls("getAge"));
    assertEquals(0, cba.getCalls("setAge"));
    // Won't be advised
    proxied.setAge(26);
    assertEquals(1, cba.getCalls());
    assertEquals(26, proxied.getAge());
  }
View Full Code Here

    pc.addAdvice(mami6);

    // We don't care about the object
    pc.setTarget(new TestBean());
    AopProxy aop = createAopProxy(pc);
    ITestBean tb = (ITestBean) aop.getProxy();

    String newName = "foo";
    tb.setName(newName);
    assertEquals(newName, tb.getName());
  }
View Full Code Here

    target.setAge(80);
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvisor(matchesNoArgs);
    assertEquals("Advisor was added", matchesNoArgs, pf.getAdvisors()[1]);
    ITestBean proxied = (ITestBean) createProxy(pf);

    assertEquals(0, cca.getCalls());
    assertEquals(0, cca.getCalls("getAge"));
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(2, cca.getCalls());
    assertEquals(2, cca.getCalls("getAge"));
    assertEquals(0, cca.getCalls("setAge"));
    // Won't be advised
    proxied.setAge(26);
    assertEquals(2, cca.getCalls());
    assertEquals(26, proxied.getAge());
    assertEquals(4, cca.getCalls());
    try {
      proxied.exceptional(new CannotGetJdbcConnectionException("foo", (SQLException)null));
      fail("Should have thrown CannotGetJdbcConnectionException");
    }
    catch (CannotGetJdbcConnectionException ex) {
      // expected
    }
View Full Code Here

TOP

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