You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServerImplTest.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.platform;
  21. import java.io.File;
  22. import java.io.IOException;
  23. import org.junit.Rule;
  24. import org.junit.Test;
  25. import org.junit.rules.TemporaryFolder;
  26. import org.sonar.api.CoreProperties;
  27. import org.sonar.api.SonarRuntime;
  28. import org.sonar.api.config.internal.MapSettings;
  29. import org.sonar.api.utils.Version;
  30. import static org.assertj.core.api.Assertions.assertThat;
  31. import static org.mockito.Mockito.mock;
  32. import static org.mockito.Mockito.when;
  33. public class ServerImplTest {
  34. private MapSettings settings = new MapSettings();
  35. private StartupMetadata state = mock(StartupMetadata.class);
  36. private ServerFileSystem fs = mock(ServerFileSystem.class);
  37. private UrlSettings urlSettings = mock(UrlSettings.class);
  38. private SonarRuntime runtime = mock(SonarRuntime.class);
  39. private ServerImpl underTest = new ServerImpl(settings.asConfig(), state, fs, urlSettings, runtime);
  40. @Rule
  41. public TemporaryFolder temp = new TemporaryFolder();
  42. @Test
  43. public void test_url_information() {
  44. when(urlSettings.getContextPath()).thenReturn("/foo");
  45. when(urlSettings.getBaseUrl()).thenReturn("http://localhost:9000/foo");
  46. when(urlSettings.isSecured()).thenReturn(false);
  47. assertThat(underTest.getContextPath()).isEqualTo("/foo");
  48. assertThat(underTest.getPublicRootUrl()).isEqualTo("http://localhost:9000/foo");
  49. assertThat(underTest.isSecured()).isFalse();
  50. }
  51. @Test
  52. public void test_file_system_information() throws IOException {
  53. File home = temp.newFolder();
  54. when(fs.getHomeDir()).thenReturn(home);
  55. }
  56. @Test
  57. public void test_startup_information() {
  58. long time = 123_456_789L;
  59. when(state.getStartedAt()).thenReturn(time);
  60. assertThat(underTest.getStartedAt().getTime()).isEqualTo(time);
  61. }
  62. @Test
  63. public void test_id() {
  64. settings.setProperty(CoreProperties.SERVER_ID, "foo");
  65. assertThat(underTest.getId()).isEqualTo("foo");
  66. assertThat(underTest.getPermanentServerId()).isEqualTo("foo");
  67. }
  68. @Test
  69. public void test_getVersion() {
  70. Version version = Version.create(6, 1);
  71. when(runtime.getApiVersion()).thenReturn(version);
  72. assertThat(underTest.getVersion()).isEqualTo(version.toString());
  73. }
  74. }