Search in sources :

Example 31 with EnvironmentEntity

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

the class IdentityProviderUpgrader method getActivationsTarget.

private ActivationTarget[] getActivationsTarget(int providerIndex) {
    List<String> targetStrings = getListOfString("security.providers[" + providerIndex + "].activations");
    List<ActivationTarget> activationTargets = new ArrayList<>();
    targetStrings.forEach(target -> {
        final String[] orgEnv = target.split(":");
        if (orgEnv.length == 1) {
            try {
                this.organizationService.findById(orgEnv[0]);
                activationTargets.add(new ActivationTarget(orgEnv[0], IdentityProviderActivationReferenceType.ORGANIZATION));
            } catch (OrganizationNotFoundException onfe) {
                logger.warn("Organization {} does not exist", orgEnv[0]);
            }
        } else if (orgEnv.length == 2) {
            try {
                this.organizationService.findById(orgEnv[0]);
                EnvironmentEntity env = this.environmentService.findById(orgEnv[1]);
                if (env.getOrganizationId().equals(orgEnv[0])) {
                    activationTargets.add(new ActivationTarget(orgEnv[1], IdentityProviderActivationReferenceType.ENVIRONMENT));
                } else {
                    logger.warn("Environment {} does not exist in organization {}", orgEnv[1], orgEnv[0]);
                }
            } catch (OrganizationNotFoundException onfe) {
                logger.warn("Organization {} does not exist", orgEnv[0]);
            } catch (EnvironmentNotFoundException Enfe) {
                logger.warn("Environment {} does not exist", orgEnv[1]);
            }
        }
    });
    return activationTargets.toArray(new ActivationTarget[activationTargets.size()]);
}
Also used : ActivationTarget(io.gravitee.rest.api.service.configuration.identity.IdentityProviderActivationService.ActivationTarget) OrganizationNotFoundException(io.gravitee.rest.api.service.exceptions.OrganizationNotFoundException) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) EnvironmentNotFoundException(io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException)

Example 32 with EnvironmentEntity

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

the class ParameterServiceTest method shouldFindAsBooleanDefaultValue.

@Test
public void shouldFindAsBooleanDefaultValue() throws TechnicalException {
    when(parameterRepository.findById(PORTAL_USERCREATION_ENABLED.key(), "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(empty());
    when(parameterRepository.findById(PORTAL_USERCREATION_ENABLED.key(), "DEFAULT_ORG", ParameterReferenceType.ORGANIZATION)).thenReturn(empty());
    EnvironmentEntity defaultEnv = new EnvironmentEntity();
    defaultEnv.setOrganizationId("DEFAULT_ORG");
    when(environmentService.findById("DEFAULT")).thenReturn(defaultEnv);
    assertTrue(parameterService.findAsBoolean(PORTAL_USERCREATION_ENABLED, io.gravitee.rest.api.model.parameters.ParameterReferenceType.ENVIRONMENT));
}
Also used : EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Test(org.junit.Test)

Example 33 with EnvironmentEntity

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

the class CategoryService_CreateTest method shouldCreateCategory.

@Test
public void shouldCreateCategory() throws TechnicalException {
    NewCategoryEntity v1 = new NewCategoryEntity();
    v1.setName("v1");
    when(mockCategoryRepository.create(argThat(cat -> cat.getCreatedAt() != null))).thenReturn(new Category());
    when(mockEnvironmentService.findById("DEFAULT")).thenReturn(new EnvironmentEntity());
    CategoryEntity category = categoryService.create(v1);
    assertNotNull("result is null", category);
    verify(mockAuditService, times(1)).createEnvironmentAuditLog(any(), eq(CATEGORY_CREATED), any(), isNull(), any());
    verify(mockCategoryRepository, times(1)).create(argThat(arg -> arg != null && arg.getName().equals("v1")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) NewCategoryEntity(io.gravitee.rest.api.model.NewCategoryEntity) InjectMocks(org.mockito.InjectMocks) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) Assert.assertNotNull(org.junit.Assert.assertNotNull) CategoryServiceImpl(io.gravitee.rest.api.service.impl.CategoryServiceImpl) Mock(org.mockito.Mock) CATEGORY_CREATED(io.gravitee.repository.management.model.Category.AuditEvent.CATEGORY_CREATED) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) AuditService(io.gravitee.rest.api.service.AuditService) Test(org.junit.Test) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) Mockito(org.mockito.Mockito) Category(io.gravitee.repository.management.model.Category) CategoryRepository(io.gravitee.repository.management.api.CategoryRepository) EnvironmentNotFoundException(io.gravitee.rest.api.service.exceptions.EnvironmentNotFoundException) DuplicateCategoryNameException(io.gravitee.rest.api.service.exceptions.DuplicateCategoryNameException) Assert(org.junit.Assert) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Category(io.gravitee.repository.management.model.Category) EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) NewCategoryEntity(io.gravitee.rest.api.model.NewCategoryEntity) NewCategoryEntity(io.gravitee.rest.api.model.NewCategoryEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) 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