Search in sources :

Example 11 with PromotionEntity

use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.

the class PromoteApiOperationHandlerTest method shouldHandlePromotionRequest.

@Test
public void shouldHandlePromotionRequest() throws JsonProcessingException {
    BridgeCommand command = new BridgeCommand();
    command.setOperation(BridgeOperation.PROMOTE_API.name());
    command.setId(COMMAND_ID);
    command.setInstallationId(INSTALLATION_ID);
    command.setOrganizationId(ORGANIZATION_ID);
    command.setEnvironmentId(ENVIRONMENT_ID);
    command.setPayload(new BridgePayload());
    final BridgeTarget bridgeTarget = new BridgeTarget();
    bridgeTarget.setEnvironmentId("target");
    command.setTarget(bridgeTarget);
    ArgumentCaptor<PromotionEntity> argument = ArgumentCaptor.forClass(PromotionEntity.class);
    when(objectMapper.readValue(command.getPayload().getContent(), PromotionEntity.class)).thenReturn(getAPromotionEntity());
    InstallationEntity installationEntity = new InstallationEntity();
    installationEntity.setId(INSTALLATION_ID);
    when(installationService.get()).thenReturn(installationEntity);
    TestObserver<BridgeReply> obs = cut.handle(command).test();
    verify(promotionService, times(1)).createOrUpdate(argument.capture());
    Assertions.assertThat(argument.getValue().getStatus()).isEqualTo(PromotionEntityStatus.TO_BE_VALIDATED);
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> {
        BridgeSimpleReply simpleReply = (BridgeSimpleReply) reply;
        return (simpleReply.getCommandStatus().equals(CommandStatus.SUCCEEDED) && simpleReply.getOrganizationId().equals(ORGANIZATION_ID) && simpleReply.getEnvironmentId().equals("target") && simpleReply.getInstallationId().equals(INSTALLATION_ID) && simpleReply.getCommandId().equals(COMMAND_ID));
    });
}
Also used : BridgePayload(io.gravitee.cockpit.api.command.bridge.BridgePayload) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) BridgeTarget(io.gravitee.cockpit.api.command.bridge.BridgeTarget) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 12 with PromotionEntity

use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.

the class GoodbyeCommandHandlerTest method handleRejectAllPromotionToValidate.

@Test
public void handleRejectAllPromotionToValidate() {
    final InstallationEntity installation = new InstallationEntity();
    installation.setId(INSTALLATION_ID);
    installation.getAdditionalInformation().put(CUSTOM_KEY, CUSTOM_VALUE);
    GoodbyeCommand command = new GoodbyeCommand();
    when(installationService.getOrInitialize()).thenReturn(installation);
    PromotionEntity promotionEntity1 = getAPromotionEntity("promotion#1");
    PromotionEntity promotionEntity2 = getAPromotionEntity("promotion#2");
    when(promotionService.search(any(), any(), any())).thenReturn(new Page<>(List.of(promotionEntity1, promotionEntity2), 0, 0, 0));
    TestObserver<GoodbyeReply> obs = cut.handle(command).test();
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
    ArgumentCaptor<PromotionEntity> captor = ArgumentCaptor.forClass(PromotionEntity.class);
    verify(promotionService, times(2)).createOrUpdate(captor.capture());
    assertThat(captor.getAllValues()).extracting(PromotionEntity::getId, PromotionEntity::getStatus).containsExactlyInAnyOrder(tuple(promotionEntity1.getId(), PromotionEntityStatus.REJECTED), tuple(promotionEntity2.getId(), PromotionEntityStatus.REJECTED));
}
Also used : GoodbyeCommand(io.gravitee.cockpit.api.command.goodbye.GoodbyeCommand) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) GoodbyeReply(io.gravitee.cockpit.api.command.goodbye.GoodbyeReply) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) Test(org.junit.Test)

Example 13 with PromotionEntity

use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.

the class ProcessPromotionOperationHandlerTest method shouldHandlePromotionRequest.

