]> source.dussan.org Git - sonarqube.git/commitdiff
remove hardcoded dates in ITs (#1485) 1497/head
authorStas Vilchik <vilchiks@gmail.com>
Tue, 27 Dec 2016 16:10:01 +0000 (17:10 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 5 Jan 2017 10:12:11 +0000 (11:12 +0100)
it/it-tests/src/test/java/it/dbCleaner/PurgeTest.java
it/it-tests/src/test/java/it/projectAdministration/ProjectAdministrationTest.java
it/it-tests/src/test/java/it/qualityGate/QualityGateUiTest.java

index 769d80febf71c6753fcc68ea8e57f5448dc9f090..73501238752aaabfe4f43608768988a590cac4cf 100644 (file)
@@ -54,6 +54,9 @@ public class PurgeTest {
   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;
 
@@ -249,12 +252,12 @@ public class PurgeTest {
    */
   @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);
@@ -266,14 +269,14 @@ public class PurgeTest {
    */
   @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);
@@ -285,7 +288,7 @@ public class PurgeTest {
    */
   @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')";
@@ -293,7 +296,7 @@ public class PurgeTest {
     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);
   }
index 5026725cbc8aced909c3cd095e5fa3aa69aa05e2..732af4fadbcefa29b2e7b13a006d9015e43501e7 100644 (file)
@@ -26,8 +26,10 @@ import it.Category1Suite;
 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;
@@ -41,12 +43,16 @@ import pageobjects.Navigation;
 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;
 
@@ -66,7 +72,7 @@ public class ProjectAdministrationTest {
 
   @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();
@@ -80,7 +86,7 @@ public class ProjectAdministrationTest {
   @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();
@@ -92,7 +98,7 @@ public class ProjectAdministrationTest {
   @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();
 
index e5c086800d423598ba6b066d9cda7ff4765d4100..5c2d5021258813eacc2b384ffc05c81b210584d3 100644 (file)
@@ -23,7 +23,9 @@ import com.sonar.orchestrator.Orchestrator;
 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;
@@ -37,6 +39,7 @@ import org.sonar.wsclient.qualitygate.UpdateCondition;
 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;
 
@@ -75,12 +78,15 @@ public class QualityGateUiTest {
     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",