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