Search in sources :

Example 1 with CockpitReply

use of io.gravitee.rest.api.service.cockpit.services.CockpitReply in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceImpl method listPromotionTargets.

@Override
public List<PromotionTargetEntity> listPromotionTargets(String organizationId, String environmentId) {
    EnvironmentEntity environmentEntity = environmentService.findById(environmentId);
    final CockpitReply<List<PromotionTargetEntity>> listCockpitReply = this.cockpitService.listPromotionTargets(organizationId);
    if (listCockpitReply.getStatus() == CockpitReplyStatus.SUCCEEDED) {
        return listCockpitReply.getReply().stream().filter(target -> !target.getId().equals(environmentEntity.getCockpitId())).collect(Collectors.toList());
    }
    throw new BridgeOperationException(BridgeOperation.LIST_ENVIRONMENT);
}
Also used : PROMOTION_CREATED(io.gravitee.repository.management.model.Promotion.AuditEvent.PROMOTION_CREATED) io.gravitee.rest.api.service(io.gravitee.rest.api.service) CockpitService(io.gravitee.rest.api.service.cockpit.services.CockpitService) Pageable(io.gravitee.rest.api.model.common.Pageable) Date(java.util.Date) Page(io.gravitee.common.data.domain.Page) Sortable(io.gravitee.rest.api.model.common.Sortable) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Order(io.gravitee.repository.management.api.search.Order) CockpitReplyStatus(io.gravitee.rest.api.service.cockpit.services.CockpitReplyStatus) LoggerFactory(org.slf4j.LoggerFactory) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) UPDATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE) Collections.singletonList(java.util.Collections.singletonList) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) AbstractService(io.gravitee.rest.api.service.impl.AbstractService) PromotionCriteria(io.gravitee.repository.management.api.search.PromotionCriteria) Collections.emptyMap(java.util.Collections.emptyMap) UuidString(io.gravitee.rest.api.service.common.UuidString) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Logger(org.slf4j.Logger) ENVIRONMENT_API(io.gravitee.rest.api.model.permissions.RolePermission.ENVIRONMENT_API) Promotion(io.gravitee.repository.management.model.Promotion) BridgeOperation(io.gravitee.rest.api.service.cockpit.command.bridge.operation.BridgeOperation) CockpitReply(io.gravitee.rest.api.service.cockpit.services.CockpitReply) PromotionService(io.gravitee.rest.api.service.promotion.PromotionService) Collectors(java.util.stream.Collectors) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) io.gravitee.rest.api.model.promotion(io.gravitee.rest.api.model.promotion) List(java.util.List) Component(org.springframework.stereotype.Component) PromotionStatus(io.gravitee.repository.management.model.PromotionStatus) SortableBuilder(io.gravitee.repository.management.api.search.builder.SortableBuilder) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) CollectionUtils(org.springframework.util.CollectionUtils) CREATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.CREATE) PromotionRepository(io.gravitee.repository.management.api.PromotionRepository) Optional(java.util.Optional) PromotionAuthor(io.gravitee.repository.management.model.PromotionAuthor) ApiSerializer(io.gravitee.rest.api.service.jackson.ser.api.ApiSerializer) Collections(java.util.Collections) UserEntity(io.gravitee.rest.api.model.UserEntity) StringUtils(org.springframework.util.StringUtils) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List)

Example 2 with CockpitReply

use of io.gravitee.rest.api.service.cockpit.services.CockpitReply in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method shouldProcessRejectedPromotion.

@Test
public void shouldProcessRejectedPromotion() throws Exception {
    when(promotionRepository.findById(any())).thenReturn(Optional.of(getAPromotion()));
    when(environmentService.findByCockpitId(any())).thenReturn(new EnvironmentEntity());
    Page<Promotion> promotionPage = new Page<>(singletonList(getAPromotion()), 0, 1, 1);
    when(promotionRepository.search(any(), any(), any())).thenReturn(promotionPage);
    CockpitReply<PromotionEntity> cockpitReply = new CockpitReply<>(null, CockpitReplyStatus.SUCCEEDED);
    when(cockpitService.processPromotion(any())).thenReturn(cockpitReply);
    when(promotionRepository.update(any())).thenReturn(getAPromotion());
    promotionService.processPromotion(PROMOTION_ID, false, USER_ID);
    verify(apiDuplicatorService, never()).createWithImportedDefinition(any(), eq(USER_ID), any(), any());
    verify(apiDuplicatorService, never()).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) Page(io.gravitee.common.data.domain.Page) Promotion(io.gravitee.repository.management.model.Promotion) Test(org.junit.Test)

Example 3 with CockpitReply

use of io.gravitee.rest.api.service.cockpit.services.CockpitReply in project gravitee-management-rest-api by gravitee-io.

the class PromotionServiceTest method shouldProcessAcceptedPromotionCreateApi.

@Test
public void shouldProcessAcceptedPromotionCreateApi() 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<>(emptyList(), 0, 1, 1);
    when(promotionRepository.search(any(), any(), any())).thenReturn(promotionPage);
    when(apiDuplicatorService.createWithImportedDefinition(any(), any(), any(), any())).thenReturn(new ApiEntity());
    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)).createWithImportedDefinition(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 4 with CockpitReply

use of io.gravitee.rest.api.service.cockpit.services.CockpitReply 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 5 with CockpitReply

use of io.gravitee.rest.api.service.cockpit.services.CockpitReply 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)

Aggregations

Page (io.gravitee.common.data.domain.Page)6 Promotion (io.gravitee.repository.management.model.Promotion)6 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)6 CockpitReply (io.gravitee.rest.api.service.cockpit.services.CockpitReply)6 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 Test (org.junit.Test)4 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 PromotionRepository (io.gravitee.repository.management.api.PromotionRepository)2 Order (io.gravitee.repository.management.api.search.Order)2 PromotionCriteria (io.gravitee.repository.management.api.search.PromotionCriteria)2 PageableBuilder (io.gravitee.repository.management.api.search.builder.PageableBuilder)2 SortableBuilder (io.gravitee.repository.management.api.search.builder.SortableBuilder)2 PROMOTION_CREATED (io.gravitee.repository.management.model.Promotion.AuditEvent.PROMOTION_CREATED)2 PromotionAuthor (io.gravitee.repository.management.model.PromotionAuthor)2 PromotionStatus (io.gravitee.repository.management.model.PromotionStatus)2 UserEntity (io.gravitee.rest.api.model.UserEntity)2 Pageable (io.gravitee.rest.api.model.common.Pageable)2 Sortable (io.gravitee.rest.api.model.common.Sortable)2 SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)2 ENVIRONMENT_API (io.gravitee.rest.api.model.permissions.RolePermission.ENVIRONMENT_API)2