Search in sources :

Example 6 with ConsoleSettingsEntity

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());
}
Also used : Response(javax.ws.rs.core.Response) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) User(io.gravitee.rest.api.portal.rest.model.User) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 7 with ConsoleSettingsEntity

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());
}
Also used : Response(javax.ws.rs.core.Response) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) User(io.gravitee.rest.api.portal.rest.model.User) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 8 with ConsoleSettingsEntity

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());
}
Also used : Response(javax.ws.rs.core.Response) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) User(io.gravitee.rest.api.portal.rest.model.User) Management(io.gravitee.rest.api.model.settings.Management) UserConfig(io.gravitee.rest.api.portal.rest.model.UserConfig) UpdateUserEntity(io.gravitee.rest.api.model.UpdateUserEntity) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 9 with ConsoleSettingsEntity

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));
}
Also used : Response(javax.ws.rs.core.Response) ConsoleSettingsEntity(io.gravitee.rest.api.model.settings.ConsoleSettingsEntity) Test(org.junit.Test)

Example 10 with ConsoleSettingsEntity

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