@Test
public void testMerge() throws Exception {

  HostConfigMapping source = createEntity(1L, "h1", "global", "v1");
  HostEntity hostEntity = hostDAO.findByName("h1");
  Set<HostConfigMapping> target = hostConfigMappingDAO.findByType(1L, hostEntity.getHostId(), "global");
  Assert.assertEquals("Expected one result", 1, target.size());
  
  HostConfigMapping toChange = null;
  
  for (HostConfigMapping item: target) {
    Assert.assertEquals("Expected version 'v1'", source.getVersion(), item.getVersion());
    Assert.assertEquals("Expected selected flag 1", 1, (int)item.getSelected());
    toChange = item;
    toChange.setSelected(0);
  }
  
  hostConfigMappingDAO.merge(toChange);
  
  target = hostConfigMappingDAO.findByType(1L, hostEntity.getHostId(), "global");
  Assert.assertEquals("Expected one result", 1, target.size());
  
  for (HostConfigMapping item: target) {
    Assert.assertEquals("Expected version 'v1'", source.getVersion(), item.getVersion());
    Assert.assertEquals("Expected selected flag 0", 0, (int)item.getSelected());
  }
}