@Test
public void testFindSelectedByType() throws Exception {

  HostConfigMapping entity1 = createEntity(1L, "h1", "global", "version1");
  HostEntity hostEntity = hostDAO.findByName("h1");
  
  HostConfigMapping target = hostConfigMappingDAO.findSelectedByType(1L, hostEntity.getHostId(), "core-site");
  Assert.assertNull("Expected null entity for type 'core-site'", target);
  
  target = hostConfigMappingDAO.findSelectedByType(1L, hostEntity.getHostId(), "global");
  Assert.assertNotNull("Expected non-null entity for type 'global'", target);
  Assert.assertEquals("Expected version to be '" + entity1.getVersion() + "'", entity1.getVersion(), target.getVersion());
  
  target.setSelected(0);
  hostConfigMappingDAO.merge(target);
  
  HostConfigMapping entity2 = createEntity(1L, "h1", "global", "version2");
  
  target = hostConfigMappingDAO.findSelectedByType(1L, hostEntity.getHostId(), "global");
  Assert.assertNotNull("Expected non-null entity for type 'global'", target);
  
  Assert.assertEquals("Expected version to be '" + entity2.getVersion() + "'", entity2.getVersion(), target.getVersion());
  
  Assert.assertEquals("Expected instance equality", entity2, target);
}