Package org.springframework.aop

Examples of org.springframework.aop.Pointcut


      public boolean matches(Method method, Class<?> clazzy) {
        return false;
      }
    }

    Pointcut no = new TestPointcut();
    assertFalse(AopUtils.canApply(no, Object.class));
  }
View Full Code Here


      public boolean matches(Method method, Class<?> clazz) {
        return method.getName().equals("hashCode");
      }
    }

    Pointcut pc = new TestPointcut();

    // will return true if we're not proxying interfaces
    assertTrue(AopUtils.canApply(pc, Object.class));
  }
View Full Code Here

  public void testSelectiveApplication() {
    TestBean target = new TestBean();
    target.setAge(27);
    NopInterceptor nop = new NopInterceptor();
    ControlFlowPointcut cflow = new ControlFlowPointcut(One.class);
    Pointcut settersUnderOne = Pointcuts.intersection(Pointcuts.SETTERS, cflow);
    ProxyFactory pf = new ProxyFactory(target);
    ITestBean proxied = (ITestBean) pf.getProxy();
    pf.addAdvisor(new DefaultPointcutAdvisor(settersUnderOne, nop));

    // Not advised, not under One
View Full Code Here

  /**
   * Should match all setters and getters on any class
   */
  @Test
  public void testUnionOfSettersAndGetters() {
    Pointcut union = Pointcuts.union(allClassGetterPointcut, allClassSetterPointcut);
    assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
    assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
    assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
  }
View Full Code Here

    assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
  }

  @Test
  public void testUnionOfSpecificGetters() {
    Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut);
    assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
    assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
    assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class, null));
    assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null));
    assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
View Full Code Here

  public void testUnionOfAllSettersAndSubclassSetters() {
    assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
    assertTrue(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Object[] { new Integer(6)}));
    assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null));

    Pointcut union = Pointcuts.union(myTestBeanSetterPointcut, allClassGetterPointcut);
    assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
    assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class, null));
    // Still doesn't match superclass setter
    assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Object[] { new Integer(6)}));
    assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
View Full Code Here

    assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class, null));
    assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class, null));
    assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, MyTestBean.class, null));
    assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class, null));

    Pointcut intersection = Pointcuts.intersection(allClassGetAgePointcut, myTestBeanGetterPointcut);
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class, null));
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class, null));
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class, null));
    assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class, null));
    // Matches subclass of MyTestBean
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null));
    assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null));

    // Now intersection with MyTestBeanSubclass getters should eliminate MyTestBean target
    intersection = Pointcuts.intersection(intersection, myTestBeanSubclassGetterPointcut);
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class, null));
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class, null));
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class, null));
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class, null));
    // Still matches subclass of MyTestBean
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class, null));
    assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class, null));

    // Now union with all TestBean methods
    Pointcut union = Pointcuts.union(intersection, allTestBeanMethodsPointcut);
    assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class, null));
    assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class, null));
    assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBean.class, null));
    assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class, null));
    // Still matches subclass of MyTestBean
View Full Code Here

  /**
   * The intersection of these two pointcuts leaves nothing.
   */
  @Test
  public void testSimpleIntersection() {
    Pointcut intersection = Pointcuts.intersection(allClassGetterPointcut, allClassSetterPointcut);
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, new Object[] { new Integer(6)}));
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class, null));
    assertFalse(Pointcuts.matches(intersection, TEST_BEAN_ABSQUATULATE, TestBean.class, null));
  }
View Full Code Here

    }
  };

  @Test
  public void testMatchAll() throws NoSuchMethodException {
    Pointcut pc = new ComposablePointcut();
    assertTrue(pc.getClassFilter().matches(Object.class));
    assertTrue(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode", (Class[]) null), Exception.class));
  }
View Full Code Here

   * @return the applicable Pointcut object, or <code>null</code> if none
   */
  protected Pointcut buildPointcut(Set<Class<? extends Annotation>> asyncAnnotationTypes) {
    ComposablePointcut result = null;
    for (Class<? extends Annotation> asyncAnnotationType : asyncAnnotationTypes) {
      Pointcut cpc = new AnnotationMatchingPointcut(asyncAnnotationType, true);
      Pointcut mpc = new AnnotationMatchingPointcut(null, asyncAnnotationType);
      if (result == null) {
        result = new ComposablePointcut(cpc).union(mpc);
      }
      else {
        result.union(cpc).union(mpc);
View Full Code Here

TOP

Related Classes of org.springframework.aop.Pointcut

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.