Search in sources :

Example 1 with SettingsOption

use of org.motechproject.admin.settings.SettingsOption in project motech by motech.

the class SettingsServiceTest method shouldSaveNullSettingAsNullValue.

@Test
public void shouldSaveNullSettingAsNullValue() {
    SettingsOption option = new SettingsOption(OPTION_KEY, null);
    Settings settings = new Settings("section", singletonList(option));
    settingsService.savePlatformSettings(settings);
    verify(configurationService).setPlatformSetting(OPTION_KEY, null);
}
Also used : SettingsOption(org.motechproject.admin.settings.SettingsOption) AdminSettings(org.motechproject.admin.settings.AdminSettings) Settings(org.motechproject.admin.settings.Settings) MotechSettings(org.motechproject.config.domain.MotechSettings) Test(org.junit.Test)

Example 2 with SettingsOption

use of org.motechproject.admin.settings.SettingsOption in project motech by motech.

the class SettingsServiceImpl method savePlatformSettings.

@Override
public void savePlatformSettings(Settings settings) {
    for (SettingsOption option : settings.getSettings()) {
        Object val = option.getValue();
        configurationService.setPlatformSetting(option.getKey(), val == null ? null : String.valueOf(val));
    }
    Map<String, Object> params = new HashMap<>();
    params.put(ConfigurationConstants.SETTINGS, settings);
    MotechEvent platformSettingsChangedEvent = new MotechEvent(ConfigurationConstants.BUNDLE_SETTINGS_CHANGED_EVENT_SUBJECT, params);
    eventRelay.sendEventMessage(platformSettingsChangedEvent);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MotechEvent(org.motechproject.event.MotechEvent) SettingsOption(org.motechproject.admin.settings.SettingsOption)

Example 3 with SettingsOption

use of org.motechproject.admin.settings.SettingsOption in project motech by motech.

the class SettingsControllerTest method testGetPlatformSettings.

@Test
public void testGetPlatformSettings() {
    SettingsOption option = new SettingsOption(new AbstractMap.SimpleEntry<Object, Object>(ConfigurationConstants.LANGUAGE, "en"));
    List<Settings> pSettingsList = new ArrayList<>();
    pSettingsList.add(platformSettings);
    AdminSettings adminSettings = new AdminSettings(pSettingsList, false);
    when(settingsService.getSettings()).thenReturn(adminSettings);
    when(platformSettings.getSettings()).thenReturn(Arrays.asList(option));
    List<Settings> result = controller.getPlatformSettings().getSettingsList();
    assertEquals(option.getKey(), result.get(0).getSettings().get(0).getKey());
    assertEquals(option.getValue(), result.get(0).getSettings().get(0).getValue());
    verify(settingsService).getSettings();
}
Also used : AbstractMap(java.util.AbstractMap) ArrayList(java.util.ArrayList) SettingsOption(org.motechproject.admin.settings.SettingsOption) AdminSettings(org.motechproject.admin.settings.AdminSettings) Settings(org.motechproject.admin.settings.Settings) AdminSettings(org.motechproject.admin.settings.AdminSettings) Test(org.junit.Test)

Example 4 with SettingsOption

use of org.motechproject.admin.settings.SettingsOption in project motech by motech.

the class SettingsServiceTest method testGetBundleSettings.

@Test
public void testGetBundleSettings() throws IOException {
    List<Settings> bundleSettingsList = settingsService.getBundleSettings(BUNDLE_ID);
    assertEquals(1, bundleSettingsList.size());
    Settings bundleSettings = bundleSettingsList.get(0);
    assertEquals(BUNDLE_FILENAME, bundleSettings.getSection());
    List<SettingsOption> settingsOptions = bundleSettings.getSettings();
    assertEquals(1, settingsOptions.size());
    assertEquals(OPTION_KEY, settingsOptions.get(0).getKey());
    assertEquals(OPTION_VALUE, settingsOptions.get(0).getValue());
}
Also used : AdminSettings(org.motechproject.admin.settings.AdminSettings) Settings(org.motechproject.admin.settings.Settings) MotechSettings(org.motechproject.config.domain.MotechSettings) SettingsOption(org.motechproject.admin.settings.SettingsOption) Test(org.junit.Test)

Example 5 with SettingsOption

use of org.motechproject.admin.settings.SettingsOption in project motech by motech.

the class SettingsServiceTest method testSaveBundleSettings.

@Test
public void testSaveBundleSettings() throws IOException {
    SettingsOption option = new SettingsOption(OPTION_KEY, OPTION_VALUE);
    Settings settings = new Settings(BUNDLE_FILENAME, singletonList(option));
    settingsService.saveBundleSettings(settings, BUNDLE_ID);
    verify(configurationService).addOrUpdateProperties(BUNDLE_SYMBOLIC_NAME, "", BUNDLE_FILENAME, bundleProperty, null);
}
Also used : SettingsOption(org.motechproject.admin.settings.SettingsOption) AdminSettings(org.motechproject.admin.settings.AdminSettings) Settings(org.motechproject.admin.settings.Settings) MotechSettings(org.motechproject.config.domain.MotechSettings) Test(org.junit.Test)

Aggregations

SettingsOption (org.motechproject.admin.settings.SettingsOption)8 AdminSettings (org.motechproject.admin.settings.AdminSettings)7 Settings (org.motechproject.admin.settings.Settings)7 MotechSettings (org.motechproject.config.domain.MotechSettings)6 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 AbstractMap (java.util.AbstractMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 MotechEvent (org.motechproject.event.MotechEvent)1