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();
}
}
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));
}
}
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));
}
}
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();
}
}
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();
}
Aggregations