aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2013-06-09 22:54:25 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2013-06-09 22:54:25 +0200
commit44103f1921fc4b1900b8b6047e865c1e49f325d6 (patch)
tree75ad2ba880da7022897821d1d84dd9bb3eeb6cac /sonar-batch
parent72fbbf025107c5bad6739313c29e05e72bb528a5 (diff)
downloadsonarqube-44103f1921fc4b1900b8b6047e865c1e49f325d6.tar.gz
sonarqube-44103f1921fc4b1900b8b6047e865c1e49f325d6.zip
SONAR-4382 Add a success log at the end of dryRun analysis
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java15
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java39
2 files changed, 47 insertions, 7 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
index 4ee9697b5ff..0dd90eca8df 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java
@@ -19,6 +19,8 @@
*/
package org.sonar.batch.phases;
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.CoreProperties;
@@ -31,7 +33,6 @@ import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.batch.index.ResourcePersister;
import javax.persistence.Query;
-
import java.util.List;
public class UpdateStatusJob implements BatchComponent {
@@ -75,7 +76,15 @@ public class UpdateStatusJob implements BatchComponent {
Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(snapshot, false);
boolean isLast = (previousLastSnapshot == null || previousLastSnapshot.getCreatedAt().before(snapshot.getCreatedAt()));
setFlags(snapshot, isLast, Snapshot.STATUS_PROCESSED);
- if (!settings.getBoolean(CoreProperties.DRY_RUN)) {
+ logSuccess(LoggerFactory.getLogger(getClass()));
+ }
+
+ @VisibleForTesting
+ void logSuccess(Logger logger) {
+ if (settings.getBoolean(CoreProperties.DRY_RUN)) {
+ logger.info("ANALYSIS SUCCESSFUL");
+
+ } else {
String baseUrl = settings.getString(CoreProperties.SERVER_BASE_URL);
if (baseUrl.equals(settings.getDefaultValue(CoreProperties.SERVER_BASE_URL))) {
// If server base URL was not configured in Sonar server then is is better to take URL configured on batch side
@@ -85,7 +94,7 @@ public class UpdateStatusJob implements BatchComponent {
baseUrl += "/";
}
String url = baseUrl + "dashboard/index/" + project.getKey();
- LoggerFactory.getLogger(getClass()).info("ANALYSIS SUCCESSFUL, you can browse {}", url);
+ logger.info("ANALYSIS SUCCESSFUL, you can browse {}", url);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
index 3102e3cc36d..b38e777583e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/phases/UpdateStatusJobTest.java
@@ -20,6 +20,7 @@
package org.sonar.batch.phases;
import org.junit.Test;
+import org.slf4j.Logger;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseSession;
@@ -29,12 +30,14 @@ import org.sonar.api.security.ResourcePermissions;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.batch.index.DefaultResourcePersister;
import org.sonar.batch.index.ResourceCache;
+import org.sonar.batch.index.ResourcePersister;
import org.sonar.batch.index.SnapshotCache;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
import javax.persistence.Query;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
@@ -57,10 +60,10 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
setupData("sharedFixture", fixture);
DatabaseSession session = getSession();
- UpdateStatusJob sensor = new UpdateStatusJob(new Settings().appendProperty(CoreProperties.SERVER_BASE_URL, "http://myserver/"), mock(ServerClient.class), session,
- new DefaultResourcePersister(session, mock(ResourcePermissions.class), mock(SnapshotCache.class), mock(ResourceCache.class)),
- mock(Project.class), loadSnapshot(snapshotId));
- sensor.execute();
+ UpdateStatusJob job = new UpdateStatusJob(new Settings().appendProperty(CoreProperties.SERVER_BASE_URL, "http://myserver/"), mock(ServerClient.class), session,
+ new DefaultResourcePersister(session, mock(ResourcePermissions.class), mock(SnapshotCache.class), mock(ResourceCache.class)),
+ mock(Project.class), loadSnapshot(snapshotId));
+ job.execute();
checkTables(fixture, "snapshots");
}
@@ -70,4 +73,32 @@ public class UpdateStatusJobTest extends AbstractDbUnitTestCase {
query.setParameter("id", id);
return (Snapshot) query.getSingleResult();
}
+
+ @Test
+ public void should_log_successful_analysis() throws Exception {
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.SERVER_BASE_URL, "http://myserver/");
+ Project project = new Project("struts");
+ UpdateStatusJob job = new UpdateStatusJob(settings, mock(ServerClient.class), mock(DatabaseSession.class),
+ mock(ResourcePersister.class), project, mock(Snapshot.class));
+
+ Logger logger = mock(Logger.class);
+ job.logSuccess(logger);
+
+ verify(logger).info("ANALYSIS SUCCESSFUL, you can browse {}", "http://myserver/dashboard/index/struts");
+ }
+
+ @Test
+ public void should_log_successful_dry_run_analysis() throws Exception {
+ Settings settings = new Settings();
+ settings.setProperty("sonar.dryRun", true);
+ Project project = new Project("struts");
+ UpdateStatusJob job = new UpdateStatusJob(settings, mock(ServerClient.class), mock(DatabaseSession.class),
+ mock(ResourcePersister.class), project, mock(Snapshot.class));
+
+ Logger logger = mock(Logger.class);
+ job.logSuccess(logger);
+
+ verify(logger).info("ANALYSIS SUCCESSFUL");
+ }
}