use of io.gravitee.rest.api.model.settings.ConsoleSettingsEntity in project gravitee-management-rest-api by gravitee-io.
the class UserResourceTest method shouldGetCurrentUserWithEmptyManagementConfig.
@Test
public void shouldGetCurrentUserWithEmptyManagementConfig() {
when(userService.findByIdWithRoles(USER_NAME)).thenReturn(new UserEntity());
when(permissionService.hasManagementRights(USER_NAME)).thenReturn(Boolean.TRUE);
when(configService.getConsoleSettings()).thenReturn(new ConsoleSettingsEntity());
final Response response = target().request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
ArgumentCaptor<String> userId = ArgumentCaptor.forClass(String.class);
Mockito.verify(userService).findByIdWithRoles(userId.capture());
assertEquals(USER_NAME, userId.getValue());
User user = response.readEntity(User.class);
assertNotNull(user);
assertNull(user.getConfig());
assertNotNull(user.getLinks());
}
use of io.gravitee.rest.api.model.settings.ConsoleSettingsEntity in project gravitee-management-rest-api by gravitee-io.
the class UserResourceTest method shouldGetCurrentUserWithManagementConfigWithoutUrl.
@Test
public void shouldGetCurrentUserWithManagementConfigWithoutUrl() {
when(userService.findByIdWithRoles(USER_NAME)).thenReturn(new UserEntity());
when(permissionService.hasManagementRights(USER_NAME)).thenReturn(Boolean.TRUE);
ConsoleSettingsEntity consoleConfigEntity = new ConsoleSettingsEntity();
when(configService.getConsoleSettings()).thenReturn(consoleConfigEntity);
final Response response = target().request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
ArgumentCaptor<String> userId = ArgumentCaptor.forClass(String.class);
Mockito.verify(userService).findByIdWithRoles(userId.capture());
assertEquals(USER_NAME, userId.getValue());
User user = response.readEntity(User.class);
assertNotNull(user);
assertNull(user.getConfig());
assertNotNull(user.getLinks());
}
use of io.gravitee.rest.api.model.settings.ConsoleSettingsEntity in project gravitee-management-rest-api by gravitee-io.
the class UserResourceTest method shouldGetCurrentUserWithManagementConfigWithUrl.
@Test
public void shouldGetCurrentUserWithManagementConfigWithUrl() {
when(userService.findByIdWithRoles(USER_NAME)).thenReturn(new UserEntity());
when(permissionService.hasManagementRights(USER_NAME)).thenReturn(Boolean.TRUE);
ConsoleSettingsEntity consoleConfigEntity = new ConsoleSettingsEntity();
Management managementConfig = new Management();
managementConfig.setUrl("URL");
consoleConfigEntity.setManagement(managementConfig);
when(configService.getConsoleSettings()).thenReturn(consoleConfigEntity);
final Response response = target().request().get();
assertEquals(HttpStatusCode.OK_200, response.getStatus());
ArgumentCaptor<String> userId = ArgumentCaptor.forClass(String.class);
Mockito.verify(userService).findByIdWithRoles(userId.capture());
assertEquals(USER_NAME, userId.getValue());
User user = response.readEntity(User.class);
assertNotNull(user);
UserConfig config = user.getConfig();
assertNotNull(config);
assertEquals("URL", config.getManagementUrl());
assertNotNull(user.getLinks());
}
use of io.gravitee.rest.api.model.settings.ConsoleSettingsEntity in project gravitee-management-rest-api by gravitee-io.
the class ConsoleSettingsResourceTest method shouldNotCallSaveMethod_MaintenanceEnabled.
@Test
public void shouldNotCallSaveMethod_MaintenanceEnabled() {
ConsoleSettingsEntity config = new ConsoleSettingsEntity();
when(parameterService.findAsBoolean(Key.MAINTENANCE_MODE_ENABLED, GraviteeContext.getCurrentOrganization(), ParameterReferenceType.ORGANIZATION)).thenReturn(true);
final Response response = orgTarget().request().post(Entity.json(config));
assertEquals(response.readEntity(String.class), SERVICE_UNAVAILABLE_503, response.getStatus());
verify(configService, never()).save(any(ConsoleSettingsEntity.class));
}
use of io.gravitee.rest.api.model.settings.ConsoleSettingsEntity in project gravitee-management-rest-api by gravitee-io.
the class ConsoleSettingsResourceTest method shouldNotCallSaveMethod_MaintenanceAlreadyEnabled.
@Test
public void shouldNotCallSaveMethod_MaintenanceAlreadyEnabled() {
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(true);
final Response response = orgTarget().request().post(Entity.json(config));
assertEquals(response.readEntity(String.class), SERVICE_UNAVAILABLE_503, response.getStatus());
verify(configService, never()).save(any(ConsoleSettingsEntity.class));
}
Aggregations