Search in sources :

Example 6 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class AnalysisContextReportPublisherTest method prepare.

@Before
public void prepare() throws Exception {
    logTester.setLevel(LoggerLevel.INFO);
    system2 = mock(System2.class);
    when(system2.properties()).thenReturn(new Properties());
    projectRepos = mock(ProjectRepositories.class);
    globalSettings = mock(GlobalSettings.class);
    publisher = new AnalysisContextReportPublisher(analysisMode, pluginRepo, system2, projectRepos, globalSettings);
}
Also used : System2(org.sonar.api.utils.System2) GlobalSettings(org.sonar.scanner.bootstrap.GlobalSettings) Properties(java.util.Properties) ProjectRepositories(org.sonar.scanner.repository.ProjectRepositories) Before(org.junit.Before)

Example 7 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class CreateDefaultOrganization method saveDefaultOrganizationUuid.

private void saveDefaultOrganizationUuid(Context context, String uuid) throws SQLException {
    Select select = context.prepareSelect("select kee from internal_properties where kee=?");
    select.setString(1, INTERNAL_PROPERTY_DEFAULT_ORGANIZATION);
    if (select.get(row -> row.getNullableString(1)) == null) {
        context.prepareUpsert("insert into internal_properties" + " (kee, is_empty, text_value, created_at)" + " values" + " (?, ?, ?, ?)").setString(1, INTERNAL_PROPERTY_DEFAULT_ORGANIZATION).setBoolean(2, false).setString(3, uuid).setLong(4, system2.now()).execute().commit();
    }
}
Also used : SQLException(java.sql.SQLException) System2(org.sonar.api.utils.System2) Select(org.sonar.server.platform.db.migration.step.Select) UuidFactory(org.sonar.core.util.UuidFactory) Database(org.sonar.db.Database) DataChange(org.sonar.server.platform.db.migration.step.DataChange) Select(org.sonar.server.platform.db.migration.step.Select)

Example 8 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class PersistTestsStepTest method setup.

@Before
public void setup() {
    System2 system2 = mock(System2.class);
    when(system2.now()).thenReturn(now);
    underTest = new PersistTestsStep(dbClient, system2, reportReader, treeRootHolder);
    root = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren(ReportComponent.builder(Component.Type.MODULE, 2).setUuid("MODULE_UUID").setKey("MODULE_KEY").addChildren(ReportComponent.builder(Component.Type.FILE, 3).setUuid(TEST_FILE_UUID_1).setKey("TEST_FILE1_KEY").setFileAttributes(new FileAttributes(true, null, 1)).build(), ReportComponent.builder(Component.Type.FILE, 4).setUuid(TEST_FILE_UUID_2).setKey("TEST_FILE2_KEY").setFileAttributes(new FileAttributes(true, null, 1)).build(), ReportComponent.builder(Component.Type.FILE, 5).setUuid(MAIN_FILE_UUID_1).setKey("MAIN_FILE1_KEY").build(), ReportComponent.builder(Component.Type.FILE, 6).setUuid(MAIN_FILE_UUID_2).setKey("MAIN_FILE2_KEY").build()).build()).build();
    treeRootHolder.setRoot(root);
}
Also used : System2(org.sonar.api.utils.System2) FileAttributes(org.sonar.server.computation.task.projectanalysis.component.FileAttributes) Before(org.junit.Before)

Example 9 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class IssueIndexTest method setUp.

@Before
public void setUp() {
    System2 system = mock(System2.class);
    when(system.getDefaultTimeZone()).thenReturn(TimeZone.getTimeZone("GMT-1:00"));
    when(system.now()).thenReturn(System.currentTimeMillis());
    underTest = new IssueIndex(tester.client(), system, userSessionRule, new AuthorizationTypeSupport(userSessionRule));
}
Also used : System2(org.sonar.api.utils.System2) AuthorizationTypeSupport(org.sonar.server.permission.index.AuthorizationTypeSupport) Before(org.junit.Before)

