aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java36
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java12
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilder.java30
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilders.java86
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java17
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/component/ChildFirstTypeAwareVisitorTest.java43
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/component/DumbComponent.java86
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedComponentsCacheStepTest.java18
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java9
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java15
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java7
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java30
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java26
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java21
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java74
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java22
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java11
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java22
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java19
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java5
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/SendIssueNotificationsStepTest.java11
23 files changed, 469 insertions, 143 deletions
diff --git a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java
index 1f6d704cf76..d4a52759cb6 100644
--- a/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java
+++ b/server/sonar-server-benchmarks/src/test/java/org/sonar/server/benchmark/PersistFileSourcesStepTest.java
@@ -37,6 +37,9 @@ import org.sonar.core.persistence.DbTester;
import org.sonar.server.computation.ComputationContext;
import org.sonar.server.computation.component.DbComponentsRefCache;
import org.sonar.server.computation.component.DbComponentsRefCache.DbComponent;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.step.PersistFileSourcesStep;
import org.sonar.server.db.DbClient;
import org.sonar.server.source.db.FileSourceDao;
@@ -47,6 +50,7 @@ import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
public class PersistFileSourcesStepTest {
@@ -80,7 +84,7 @@ public class PersistFileSourcesStepTest {
long start = System.currentTimeMillis();
PersistFileSourcesStep step = new PersistFileSourcesStep(dbClient, System2.INSTANCE, dbComponentsRefCache);
- step.execute(new ComputationContext(new BatchReportReader(reportDir), "PROJECT_KEY", new Settings()));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), "PROJECT_KEY", new Settings(), dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), mock(LanguageRepository.class)));
long end = System.currentTimeMillis();
long duration = end - start;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java
index 77cb3847907..d9f0a9ca0f7 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java
@@ -17,27 +17,36 @@
* 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.server.computation;
import org.sonar.api.config.Settings;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReportReader;
+import org.sonar.server.computation.component.Component;
+import org.sonar.server.computation.component.ComponentTreeBuilder;
+import org.sonar.server.computation.language.LanguageRepository;
+import org.sonar.server.db.DbClient;
-public class ComputationContext {
-
+public class ComputationContext implements org.sonar.server.computation.context.ComputationContext {
private final BatchReportReader reportReader;
+ private final Settings projectSettings;
+ private final DbClient dbClient;
// Project key (including branch if any)
private final String projectKey;
// cache of metadata as it's frequently accessed
private final BatchReport.Metadata reportMetadata;
- private final Settings projectSettings;
+ private final Component component;
+ private final LanguageRepository languageRepository;
- public ComputationContext(BatchReportReader reportReader, String projectKey, Settings projectSettings) {
+ public ComputationContext(BatchReportReader reportReader, String projectKey, Settings projectSettings, DbClient dbClient,
+ ComponentTreeBuilder componentTreeBuilder, LanguageRepository languageRepository) {
this.reportReader = reportReader;
this.projectKey = projectKey;
this.projectSettings = projectSettings;
+ this.dbClient = dbClient;
this.reportMetadata = reportReader.readMetadata();
+ this.component = componentTreeBuilder.build(this);
+ this.languageRepository = languageRepository;
}
public BatchReport.Metadata getReportMetadata() {
@@ -56,4 +65,21 @@ public class ComputationContext {
return projectSettings;
}
+ @Override
+ public Component getRoot() {
+ return component;
+ }
+
+ /**
+ * @deprecated because dbclient is too low level to be exposed in the CE API
+ */
+ @Deprecated
+ public DbClient getDbClient() {
+ return dbClient;
+ }
+
+ @Override
+ public LanguageRepository getLanguageRepository() {
+ return languageRepository;
+ }
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java
index 698b883eaac..134e2f411ae 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java
@@ -21,6 +21,9 @@
package org.sonar.server.computation;
import com.google.common.base.Throwables;
+import java.io.File;
+import java.io.IOException;
+import javax.annotation.Nullable;
import org.apache.commons.io.FileUtils;
import org.sonar.api.config.Settings;
import org.sonar.api.server.ServerSide;
@@ -37,6 +40,8 @@ import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.MyBatis;
import org.sonar.server.activity.Activity;
import org.sonar.server.activity.ActivityService;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.step.ComputationStep;
import org.sonar.server.computation.step.ComputationSteps;
import org.sonar.server.db.DbClient;
@@ -63,15 +68,18 @@ public class ComputationService {
private final ProjectSettingsFactory projectSettingsFactory;
private final TempFolder tempFolder;
private final System2 system;
+ private final LanguageRepository languageRepository;
public ComputationService(DbClient dbClient, ComputationSteps steps, ActivityService activityService,
- ProjectSettingsFactory projectSettingsFactory, TempFolder tempFolder, System2 system) {
+ ProjectSettingsFactory projectSettingsFactory, TempFolder tempFolder, System2 system,
+ LanguageRepository languageRepository) {
this.dbClient = dbClient;
this.steps = steps;
this.activityService = activityService;
this.projectSettingsFactory = projectSettingsFactory;
this.tempFolder = tempFolder;
this.system = system;
+ this.languageRepository = languageRepository;
}
public void process(ReportQueue.Item item) {
@@ -83,7 +91,7 @@ public class ComputationService {
File reportDir = extractReportInDir(item);
BatchReportReader reader = new BatchReportReader(reportDir);
Settings projectSettings = projectSettingsFactory.newProjectSettings(projectKey);
- ComputationContext context = new ComputationContext(reader, projectKey, projectSettings);
+ ComputationContext context = new ComputationContext(reader, projectKey, projectSettings, dbClient, ComponentTreeBuilders.from(reader), languageRepository);
for (ComputationStep step : steps.orderedSteps()) {
Profiler stepProfiler = Profiler.createIfDebug(LOG).startDebug(step.getDescription());
step.execute(context);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilder.java
new file mode 100644
index 00000000000..82aab5f6564
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilder.java
@@ -0,0 +1,30 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.computation.component;
+
+import org.sonar.server.computation.ComputationContext;
+
+public interface ComponentTreeBuilder {
+ /**
+ * Builds the tree of components for the specified ComputationContext and returns the Component of the root of this
+ * tree.
+ */
+ Component build(ComputationContext context);
+}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilders.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilders.java
new file mode 100644
index 00000000000..1ecbd9105c8
--- /dev/null
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilders.java
@@ -0,0 +1,86 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.computation.component;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import javax.annotation.Nonnull;
+import org.sonar.batch.protocol.output.BatchReport;
+import org.sonar.batch.protocol.output.BatchReportReader;
+import org.sonar.server.computation.ComputationContext;
+
+import static java.util.Objects.requireNonNull;
+
+public final class ComponentTreeBuilders {
+ public static ComponentTreeBuilder from(final BatchReportReader reportReader) {
+ // fail fast
+ requireNonNull(reportReader);
+
+ return new BatchReportComponentTreeBuilderImpl(reportReader);
+ }
+
+ public static ComponentTreeBuilder from(final Component root) {
+ // fail-fast
+ requireNonNull(root);
+ return new ComponentTreeBuilder() {
+ @Override
+ public Component build(ComputationContext context) {
+ return root;
+ }
+ };
+ }
+
+ public interface BatchReportComponentTreeBuilder extends ComponentTreeBuilder {
+
+ }
+
+ private static class BatchReportComponentTreeBuilderImpl implements BatchReportComponentTreeBuilder {
+ private final BatchReportReader reportReader;
+
+ public BatchReportComponentTreeBuilderImpl(BatchReportReader reportReader) {
+ this.reportReader = reportReader;
+ }
+
+ @Override
+ public Component build(ComputationContext context) {
+ return buildComponentRoot(context, reportReader);
+ }
+
+ private Component buildComponentRoot(ComputationContext computationContext, BatchReportReader reportReader) {
+ int rootComponentRef = computationContext.getReportMetadata().getRootComponentRef();
+ BatchReport.Component component = reportReader.readComponent(rootComponentRef);
+ return new ComponentImpl(computationContext, component, buildComponent(computationContext, rootComponentRef));
+ }
+
+ private Iterable<Component> buildComponent(final ComputationContext computationContext, int componentRef) {
+ BatchReport.Component component = computationContext.getReportReader().readComponent(componentRef);
+ return Iterables.transform(
+ component.getChildRefList(),
+ new Function<Integer, Component>() {
+ @Override
+ public Component apply(@Nonnull Integer componentRef) {
+ BatchReport.Component component = computationContext.getReportReader().readComponent(componentRef);
+ return new ComponentImpl(computationContext, component, buildComponent(computationContext, componentRef));
+ }
+ }
+ );
+ }
+ }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java
index 6cb90d13cce..c1efb61f6fc 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/ComputationServiceTest.java
@@ -19,6 +19,9 @@
*/
package org.sonar.server.computation;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.Before;
@@ -35,6 +38,7 @@ import org.sonar.api.utils.ZipUtils;
import org.sonar.api.utils.internal.JUnitTempFolder;
import org.sonar.api.utils.log.LogTester;
import org.sonar.api.utils.log.LoggerLevel;
+import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.core.computation.db.AnalysisReportDto;
@@ -44,15 +48,12 @@ import org.sonar.server.activity.Activity;
import org.sonar.server.activity.ActivityService;
import org.sonar.server.component.db.ComponentDao;
import org.sonar.server.component.db.SnapshotDao;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.step.ComputationStep;
import org.sonar.server.computation.step.ComputationSteps;
import org.sonar.server.db.DbClient;
import org.sonar.server.properties.ProjectSettingsFactory;
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.any;
@@ -88,7 +89,7 @@ public class ComputationServiceTest {
public void setUp() {
dbTester.truncateTables();
DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new ComponentDao(), new SnapshotDao(system));
- sut = new ComputationService(dbClient, steps, activityService, settingsFactory, tempFolder, system);
+ sut = new ComputationService(dbClient, steps, activityService, settingsFactory, tempFolder, system, mock(LanguageRepository.class));
}
@Test
@@ -219,6 +220,12 @@ public class ComputationServiceTest {
.setAnalysisDate(150000000L)
.setSnapshotId(snapshotId)
.build());
+ writer.writeComponent(BatchReport.Component.newBuilder()
+ .setRef(1)
+ .setType(Constants.ComponentType.PROJECT)
+ .setKey("PROJECT_KEY")
+ .setSnapshotId(snapshotId)
+ .build());
File zip = tempFolder.newFile();
ZipUtils.zipDir(dir, zip);
return zip;
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ChildFirstTypeAwareVisitorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ChildFirstTypeAwareVisitorTest.java
index d3b66354cf9..6f763397ad6 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ChildFirstTypeAwareVisitorTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ChildFirstTypeAwareVisitorTest.java
@@ -19,15 +19,8 @@
*/
package org.sonar.server.computation.component;
-import com.google.common.collect.ImmutableList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
import org.junit.Test;
import org.mockito.InOrder;
-import org.sonar.server.computation.context.ComputationContext;
-import org.sonar.server.computation.event.EventRepository;
-import org.sonar.server.computation.measure.MeasureRepository;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.spy;
@@ -38,8 +31,6 @@ import static org.sonar.server.computation.component.Component.Type.PROJECT;
public class ChildFirstTypeAwareVisitorTest {
- private static final String UNSUPPORTED_OPERATION_ERROR = "This node has no repository nor context";
-
private static final Component FILE_4 = component(FILE, 4);
private static final Component FILE_5 = component(FILE, 5);
private static final Component DIRECTORY_3 = component(DIRECTORY, 3, FILE_4, FILE_5);
@@ -268,37 +259,7 @@ public class ChildFirstTypeAwareVisitorTest {
}
private static Component component(final Component.Type type, final int ref, final Component... children) {
- return new Component() {
-
- @Override
- public Type getType() {
- return type;
- }
-
- @Override
- public int getRef() {
- return ref;
- }
-
- @Override
- public List<Component> getChildren() {
- return children == null ? Collections.<Component>emptyList() : ImmutableList.copyOf(Arrays.asList(children));
- }
-
- @Override
- public ComputationContext getContext() {
- throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_ERROR);
- }
-
- @Override
- public EventRepository getEventRepository() {
- throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_ERROR);
- }
-
- @Override
- public MeasureRepository getMeasureRepository() {
- throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_ERROR);
- }
- };
+ return new DumbComponent(type, ref, children);
}
+
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/DumbComponent.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/DumbComponent.java
new file mode 100644
index 00000000000..ca5a03ccb66
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/DumbComponent.java
@@ -0,0 +1,86 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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.server.computation.component;
+
+import com.google.common.collect.ImmutableList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.server.computation.context.ComputationContext;
+import org.sonar.server.computation.event.EventRepository;
+import org.sonar.server.computation.measure.MeasureRepository;
+
+public class DumbComponent implements Component {
+ public static final Component DUMB_PROJECT = new DumbComponent(Type.PROJECT, 1);
+
+ private static final String UNSUPPORTED_OPERATION_ERROR = "This node has no repository nor context";
+
+ @CheckForNull
+ private final ComputationContext context;
+ private final Type type;
+ private final int ref;
+ private final List<Component> children;
+
+ public DumbComponent(Type type, int ref, @Nullable Component... children) {
+ this(null, type, ref, children);
+ }
+
+ public DumbComponent(@Nullable ComputationContext context, Type type, int ref, @Nullable Component... children) {
+ this.context = context;
+ this.type = type;
+ this.ref = ref;
+ this.children = children == null ? Collections.<Component>emptyList() : ImmutableList.copyOf(Arrays.asList(children));
+ }
+
+ @Override
+ public Type getType() {
+ return type;
+ }
+
+ @Override
+ public int getRef() {
+ return ref;
+ }
+
+ @Override
+ public List<Component> getChildren() {
+ return children;
+ }
+
+ @Override
+ public ComputationContext getContext() {
+ if (context == null) {
+ throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_ERROR);
+ }
+ return context;
+ }
+
+ @Override
+ public EventRepository getEventRepository() {
+ throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_ERROR);
+ }
+
+ @Override
+ public MeasureRepository getMeasureRepository() {
+ throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_ERROR);
+ }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedComponentsCacheStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedComponentsCacheStepTest.java
index def1b081758..820ae78b5bf 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedComponentsCacheStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/FeedComponentsCacheStepTest.java
@@ -20,6 +20,7 @@
package org.sonar.server.computation.step;
+import java.io.File;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -35,13 +36,15 @@ import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.component.db.ComponentDao;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
import org.sonar.server.computation.component.ComputeComponentsRefCache;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.db.DbClient;
import org.sonar.test.DbTests;
-import java.io.File;
-
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
@Category(DbTests.class)
public class FeedComponentsCacheStepTest extends BaseStepTest {
@@ -62,6 +65,8 @@ public class FeedComponentsCacheStepTest extends BaseStepTest {
Settings projectSettings;
+ LanguageRepository languageRepository = mock(LanguageRepository.class);
+
ComputeComponentsRefCache computeComponentsRefCache;
FeedComponentsCacheStep sut;
@@ -116,7 +121,8 @@ public class FeedComponentsCacheStepTest extends BaseStepTest {
.setPath("src/main/java/dir/Foo.java")
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(computeComponentsRefCache.getByRef(1).getKey()).isEqualTo(PROJECT_KEY);
assertThat(computeComponentsRefCache.getByRef(1).getUuid()).isNotNull();
@@ -172,7 +178,8 @@ public class FeedComponentsCacheStepTest extends BaseStepTest {
.setPath("src/main/java/dir/Foo.java")
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(computeComponentsRefCache.getByRef(4).getKey()).isEqualTo("SUB_MODULE_KEY:src/main/java/dir");
assertThat(computeComponentsRefCache.getByRef(5).getKey()).isEqualTo("SUB_MODULE_KEY:src/main/java/dir/Foo.java");
@@ -213,7 +220,8 @@ public class FeedComponentsCacheStepTest extends BaseStepTest {
.setPath("src/main/java/dir/Foo.java")
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(computeComponentsRefCache.getByRef(1).getKey()).isEqualTo("PROJECT_KEY:origin/master");
assertThat(computeComponentsRefCache.getByRef(2).getKey()).isEqualTo("MODULE_KEY:origin/master");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java
index 8a4bf022854..3eb6454c10a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexComponentsStepTest.java
@@ -32,6 +32,10 @@ import org.sonar.core.resource.ResourceIndexerDao;
import org.sonar.server.computation.ComputationContext;
import org.sonar.server.computation.component.DbComponentsRefCache;
import org.sonar.server.computation.component.DbComponentsRefCache.DbComponent;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
+import org.sonar.server.db.DbClient;
import java.io.File;
import java.io.IOException;
@@ -63,7 +67,7 @@ public class IndexComponentsStepTest extends BaseStepTest {
ComponentDto project = mock(ComponentDto.class);
when(project.getId()).thenReturn(123L);
- ComputationContext context = new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, new Settings());
+ ComputationContext context = new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, new Settings(), mock(DbClient.class), ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), mock(LanguageRepository.class));
sut.execute(context);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java
index 771315f5a06..f17618d51ef 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexSourceLinesStepTest.java
@@ -19,6 +19,8 @@
*/
package org.sonar.server.computation.step;
+import java.sql.Connection;
+import java.util.List;
import org.elasticsearch.search.SearchHit;
import org.junit.Before;
import org.junit.ClassRule;
@@ -32,6 +34,9 @@ import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.computation.ComputationContext;
import org.sonar.server.computation.component.DbComponentsRefCache;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
import org.sonar.server.source.db.FileSourceDao;
@@ -45,6 +50,7 @@ import java.sql.Connection;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
public class IndexSourceLinesStepTest extends BaseStepTest {
@@ -91,7 +97,8 @@ public class IndexSourceLinesStepTest extends BaseStepTest {
.setRootComponentRef(1)
.build());
- step().execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, new Settings()));
+ step().execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, new Settings(), dbClient,
+ ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), mock(LanguageRepository.class)));
List<SearchHit> docs = esTester.getDocuments(SourceLineIndexDefinition.INDEX, SourceLineIndexDefinition.TYPE);
assertThat(docs).hasSize(1);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java
index fed0a235a6e..c36cf90f1a1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/IndexTestsStepTest.java
@@ -20,6 +20,9 @@
package org.sonar.server.computation.step;
+import java.io.File;
+import java.sql.Connection;
+import java.util.List;
import org.elasticsearch.search.SearchHit;
import org.junit.Before;
import org.junit.ClassRule;
@@ -32,7 +35,10 @@ import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
import org.sonar.server.computation.component.DbComponentsRefCache;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.db.DbClient;
import org.sonar.server.es.EsTester;
import org.sonar.server.source.db.FileSourceDao;
@@ -41,11 +47,8 @@ import org.sonar.server.test.index.TestDoc;
import org.sonar.server.test.index.TestIndexDefinition;
import org.sonar.server.test.index.TestIndexer;
-import java.io.File;
-import java.sql.Connection;
-import java.util.List;
-
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
public class IndexTestsStepTest extends BaseStepTest {
@@ -59,6 +62,7 @@ public class IndexTestsStepTest extends BaseStepTest {
public static EsTester esTester = new EsTester().addDefinitions(new TestIndexDefinition(new Settings()));
DbClient dbClient;
+ ComputationContext underTest;
DbComponentsRefCache dbComponentsRefCache;
@@ -91,7 +95,8 @@ public class IndexTestsStepTest extends BaseStepTest {
.setRootComponentRef(1)
.build());
- step().execute(new ComputationContext(new BatchReportReader(reportDir), "PROJECT_KEY", new Settings()));
+ step().execute(new ComputationContext(new BatchReportReader(reportDir), "PROJECT_KEY", new Settings(), dbClient,
+ ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), mock(LanguageRepository.class)));
List<SearchHit> docs = esTester.getDocuments(TestIndexDefinition.INDEX, TestIndexDefinition.TYPE);
assertThat(docs).hasSize(1);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java
index 53034ed466a..23b9764c80b 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/ParseReportStepTest.java
@@ -30,6 +30,8 @@ import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
import org.sonar.server.computation.component.ComputeComponentsRefCache;
import org.sonar.server.computation.issue.IssueComputation;
@@ -38,6 +40,8 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import org.sonar.server.computation.language.LanguageRepository;
+import org.sonar.server.db.DbClient;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -70,7 +74,8 @@ public class ParseReportStepTest extends BaseStepTest {
File reportDir = generateReport();
- ComputationContext context = new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, new Settings());
+ ComputationContext context = new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, new Settings(),
+ mock(DbClient.class), ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), mock(LanguageRepository.class));
sut.execute(context);
assertThat(context.getReportMetadata().getRootComponentRef()).isEqualTo(1);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java
index 8ef3b41423a..12aa751a461 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistComponentsStepTest.java
@@ -39,12 +39,16 @@ import org.sonar.core.persistence.DbTester;
import org.sonar.server.component.ComponentTesting;
import org.sonar.server.component.db.ComponentDao;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
import org.sonar.server.computation.component.ComputeComponentsRefCache;
import org.sonar.server.computation.component.DbComponentsRefCache;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.db.DbClient;
import org.sonar.test.DbTests;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
@Category(DbTests.class)
public class PersistComponentsStepTest extends BaseStepTest {
@@ -64,6 +68,7 @@ public class PersistComponentsStepTest extends BaseStepTest {
DbClient dbClient;
Settings projectSettings;
+ LanguageRepository languageRepository;
ComputeComponentsRefCache computeComponentsRefCache;
DbComponentsRefCache dbComponentsRefCache;
@@ -79,6 +84,7 @@ public class PersistComponentsStepTest extends BaseStepTest {
computeComponentsRefCache = new ComputeComponentsRefCache();
projectSettings = new Settings();
+ languageRepository = mock(LanguageRepository.class);
dbComponentsRefCache = new DbComponentsRefCache();
sut = new PersistComponentsStep(dbClient, computeComponentsRefCache, dbComponentsRefCache);
}
@@ -135,7 +141,8 @@ public class PersistComponentsStepTest extends BaseStepTest {
.setLanguage("java")
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(4);
@@ -225,7 +232,8 @@ public class PersistComponentsStepTest extends BaseStepTest {
.setPath("pom.xml")
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
ComponentDto directory = dbClient.componentDao().selectNullableByKey(session, "PROJECT_KEY:/");
assertThat(directory).isNotNull();
@@ -270,7 +278,8 @@ public class PersistComponentsStepTest extends BaseStepTest {
.setIsTest(true)
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
ComponentDto file = dbClient.componentDao().selectNullableByKey(session, "PROJECT_KEY:src/test/java/dir/FooTest.java");
assertThat(file).isNotNull();
@@ -326,7 +335,8 @@ public class PersistComponentsStepTest extends BaseStepTest {
.setPath("src/main/java/dir/Foo.java")
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(4);
@@ -405,7 +415,8 @@ public class PersistComponentsStepTest extends BaseStepTest {
.setPath("src/main/java/dir")
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(5);
@@ -478,7 +489,8 @@ public class PersistComponentsStepTest extends BaseStepTest {
.setPath("src/main/java/dir/Foo.java")
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(4);
assertThat(dbClient.componentDao().selectNullableByKey(session, PROJECT_KEY).getId()).isEqualTo(project.getId());
@@ -556,7 +568,8 @@ public class PersistComponentsStepTest extends BaseStepTest {
.setDescription("New module description")
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
ComponentDto projectReloaded = dbClient.componentDao().selectNullableByKey(session, PROJECT_KEY);
assertThat(projectReloaded.name()).isEqualTo("New project name");
@@ -625,7 +638,8 @@ public class PersistComponentsStepTest extends BaseStepTest {
.setPath("src/main/java/dir/Foo.java")
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(5);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java
index b5689dc7175..2b96c2b4b6a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistDuplicationsStepTest.java
@@ -38,6 +38,9 @@ import org.sonar.core.measure.db.MetricDto;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.component.DbComponentsRefCache;
import org.sonar.server.computation.component.DbComponentsRefCache.DbComponent;
import org.sonar.server.db.DbClient;
@@ -50,6 +53,7 @@ import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
@Category(DbTests.class)
public class PersistDuplicationsStepTest extends BaseStepTest {
@@ -69,6 +73,7 @@ public class PersistDuplicationsStepTest extends BaseStepTest {
DbClient dbClient;
Settings projectSettings;
+ LanguageRepository languageRepository;
DbComponentsRefCache dbComponentsRefCache;
@@ -84,6 +89,7 @@ public class PersistDuplicationsStepTest extends BaseStepTest {
projectSettings = new Settings();
dbComponentsRefCache = new DbComponentsRefCache();
+ languageRepository = mock(LanguageRepository.class);
sut = new PersistDuplicationsStep(dbClient, dbComponentsRefCache);
}
@@ -102,7 +108,8 @@ public class PersistDuplicationsStepTest extends BaseStepTest {
saveDuplicationMetric();
initReportWithProjectAndFile();
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(0);
}
@@ -128,7 +135,8 @@ public class PersistDuplicationsStepTest extends BaseStepTest {
.build();
writer.writeComponentDuplications(2, newArrayList(duplication));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
@@ -188,7 +196,7 @@ public class PersistDuplicationsStepTest extends BaseStepTest {
.build();
writer.writeComponentDuplications(3, newArrayList(duplication));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
@@ -247,7 +255,8 @@ public class PersistDuplicationsStepTest extends BaseStepTest {
.build();
writer.writeComponentDuplications(3, newArrayList(duplication));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
@@ -313,7 +322,8 @@ public class PersistDuplicationsStepTest extends BaseStepTest {
.build();
writer.writeComponentDuplications(10, newArrayList(duplication));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
@@ -349,7 +359,8 @@ public class PersistDuplicationsStepTest extends BaseStepTest {
.build();
writer.writeComponentDuplications(2, newArrayList(duplication));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
@@ -378,7 +389,8 @@ public class PersistDuplicationsStepTest extends BaseStepTest {
.build();
writer.writeComponentDuplications(2, newArrayList(duplication));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(1);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java
index a055d877613..8de9804875c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistEventsStepTest.java
@@ -37,6 +37,9 @@ import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.component.DbComponentsRefCache;
import org.sonar.server.computation.component.DbComponentsRefCache.DbComponent;
import org.sonar.server.db.DbClient;
@@ -58,6 +61,8 @@ public class PersistEventsStepTest extends BaseStepTest {
public static DbTester dbTester = new DbTester();
DbSession session;
+ DbClient dbClient;
+ LanguageRepository languageRepository;
EventDao dao;
@@ -79,6 +84,7 @@ public class PersistEventsStepTest extends BaseStepTest {
when(system2.now()).thenReturn(1225630680000L);
projectSettings = new Settings();
+ languageRepository = mock(LanguageRepository.class);
dbComponentsRefCache = new DbComponentsRefCache();
step = new PersistEventsStep(dbClient, system2, dbComponentsRefCache);
@@ -113,7 +119,8 @@ public class PersistEventsStepTest extends BaseStepTest {
.setType(Constants.ComponentType.PROJECT)
.build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
dbTester.assertDbUnit(getClass(), "nothing_to_do_when_no_events_in_report.xml", "events");
}
@@ -150,7 +157,8 @@ public class PersistEventsStepTest extends BaseStepTest {
)
.build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
dbTester.assertDbUnit(getClass(), "add_events-result.xml", "events");
}
@@ -193,7 +201,8 @@ public class PersistEventsStepTest extends BaseStepTest {
.build()
).build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
dbTester.assertDbUnit(getClass(), "persist_report_events_with_component_children-result.xml", "events");
}
@@ -219,7 +228,8 @@ public class PersistEventsStepTest extends BaseStepTest {
.setVersion("1.0")
.build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
dbTester.assertDbUnit(getClass(), "add_version_event-result.xml", "events");
}
@@ -245,7 +255,8 @@ public class PersistEventsStepTest extends BaseStepTest {
.setVersion("1.5-SNAPSHOT")
.build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
dbTester.assertDbUnit(getClass(), "keep_one_event_by_version-result.xml", "events");
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java
index eeb757d4b73..05464f560c9 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistFileSourcesStepTest.java
@@ -20,7 +20,11 @@
package org.sonar.server.computation.step;
+import com.google.common.base.Optional;
import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
@@ -30,6 +34,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.config.Settings;
+import org.sonar.api.resources.Language;
import org.sonar.api.utils.System2;
import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;
@@ -41,16 +46,15 @@ import org.sonar.core.persistence.DbTester;
import org.sonar.core.source.db.FileSourceDto;
import org.sonar.core.source.db.FileSourceDto.Type;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.component.DbComponentsRefCache;
import org.sonar.server.db.DbClient;
import org.sonar.server.source.db.FileSourceDao;
import org.sonar.server.source.db.FileSourceDb;
import org.sonar.test.DbTests;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
@@ -79,6 +83,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
DbClient dbClient;
Settings projectSettings;
+ LanguageRepository languageRepository;
System2 system2;
@@ -94,6 +99,7 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
session = dbTester.myBatis().openSession(false);
dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), new FileSourceDao(dbTester.myBatis()));
projectSettings = new Settings();
+ languageRepository = mock(LanguageRepository.class);
reportDir = temp.newFolder();
@@ -117,7 +123,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
public void persist_sources() throws Exception {
initBasicReport(2);
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders .from(DumbComponent.DUMB_PROJECT), new EmptyLanguageRepository()));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource(FILE_UUID);
@@ -160,7 +167,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
.setLines(3)
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource(FILE_UUID);
@@ -174,7 +182,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
public void persist_source_hashes() throws Exception {
initBasicReport(2);
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource("FILE");
@@ -196,7 +205,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
.setOverallCoveredConditions(4)
.build()));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource(FILE_UUID);
@@ -229,7 +239,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
.addChangesetIndexByLine(0)
.build());
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource(FILE_UUID);
@@ -255,7 +266,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
.build()
));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource(FILE_UUID);
@@ -281,7 +293,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
).build()
));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource(FILE_UUID);
@@ -313,7 +326,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
.build()
));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource(FILE_UUID);
@@ -351,7 +365,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
// Sources from the report
initBasicReport(1);
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource(FILE_UUID);
@@ -385,7 +400,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
initBasicReport(1);
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource(FILE_UUID);
@@ -416,7 +432,8 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
initBasicReport(1);
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
FileSourceDto fileSourceDto = dbClient.fileSourceDao().selectSource(FILE_UUID);
@@ -431,19 +448,20 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
BatchReportWriter writer = initBasicReport(1);
writer.writeComponentSyntaxHighlighting(FILE_REF, newArrayList(BatchReport.SyntaxHighlighting.newBuilder()
- .setRange(BatchReport.Range.newBuilder()
- .setStartLine(1).setEndLine(1)
- // Wrong offset -> fail
- .setStartOffset(4).setEndOffset(2)
- .build())
- .setType(Constants.HighlightingType.ANNOTATION)
- .build()
- ));
+ .setRange(BatchReport.Range.newBuilder()
+ .setStartLine(1).setEndLine(1)
+ // Wrong offset -> fail
+ .setStartOffset(4).setEndOffset(2)
+ .build())
+ .setType(Constants.HighlightingType.ANNOTATION)
+ .build()
+ ));
try {
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
failBecauseExceptionWasNotThrown(IllegalStateException.class);
- } catch (IllegalStateException e){
+ } catch (IllegalStateException e) {
assertThat(e).hasMessage("Cannot persist sources of src/Foo.java").hasCauseInstanceOf(IllegalArgumentException.class);
}
}
@@ -485,4 +503,10 @@ public class PersistFileSourcesStepTest extends BaseStepTest {
return writer;
}
+ private static class EmptyLanguageRepository implements LanguageRepository {
+ @Override
+ public Optional<Language> find(String languageKey) {
+ return Optional.absent();
+ }
+ }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
index 16e9e6a0387..4a75cd23e32 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistMeasuresStepTest.java
@@ -20,6 +20,11 @@
package org.sonar.server.computation.step;
+import java.io.File;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
@@ -27,8 +32,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TemporaryFolder;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
import org.sonar.api.config.Settings;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
@@ -47,9 +50,12 @@ import org.sonar.core.persistence.DbTester;
import org.sonar.core.rule.RuleDto;
import org.sonar.server.component.db.ComponentDao;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
import org.sonar.server.computation.component.DbComponentsRefCache;
+import org.sonar.server.computation.component.DumbComponent;
import org.sonar.server.computation.issue.RuleCache;
import org.sonar.server.computation.issue.RuleCacheLoader;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.measure.MetricCache;
import org.sonar.server.db.DbClient;
import org.sonar.server.measure.persistence.MeasureDao;
@@ -58,13 +64,8 @@ import org.sonar.server.rule.RuleTesting;
import org.sonar.server.rule.db.RuleDao;
import org.sonar.test.DbTests;
-import java.io.File;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
@Category(DbTests.class)
public class PersistMeasuresStepTest extends BaseStepTest {
@@ -179,7 +180,8 @@ public class PersistMeasuresStepTest extends BaseStepTest {
.setCharactericId(123456)
.build()));
- sut.execute(new ComputationContext(new BatchReportReader(dir), PROJECT_KEY, new Settings()));
+ sut.execute(new ComputationContext(new BatchReportReader(dir), PROJECT_KEY, new Settings(),
+ dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), mock(LanguageRepository.class)));
session.commit();
assertThat(dbTester.countRowsOfTable("project_measures")).isEqualTo(2);
@@ -425,7 +427,7 @@ public class PersistMeasuresStepTest extends BaseStepTest {
.setSnapshotId(3);
}
- private ComponentDto addComponent(int ref, String key){
+ private ComponentDto addComponent(int ref, String key) {
ComponentDto componentDto = new ComponentDto().setKey(key).setUuid(Uuids.create());
dbClient.componentDao().insert(session, componentDto);
session.commit();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java
index fe09b054623..884c854b79a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStepTest.java
@@ -38,6 +38,9 @@ import org.sonar.core.measure.db.MetricDto;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.computation.ComputationContext;
import org.sonar.server.computation.component.DbComponentsRefCache;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.measure.MetricCache;
import org.sonar.server.db.DbClient;
import org.sonar.server.measure.persistence.MeasureDao;
@@ -61,6 +64,7 @@ public class PersistNumberOfDaysSinceLastCommitStepTest extends BaseStepTest {
SourceLineIndex sourceLineIndex;
MetricCache metricCache;
Settings projectSettings;
+ LanguageRepository languageRepository;
DbComponentsRefCache dbComponentsRefCache;
@@ -71,6 +75,7 @@ public class PersistNumberOfDaysSinceLastCommitStepTest extends BaseStepTest {
sourceLineIndex = mock(SourceLineIndex.class);
metricCache = mock(MetricCache.class);
projectSettings = new Settings();
+ languageRepository = mock(LanguageRepository.class);
when(metricCache.get(anyString())).thenReturn(new MetricDto().setId(10));
dbComponentsRefCache = new DbComponentsRefCache();
dir = temp.newFolder();
@@ -96,7 +101,7 @@ public class PersistNumberOfDaysSinceLastCommitStepTest extends BaseStepTest {
)
.build()
);
- ComputationContext context = new ComputationContext(new BatchReportReader(dir), "PROJECT_KEY", projectSettings);
+ ComputationContext context = new ComputationContext(new BatchReportReader(dir), "PROJECT_KEY", projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository);
sut.execute(context);
@@ -108,7 +113,7 @@ public class PersistNumberOfDaysSinceLastCommitStepTest extends BaseStepTest {
Date sixDaysAgo = DateUtils.addDays(new Date(), -6);
when(sourceLineIndex.lastCommitDateOnProject("project-uuid")).thenReturn(sixDaysAgo);
initReportWithProjectAndFile();
- ComputationContext context = new ComputationContext(new BatchReportReader(dir), "PROJECT_KEY", projectSettings);
+ ComputationContext context = new ComputationContext(new BatchReportReader(dir), "PROJECT_KEY", projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository);
sut.execute(context);
@@ -118,7 +123,7 @@ public class PersistNumberOfDaysSinceLastCommitStepTest extends BaseStepTest {
@Test
public void no_scm_information_in_report_and_index() {
initReportWithProjectAndFile();
- ComputationContext context = new ComputationContext(new BatchReportReader(dir),"PROJECT_KEY", projectSettings);
+ ComputationContext context = new ComputationContext(new BatchReportReader(dir),"PROJECT_KEY", projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository);
sut.execute(context);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java
index 61031784c55..b8ea9f7ed00 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistProjectLinksStepTest.java
@@ -39,6 +39,9 @@ import org.sonar.core.persistence.DbSession;
import org.sonar.core.persistence.DbTester;
import org.sonar.server.component.db.ComponentLinkDao;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.component.DbComponentsRefCache;
import org.sonar.server.db.DbClient;
import org.sonar.test.DbTests;
@@ -60,7 +63,9 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
public static DbTester dbTester = new DbTester();
DbSession session;
+ DbClient dbClient;
Settings projectSettings;
+ LanguageRepository languageRepository;
ComponentLinkDao dao;
@@ -75,7 +80,8 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
session = dbTester.myBatis().openSession(false);
dao = new ComponentLinkDao();
projectSettings = new Settings();
- DbClient dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), dao);
+ languageRepository = mock(LanguageRepository.class);
+ dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), dao);
i18n = mock(I18n.class);
when(i18n.message(Locale.ENGLISH, "project_links.homepage", null)).thenReturn("Home");
@@ -130,7 +136,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
.addLink(BatchReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.SCM).setHref("https://github.com/SonarSource/sonar/server").build())
.build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
dbTester.assertDbUnit(getClass(), "add_links_on_project_and_module-result.xml", "project_links");
}
@@ -154,7 +160,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
.addLink(BatchReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
.build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
dbTester.assertDbUnit(getClass(), "nothing_to_do_when_link_already_exists.xml", "project_links");
}
@@ -178,7 +184,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
.addLink(BatchReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
.build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("project_links")).isEqualTo(0);
}
@@ -202,7 +208,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
.addLink(BatchReport.ComponentLink.newBuilder().setType(Constants.ComponentLinkType.HOME).setHref("http://www.sonarqube.org").build())
.build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
dbTester.assertDbUnit(getClass(), "update_link-result.xml", "project_links");
}
@@ -225,7 +231,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
.setType(Constants.ComponentType.PROJECT)
.build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbTester.countRowsOfTable("project_links")).isEqualTo(0);
}
@@ -248,7 +254,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
.setType(Constants.ComponentType.PROJECT)
.build());
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
dbTester.assertDbUnit(getClass(), "not_delete_custom_link.xml", "project_links");
}
@@ -274,7 +280,7 @@ public class PersistProjectLinksStepTest extends BaseStepTest {
.build());
try {
- step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ step.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("Link of type 'homepage' has already been declared on component 'ABCD'");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java
index 9e45fdb347f..8f7165ab46f 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PersistTestsStepTest.java
@@ -43,6 +43,9 @@ import org.sonar.core.persistence.DbTester;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.source.db.FileSourceDto;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.component.DbComponentsRefCache;
import org.sonar.server.computation.component.DbComponentsRefCache.DbComponent;
import org.sonar.server.db.DbClient;
@@ -82,6 +85,7 @@ public class PersistTestsStepTest extends BaseStepTest {
DbClient dbClient;
System2 system2;
Settings projectSettings;
+ LanguageRepository languageRepository;
long now = 123456789L;
@@ -96,6 +100,7 @@ public class PersistTestsStepTest extends BaseStepTest {
dbClient = new DbClient(db.database(), db.myBatis(), new FileSourceDao(db.myBatis()));
reportDir = temp.newFolder();
projectSettings = new Settings();
+ languageRepository = mock(LanguageRepository.class);
system2 = mock(System2.class);
when(system2.now()).thenReturn(now);
@@ -119,7 +124,7 @@ public class PersistTestsStepTest extends BaseStepTest {
@Test
public void no_test_in_database_and_batch_report() {
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(dbClient.fileSourceDao().selectTest(TEST_FILE_UUID_1)).isNull();
assertThat(log.logs()).isEmpty();
@@ -137,7 +142,7 @@ public class PersistTestsStepTest extends BaseStepTest {
);
writer.writeCoverageDetails(TEST_FILE_REF_1, coverageDetails);
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(db.countRowsOfTable("file_sources")).isEqualTo(1);
@@ -161,7 +166,7 @@ public class PersistTestsStepTest extends BaseStepTest {
writer.writeTests(TEST_FILE_REF_1, Arrays.asList(newTest(1)));
writer.writeCoverageDetails(TEST_FILE_REF_1, Arrays.asList(newCoverageDetail(1, MAIN_FILE_REF_1)));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
FileSourceDto dto = dbClient.fileSourceDao().selectTest(TEST_FILE_UUID_1);
assertThat(dto.getCreatedAt()).isEqualTo(now);
@@ -188,7 +193,7 @@ public class PersistTestsStepTest extends BaseStepTest {
List<BatchReport.Test> batchTests = Arrays.asList(newTest(1));
writer.writeTests(TEST_FILE_REF_1, batchTests);
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
FileSourceDto dto = dbClient.fileSourceDao().selectTest(TEST_FILE_UUID_1);
assertThat(dto.getFileUuid()).isEqualTo(TEST_FILE_UUID_1);
@@ -207,7 +212,7 @@ public class PersistTestsStepTest extends BaseStepTest {
writer.writeCoverageDetails(TEST_FILE_REF_1, coverageDetails);
writer.writeCoverageDetails(TEST_FILE_REF_2, coverageDetails);
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
assertThat(log.logs(LoggerLevel.WARN)).hasSize(1);
assertThat(log.logs(LoggerLevel.WARN).get(0)).isEqualTo("Some coverage tests are not taken into account during analysis of project 'PROJECT_KEY'");
@@ -225,7 +230,7 @@ public class PersistTestsStepTest extends BaseStepTest {
newCoverageDetailWithLines(1, MAIN_FILE_REF_1, 1, 3),
newCoverageDetailWithLines(1, MAIN_FILE_REF_1, 2, 4)));
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
FileSourceDto dto = dbClient.fileSourceDao().selectTest(TEST_FILE_UUID_1);
List<Integer> coveredLines = dto.getTestData().get(0).getCoveredFile(0).getCoveredLineList();
@@ -259,7 +264,7 @@ public class PersistTestsStepTest extends BaseStepTest {
writer.writeCoverageDetails(TEST_FILE_REF_1, Arrays.asList(newCoverageDetail));
// ACT
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings, dbClient, ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), languageRepository));
// ASSERT
FileSourceDto dto = dbClient.fileSourceDao().selectTest(TEST_FILE_UUID_1);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java
index efb967031e3..35d0f55a366 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java
@@ -34,6 +34,9 @@ import org.sonar.core.computation.dbcleaner.ProjectCleaner;
import org.sonar.core.persistence.DbSession;
import org.sonar.core.purge.IdUuidPair;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.language.LanguageRepository;
import org.sonar.server.computation.component.DbComponentsRefCache;
import org.sonar.server.db.DbClient;
@@ -67,7 +70,7 @@ public class PurgeDatastoresStepTest extends BaseStepTest {
.build());
ComponentDto project = mock(ComponentDto.class);
- ComputationContext context = new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, new Settings());
+ ComputationContext context = new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, new Settings(), mock(DbClient.class), ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), mock(LanguageRepository.class));
sut.execute(context);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SendIssueNotificationsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SendIssueNotificationsStepTest.java
index 443f3dc8681..2301abbcd21 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/SendIssueNotificationsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/SendIssueNotificationsStepTest.java
@@ -34,9 +34,14 @@ import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.Component;
+import org.sonar.server.computation.component.ComponentTreeBuilders;
import org.sonar.server.computation.component.DbComponentsRefCache;
+import org.sonar.server.computation.component.DumbComponent;
import org.sonar.server.computation.issue.IssueCache;
import org.sonar.server.computation.issue.RuleCache;
+import org.sonar.server.computation.language.LanguageRepository;
+import org.sonar.server.db.DbClient;
import org.sonar.server.issue.notification.IssueChangeNotification;
import org.sonar.server.issue.notification.NewIssuesNotification;
import org.sonar.server.issue.notification.NewIssuesNotificationFactory;
@@ -95,7 +100,8 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
public void do_not_send_notifications_if_no_subscribers() throws IOException {
when(notifService.hasProjectSubscribersForTypes(PROJECT_UUID, SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(false);
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ mock(DbClient.class), ComponentTreeBuilders.from(new DumbComponent(Component.Type.PROJECT, 1)), mock(LanguageRepository.class)));
verify(notifService, never()).deliver(any(Notification.class));
}
@@ -107,7 +113,8 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
when(notifService.hasProjectSubscribersForTypes(PROJECT_UUID, SendIssueNotificationsStep.NOTIF_TYPES)).thenReturn(true);
- sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings));
+ sut.execute(new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, projectSettings,
+ mock(DbClient.class), ComponentTreeBuilders.from(new DumbComponent(Component.Type.PROJECT, 1)), mock(LanguageRepository.class)));
verify(notifService).deliver(any(NewIssuesNotification.class));
verify(notifService, atLeastOnce()).deliver(any(IssueChangeNotification.class));