Search in sources :

Example 1 with PortalSettingsEntity

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

the class ConfigurationMapperTest method testConvert.

@Test
public void testConvert() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    PortalSettingsEntity portalSettingsEntity = mapper.readValue(this.getClass().getResourceAsStream("portalSettingsEntity.json"), PortalSettingsEntity.class);
    ConsoleSettingsEntity consoleSettingsEntity = mapper.readValue(this.getClass().getResourceAsStream("consoleSettingsEntity.json"), ConsoleSettingsEntity.class);
    String expected = IOUtils.toString(this.getClass().getResourceAsStream("expectedPortalConfiguration.json"), "UTF-8");
    ConfigurationMapper configurationMapper = new ConfigurationMapper();
    ConfigurationResponse configuration = configurationMapper.convert(portalSettingsEntity, consoleSettingsEntity);
    mapper.setSerializationInclusion(Include.NON_NULL);
    mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
    String configurationAsJSON = mapper.writeValueAsString(configuration);
    assertEquals(expected.trim(), configurationAsJSON.trim());
}
Also used : PortalSettingsEntity(io.gravitee.rest.api.model.settings.PortalSettingsEntity) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) ConfigurationResponse(io.gravitee.rest.api.portal.rest.model.ConfigurationResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with PortalSettingsEntity

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

the class ConfigServiceTest method shouldGetPortalSettingsFromEnvVar.

@Test
public void shouldGetPortalSettingsFromEnvVar() {
    Map<String, List<String>> params = new HashMap<>();
    params.put(Key.PORTAL_AUTHENTICATION_FORCELOGIN_ENABLED.key(), singletonList("true"));
    params.put(Key.API_LABELS_DICTIONARY.key(), Arrays.asList("label1"));
    params.put(Key.PORTAL_SCHEDULER_NOTIFICATIONS.key(), singletonList("11"));
    params.put(Key.PORTAL_ANALYTICS_ENABLED.key(), singletonList("true"));
    params.put(Key.OPEN_API_DOC_TYPE_SWAGGER_ENABLED.key(), singletonList("true"));
    params.put(Key.PORTAL_HTTP_CORS_EXPOSED_HEADERS.key(), singletonList("OnlyOneHeader"));
    when(mockParameterService.findAll(any(List.class), any(Function.class), eq("DEFAULT"), eq(ParameterReferenceType.ENVIRONMENT))).thenReturn(params);
    when(environment.containsProperty(eq(Key.PORTAL_AUTHENTICATION_FORCELOGIN_ENABLED.key()))).thenReturn(true);
    when(environment.containsProperty(Key.API_LABELS_DICTIONARY.key())).thenReturn(true);
    when(environment.containsProperty(Key.PORTAL_SCHEDULER_NOTIFICATIONS.key())).thenReturn(true);
    when(environment.containsProperty(Key.PORTAL_ANALYTICS_ENABLED.key())).thenReturn(true);
    when(environment.containsProperty(Key.OPEN_API_DOC_TYPE_SWAGGER_ENABLED.key())).thenReturn(true);
    PortalSettingsEntity portalSettings = configService.getPortalSettings();
    assertNotNull(portalSettings);
    assertEquals("force login", true, portalSettings.getAuthentication().getForceLogin().isEnabled());
    assertEquals("labels dictionary", 1, portalSettings.getApi().getLabelsDictionary().size());
    assertEquals("scheduler notifications", Integer.valueOf(11), portalSettings.getScheduler().getNotificationsInSeconds());
    assertEquals("analytics", Boolean.TRUE, portalSettings.getPortal().getAnalytics().isEnabled());
    assertEquals("open api swagger enabled", Boolean.TRUE, portalSettings.getOpenAPIDocViewer().getOpenAPIDocType().getSwagger().isEnabled());
    assertEquals("cors exposed headers", 1, portalSettings.getCors().getExposedHeaders().size());
    List<String> readonlyMetadata = portalSettings.getMetadata().get(PortalSettingsEntity.METADATA_READONLY);
    assertEquals("Config metadata size", 5, readonlyMetadata.size());
    assertTrue("Config metadata contains AUTHENTICATION_FORCELOGIN_ENABLED", readonlyMetadata.contains(Key.PORTAL_AUTHENTICATION_FORCELOGIN_ENABLED.key()));
    assertTrue("Config metadata contains API_LABELS_DICTIONARY", readonlyMetadata.contains(Key.API_LABELS_DICTIONARY.key()));
    assertTrue("Config metadata contains SCHEDULER_NOTIFICATIONS", readonlyMetadata.contains(Key.PORTAL_SCHEDULER_NOTIFICATIONS.key()));
    assertTrue("Config metadata contains PORTAL_ANALYTICS_ENABLED", readonlyMetadata.contains(Key.PORTAL_ANALYTICS_ENABLED.key()));
    assertTrue("Config metadata contains OPEN_API_DOC_TYPE_SWAGGER_ENABLED", readonlyMetadata.contains(Key.OPEN_API_DOC_TYPE_SWAGGER_ENABLED.key()));
}
Also used : PortalSettingsEntity(io.gravitee.rest.api.model.settings.PortalSettingsEntity) Function(java.util.function.Function) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Test(org.junit.Test)

Example 3 with PortalSettingsEntity

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

the class ConfigurationIdentitiesResourceTest method shouldGetConfigurationIdentities.

@Test
public void shouldGetConfigurationIdentities() {
    resetAllMocks();
    IdentityProviderActivationEntity activatedIdp = new IdentityProviderActivationEntity();
    activatedIdp.setIdentityProvider(IDP_ID);
    doReturn(Sets.newSet(activatedIdp)).when(identityProviderActivationService).findAllByTarget(any());
    doReturn(Sets.newSet(mockAMIdentityProviderEntity(), mockGoogleIdentityProviderEntity(), mockGitHubIdentityProviderEntity(), mockOIDCIdentityProviderEntity())).when(socialIdentityProviderService).findAll(any());
    PortalSettingsEntity configEntity = new PortalSettingsEntity();
    doReturn(configEntity).when(configService).getPortalSettings();
    final Response response = target().request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    verify(identityProviderMapper, times(4)).convert(any());
    verify(socialIdentityProviderService).findAll(any());
    ConfigurationIdentitiesResponse configurationIdentitiesResponse = response.readEntity(ConfigurationIdentitiesResponse.class);
    assertEquals(4, configurationIdentitiesResponse.getData().size());
}
Also used : PortalSettingsEntity(io.gravitee.rest.api.model.settings.PortalSettingsEntity) ConfigurationIdentitiesResponse(io.gravitee.rest.api.portal.rest.model.ConfigurationIdentitiesResponse) Response(javax.ws.rs.core.Response) IdentityProviderActivationEntity(io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity) ConfigurationIdentitiesResponse(io.gravitee.rest.api.portal.rest.model.ConfigurationIdentitiesResponse) Test(org.junit.Test)

Example 4 with PortalSettingsEntity

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

the class ConfigurationResourceTest method shouldGetConfiguration.

@Test
public void shouldGetConfiguration() {
    resetAllMocks();
    PortalSettingsEntity portalConfigEntity = new PortalSettingsEntity();
    ConsoleSettingsEntity consoleSettingsEntity = new ConsoleSettingsEntity();
    doReturn(portalConfigEntity).when(configService).getPortalSettings();
    doReturn(consoleSettingsEntity).when(configService).getConsoleSettings();
    final Response response = target().request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    Mockito.verify(configMapper).convert(portalConfigEntity, consoleSettingsEntity);
    Mockito.verify(configService).getPortalSettings();
    Mockito.verify(configService).getConsoleSettings();
}
Also used : PortalSettingsEntity(io.gravitee.rest.api.model.settings.PortalSettingsEntity) Response(javax.ws.rs.core.Response) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) Test(org.junit.Test)

