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