*/
package batch.suite;
-import com.sonar.orchestrator.locator.ResourceLocation;
-import util.ItUtils;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.build.SonarRunner;
import com.sonar.orchestrator.locator.FileLocation;
-
+import com.sonar.orchestrator.locator.ResourceLocation;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
-
-import static org.assertj.core.api.Assertions.assertThat;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.skyscreamer.jsonassert.JSONAssert;
+import util.ItUtils;
+
+import static org.assertj.core.api.Assertions.assertThat;
public class IssueJsonReportTest {
import org.sonar.api.server.ws.Request;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.component.ComponentDto;
import org.sonar.db.qualityprofile.QualityProfileDto;
+import org.sonar.server.component.ComponentFinder;
import org.sonar.server.qualityprofile.QProfile;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.qualityprofile.QProfileLoader;
private final QProfileLoader profileLoader;
private final QProfileFactory profileFactory;
private final DbClient dbClient;
+ private final ComponentFinder componentFinder;
- public SearchDataLoader(Languages languages, QProfileLookup profileLookup, QProfileLoader profileLoader, QProfileFactory profileFactory, DbClient dbClient) {
+ public SearchDataLoader(Languages languages, QProfileLookup profileLookup, QProfileLoader profileLoader, QProfileFactory profileFactory, DbClient dbClient, ComponentFinder componentFinder) {
this.languages = languages;
this.profileLookup = profileLookup;
this.profileLoader = profileLoader;
this.profileFactory = profileFactory;
this.dbClient = dbClient;
+ this.componentFinder = componentFinder;
}
SearchData load(Request request) {
}
private List<QProfile> findProjectProfiles(Request request) {
- String projectKey = request.param(PARAM_PROJECT_KEY);
+ String moduleKey = request.param(PARAM_PROJECT_KEY);
String profileName = request.param(PARAM_PROFILE_NAME);
List<QProfile> profiles = new ArrayList<>();
try {
for (Language language : languages.all()) {
String languageKey = language.getKey();
- profiles.add(getProfile(dbSession, languageKey, projectKey, profileName));
+ ComponentDto project = getProject(moduleKey, dbSession);
+ profiles.add(getProfile(dbSession, languageKey, project.key(), profileName));
}
} finally {
dbClient.closeSession(dbSession);
return profiles;
}
+ private ComponentDto getProject(String moduleKey, DbSession session) {
+ ComponentDto module = componentFinder.getByKey(session, moduleKey);
+ if (!module.isRootProject()) {
+ return dbClient.componentDao().selectOrFailByUuid(session, module.projectUuid());
+ } else {
+ return module;
+ }
+ }
+
private List<QProfile> findDefaultProfiles() {
List<QProfile> profiles = new ArrayList<>();
import org.sonar.db.qualityprofile.QualityProfileDao;
import org.sonar.db.qualityprofile.QualityProfileDbTester;
import org.sonar.db.qualityprofile.QualityProfileDto;
+import org.sonar.server.component.ComponentFinder;
import org.sonar.server.language.LanguageTesting;
import org.sonar.server.qualityprofile.QProfileFactory;
import org.sonar.server.qualityprofile.QProfileLoader;
new RuleDao(System2.INSTANCE),
System2.INSTANCE));
ws = new WsActionTester(new SearchAction(
- new SearchDataLoader(languages, new QProfileLookup(dbClient), profileLoader, new QProfileFactory(oldDbClient), dbClient), languages));
+ new SearchDataLoader(
+ languages,
+ new QProfileLookup(dbClient),
+ profileLoader,
+ new QProfileFactory(oldDbClient),
+ dbClient,
+ new ComponentFinder(dbClient)),
+ languages));
}
@Test