Search in sources :

Example 1 with InstallationEntity

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

the class InstallationCommandHandlerTest method handle.

@Test
public void handle() {
    final InstallationEntity installation = new InstallationEntity();
    installation.setId(INSTALLATION_ID);
    installation.getAdditionalInformation().put(CUSTOM_KEY, CUSTOM_VALUE);
    InstallationPayload installationPayload = new InstallationPayload();
    InstallationCommand command = new InstallationCommand(installationPayload);
    installationPayload.setId(INSTALLATION_ID);
    installationPayload.setStatus("ACCEPTED");
    when(installationService.getOrInitialize()).thenReturn(installation);
    TestObserver<InstallationReply> obs = cut.handle(command).test();
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
    final HashMap<String, String> expectedAdditionalInfos = new HashMap<>();
    expectedAdditionalInfos.put(CUSTOM_KEY, CUSTOM_VALUE);
    expectedAdditionalInfos.put(InstallationService.COCKPIT_INSTALLATION_STATUS, "ACCEPTED");
    verify(installationService, times(1)).setAdditionalInformation(expectedAdditionalInfos);
}
Also used : InstallationCommand(io.gravitee.cockpit.api.command.installation.InstallationCommand) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) HashMap(java.util.HashMap) InstallationPayload(io.gravitee.cockpit.api.command.installation.InstallationPayload) InstallationReply(io.gravitee.cockpit.api.command.installation.InstallationReply) Test(org.junit.Test)

Example 2 with InstallationEntity

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

the class ListEnvironmentOperationHandlerTest method shouldListEnvironments.

@Test
public void shouldListEnvironments() throws JsonProcessingException {
    // Given
    EnvironmentEntity envA = new EnvironmentEntity();
    envA.setId("my-env-A");
    envA.setOrganizationId(ORGANIZATION_ID);
    envA.setName("ENV A");
    EnvironmentEntity envB = new EnvironmentEntity();
    envB.setId("my-env-B");
    envB.setOrganizationId(ORGANIZATION_ID);
    envB.setName("ENV B");
    EnvironmentEntity envC_ERROR = new EnvironmentEntity();
    envC_ERROR.setId("my-env-C");
    envC_ERROR.setOrganizationId(ORGANIZATION_ID);
    envC_ERROR.setName("ENV C");
    when(environmentService.findByOrganization(ORGANIZATION_ID)).thenReturn(Arrays.asList(envA, envB, envC_ERROR));
    when(objectMapper.writeValueAsString(envA)).thenReturn("envA");
    when(objectMapper.writeValueAsString(envB)).thenReturn("envB");
    when(objectMapper.writeValueAsString(envC_ERROR)).thenThrow(new JsonProcessingException("") {
    });
    InstallationEntity installationEntity = new InstallationEntity();
    installationEntity.setId(INSTALLATION_ID);
    when(installationService.get()).thenReturn(installationEntity);
    BridgeCommand command = new BridgeCommand();
    command.setOperation(BridgeOperation.LIST_ENVIRONMENT.name());
    command.setId(COMMAND_ID);
    command.setInstallationId(INSTALLATION_ID);
    command.setOrganizationId(ORGANIZATION_ID);
    command.setEnvironmentId(ENVIRONMENT_ID);
    // When
    TestObserver<BridgeReply> obs = cut.handle(command).test();
    // Then
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> {
        if (reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED) && BridgeMultiReply.class.isInstance(reply)) {
            BridgeMultiReply multiReply = ((BridgeMultiReply) reply);
            if (multiReply.getReplies() != null && multiReply.getReplies().size() == 3) {
                for (BridgeSimpleReply simpleReply : multiReply.getReplies()) {
                    if (simpleReply.getEnvironmentId().equals(envA.getId()) && simpleReply.getCommandStatus() == CommandStatus.ERROR) {
                        return false;
                    }
                    if (simpleReply.getEnvironmentId().equals(envB.getId()) && simpleReply.getCommandStatus() == CommandStatus.ERROR) {
                        return false;
                    }
                    if (simpleReply.getEnvironmentId().equals(envC_ERROR.getId()) && simpleReply.getCommandStatus() == CommandStatus.SUCCEEDED) {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    });
}
Also used : BridgeMultiReply(io.gravitee.cockpit.api.command.bridge.BridgeMultiReply) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) BridgeSimpleReply(io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 3 with InstallationEntity

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

the class PromoteApiOperationHandlerTest 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("target");
    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 request for environment [" + ENVIRONMENT_ID + "]"));
}
Also used : BridgePayload(io.gravitee.cockpit.api.command.bridge.BridgePayload) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) BridgeTarget(io.gravitee.cockpit.api.command.bridge.BridgeTarget) BridgeCommand(io.gravitee.cockpit.api.command.bridge.BridgeCommand) BridgeReply(io.gravitee.cockpit.api.command.bridge.BridgeReply) Test(org.junit.Test)

Example 4 with InstallationEntity

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

the class GoodbyeCommandHandlerTest method handleWithException.

@Test
public void handleWithException() {
    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);
    when(installationService.setAdditionalInformation(anyMap())).thenThrow(new TechnicalManagementException());
    when(promotionService.search(any(), any(), any())).thenReturn(new Page<>(emptyList(), 0, 0, 0));
    TestObserver<GoodbyeReply> obs = cut.handle(command).test();
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR));
}
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) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) Test(org.junit.Test)

Example 5 with InstallationEntity

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

the class BridgeCommandFactoryTest method setup.

@Before
public void setup() {
    InstallationEntity installationEntity = new InstallationEntity();
    installationEntity.setId(INSTALLATION_ID);
    when(installationService.get()).thenReturn(installationEntity);
    bridgeCommandFactory = new BridgeCommandFactory(installationService);
    GraviteeContext.setCurrentOrganization(ORGANIZATION_ID);
    GraviteeContext.setCurrentEnvironment(ENVIRONMENT_ID);
}
Also used : InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) Before(org.junit.Before)

Aggregations

InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)19 Test (org.junit.Test)15 BridgeCommand (io.gravitee.cockpit.api.command.bridge.BridgeCommand)5 BridgeReply (io.gravitee.cockpit.api.command.bridge.BridgeReply)5 BridgePayload (io.gravitee.cockpit.api.command.bridge.BridgePayload)4 BridgeTarget (io.gravitee.cockpit.api.command.bridge.BridgeTarget)4 BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)3 GoodbyeCommand (io.gravitee.cockpit.api.command.goodbye.GoodbyeCommand)3 GoodbyeReply (io.gravitee.cockpit.api.command.goodbye.GoodbyeReply)3 PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)3 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 InstallationCommand (io.gravitee.cockpit.api.command.installation.InstallationCommand)2 InstallationPayload (io.gravitee.cockpit.api.command.installation.InstallationPayload)2 InstallationReply (io.gravitee.cockpit.api.command.installation.InstallationReply)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BridgeMultiReply (io.gravitee.cockpit.api.command.bridge.BridgeMultiReply)1 HelloCommand (io.gravitee.cockpit.api.command.hello.HelloCommand)1 HelloPayload (io.gravitee.cockpit.api.command.hello.HelloPayload)1