import org.sonar.db.component.ComponentTesting;
import org.sonar.db.measure.custom.CustomMeasureDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.es.EsTester;
@Test
public void create_custom_measure_on_a_view() {
MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true).setValueType(BOOL.name()));
- OrganizationDto organization = db.organizations().insert();
- ComponentDto view = db.components().insertPrivatePortfolio(organization);
+ ComponentDto view = db.components().insertPrivatePortfolio();
UserDto user = db.users().insertUser();
userSession.logIn(user).addProjectPermission(ADMIN, view);
@Test
public void create_custom_measure_on_a_sub_view() {
MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true).setValueType(BOOL.name()));
- OrganizationDto organization = db.organizations().insert();
- ComponentDto view = db.components().insertPrivatePortfolio(organization);
+ ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subView = db.components().insertSubView(view);
UserDto user = db.users().insertUser();
userSession.logIn(user).addProjectPermission(ADMIN, view);
private final DbClient dbClient = db.getDbClient();
private final DbSession dbSession = db.getSession();
private ComponentDto defaultProject;
- private MetricsAction underTest = new MetricsAction(dbClient, userSession, TestComponentFinder.from(db));
- private WsActionTester tester = new WsActionTester(underTest);
+ private final MetricsAction underTest = new MetricsAction(dbClient, userSession, TestComponentFinder.from(db));
+ private final WsActionTester tester = new WsActionTester(underTest);
@Before
public void setUp() {
}
private ComponentDto insertProject(String projectUuid, String projectKey) {
- ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), projectUuid)
+ ComponentDto project = ComponentTesting.newPrivateProjectDto(projectUuid)
.setDbKey(projectKey);
- dbClient.componentDao().insert(dbSession, project);
- dbSession.commit();
-
+ db.components().insertComponent(project);
return project;
}
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.es.ProjectIndexer;
import org.sonar.server.es.TestProjectIndexers;
private MetricDto intMetric;
private MetricDto ratingMetric;
private MetricDto alertStatusMetric;
- private OrganizationDto organization;
private ComponentDto project;
private ProjectDto projectDto;
private ComponentDto dir;
intMetric = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.INT.name()));
ratingMetric = db.measures().insertMetric(m -> m.setValueType(Metric.ValueType.RATING.name()));
alertStatusMetric = db.measures().insertMetric(m -> m.setKey(CoreMetrics.ALERT_STATUS_KEY));
- organization = db.organizations().insert();
- project = db.components().insertPublicProject(organization);
+ project = db.components().insertPublicProject();
projectDto = db.components().getProjectDto(project);
dir = db.components().insertComponent(ComponentTesting.newDirectory(project, "src/main/java"));
file1 = db.components().insertComponent(ComponentTesting.newFileDto(project, dir));
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.groups.Tuple.tuple;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
public class LiveQualityGateComputerImplTest {
}
@Test
- public void loadQualityGate_on_branch_returns_organization_default_gate() {
+ public void loadQualityGate_on_branch_returns_default_gate() {
ProjectDto project = db.components().insertPublicProjectDto();
BranchDto branch = db.components().insertProjectBranch(project).setBranchType(BranchType.BRANCH);
@Test
public void refreshGateStatus_generates_gate_related_measures() {
- ComponentDto project = ComponentTesting.newPublicProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPublicProjectDto();
MetricDto conditionMetric = newMetricDto();
MetricDto statusMetric = newMetricDto().setKey(CoreMetrics.ALERT_STATUS_KEY);
MetricDto detailsMetric = newMetricDto().setKey(CoreMetrics.QUALITY_GATE_DETAILS_KEY);
@Test
public void refreshGateStatus_provides_measures_to_evaluator() {
- ComponentDto project = ComponentTesting.newPublicProjectDto(newOrganizationDto());
+ ComponentDto project = ComponentTesting.newPublicProjectDto();
MetricDto numericMetric = newMetricDto().setValueType(Metric.ValueType.FLOAT.name());
MetricDto numericNewMetric = newMetricDto().setValueType(Metric.ValueType.FLOAT.name()).setKey("new_metric");
MetricDto stringMetric = newMetricDto().setValueType(Metric.ValueType.STRING.name());
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.metric.MetricTesting.newMetricDto;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
public class MeasureMatrixTest {
- private static final OrganizationDto ORGANIZATION = newOrganizationDto();
- private static final ComponentDto PROJECT = ComponentTesting.newPublicProjectDto(ORGANIZATION);
+ private static final ComponentDto PROJECT = ComponentTesting.newPublicProjectDto();
private static final ComponentDto FILE = ComponentTesting.newFileDto(PROJECT);
private static final MetricDto METRIC_1 = newMetricDto().setUuid("100");
private static final MetricDto METRIC_2 = newMetricDto().setUuid("200");
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- private WsActionTester ws = new WsActionTester(new ComponentAction(db.getDbClient(), TestComponentFinder.from(db), userSession));
+ private final WsActionTester ws = new WsActionTester(new ComponentAction(db.getDbClient(), TestComponentFinder.from(db), userSession));
@Test
public void definition() {
@Test
public void fail_when_using_branch_db_key() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto branch = db.components().insertProjectBranch(project);
MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT"));
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.metric.MetricTesting;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ForbiddenException;
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- private I18nRule i18n = new I18nRule();
- private ResourceTypesRule resourceTypes = new ResourceTypesRule()
+ private final I18nRule i18n = new I18nRule();
+ private final ResourceTypesRule resourceTypes = new ResourceTypesRule()
.setRootQualifiers(PROJECT)
.setLeavesQualifiers(FILE, UNIT_TEST_FILE);
- private DbClient dbClient = db.getDbClient();
- private DbSession dbSession = db.getSession();
+ private final DbClient dbClient = db.getDbClient();
+ private final DbSession dbSession = db.getSession();
- private WsActionTester ws = new WsActionTester(
+ private final WsActionTester ws = new WsActionTester(
new ComponentTreeAction(
dbClient, new ComponentFinder(dbClient, resourceTypes), userSession,
i18n, resourceTypes));
@Test
public void branch() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
SnapshotDto analysis = db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
@Test
public void pull_request() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
SnapshotDto analysis = db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
@Test
public void fix_pull_request_new_issue_count_metrics() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST));
SnapshotDto analysis = db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
@Test
public void new_issue_count_measures_are_not_transformed_if_they_dont_exist_in_pr() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setKey("pr").setBranchType(PULL_REQUEST));
SnapshotDto analysis = db.components().insertSnapshot(pr);
ComponentDto file = db.components().insertComponent(newFileDto(pr));
@Test
public void project_reference_from_portfolio() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto view = db.components().insertPrivatePortfolio(db.getDefaultOrganization());
+ ComponentDto view = db.components().insertPrivatePortfolio();
SnapshotDto viewAnalysis = db.components().insertSnapshot(view);
ComponentDto projectCopy = db.components().insertComponent(newProjectCopy(project, view));
MetricDto ncloc = insertNclocMetric();
}
@Test
- public void fail_when_using_branch_db_key() throws Exception {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ public void fail_when_using_branch_db_key() {
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto branch = db.components().insertProjectBranch(project);
insertNclocMetric();
@Test
public void fail_when_using_branch_uuid() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto branch = db.components().insertProjectBranch(project);
insertNclocMetric();
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.tester.UserSessionRule;
import org.sonar.server.ws.TestRequest;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newSubView;
-import static org.sonar.test.JsonAssert.assertJson;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_METRIC_KEYS;
import static org.sonar.server.component.ws.MeasuresWsParameters.PARAM_PROJECT_KEYS;
+import static org.sonar.test.JsonAssert.assertJson;
public class SearchActionTest {
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- private WsActionTester ws = new WsActionTester(new SearchAction(userSession, db.getDbClient()));
+ private final WsActionTester ws = new WsActionTester(new SearchAction(userSession, db.getDbClient()));
@Test
public void json_example() {
- OrganizationDto organization = db.organizations().insert();
-
- ComponentDto project1 = db.components().insertPrivateProject(organization, p -> p.setDbKey("MY_PROJECT_1").setName("Project 1"));
- ComponentDto project2 = db.components().insertPrivateProject(organization, p -> p.setDbKey("MY_PROJECT_2").setName("Project 2"));
- ComponentDto project3 = db.components().insertPrivateProject(organization, p -> p.setDbKey("MY_PROJECT_3").setName("Project 3"));
+ ComponentDto project1 = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT_1").setName("Project 1"));
+ ComponentDto project2 = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT_2").setName("Project 2"));
+ ComponentDto project3 = db.components().insertPrivateProject(p -> p.setDbKey("MY_PROJECT_3").setName("Project 3"));
userSession.addProjectPermission(UserRole.USER, project1);
userSession.addProjectPermission(UserRole.USER, project2);
@Test
public void return_measures() {
- ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d));
@Test
public void return_best_value() {
- ComponentDto project = db.components().insertPrivateProject(db.getDefaultOrganization());
+ ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
MetricDto matchBestValue = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()).setBestValue(15.5d));
db.measures().insertLiveMeasure(project, matchBestValue, m -> m.setValue(15.5d));
@Test
public void return_measures_on_new_code_period() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
db.measures().insertLiveMeasure(project, coverage, m -> m.setValue(15.5d).setVariation(10d));
public void sort_by_metric_key_then_project_name() {
MetricDto coverage = db.measures().insertMetric(m -> m.setKey("coverage").setValueType(FLOAT.name()));
MetricDto complexity = db.measures().insertMetric(m -> m.setKey("complexity").setValueType(INT.name()));
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization, p -> p.setName("C"));
- ComponentDto project2 = db.components().insertPrivateProject(organization, p -> p.setName("A"));
- ComponentDto project3 = db.components().insertPrivateProject(organization, p -> p.setName("B"));
+ ComponentDto project1 = db.components().insertPrivateProject(p -> p.setName("C"));
+ ComponentDto project2 = db.components().insertPrivateProject(p -> p.setName("A"));
+ ComponentDto project3 = db.components().insertPrivateProject(p -> p.setName("B"));
userSession.addProjectPermission(UserRole.USER, project1);
userSession.addProjectPermission(UserRole.USER, project2);
userSession.addProjectPermission(UserRole.USER, project3);
@Test
public void return_measures_on_view() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto view = db.components().insertPrivatePortfolio(organization);
+ ComponentDto view = db.components().insertPrivatePortfolio();
userSession.addProjectPermission(UserRole.USER, view);
MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
db.measures().insertLiveMeasure(view, coverage, m -> m.setValue(15.5d));
@Test
public void return_measures_on_application() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto application = db.components().insertPrivateApplication(organization);
+ ComponentDto application = db.components().insertPrivateApplication();
userSession.addProjectPermission(UserRole.USER, application);
MetricDto coverage = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
db.measures().insertLiveMeasure(application, coverage, m -> m.setValue(15.5d));
@Test
public void return_measures_on_sub_view() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto view = db.components().insertPrivatePortfolio(organization);
+ ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subView = db.components().insertComponent(newSubView(view));
userSession.addProjectPermission(UserRole.USER, subView);
MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
@Test
public void only_returns_authorized_projects() {
MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
- ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization());
- ComponentDto project2 = db.components().insertPrivateProject(db.getDefaultOrganization());
+ ComponentDto project1 = db.components().insertPrivateProject();
+ ComponentDto project2 = db.components().insertPrivateProject();
db.measures().insertLiveMeasure(project1, metric, m -> m.setValue(15.5d));
db.measures().insertLiveMeasure(project2, metric, m -> m.setValue(42.0d));
Arrays.stream(new ComponentDto[] {project1}).forEach(p -> userSession.addProjectPermission(UserRole.USER, p));
@Test
public void do_not_verify_permissions_if_user_is_root() {
MetricDto metric = db.measures().insertMetric(m -> m.setValueType(FLOAT.name()));
- ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization());
+ ComponentDto project1 = db.components().insertPrivateProject();
db.measures().insertLiveMeasure(project1, metric, m -> m.setValue(15.5d));
userSession.setNonRoot();
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.MeasureDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.server.component.TestComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
@Rule
public DbTester db = DbTester.create();
- private DbClient dbClient = db.getDbClient();
- private DbSession dbSession = db.getSession();
+ private final DbClient dbClient = db.getDbClient();
+ private final DbSession dbSession = db.getSession();
- private WsActionTester ws = new WsActionTester(new SearchHistoryAction(dbClient, TestComponentFinder.from(db), userSession));
+ private final WsActionTester ws = new WsActionTester(new SearchHistoryAction(dbClient, TestComponentFinder.from(db), userSession));
private ComponentDto project;
private SnapshotDto analysis;
@Before
public void setUp() {
- project = newPrivateProjectDto(db.getDefaultOrganization());
+ project = newPrivateProjectDto();
analysis = db.components().insertProjectAndSnapshot(project);
userSession.addProjectPermission(UserRole.USER, project);
nclocMetric = insertNclocMetric();
@Test
public void fail_when_using_branch_db_key() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
userSession.logIn().addProjectPermission(UserRole.USER, project);
ComponentDto branch = db.components().insertProjectBranch(project);
@Test
public void fail_when_component_is_removed() {
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization()));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto());
db.components().insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false));
userSession.addProjectPermission(UserRole.USER, project);