Search in sources :

Example 1 with ConsoleSettingsEntity

use of io.gravitee.rest.api.model.settings.ConsoleSettingsEntity 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 ConsoleSettingsEntity

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

the class ConfigServiceTest method shouldGetConsoleSettings.

@Test
public void shouldGetConsoleSettings() {
    Map<String, List<String>> params = new HashMap<>();
    params.put(COMPANY_NAME.key(), singletonList("ACME"));
    params.put(Key.CONSOLE_SCHEDULER_NOTIFICATIONS.key(), singletonList("11"));
    params.put(Key.ALERT_ENABLED.key(), singletonList("true"));
    when(mockParameterService.findAll(any(List.class), any(Function.class), eq("DEFAULT"), eq(ParameterReferenceType.ORGANIZATION))).thenReturn(params);
    when(reCaptchaService.getSiteKey()).thenReturn("my-site-key");
    when(reCaptchaService.isEnabled()).thenReturn(true);
    ConsoleSettingsEntity consoleSettings = configService.getConsoleSettings();
    assertNotNull(consoleSettings);
    assertEquals("scheduler notifications", Integer.valueOf(11), consoleSettings.getScheduler().getNotificationsInSeconds());
    assertEquals("recaptcha siteKey", "my-site-key", consoleSettings.getReCaptcha().getSiteKey());
    assertEquals("alerting enabled", Boolean.TRUE, consoleSettings.getAlert().getEnabled());
    assertEquals("recaptcha enabled", Boolean.TRUE, consoleSettings.getReCaptcha().getEnabled());
    assertEquals("cors exposed headers", 2, consoleSettings.getCors().getExposedHeaders().size());
}
Also used : Function(java.util.function.Function) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Test(org.junit.Test)

Example 3 with ConsoleSettingsEntity

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

the class ConfigServiceTest method shouldCreateConsoleSettings.

@Test
public void shouldCreateConsoleSettings() {
    ConsoleSettingsEntity consoleSettingsEntity = new ConsoleSettingsEntity();
    consoleSettingsEntity.getAlert().setEnabled(true);
    Logging logging = new Logging();
    logging.setMaxDurationMillis(3000l);
    Logging.Audit audit = new Logging.Audit();
    audit.setEnabled(true);
    Logging.Audit.AuditTrail trail = new Logging.Audit.AuditTrail();
    trail.setEnabled(true);
    audit.setTrail(trail);
    logging.setAudit(audit);
    Logging.User user = new Logging.User();
    user.setDisplayed(true);
    logging.setUser(user);
    consoleSettingsEntity.setLogging(logging);
    when(mockParameterService.save(ALERT_ENABLED, "true", "DEFAULT", ParameterReferenceType.ORGANIZATION)).thenReturn(new Parameter());
    when(mockParameterService.save(LOGGING_DEFAULT_MAX_DURATION, "3000", "DEFAULT", ParameterReferenceType.ORGANIZATION)).thenReturn(new Parameter());
    when(mockParameterService.save(LOGGING_USER_DISPLAYED, "true", "DEFAULT", ParameterReferenceType.ORGANIZATION)).thenReturn(new Parameter());
    when(mockParameterService.save(LOGGING_AUDIT_ENABLED, "true", "DEFAULT", ParameterReferenceType.ORGANIZATION)).thenReturn(new Parameter());
    when(mockParameterService.save(LOGGING_AUDIT_TRAIL_ENABLED, "true", "DEFAULT", ParameterReferenceType.ORGANIZATION)).thenReturn(new Parameter());
    configService.save(consoleSettingsEntity);
    verify(mockParameterService, times(1)).save(ALERT_ENABLED, "true", "DEFAULT", ParameterReferenceType.ORGANIZATION);
    verify(mockParameterService, times(1)).save(LOGGING_DEFAULT_MAX_DURATION, "3000", "DEFAULT", ParameterReferenceType.ORGANIZATION);
    verify(mockParameterService, times(1)).save(LOGGING_USER_DISPLAYED, "true", "DEFAULT", ParameterReferenceType.ORGANIZATION);
    verify(mockParameterService, times(1)).save(LOGGING_AUDIT_ENABLED, "true", "DEFAULT", ParameterReferenceType.ORGANIZATION);
    verify(mockParameterService, times(1)).save(LOGGING_AUDIT_TRAIL_ENABLED, "true", "DEFAULT", ParameterReferenceType.ORGANIZATION);
}
Also used : Logging(io.gravitee.rest.api.model.settings.Logging) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) Parameter(io.gravitee.repository.management.model.Parameter) Test(org.junit.Test)

