Search in sources :

Example 6 with Promotion

use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method shouldProcessAcceptedPromotionUpdateApi.

@Test
public void shouldProcessAcceptedPromotionUpdateApi() throws Exception {
    when(promotionRepository.findById(any())).thenReturn(Optional.of(getAPromotion()));
    when(environmentService.findByCockpitId(any())).thenReturn(new EnvironmentEntity());
    when(permissionService.hasPermission(any(), any(), any())).thenReturn(true);
    Page<Promotion> promotionPage = new Page<>(singletonList(getAPromotion()), 0, 1, 1);
    when(promotionRepository.search(any(), any(), any())).thenReturn(promotionPage);
    when(apiDuplicatorService.updateWithImportedDefinition(any(), any(), any(), any(), any())).thenReturn(new ApiEntity());
    when(apiService.exists(any())).thenReturn(true);
    ApiEntity existingApi = new ApiEntity();
    existingApi.setId("api#existing");
    when(apiService.findById(any())).thenReturn(existingApi);
    CockpitReply<PromotionEntity> cockpitReply = new CockpitReply<>(null, CockpitReplyStatus.SUCCEEDED);
    when(cockpitService.processPromotion(any())).thenReturn(cockpitReply);
    when(promotionRepository.update(any())).thenReturn(getAPromotion());
    promotionService.processPromotion(PROMOTION_ID, true, USER_ID);
    verify(apiDuplicatorService, times(1)).updateWithImportedDefinition(any(), any(), eq(USER_ID), any(), any());
    verify(promotionRepository, times(1)).update(any());
}
Also used : CockpitReply(io.gravitee.rest.api.service.cockpit.services.CockpitReply) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Page(io.gravitee.common.data.domain.Page) Promotion(io.gravitee.repository.management.model.Promotion) Test(org.junit.Test)

Example 7 with Promotion

use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method shouldNotProcessPromotionIfCockpitReplyError.

@Test(expected = BridgeOperationException.class)
public void shouldNotProcessPromotionIfCockpitReplyError() throws Exception {
    when(promotionRepository.findById(any())).thenReturn(Optional.of(getAPromotion()));
    when(environmentService.findByCockpitId(any())).thenReturn(new EnvironmentEntity());
    when(permissionService.hasPermission(any(), any(), any())).thenReturn(true);
    Page<Promotion> promotionPage = new Page<>(singletonList(getAPromotion()), 0, 1, 1);
    when(promotionRepository.search(any(), any(), any())).thenReturn(promotionPage);
    when(apiService.exists(any())).thenReturn(true);
    when(apiDuplicatorService.updateWithImportedDefinition(any(), any(), any(), any(), any())).thenReturn(new ApiEntity());
    ApiEntity existingApi = new ApiEntity();
    existingApi.setId("api#existing");
    when(apiService.findById(any())).thenReturn(existingApi);
    CockpitReply<PromotionEntity> cockpitReply = new CockpitReply<>(null, CockpitReplyStatus.ERROR);
    when(cockpitService.processPromotion(any())).thenReturn(cockpitReply);
    promotionService.processPromotion(PROMOTION_ID, true, USER_ID);
    verify(apiDuplicatorService, times(1)).updateWithImportedDefinition(any(), any(), eq(USER_ID), any(), any());
    verify(promotionRepository, times(0)).update(any());
}
Also used : CockpitReply(io.gravitee.rest.api.service.cockpit.services.CockpitReply) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Page(io.gravitee.common.data.domain.Page) Promotion(io.gravitee.repository.management.model.Promotion) Test(org.junit.Test)

Example 8 with Promotion

use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method shouldPromote.

@Test
public void shouldPromote() throws TechnicalException {
    when(userService.findById(any())).thenReturn(getAUserEntity());
    EnvironmentEntity environmentEntity = new EnvironmentEntity();
    environmentEntity.setCockpitId("env#cockpit-1");
    environmentEntity.setName("Env 1");
    when(environmentService.findById(any())).thenReturn(environmentEntity);
    Page<Promotion> promotionPage = new Page<>(emptyList(), 0, 0, 0);
    when(promotionRepository.search(any(), any(), any())).thenReturn(promotionPage);
    when(promotionRepository.create(any())).thenReturn(getAPromotion());
    when(cockpitService.requestPromotion(any())).thenReturn(new CockpitReply<>(getAPromotionEntity(), CockpitReplyStatus.SUCCEEDED));
    when(promotionRepository.update(any())).thenReturn(mock(Promotion.class));
    final PromotionEntity promotionEntity = promotionService.promote("api#1", getAPromotionRequestEntity(), "user#1");
    assertThat(promotionEntity).isNotNull();
    verify(auditService).createApiAuditLog(eq("api#1"), any(), eq(PROMOTION_CREATED), any(), isNull(), any());
}
Also used : EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Page(io.gravitee.common.data.domain.Page) Promotion(io.gravitee.repository.management.model.Promotion) Test(org.junit.Test)

