Search in sources :

Example 51 with Namespace

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

the class NamespaceUnlockAspectTest method testChildNamespaceNotModified.

@Test
public void testChildNamespaceNotModified() {
    long childNamespaceId = 1, parentNamespaceId = 2;
    Namespace childNamespace = createNamespace(childNamespaceId);
    Namespace parentNamespace = createNamespace(parentNamespaceId);
    Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}");
    List<Item> childItems = Collections.singletonList(createItem("k1", "v3"));
    Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
    when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
    when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease);
    when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems);
    when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
    boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
    Assert.assertFalse(isModified);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 52 with Namespace

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

the class NamespaceUnlockAspectTest method testParentNamespaceNotReleased.

@Test
public void testParentNamespaceNotReleased() {
    long childNamespaceId = 1, parentNamespaceId = 2;
    Namespace childNamespace = createNamespace(childNamespaceId);
    Namespace parentNamespace = createNamespace(parentNamespaceId);
    Release childRelease = createRelease("{\"k1\":\"v3\", \"k2\":\"v2\"}");
    List<Item> childItems = Arrays.asList(createItem("k1", "v2"), createItem("k2", "v2"));
    when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
    when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(null);
    when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems);
    when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
    boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
    Assert.assertTrue(isModified);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 53 with Namespace

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

the class NamespaceUnlockAspectTest method testNamespaceModifyItem.

@Test
public void testNamespaceModifyItem() {
    long namespaceId = 1;
    Namespace namespace = createNamespace(namespaceId);
    Release release = createRelease("{\"k1\":\"v1\"}");
    List<Item> items = Collections.singletonList(createItem("k1", "v2"));
    when(releaseService.findLatestActiveRelease(namespace)).thenReturn(release);
    when(itemService.findItemsWithoutOrdered(namespaceId)).thenReturn(items);
    when(namespaceService.findParentNamespace(namespace)).thenReturn(null);
    boolean isModified = namespaceUnlockAspect.isModified(namespace);
    Assert.assertTrue(isModified);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 54 with Namespace

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

the class NamespaceUnlockAspectTest method testChildNamespaceModified.

@Test
public void testChildNamespaceModified() {
    long childNamespaceId = 1, parentNamespaceId = 2;
    Namespace childNamespace = createNamespace(childNamespaceId);
    Namespace parentNamespace = createNamespace(parentNamespaceId);
    Release childRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
    List<Item> childItems = Collections.singletonList(createItem("k1", "v3"));
    Release parentRelease = createRelease("{\"k1\":\"v1\", \"k2\":\"v2\"}");
    when(releaseService.findLatestActiveRelease(childNamespace)).thenReturn(childRelease);
    when(releaseService.findLatestActiveRelease(parentNamespace)).thenReturn(parentRelease);
    when(itemService.findItemsWithoutOrdered(childNamespaceId)).thenReturn(childItems);
    when(namespaceService.findParentNamespace(childNamespace)).thenReturn(parentNamespace);
    boolean isModified = namespaceUnlockAspect.isModified(childNamespace);
    Assert.assertTrue(isModified);
}
Also used : Item(com.ctrip.framework.apollo.biz.entity.Item) Namespace(com.ctrip.framework.apollo.biz.entity.Namespace) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 55 with Namespace

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

the class NamespaceUnlockAspectTest method createNamespace.

private Namespace createNamespace(long namespaceId) {
    Namespace namespace = new Namespace();
    namespace.setId(namespaceId);
    return namespace;
}
Also used : Namespace(com.ctrip.framework.apollo.biz.entity.Namespace)

Aggregations

Namespace (com.ctrip.framework.apollo.biz.entity.Namespace)60 Test (org.junit.Test)24 Release (com.ctrip.framework.apollo.biz.entity.Release)22 AppNamespace (com.ctrip.framework.apollo.common.entity.AppNamespace)14 Item (com.ctrip.framework.apollo.biz.entity.Item)13 Transactional (org.springframework.transaction.annotation.Transactional)11 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)10 Cluster (com.ctrip.framework.apollo.biz.entity.Cluster)10 Sql (org.springframework.test.context.jdbc.Sql)10 ReleaseHistory (com.ctrip.framework.apollo.biz.entity.ReleaseHistory)8 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)8 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)8 GrayReleaseRule (com.ctrip.framework.apollo.biz.entity.GrayReleaseRule)6 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 AbstractUnitTest (com.ctrip.framework.apollo.biz.AbstractUnitTest)4 Commit (com.ctrip.framework.apollo.biz.entity.Commit)3 PreAcquireNamespaceLock (com.ctrip.framework.apollo.adminservice.aop.PreAcquireNamespaceLock)2 ConfigChangeContentBuilder (com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder)2 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2