Package org.springframework.tests.sample.beans

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


    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 SpecializedUncheckedException("foo", (SQLException)null));
      fail("Should have thrown CannotGetJdbcConnectionException");
    }
    catch (SpecializedUncheckedException ex) {
      // expected
    }
View Full Code Here

    NopInterceptor nop2 = new NopInterceptor();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(nop1);
    pf.addAdvice(ba);
    pf.addAdvice(nop2);
    ITestBean proxied = (ITestBean) createProxy(pf);
    // Won't throw an exception
    assertEquals(target.getAge(), proxied.getAge());
    assertEquals(1, ba.getCalls());
    assertEquals(1, ba.getCalls("getAge"));
    assertEquals(1, nop1.getCount());
    assertEquals(1, nop2.getCount());
    // Will fail, after invoking Nop1
    try {
      proxied.setAge(26);
      fail("before advice should have ended chain");
    }
    catch (RuntimeException ex) {
      assertEquals(rex, ex);
    }
    assertEquals(2, ba.getCalls());
    assertEquals(2, nop1.getCount());
    // Nop2 didn't get invoked when the exception was thrown
    assertEquals(1, nop2.getCount());
    // Shouldn't have changed value in joinpoint
    assertEquals(target.getAge(), proxied.getAge());
  }
View Full Code Here

    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvisor(matchesInt);
    assertEquals("Advisor was added", matchesInt, pf.getAdvisors()[1]);
    ITestBean proxied = (ITestBean) createProxy(pf);
    assertEquals(0, aa.sum);
    int i1 = 12;
    int i2 = 13;

    // Won't be advised
    proxied.setAge(i1);
    assertEquals(i1, proxied.getAge());
    assertEquals(i1, aa.sum);
    proxied.setAge(i2);
    assertEquals(i2, proxied.getAge());
    assertEquals(i1 + i2, aa.sum);
    assertEquals(i2, proxied.getAge());
  }
View Full Code Here

    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    pf.addAdvice(new NopInterceptor());
    pf.addAdvice(car);
    assertEquals("Advice was wrapped in Advisor and added", car, pf.getAdvisors()[1].getAdvice());
    ITestBean proxied = (ITestBean) createProxy(pf);
    assertEquals(0, car.getCalls());
    int age = 10;
    proxied.setAge(age);
    assertEquals(age, proxied.getAge());
    assertEquals(2, car.getCalls());
    Exception exc = new Exception();
    // On exception it won't be invoked
    try {
      proxied.exceptional(exc);
      fail();
    }
    catch (Throwable t) {
      assertSame(exc, t);
    }
View Full Code Here

  }

  @Test
  public void testAspectsAreApplied() {
    ClassPathXmlApplicationContext bf = newContext("aspects.xml");
    ITestBean tb = (ITestBean) bf.getBean("adrian");
    assertEquals(68, tb.getAge());
    MethodInvokingFactoryBean factoryBean = (MethodInvokingFactoryBean) bf.getBean("&factoryBean");
    assertTrue(AopUtils.isAopProxy(factoryBean.getTargetObject()));
    assertEquals(68, ((ITestBean) factoryBean.getTargetObject()).getAge());
  }
View Full Code Here

  }

  @Test
  public void testMultipleAspectsWithParameterApplied() {
    ClassPathXmlApplicationContext bf = newContext("aspects.xml");
    ITestBean tb = (ITestBean) bf.getBean("adrian");
    tb.setAge(10);
    assertEquals(20, tb.getAge());
  }
View Full Code Here

  }

  @Test
  public void testAspectsAreAppliedInDefinedOrder() {
    ClassPathXmlApplicationContext bf = newContext("aspectsWithOrdering.xml");
    ITestBean tb = (ITestBean) bf.getBean("adrian");
    assertEquals(71, tb.getAge());
  }
View Full Code Here

  }

  @Test
  public void testAspectsAndAdvisorAreApplied() {
    ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
    ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian");
    doTestAspectsAndAdvisorAreApplied(ac, shouldBeWeaved);
  }
View Full Code Here

    Assume.notLogging(factoryLog);
    ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
    StopWatch sw = new StopWatch();
    sw.start("Prototype Creation");
    for (int i = 0; i < 10000; i++) {
      ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian2");
      if (i < 10) {
        doTestAspectsAndAdvisorAreApplied(ac, shouldBeWeaved);
      }
    }
    sw.stop();
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.