ReleaseService { public Release findLatestActiveRelease(Namespace namespace) { return findLatestActiveRelease(namespace.getAppId(), namespace.getClusterName(), namespace.getNamespaceName()); } ReleaseService(
      final ReleaseRepository releaseRepository,
      final ItemService itemService,
      final AuditService auditService,
      final NamespaceLockService namespaceLockService,
      final NamespaceService namespaceService,
      final NamespaceBranchService namespaceBranchService,
      final ReleaseHistoryService releaseHistoryService,
      final ItemSetService itemSetService); Release findOne(long releaseId); Release findActiveOne(long releaseId); List<Release> findByReleaseIds(Set<Long> releaseIds); List<Release> findByReleaseKeys(Set<String> releaseKeys); Release findLatestActiveRelease(Namespace namespace); Release findLatestActiveRelease(String appId, String clusterName, String namespaceName); List<Release> findAllReleases(String appId, String clusterName, String namespaceName, Pageable page); List<Release> findActiveReleases(String appId, String clusterName, String namespaceName, Pageable page); @Transactional Release mergeBranchChangeSetsAndRelease(Namespace namespace, String branchName, String releaseName,
                                                 String releaseComment, boolean isEmergencyPublish,
                                                 ItemChangeSets changeSets); @Transactional Release publish(Namespace namespace, String releaseName, String releaseComment,
                         String operator, boolean isEmergencyPublish); @Transactional Release grayDeletionPublish(Namespace namespace, String releaseName, String releaseComment,
                                     String operator, boolean isEmergencyPublish, Set<String> grayDelKeys); @Transactional Release rollback(long releaseId, String operator); @Transactional Release rollbackTo(long releaseId, long toReleaseId, String operator); @Transactional int batchDelete(String appId, String clusterName, String namespaceName, String operator);  }
@Test public void testFindRelease() throws Exception { String someAppId = "1"; String someClusterName = "someClusterName"; String someNamespaceName = "someNamespaceName"; long someReleaseId = 1; String someReleaseKey = "someKey"; String someValidConfiguration = "{\"apollo.bar\": \"foo\"}"; Release someRelease = MockBeanFactory.mockRelease(someReleaseId, someReleaseKey, someAppId, someClusterName, someNamespaceName, someValidConfiguration); when(releaseRepository.findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(someAppId, someClusterName, someNamespaceName)) .thenReturn(someRelease); Release result = releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName); verify(releaseRepository, times(1)) .findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(someAppId, someClusterName, someNamespaceName); assertEquals(someAppId, result.getAppId()); assertEquals(someClusterName, result.getClusterName()); assertEquals(someReleaseId, result.getId()); assertEquals(someReleaseKey, result.getReleaseKey()); assertEquals(someValidConfiguration, result.getConfigurations()); }
@Test public void testLoadConfigWithConfigNotFound() throws Exception { String someAppId = "1"; String someClusterName = "someClusterName"; String someNamespaceName = "someNamespaceName"; when(releaseRepository.findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc(someAppId, someClusterName, someNamespaceName)) .thenReturn(null); Release result = releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName); assertNull(result); verify(releaseRepository, times(1)).findFirstByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseOrderByIdDesc( someAppId, someClusterName, someNamespaceName); }