Search in sources :

Example 6 with AwsRegionVO

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

the class AwsRegionManagerTest method createShouldSetKmsKeyIdToDefaultValueIfMissing.

@Test
public void createShouldSetKmsKeyIdToDefaultValueIfMissing() {
    final String defaultKeyId = KMS_KEY_ID;
    when(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SECURITY_KEY_ID)).thenReturn(defaultKeyId);
    final AwsRegionVO regionVO = getAwsRegionVoBuilder().kmsKeyArn(KMS_KEY_ARN).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.getKmsKeyId(), is(defaultKeyId));
}
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 7 with AwsRegionVO

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

the class AwsRegionManager method changeOwner.

@Override
public AwsRegion changeOwner(final Long id, final String owner) {
    final AwsRegion awsRegion = load(id);
    awsRegion.setOwner(owner);
    final AwsRegionVO awsRegionVO = awsRegionMapper.toAwsRegionVO(awsRegion);
    return update(id, awsRegionVO);
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO)

Example 8 with AwsRegionVO

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

the class AwsRegionManagerTest method createShouldSetOwnerForAwsRegion.

@Test
public void createShouldSetOwnerForAwsRegion() {
    final String ownerUserName = "ownerUserName";
    final AwsRegionVO awsRegionVO = getAwsRegionVoBuilder().build();
    when(authManager.getAuthorizedUser()).thenReturn(ownerUserName);
    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();
    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)

Example 9 with AwsRegionVO

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

the class AwsRegionManagerTest method updateShouldUpdateEntityInDao.

@Test
public void updateShouldUpdateEntityInDao() {
    final AwsRegion originalRegion = getCommonRegion();
    originalRegion.setId(ID);
    originalRegion.setCorsRules(EMPTY_CORS_RULES);
    originalRegion.setPolicy(EMPTY_POLICY);
    originalRegion.setKmsKeyId(KMS_KEY_ID);
    originalRegion.setKmsKeyArn(KMS_KEY_ARN);
    final AwsRegion updatedRegion = getCommonRegion();
    updatedRegion.setId(ID);
    updatedRegion.setName("anotherName");
    updatedRegion.setCorsRules(EMPTY_CORS_RULES);
    updatedRegion.setPolicy(EMPTY_POLICY);
    updatedRegion.setKmsKeyId(KMS_KEY_ID);
    updatedRegion.setKmsKeyArn(KMS_KEY_ARN);
    final AwsRegionVO updatedRegionVO = awsRegionMapper.toAwsRegionVO(updatedRegion);
    when(awsRegionDao.loadById(ID)).thenReturn(Optional.of(originalRegion));
    awsRegionManager.update(ID, updatedRegionVO);
    verify(awsRegionDao).update(eq(updatedRegion));
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

Example 10 with AwsRegionVO

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

the class AwsRegionManagerTest method createShouldSetPolicyToNullIfDefaultValueIsNull.

@Test
public void createShouldSetPolicyToNullIfDefaultValueIsNull() {
    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());
    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(), isEmptyOrNullString());
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) 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