123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835 |
- /*
- * 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.ce.task.projectanalysis.step;
-
- import com.tngtech.java.junit.dataprovider.DataProvider;
- import com.tngtech.java.junit.dataprovider.DataProviderRunner;
- import com.tngtech.java.junit.dataprovider.UseDataProvider;
- import java.text.SimpleDateFormat;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.Random;
- import java.util.stream.Stream;
- import javax.annotation.Nullable;
- import org.junit.Before;
- import org.junit.Rule;
- import org.junit.Test;
- import org.junit.rules.ExpectedException;
- import org.junit.runner.RunWith;
- import org.sonar.api.impl.config.MapSettings;
- import org.sonar.api.utils.MessageException;
- import org.sonar.api.utils.System2;
- import org.sonar.api.utils.log.LogAndArguments;
- import org.sonar.api.utils.log.LogTester;
- import org.sonar.api.utils.log.LoggerLevel;
- import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
- import org.sonar.ce.task.projectanalysis.analysis.Branch;
- import org.sonar.ce.task.projectanalysis.component.Component;
- import org.sonar.ce.task.projectanalysis.component.ConfigurationRepository;
- import org.sonar.ce.task.projectanalysis.component.ReportComponent;
- import org.sonar.ce.task.projectanalysis.component.TreeRootHolder;
- import org.sonar.ce.task.projectanalysis.component.TreeRootHolderRule;
- import org.sonar.ce.task.projectanalysis.period.Period;
- import org.sonar.ce.task.projectanalysis.period.PeriodHolderImpl;
- import org.sonar.ce.task.step.ComputationStep;
- import org.sonar.ce.task.step.TestComputationStepContext;
- import org.sonar.db.DbClient;
- import org.sonar.db.DbTester;
- import org.sonar.db.component.BranchDto;
- import org.sonar.db.component.BranchType;
- import org.sonar.db.component.ComponentDto;
- import org.sonar.db.component.SnapshotDto;
- import org.sonar.db.event.EventTesting;
- import org.sonar.db.organization.OrganizationDto;
-
- import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
- import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
- import static org.assertj.core.api.Assertions.assertThat;
- import static org.assertj.core.api.Assertions.fail;
- import static org.mockito.Mockito.doReturn;
- import static org.mockito.Mockito.mock;
- import static org.mockito.Mockito.verify;
- import static org.mockito.Mockito.verifyNoMoreInteractions;
- import static org.mockito.Mockito.verifyZeroInteractions;
- import static org.mockito.Mockito.when;
- import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DATE;
- import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DAYS;
- import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_MANUAL_BASELINE;
- import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION;
- import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_VERSION;
- import static org.sonar.db.component.SnapshotDto.STATUS_PROCESSED;
- import static org.sonar.db.component.SnapshotDto.STATUS_UNPROCESSED;
- import static org.sonar.db.event.EventDto.CATEGORY_VERSION;
- import static org.sonar.db.event.EventTesting.newEvent;
-
- @RunWith(DataProviderRunner.class)
- public class LoadPeriodsStepTest extends BaseStepTest {
-
- private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
-
- @Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
- @Rule
- public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
- @Rule
- public LogTester logTester = new LogTester();
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class);
- private PeriodHolderImpl periodsHolder = new PeriodHolderImpl();
- private MapSettings settings = new MapSettings();
- private ConfigurationRepository configurationRepository = mock(ConfigurationRepository.class);
- private System2 system2Mock = mock(System2.class);
-
- private LoadPeriodsStep underTest = new LoadPeriodsStep(analysisMetadataHolder, treeRootHolder, periodsHolder, system2Mock,
- dbTester.getDbClient(), configurationRepository);
-
- private Date november30th2008;
-
- @Override
- protected ComputationStep step() {
- return underTest;
- }
-
- @Before
- public void setUp() throws Exception {
- november30th2008 = DATE_FORMAT.parse("2008-11-30");
- when(analysisMetadataHolder.isLongLivingBranch()).thenReturn(true);
- }
-
- @Test
- public void no_period_on_first_analysis_and_execute_has_no_effect() {
- TreeRootHolder treeRootHolderMock = mock(TreeRootHolder.class);
- PeriodHolderImpl periodHolderMock = mock(PeriodHolderImpl.class);
- DbClient dbClientMock = mock(DbClient.class);
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(true);
-
- LoadPeriodsStep underTest = new LoadPeriodsStep(analysisMetadataHolder, treeRootHolderMock, periodHolderMock, system2Mock, dbClientMock, configurationRepository);
-
- underTest.execute(new TestComputationStepContext());
-
- verify(analysisMetadataHolder).isFirstAnalysis();
- verify(periodHolderMock).setPeriod(null);
- verifyNoMoreInteractions(analysisMetadataHolder, periodHolderMock);
- verifyZeroInteractions(treeRootHolderMock, system2Mock, dbClientMock, configurationRepository);
- }
-
- @Test
- public void feed_one_period() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L)); // 2008-11-29
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
- String textDate = "2008-11-22";
-
- settings.setProperty("sonar.leak.period", textDate);
- underTest.execute(new TestComputationStepContext());
-
- assertPeriod(LEAK_PERIOD_MODE_DATE, textDate, analysis.getCreatedAt(), analysis.getUuid());
- }
-
- @Test
- public void ignore_unprocessed_snapshots() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis1 = dbTester.components()
- .insertSnapshot(project, snapshot -> snapshot.setStatus(STATUS_UNPROCESSED).setCreatedAt(1226379600000L).setLast(false));// 2008-11-11
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(project,
- snapshot -> snapshot.setStatus(STATUS_PROCESSED).setProjectVersion("not provided").setCreatedAt(1226379600000L).setLast(false));// 2008-11-29
- dbTester.events().insertEvent(newEvent(analysis1).setName("not provided").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt()));
- dbTester.events().insertEvent(newEvent(analysis2).setName("not provided").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt()));
- when(analysisMetadataHolder.getAnalysisDate()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
-
- settings.setProperty("sonar.leak.period", "100");
- underTest.execute(new TestComputationStepContext());
-
- assertPeriod(LEAK_PERIOD_MODE_DAYS, "100", analysis2.getCreatedAt(), analysis2.getUuid());
- verifyDebugLogs("Resolving new code period by 100 days: 2008-08-22");
- }
-
- @Test
- public void feed_period_by_date() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setLast(false)); // 2008-11-11
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setLast(false)); // 2008-11-12
- SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setLast(false)); // 2008-11-20
- SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setLast(false)); // 2008-11-22
- SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setLast(true)); // 2008-11-29
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
-
- String textDate = "2008-11-22";
- settings.setProperty("sonar.leak.period", textDate);
- underTest.execute(new TestComputationStepContext());
-
- // Return analysis from given date 2008-11-22
- assertPeriod(LEAK_PERIOD_MODE_DATE, textDate, analysis4.getCreatedAt(), analysis4.getUuid());
-
- verifyDebugLogs("Resolving new code period by date: 2008-11-22");
- }
-
- @Test
- @UseDataProvider("branchTypesNotAllowedToHaveManualBaseline")
- public void feed_period_by_date_and_ignore_baseline_when_not_eligible_for_manual(BranchType branchType) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- ComponentDto branch = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(branchType));
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(branch, snapshot -> snapshot.setCreatedAt(1226379600000L).setLast(false)); // 2008-11-11
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(branch, snapshot -> snapshot.setCreatedAt(1226494680000L).setLast(false)); // 2008-11-12
- SnapshotDto analysis3 = dbTester.components().insertSnapshot(branch, snapshot -> snapshot.setCreatedAt(1227157200000L).setLast(false)); // 2008-11-20
- SnapshotDto analysis4 = dbTester.components().insertSnapshot(branch, snapshot -> snapshot.setCreatedAt(1227358680000L).setLast(false)); // 2008-11-22
- SnapshotDto analysis5 = dbTester.components().insertSnapshot(branch, snapshot -> snapshot.setCreatedAt(1227934800000L).setLast(true)); // 2008-11-29
- dbTester.getDbClient().branchDao().updateManualBaseline(dbTester.getSession(), branch.uuid(), analysis1.getUuid());
- dbTester.commit();
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setBranchOf(branch);
- setupRoot(branch);
-
- String textDate = "2008-11-22";
- settings.setProperty("sonar.leak.period", textDate);
- underTest.execute(new TestComputationStepContext());
-
- // Return analysis from given date 2008-11-22
- assertPeriod(LEAK_PERIOD_MODE_DATE, textDate, analysis4.getCreatedAt(), analysis4.getUuid());
-
- verifyDebugLogs("Resolving new code period by date: 2008-11-22");
- }
-
- @DataProvider
- public static Object[][] branchTypesNotAllowedToHaveManualBaseline() {
- return new Object[][] {
- {BranchType.SHORT},
- {BranchType.PULL_REQUEST}
- };
- }
-
- @Test
- @UseDataProvider("anyValidLeakPeriodSettingValue")
- public void do_not_fail_when_project_has_no_BranchDto(String leakPeriodSettingValue) {
- OrganizationDto organization = dbTester.organizations().insert();
- // creates row in projects but not in project_branches
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
- dbTester.components().insertSnapshot(project);
- SnapshotDto aVersionAnalysis = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setLast(false));// 2008-11-22
- dbTester.events().insertEvent(EventTesting.newEvent(aVersionAnalysis).setName("a_version").setCategory(CATEGORY_VERSION));
- dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setLast(true)); // 2008-11-29
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.getAnalysisDate()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setMetadataBranch(BranchType.LONG);
- setupRoot(project);
-
- settings.setProperty("sonar.leak.period", leakPeriodSettingValue);
- underTest.execute(new TestComputationStepContext());
- }
-
- @Test
- @UseDataProvider("anyValidLeakPeriodSettingValue")
- public void fail_with_ISE_when_manual_baseline_is_set_but_does_not_exist_in_DB(String leakPeriodSettingValue) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- dbTester.components().setManualBaseline(project, new SnapshotDto().setUuid("nonexistent"));
- setBranchOf(project);
- setupRoot(project);
-
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Analysis 'nonexistent' of project '" + project.uuid() + "' defined as manual baseline does not exist");
-
- settings.setProperty("sonar.leak.period", leakPeriodSettingValue);
- underTest.execute(new TestComputationStepContext());
- }
-
- @Test
- @UseDataProvider("anyValidLeakPeriodSettingValue")
- public void fail_with_ISE_when_manual_baseline_is_set_but_does_not_belong_to_current_project(String leakPeriodSettingValue) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- ComponentDto otherProject = dbTester.components().insertMainBranch(organization);
- SnapshotDto otherProjectAnalysis = dbTester.components().insertSnapshot(otherProject);
- dbTester.components().setManualBaseline(project, otherProjectAnalysis);
- setBranchOf(project);
- setupRoot(project);
-
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Analysis '" + otherProjectAnalysis.getUuid() + "' of project '" + project.uuid()
- + "' defined as manual baseline does not exist");
-
- settings.setProperty("sonar.leak.period", leakPeriodSettingValue);
- underTest.execute(new TestComputationStepContext());
- }
-
- @Test
- @UseDataProvider("anyValidLeakPeriodSettingValue")
- public void feed_period_by_manual_baseline_ignores_leak_period_setting(String leakPeriodSettingValue) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project);
- SnapshotDto aVersionAnalysis = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setLast(false));// 2008-11-22
- dbTester.events().insertEvent(EventTesting.newEvent(aVersionAnalysis).setName("a_version").setCategory(CATEGORY_VERSION));
- dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setLast(true)); // 2008-11-29
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.getAnalysisDate()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- dbTester.components().setManualBaseline(project, manualBaselineAnalysis);
- setBranchOf(project);
- setupRoot(project);
-
- settings.setProperty("sonar.leak.period", leakPeriodSettingValue);
- underTest.execute(new TestComputationStepContext());
-
- assertPeriod(LEAK_PERIOD_MODE_MANUAL_BASELINE, null, manualBaselineAnalysis.getCreatedAt(), manualBaselineAnalysis.getUuid());
-
- verifyDebugLogs("Resolving new code period by manual baseline");
- }
-
- @Test
- @UseDataProvider("anyValidLeakPeriodSettingValue")
- public void feed_period_by_manual_baseline_on_long_living_branch(String leakPeriodSettingValue) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- ComponentDto branch = dbTester.components().insertProjectBranch(project);
- SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(branch);
- SnapshotDto aVersionAnalysis = dbTester.components().insertSnapshot(branch, snapshot -> snapshot.setCreatedAt(1227358680000L).setLast(false));// 2008-11-22
- dbTester.events().insertEvent(EventTesting.newEvent(aVersionAnalysis).setName("a_version").setCategory(CATEGORY_VERSION));
- dbTester.components().insertSnapshot(branch, snapshot -> snapshot.setCreatedAt(1227934800000L).setLast(true)); // 2008-11-29
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.getAnalysisDate()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- dbTester.components().setManualBaseline(branch, manualBaselineAnalysis);
- setBranchOf(branch);
- setupRoot(branch);
-
- settings.setProperty("sonar.leak.period", leakPeriodSettingValue);
- underTest.execute(new TestComputationStepContext());
-
- assertPeriod(LEAK_PERIOD_MODE_MANUAL_BASELINE, null, manualBaselineAnalysis.getCreatedAt(), manualBaselineAnalysis.getUuid());
-
- verifyDebugLogs("Resolving new code period by manual baseline");
- }
-
- @DataProvider
- public static Object[][] anyValidLeakPeriodSettingValue() {
- return new Object[][] {
- // days
- {"100"},
- // date
- {"2008-11-22"},
- // previous_version keyword
- {"previous_version"},
- // an existing version event value
- {"a_version"},
- };
- }
-
- @Test
- public void feed_period_parameter_as_null_when_manual_baseline_has_no_version() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project);
- dbTester.components().setManualBaseline(project, manualBaselineAnalysis);
- setBranchOf(project);
- setupRoot(project);
-
- settings.setProperty("sonar.leak.period", "ignored");
- underTest.execute(new TestComputationStepContext());
-
- assertPeriod(LEAK_PERIOD_MODE_MANUAL_BASELINE, null, manualBaselineAnalysis.getCreatedAt(), manualBaselineAnalysis.getUuid());
- }
-
- @Test
- public void feed_period_parameter_as_null_when_manual_baseline_has_same_project_version() {
- String version = randomAlphabetic(12);
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setProjectVersion(version).setProjectVersion(version));
- dbTester.components().setManualBaseline(project, manualBaselineAnalysis);
- setBranchOf(project);
- setupRoot(project);
-
- settings.setProperty("sonar.leak.period", "ignored");
- underTest.execute(new TestComputationStepContext());
-
- assertPeriod(LEAK_PERIOD_MODE_MANUAL_BASELINE, null, manualBaselineAnalysis.getCreatedAt(), manualBaselineAnalysis.getUuid());
- }
-
- @Test
- public void feed_no_period_parameter_as_projectVersion_when_manual_baseline_has_project_version() {
- String projectVersion = randomAlphabetic(15);
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setProjectVersion(projectVersion));
- dbTester.components().setManualBaseline(project, manualBaselineAnalysis);
- setBranchOf(project);
- setupRoot(project);
-
- settings.setProperty("sonar.leak.period", "ignored");
- underTest.execute(new TestComputationStepContext());
-
- assertPeriod(LEAK_PERIOD_MODE_MANUAL_BASELINE, null, manualBaselineAnalysis.getCreatedAt(), manualBaselineAnalysis.getUuid());
- }
-
- @Test
- @UseDataProvider("projectVersionNullOrNot")
- public void feed_no_period_parameter_as_version_event_version_when_manual_baseline_has_one(@Nullable String projectVersion) {
- String eventVersion = randomAlphabetic(15);
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setProjectVersion(projectVersion));
- dbTester.events().insertEvent(EventTesting.newEvent(manualBaselineAnalysis).setCategory(CATEGORY_VERSION).setName(eventVersion));
- dbTester.components().setManualBaseline(project, manualBaselineAnalysis);
- setBranchOf(project);
- setupRoot(project);
-
- settings.setProperty("sonar.leak.period", "ignored");
- underTest.execute(new TestComputationStepContext());
-
- assertPeriod(LEAK_PERIOD_MODE_MANUAL_BASELINE, null, manualBaselineAnalysis.getCreatedAt(), manualBaselineAnalysis.getUuid());
- }
-
- @DataProvider
- public static Object[][] projectVersionNullOrNot() {
- return new Object[][] {
- {null},
- {randomAlphabetic(15)},
- };
- }
-
- private Branch setBranchOf(ComponentDto project) {
- BranchDto branchDto = dbTester.getDbClient().branchDao().selectByUuid(dbTester.getSession(), project.uuid()).get();
- return setMetadataBranch(branchDto.getBranchType());
- }
-
- private Branch setMetadataBranch(BranchType branchType) {
- Branch branch = mock(Branch.class, invoc -> {
- throw new UnsupportedOperationException();
- });
- doReturn(branchType).when(branch).getType();
- when(analysisMetadataHolder.getBranch()).thenReturn(branch);
- return branch;
- }
-
- @Test
- public void search_by_date_return_nearest_later_analysis() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setLast(false)); // 2008-11-11
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setLast(false)); // 2008-11-12
- SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setLast(false)); // 2008-11-20
- SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setLast(false)); // 2008-11-22
- SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setLast(true)); // 2008-11-29
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
-
- String date = "2008-11-13";
- settings.setProperty("sonar.leak.period", date);
- underTest.execute(new TestComputationStepContext());
-
- // Analysis form 2008-11-20
- assertPeriod(LEAK_PERIOD_MODE_DATE, date, analysis3.getCreatedAt(), analysis3.getUuid());
- verifyDebugLogs("Resolving new code period by date: 2008-11-13");
- }
-
- @Test
- public void fail_with_MessageException_if_period_is_date_after_today() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L)); // 2008-11-29
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
- String propertyValue = "2008-12-01";
- settings.setProperty("sonar.leak.period", propertyValue);
-
- verifyFailWithInvalidValueMessageException(propertyValue,
- "Invalid code period '2008-12-01': date is in the future (now: '2008-11-30')");
- }
-
- @Test
- public void fail_with_MessageException_if_date_does_not_exist() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L)); // 2008-11-29
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
- String propertyValue = "2008-11-31";
- settings.setProperty("sonar.leak.period", propertyValue);
-
- verifyFailWithInvalidValueMessageException(propertyValue,
- "Invalid code period '2008-11-31': Invalid date");
- }
-
- @Test
- public void fail_with_MessageException_if_period_is_today_but_no_analysis_today() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L)); // 2008-11-29
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
- String propertyValue = "2008-11-30";
- settings.setProperty("sonar.leak.period", propertyValue);
-
- verifyFailWithInvalidValueMessageException(propertyValue,
- "Resolving new code period by date: 2008-11-30",
- "Invalid code period '2008-11-30': No analysis found created after date '2008-11-30'");
- }
-
- @Test
- @UseDataProvider("zeroOrLess")
- public void fail_with_MessageException_if_period_is_0_or_less(int zeroOrLess) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
- String propertyValue = String.valueOf(zeroOrLess);
- settings.setProperty("sonar.leak.period", propertyValue);
-
- verifyFailWithInvalidValueMessageException(propertyValue,
- "Invalid code period '" + zeroOrLess + "': number of days is <= 0");
- }
-
- @DataProvider
- public static Object[][] zeroOrLess() {
- return new Object[][] {
- {0},
- {-1 - new Random().nextInt(30)}
- };
- }
-
- @Test
- public void fail_with_ISE_if_not_firstAnalysis_but_no_snapshot_in_DB() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
- settings.setProperty("sonar.leak.period", "previous_version");
-
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage("Attempting to resolve period while no analysis exist");
-
- underTest.execute(new TestComputationStepContext());
- }
-
- @Test
- @UseDataProvider("stringConsideredAsVersions")
- public void fail_with_MessageException_if_string_is_not_an_existing_version_event(String propertyValue) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12
- SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20
- SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22
- SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29
- dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt()));
- dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt()));
- dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION).setDate(analysis4.getCreatedAt()));
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
- settings.setProperty("sonar.leak.period", propertyValue);
-
- try {
- underTest.execute(new TestComputationStepContext());
- fail("a Message Exception should have been thrown");
- } catch (MessageException e) {
- verifyInvalidValueMessage(e, propertyValue);
- assertThat(logTester.getLogs()).hasSize(2);
- assertThat(logTester.getLogs(LoggerLevel.DEBUG))
- .hasSize(2)
- .extracting(LogAndArguments::getFormattedMsg)
- .contains("Invalid code period '" + propertyValue + "': version is none of the existing ones: [1.1, 1.0, 0.9]");
- }
- }
-
- @DataProvider
- public static Object[][] stringConsideredAsVersions() {
- return new Object[][] {
- {randomAlphabetic(5)},
- {"1,3"},
- {"1.3"},
- {"0 1"},
- {"1-SNAPSHOT"},
- {"01-12-2018"}, // unsupported date format
- };
- }
-
- @Test
- public void fail_with_MessageException_if_property_does_not_exist() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
-
- verifyFailWithInvalidValueMessageException("", "Invalid code period '': property is undefined or value is empty");
- }
-
- @Test
- public void fail_with_MessageException_if_property_is_empty() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- String propertyValue = "";
- settings.setProperty("sonar.leak.period", propertyValue);
-
- verifyFailWithInvalidValueMessageException(propertyValue, "Invalid code period '': property is undefined or value is empty");
- }
-
- private void verifyFailWithInvalidValueMessageException(String propertyValue, String debugLog, String... otherDebugLogs) {
- try {
- underTest.execute(new TestComputationStepContext());
- fail("a Message Exception should have been thrown");
- } catch (MessageException e) {
- verifyInvalidValueMessage(e, propertyValue);
- verifyDebugLogs(debugLog, otherDebugLogs);
- }
- }
-
- @Test
- public void feed_period_by_days() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setLast(false)); // 2008-11-11
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setLast(false)); // 2008-11-12
- SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setLast(false)); // 2008-11-20
- SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setLast(false)); // 2008-11-22
- SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setLast(true)); // 2008-11-29
- when(analysisMetadataHolder.getAnalysisDate()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project);
- setupBranchWithNoManualBaseline(project);
-
- settings.setProperty("sonar.leak.period", "10");
- underTest.execute(new TestComputationStepContext());
-
- // return analysis from 2008-11-20
- assertPeriod(LEAK_PERIOD_MODE_DAYS, "10", analysis3.getCreatedAt(), analysis3.getUuid());
-
- assertThat(logTester.getLogs()).hasSize(1);
- assertThat(logTester.getLogs(LoggerLevel.DEBUG))
- .extracting(LogAndArguments::getFormattedMsg)
- .containsOnly("Resolving new code period by 10 days: 2008-11-20");
- }
-
- @Test
- public void feed_period_by_previous_version() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12
- SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20
- SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22
- SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29
- dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt()));
- dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt()));
- dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION).setDate(analysis4.getCreatedAt()));
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project, "1.1");
- setupBranchWithNoManualBaseline(project);
-
- settings.setProperty("sonar.leak.period", "previous_version");
- underTest.execute(new TestComputationStepContext());
-
- // Analysis form 2008-11-12
- assertPeriod(LEAK_PERIOD_MODE_PREVIOUS_VERSION, "1.0", analysis2.getCreatedAt(), analysis2.getUuid());
-
- verifyDebugLogs("Resolving new code period by previous version: 1.0");
- }
-
- @Test
- public void feed_period_by_previous_version_with_previous_version_deleted() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12
- SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20
- dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION));
- // The "1.0" version was deleted from the history
- dbTester.events().insertEvent(newEvent(analysis3).setName("1.1").setCategory(CATEGORY_VERSION));
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project, "1.1");
- setupBranchWithNoManualBaseline(project);
-
- settings.setProperty("sonar.leak.period", "previous_version");
- underTest.execute(new TestComputationStepContext());
-
- // Analysis form 2008-11-11
- assertPeriod(LEAK_PERIOD_MODE_PREVIOUS_VERSION, "0.9", analysis1.getCreatedAt(), analysis1.getUuid());
- }
-
- @Test
- public void feed_period_by_previous_version_with_first_analysis_when_no_previous_version_found() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("1.1").setLast(false)); // 2008-11-11
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29
- dbTester.events().insertEvent(newEvent(analysis2).setName("1.1").setCategory(CATEGORY_VERSION));
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project, "1.1");
- setupBranchWithNoManualBaseline(project);
-
- settings.setProperty("sonar.leak.period", "previous_version");
- underTest.execute(new TestComputationStepContext());
-
- assertPeriod(LEAK_PERIOD_MODE_PREVIOUS_VERSION, null, analysis1.getCreatedAt(), analysis1.getUuid());
-
- verifyDebugLogs("Resolving first analysis as new code period as there is only one existing version");
- }
-
- @Test
- public void feed_period_by_previous_version_with_first_analysis_when_previous_snapshot_is_the_last_one() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(true)); // 2008-11-11
- dbTester.events().insertEvent(newEvent(analysis).setName("0.9").setCategory(CATEGORY_VERSION));
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project, "1.1");
- setupBranchWithNoManualBaseline(project);
-
- settings.setProperty("sonar.leak.period", "previous_version");
- underTest.execute(new TestComputationStepContext());
-
- assertPeriod(LEAK_PERIOD_MODE_PREVIOUS_VERSION, null, analysis.getCreatedAt(), analysis.getUuid());
- verifyDebugLogs("Resolving first analysis as new code period as there is only one existing version");
- }
-
- @Test
- public void feed_period_by_version() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11
- SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12
- SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20
- SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22
- SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29
- dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION));
- dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION));
- dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION));
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project, "1.1");
- setupBranchWithNoManualBaseline(project);
-
- settings.setProperty("sonar.leak.period", "1.0");
- underTest.execute(new TestComputationStepContext());
-
- // Analysis form 2008-11-11
- assertPeriod(LEAK_PERIOD_MODE_VERSION, "1.0", analysis2.getCreatedAt(), analysis2.getUuid());
- verifyDebugLogs("Resolving new code period by version: 1.0");
- }
-
- /**
- * SONAR-11492
- */
- @Test
- public void feed_period_by_version_with_only_one_existing_version() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertMainBranch(organization);
- SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(true)); // 2008-11-11
- dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION));
- when(system2Mock.now()).thenReturn(november30th2008.getTime());
- when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
- setupRoot(project, "0.9");
- setupBranchWithNoManualBaseline(project);
-
- settings.setProperty("sonar.leak.period", "0.9");
- underTest.execute(new TestComputationStepContext());
-
- // Analysis form 2008-11-11
- assertPeriod(LEAK_PERIOD_MODE_VERSION, "0.9", analysis1.getCreatedAt(), analysis1.getUuid());
- verifyDebugLogs("Resolving new code period by version: 0.9");
- }
-
- @Test
- @UseDataProvider("anyValidLeakPeriodSettingValue")
- public void leak_period_setting_is_ignored_for_SLB_or_PR(String leakPeriodSettingValue) {
- when(analysisMetadataHolder.isLongLivingBranch()).thenReturn(false);
-
- settings.setProperty("sonar.leak.period", leakPeriodSettingValue);
- underTest.execute(new TestComputationStepContext());
-
- assertThat(periodsHolder.hasPeriod()).isFalse();
- }
-
- private void assertPeriod(String mode, @Nullable String modeParameter, long snapshotDate, String analysisUuid) {
- Period period = periodsHolder.getPeriod();
- assertThat(period).isNotNull();
- assertThat(period.getMode()).isEqualTo(mode);
- assertThat(period.getModeParameter()).isEqualTo(modeParameter);
- assertThat(period.getSnapshotDate()).isEqualTo(snapshotDate);
- assertThat(period.getAnalysisUuid()).isEqualTo(analysisUuid);
- }
-
- private void verifyDebugLogs(String log, String... otherLogs) {
- assertThat(logTester.getLogs()).hasSize(1 + otherLogs.length);
- assertThat(logTester.getLogs(LoggerLevel.DEBUG))
- .extracting(LogAndArguments::getFormattedMsg)
- .containsOnly(Stream.concat(Stream.of(log), Arrays.stream(otherLogs)).toArray(String[]::new));
- }
-
- private void setupRoot(ComponentDto project) {
- setupRoot(project, randomAlphanumeric(3));
- }
-
- private void setupRoot(ComponentDto project, String version) {
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setProjectVersion(version).build());
- when(configurationRepository.getConfiguration()).thenReturn(settings.asConfig());
- }
-
- private void setupBranchWithNoManualBaseline(ComponentDto projectOrLongBranch) {
- dbTester.components().unsetManualBaseline(projectOrLongBranch);
- setBranchOf(projectOrLongBranch);
- }
-
- private static void verifyInvalidValueMessage(MessageException e, String propertyValue) {
- assertThat(e).hasMessage("Invalid new code period. '" + propertyValue
- + "' is not one of: integer > 0, date before current analysis j, \"previous_version\", or version string that exists in the project' \n" +
- "Please contact a project administrator to correct this setting");
- }
-
- }
|