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.

TestDoc.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.server.test.index;
  21. import com.google.common.annotations.VisibleForTesting;
  22. import com.google.common.collect.Maps;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. import java.util.Map;
  26. import javax.annotation.CheckForNull;
  27. import org.sonar.server.es.BaseDoc;
  28. import static org.sonar.server.test.index.TestIndexDefinition.FIELD_COVERED_FILES;
  29. import static org.sonar.server.test.index.TestIndexDefinition.FIELD_DURATION_IN_MS;
  30. import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID;
  31. import static org.sonar.server.test.index.TestIndexDefinition.FIELD_MESSAGE;
  32. import static org.sonar.server.test.index.TestIndexDefinition.FIELD_NAME;
  33. import static org.sonar.server.test.index.TestIndexDefinition.FIELD_PROJECT_UUID;
  34. import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STACKTRACE;
  35. import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STATUS;
  36. import static org.sonar.server.test.index.TestIndexDefinition.FIELD_TEST_UUID;
  37. public class TestDoc extends BaseDoc {
  38. public TestDoc(Map<String, Object> fields) {
  39. super(fields);
  40. }
  41. @VisibleForTesting
  42. public TestDoc() {
  43. super(Maps.newHashMapWithExpectedSize(10));
  44. }
  45. @Override
  46. public String getId() {
  47. return testUuid();
  48. }
  49. @Override
  50. public String getRouting() {
  51. return projectUuid();
  52. }
  53. @Override
  54. public String getParent() {
  55. return null;
  56. }
  57. public String projectUuid() {
  58. return getField(FIELD_PROJECT_UUID);
  59. }
  60. public TestDoc setProjectUuid(String projectUuid) {
  61. setField(FIELD_PROJECT_UUID, projectUuid);
  62. return this;
  63. }
  64. public String fileUuid() {
  65. return getField(FIELD_FILE_UUID);
  66. }
  67. public TestDoc setFileUuid(String fileUuid) {
  68. setField(FIELD_FILE_UUID, fileUuid);
  69. return this;
  70. }
  71. public String testUuid() {
  72. return getField(FIELD_TEST_UUID);
  73. }
  74. public TestDoc setUuid(String testUuid) {
  75. setField(FIELD_TEST_UUID, testUuid);
  76. return this;
  77. }
  78. public String name() {
  79. return getField(FIELD_NAME);
  80. }
  81. public TestDoc setName(String name) {
  82. setField(FIELD_NAME, name);
  83. return this;
  84. }
  85. public String status() {
  86. return getField(FIELD_STATUS);
  87. }
  88. public TestDoc setStatus(String status) {
  89. setField(FIELD_STATUS, status);
  90. return this;
  91. }
  92. @CheckForNull
  93. public String message() {
  94. return getNullableField(FIELD_MESSAGE);
  95. }
  96. public TestDoc setMessage(String message) {
  97. setField(FIELD_MESSAGE, message);
  98. return this;
  99. }
  100. @CheckForNull
  101. public String stackTrace() {
  102. return getNullableField(FIELD_STACKTRACE);
  103. }
  104. public TestDoc setStackTrace(String stackTrace) {
  105. setField(FIELD_STACKTRACE, stackTrace);
  106. return this;
  107. }
  108. @CheckForNull
  109. public Long durationInMs() {
  110. Number number = getNullableField(FIELD_DURATION_IN_MS);
  111. return number == null ? null : number.longValue();
  112. }
  113. public TestDoc setDurationInMs(Long durationInMs) {
  114. setField(FIELD_DURATION_IN_MS, durationInMs);
  115. return this;
  116. }
  117. public List<CoveredFileDoc> coveredFiles() {
  118. List<Map<String, Object>> coveredFilesAsMaps = getNullableField(FIELD_COVERED_FILES);
  119. if (coveredFilesAsMaps == null) {
  120. return new ArrayList<>();
  121. }
  122. List<CoveredFileDoc> coveredFiles = new ArrayList<>();
  123. for (Map<String, Object> coveredFileMap : coveredFilesAsMaps) {
  124. coveredFiles.add(new CoveredFileDoc(coveredFileMap));
  125. }
  126. return coveredFiles;
  127. }
  128. public TestDoc setCoveredFiles(List<CoveredFileDoc> coveredFiles) {
  129. List<Map<String, Object>> coveredFilesAsMaps = new ArrayList<>();
  130. for (CoveredFileDoc coveredFile : coveredFiles) {
  131. coveredFilesAsMaps.add(coveredFile.getFields());
  132. }
  133. setField(FIELD_COVERED_FILES, coveredFilesAsMaps);
  134. return this;
  135. }
  136. }