Search in sources :

Example 6 with Instance

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

the class InstanceConfigControllerTest method testGetInstancesByNamespaceAndInstanceAppId.

@Test
public void testGetInstancesByNamespaceAndInstanceAppId() throws Exception {
    String someInstanceAppId = "someInstanceAppId";
    String someAppId = "someAppId";
    String someClusterName = "someClusterName";
    String someNamespaceName = "someNamespaceName";
    String someIp = "someIp";
    long someInstanceId = 1;
    long anotherInstanceId = 2;
    Instance someInstance = assembleInstance(someInstanceId, someAppId, someClusterName, someNamespaceName, someIp);
    Instance anotherInstance = assembleInstance(anotherInstanceId, someAppId, someClusterName, someNamespaceName, someIp);
    Page<Instance> instances = new PageImpl<>(Lists.newArrayList(someInstance, anotherInstance), pageable, 2);
    when(instanceService.findInstancesByNamespaceAndInstanceAppId(someInstanceAppId, someAppId, someClusterName, someNamespaceName, pageable)).thenReturn(instances);
    PageDTO<InstanceDTO> result = instanceConfigController.getInstancesByNamespace(someAppId, someClusterName, someNamespaceName, someInstanceAppId, pageable);
    assertEquals(2, result.getContent().size());
    InstanceDTO someInstanceDto = null;
    InstanceDTO anotherInstanceDto = null;
    for (InstanceDTO instanceDTO : result.getContent()) {
        if (instanceDTO.getId() == someInstanceId) {
            someInstanceDto = instanceDTO;
        } else if (instanceDTO.getId() == anotherInstanceId) {
            anotherInstanceDto = instanceDTO;
        }
    }
    verifyInstance(someInstance, someInstanceDto);
    verifyInstance(anotherInstance, anotherInstanceDto);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Instance(com.ctrip.framework.apollo.biz.entity.Instance) InstanceDTO(com.ctrip.framework.apollo.common.dto.InstanceDTO) Test(org.junit.Test)

Example 7 with Instance

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

the class InstanceConfigControllerTest method testGetInstancesByNamespace.

@Test
public void testGetInstancesByNamespace() throws Exception {
    String someAppId = "someAppId";
    String someClusterName = "someClusterName";
    String someNamespaceName = "someNamespaceName";
    String someIp = "someIp";
    long someInstanceId = 1;
    long anotherInstanceId = 2;
    Instance someInstance = assembleInstance(someInstanceId, someAppId, someClusterName, someNamespaceName, someIp);
    Instance anotherInstance = assembleInstance(anotherInstanceId, someAppId, someClusterName, someNamespaceName, someIp);
    Page<Instance> instances = new PageImpl<>(Lists.newArrayList(someInstance, anotherInstance), pageable, 2);
    when(instanceService.findInstancesByNamespace(someAppId, someClusterName, someNamespaceName, pageable)).thenReturn(instances);
    PageDTO<InstanceDTO> result = instanceConfigController.getInstancesByNamespace(someAppId, someClusterName, someNamespaceName, null, pageable);
    assertEquals(2, result.getContent().size());
    InstanceDTO someInstanceDto = null;
    InstanceDTO anotherInstanceDto = null;
    for (InstanceDTO instanceDTO : result.getContent()) {
        if (instanceDTO.getId() == someInstanceId) {
            someInstanceDto = instanceDTO;
        } else if (instanceDTO.getId() == anotherInstanceId) {
            anotherInstanceDto = instanceDTO;
        }
    }
    verifyInstance(someInstance, someInstanceDto);
    verifyInstance(anotherInstance, anotherInstanceDto);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Instance(com.ctrip.framework.apollo.biz.entity.Instance) InstanceDTO(com.ctrip.framework.apollo.common.dto.InstanceDTO) Test(org.junit.Test)

Example 8 with Instance

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

the class InstanceConfigControllerTest method assembleInstance.

private Instance assembleInstance(long instanceId, String appId, String clusterName, String dataCenter, String ip) {
    Instance instance = new Instance();
    instance.setId(instanceId);
    instance.setAppId(appId);
    instance.setIp(ip);
    instance.setClusterName(clusterName);
    instance.setDataCenter(dataCenter);
    instance.setDataChangeCreatedTime(new Date());
    return instance;
}
Also used : Instance(com.ctrip.framework.apollo.biz.entity.Instance) Date(java.util.Date)

Example 9 with Instance

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

the class InstanceConfigControllerTest method getByRelease.

@Test
public void getByRelease() throws Exception {
    long someReleaseId = 1;
    long someInstanceId = 1;
    long anotherInstanceId = 2;
    String someReleaseKey = "someKey";
    Release someRelease = new Release();
    someRelease.setReleaseKey(someReleaseKey);
    String someAppId = "someAppId";
    String anotherAppId = "anotherAppId";
    String someCluster = "someCluster";
    String someDataCenter = "someDC";
    String someConfigAppId = "someConfigAppId";
    String someConfigNamespace = "someNamespace";
    String someIp = "someIp";
    Date someReleaseDeliveryTime = new Date();
    Date anotherReleaseDeliveryTime = new Date();
    when(releaseService.findOne(someReleaseId)).thenReturn(someRelease);
    InstanceConfig someInstanceConfig = assembleInstanceConfig(someInstanceId, someConfigAppId, someConfigNamespace, someReleaseKey, someReleaseDeliveryTime);
    InstanceConfig anotherInstanceConfig = assembleInstanceConfig(anotherInstanceId, someConfigAppId, someConfigNamespace, someReleaseKey, anotherReleaseDeliveryTime);
    List<InstanceConfig> instanceConfigs = Lists.newArrayList(someInstanceConfig, anotherInstanceConfig);
    Page<InstanceConfig> instanceConfigPage = new PageImpl<>(instanceConfigs, pageable, instanceConfigs.size());
    when(instanceService.findActiveInstanceConfigsByReleaseKey(someReleaseKey, pageable)).thenReturn(instanceConfigPage);
    Instance someInstance = assembleInstance(someInstanceId, someAppId, someCluster, someDataCenter, someIp);
    Instance anotherInstance = assembleInstance(anotherInstanceId, anotherAppId, someCluster, someDataCenter, someIp);
    List<Instance> instances = Lists.newArrayList(someInstance, anotherInstance);
    Set<Long> instanceIds = Sets.newHashSet(someInstanceId, anotherInstanceId);
    when(instanceService.findInstancesByIds(instanceIds)).thenReturn(instances);
    PageDTO<InstanceDTO> result = instanceConfigController.getByRelease(someReleaseId, pageable);
    assertEquals(2, result.getContent().size());
    InstanceDTO someInstanceDto = null;
    InstanceDTO anotherInstanceDto = null;
    for (InstanceDTO instanceDTO : result.getContent()) {
        if (instanceDTO.getId() == someInstanceId) {
            someInstanceDto = instanceDTO;
        } else if (instanceDTO.getId() == anotherInstanceId) {
            anotherInstanceDto = instanceDTO;
        }
    }
    verifyInstance(someInstance, someInstanceDto);
    verifyInstance(anotherInstance, anotherInstanceDto);
    assertEquals(1, someInstanceDto.getConfigs().size());
    assertEquals(someReleaseDeliveryTime, someInstanceDto.getConfigs().get(0).getReleaseDeliveryTime());
    assertEquals(1, anotherInstanceDto.getConfigs().size());
    assertEquals(anotherReleaseDeliveryTime, anotherInstanceDto.getConfigs().get(0).getReleaseDeliveryTime());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Instance(com.ctrip.framework.apollo.biz.entity.Instance) Date(java.util.Date) InstanceConfig(com.ctrip.framework.apollo.biz.entity.InstanceConfig) InstanceDTO(com.ctrip.framework.apollo.common.dto.InstanceDTO) Release(com.ctrip.framework.apollo.biz.entity.Release) Test(org.junit.Test)

Example 10 with Instance

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

the class InstanceServiceTest method assembleInstance.

private Instance assembleInstance(String appId, String clusterName, String dataCenter, String ip) {
    Instance instance = new Instance();
    instance.setAppId(appId);
    instance.setIp(ip);
    instance.setClusterName(clusterName);
    instance.setDataCenter(dataCenter);
    return instance;
}
Also used : Instance(com.ctrip.framework.apollo.biz.entity.Instance)

Aggregations

Instance (com.ctrip.framework.apollo.biz.entity.Instance)15 Test (org.junit.Test)10 InstanceConfig (com.ctrip.framework.apollo.biz.entity.InstanceConfig)6 InstanceDTO (com.ctrip.framework.apollo.common.dto.InstanceDTO)6 Date (java.util.Date)6 AbstractIntegrationTest (com.ctrip.framework.apollo.biz.AbstractIntegrationTest)5 Rollback (org.springframework.test.annotation.Rollback)5 Release (com.ctrip.framework.apollo.biz.entity.Release)4 PageImpl (org.springframework.data.domain.PageImpl)3 InstanceService (com.ctrip.framework.apollo.biz.service.InstanceService)2 ReleaseService (com.ctrip.framework.apollo.biz.service.ReleaseService)2 InstanceConfigDTO (com.ctrip.framework.apollo.common.dto.InstanceConfigDTO)2 PageDTO (com.ctrip.framework.apollo.common.dto.PageDTO)2 ReleaseDTO (com.ctrip.framework.apollo.common.dto.ReleaseDTO)2 NotFoundException (com.ctrip.framework.apollo.common.exception.NotFoundException)2 BeanUtils (com.ctrip.framework.apollo.common.utils.BeanUtils)2 Splitter (com.google.common.base.Splitter)2 Strings (com.google.common.base.Strings)2 HashMultimap (com.google.common.collect.HashMultimap)2 Maps (com.google.common.collect.Maps)2