Example 9 with Promotion

use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method shouldNotProcessPromotionIfNoPermissionForTargetEnvironment.

@Test(expected = ForbiddenAccessException.class)
public void shouldNotProcessPromotionIfNoPermissionForTargetEnvironment() throws Exception {
    when(promotionRepository.findById(any())).thenReturn(Optional.of(getAPromotion()));
    when(environmentService.findByCockpitId(any())).thenReturn(new EnvironmentEntity());
    when(apiService.exists(any())).thenReturn(true);
    Page<Promotion> promotionPage = new Page<>(singletonList(getAPromotion()), 0, 1, 1);
    when(promotionRepository.search(any(), any(), any())).thenReturn(promotionPage);
    when(permissionService.hasPermission(any(), any(), any())).thenReturn(false);
    promotionService.processPromotion(PROMOTION_ID, true, USER_ID);
}
Also used : EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Page(io.gravitee.common.data.domain.Page) Promotion(io.gravitee.repository.management.model.Promotion) Test(org.junit.Test)

Example 10 with Promotion

use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method shouldNotPromoteIfThereIsAlreadyAnInProgressPromotionForTheSameEnv.

@Test(expected = PromotionAlreadyInProgressException.class)
public void shouldNotPromoteIfThereIsAlreadyAnInProgressPromotionForTheSameEnv() throws TechnicalException {
    when(userService.findById(any())).thenReturn(getAUserEntity());
    EnvironmentEntity environmentEntity = new EnvironmentEntity();
    environmentEntity.setCockpitId("env#cockpit-1");
    environmentEntity.setName("Env 1");
    when(environmentService.findById(any())).thenReturn(environmentEntity);
    String targetEnvCockpitId = "env#cockpit-target";
    Promotion promotion = getAPromotion();
    promotion.setApiId("api#1");
    promotion.setStatus(PromotionStatus.TO_BE_VALIDATED);
    promotion.setTargetEnvCockpitId(targetEnvCockpitId);
    Promotion promotion2 = getAPromotion();
    promotion2.setApiId("api#1");
    promotion2.setStatus(PromotionStatus.TO_BE_VALIDATED);
    promotion2.setTargetEnvCockpitId("env#another-env");
    Page<Promotion> promotionPage = new Page<>(List.of(promotion, promotion2), 0, 2, 2);
    when(promotionRepository.search(any(), any(), any())).thenReturn(promotionPage);
    PromotionRequestEntity promotionRequestEntity = getAPromotionRequestEntity();
    promotionRequestEntity.setTargetEnvCockpitId(targetEnvCockpitId);
    promotionService.promote("api#1", promotionRequestEntity, "user#1");
}
Also used : EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Page(io.gravitee.common.data.domain.Page) Promotion(io.gravitee.repository.management.model.Promotion) Test(org.junit.Test)

Aggregations

Promotion (io.gravitee.repository.management.model.Promotion)14 Page (io.gravitee.common.data.domain.Page)9 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)9 Test (org.junit.Test)7 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 CockpitReply (io.gravitee.rest.api.service.cockpit.services.CockpitReply)5 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)4 PromotionAuthor (io.gravitee.repository.management.model.PromotionAuthor)4 Date (java.util.Date)3 PromotionCriteria (io.gravitee.repository.management.api.search.PromotionCriteria)2 SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)2 PromotionRepository (io.gravitee.repository.management.api.PromotionRepository)1 Order (io.gravitee.repository.management.api.search.Order)1 PageableBuilder (io.gravitee.repository.management.api.search.builder.PageableBuilder)1 SortableBuilder (io.gravitee.repository.management.api.search.builder.SortableBuilder)1 PROMOTION_CREATED (io.gravitee.repository.management.model.Promotion.AuditEvent.PROMOTION_CREATED)1 PromotionStatus (io.gravitee.repository.management.model.PromotionStatus)1 UserEntity (io.gravitee.rest.api.model.UserEntity)1 Pageable (io.gravitee.rest.api.model.common.Pageable)1 Sortable (io.gravitee.rest.api.model.common.Sortable)1