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());
}
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());
}
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);
}
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()));
}
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));
}
Aggregations