Search in sources :

Example 76 with BeansException

use of org.springframework.beans.BeansException 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 77 with BeansException

use of org.springframework.beans.BeansException in project dal by ctripcorp.

the class DalTransactionalValidatorAutoWireTest method testValidateFail.

@Test
public void testValidateFail() throws InstantiationException, IllegalAccessException {
    ApplicationContext ctx;
    try {
        ctx = new ClassPathXmlApplicationContext("transactionTestFailByAutowire.xml");
        Assert.fail();
    } catch (BeansException e) {
        Assert.assertTrue(e.getMessage().contains(DalAnnotationValidator.VALIDATION_MSG));
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeansException(org.springframework.beans.BeansException) Test(org.junit.Test)

Example 78 with BeansException

use of org.springframework.beans.BeansException in project dal by ctripcorp.

the class DalTransactionalValidatorTest method testValidateFail.

@Test
public void testValidateFail() throws InstantiationException, IllegalAccessException {
    ApplicationContext ctx;
    try {
        ctx = new ClassPathXmlApplicationContext("transactionTestByBeanDefFail.xml");
        Assert.fail();
    } catch (BeansException e) {
        Assert.assertTrue(e.getMessage().contains(DalAnnotationValidator.VALIDATION_MSG));
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeansException(org.springframework.beans.BeansException) Test(org.junit.Test)

Example 79 with BeansException

use of org.springframework.beans.BeansException in project dal by ctripcorp.

the class DalTransactionalValidatorTest method testValidatePass.

@Test
public void testValidatePass() throws InstantiationException, IllegalAccessException {
    ApplicationContext ctx;
    try {
        ctx = new ClassPathXmlApplicationContext("transactionTestByBeanDef.xml");
        TransactionAnnoClass b = ctx.getBean(TransactionAnnoClass.class);
        b.perform();
        Assert.assertNotNull(b.getTest());
        b.performOld();
    } catch (BeansException e) {
        Assert.fail();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeansException(org.springframework.beans.BeansException) Test(org.junit.Test)

Example 80 with BeansException

use of org.springframework.beans.BeansException in project opennms by OpenNMS.

the class SnmpAssetProvisioningAdapter method doUpdateNode.

/**
 * <p>doUpdate</p>
 *
 * @param nodeId a int.
 * @param retry a boolean.
 * @throws org.opennms.netmgt.provision.ProvisioningAdapterException if any.
 */
@Override
public void doUpdateNode(final int nodeId) throws ProvisioningAdapterException {
    LOG.debug("doUpdate: updating nodeid: {}", nodeId);
    final OnmsNode node = m_nodeDao.get(nodeId);
    Assert.notNull(node, "doUpdate: failed to return node for given nodeId:" + nodeId);
    final InetAddress ipaddress = m_template.execute(new TransactionCallback<InetAddress>() {

        @Override
        public InetAddress doInTransaction(final TransactionStatus arg0) {
            return getIpForNode(node);
        }
    });
    final String locationName = node.getLocation() != null ? node.getLocation().getLocationName() : null;
    final SnmpAgentConfig agentConfig = m_snmpConfigDao.getAgentConfig(ipaddress, locationName);
    final OnmsAssetRecord asset = node.getAssetRecord();
    m_config.getReadLock().lock();
    try {
        for (AssetField field : m_config.getAssetFieldsForAddress(ipaddress, node.getSysObjectId())) {
            try {
                String value = fetchSnmpAssetString(m_locationAwareSnmpClient, agentConfig, locationName, field.getMibObjs(), field.getFormatString());
                LOG.debug("doUpdate: Setting asset field \" {} \" to value: {}", value, field.getName());
                // Use Spring bean-accessor classes to set the field value
                BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(asset);
                try {
                    wrapper.setPropertyValue(field.getName(), value);
                } catch (BeansException e) {
                    LOG.warn("doUpdate: Could not set property \" {} \" on asset object: {}", field.getName(), e.getMessage(), e);
                }
            } catch (Throwable t) {
                // This exception is thrown if the SNMP operation fails or an incorrect number of
                // parameters is returned by the agent or because of a misconfiguration.
                LOG.warn("doUpdate: Could not set value for asset field \" {} \": {}", field.getName(), t.getMessage(), t);
            }
        }
    } finally {
        m_config.getReadLock().unlock();
    }
    node.setAssetRecord(asset);
    m_nodeDao.saveOrUpdate(node);
    m_nodeDao.flush();
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) AssetField(org.opennms.netmgt.config.snmpAsset.adapter.AssetField) TransactionStatus(org.springframework.transaction.TransactionStatus) InetAddress(java.net.InetAddress) BeansException(org.springframework.beans.BeansException)

Aggregations

BeansException (org.springframework.beans.BeansException)126 Test (org.junit.Test)24 ApplicationContext (org.springframework.context.ApplicationContext)22 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)13 BeanCreationException (org.springframework.beans.factory.BeanCreationException)11 HashMap (java.util.HashMap)10 BeanWrapper (org.springframework.beans.BeanWrapper)10 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)10 MalformedURLException (java.net.MalformedURLException)9 File (java.io.File)8 IOException (java.io.IOException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)8 List (java.util.List)7 Method (java.lang.reflect.Method)6 LinkedHashSet (java.util.LinkedHashSet)6