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());
}
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());
}
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());
}
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);
}
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");
}
Aggregations