private static final String PROJECT_KEY = "com.sonarsource.it.samples:multi-modules-sample";
private static final String PROJECT_SAMPLE_PATH = "dbCleaner/xoo-multi-modules-sample";
+ private static final String ONE_DAY_AGO = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -1));
+ private static final String TWO_DAYS_AGO = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -2));
+
@ClassRule
public static final Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
*/
@Test
public void should_delete_historical_data_of_directories_by_default() {
- scan(PROJECT_SAMPLE_PATH, "2012-01-01");
+ scan(PROJECT_SAMPLE_PATH, TWO_DAYS_AGO);
int fileMeasures = count(COUNT_FILE_MEASURES);
int dirMeasures = count(COUNT_DIR_MEASURES);
- scan(PROJECT_SAMPLE_PATH, "2012-02-02");
+ scan(PROJECT_SAMPLE_PATH, ONE_DAY_AGO);
// second analysis with new_* metrics
assertThat(count(COUNT_FILE_MEASURES)).isLessThan(2 * fileMeasures);
*/
@Test
public void should_not_delete_historical_data_of_directories() {
- scan(PROJECT_SAMPLE_PATH, "2012-01-01");
+ scan(PROJECT_SAMPLE_PATH, TWO_DAYS_AGO);
int fileMeasures = count(COUNT_FILE_MEASURES);
int dirMeasures = count(COUNT_DIR_MEASURES);
setServerProperty(orchestrator, "sonar.dbcleaner.cleanDirectory", "false");
- scan(PROJECT_SAMPLE_PATH, "2012-02-02");
+ scan(PROJECT_SAMPLE_PATH, ONE_DAY_AGO);
// second analysis as NEW_* metrics
assertThat(count(COUNT_FILE_MEASURES)).isLessThan( 2 * fileMeasures);
*/
@Test
public void should_delete_historical_data_of_flagged_metrics() {
- scan(PROJECT_SAMPLE_PATH, "2012-01-01");
+ scan(PROJECT_SAMPLE_PATH, TWO_DAYS_AGO);
// historical data of complexity_in_classes is supposed to be deleted (see CoreMetrics)
String selectNcloc = "project_measures where metric_id in (select id from metrics where name='ncloc')";
int nclocCount = count(selectNcloc);
int complexitInClassesCount = count(selectComplexityInClasses);
- scan(PROJECT_SAMPLE_PATH, "2012-02-02");
+ scan(PROJECT_SAMPLE_PATH, ONE_DAY_AGO);
assertThat(count(selectNcloc)).isGreaterThan(nclocCount);
assertThat(count(selectComplexityInClasses)).isEqualTo(complexitInClassesCount);
}
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;
import java.util.Calendar;
+import java.util.Date;
import java.util.GregorianCalendar;
import javax.annotation.Nullable;
+import org.apache.commons.lang.time.DateFormatUtils;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import pageobjects.settings.SettingsPage;
import util.selenium.SeleneseTest;
+import static org.apache.commons.lang.time.DateUtils.addDays;
import static org.assertj.core.api.Assertions.assertThat;
import static util.ItUtils.projectDir;
public class ProjectAdministrationTest {
private static final String DELETE_WS_ENDPOINT = "api/projects/bulk_delete";
+ // take some day in the past
+ private static final String ANALYSIS_DATE = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -1));
+
@ClassRule
public static Orchestrator orchestrator = Category1Suite.ORCHESTRATOR;
@Test
public void delete_project_by_web_service() {
- scanSampleWithDate("2012-01-01");
+ scanSampleWithDate(ANALYSIS_DATE);
assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.create(PROJECT_KEY))).isNotNull();
assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.create(FILE_KEY))).isNotNull();
@Test
public void fail_when_trying_to_delete_a_file() {
expectedException.expect(HttpException.class);
- scanSampleWithDate("2012-01-01");
+ scanSampleWithDate(ANALYSIS_DATE);
assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.create(PROJECT_KEY))).isNotNull();
assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.create(FILE_KEY))).isNotNull();
@Test
public void fail_when_insufficient_privilege() {
expectedException.expect(HttpException.class);
- scanSampleWithDate("2012-01-01");
+ scanSampleWithDate(ANALYSIS_DATE);
assertThat(orchestrator.getServer().getWsClient().find(ResourceQuery.create(PROJECT_KEY))).isNotNull();
import com.sonar.orchestrator.build.SonarScanner;
import com.sonar.orchestrator.selenium.Selenese;
import it.Category1Suite;
+import java.util.Date;
import javax.annotation.Nullable;
+import org.apache.commons.lang3.time.DateFormatUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import util.ItUtils;
import util.selenium.SeleneseTest;
+import static org.apache.commons.lang.time.DateUtils.addDays;
import static util.ItUtils.projectDir;
import static util.ItUtils.setServerProperty;
QualityGate qGate = qgClient.create("AlertsForHistory");
qgClient.setDefault(qGate.id());
+ String firstAnalysisDate = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -2));
+ String secondAnalysisDate = DateFormatUtils.ISO_DATE_FORMAT.format(addDays(new Date(), -1));
+
// with this configuration, project should have an Orange alert
QualityGateCondition lowThresholds = qgClient.createCondition(NewCondition.create(qGate.id()).metricKey("lines").operator("GT").warningThreshold("5").errorThreshold("50"));
- scanSampleWithDate("2012-01-01");
+ scanSampleWithDate(firstAnalysisDate);
// with this configuration, project should have a Green alert
qgClient.updateCondition(UpdateCondition.create(lowThresholds.id()).metricKey("lines").operator("GT").warningThreshold("5000").errorThreshold("5000"));
- scanSampleWithDate("2012-01-02");
+ scanSampleWithDate(secondAnalysisDate);
new SeleneseTest(Selenese.builder()
.setHtmlTestsInClasspath("display-alerts-history-page",