Search in sources :

Example 11 with AwsRegionVO

use of com.epam.pipeline.controller.vo.AwsRegionVO in project cloud-pipeline by epam.

the class AwsRegionManagerTest method createShouldSetCreatedDateForAwsRegion.

@Test
public void createShouldSetCreatedDateForAwsRegion() {
    final AwsRegionVO awsRegionVO = getAwsRegionVoBuilder().build();
    doReturn(Optional.ofNullable(null)).when(preferenceManager).load(SystemPreferences.DATA_STORAGE_CORS_POLICY.getKey());
    doReturn(Optional.ofNullable(null)).when(preferenceManager).load(SystemPreferences.DATA_STORAGE_POLICY.getKey());
    awsRegionManager.create(awsRegionVO);
    final ArgumentCaptor<AwsRegion> regionCaptor = ArgumentCaptor.forClass(AwsRegion.class);
    verify(awsRegionDao).create(regionCaptor.capture());
    final AwsRegion actualRegion = regionCaptor.getValue();
    assertNotNull(actualRegion.getCreatedDate());
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

Example 12 with AwsRegionVO

use of com.epam.pipeline.controller.vo.AwsRegionVO in project cloud-pipeline by epam.

the class AwsRegionManagerTest method createShouldSetPolicyToDefaultValueIfMissing.

@Test
public void createShouldSetPolicyToDefaultValueIfMissing() {
    final String defaultPolicyAsString = "{" + "\"key1\":\"value1\"," + "\"key2\":\"value2\"" + "}";
    Preference policy = new Preference();
    policy.setValue(defaultPolicyAsString);
    doReturn(Optional.of(policy)).when(preferenceManager).load(SystemPreferences.DATA_STORAGE_POLICY.getKey());
    final AwsRegionVO regionVO = getAwsRegionVoBuilder().corsRules(EMPTY_CORS_RULES).kmsKeyId(KMS_KEY_ID).kmsKeyArn(KMS_KEY_ARN).awsRegionName(VALID_REGION_ID).isDefault(false).build();
    awsRegionManager.create(regionVO);
    final ArgumentCaptor<AwsRegion> regionCaptor = ArgumentCaptor.forClass(AwsRegion.class);
    verify(awsRegionDao).create(regionCaptor.capture());
    final AwsRegion actualRegion = regionCaptor.getValue();
    assertThat(actualRegion.getPolicy(), is(defaultPolicyAsString));
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Preference(com.epam.pipeline.entity.preference.Preference) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

Example 13 with AwsRegionVO

use of com.epam.pipeline.controller.vo.AwsRegionVO in project cloud-pipeline by epam.

the class AwsRegionManagerTest method createShouldSaveRegionAsIsIfAllOptionalFieldsIsAlreadySet.

@Test
public void createShouldSaveRegionAsIsIfAllOptionalFieldsIsAlreadySet() {
    final AwsRegionVO regionVO = getAwsRegionVoBuilder().corsRules(EMPTY_CORS_RULES).policy(EMPTY_POLICY).kmsKeyId(KMS_KEY_ID).kmsKeyArn(KMS_KEY_ARN).awsRegionName(VALID_REGION_ID).isDefault(false).build();
    final AwsRegion expectedRegion = awsRegionMapper.toAwsRegion(regionVO);
    awsRegionManager.create(regionVO);
    final ArgumentCaptor<AwsRegion> regionCaptor = ArgumentCaptor.forClass(AwsRegion.class);
    verify(awsRegionDao).create(regionCaptor.capture());
    final AwsRegion actualRegion = regionCaptor.getValue();
    assertRegionEquals(expectedRegion, actualRegion);
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

Example 14 with AwsRegionVO

use of com.epam.pipeline.controller.vo.AwsRegionVO in project cloud-pipeline by epam.

the class AwsRegionManagerTest method createShouldSetKmsKeyArnToDefaultValueIfMissing.

@Test
public void createShouldSetKmsKeyArnToDefaultValueIfMissing() {
    final String defaultKeyArn = KMS_KEY_ARN;
    when(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SECURITY_KEY_ARN)).thenReturn(defaultKeyArn);
    final AwsRegionVO regionVO = getAwsRegionVoBuilder().kmsKeyId(KMS_KEY_ID).policy(EMPTY_POLICY).corsRules(EMPTY_CORS_RULES).awsRegionName(VALID_REGION_ID).isDefault(false).build();
    awsRegionManager.create(regionVO);
    final ArgumentCaptor<AwsRegion> regionCaptor = ArgumentCaptor.forClass(AwsRegion.class);
    verify(awsRegionDao).create(regionCaptor.capture());
    final AwsRegion actualRegion = regionCaptor.getValue();
    assertThat(actualRegion.getKmsKeyArn(), is(defaultKeyArn));
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

Example 15 with AwsRegionVO

use of com.epam.pipeline.controller.vo.AwsRegionVO in project cloud-pipeline by epam.

the class AwsRegionManagerTest method updateShouldSaveOwnerFromTheOldValue.

@Test
public void updateShouldSaveOwnerFromTheOldValue() {
    final String ownerUserName = "ownerUserName";
    final AwsRegionVO awsRegionVO = getAwsRegionVoBuilder().build();
    final AwsRegion originalRegion = getCommonRegion();
    originalRegion.setOwner(ownerUserName);
    when(awsRegionDao.loadById(ID)).thenReturn(Optional.of(originalRegion));
    doReturn(Optional.ofNullable(null)).when(preferenceManager).load(SystemPreferences.DATA_STORAGE_CORS_POLICY.getKey());
    doReturn(Optional.ofNullable(null)).when(preferenceManager).load(SystemPreferences.DATA_STORAGE_POLICY.getKey());
    awsRegionManager.update(ID, awsRegionVO);
    final ArgumentCaptor<AwsRegion> regionCaptor = ArgumentCaptor.forClass(AwsRegion.class);
    verify(awsRegionDao).update(regionCaptor.capture());
    final AwsRegion actualRegion = regionCaptor.getValue();
    assertThat(actualRegion.getOwner(), is(ownerUserName));
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

Aggregations

AwsRegionVO (com.epam.pipeline.controller.vo.AwsRegionVO)16 Test (org.junit.Test)15 AwsRegion (com.epam.pipeline.entity.region.AwsRegion)13 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)6 Preference (com.epam.pipeline.entity.preference.Preference)2 Date (java.util.Date)1