private HostConfigMapping createEntity(long clusterId, String hostName, String type, String version) throws Exception {
    HostConfigMapping hostConfigMappingEntity = new HostConfigMappingImpl();
    hostConfigMappingEntity.setClusterId(Long.valueOf(clusterId));
    hostConfigMappingEntity.setCreateTimestamp(Long.valueOf(System.currentTimeMillis()));

    HostEntity hostEntity = hostDAO.findByName(hostName);
    if (hostEntity == null) {
      hostEntity = new HostEntity();
      hostEntity.setHostName(hostName);
      hostDAO.create(hostEntity);
    }

    hostConfigMappingEntity.setHostId(hostEntity.getHostId());
    hostConfigMappingEntity.setSelected(1);
    hostConfigMappingEntity.setType(type);
    hostConfigMappingEntity.setVersion(version);
    hostConfigMappingEntity.setUser("_test");

    hostConfigMappingDAO.create(hostConfigMappingEntity);
    
    return hostConfigMappingEntity;
  }
Tests host config mapping DAO and Entities
ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAOTest.java