@Test
public void shouldHandlePromotionRequest() throws JsonProcessingException {
    BridgeCommand command = new BridgeCommand();
    command.setOperation(BridgeOperation.PROMOTE_API.name());
    command.setId(COMMAND_ID);
    command.setInstallationId(INSTALLATION_ID);
    command.setOrganizationId(ORGANIZATION_ID);
    command.setEnvironmentId(ENVIRONMENT_ID);
    command.setPayload(new BridgePayload());
    final BridgeTarget bridgeTarget = new BridgeTarget();
    bridgeTarget.setEnvironmentId("source");
    command.setTarget(bridgeTarget);
    ArgumentCaptor<PromotionEntity> argument = ArgumentCaptor.forClass(PromotionEntity.class);
    when(objectMapper.readValue(command.getPayload().getContent(), PromotionEntity.class)).thenReturn(getAPromotionEntity());
    InstallationEntity installationEntity = new InstallationEntity();
    installationEntity.setId(INSTALLATION_ID);
    when(installationService.get()).thenReturn(installationEntity);
    TestObserver<BridgeReply> obs = cut.handle(command).test();
    verify(promotionService, times(1)).createOrUpdate(argument.capture());
    Assertions.assertThat(argument.getValue().getStatus()).isEqualTo(PromotionEntityStatus.ACCEPTED);
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> {
        BridgeSimpleReply simpleReply = (BridgeSimpleReply) reply;
        return (simpleReply.getCommandStatus().equals(CommandStatus.SUCCEEDED) && simpleReply.getOrganizationId().equals(ORGANIZATION_ID) && simpleReply.getEnvironmentId().equals("source") && simpleReply.getInstallationId().equals(INSTALLATION_ID) && simpleReply.getCommandId().equals(COMMAND_ID));
    });
}
Also used : BridgePayload(io.gravitee.cockpit.api.command.bridge.BridgePayload) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) BridgeTarget(io.gravitee.cockpit.api.command.bridge.BridgeTarget) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 14 with PromotionEntity

use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.

the class ProcessPromotionOperationHandlerTest method getAPromotionEntity.

private PromotionEntity getAPromotionEntity() {
    final PromotionEntity promotionEntity = new PromotionEntity();
    promotionEntity.setSourceEnvCockpitId("sourceEnvId");
    promotionEntity.setTargetEnvCockpitId("targetEnvId");
    promotionEntity.setApiDefinition("definition");
    promotionEntity.setStatus(PromotionEntityStatus.ACCEPTED);
    return promotionEntity;
}
Also used : PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity)

Example 15 with PromotionEntity

use of io.gravitee.rest.api.model.promotion.PromotionEntity in project gravitee-management-rest-api by gravitee-io.

the class CockpitServiceTest method shouldProcessPromotion.

@Test
public void shouldProcessPromotion() {
    BridgeReply reply = new BridgeSimpleReply();
    reply.setCommandStatus(CommandStatus.SUCCEEDED);
    when(cockpitCommandService.send(any())).thenReturn(reply);
    final PromotionEntity promotionEntity = new PromotionEntity();
    final CockpitReply<PromotionEntity> result = cockpitService.processPromotion(promotionEntity);
    assertThat(result).isNotNull();
    assertThat(result.getStatus()).isEqualTo(CockpitReplyStatus.SUCCEEDED);
    final PromotionEntity entity = result.getReply();
    assertThat(entity).isNotNull();
}
Also used : BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) PromotionEntity(io.gravitee.rest.api.model.promotion.PromotionEntity) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Aggregations

PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)18 Test (org.junit.Test)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)7 BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)6 PromotionEntityAuthor (io.gravitee.rest.api.model.promotion.PromotionEntityAuthor)6 PromotionEntityStatus (io.gravitee.rest.api.model.promotion.PromotionEntityStatus)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Page (io.gravitee.common.data.domain.Page)5 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)5 TaskEntity (io.gravitee.rest.api.model.TaskEntity)5 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 CREATE (io.gravitee.rest.api.model.permissions.RolePermissionAction.CREATE)5 UPDATE (io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE)5 ApiService (io.gravitee.rest.api.service.ApiService)5 EnvironmentService (io.gravitee.rest.api.service.EnvironmentService)5 PermissionService (io.gravitee.rest.api.service.PermissionService)5 PromotionService (io.gravitee.rest.api.service.promotion.PromotionService)5 PromotionTasksService (io.gravitee.rest.api.service.promotion.PromotionTasksService)5 java.util (java.util)5 Collections.emptyList (java.util.Collections.emptyList)5