Search in sources :

Example 1 with AwsRegionVO

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

the class AwsRegionManagerTest method createShouldThrowIfSpecifiedPolicyIsInvalid.

@Test
public void createShouldThrowIfSpecifiedPolicyIsInvalid() {
    final AwsRegionVO awsRegionVO = getAwsRegionVoBuilder().policy(INVALID_POLICY).build();
    assertThrows(AwsRegionException.class, () -> awsRegionManager.create(awsRegionVO));
}
Also used : AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

Example 2 with AwsRegionVO

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

the class AwsRegionManagerTest method createShouldSetCorsRulesToDefaultValueIfMissing.

@Test
public void createShouldSetCorsRulesToDefaultValueIfMissing() {
    final String corsRulesAsString = "[{" + "\"id\":\"id1\"," + "\"allowedOrigins\":[\"origin1\",\"origin2\"]," + "\"maxAgeSeconds\":0" + "},{" + "\"id\":\"id2\"," + "\"maxAgeSeconds\":0," + "\"allowedHeaders\":[\"header1\"]" + "}]";
    Preference corsPolicy = new Preference();
    corsPolicy.setValue(corsRulesAsString);
    doReturn(Optional.of(corsPolicy)).when(preferenceManager).load(eq(SystemPreferences.DATA_STORAGE_CORS_POLICY.getKey()));
    final AwsRegionVO regionVO = getAwsRegionVoBuilder().policy(EMPTY_POLICY).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.getCorsRules(), is(corsRulesAsString));
}
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 3 with AwsRegionVO

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

the class AwsRegionManagerTest method updateShouldSaveCreatedDateFromTheOldValue.

@Test
public void updateShouldSaveCreatedDateFromTheOldValue() {
    final Date createdDate = new Date();
    final AwsRegionVO awsRegionVO = getAwsRegionVoBuilder().build();
    final AwsRegion originalRegion = getCommonRegion();
    originalRegion.setCreatedDate(createdDate);
    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.getCreatedDate(), is(createdDate));
}
Also used : AwsRegion(com.epam.pipeline.entity.region.AwsRegion) AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Date(java.util.Date) Test(org.junit.Test)

Example 4 with AwsRegionVO

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

the class AwsRegionManagerTest method createShouldSaveEntityInDao.

@Test
public void createShouldSaveEntityInDao() {
    final AwsRegionVO regionVO = getAwsRegionVoBuilder().awsRegionName(VALID_REGION_ID).corsRules(EMPTY_CORS_RULES).policy(EMPTY_POLICY).kmsKeyId(KMS_KEY_ID).kmsKeyArn(KMS_KEY_ARN).isDefault(false).build();
    awsRegionManager.create(regionVO);
    verify(awsRegionDao).create(any());
}
Also used : AwsRegionVO(com.epam.pipeline.controller.vo.AwsRegionVO) Test(org.junit.Test)

Example 5 with AwsRegionVO

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

the class AwsRegionManagerTest method createShouldSetCorsRulesToNullIfDefaultValueIsNull.

@Test
public void createShouldSetCorsRulesToNullIfDefaultValueIsNull() {
    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().policy(EMPTY_POLICY).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.getCorsRules(), 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