Search in sources :

Example 11 with EnvironmentEntity

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));
}
Also used : EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) VirtualHost(io.gravitee.definition.model.VirtualHost) Test(org.junit.Test)

Example 12 with EnvironmentEntity

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);
}
Also used : EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Test(org.junit.Test)

Example 13 with EnvironmentEntity

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());
}
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 14 with EnvironmentEntity

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());
}
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 15 with EnvironmentEntity

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

EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)33 Test (org.junit.Test)21 Page (io.gravitee.common.data.domain.Page)10 Promotion (io.gravitee.repository.management.model.Promotion)10 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)8 VirtualHost (io.gravitee.definition.model.VirtualHost)6 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)6 CockpitReply (io.gravitee.rest.api.service.cockpit.services.CockpitReply)6 List (java.util.List)6 Collections (java.util.Collections)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 BridgeMultiReply (io.gravitee.cockpit.api.command.bridge.BridgeMultiReply)4 UpdateEnvironmentEntity (io.gravitee.rest.api.model.UpdateEnvironmentEntity)4 RunWith (org.junit.runner.RunWith)4 Mock (org.mockito.Mock)4 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)4 CommandStatus (io.gravitee.cockpit.api.command.CommandStatus)3 BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)3 SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)3 Arrays (java.util.Arrays)3