Search in sources :

Example 1 with StartupViewData

use of org.motechproject.server.web.dto.StartupViewData in project motech by motech.

the class StartupControllerTest method shouldInformViewThatConfigFilesNotRequiredWhenConfigSourceIsUI.

@Test
public void shouldInformViewThatConfigFilesNotRequiredWhenConfigSourceIsUI() throws IOException {
    when(configurationService.requiresConfigurationFiles()).thenReturn(true);
    when(localeService.getUserLocale(httpServletRequest)).thenReturn(new Locale("en"));
    BootstrapConfig bootstrapConfig = mock(BootstrapConfig.class);
    when(bootstrapConfig.getConfigSource()).thenReturn(ConfigSource.UI);
    when(configurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    StartupViewData startupViewData = startupController.getStartupViewData(httpServletRequest);
    assertThat(startupViewData.getRequireConfigFiles(), Is.is(false));
    verify(configurationService, never()).requiresConfigurationFiles();
}
Also used : Locale(java.util.Locale) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) StartupViewData(org.motechproject.server.web.dto.StartupViewData) Test(org.junit.Test)

Example 2 with StartupViewData

use of org.motechproject.server.web.dto.StartupViewData in project motech by motech.

the class StartupControllerTest method shouldInformViewThatConfigFilesNotRequiredWhenConfigSourceIsFileAndConfigFilesExist.

@Test
public void shouldInformViewThatConfigFilesNotRequiredWhenConfigSourceIsFileAndConfigFilesExist() throws IOException {
    when(configurationService.requiresConfigurationFiles()).thenReturn(true);
    when(localeService.getUserLocale(httpServletRequest)).thenReturn(new Locale("en"));
    BootstrapConfig bootstrapConfig = mock(BootstrapConfig.class);
    when(bootstrapConfig.getConfigSource()).thenReturn(ConfigSource.FILE);
    when(configurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    when(configurationService.requiresConfigurationFiles()).thenReturn(false);
    StartupViewData startupViewData = startupController.getStartupViewData(httpServletRequest);
    assertThat((startupViewData.getRequireConfigFiles()), Is.is(false));
    verify(configurationService).requiresConfigurationFiles();
}
Also used : Locale(java.util.Locale) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) StartupViewData(org.motechproject.server.web.dto.StartupViewData) Test(org.junit.Test)

Example 3 with StartupViewData

use of org.motechproject.server.web.dto.StartupViewData in project motech by motech.

the class StartupControllerTest method testStartup.

@Test
public void testStartup() {
    Properties properties = new Properties();
    properties.put("host", "localhost");
    properties.put("port", "12345");
    NavigableMap<String, String> map = new TreeMap<>();
    when(startupManager.canLaunchBundles()).thenReturn(false);
    when(startupManager.getDefaultSettings()).thenReturn(motechSettings);
    when(localeService.getUserLocale(httpServletRequest)).thenReturn(new Locale("en"));
    when(localeService.getSupportedLanguages()).thenReturn(map);
    when(configurationService.getPlatformSettings()).thenReturn(motechSettings);
    StartupViewData result = startupController.getStartupViewData(httpServletRequest);
    verify(startupManager).canLaunchBundles();
    verify(localeService).getSupportedLanguages();
    verify(localeService).getUserLocale(httpServletRequest);
    assertThat(result.getRedirectHome(), Is.is(false));
    StartupSuggestionsForm startupSuggestionsForm = result.getSuggestions();
    assertTrue(startupSuggestionsForm.getDatabaseUrls().isEmpty());
    assertTrue(startupSuggestionsForm.getQueueUrls().isEmpty());
    assertTrue(startupSuggestionsForm.getSchedulerUrls().isEmpty());
    StartupForm startupSettings = result.getStartupSettings();
    Boolean requiresConfigFiles = result.getRequireConfigFiles();
    Assert.assertFalse(requiresConfigFiles);
    assertEquals("en", startupSettings.getLanguage());
}
Also used : Locale(java.util.Locale) StartupSuggestionsForm(org.motechproject.server.web.form.StartupSuggestionsForm) StartupForm(org.motechproject.server.web.form.StartupForm) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) TreeMap(java.util.TreeMap) StartupViewData(org.motechproject.server.web.dto.StartupViewData) Test(org.junit.Test)

