use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method validate_hostEqualsToDomainConstraint.
@Test
public void validate_hostEqualsToDomainConstraint() {
VirtualHost vhost = getValidVirtualHost();
EnvironmentEntity environmentEntity = new EnvironmentEntity();
environmentEntity.setDomainRestrictions(Collections.singletonList(vhost.getHost()));
when(environmentService.findById(any())).thenReturn(environmentEntity);
virtualHostService.sanitizeAndValidate(Collections.singletonList(vhost));
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class PromotionServiceTest method shouldListPromotionTargets.
@Test
public void shouldListPromotionTargets() {
// Given
PromotionTargetEntity envA = new PromotionTargetEntity();
envA.setId("my-env-A");
envA.setHrids(Collections.singletonList("my-env-A"));
envA.setOrganizationId(ORGANIZATION_ID);
envA.setName("ENV A");
envA.setInstallationId(INSTALLATION_ID);
PromotionTargetEntity envB = new PromotionTargetEntity();
envB.setId("my-env-B");
envB.setHrids(Collections.singletonList("my-env-B"));
envB.setOrganizationId(ORGANIZATION_ID);
envB.setName("ENV B");
envB.setInstallationId(INSTALLATION_ID);
PromotionTargetEntity currentEnv = new PromotionTargetEntity();
currentEnv.setId(ENVIRONMENT_ID);
currentEnv.setHrids(Collections.singletonList(ENVIRONMENT_ID));
currentEnv.setOrganizationId(ORGANIZATION_ID);
currentEnv.setName("My Environment");
currentEnv.setInstallationId(INSTALLATION_ID);
when(cockpitService.listPromotionTargets(ORGANIZATION_ID)).thenReturn(new CockpitReply<>(Arrays.asList(envA, envB, currentEnv), CockpitReplyStatus.SUCCEEDED));
EnvironmentEntity environmentEntity = new EnvironmentEntity();
environmentEntity.setId(ENVIRONMENT_ID);
environmentEntity.setCockpitId(ENVIRONMENT_ID);
environmentEntity.setHrids(Collections.singletonList(ENVIRONMENT_ID));
when(environmentService.findById(ENVIRONMENT_ID)).thenReturn(environmentEntity);
final List<PromotionTargetEntity> promotionTargetEntities = promotionService.listPromotionTargets(ORGANIZATION_ID, ENVIRONMENT_ID);
assertThat(promotionTargetEntities).isNotNull();
assertThat(promotionTargetEntities).hasSize(2);
}
use of io.gravitee.rest.api.model.EnvironmentEntity 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.model.EnvironmentEntity 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.model.EnvironmentEntity 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());
}
Aggregations