Search in sources :

Example 6 with IUserSetting

use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.

the class UserSettingServiceTest method testGetGlobalUserSettingUnset.

@Test
public void testGetGlobalUserSettingUnset() throws Exception {
    final String settingName = "settings";
    final String defaultValue = "defaultValue";
    final IUserSetting globalUserSetting = userSettingService.getGlobalUserSetting(settingName, defaultValue);
    assertEquals(settingName, globalUserSetting.getSettingName());
    assertEquals(defaultValue, globalUserSetting.getSettingValue());
}
Also used : IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Example 7 with IUserSetting

use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportUserSettings_NoOverwrite.

@Test
public void testImportUserSettings_NoOverwrite() throws Exception {
    UserExport user = new UserExport();
    user.setUsername("pentaho");
    user.addUserSetting(new ExportManifestUserSetting("theme", "crystal"));
    user.addUserSetting(new ExportManifestUserSetting("language", "en_US"));
    IAnyUserSettingService userSettingService = Mockito.mock(IAnyUserSettingService.class);
    PentahoSystem.registerObject(userSettingService);
    importHandler.setOverwriteFile(false);
    IUserSetting existingSetting = Mockito.mock(IUserSetting.class);
    Mockito.when(userSettingService.getUserSetting("pentaho", "theme", null)).thenReturn(existingSetting);
    Mockito.when(userSettingService.getUserSetting("pentaho", "language", null)).thenReturn(null);
    importHandler.importUserSettings(user);
    Mockito.verify(userSettingService, Mockito.never()).setUserSetting("pentaho", "theme", "crystal");
    Mockito.verify(userSettingService).setUserSetting("pentaho", "language", "en_US");
    Mockito.verify(userSettingService).getUserSetting("pentaho", "theme", null);
    Mockito.verify(userSettingService).getUserSetting("pentaho", "language", null);
}
Also used : IAnyUserSettingService(org.pentaho.platform.api.usersettings.IAnyUserSettingService) UserExport(org.pentaho.platform.plugin.services.importexport.UserExport) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Example 8 with IUserSetting

use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportGlobalUserSetting_noOverwrite.

@Test
public void testImportGlobalUserSetting_noOverwrite() throws Exception {
    importHandler.setOverwriteFile(false);
    List<ExportManifestUserSetting> settings = new ArrayList<>();
    settings.add(new ExportManifestUserSetting("language", "en_US"));
    settings.add(new ExportManifestUserSetting("showHiddenFiles", "false"));
    IUserSettingService userSettingService = Mockito.mock(IUserSettingService.class);
    PentahoSystem.registerObject(userSettingService);
    IUserSetting setting = Mockito.mock(IUserSetting.class);
    Mockito.when(userSettingService.getGlobalUserSetting("language", null)).thenReturn(null);
    Mockito.when(userSettingService.getGlobalUserSetting("showHiddenFiles", null)).thenReturn(setting);
    importHandler.importGlobalUserSettings(settings);
    Mockito.verify(userSettingService).setGlobalUserSetting("language", "en_US");
    Mockito.verify(userSettingService, Mockito.never()).setGlobalUserSetting(Mockito.eq("showHiddenFiles"), Mockito.anyString());
    Mockito.verify(userSettingService).getGlobalUserSetting("language", null);
    Mockito.verify(userSettingService).getGlobalUserSetting("showHiddenFiles", null);
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) ArrayList(java.util.ArrayList) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Example 9 with IUserSetting

use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.

the class UserSettingsResourceTest method testGetUserSettings.

@Test
public void testGetUserSettings() throws Exception {
    IUserSetting userSetting = mock(IUserSetting.class);
    when(userSetting.getSettingName()).thenReturn(USER_SETTING_NAME);
    when(userSetting.getSettingValue()).thenReturn(USER_SETTING_VALUE);
    List<IUserSetting> userSettings = new ArrayList<>();
    userSettings.add(userSetting);
    when(userSettingService.getUserSettings()).thenReturn(userSettings);
    when(userSettingsResource.getUserSettings()).thenCallRealMethod();
    ArrayList<Setting> response = userSettingsResource.getUserSettings();
    assertNotNull(response);
    assertTrue(!response.isEmpty());
    assertTrue(response.get(0).getName().equals(USER_SETTING_NAME));
    assertTrue(response.get(0).getValue().equals(USER_SETTING_VALUE));
}
Also used : IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) ArrayList(java.util.ArrayList) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Test(org.junit.Test)

Example 10 with IUserSetting

use of org.pentaho.platform.api.usersettings.pojo.IUserSetting in project pentaho-platform by pentaho.

the class UserSettingsResource method getUserSetting.

/**
 * Retrieve a particular user setting for the current user
 *
 * @param setting (Name of the setting)
 *
 * @return value of the setting for the user
 */
@GET
@Path("{setting : .+}")
@Facet(name = "Unsupported")
public Response getUserSetting(@PathParam("setting") String setting) {
    IUserSettingService settingsService = getUserSettingService();
    IUserSetting userSetting = settingsService.getUserSetting(setting, null);
    return Response.ok(userSetting != null ? userSetting.getSettingValue() : null).build();
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Aggregations

IUserSetting (org.pentaho.platform.api.usersettings.pojo.IUserSetting)21 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)8 IUserSettingService (org.pentaho.platform.api.usersettings.IUserSettingService)6 ExportManifestUserSetting (org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting)5 HashMap (java.util.HashMap)4 IAnyUserSettingService (org.pentaho.platform.api.usersettings.IAnyUserSettingService)4 Serializable (java.io.Serializable)3 Map (java.util.Map)3 UserExport (org.pentaho.platform.plugin.services.importexport.UserExport)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Facet (org.codehaus.enunciate.Facet)2 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)2 ITenant (org.pentaho.platform.api.mt.ITenant)2 RoleExport (org.pentaho.platform.plugin.services.importexport.RoleExport)2 IRoleAuthorizationPolicyRoleBindingDao (org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao)2 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)2 IOException (java.io.IOException)1 List (java.util.List)1