import org.elasticsearch.search.sort.FieldSortBuilder;
import org.elasticsearch.search.sort.ScoreSortBuilder;
import org.elasticsearch.search.sort.SortOrder;
+import org.sonar.api.utils.System2;
import org.sonar.server.es.EsClient;
import org.sonar.server.es.SearchIdResult;
import org.sonar.server.es.SearchOptions;
private final EsClient client;
private final AuthorizationTypeSupport authorizationTypeSupport;
+ private final System2 system2;
- public ComponentIndex(EsClient client, AuthorizationTypeSupport authorizationTypeSupport) {
+ public ComponentIndex(EsClient client, AuthorizationTypeSupport authorizationTypeSupport, System2 system2) {
this.client = client;
this.authorizationTypeSupport = authorizationTypeSupport;
+ this.system2 = system2;
}
public SearchIdResult<String> search(ComponentQuery query, SearchOptions searchOptions) {
requestBuilder.setQuery(esQuery);
requestBuilder.addSort(SORTABLE_ANALYZER.subField(FIELD_NAME), SortOrder.ASC);
- return new SearchIdResult<>(requestBuilder.get(), id -> id);
+ return new SearchIdResult<>(requestBuilder.get(), id -> id, system2.getDefaultTimeZone());
}
public ComponentIndexResults searchSuggestions(SuggestionQuery query) {
package org.sonar.server.es;
import java.util.Collections;
+import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.TimeZone;
import javax.annotation.CheckForNull;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
-import static org.sonar.api.utils.DateUtils.formatDate;
import static org.sonar.api.utils.DateUtils.parseDateTime;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE_EFFORT;
private static final java.lang.String NO_DATA_PREFIX = "no_data_";
private final LinkedHashMap<String, LinkedHashMap<String, Long>> facetsByName;
+ private final TimeZone timeZone;
- public Facets(LinkedHashMap<String, LinkedHashMap<String, Long>> facetsByName) {
+ public Facets(LinkedHashMap<String, LinkedHashMap<String, Long>> facetsByName, TimeZone timeZone) {
this.facetsByName = facetsByName;
+ this.timeZone = timeZone;
}
- public Facets(SearchResponse response) {
+ public Facets(SearchResponse response, TimeZone timeZone) {
this.facetsByName = new LinkedHashMap<>();
+ this.timeZone = timeZone;
Aggregations aggregations = response.getAggregations();
if (aggregations != null) {
for (Aggregation facet : aggregations) {
private void processDateHistogram(Histogram aggregation) {
LinkedHashMap<String, Long> facet = getOrCreateFacet(aggregation.getName());
for (Histogram.Bucket value : aggregation.getBuckets()) {
- String day = formatDate(parseDateTime(value.getKeyAsString()));
+ String day = dateTimeToDate(value.getKeyAsString(), timeZone);
if (value.getAggregations().getAsMap().containsKey(FACET_MODE_EFFORT)) {
facet.put(day, Math.round(((Sum) value.getAggregations().get(FACET_MODE_EFFORT)).getValue()));
} else {
}
}
+ private static String dateTimeToDate(String timestamp, TimeZone timeZone) {
+ Date date = parseDateTime(timestamp);
+ return date.toInstant().atZone(timeZone.toZoneId()).toLocalDate().toString();
+ }
+
private void processSum(Sum aggregation) {
getOrCreateFacet(aggregation.getName()).put(TOTAL, Math.round(aggregation.getValue()));
}
import com.google.common.base.Function;
import java.util.ArrayList;
import java.util.List;
+import java.util.TimeZone;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit;
private final Facets facets;
private final long total;
- public SearchIdResult(SearchResponse response, Function<String, ID> converter) {
- this.facets = new Facets(response);
+ public SearchIdResult(SearchResponse response, Function<String, ID> converter, TimeZone timeZone) {
+ this.facets = new Facets(response, timeZone);
this.total = response.getHits().getTotalHits();
this.ids = convertToIds(response.getHits(), converter);
}
import java.util.List;
import java.util.Map;
+import java.util.TimeZone;
import java.util.function.Function;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.elasticsearch.action.search.SearchResponse;
private final Facets facets;
private final long total;
- public SearchResult(SearchResponse response, Function<Map<String, Object>, DOC> converter) {
- this.facets = new Facets(response);
+ public SearchResult(SearchResponse response, Function<Map<String, Object>, DOC> converter, TimeZone timeZone) {
+ this.facets = new Facets(response, timeZone);
this.total = response.getHits().getTotalHits();
this.docs = EsUtils.convertToDocs(response.getHits(), converter);
}
import org.sonar.api.issue.DefaultTransitions;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.rules.RuleType;
+import org.sonar.api.utils.System2;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueChangeContext;
import org.sonar.db.DbClient;
private final ProjectConfigurationLoader projectConfigurationLoader;
private final WebhookPayloadFactory webhookPayloadFactory;
private final IssueIndex issueIndex;
+ private final System2 system2;
public IssueChangeWebhookImpl(DbClient dbClient, WebHooks webhooks, ProjectConfigurationLoader projectConfigurationLoader,
- WebhookPayloadFactory webhookPayloadFactory, IssueIndex issueIndex) {
+ WebhookPayloadFactory webhookPayloadFactory, IssueIndex issueIndex, System2 system2) {
this.dbClient = dbClient;
this.webhooks = webhooks;
this.projectConfigurationLoader = projectConfigurationLoader;
this.webhookPayloadFactory = webhookPayloadFactory;
this.issueIndex = issueIndex;
+ this.system2 = system2;
}
@Override
return webhookPayloadFactory.create(projectAnalysis);
}
- private static QualityGate createQualityGate(ComponentDto branch, IssueIndex issueIndex) {
+ private QualityGate createQualityGate(ComponentDto branch, IssueIndex issueIndex) {
SearchResponse searchResponse = issueIndex.search(IssueQuery.builder()
.projectUuids(singletonList(branch.getMainBranchProjectUuid()))
.branchUuid(branch.uuid())
.checkAuthorization(false)
.build(),
new SearchOptions().addFacets(RuleIndex.FACET_TYPES));
- LinkedHashMap<String, Long> typeFacet = new Facets(searchResponse)
+ LinkedHashMap<String, Long> typeFacet = new Facets(searchResponse, system2.getDefaultTimeZone())
.get(RuleIndex.FACET_TYPES);
Set<QualityGate.Condition> conditions = ShortLivingBranchQualityGate.CONDITIONS.stream()
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.Param;
import org.sonar.api.utils.Paging;
+import org.sonar.api.utils.System2;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.server.es.Facets;
import org.sonar.server.es.SearchOptions;
private final IssueQueryFactory issueQueryFactory;
private final SearchResponseLoader searchResponseLoader;
private final SearchResponseFormat searchResponseFormat;
+ private final System2 system2;
public SearchAction(UserSession userSession, IssueIndex issueIndex, IssueQueryFactory issueQueryFactory,
- SearchResponseLoader searchResponseLoader, SearchResponseFormat searchResponseFormat) {
+ SearchResponseLoader searchResponseLoader, SearchResponseFormat searchResponseFormat, System2 system2) {
this.userSession = userSession;
this.issueIndex = issueIndex;
this.issueQueryFactory = issueQueryFactory;
this.searchResponseLoader = searchResponseLoader;
this.searchResponseFormat = searchResponseFormat;
+ this.system2 = system2;
}
@Override
collectRequestParams(collector, request);
Facets facets = null;
if (!options.getFacets().isEmpty()) {
- facets = new Facets(result);
+ facets = new Facets(result, system2.getDefaultTimeZone());
// add missing values to facets. For example if assignee "john" and facet on "assignees" are requested, then
// "john" should always be listed in the facet. If it is not present, then it is added with value zero.
// This is a constraint from webapp UX.
return options;
}
- private static Facets reorderFacets(@Nullable Facets facets, Collection<String> orderedNames) {
+ private Facets reorderFacets(@Nullable Facets facets, Collection<String> orderedNames) {
if (facets == null) {
return null;
}
orderedFacets.put(facetName, facet);
}
}
- return new Facets(orderedFacets);
+ return new Facets(orderedFacets, system2.getDefaultTimeZone());
}
private void completeFacets(Facets facets, SearchWsRequest request, Request wsRequest) {
import org.elasticsearch.search.sort.FieldSortBuilder;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.System2;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.server.es.DefaultIndexSettingsElement;
import org.sonar.server.es.EsClient;
private final EsClient client;
private final AuthorizationTypeSupport authorizationTypeSupport;
+ private final System2 system2;
- public ProjectMeasuresIndex(EsClient client, AuthorizationTypeSupport authorizationTypeSupport) {
+ public ProjectMeasuresIndex(EsClient client, AuthorizationTypeSupport authorizationTypeSupport, System2 system2) {
this.client = client;
this.authorizationTypeSupport = authorizationTypeSupport;
+ this.system2 = system2;
}
public SearchIdResult<String> search(ProjectMeasuresQuery query, SearchOptions searchOptions) {
addFacets(requestBuilder, searchOptions, filters, query);
addSort(query, requestBuilder);
- return new SearchIdResult<>(requestBuilder.get(), id -> id);
+ return new SearchIdResult<>(requestBuilder.get(), id -> id, system2.getDefaultTimeZone());
}
public ProjectMeasuresStatistics searchTelemetryStatistics() {
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
+import org.sonar.api.utils.System2;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.qualityprofile.QProfileDto;
private static final String AGGREGATION_NAME_FOR_TAGS = "tagsAggregation";
private final EsClient client;
+ private final System2 system2;
- public RuleIndex(EsClient client) {
+ public RuleIndex(EsClient client, System2 system2) {
this.client = client;
+ this.system2 = system2;
}
public SearchIdResult<RuleKey> search(RuleQuery query, SearchOptions options) {
}
esSearch.setQuery(boolQuery().must(qb).filter(fb));
- return new SearchIdResult<>(esSearch.get(), RuleKey::parse);
+ return new SearchIdResult<>(esSearch.get(), RuleKey::parse, system2.getDefaultTimeZone());
}
/**
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.search.SearchHit;
+import org.sonar.api.utils.System2;
import org.sonar.server.es.EsClient;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.es.SearchResult;
public class TestIndex {
private final EsClient client;
+ private final System2 system2;
- public TestIndex(EsClient client) {
+ public TestIndex(EsClient client, System2 system2) {
this.client = client;
+ this.system2 = system2;
}
public List<CoveredFileDoc> coveredFiles(String testUuid) {
.setFrom(searchOptions.getOffset())
.setQuery(boolQuery().must(matchAllQuery()).filter(termQuery(FIELD_FILE_UUID, testFileUuid)));
- return new SearchResult<>(searchRequest.get(), TestDoc::new);
+ return new SearchResult<>(searchRequest.get(), TestDoc::new, system2.getDefaultTimeZone());
}
public SearchResult<TestDoc> searchBySourceFileUuidAndLineNumber(String sourceFileUuid, int lineNumber, SearchOptions searchOptions) {
.must(termQuery(FIELD_COVERED_FILES + "." + FIELD_COVERED_FILE_LINES, lineNumber)),
ScoreMode.Avg));
- return new SearchResult<>(searchRequest.get(), TestDoc::new);
+ return new SearchResult<>(searchRequest.get(), TestDoc::new, system2.getDefaultTimeZone());
}
public TestDoc getByTestUuid(String testUuid) {
.setFrom(searchOptions.getOffset())
.setQuery(boolQuery().must(matchAllQuery()).filter(termQuery(FIELD_TEST_UUID, testUuid)));
- return new SearchResult<>(searchRequest.get(), TestDoc::new);
+ return new SearchResult<>(searchRequest.get(), TestDoc::new, system2.getDefaultTimeZone());
}
}
import org.elasticsearch.search.sort.SortOrder;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.System2;
import org.sonar.server.es.EsClient;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.es.SearchResult;
public class UserIndex {
private final EsClient esClient;
+ private final System2 system2;
- public UserIndex(EsClient esClient) {
+ public UserIndex(EsClient esClient, System2 system2) {
this.esClient = esClient;
+ this.system2 = system2;
}
@CheckForNull
request.setQuery(boolQuery().must(esQuery).filter(filter));
- return new SearchResult<>(request.get(), UserDoc::new);
+ return new SearchResult<>(request.get(), UserDoc::new, system2.getDefaultTimeZone());
}
}
private ComponentIndexer indexer = new ComponentIndexer(db.getDbClient(), es.client());
private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, indexer);
- private ComponentIndex underTest = new ComponentIndex(es.client(), new AuthorizationTypeSupport(userSession));
+ private ComponentIndex underTest = new ComponentIndex(es.client(), new AuthorizationTypeSupport(userSession), System2.INSTANCE);
@Test
public void filter_by_language() {
public ComponentTextSearchFeatureRule features = new ComponentTextSearchFeatureRule();
protected ComponentIndexer indexer = new ComponentIndexer(db.getDbClient(), es.client());
- protected ComponentIndex index = new ComponentIndex(es.client(), new AuthorizationTypeSupport(userSession));
+ protected ComponentIndex index = new ComponentIndex(es.client(), new AuthorizationTypeSupport(userSession), System2.INSTANCE);
protected PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, indexer);
private OrganizationDto organization;
private Languages languages = mock(Languages.class);
private ComponentIndexer indexer = new ComponentIndexer(db.getDbClient(), es.client());
private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, indexer);
- private ComponentIndex index = new ComponentIndex(es.client(), new AuthorizationTypeSupport(userSession));
+ private ComponentIndex index = new ComponentIndex(es.client(), new AuthorizationTypeSupport(userSession), System2.INSTANCE);
private UserDto user;
private DbSession dbSession = db.getSession();
private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, new ProjectMeasuresIndexer(dbClient, es.client()));
- private ProjectMeasuresIndex index = new ProjectMeasuresIndex(es.client(), new AuthorizationTypeSupport(userSession));
+ private ProjectMeasuresIndex index = new ProjectMeasuresIndex(es.client(), new AuthorizationTypeSupport(userSession), System2.INSTANCE);
private ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(db.getDbClient(), es.client());
private WsActionTester ws = new WsActionTester(
private ComponentIndexer componentIndexer = new ComponentIndexer(db.getDbClient(), es.client());
private FavoriteFinder favoriteFinder = mock(FavoriteFinder.class);
- private ComponentIndex index = new ComponentIndex(es.client(), new AuthorizationTypeSupport(userSessionRule));
+ private ComponentIndex index = new ComponentIndex(es.client(), new AuthorizationTypeSupport(userSessionRule), System2.INSTANCE);
private SuggestionsAction underTest = new SuggestionsAction(db.getDbClient(), index, favoriteFinder, userSessionRule, resourceTypes);
private OrganizationDto organization;
private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, componentIndexer);
import java.util.Collections;
import org.junit.Test;
import org.sonar.api.config.internal.MapSettings;
+import org.sonar.api.utils.System2;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.server.es.EsTester;
.setScmAccounts(asList("charlie", "jesuis@charlie.com"));
esTester.putDocuments(UserIndexDefinition.INDEX_TYPE_USER.getIndex(), UserIndexDefinition.INDEX_TYPE_USER.getType(), user);
- UserIndex index = new UserIndex(esTester.client());
+ UserIndex index = new UserIndex(esTester.client(), System2.INSTANCE);
ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index);
assertThat(underTest.load("missing")).isNull();
.setScmAccounts(asList("charlie"));
esTester.putDocuments(UserIndexDefinition.INDEX_TYPE_USER.getIndex(), UserIndexDefinition.INDEX_TYPE_USER.getType(), user2);
- UserIndex index = new UserIndex(esTester.client());
+ UserIndex index = new UserIndex(esTester.client(), System2.INSTANCE);
ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index);
assertThat(underTest.load("charlie")).isNull();
@Test
public void load_by_multiple_scm_accounts_is_not_supported_yet() {
- UserIndex index = new UserIndex(esTester.client());
+ UserIndex index = new UserIndex(esTester.client(), System2.INSTANCE);
ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index);
try {
underTest.loadAll(Collections.<String>emptyList());
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.System2;
+import org.sonar.api.utils.internal.TestSystem2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.DEPRECATED_FACET_MODE_DEBT;
import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE_EFFORT;
public class IssueIndexDebtTest {
- private System2 system2 = System2.INSTANCE;
+ private System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(TimeZone.getTimeZone("GMT-01:00"));
@Rule
public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings().asConfig()), new ViewIndexDefinition(new MapSettings().asConfig()));
@Before
public void setUp() {
- System2 system = mock(System2.class);
- when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("+01:00"));
- when(system.now()).thenReturn(System.currentTimeMillis());
- underTest = new IssueIndex(es.client(), system, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
+ underTest = new IssueIndex(es.client(), system2, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
}
@Test
}
private Facets search(String additionalFacet) {
- return new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(asList(additionalFacet))));
+ return new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(asList(additionalFacet))), system2.getDefaultTimeZone());
}
@Test
IssueDocTesting.newDoc("I3", file).setAssignee("simon").setEffort(10L),
IssueDocTesting.newDoc("I4", file).setAssignee(null).setEffort(10L));
- Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(asList("assignees"))));
+ Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(asList("assignees"))), system2.getDefaultTimeZone());
assertThat(facets.getNames()).containsOnly("assignees", FACET_MODE_EFFORT);
assertThat(facets.get("assignees")).containsOnly(entry("steph", 10L), entry("simon", 20L), entry("", 10L));
assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 40L));
IssueDocTesting.newDoc("I3", file).setAuthorLogin("simon").setEffort(10L),
IssueDocTesting.newDoc("I4", file).setAuthorLogin(null).setEffort(10L));
- Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(asList("authors"))));
+ Facets facets = new Facets(underTest.search(newQueryBuilder().build(), new SearchOptions().addFacets(asList("authors"))), system2.getDefaultTimeZone());
assertThat(facets.getNames()).containsOnly("authors", FACET_MODE_EFFORT);
assertThat(facets.get("authors")).containsOnly(entry("steph", 10L), entry("simon", 20L));
assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 40L));
SearchOptions searchOptions = fixtureForCreatedAtFacet();
Builder query = newQueryBuilder().createdBefore(DateUtils.parseDateTime("2016-01-01T00:00:00+0100"));
- Map<String, Long> createdAt = new Facets(underTest.search(query.build(), searchOptions)).get("createdAt");
+ Map<String, Long> createdAt = new Facets(underTest.search(query.build(), searchOptions), system2.getDefaultTimeZone()).get("createdAt");
assertThat(createdAt).containsOnly(
entry("2011-01-01", 10L),
entry("2012-01-01", 0L),
IssueDocTesting.newDoc("I3", ComponentTesting.newFileDto(project2, null)).setEffort(10L));
Facets facets = new Facets(underTest.search(IssueQuery.builder().facetMode(DEPRECATED_FACET_MODE_DEBT).build(),
- new SearchOptions().addFacets(asList("projectUuids"))));
+ new SearchOptions().addFacets(asList("projectUuids"))), system2.getDefaultTimeZone());
assertThat(facets.getNames()).containsOnly("projectUuids", FACET_MODE_EFFORT);
assertThat(facets.get("projectUuids")).containsOnly(entry("ABCD", 20L), entry("EFGH", 10L));
assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 30L));
import org.assertj.core.groups.Tuple;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.utils.System2;
+import org.sonar.api.utils.internal.TestSystem2;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.api.Assertions.tuple;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
import static org.sonar.api.issue.Issue.RESOLUTION_FIXED;
import static org.sonar.api.rules.RuleType.BUG;
import static org.sonar.api.rules.RuleType.CODE_SMELL;
public UserSessionRule userSessionRule = UserSessionRule.standalone();
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private System2 system2 = mock(System2.class);
+ private System2 system2 = new TestSystem2().setNow(1_500_000_000_000L).setDefaultTimeZone(TimeZone.getTimeZone("GMT-01:00"));
@Rule
public DbTester db = DbTester.create(system2);
private IssueIndexer issueIndexer = new IssueIndexer(es.client(), db.getDbClient(), new IssueIteratorFactory(db.getDbClient()));
private IssueIndex underTest = new IssueIndex(es.client(), system2, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
- @Before
- public void setUp() {
- when(system2.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("GMT-1:00"));
- when(system2.now()).thenReturn(System.currentTimeMillis());
- }
-
@Test
public void filter_by_keys() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto());
.checkAuthorization(false)
.build();
SearchResponse result = underTest.search(query, options);
- Map<String, Long> buckets = new Facets(result).get("createdAt");
+ Map<String, Long> buckets = new Facets(result, system2.getDefaultTimeZone()).get("createdAt");
assertThat(buckets).containsOnly(
entry("2014-08-31", 0L),
entry("2014-09-01", 2L),
.createdAfter(parseDateTime("2014-09-01T00:00:00+0100"))
.createdBefore(parseDateTime("2014-09-21T00:00:00+0100")).build(),
options);
- Map<String, Long> createdAt = new Facets(result).get("createdAt");
+ Map<String, Long> createdAt = new Facets(result, system2.getDefaultTimeZone()).get("createdAt");
assertThat(createdAt).containsOnly(
entry("2014-08-25", 0L),
entry("2014-09-01", 4L),
.createdAfter(parseDateTime("2014-09-01T00:00:00+0100"))
.createdBefore(parseDateTime("2015-01-19T00:00:00+0100")).build(),
options);
- Map<String, Long> createdAt = new Facets(result).get("createdAt");
+ Map<String, Long> createdAt = new Facets(result, system2.getDefaultTimeZone()).get("createdAt");
assertThat(createdAt).containsOnly(
entry("2014-08-01", 0L),
entry("2014-09-01", 5L),
.createdAfter(parseDateTime("2011-01-01T00:00:00+0100"))
.createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(),
options);
- Map<String, Long> createdAt = new Facets(result).get("createdAt");
+ Map<String, Long> createdAt = new Facets(result, system2.getDefaultTimeZone()).get("createdAt");
assertThat(createdAt).containsOnly(
entry("2010-01-01", 0L),
entry("2011-01-01", 1L),
.createdAfter(parseDateTime("2014-09-01T00:00:00-0100"))
.createdBefore(parseDateTime("2014-09-02T00:00:00-0100")).build(),
options);
- Map<String, Long> createdAt = new Facets(result).get("createdAt");
+ Map<String, Long> createdAt = new Facets(result, system2.getDefaultTimeZone()).get("createdAt");
assertThat(createdAt).containsOnly(
entry("2014-09-01", 2L));
}
.createdAfter(parseDateTime("2009-01-01T00:00:00+0100"))
.createdBefore(parseDateTime("2016-01-01T00:00:00+0100"))
.build(), options);
- Map<String, Long> createdAt = new Facets(result).get("createdAt");
+ Map<String, Long> createdAt = new Facets(result, system2.getDefaultTimeZone()).get("createdAt");
assertThat(createdAt).containsOnly(
entry("2008-01-01", 0L),
entry("2009-01-01", 0L),
SearchResponse result = underTest.search(IssueQuery.builder()
.createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(),
searchOptions);
- Map<String, Long> createdAt = new Facets(result).get("createdAt");
+ Map<String, Long> createdAt = new Facets(result, system2.getDefaultTimeZone()).get("createdAt");
assertThat(createdAt).containsOnly(
entry("2011-01-01", 1L),
entry("2012-01-01", 0L),
SearchOptions searchOptions = new SearchOptions().addFacets("createdAt");
SearchResponse result = underTest.search(IssueQuery.builder().build(), searchOptions);
- Map<String, Long> createdAt = new Facets(result).get("createdAt");
+ Map<String, Long> createdAt = new Facets(result, system2.getDefaultTimeZone()).get("createdAt");
assertThat(createdAt).isNull();
}
private void assertThatFacetHasExactly(IssueQuery.Builder query, String facet, Map.Entry<String, Long>... expectedEntries) {
SearchResponse result = underTest.search(query.build(), new SearchOptions().addFacets(asList(facet)));
- Facets facets = new Facets(result);
+ Facets facets = new Facets(result, system2.getDefaultTimeZone());
assertThat(facets.getNames()).containsOnly(facet);
assertThat(facets.get(facet)).containsExactly(expectedEntries);
}
private void assertThatFacetHasOnly(IssueQuery.Builder query, String facet, Map.Entry<String, Long>... expectedEntries) {
SearchResponse result = underTest.search(query.build(), new SearchOptions().addFacets(asList(facet)));
- Facets facets = new Facets(result);
+ Facets facets = new Facets(result, system2.getDefaultTimeZone());
assertThat(facets.getNames()).containsOnly(facet);
assertThat(facets.get(facet)).containsOnly(expectedEntries);
}
private IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
private DbClient spiedOnDbClient = spy(dbClient);
private ProjectConfigurationLoader projectConfigurationLoader = mock(ProjectConfigurationLoader.class);
- private IssueChangeWebhookImpl underTest = new IssueChangeWebhookImpl(spiedOnDbClient, webHooks, projectConfigurationLoader, webhookPayloadFactory, issueIndex);
+ private IssueChangeWebhookImpl underTest = new IssueChangeWebhookImpl(spiedOnDbClient, webHooks, projectConfigurationLoader, webhookPayloadFactory, issueIndex, System2.INSTANCE);
private DbClient mockedDbClient = mock(DbClient.class);
private IssueIndex spiedOnIssueIndex = spy(issueIndex);
- private IssueChangeWebhookImpl mockedUnderTest = new IssueChangeWebhookImpl(mockedDbClient, webHooks, projectConfigurationLoader, webhookPayloadFactory, spiedOnIssueIndex);
+ private IssueChangeWebhookImpl mockedUnderTest = new IssueChangeWebhookImpl(mockedDbClient, webHooks, projectConfigurationLoader, webhookPayloadFactory, spiedOnIssueIndex, System2.INSTANCE);
@Test
public void on_type_change_has_no_effect_if_SearchResponseData_has_no_issue() {
private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), new WsResponseCommonFormat(languages), languages, new AvatarResolverImpl());
private PermissionIndexerTester permissionIndexer = new PermissionIndexerTester(es, issueIndexer);
- private WsActionTester ws = new WsActionTester(new SearchAction(userSession, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat));
+ private WsActionTester ws = new WsActionTester(new SearchAction(userSession, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat, System2.INSTANCE));
@Test
public void search_all_issues_when_no_parameter() {
private SearchResponseLoader searchResponseLoader = new SearchResponseLoader(userSessionRule, dbClient, new TransitionService(userSessionRule, issueWorkflow));
private Languages languages = new Languages();
private SearchResponseFormat searchResponseFormat = new SearchResponseFormat(new Durations(), new WsResponseCommonFormat(languages), languages, new AvatarResolverImpl());
- private WsActionTester ws = new WsActionTester(new SearchAction(userSessionRule, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat));
+ private WsActionTester ws = new WsActionTester(new SearchAction(userSessionRule, issueIndex, issueQueryFactory, searchResponseLoader, searchResponseFormat, System2.INSTANCE));
private OrganizationDto defaultOrganization;
private OrganizationDto otherOrganization1;
private OrganizationDto otherOrganization2;
private RuleIndexer ruleIndexer = new RuleIndexer(esTester.client(), dbTester.getDbClient());
private PermissionIndexerTester permissionIndexerTester = new PermissionIndexerTester(esTester, issueIndexer);
private IssueIndex issueIndex = new IssueIndex(esTester.client(), System2.INSTANCE, userSession, new AuthorizationTypeSupport(userSession));
- private RuleIndex ruleIndex = new RuleIndex(esTester.client());
+ private RuleIndex ruleIndex = new RuleIndex(esTester.client(), System2.INSTANCE);
private WsActionTester ws = new WsActionTester(new TagsAction(issueIndex, ruleIndex, dbTester.getDbClient(), TestDefaultOrganizationProvider.from(dbTester)));
private OrganizationDto organization;
import org.junit.runner.RunWith;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.utils.System2;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
private ProjectMeasuresIndexer projectMeasureIndexer = new ProjectMeasuresIndexer(null, es.client());
private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, projectMeasureIndexer);
- private ProjectMeasuresIndex underTest = new ProjectMeasuresIndex(es.client(), new AuthorizationTypeSupport(userSession));
+ private ProjectMeasuresIndex underTest = new ProjectMeasuresIndex(es.client(), new AuthorizationTypeSupport(userSession), System2.INSTANCE);
@Test
public void return_empty_if_no_projects() {
import org.junit.rules.ExpectedException;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.utils.System2;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
private ProjectMeasuresIndexer projectMeasureIndexer = new ProjectMeasuresIndexer(null, es.client());
private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, projectMeasureIndexer);
- private ProjectMeasuresIndex underTest = new ProjectMeasuresIndex(es.client(), new AuthorizationTypeSupport(userSession));
+ private ProjectMeasuresIndex underTest = new ProjectMeasuresIndex(es.client(), new AuthorizationTypeSupport(userSession), System2.INSTANCE);
@Test
public void match_exact_case_insensitive_name() {
private OrganizationValidation organizationValidation = mock(OrganizationValidation.class);
private MapSettings settings = new MapSettings();
private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
- private UserIndex userIndex = new UserIndex(es.client());
+ private UserIndex userIndex = new UserIndex(es.client(), system2);
private DefaultGroupCreator defaultGroupCreator = new DefaultGroupCreatorImpl(dbClient);
private OrganizationCreationImpl underTest = new OrganizationCreationImpl(dbClient, system2, uuidFactory, organizationValidation, settings.asConfig(), userIndexer,
builtInQProfileRepositoryRule, defaultGroupCreator);
import org.junit.rules.ExpectedException;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot();
@Rule
public EsTester es = new EsTester(new UserIndexDefinition(new MapSettings().asConfig()));
- private UserIndex userIndex = new UserIndex(es.client());
+ private UserIndex userIndex = new UserIndex(es.client(), System2.INSTANCE);
@Rule
public DbTester db = DbTester.create();
private DbClient dbClient = db.getDbClient();
private UuidFactory uuidFactory = mock(UuidFactory.class);
private OrganizationValidation organizationValidation = new OrganizationValidationImpl();
private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
- private UserIndex userIndex = new UserIndex(es.client());
+ private UserIndex userIndex = new UserIndex(es.client(), System2.INSTANCE);
private OrganizationCreation organizationCreation = new OrganizationCreationImpl(dbClient, system2, uuidFactory, organizationValidation, settings.asConfig(), userIndexer,
mock(BuiltInQProfileRepository.class), new DefaultGroupCreatorImpl(dbClient));
private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone().setEnabled(true);
private TestOrganizationFlags organizationFlags = TestOrganizationFlags.standalone().setEnabled(true);
private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
private QProfileFactory qProfileFactory = new QProfileFactoryImpl(dbClient, mock(UuidFactory.class), System2.INSTANCE, mock(ActiveRuleIndexer.class));
- private UserIndex userIndex = new UserIndex(es.client());
+ private UserIndex userIndex = new UserIndex(es.client(), System2.INSTANCE);
private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
private WsActionTester wsTester = new WsActionTester(new DeleteAction(userSession, dbClient, defaultOrganizationProvider, componentCleanerService, organizationFlags, userIndexer, qProfileFactory));
import org.junit.rules.ExpectedException;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();
- private UserIndex userIndex = new UserIndex(es.client());
+ private UserIndex userIndex = new UserIndex(es.client(), System2.INSTANCE);
private UserIndexer userIndexer = new UserIndexer(dbClient, es.client());
private WsActionTester ws = new WsActionTester(new RemoveMemberAction(dbClient, userSession, userIndexer));
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.server.ws.WebService.Param;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
private DefaultOrganizationProvider organizationProvider = TestDefaultOrganizationProvider.from(db);
private UserIndexer indexer = new UserIndexer(dbClient, es.client());
- private WsActionTester ws = new WsActionTester(new SearchMembersAction(dbClient, new UserIndex(es.client()), organizationProvider, userSession, new AvatarResolverImpl()));
+ private WsActionTester ws = new WsActionTester(new SearchMembersAction(dbClient, new UserIndex(es.client(), System2.INSTANCE), organizationProvider, userSession, new AvatarResolverImpl()));
private SearchMembersWsRequest request = new SearchMembersWsRequest();
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.System2;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.organization.OrganizationDto;
private ProjectMeasuresIndexer projectMeasureIndexer = new ProjectMeasuresIndexer(null, es.client());
private PermissionIndexerTester authorizationIndexerTester = new PermissionIndexerTester(es, projectMeasureIndexer);
- private ProjectMeasuresIndex index = new ProjectMeasuresIndex(es.client(), new AuthorizationTypeSupport(userSession));
+ private ProjectMeasuresIndex index = new ProjectMeasuresIndex(es.client(), new AuthorizationTypeSupport(userSession), System2.INSTANCE);
private WsActionTester ws = new WsActionTester(new SearchAction(index));
ruleActivator = new RuleActivator(
System2.INSTANCE,
db,
- new RuleIndex(esTester.client()),
+ new RuleIndex(esTester.client(), System2.INSTANCE),
new RuleActivatorContextFactory(db),
new TypeValidations(singletonList(new IntegerTypeValidation())),
new ActiveRuleIndexer(db, esTester.client()),
public EsTester es = new EsTester(RuleIndexDefinition.createForTest(new MapSettings().asConfig()));
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
- private RuleIndex ruleIndex = new RuleIndex(es.client());
+ private RuleIndex ruleIndex = new RuleIndex(es.client(), system2);
private RuleActivatorContextFactory contextFactory = new RuleActivatorContextFactory(db.getDbClient());
private ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(db.getDbClient(), es.client());
private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
dbClient = db.getDbClient();
dbSession = db.getSession();
EsClient esClient = esTester.client();
- ruleIndex = new RuleIndex(esClient);
+ ruleIndex = new RuleIndex(esClient, System2.INSTANCE);
ruleIndexer = new RuleIndexer(esClient, dbClient);
activeRuleIndexer = new ActiveRuleIndexer(dbClient, esClient);
RuleActivatorContextFactory ruleActivatorContextFactory = new RuleActivatorContextFactory(dbClient);
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();
- private RuleIndex ruleIndex = new RuleIndex(es.client());
+ private RuleIndex ruleIndex = new RuleIndex(es.client(), System2.INSTANCE);
private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), dbClient);
private ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(dbClient, es.client());
private ProfileImporter[] profileImporters = createImporters();
ruleActivator = new RuleActivator(
System2.INSTANCE,
dbClient,
- new RuleIndex(esClient),
+ new RuleIndex(esClient, System2.INSTANCE),
new RuleActivatorContextFactory(dbClient),
new TypeValidations(new ArrayList<>()),
activeRuleIndexer,
private DbClient dbClient = dbTester.getDbClient();
private DbSession dbSession = dbTester.getSession();
- private RuleIndex ruleIndex = new RuleIndex(esTester.client());
+ private RuleIndex ruleIndex = new RuleIndex(esTester.client(), System2.INSTANCE);
private RuleIndexer ruleIndexer = new RuleIndexer(esTester.client(), dbClient);
private ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(dbClient, esTester.client());
private RuleActivatorContextFactory ruleActivatorContextFactory = new RuleActivatorContextFactory(dbClient);
import org.sonar.api.resources.Languages;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.db.rule.RuleDefinitionDto;
private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
private ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(db.getDbClient(), es.client());
- private RuleIndex ruleIndex = new RuleIndex(es.client());
+ private RuleIndex ruleIndex = new RuleIndex(es.client(), System2.INSTANCE);
private WsActionTester ws = new WsActionTester(
new ShowAction(db.getDbClient(), new QProfileWsSupport(db.getDbClient(), userSession, TestDefaultOrganizationProvider.from(db)), LANGUAGES, ruleIndex));
public void before() {
when(system.now()).thenReturn(DATE1.getTime());
ruleIndexer = new RuleIndexer(esTester.client(), dbClient);
- ruleIndex = new RuleIndex(esTester.client());
+ ruleIndex = new RuleIndex(esTester.client(), system);
activeRuleIndexer = new ActiveRuleIndexer(dbClient, esTester.client());
defaultOrganization = dbTester.getDefaultOrganization();
}
@Rule
public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
- private RuleIndex ruleIndex = new RuleIndex(es.client());
+ private RuleIndex ruleIndex = new RuleIndex(es.client(), system2);
private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), dbTester.getDbClient());
private DbSession dbSession = dbTester.getSession();
@Rule
public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
- private RuleIndex ruleIndex = new RuleIndex(es.client());
+ private RuleIndex ruleIndex = new RuleIndex(es.client(), system2);
private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
private DbSession dbSession = db.getSession();
private TestDefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
public void setUp() {
ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
activeRuleIndexer = new ActiveRuleIndexer(db.getDbClient(), es.client());
- underTest = new RuleIndex(es.client());
+ underTest = new RuleIndex(es.client(), system2);
}
@Test
public EsTester es = new EsTester(new RuleIndexDefinition(new MapSettings().asConfig()));
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private RuleIndex ruleIndex = new RuleIndex(es.client());
+ private RuleIndex ruleIndex = new RuleIndex(es.client() ,system2);
private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), db.getDbClient());
private ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(db.getDbClient(), es.client());
private Languages languages = LanguageTesting.newLanguages(JAVA, "js");
import org.junit.Test;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
private DbClient dbClient = db.getDbClient();
private EsClient esClient = es.client();
- private RuleIndex ruleIndex = new RuleIndex(esClient);
+ private RuleIndex ruleIndex = new RuleIndex(esClient, System2.INSTANCE);
private RuleIndexer ruleIndexer = new RuleIndexer(esClient, dbClient);
private WsActionTester ws = new WsActionTester(new org.sonar.server.rule.ws.TagsAction(ruleIndex, dbClient, TestDefaultOrganizationProvider.from(db)));
private ProjectMeasuresIndexer projectMeasuresIndexer = new ProjectMeasuresIndexer(db.getDbClient(), es.client());
private UserIndexer userIndexer = new UserIndexer(db.getDbClient(), es.client());
- private TelemetryDaemon underTest = new TelemetryDaemon(new TelemetryDataLoader(server, db.getDbClient(), pluginRepository, new UserIndex(es.client()),
- new ProjectMeasuresIndex(es.client(), null)), client, settings.asConfig(), internalProperties, system2);
+ private TelemetryDaemon underTest = new TelemetryDaemon(new TelemetryDataLoader(server, db.getDbClient(), pluginRepository, new UserIndex(es.client(), system2),
+ new ProjectMeasuresIndex(es.client(), null, system2)), client, settings.asConfig(), internalProperties, system2);
@After
public void tearDown() throws Exception {
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.internal.MapSettings;
+import org.sonar.api.utils.System2;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchOptions;
@Rule
public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings().asConfig()));
- TestIndex underTest = new TestIndex(es.client());
+ TestIndex underTest = new TestIndex(es.client(), System2.INSTANCE);
@Test
public void coveredFiles() throws Exception {
import org.junit.rules.ExpectedException;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.System2;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
@Rule
public DbTester db = DbTester.create();
- private TestIndex testIndex = new TestIndex(es.client());
+ private TestIndex testIndex = new TestIndex(es.client(), System2.INSTANCE);
private TestIndexer testIndexer = new TestIndexer(db.getDbClient(), es.client());
private WsActionTester ws = new WsActionTester(new CoveredFilesAction(db.getDbClient(), testIndex, userSession));
import org.junit.rules.ExpectedException;
import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.System2;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
private DbClient dbClient = db.getDbClient();
- private TestIndex testIndex = new TestIndex(es.client());
+ private TestIndex testIndex = new TestIndex(es.client(), System2.INSTANCE);
private TestIndexer testIndexer = new TestIndexer(db.getDbClient(), es.client());
private ComponentDto project;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.config.internal.MapSettings;
+import org.sonar.api.utils.System2;
import org.sonar.server.es.EsTester;
import org.sonar.server.es.SearchOptions;
@Before
public void setUp() {
- underTest = new UserIndex(esTester.client());
+ underTest = new UserIndex(esTester.client(), System2.INSTANCE);
}
@Test
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private UserIndex index = new UserIndex(esTester.client());
+ private UserIndex index = new UserIndex(esTester.client(), System2.INSTANCE);
private UserIndexer userIndexer = new UserIndexer(db.getDbClient(), esTester.client());
private GroupDto defaultGroupInDefaultOrg;
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
public UserSessionRule userSession = UserSessionRule.standalone();
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(db);
- private UserIndex index = new UserIndex(esTester.client());
+ private UserIndex index = new UserIndex(esTester.client(), system2);
private DbClient dbClient = db.getDbClient();
private UserIndexer userIndexer = new UserIndexer(dbClient, esTester.client());
private DbSession dbSession = db.getSession();
private DbClient dbClient = db.getDbClient();
private DbSession dbSession = db.getSession();
- private UserIndex index = new UserIndex(esTester.client());
+ private UserIndex index = new UserIndex(esTester.client(), system2);
private UserIndexer userIndexer = new UserIndexer(dbClient, esTester.client());
private WsTester ws = new WsTester(new UsersWs(new SearchAction(userSession, index, dbClient, new AvatarResolverImpl())));
*/
package org.sonar.api.utils.internal;
+import java.util.TimeZone;
import org.sonar.api.utils.System2;
public class TestSystem2 extends System2 {
private long now = 0L;
+ private TimeZone defaultTimeZone = getDefaultTimeZone();
public TestSystem2 setNow(long l) {
this.now = l;
}
return now;
}
+
+ public TestSystem2 setDefaultTimeZone(TimeZone defaultTimeZone) {
+ this.defaultTimeZone = defaultTimeZone;
+ return this;
+ }
+
+ @Override
+ public TimeZone getDefaultTimeZone() {
+ return defaultTimeZone;
+ }
}