Search in sources :

Example 1 with DalAnnotationValidator

use of com.ctrip.platform.dal.dao.client.DalAnnotationValidator in project dal by ctripcorp.

the class DalAnnotationValidatorTest method testValidateFactoryBeanProxyAgain.

@Test
public void testValidateFactoryBeanProxyAgain() throws Exception {
    DalAnnotationValidator test = new DalAnnotationValidator();
    try {
        TransactionAnnoClass bean = DalTransactionManager.create(TransactionAnnoClass.class);
        // Try to wrap it again
        Class targetClass = bean.getClass();
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(targetClass);
        enhancer.setClassLoader(targetClass.getClassLoader());
        enhancer.setCallbackFilter(new CallbackFilter() {

            @Override
            public int accept(Method method) {
                return method.getName().startsWith("per") ? 0 : 1;
            }
        });
        Callback[] callbacks = new Callback[] { new MethodInterceptor() {

            @Override
            public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
                return proxy.invoke(obj, args);
            }
        }, NoOp.INSTANCE };
        enhancer.setCallbacks(callbacks);
        bean = (TransactionAnnoClass) enhancer.create();
        test.postProcessAfterInitialization(bean, "beanName");
    } catch (BeansException e) {
        fail();
    }
}
Also used : Enhancer(net.sf.cglib.proxy.Enhancer) Method(java.lang.reflect.Method) TransactionAnnoClass(test.com.ctrip.platform.dal.dao.annotation.autowire.TransactionAnnoClass) DalAnnotationValidator(com.ctrip.platform.dal.dao.client.DalAnnotationValidator) Callback(net.sf.cglib.proxy.Callback) MethodInterceptor(net.sf.cglib.proxy.MethodInterceptor) MethodProxy(net.sf.cglib.proxy.MethodProxy) TransactionAnnoClass(test.com.ctrip.platform.dal.dao.annotation.autowire.TransactionAnnoClass) CallbackFilter(net.sf.cglib.proxy.CallbackFilter) BeansException(org.springframework.beans.BeansException) Test(org.junit.Test)

Example 2 with DalAnnotationValidator

use of com.ctrip.platform.dal.dao.client.DalAnnotationValidator in project dal by ctripcorp.

the class DalAnnotationValidatorTest method testValidateRawBean.

@Test
public void testValidateRawBean() throws Exception {
    DalAnnotationValidator test = new DalAnnotationValidator();
    try {
        TransactionAnnoClass bean = new TransactionAnnoClass();
        test.postProcessAfterInitialization(bean, "beanName");
        fail();
    } catch (BeanInstantiationException e) {
        assertTrue(e.getMessage().contains(DalAnnotationValidator.VALIDATION_MSG));
    }
}
Also used : TransactionAnnoClass(test.com.ctrip.platform.dal.dao.annotation.autowire.TransactionAnnoClass) DalAnnotationValidator(com.ctrip.platform.dal.dao.client.DalAnnotationValidator) BeanInstantiationException(org.springframework.beans.BeanInstantiationException) Test(org.junit.Test)

Example 3 with DalAnnotationValidator

use of com.ctrip.platform.dal.dao.client.DalAnnotationValidator in project dal by ctripcorp.

the class DalAnnotationValidatorTest method testValidateFactoryBean.

@Test
public void testValidateFactoryBean() throws Exception {
    DalAnnotationValidator test = new DalAnnotationValidator();
    try {
        TransactionAnnoClass bean = DalTransactionManager.create(TransactionAnnoClass.class);
        test.postProcessAfterInitialization(bean, "beanName");
    } catch (BeansException e) {
        fail();
    }
}
Also used : TransactionAnnoClass(test.com.ctrip.platform.dal.dao.annotation.autowire.TransactionAnnoClass) DalAnnotationValidator(com.ctrip.platform.dal.dao.client.DalAnnotationValidator) BeansException(org.springframework.beans.BeansException) Test(org.junit.Test)

Example 4 with DalAnnotationValidator

use of com.ctrip.platform.dal.dao.client.DalAnnotationValidator in project dal by ctripcorp.

the class DalAnnotationValidatorTest method testPostProcessBeforeInitialization.

@Test
public void testPostProcessBeforeInitialization() throws Exception {
    DalAnnotationValidator test = new DalAnnotationValidator();
    assertNotNull(test.postProcessBeforeInitialization(new Object(), "beanName"));
}
Also used : DalAnnotationValidator(com.ctrip.platform.dal.dao.client.DalAnnotationValidator) Test(org.junit.Test)

Example 5 with DalAnnotationValidator

use of com.ctrip.platform.dal.dao.client.DalAnnotationValidator in project dal by ctripcorp.

the class DalAnnotationValidatorTest method testValidateRawBean.

@Test
public void testValidateRawBean() throws Exception {
    DalAnnotationValidator test = new DalAnnotationValidator();
    try {
        TransactionAnnoClass bean = new TransactionAnnoClass();
        test.postProcessAfterInitialization(bean, "beanName");
        fail();
    } catch (BeanInstantiationException e) {
        assertTrue(e.getMessage().contains(DalAnnotationValidator.VALIDATION_MSG));
    }
}
Also used : TransactionAnnoClass(com.ctrip.platform.dal.dao.annotation.autowire.TransactionAnnoClass) DalAnnotationValidator(com.ctrip.platform.dal.dao.client.DalAnnotationValidator) BeanInstantiationException(org.springframework.beans.BeanInstantiationException) Test(org.junit.Test)

Aggregations

DalAnnotationValidator (com.ctrip.platform.dal.dao.client.DalAnnotationValidator)8 Test (org.junit.Test)8 BeansException (org.springframework.beans.BeansException)4 TransactionAnnoClass (com.ctrip.platform.dal.dao.annotation.autowire.TransactionAnnoClass)3 TransactionAnnoClass (test.com.ctrip.platform.dal.dao.annotation.autowire.TransactionAnnoClass)3 Method (java.lang.reflect.Method)2 BeanInstantiationException (org.springframework.beans.BeanInstantiationException)2 Callback (net.sf.cglib.proxy.Callback)1 CallbackFilter (net.sf.cglib.proxy.CallbackFilter)1 Enhancer (net.sf.cglib.proxy.Enhancer)1 MethodInterceptor (net.sf.cglib.proxy.MethodInterceptor)1 MethodProxy (net.sf.cglib.proxy.MethodProxy)1