use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.
the class PromotionServiceImpl method convert.
private Promotion convert(String apiId, String apiDefinition, EnvironmentEntity source, PromotionRequestEntity target, UserEntity author) {
PromotionAuthor promotionAuthor = new PromotionAuthor();
promotionAuthor.setUserId(author.getId());
promotionAuthor.setDisplayName(author.getDisplayName());
promotionAuthor.setEmail(author.getEmail());
promotionAuthor.setPicture(author.getPicture());
promotionAuthor.setSource(author.getSource());
promotionAuthor.setSourceId(author.getSourceId());
Promotion promotion = new Promotion();
promotion.setCreatedAt(new Date());
promotion.setStatus(PromotionStatus.CREATED);
promotion.setApiDefinition(apiDefinition);
promotion.setApiId(apiId);
promotion.setSourceEnvCockpitId(source.getCockpitId());
promotion.setSourceEnvName(source.getName());
promotion.setTargetEnvCockpitId(target.getTargetEnvCockpitId());
promotion.setTargetEnvName(target.getTargetEnvName());
promotion.setAuthor(promotionAuthor);
return promotion;
}
use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.
the class PromotionServiceImpl method convert.
private Promotion convert(PromotionEntity promotionEntity) {
PromotionAuthor promotionAuthor = new PromotionAuthor();
promotionAuthor.setUserId(promotionEntity.getAuthor().getUserId());
promotionAuthor.setDisplayName(promotionEntity.getAuthor().getDisplayName());
promotionAuthor.setEmail(promotionEntity.getAuthor().getEmail());
promotionAuthor.setPicture(promotionEntity.getAuthor().getPicture());
promotionAuthor.setSource(promotionEntity.getAuthor().getSource());
promotionAuthor.setSourceId(promotionEntity.getAuthor().getSourceId());
Promotion promotion = new Promotion();
promotion.setId(promotionEntity.getId());
promotion.setApiId(promotionEntity.getApiId());
promotion.setCreatedAt(promotionEntity.getCreatedAt());
promotion.setUpdatedAt(promotionEntity.getUpdatedAt());
promotion.setSourceEnvCockpitId(promotionEntity.getSourceEnvCockpitId());
promotion.setSourceEnvName(promotionEntity.getSourceEnvName());
promotion.setTargetEnvCockpitId(promotionEntity.getTargetEnvCockpitId());
promotion.setTargetEnvName(promotionEntity.getTargetEnvName());
promotion.setApiDefinition(promotionEntity.getApiDefinition());
promotion.setStatus(convert(promotionEntity.getStatus()));
promotion.setAuthor(promotionAuthor);
return promotion;
}
use of io.gravitee.repository.management.model.Promotion in project gravitee-management-rest-api by gravitee-io.
the class PromotionServiceTest method getAPromotion.
private Promotion getAPromotion() {
PromotionAuthor promotionAuthor = new PromotionAuthor();
promotionAuthor.setUserId("user#1");
promotionAuthor.setDisplayName("User 1");
promotionAuthor.setEmail("user1@gv.io");
promotionAuthor.setSource("cockpit");
promotionAuthor.setSourceId("user1");
Promotion promotion = new Promotion();
promotion.setCreatedAt(new Date());
promotion.setStatus(PromotionStatus.TO_BE_VALIDATED);
promotion.setApiId("api#1");
promotion.setApiDefinition("apiDefinition");
promotion.setSourceEnvCockpitId("sourceEnvId");
promotion.setSourceEnvName("sourceEnv Name");
promotion.setTargetEnvCockpitId("targetEnvironmentId");
promotion.setTargetEnvName("targetEnv Name");
promotion.setAuthor(promotionAuthor);
return promotion;
}
use of io.gravitee.repository.management.model.Promotion 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.repository.management.model.Promotion 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());
}
Aggregations