use of io.gravitee.cockpit.api.command.bridge.BridgePayload in project gravitee-management-rest-api by gravitee-io.
the class BridgeCommandFactory method createProcessPromotionCommand.
public BridgeCommand createProcessPromotionCommand(String sourceEnvCockpitId, String serializedPromotion) {
BridgeCommand processPromotionCommand = initBridgeCommand();
processPromotionCommand.setOperation(BridgeOperation.PROCESS_API_PROMOTION.name());
BridgePayload payload = new BridgePayload();
payload.setContent(serializedPromotion);
processPromotionCommand.setPayload(payload);
BridgeTarget target = new BridgeTarget();
target.setScopes(Collections.singletonList(BRIDGE_SCOPE_APIM));
target.setEnvironmentId(sourceEnvCockpitId);
processPromotionCommand.setTarget(target);
return processPromotionCommand;
}
use of io.gravitee.cockpit.api.command.bridge.BridgePayload 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));
});
}
use of io.gravitee.cockpit.api.command.bridge.BridgePayload in project gravitee-management-rest-api by gravitee-io.
the class ProcessPromotionOperationHandlerTest method shouldHandlePromotionRequestIfCannotWritePayload.
@Test
public void shouldHandlePromotionRequestIfCannotWritePayload() 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);
when(objectMapper.readValue(command.getPayload().getContent(), PromotionEntity.class)).thenReturn(getAPromotionEntity());
InstallationEntity installationEntity = new InstallationEntity();
installationEntity.setId(INSTALLATION_ID);
when(installationService.get()).thenReturn(installationEntity);
when(objectMapper.writeValueAsString(any())).thenThrow(JsonProcessingException.class);
when(promotionService.createOrUpdate(any())).thenReturn(getAPromotionEntity());
// When
TestObserver<BridgeReply> obs = cut.handle(command).test();
// Then
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR) && reply.getMessage().equals("Problem while serializing promotion for environment [" + ENVIRONMENT_ID + "]"));
}
use of io.gravitee.cockpit.api.command.bridge.BridgePayload 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));
});
}
Aggregations