Skip to content

Commit

Permalink
NMS-9470: Added tests (that are disabled until we can upgrade Hiberna…
Browse files Browse the repository at this point in the history
…te) that

expose a problem with join conditions in Hibernate.
  • Loading branch information
soleger committed Jun 27, 2017
1 parent b2e2e8c commit e08cae0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
Expand Up @@ -36,13 +36,18 @@
import java.util.List;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opennms.core.criteria.CriteriaBuilder;
import org.opennms.core.criteria.Alias.JoinType;
import org.opennms.core.criteria.restrictions.Restrictions;
import org.opennms.core.spring.BeanUtils;
import org.opennms.core.test.OpenNMSJUnit4ClassRunner;
import org.opennms.core.test.db.annotations.JUnitTemporaryDatabase;
import org.opennms.netmgt.dao.api.MonitoredServiceDao;
import org.opennms.netmgt.model.OnmsMonitoredService;
import org.opennms.netmgt.model.OnmsNode;
import org.opennms.test.JUnitConfigurationEnvironment;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -117,4 +122,22 @@ public void testGetByCompositeId() {

}

/**
* This test exposes a bug in Hibernate: it is not applying join conditions
* correctly to the many-to-many service-to-application relationship.
*
* This issue is documented in NMS-9470. If we upgrade Hibernate, we should
* recheck this issue to see if it is fixed.
*
* @see https://issues.opennms.org/browse/NMS-9470
*/
@Test
@Transactional
@Ignore("Ignore until Hibernate can be upgraded and this can be rechecked")
public void testCriteriaBuilderWithApplicationAlias() {
CriteriaBuilder cb = new CriteriaBuilder(OnmsMonitoredService.class);
cb.alias("applications", "application", JoinType.LEFT_JOIN, Restrictions.eq("application.name", "HelloWorld"));
m_monitoredServiceDao.findMatching(cb.toCriteria());
}

}
33 changes: 25 additions & 8 deletions opennms-dao/src/test/java/org/opennms/netmgt/dao/NodeDaoIT.java
Expand Up @@ -46,10 +46,13 @@
import org.apache.commons.beanutils.BeanUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opennms.core.criteria.Alias.JoinType;
import org.opennms.core.criteria.Criteria;
import org.opennms.core.criteria.CriteriaBuilder;
import org.opennms.core.criteria.restrictions.Restrictions;
import org.opennms.core.test.OpenNMSJUnit4ClassRunner;
import org.opennms.core.test.db.annotations.JUnitTemporaryDatabase;
import org.opennms.core.utils.InetAddressUtils;
Expand Down Expand Up @@ -293,8 +296,7 @@ public void testQuery() throws Exception {
@Transactional
public void testDeleteOnOrphanIpInterface() {

@SuppressWarnings("deprecation")
int preCount = getJdbcTemplate().queryForObject("select count(*) from ipinterface where ipinterface.nodeId = " + getNode1().getId(), Integer.class);
int preCount = getJdbcTemplate().queryForObject("select count(*) from ipinterface where ipinterface.nodeId = " + getNode1().getId(), Integer.class);

OnmsNode n = getNodeDao().get(getNode1().getId());
Iterator<OnmsIpInterface> it = n.getIpInterfaces().iterator();
Expand All @@ -303,8 +305,7 @@ public void testDeleteOnOrphanIpInterface() {
getNodeDao().saveOrUpdate(n);
getNodeDao().flush();

@SuppressWarnings("deprecation")
int postCount = getJdbcTemplate().queryForObject("select count(*) from ipinterface where ipinterface.nodeId = " + getNode1().getId(), Integer.class);
int postCount = getJdbcTemplate().queryForObject("select count(*) from ipinterface where ipinterface.nodeId = " + getNode1().getId(), Integer.class);

assertEquals(preCount-1, postCount);

Expand All @@ -314,15 +315,13 @@ public void testDeleteOnOrphanIpInterface() {
@Test
@Transactional
public void testDeleteNode() {
@SuppressWarnings("deprecation")
int preCount = getJdbcTemplate().queryForObject("select count(*) from node", Integer.class);
int preCount = getJdbcTemplate().queryForObject("select count(*) from node", Integer.class);

OnmsNode n = getNodeDao().get(getNode1().getId());
getNodeDao().delete(n);
getNodeDao().flush();

@SuppressWarnings("deprecation")
int postCount = getJdbcTemplate().queryForObject("select count(*) from node", Integer.class);
int postCount = getJdbcTemplate().queryForObject("select count(*) from node", Integer.class);

assertEquals(preCount-1, postCount);
}
Expand Down Expand Up @@ -631,6 +630,24 @@ public void testCB() {
assertEquals(2, nodes.size());
}

/**
* This test exposes a bug in Hibernate: it is not applying join conditions
* correctly to the many-to-many node-to-category relationship.
*
* This issue is documented in NMS-9470. If we upgrade Hibernate, we should
* recheck this issue to see if it is fixed.
*
* @see https://issues.opennms.org/browse/NMS-9470
*/
@Test
@Transactional
@Ignore("Ignore until Hibernate can be upgraded and this can be rechecked")
public void testCriteriaBuilderWithCategoryAlias() {
CriteriaBuilder cb = new CriteriaBuilder(OnmsNode.class);
cb.alias("categories", "category", JoinType.LEFT_JOIN, Restrictions.eq("category.name", "Routers"));
m_nodeDao.findMatching(cb.toCriteria());
}

@Test
@Transactional
public void testCriteriaBuilderOrderBy() {
Expand Down
Expand Up @@ -114,8 +114,7 @@ public void testInsert() {
assertEquals(1, countIfs(m_populator.getNode1().getId(), 1001, newIfName));
}

@SuppressWarnings("deprecation")
private int countIfs(int nodeId, int ifIndex, String ifName) {
private int countIfs(int nodeId, int ifIndex, String ifName) {
return m_jdbcTemplate.queryForObject("select count(*) from snmpInterface where nodeid=? and snmpifindex=? and snmpifname=?", new Object[] { nodeId, ifIndex, ifName }, Integer.class);
}

Expand Down

0 comments on commit e08cae0

Please sign in to comment.