Example 4 with StartupViewData

use of org.motechproject.server.web.dto.StartupViewData in project motech by motech.

the class StartupControllerTest method shouldInformViewThatConfigFilesRequiredWhenConfigSourceIsFileAndConfigFilesDoNotExist.

@Test
public void shouldInformViewThatConfigFilesRequiredWhenConfigSourceIsFileAndConfigFilesDoNotExist() throws IOException {
    when(configurationService.requiresConfigurationFiles()).thenReturn(true);
    when(localeService.getUserLocale(httpServletRequest)).thenReturn(new Locale("en"));
    BootstrapConfig bootstrapConfig = mock(BootstrapConfig.class);
    when(bootstrapConfig.getConfigSource()).thenReturn(ConfigSource.FILE);
    when(configurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    when(configurationService.requiresConfigurationFiles()).thenReturn(true);
    StartupViewData startupViewData = startupController.getStartupViewData(httpServletRequest);
    assertThat((startupViewData.getRequireConfigFiles()), Is.is(true));
    verify(configurationService).requiresConfigurationFiles();
}
Also used : Locale(java.util.Locale) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) StartupViewData(org.motechproject.server.web.dto.StartupViewData) Test(org.junit.Test)

Example 5 with StartupViewData

use of org.motechproject.server.web.dto.StartupViewData in project motech by motech.

the class StartupController method getStartupViewData.

@RequestMapping(value = "/startupviewdata", method = RequestMethod.GET)
@ResponseBody
public StartupViewData getStartupViewData(final HttpServletRequest request) {
    StartupViewData viewData = new StartupViewData();
    if (startupManager.canLaunchBundles()) {
        viewData.setRedirectHome(true);
        return viewData;
    } else {
        Locale userLocale = localeService.getUserLocale(request);
        ConfigSource configSource = (configurationService.loadBootstrapConfig() != null) ? configurationService.loadBootstrapConfig().getConfigSource() : ConfigSource.UI;
        boolean requiresConfigFiles = configSource.isFile() && configurationService.requiresConfigurationFiles();
        StartupForm startupSettings = new StartupForm();
        startupSettings.setLanguage(userLocale.getLanguage());
        viewData.setRequireConfigFiles(requiresConfigFiles);
        viewData.setSuggestions(createSuggestions());
        viewData.setStartupSettings(startupSettings);
        viewData.setLanguages(localeService.getSupportedLanguages());
        viewData.setPageLang(userLocale);
        viewData.setIsFileMode(ConfigSource.FILE.equals(configSource));
        viewData.setIsAdminRegistered(userService.hasActiveMotechAdmin());
        viewData.setRedirectHome(false);
    }
    return viewData;
}
Also used : Locale(java.util.Locale) ConfigSource(org.motechproject.config.core.domain.ConfigSource) StartupForm(org.motechproject.server.web.form.StartupForm) StartupViewData(org.motechproject.server.web.dto.StartupViewData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Locale (java.util.Locale)5 StartupViewData (org.motechproject.server.web.dto.StartupViewData)5 Test (org.junit.Test)4 BootstrapConfig (org.motechproject.config.core.domain.BootstrapConfig)3 StartupForm (org.motechproject.server.web.form.StartupForm)2 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 Matchers.anyString (org.mockito.Matchers.anyString)1 ConfigSource (org.motechproject.config.core.domain.ConfigSource)1 StartupSuggestionsForm (org.motechproject.server.web.form.StartupSuggestionsForm)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1