### Question:
ServiceConfigDAO { @RequiresSession public List<ServiceConfigEntity> getLastServiceConfigs(Long clusterId) { TypedQuery<ServiceConfigEntity> query = entityManagerProvider.get().createNamedQuery( "ServiceConfigEntity.findLatestServiceConfigsByCluster", ServiceConfigEntity.class); query.setParameter("clusterId", clusterId); return daoUtils.selectList(query); }  @RequiresSession ServiceConfigEntity find(Long serviceConfigId); @RequiresSession ServiceConfigEntity findByServiceAndVersion(String serviceName, Long version); @RequiresSession List<ServiceConfigEntity> findByService(Long clusterId, String serviceName); @RequiresSession List<ServiceConfigEntity> getLastServiceConfigVersionsForGroups(Collection<Long> configGroupIds); @RequiresSession ServiceConfigEntity getLastServiceConfigVersionsForGroup(Long configGroupId); @RequiresSession List<Long> getServiceConfigVersionsByConfig(Long clusterId, String configType, Long configVersion); @RequiresSession List<ServiceConfigEntity> getLastServiceConfigs(Long clusterId); @RequiresSession List<ServiceConfigEntity> getLastServiceConfigsForService(Long clusterId, String serviceName); @RequiresSession ServiceConfigEntity getLastServiceConfigForServiceDefaultGroup(Long clusterId, String serviceName); @RequiresSession List<ServiceConfigEntity> getServiceConfigsForServiceAndStack(Long clusterId,
      StackId stackId, String serviceName); @RequiresSession List<ServiceConfigEntity> getLatestServiceConfigs(Long clusterId,
      StackId stackId); @RequiresSession ServiceConfigEntity getLastServiceConfig(Long clusterId, String serviceName); @RequiresSession ServiceConfigEntity findMaxVersion(Long clusterId, String serviceName); @RequiresSession List<ServiceConfigEntity> getServiceConfigs(Long clusterId); @RequiresSession List<ServiceConfigEntity> findAll(); @RequiresSession Long findNextServiceConfigVersion(long clusterId, String serviceName); @Transactional void removeHostFromServiceConfigs(final Long hostId); @Transactional void create(ServiceConfigEntity serviceConfigEntity); @Transactional ServiceConfigEntity merge(ServiceConfigEntity serviceConfigEntity); @Transactional void remove(ServiceConfigEntity serviceConfigEntity);  }### Answer:
@Test public void testGetLastServiceConfigs() throws Exception { createServiceConfig("HDFS", "admin", 1L, 1L, 1111L, null); createServiceConfig("HDFS", "admin", 2L, 2L, 2222L, null); createServiceConfig("YARN", "admin", 1L, 3L, 3333L, null); List<ServiceConfigEntity> serviceConfigEntities = serviceConfigDAO.getLastServiceConfigs(clusterDAO.findByName("c1").getClusterId()); Assert.assertNotNull(serviceConfigEntities); Assert.assertEquals(2, serviceConfigEntities.size()); Long clusterId = clusterDAO.findByName("c1").getClusterId(); for (ServiceConfigEntity sce: serviceConfigEntities) { if ("HDFS".equals(sce.getServiceName())) { Assert.assertEquals("c1", sce.getClusterEntity().getClusterName()); Assert.assertEquals(clusterId, sce.getClusterEntity() .getClusterId()); Assert.assertEquals(Long.valueOf(2222L), sce.getCreateTimestamp()); Assert.assertEquals(Long.valueOf(2), sce.getVersion()); Assert.assertTrue(sce.getClusterConfigEntities().isEmpty()); Assert.assertNotNull(sce.getServiceConfigId()); } if ("YARN".equals(sce.getServiceName())) { Assert.assertEquals("c1", sce.getClusterEntity().getClusterName()); Assert.assertEquals(clusterId, sce.getClusterEntity() .getClusterId()); Assert.assertEquals(Long.valueOf(3333L), sce.getCreateTimestamp()); Assert.assertEquals(Long.valueOf(1), sce.getVersion()); Assert.assertTrue(sce.getClusterConfigEntities().isEmpty()); Assert.assertNotNull(sce.getServiceConfigId()); } Assert.assertEquals("admin", sce.getUser()); } }