Example 4 with ConsoleSettingsEntity

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

the class ConfigServiceTest method shouldGetConsoleSettingsFromEnvVar.

@Test
public void shouldGetConsoleSettingsFromEnvVar() {
    Map<String, List<String>> params = new HashMap<>();
    params.put(COMPANY_NAME.key(), singletonList("ACME"));
    params.put(Key.CONSOLE_AUTHENTICATION_LOCALLOGIN_ENABLED.key(), singletonList("false"));
    params.put(Key.CONSOLE_SCHEDULER_NOTIFICATIONS.key(), singletonList("11"));
    params.put(Key.ALERT_ENABLED.key(), singletonList("true"));
    params.put(Key.ANALYTICS_CLIENT_TIMEOUT.key(), singletonList("60000"));
    params.put(Key.CONSOLE_HTTP_CORS_EXPOSED_HEADERS.key(), singletonList("OnlyOneHeader"));
    when(mockParameterService.findAll(any(List.class), any(Function.class), eq("DEFAULT"), eq(ParameterReferenceType.ORGANIZATION))).thenReturn(params);
    when(environment.containsProperty(eq(Key.CONSOLE_AUTHENTICATION_LOCALLOGIN_ENABLED.key()))).thenReturn(true);
    when(environment.containsProperty(Key.CONSOLE_SCHEDULER_NOTIFICATIONS.key())).thenReturn(true);
    ConsoleSettingsEntity consoleSettings = configService.getConsoleSettings();
    assertNotNull(consoleSettings);
    assertEquals("scheduler notifications", Integer.valueOf(11), consoleSettings.getScheduler().getNotificationsInSeconds());
    assertEquals("cors exposed headers", 1, consoleSettings.getCors().getExposedHeaders().size());
    List<String> readonlyMetadata = consoleSettings.getMetadata().get(PortalSettingsEntity.METADATA_READONLY);
    assertEquals("Config metadata size", 2, readonlyMetadata.size());
    assertTrue("Config metadata contains CONSOLE_AUTHENTICATION_LOCALLOGIN_ENABLED", readonlyMetadata.contains(Key.CONSOLE_AUTHENTICATION_LOCALLOGIN_ENABLED.key()));
    assertTrue("Config metadata contains CONSOLE_SCHEDULER_NOTIFICATIONS", readonlyMetadata.contains(Key.CONSOLE_SCHEDULER_NOTIFICATIONS.key()));
}
Also used : Function(java.util.function.Function) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Test(org.junit.Test)

Example 5 with ConsoleSettingsEntity

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

the class ConsoleSettingsResourceTest method shouldCallSaveMethod_EnabledMaintenance.

@Test
public void shouldCallSaveMethod_EnabledMaintenance() {
    ConsoleSettingsEntity config = new ConsoleSettingsEntity();
    Maintenance maintenance = new Maintenance();
    maintenance.setEnabled(true);
    config.setMaintenance(maintenance);
    when(parameterService.findAsBoolean(Key.MAINTENANCE_MODE_ENABLED, GraviteeContext.getCurrentOrganization(), ParameterReferenceType.ORGANIZATION)).thenReturn(false);
    final Response response = orgTarget().request().post(Entity.json(config));
    assertEquals(response.readEntity(String.class), OK_200, response.getStatus());
    verify(configService).save(any(ConsoleSettingsEntity.class));
}
Also used : Response(javax.ws.rs.core.Response) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) Maintenance(io.gravitee.rest.api.model.settings.Maintenance) Test(org.junit.Test)

Aggregations

ConsoleSettingsEntity (io.gravitee.rest.api.model.settings.ConsoleSettingsEntity)12 Test (org.junit.Test)12 Response (javax.ws.rs.core.Response)8 UpdateUserEntity (io.gravitee.rest.api.model.UpdateUserEntity)3 UserEntity (io.gravitee.rest.api.model.UserEntity)3 Maintenance (io.gravitee.rest.api.model.settings.Maintenance)3 User (io.gravitee.rest.api.portal.rest.model.User)3 PortalSettingsEntity (io.gravitee.rest.api.model.settings.PortalSettingsEntity)2 Collections.singletonList (java.util.Collections.singletonList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Function (java.util.function.Function)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Parameter (io.gravitee.repository.management.model.Parameter)1 Logging (io.gravitee.rest.api.model.settings.Logging)1 Management (io.gravitee.rest.api.model.settings.Management)1 ConfigurationResponse (io.gravitee.rest.api.portal.rest.model.ConfigurationResponse)1 UserConfig (io.gravitee.rest.api.portal.rest.model.UserConfig)1