123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- /*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
- package org.sonar.server.test.index;
-
- import com.google.common.annotations.VisibleForTesting;
- import com.google.common.collect.Maps;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import javax.annotation.CheckForNull;
- import org.sonar.server.es.BaseDoc;
-
- import static org.sonar.server.test.index.TestIndexDefinition.FIELD_COVERED_FILES;
- import static org.sonar.server.test.index.TestIndexDefinition.FIELD_DURATION_IN_MS;
- import static org.sonar.server.test.index.TestIndexDefinition.FIELD_FILE_UUID;
- import static org.sonar.server.test.index.TestIndexDefinition.FIELD_MESSAGE;
- import static org.sonar.server.test.index.TestIndexDefinition.FIELD_NAME;
- import static org.sonar.server.test.index.TestIndexDefinition.FIELD_PROJECT_UUID;
- import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STACKTRACE;
- import static org.sonar.server.test.index.TestIndexDefinition.FIELD_STATUS;
- import static org.sonar.server.test.index.TestIndexDefinition.FIELD_TEST_UUID;
-
- public class TestDoc extends BaseDoc {
-
- public TestDoc(Map<String, Object> fields) {
- super(fields);
- }
-
- @VisibleForTesting
- public TestDoc() {
- super(Maps.newHashMapWithExpectedSize(10));
- }
-
- @Override
- public String getId() {
- return testUuid();
- }
-
- @Override
- public String getRouting() {
- return projectUuid();
- }
-
- @Override
- public String getParent() {
- return null;
- }
-
- public String projectUuid() {
- return getField(FIELD_PROJECT_UUID);
- }
-
- public TestDoc setProjectUuid(String projectUuid) {
- setField(FIELD_PROJECT_UUID, projectUuid);
- return this;
- }
-
- public String fileUuid() {
- return getField(FIELD_FILE_UUID);
- }
-
- public TestDoc setFileUuid(String fileUuid) {
- setField(FIELD_FILE_UUID, fileUuid);
- return this;
- }
-
- public String testUuid() {
- return getField(FIELD_TEST_UUID);
- }
-
- public TestDoc setUuid(String testUuid) {
- setField(FIELD_TEST_UUID, testUuid);
- return this;
- }
-
- public String name() {
- return getField(FIELD_NAME);
- }
-
- public TestDoc setName(String name) {
- setField(FIELD_NAME, name);
- return this;
- }
-
- public String status() {
- return getField(FIELD_STATUS);
- }
-
- public TestDoc setStatus(String status) {
- setField(FIELD_STATUS, status);
- return this;
- }
-
- @CheckForNull
- public String message() {
- return getNullableField(FIELD_MESSAGE);
- }
-
- public TestDoc setMessage(String message) {
- setField(FIELD_MESSAGE, message);
- return this;
- }
-
- @CheckForNull
- public String stackTrace() {
- return getNullableField(FIELD_STACKTRACE);
- }
-
- public TestDoc setStackTrace(String stackTrace) {
- setField(FIELD_STACKTRACE, stackTrace);
- return this;
- }
-
- @CheckForNull
- public Long durationInMs() {
- Number number = getNullableField(FIELD_DURATION_IN_MS);
- return number == null ? null : number.longValue();
- }
-
- public TestDoc setDurationInMs(Long durationInMs) {
- setField(FIELD_DURATION_IN_MS, durationInMs);
- return this;
- }
-
- public List<CoveredFileDoc> coveredFiles() {
- List<Map<String, Object>> coveredFilesAsMaps = getNullableField(FIELD_COVERED_FILES);
- if (coveredFilesAsMaps == null) {
- return new ArrayList<>();
- }
- List<CoveredFileDoc> coveredFiles = new ArrayList<>();
- for (Map<String, Object> coveredFileMap : coveredFilesAsMaps) {
- coveredFiles.add(new CoveredFileDoc(coveredFileMap));
- }
- return coveredFiles;
- }
-
- public TestDoc setCoveredFiles(List<CoveredFileDoc> coveredFiles) {
- List<Map<String, Object>> coveredFilesAsMaps = new ArrayList<>();
- for (CoveredFileDoc coveredFile : coveredFiles) {
- coveredFilesAsMaps.add(coveredFile.getFields());
- }
- setField(FIELD_COVERED_FILES, coveredFilesAsMaps);
- return this;
- }
- }
|