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.

ProjectDefinitionTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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.api.batch.bootstrap;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import org.junit.Test;
  24. import org.sonar.api.CoreProperties;
  25. import static org.assertj.core.api.Assertions.assertThat;
  26. public class ProjectDefinitionTest {
  27. @Test
  28. public void shouldSetKey() {
  29. ProjectDefinition def = ProjectDefinition.create();
  30. def.setKey("mykey");
  31. assertThat(def.getKey()).isEqualTo("mykey");
  32. }
  33. @Test
  34. public void shouldSetVersion() {
  35. ProjectDefinition def = ProjectDefinition.create();
  36. def.setProjectVersion("2.0-SNAPSHOT");
  37. assertThat(def.getVersion()).isEqualTo("2.0-SNAPSHOT");
  38. }
  39. @Test
  40. public void shouldSupportNoVersion() {
  41. ProjectDefinition def = ProjectDefinition.create();
  42. def.setProjectVersion(null);
  43. assertThat(def.getVersion()).isEqualTo("not provided");
  44. assertThat(def.getOriginalVersion()).isEqualTo("");
  45. }
  46. @Test
  47. public void shouldSetOptionalFields() {
  48. ProjectDefinition def = ProjectDefinition.create();
  49. def.setName("myname");
  50. def.setDescription("desc");
  51. assertThat(def.getName()).isEqualTo("myname");
  52. assertThat(def.getDescription()).isEqualTo("desc");
  53. }
  54. @Test
  55. public void shouldSupportDefaultName() {
  56. ProjectDefinition def = ProjectDefinition.create();
  57. def.setKey("myKey");
  58. assertThat(def.getName()).isEqualTo("myKey");
  59. }
  60. @Test
  61. public void shouldGetKeyFromProperties() {
  62. Map<String, String> props = new HashMap<>();
  63. props.put(CoreProperties.PROJECT_KEY_PROPERTY, "foo");
  64. ProjectDefinition def = ProjectDefinition.create();
  65. def.setProperties(props);
  66. assertThat(def.getKey()).isEqualTo("foo");
  67. }
  68. @Test
  69. public void testDefaultValues() {
  70. ProjectDefinition def = ProjectDefinition.create();
  71. assertThat(def.sources()).isEmpty();
  72. assertThat(def.tests()).isEmpty();
  73. }
  74. /**
  75. * See SONAR-2879
  76. */
  77. @Test
  78. public void shouldTrimPaths() {
  79. ProjectDefinition def = ProjectDefinition.create();
  80. def.setSources("src1", " src2 ", " with whitespace");
  81. def.setTests("test1", " test2 ", " with whitespace");
  82. assertThat(def.sources()).containsOnly("src1", "src2", "with whitespace");
  83. assertThat(def.tests()).containsOnly("test1", "test2", "with whitespace");
  84. }
  85. @Test
  86. public void shouldManageRelationships() {
  87. ProjectDefinition root = ProjectDefinition.create();
  88. ProjectDefinition child = ProjectDefinition.create();
  89. root.addSubProject(child);
  90. assertThat(root.getSubProjects()).hasSize(1);
  91. assertThat(child.getSubProjects()).isEmpty();
  92. assertThat(root.getParent()).isNull();
  93. assertThat(child.getParent()).isEqualTo(root);
  94. }
  95. @Test
  96. public void shouldResetSourceDirs() {
  97. ProjectDefinition root = ProjectDefinition.create();
  98. root.addSources("src", "src2/main");
  99. assertThat(root.sources()).hasSize(2);
  100. root.resetSources();
  101. assertThat(root.sources()).isEmpty();
  102. }
  103. @Test
  104. public void shouldResetTestDirs() {
  105. ProjectDefinition root = ProjectDefinition.create();
  106. root.addTests("src", "src2/test");
  107. assertThat(root.tests()).hasSize(2);
  108. root.resetTests();
  109. assertThat(root.tests()).isEmpty();
  110. }
  111. }