Example 5 with PortalSettingsEntity

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

the class ConfigServiceTest method shouldCreatePortalSettings.

@Test
public void shouldCreatePortalSettings() {
    PortalSettingsEntity portalSettingsEntity = new PortalSettingsEntity();
    portalSettingsEntity.getPortal().setUrl("ACME");
    when(mockParameterService.save(PORTAL_URL, "ACME", "DEFAULT", ParameterReferenceType.ENVIRONMENT)).thenReturn(new Parameter());
    configService.save(portalSettingsEntity);
    verify(mockParameterService, times(1)).save(PORTAL_URL, "ACME", "DEFAULT", ParameterReferenceType.ENVIRONMENT);
}
Also used : PortalSettingsEntity(io.gravitee.rest.api.model.settings.PortalSettingsEntity) Parameter(io.gravitee.repository.management.model.Parameter) Test(org.junit.Test)

Aggregations

PortalSettingsEntity (io.gravitee.rest.api.model.settings.PortalSettingsEntity)6 Test (org.junit.Test)6 ConsoleSettingsEntity (io.gravitee.rest.api.model.settings.ConsoleSettingsEntity)2 Collections.singletonList (java.util.Collections.singletonList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Function (java.util.function.Function)2 Response (javax.ws.rs.core.Response)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Parameter (io.gravitee.repository.management.model.Parameter)1 IdentityProviderActivationEntity (io.gravitee.rest.api.model.configuration.identity.IdentityProviderActivationEntity)1 ConfigurationIdentitiesResponse (io.gravitee.rest.api.portal.rest.model.ConfigurationIdentitiesResponse)1 ConfigurationResponse (io.gravitee.rest.api.portal.rest.model.ConfigurationResponse)1