Example 10 with System2

use of org.sonar.api.utils.System2 in project sonarqube by SonarSource.

the class SearchHistoryActionTest method inclusive_from_and_to_dates.

@Test
public void inclusive_from_and_to_dates() {
    project = db.components().insertProject();
    userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
    List<String> analysisDates = LongStream.rangeClosed(1, 9).mapToObj(i -> dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setCreatedAt(System2.INSTANCE.now() + i * 1_000_000_000L))).peek(a -> dbClient.measureDao().insert(dbSession, newMeasureDto(complexityMetric, project, a).setValue(Double.valueOf(a.getCreatedAt())))).map(a -> formatDateTime(a.getCreatedAt())).collect(Collectors.toList());
    db.commit();
    wsRequest.setComponent(project.getKey()).setFrom(analysisDates.get(1)).setTo(analysisDates.get(3));
    SearchHistoryResponse result = call();
    assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(1, 100, 3);
    assertThat(result.getMeasures(0).getHistoryList()).extracting(HistoryValue::getDate).containsExactly(analysisDates.get(1), analysisDates.get(2), analysisDates.get(3));
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) Protobuf.setNullable(org.sonar.core.util.Protobuf.setNullable) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DbSession(org.sonar.db.DbSession) Collections.singletonList(java.util.Collections.singletonList) PARAM_COMPONENT(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_COMPONENT) MetricTesting.newMetricDto(org.sonar.db.metric.MetricTesting.newMetricDto) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) HistoryValue(org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryValue) HistoryMeasure(org.sonarqube.ws.WsMeasures.SearchHistoryResponse.HistoryMeasure) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Collectors(org.sonar.core.util.stream.Collectors) NotFoundException(org.sonar.server.exceptions.NotFoundException) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) PARAM_TO(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_TO) ComponentTesting.newProjectDto(org.sonar.db.component.ComponentTesting.newProjectDto) MeasureTesting.newMeasureDto(org.sonar.db.measure.MeasureTesting.newMeasureDto) MediaTypes(org.sonarqube.ws.MediaTypes) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) PARAM_METRICS(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_METRICS) UserSessionRule(org.sonar.server.tester.UserSessionRule) SearchHistoryResponse(org.sonarqube.ws.WsMeasures.SearchHistoryResponse) PARAM_FROM(org.sonarqube.ws.client.measure.MeasuresWsParameters.PARAM_FROM) LongStream(java.util.stream.LongStream) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Throwables(com.google.common.base.Throwables) Paging(org.sonarqube.ws.Common.Paging) IOException(java.io.IOException) Test(org.junit.Test) STATUS_UNPROCESSED(org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED) WsActionTester(org.sonar.server.ws.WsActionTester) ValueType(org.sonar.api.measures.Metric.ValueType) Rule(org.junit.Rule) UserRole(org.sonar.api.web.UserRole) MetricDto(org.sonar.db.metric.MetricDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) SearchHistoryRequest(org.sonarqube.ws.client.measure.SearchHistoryRequest) SnapshotDto(org.sonar.db.component.SnapshotDto) SearchHistoryResponse(org.sonarqube.ws.WsMeasures.SearchHistoryResponse) Test(org.junit.Test)

Aggregations

System2 (org.sonar.api.utils.System2)15 Before (org.junit.Before)8 Test (org.junit.Test)7 DbClient (org.sonar.db.DbClient)3 File (java.io.File)2 WsTester (org.sonar.server.ws.WsTester)2 Throwables (com.google.common.base.Throwables)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 LocalDate (java.time.LocalDate)1 Arrays (java.util.Arrays)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Properties (java.util.Properties)1 LongStream (java.util.stream.LongStream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.tuple (org.assertj.core.api.Assertions.tuple)1 Rule (org.junit.Rule)1 ExpectedException (org.junit.rules.ExpectedException)1