Search in sources :

Example 41 with Release

use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.

the class ReleaseServiceTest method init.

@Before
public void init() {
    firstRelease = new Release();
    firstRelease.setId(releaseId);
    firstRelease.setAppId(appId);
    firstRelease.setClusterName(clusterName);
    firstRelease.setNamespaceName(namespaceName);
    firstRelease.setAbandoned(false);
    secondRelease = new Release();
    secondRelease.setAppId(appId);
    secondRelease.setClusterName(clusterName);
    secondRelease.setNamespaceName(namespaceName);
    secondRelease.setAbandoned(false);
    pageRequest = PageRequest.of(0, 2);
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Before(org.junit.Before)

Example 42 with Release

use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.

the class ReleaseServiceTest method testFindByReleaseIds.

@Test
public void testFindByReleaseIds() throws Exception {
    Release someRelease = mock(Release.class);
    Release anotherRelease = mock(Release.class);
    long someReleaseId = 1;
    long anotherReleaseId = 2;
    List<Release> someReleases = Lists.newArrayList(someRelease, anotherRelease);
    Set<Long> someReleaseIds = Sets.newHashSet(someReleaseId, anotherReleaseId);
    when(releaseRepository.findAllById(someReleaseIds)).thenReturn(someReleases);
    List<Release> result = releaseService.findByReleaseIds(someReleaseIds);
    assertEquals(someReleases, result);
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Example 43 with Release

use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.

the class ReleaseServiceTest method testRollbackTo.

@Test
public void testRollbackTo() {
    List<Release> releaseList = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        Release release = new Release();
        release.setId(3 - i);
        release.setAppId(appId);
        release.setClusterName(clusterName);
        release.setNamespaceName(namespaceName);
        release.setAbandoned(false);
        releaseList.add(release);
    }
    long releaseId1 = 1;
    long releaseId3 = 3;
    when(releaseRepository.findById(releaseId1)).thenReturn(Optional.of(releaseList.get(2)));
    when(releaseRepository.findById(releaseId3)).thenReturn(Optional.of(releaseList.get(0)));
    when(releaseRepository.findByAppIdAndClusterNameAndNamespaceNameAndIsAbandonedFalseAndIdBetweenOrderByIdDesc(appId, clusterName, namespaceName, releaseId1, releaseId3)).thenReturn(releaseList);
    releaseService.rollbackTo(releaseId3, releaseId1, user);
    verify(releaseRepository).saveAll(releaseList);
    Assert.assertTrue(releaseList.get(0).isAbandoned());
    Assert.assertTrue(releaseList.get(1).isAbandoned());
    Assert.assertFalse(releaseList.get(2).isAbandoned());
    Assert.assertEquals(user, releaseList.get(0).getDataChangeLastModifiedBy());
    Assert.assertEquals(user, releaseList.get(1).getDataChangeLastModifiedBy());
}
Also used : ArrayList(java.util.ArrayList) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Example 44 with Release

use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.

the class ReleaseServiceTest method testFindRelease.

@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());
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Example 45 with Release

use of com.ctrip.framework.apollo.biz.entity.Release in project apollo by ctripcorp.

the class ReleaseServiceTest method testLoadConfigWithConfigNotFound.

@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);
}
Also used : Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test) AbstractUnitTest(com.ctrip.framework.apollo.biz.AbstractUnitTest)

Aggregations

Release (com.ctrip.framework.apollo.biz.entity.Release)71 Test (org.junit.Test)36 Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)22 Item (com.ctrip.framework.apollo.biz.entity.Item)12 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)9 Transactional (org.springframework.transaction.annotation.Transactional)9 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)7 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)7 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)7 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)7 Sql (org.springframework.test.context.jdbc.Sql)7 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)5 Instance (com.ctrip.framework.apollo.biz.entity.Instance)4 InstanceDTO (com.ctrip.framework.apollo.common.dto.InstanceDTO)4 Date (java.util.Date)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)3 ReleaseMessage (com.ctrip.framework.apollo.biz.entity.ReleaseMessage)3 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)3 PageRequest (org.springframework.data.domain.PageRequest)3