Search in sources :

Example 6 with EnvironmentEntity

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

the class EnvironmentCommandHandlerTest method handle.

@Test
public void handle() {
    EnvironmentPayload environmentPayload = new EnvironmentPayload();
    EnvironmentCommand command = new EnvironmentCommand(environmentPayload);
    environmentPayload.setId("env#1");
    environmentPayload.setCockpitId("env#cockpit-1");
    environmentPayload.setHrids(Collections.singletonList("env-1"));
    environmentPayload.setOrganizationId("orga#1");
    environmentPayload.setDescription("Environment description");
    environmentPayload.setName("Environment name");
    environmentPayload.setDomainRestrictions(Arrays.asList("domain.restriction1.io", "domain.restriction2.io"));
    when(environmentService.createOrUpdate(eq("orga#1"), eq("env#1"), argThat(newEnvironment -> newEnvironment.getCockpitId().equals(environmentPayload.getCockpitId()) && newEnvironment.getHrids().equals(environmentPayload.getHrids()) && newEnvironment.getDescription().equals(environmentPayload.getDescription()) && newEnvironment.getName().equals(environmentPayload.getName()) && newEnvironment.getDomainRestrictions().equals(environmentPayload.getDomainRestrictions())))).thenReturn(new EnvironmentEntity());
    TestObserver<EnvironmentReply> obs = cut.handle(command).test();
    obs.awaitTerminalEvent();
    obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
}
Also used : EnvironmentCommand(io.gravitee.cockpit.api.command.environment.EnvironmentCommand) Arrays(java.util.Arrays) ArgumentMatchers(org.mockito.ArgumentMatchers) UpdateEnvironmentEntity(io.gravitee.rest.api.model.UpdateEnvironmentEntity) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) EnvironmentPayload(io.gravitee.cockpit.api.command.environment.EnvironmentPayload) Command(io.gravitee.cockpit.api.command.Command) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) EnvironmentReply(io.gravitee.cockpit.api.command.environment.EnvironmentReply) CommandStatus(io.gravitee.cockpit.api.command.CommandStatus) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) EnvironmentCommand(io.gravitee.cockpit.api.command.environment.EnvironmentCommand) EnvironmentReply(io.gravitee.cockpit.api.command.environment.EnvironmentReply) UpdateEnvironmentEntity(io.gravitee.rest.api.model.UpdateEnvironmentEntity) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) EnvironmentPayload(io.gravitee.cockpit.api.command.environment.EnvironmentPayload) Test(org.junit.Test)

Example 7 with EnvironmentEntity

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

the class HelloCommandProducerTest method handleReplay_shouldUpdateDefaultEnvironmentCockpitId.

@Test
public void handleReplay_shouldUpdateDefaultEnvironmentCockpitId() {
    HelloReply helloReply = new HelloReply();
    helloReply.setCommandStatus(CommandStatus.SUCCEEDED);
    helloReply.setDefaultEnvironmentCockpitId("env#cockpit-1");
    String defaultEnvId = "DEFAULT";
    EnvironmentEntity defaultEnvironment = new EnvironmentEntity();
    defaultEnvironment.setId(defaultEnvId);
    defaultEnvironment.setOrganizationId("org#1");
    when(environmentService.findById(defaultEnvId)).thenReturn(defaultEnvironment);
    cut.handleReply(helloReply);
    verify(environmentService).createOrUpdate(eq(defaultEnvironment.getOrganizationId()), eq(defaultEnvId), argThat(env -> env.getCockpitId().equals("env#cockpit-1")));
}
Also used : ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) Command(io.gravitee.cockpit.api.command.Command) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) Before(org.junit.Before) Node(io.gravitee.node.api.Node) OrganizationEntity(io.gravitee.rest.api.model.OrganizationEntity) HelloReply(io.gravitee.cockpit.api.command.hello.HelloReply) InstallationService(io.gravitee.rest.api.service.InstallationService) Assert.assertTrue(org.junit.Assert.assertTrue) EnvironmentService(io.gravitee.rest.api.service.EnvironmentService) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) OrganizationService(io.gravitee.rest.api.service.OrganizationService) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Mockito.verify(org.mockito.Mockito.verify) HelloPayload(io.gravitee.cockpit.api.command.hello.HelloPayload) CommandStatus(io.gravitee.cockpit.api.command.CommandStatus) HelloCommand(io.gravitee.cockpit.api.command.hello.HelloCommand) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) HelloReply(io.gravitee.cockpit.api.command.hello.HelloReply) Test(org.junit.Test)

Example 8 with EnvironmentEntity

use of io.gravitee.rest.api.model.EnvironmentEntity 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 9 with EnvironmentEntity

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

the class PromotionTasksServiceImplTest method getAnEnvironmentEntity.

private EnvironmentEntity getAnEnvironmentEntity() {
    final EnvironmentEntity environmentEntity = new EnvironmentEntity();
    environmentEntity.setId("env#1");
    environmentEntity.setCockpitId("env#1-cockpit-id");
    environmentEntity.setName("Env 1");
    return environmentEntity;
}
Also used : EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity)

Example 10 with EnvironmentEntity

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

the class VirtualHostServiceTest method validate_hostSubDomainOfOneOfDomainConstraints.

@Test
public void validate_hostSubDomainOfOneOfDomainConstraints() {
    VirtualHost vhost = getValidVirtualHost();
    String domainConstraint = vhost.getHost();
    vhost.setHost("level2.level1." + domainConstraint);
    EnvironmentEntity environmentEntity = new EnvironmentEntity();
    environmentEntity.setDomainRestrictions(Arrays.asList("test.gravitee.io", "other.gravitee.io", domainConstraint));
    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)

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